@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Minipres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/headers'); |
@@ -46,61 +46,61 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 48 | 48 | |
| 49 | - utiliser_langue_visiteur(); |
|
| 50 | - |
|
| 51 | - http_no_cache(); |
|
| 52 | - |
|
| 53 | - if ($titre == 'AUTO') { |
|
| 54 | - $titre = _T('info_installation_systeme_publication'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | - # lors de l'installation |
|
| 59 | - if (!headers_sent()) { |
|
| 60 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $css = ''; |
|
| 64 | - $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | - if ($all_inline) { |
|
| 66 | - // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | - foreach ($files as $name) { |
|
| 68 | - $file = direction_css(find_in_theme($name)); |
|
| 69 | - if (function_exists('minifier')) { |
|
| 70 | - $file = minifier($file); |
|
| 71 | - } else { |
|
| 72 | - $file = url_absolue_css($file); // precaution |
|
| 73 | - } |
|
| 74 | - lire_fichier($file, $c); |
|
| 75 | - $css .= $c; |
|
| 76 | - } |
|
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | - } else { |
|
| 79 | - foreach ($files as $name) { |
|
| 80 | - $file = direction_css(find_in_theme($name)); |
|
| 81 | - $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | - define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return _DOCTYPE_ECRIRE . |
|
| 91 | - html_lang_attributes() . |
|
| 92 | - "<head>\n" . |
|
| 93 | - '<title>' . |
|
| 94 | - textebrut($titre) . |
|
| 95 | - "</title>\n" . |
|
| 96 | - "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | - $css . |
|
| 98 | - '</head> |
|
| 49 | + utiliser_langue_visiteur(); |
|
| 50 | + |
|
| 51 | + http_no_cache(); |
|
| 52 | + |
|
| 53 | + if ($titre == 'AUTO') { |
|
| 54 | + $titre = _T('info_installation_systeme_publication'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | + # lors de l'installation |
|
| 59 | + if (!headers_sent()) { |
|
| 60 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $css = ''; |
|
| 64 | + $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | + if ($all_inline) { |
|
| 66 | + // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | + foreach ($files as $name) { |
|
| 68 | + $file = direction_css(find_in_theme($name)); |
|
| 69 | + if (function_exists('minifier')) { |
|
| 70 | + $file = minifier($file); |
|
| 71 | + } else { |
|
| 72 | + $file = url_absolue_css($file); // precaution |
|
| 73 | + } |
|
| 74 | + lire_fichier($file, $c); |
|
| 75 | + $css .= $c; |
|
| 76 | + } |
|
| 77 | + $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | + } else { |
|
| 79 | + foreach ($files as $name) { |
|
| 80 | + $file = direction_css(find_in_theme($name)); |
|
| 81 | + $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | + define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return _DOCTYPE_ECRIRE . |
|
| 91 | + html_lang_attributes() . |
|
| 92 | + "<head>\n" . |
|
| 93 | + '<title>' . |
|
| 94 | + textebrut($titre) . |
|
| 95 | + "</title>\n" . |
|
| 96 | + "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | + $css . |
|
| 98 | + '</head> |
|
| 99 | 99 | <body' . $onLoad . " class='minipres'> |
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 103 | - "</h1> |
|
| 102 | + $titre . |
|
| 103 | + "</h1> |
|
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string Code HTML |
| 111 | 111 | */ |
| 112 | 112 | function install_fin_html() { |
| 113 | - return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 113 | + return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -148,86 +148,86 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function minipres($titre = '', $corps = '', $options = []) { |
| 150 | 150 | |
| 151 | - // compat signature old |
|
| 152 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | - $args = func_get_args(); |
|
| 154 | - if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | - $options = ['onload' => $args[2]]; |
|
| 156 | - } |
|
| 157 | - if (isset($args[3])) { |
|
| 158 | - $options['all_inline'] = $args[3]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $options = array_merge([ |
|
| 162 | - 'onload' => '', |
|
| 163 | - 'all_inline' => false, |
|
| 164 | - ], $options); |
|
| 165 | - |
|
| 166 | - if (!defined('_AJAX')) { |
|
| 167 | - define('_AJAX', false); |
|
| 168 | - } // par securite |
|
| 169 | - if (!$titre) { |
|
| 170 | - if (!isset($options['status'])) { |
|
| 171 | - $options['status'] = 403; |
|
| 172 | - } |
|
| 173 | - if ( |
|
| 174 | - !$titre = _request('action') |
|
| 175 | - and !$titre = _request('exec') |
|
| 176 | - and !$titre = _request('page') |
|
| 177 | - ) { |
|
| 178 | - $titre = '?'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $titre = spip_htmlspecialchars($titre); |
|
| 182 | - |
|
| 183 | - $titre = ($titre == 'install') |
|
| 184 | - ? _T('avis_espace_interdit') |
|
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | - |
|
| 187 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | - |
|
| 190 | - if ($statut != '0minirezo') { |
|
| 191 | - $titre = _T('info_acces_interdit'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($statut and test_espace_prive()) { |
|
| 195 | - $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | - $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | - } |
|
| 200 | - else { |
|
| 201 | - $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | - } |
|
| 203 | - $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (!_AJAX) { |
|
| 208 | - if (isset($options['status'])) { |
|
| 209 | - http_response_code($options['status']); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | - . $corps |
|
| 214 | - . install_fin_html(); |
|
| 215 | - |
|
| 216 | - if ($GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 217 | - and empty($options['all_inline'])) { |
|
| 218 | - define('_SET_HTML_BASE', true); |
|
| 219 | - include_spip('public/assembler'); |
|
| 220 | - $GLOBALS['html'] = true; |
|
| 221 | - page_base_href($html); |
|
| 222 | - } |
|
| 223 | - return $html; |
|
| 224 | - } else { |
|
| 225 | - include_spip('inc/headers'); |
|
| 226 | - include_spip('inc/actions'); |
|
| 227 | - $url = self('&', true); |
|
| 228 | - foreach ($_POST as $v => $c) { |
|
| 229 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 230 | - } |
|
| 231 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 232 | - } |
|
| 151 | + // compat signature old |
|
| 152 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | + $args = func_get_args(); |
|
| 154 | + if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | + $options = ['onload' => $args[2]]; |
|
| 156 | + } |
|
| 157 | + if (isset($args[3])) { |
|
| 158 | + $options['all_inline'] = $args[3]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $options = array_merge([ |
|
| 162 | + 'onload' => '', |
|
| 163 | + 'all_inline' => false, |
|
| 164 | + ], $options); |
|
| 165 | + |
|
| 166 | + if (!defined('_AJAX')) { |
|
| 167 | + define('_AJAX', false); |
|
| 168 | + } // par securite |
|
| 169 | + if (!$titre) { |
|
| 170 | + if (!isset($options['status'])) { |
|
| 171 | + $options['status'] = 403; |
|
| 172 | + } |
|
| 173 | + if ( |
|
| 174 | + !$titre = _request('action') |
|
| 175 | + and !$titre = _request('exec') |
|
| 176 | + and !$titre = _request('page') |
|
| 177 | + ) { |
|
| 178 | + $titre = '?'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $titre = spip_htmlspecialchars($titre); |
|
| 182 | + |
|
| 183 | + $titre = ($titre == 'install') |
|
| 184 | + ? _T('avis_espace_interdit') |
|
| 185 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | + |
|
| 187 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | + |
|
| 190 | + if ($statut != '0minirezo') { |
|
| 191 | + $titre = _T('info_acces_interdit'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($statut and test_espace_prive()) { |
|
| 195 | + $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | + } |
|
| 197 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | + $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | + } |
|
| 200 | + else { |
|
| 201 | + $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | + } |
|
| 203 | + $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (!_AJAX) { |
|
| 208 | + if (isset($options['status'])) { |
|
| 209 | + http_response_code($options['status']); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | + . $corps |
|
| 214 | + . install_fin_html(); |
|
| 215 | + |
|
| 216 | + if ($GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 217 | + and empty($options['all_inline'])) { |
|
| 218 | + define('_SET_HTML_BASE', true); |
|
| 219 | + include_spip('public/assembler'); |
|
| 220 | + $GLOBALS['html'] = true; |
|
| 221 | + page_base_href($html); |
|
| 222 | + } |
|
| 223 | + return $html; |
|
| 224 | + } else { |
|
| 225 | + include_spip('inc/headers'); |
|
| 226 | + include_spip('inc/actions'); |
|
| 227 | + $url = self('&', true); |
|
| 228 | + foreach ($_POST as $v => $c) { |
|
| 229 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 230 | + } |
|
| 231 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 232 | + } |
|
| 233 | 233 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | 214 | function header_silencieux($version) { |
| 215 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | - $version = ''; |
|
| 217 | - } |
|
| 215 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | + $version = ''; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $version; |
|
| 219 | + return $version; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | * - string|null si $raw = false |
| 230 | 230 | */ |
| 231 | 231 | function version_vcs_courante($dir, $raw = false) { |
| 232 | - $desc = decrire_version_git($dir); |
|
| 233 | - if ($desc === null) { |
|
| 234 | - $desc = decrire_version_svn($dir); |
|
| 235 | - } |
|
| 236 | - if ($desc === null or $raw) { |
|
| 237 | - return $desc; |
|
| 238 | - } |
|
| 239 | - // affichage "GIT [master: abcdef]" |
|
| 240 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | - if ($desc['branch']) { |
|
| 242 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | - } |
|
| 244 | - return "{$desc['vcs']} [$commit]"; |
|
| 232 | + $desc = decrire_version_git($dir); |
|
| 233 | + if ($desc === null) { |
|
| 234 | + $desc = decrire_version_svn($dir); |
|
| 235 | + } |
|
| 236 | + if ($desc === null or $raw) { |
|
| 237 | + return $desc; |
|
| 238 | + } |
|
| 239 | + // affichage "GIT [master: abcdef]" |
|
| 240 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | + if ($desc['branch']) { |
|
| 242 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | + } |
|
| 244 | + return "{$desc['vcs']} [$commit]"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -253,24 +253,24 @@ discard block |
||
| 253 | 253 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 254 | 254 | **/ |
| 255 | 255 | function decrire_version_git($dir) { |
| 256 | - if (!$dir) { |
|
| 257 | - $dir = '.'; |
|
| 258 | - } |
|
| 256 | + if (!$dir) { |
|
| 257 | + $dir = '.'; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // version installee par GIT |
|
| 261 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | - $currentHead = trim(substr($c, 4)); |
|
| 263 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | - return [ |
|
| 265 | - 'vcs' => 'GIT', |
|
| 266 | - 'branch' => basename($currentHead), |
|
| 267 | - 'commit' => trim($hash), |
|
| 268 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | - ]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 260 | + // version installee par GIT |
|
| 261 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | + $currentHead = trim(substr($c, 4)); |
|
| 263 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | + return [ |
|
| 265 | + 'vcs' => 'GIT', |
|
| 266 | + 'branch' => basename($currentHead), |
|
| 267 | + 'commit' => trim($hash), |
|
| 268 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | + ]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - return null; |
|
| 273 | + return null; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -283,25 +283,25 @@ discard block |
||
| 283 | 283 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function decrire_version_svn($dir) { |
| 286 | - if (!$dir) { |
|
| 287 | - $dir = '.'; |
|
| 288 | - } |
|
| 289 | - // version installee par SVN |
|
| 290 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | - if ($result) { |
|
| 294 | - $row = $result->fetchArray(); |
|
| 295 | - if ($row['changed_revision'] != '') { |
|
| 296 | - return [ |
|
| 297 | - 'vcs' => 'SVN', |
|
| 298 | - 'branch' => '', |
|
| 299 | - 'commit' => $row['changed_revision'], |
|
| 300 | - ]; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return null; |
|
| 286 | + if (!$dir) { |
|
| 287 | + $dir = '.'; |
|
| 288 | + } |
|
| 289 | + // version installee par SVN |
|
| 290 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | + if ($result) { |
|
| 294 | + $row = $result->fetchArray(); |
|
| 295 | + if ($row['changed_revision'] != '') { |
|
| 296 | + return [ |
|
| 297 | + 'vcs' => 'SVN', |
|
| 298 | + 'branch' => '', |
|
| 299 | + 'commit' => $row['changed_revision'], |
|
| 300 | + ]; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return null; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | * Code HTML retourné par le filtre |
| 349 | 349 | **/ |
| 350 | 350 | function filtrer($filtre) { |
| 351 | - $tous = func_get_args(); |
|
| 352 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | - return image_filtrer($tous); |
|
| 354 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | - array_shift($tous); |
|
| 356 | - return call_user_func_array($f, $tous); |
|
| 357 | - } else { |
|
| 358 | - // le filtre n'existe pas, on provoque une erreur |
|
| 359 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | - erreur_squelette($msg); |
|
| 361 | - return ''; |
|
| 362 | - } |
|
| 351 | + $tous = func_get_args(); |
|
| 352 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | + return image_filtrer($tous); |
|
| 354 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | + array_shift($tous); |
|
| 356 | + return call_user_func_array($f, $tous); |
|
| 357 | + } else { |
|
| 358 | + // le filtre n'existe pas, on provoque une erreur |
|
| 359 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | + erreur_squelette($msg); |
|
| 361 | + return ''; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 377 | 377 | */ |
| 378 | 378 | function trouver_filtre_matrice($filtre) { |
| 379 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | - find_in_path($f, '', true); |
|
| 381 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | - } |
|
| 383 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | + find_in_path($f, '', true); |
|
| 381 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | + } |
|
| 383 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @return mixed |
| 409 | 409 | */ |
| 410 | 410 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 411 | - $Pile['vars'][$key] = $val; |
|
| 412 | - return $continue ? $val : ''; |
|
| 411 | + $Pile['vars'][$key] = $val; |
|
| 412 | + return $continue ? $val : ''; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 436 | 436 | */ |
| 437 | 437 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 438 | - $Pile[0][$key] = $val; |
|
| 439 | - return $continue ? $val : ''; |
|
| 438 | + $Pile[0][$key] = $val; |
|
| 439 | + return $continue ? $val : ''; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | 447 | function filtre_sanitize_env(&$Pile, $keys) { |
| 448 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | - return ''; |
|
| 448 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | * @return mixed Retourne la valeur (sans la modifier). |
| 470 | 470 | */ |
| 471 | 471 | function filtre_debug($val, $key = null) { |
| 472 | - $debug = ( |
|
| 473 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | - ) . var_export($val, true); |
|
| 472 | + $debug = ( |
|
| 473 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | + ) . var_export($val, true); |
|
| 475 | 475 | |
| 476 | - include_spip('inc/autoriser'); |
|
| 477 | - if (autoriser('webmestre')) { |
|
| 478 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | - } |
|
| 476 | + include_spip('inc/autoriser'); |
|
| 477 | + if (autoriser('webmestre')) { |
|
| 478 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - spip_log($debug, 'debug'); |
|
| 481 | + spip_log($debug, 'debug'); |
|
| 482 | 482 | |
| 483 | - return $val; |
|
| 483 | + return $val; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -508,89 +508,89 @@ discard block |
||
| 508 | 508 | * Texte qui a reçu les filtres |
| 509 | 509 | **/ |
| 510 | 510 | function image_filtrer($args) { |
| 511 | - $filtre = array_shift($args); # enlever $filtre |
|
| 512 | - $texte = array_shift($args); |
|
| 513 | - if ($texte === null || !strlen($texte)) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | - // Cas du nom de fichier local |
|
| 519 | - $is_file = trim($texte); |
|
| 520 | - if ( |
|
| 521 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | - or strpos($is_file, '/') === 0 |
|
| 524 | - ) { |
|
| 525 | - $is_file = false; |
|
| 526 | - } |
|
| 527 | - if ($is_file) { |
|
| 528 | - $is_local_file = function ($path) { |
|
| 529 | - if (strpos($path, '?') !== false) { |
|
| 530 | - $path = supprimer_timestamp($path); |
|
| 531 | - // remove ?24px added by find_in_theme on .svg files |
|
| 532 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | - } |
|
| 534 | - return file_exists($path); |
|
| 535 | - }; |
|
| 536 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | - $res = call_user_func_array($filtre, $args); |
|
| 539 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | - return $res; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | - if ( |
|
| 546 | - preg_match_all( |
|
| 547 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | - $texte, |
|
| 549 | - $tags, |
|
| 550 | - PREG_SET_ORDER |
|
| 551 | - ) |
|
| 552 | - ) { |
|
| 553 | - foreach ($tags as $tag) { |
|
| 554 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | - if ( |
|
| 556 | - !$class or |
|
| 557 | - (strpos($class, 'filtre_inactif') === false |
|
| 558 | - // compat historique a virer en 3.2 |
|
| 559 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | - ) { |
|
| 561 | - array_unshift($args, $tag[3]); |
|
| 562 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 563 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | - if ($tag[1]) { |
|
| 565 | - $w = extraire_attribut($reduit, 'width'); |
|
| 566 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | - $w = $regs[1]; |
|
| 568 | - } |
|
| 569 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - // traiter aussi un eventuel mouseover |
|
| 576 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | - $srcover = $match[1]; |
|
| 579 | - array_shift($args); |
|
| 580 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 582 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | - } |
|
| 588 | - array_shift($args); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | - return $texte; |
|
| 511 | + $filtre = array_shift($args); # enlever $filtre |
|
| 512 | + $texte = array_shift($args); |
|
| 513 | + if ($texte === null || !strlen($texte)) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | + // Cas du nom de fichier local |
|
| 519 | + $is_file = trim($texte); |
|
| 520 | + if ( |
|
| 521 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | + or strpos($is_file, '/') === 0 |
|
| 524 | + ) { |
|
| 525 | + $is_file = false; |
|
| 526 | + } |
|
| 527 | + if ($is_file) { |
|
| 528 | + $is_local_file = function ($path) { |
|
| 529 | + if (strpos($path, '?') !== false) { |
|
| 530 | + $path = supprimer_timestamp($path); |
|
| 531 | + // remove ?24px added by find_in_theme on .svg files |
|
| 532 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | + } |
|
| 534 | + return file_exists($path); |
|
| 535 | + }; |
|
| 536 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | + $res = call_user_func_array($filtre, $args); |
|
| 539 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | + return $res; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | + if ( |
|
| 546 | + preg_match_all( |
|
| 547 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | + $texte, |
|
| 549 | + $tags, |
|
| 550 | + PREG_SET_ORDER |
|
| 551 | + ) |
|
| 552 | + ) { |
|
| 553 | + foreach ($tags as $tag) { |
|
| 554 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | + if ( |
|
| 556 | + !$class or |
|
| 557 | + (strpos($class, 'filtre_inactif') === false |
|
| 558 | + // compat historique a virer en 3.2 |
|
| 559 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | + ) { |
|
| 561 | + array_unshift($args, $tag[3]); |
|
| 562 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 563 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | + if ($tag[1]) { |
|
| 565 | + $w = extraire_attribut($reduit, 'width'); |
|
| 566 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | + $w = $regs[1]; |
|
| 568 | + } |
|
| 569 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + // traiter aussi un eventuel mouseover |
|
| 576 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | + $srcover = $match[1]; |
|
| 579 | + array_shift($args); |
|
| 580 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 582 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | + } |
|
| 588 | + array_shift($args); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | + return $texte; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -607,91 +607,91 @@ discard block |
||
| 607 | 607 | **/ |
| 608 | 608 | function infos_image($img, $force_refresh = false) { |
| 609 | 609 | |
| 610 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | - $srcWidth = 0; |
|
| 612 | - $srcHeight = 0; |
|
| 613 | - $srcSize = null; |
|
| 614 | - |
|
| 615 | - $src = extraire_attribut($img, 'src'); |
|
| 616 | - |
|
| 617 | - if (!$src) { |
|
| 618 | - $src = $img; |
|
| 619 | - } else { |
|
| 620 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | - if (tester_url_absolue($src)) { |
|
| 627 | - include_spip('inc/distant'); |
|
| 628 | - $fichier = copie_locale($src); |
|
| 629 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | - } |
|
| 631 | - if (($p = strpos($src, '?')) !== false) { |
|
| 632 | - $src = substr($src, 0, $p); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $imagesize = false; |
|
| 636 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | - $srcWidth = $largeur_img[$src]; |
|
| 638 | - } |
|
| 639 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | - $srcHeight = $hauteur_img[$src]; |
|
| 641 | - } |
|
| 642 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | - $srcSize = $poids_img[$src]; |
|
| 644 | - } |
|
| 645 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | - if ( |
|
| 647 | - file_exists($src) |
|
| 648 | - and $imagesize = spip_getimagesize($src) |
|
| 649 | - ) { |
|
| 650 | - if (!$srcWidth) { |
|
| 651 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | - } |
|
| 653 | - if (!$srcHeight) { |
|
| 654 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | - } |
|
| 656 | - if (!$srcSize){ |
|
| 657 | - $poids_img[$src] = filesize($src); |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - elseif (strpos($src, '<svg') !== false) { |
|
| 661 | - include_spip('inc/svg'); |
|
| 662 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | - if (!$srcWidth) { |
|
| 665 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | - } |
|
| 667 | - if (!$srcHeight) { |
|
| 668 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | - } |
|
| 670 | - if (!$srcSize){ |
|
| 671 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | - elseif ( |
|
| 678 | - @file_exists($f = "$src.src") |
|
| 679 | - and lire_fichier($f, $valeurs) |
|
| 680 | - and $valeurs = unserialize($valeurs) |
|
| 681 | - ) { |
|
| 682 | - if (!$srcWidth) { |
|
| 683 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | - } |
|
| 685 | - if (!$srcHeight) { |
|
| 686 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | - } |
|
| 688 | - if (!$srcSize){ |
|
| 689 | - $poids_img[$src] = $srcSize = 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 610 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | + $srcWidth = 0; |
|
| 612 | + $srcHeight = 0; |
|
| 613 | + $srcSize = null; |
|
| 614 | + |
|
| 615 | + $src = extraire_attribut($img, 'src'); |
|
| 616 | + |
|
| 617 | + if (!$src) { |
|
| 618 | + $src = $img; |
|
| 619 | + } else { |
|
| 620 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | + if (tester_url_absolue($src)) { |
|
| 627 | + include_spip('inc/distant'); |
|
| 628 | + $fichier = copie_locale($src); |
|
| 629 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | + } |
|
| 631 | + if (($p = strpos($src, '?')) !== false) { |
|
| 632 | + $src = substr($src, 0, $p); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $imagesize = false; |
|
| 636 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | + $srcWidth = $largeur_img[$src]; |
|
| 638 | + } |
|
| 639 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | + $srcHeight = $hauteur_img[$src]; |
|
| 641 | + } |
|
| 642 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | + $srcSize = $poids_img[$src]; |
|
| 644 | + } |
|
| 645 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | + if ( |
|
| 647 | + file_exists($src) |
|
| 648 | + and $imagesize = spip_getimagesize($src) |
|
| 649 | + ) { |
|
| 650 | + if (!$srcWidth) { |
|
| 651 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | + } |
|
| 653 | + if (!$srcHeight) { |
|
| 654 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | + } |
|
| 656 | + if (!$srcSize){ |
|
| 657 | + $poids_img[$src] = filesize($src); |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + elseif (strpos($src, '<svg') !== false) { |
|
| 661 | + include_spip('inc/svg'); |
|
| 662 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | + if (!$srcWidth) { |
|
| 665 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | + } |
|
| 667 | + if (!$srcHeight) { |
|
| 668 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | + } |
|
| 670 | + if (!$srcSize){ |
|
| 671 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | + elseif ( |
|
| 678 | + @file_exists($f = "$src.src") |
|
| 679 | + and lire_fichier($f, $valeurs) |
|
| 680 | + and $valeurs = unserialize($valeurs) |
|
| 681 | + ) { |
|
| 682 | + if (!$srcWidth) { |
|
| 683 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | + } |
|
| 685 | + if (!$srcHeight) { |
|
| 686 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | + } |
|
| 688 | + if (!$srcSize){ |
|
| 689 | + $poids_img[$src] = $srcSize = 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | * poids |
| 708 | 708 | **/ |
| 709 | 709 | function poids_image($img, $force_refresh = false) { |
| 710 | - $infos = infos_image($img, $force_refresh); |
|
| 711 | - return $infos['poids']; |
|
| 710 | + $infos = infos_image($img, $force_refresh); |
|
| 711 | + return $infos['poids']; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function taille_image($img, $force_refresh = false){ |
| 715 | - $infos = infos_image($img, $force_refresh); |
|
| 716 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 715 | + $infos = infos_image($img, $force_refresh); |
|
| 716 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 731 | 731 | **/ |
| 732 | 732 | function largeur($img) { |
| 733 | - if (!$img) { |
|
| 734 | - return; |
|
| 735 | - } |
|
| 736 | - [$h, $l] = taille_image($img); |
|
| 733 | + if (!$img) { |
|
| 734 | + return; |
|
| 735 | + } |
|
| 736 | + [$h, $l] = taille_image($img); |
|
| 737 | 737 | |
| 738 | - return $l; |
|
| 738 | + return $l; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 753 | 753 | **/ |
| 754 | 754 | function hauteur($img) { |
| 755 | - if (!$img) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - [$h, $l] = taille_image($img); |
|
| 755 | + if (!$img) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + [$h, $l] = taille_image($img); |
|
| 759 | 759 | |
| 760 | - return $h; |
|
| 760 | + return $h; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | * @return string |
| 778 | 778 | **/ |
| 779 | 779 | function corriger_entites_html($texte) { |
| 780 | - if (strpos($texte, '&') === false) { |
|
| 781 | - return $texte; |
|
| 782 | - } |
|
| 780 | + if (strpos($texte, '&') === false) { |
|
| 781 | + return $texte; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 784 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | * @return string |
| 797 | 797 | **/ |
| 798 | 798 | function corriger_toutes_entites_html($texte) { |
| 799 | - if (strpos($texte, '&') === false) { |
|
| 800 | - return $texte; |
|
| 801 | - } |
|
| 799 | + if (strpos($texte, '&') === false) { |
|
| 800 | + return $texte; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 803 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * @return string |
| 811 | 811 | **/ |
| 812 | 812 | function proteger_amp($texte) { |
| 813 | - return str_replace('&', '&', $texte); |
|
| 813 | + return str_replace('&', '&', $texte); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -841,21 +841,21 @@ discard block |
||
| 841 | 841 | * @return mixed|string |
| 842 | 842 | */ |
| 843 | 843 | function entites_html($texte, $tout = false, $quote = true) { |
| 844 | - if ( |
|
| 845 | - !is_string($texte) or !$texte |
|
| 846 | - or strpbrk($texte, "&\"'<>") == false |
|
| 847 | - ) { |
|
| 848 | - return $texte; |
|
| 849 | - } |
|
| 850 | - include_spip('inc/texte'); |
|
| 851 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | - $flags |= ENT_HTML401; |
|
| 853 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | - if ($tout) { |
|
| 855 | - return corriger_toutes_entites_html($texte); |
|
| 856 | - } else { |
|
| 857 | - return corriger_entites_html($texte); |
|
| 858 | - } |
|
| 844 | + if ( |
|
| 845 | + !is_string($texte) or !$texte |
|
| 846 | + or strpbrk($texte, "&\"'<>") == false |
|
| 847 | + ) { |
|
| 848 | + return $texte; |
|
| 849 | + } |
|
| 850 | + include_spip('inc/texte'); |
|
| 851 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | + $flags |= ENT_HTML401; |
|
| 853 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | + if ($tout) { |
|
| 855 | + return corriger_toutes_entites_html($texte); |
|
| 856 | + } else { |
|
| 857 | + return corriger_entites_html($texte); |
|
| 858 | + } |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -874,37 +874,37 @@ discard block |
||
| 874 | 874 | * Texte converti |
| 875 | 875 | **/ |
| 876 | 876 | function filtrer_entites($texte) { |
| 877 | - if (strpos($texte, '&') === false) { |
|
| 878 | - return $texte; |
|
| 879 | - } |
|
| 880 | - // filtrer |
|
| 881 | - $texte = html2unicode($texte); |
|
| 882 | - // remettre le tout dans le charset cible |
|
| 883 | - $texte = unicode2charset($texte); |
|
| 884 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | - // (on le faisait deja avec un ") |
|
| 886 | - if (strpos($texte, '&#') !== false) { |
|
| 887 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | - } |
|
| 877 | + if (strpos($texte, '&') === false) { |
|
| 878 | + return $texte; |
|
| 879 | + } |
|
| 880 | + // filtrer |
|
| 881 | + $texte = html2unicode($texte); |
|
| 882 | + // remettre le tout dans le charset cible |
|
| 883 | + $texte = unicode2charset($texte); |
|
| 884 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | + // (on le faisait deja avec un ") |
|
| 886 | + if (strpos($texte, '&#') !== false) { |
|
| 887 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - return $texte; |
|
| 890 | + return $texte; |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
| 894 | 894 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 895 | - /** |
|
| 896 | - * Version sécurisée de filtrer_entites |
|
| 897 | - * |
|
| 898 | - * @uses interdire_scripts() |
|
| 899 | - * @uses filtrer_entites() |
|
| 900 | - * |
|
| 901 | - * @param string $t |
|
| 902 | - * @return string |
|
| 903 | - */ |
|
| 904 | - function filtre_filtrer_entites_dist($t) { |
|
| 905 | - include_spip('inc/texte'); |
|
| 906 | - return interdire_scripts(filtrer_entites($t)); |
|
| 907 | - } |
|
| 895 | + /** |
|
| 896 | + * Version sécurisée de filtrer_entites |
|
| 897 | + * |
|
| 898 | + * @uses interdire_scripts() |
|
| 899 | + * @uses filtrer_entites() |
|
| 900 | + * |
|
| 901 | + * @param string $t |
|
| 902 | + * @return string |
|
| 903 | + */ |
|
| 904 | + function filtre_filtrer_entites_dist($t) { |
|
| 905 | + include_spip('inc/texte'); |
|
| 906 | + return interdire_scripts(filtrer_entites($t)); |
|
| 907 | + } |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -919,18 +919,18 @@ discard block |
||
| 919 | 919 | * @return string|array |
| 920 | 920 | **/ |
| 921 | 921 | function supprimer_caracteres_illegaux($texte) { |
| 922 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 923 | - static $to = null; |
|
| 922 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 923 | + static $to = null; |
|
| 924 | 924 | |
| 925 | - if (is_array($texte)) { |
|
| 926 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | - } |
|
| 925 | + if (is_array($texte)) { |
|
| 926 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - if (!$to) { |
|
| 930 | - $to = str_repeat('-', strlen($from)); |
|
| 931 | - } |
|
| 929 | + if (!$to) { |
|
| 930 | + $to = str_repeat('-', strlen($from)); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return strtr($texte, $from, $to); |
|
| 933 | + return strtr($texte, $from, $to); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | * @return string|array |
| 943 | 943 | **/ |
| 944 | 944 | function corriger_caracteres($texte) { |
| 945 | - $texte = corriger_caracteres_windows($texte); |
|
| 946 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 945 | + $texte = corriger_caracteres_windows($texte); |
|
| 946 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 947 | 947 | |
| 948 | - return $texte; |
|
| 948 | + return $texte; |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -962,44 +962,44 @@ discard block |
||
| 962 | 962 | * Texte encodé pour XML |
| 963 | 963 | */ |
| 964 | 964 | function texte_backend(string $texte): string { |
| 965 | - if ($texte === '') { |
|
| 966 | - return ''; |
|
| 967 | - } |
|
| 965 | + if ($texte === '') { |
|
| 966 | + return ''; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 969 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 970 | 970 | |
| 971 | - // si on a des liens ou des images, les passer en absolu |
|
| 972 | - $texte = liens_absolus($texte); |
|
| 971 | + // si on a des liens ou des images, les passer en absolu |
|
| 972 | + $texte = liens_absolus($texte); |
|
| 973 | 973 | |
| 974 | - // echapper les tags > < |
|
| 975 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 974 | + // echapper les tags > < |
|
| 975 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 976 | 976 | |
| 977 | - // importer les é |
|
| 978 | - $texte = filtrer_entites($texte); |
|
| 977 | + // importer les é |
|
| 978 | + $texte = filtrer_entites($texte); |
|
| 979 | 979 | |
| 980 | - // " -> " et tout ce genre de choses |
|
| 981 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | - $texte = str_replace(' ', ' ', $texte); |
|
| 983 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | - $texte = entites_html($texte, false, false); |
|
| 986 | - // mais bien echapper les double quotes ! |
|
| 987 | - $texte = str_replace('"', '"', $texte); |
|
| 980 | + // " -> " et tout ce genre de choses |
|
| 981 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | + $texte = str_replace(' ', ' ', $texte); |
|
| 983 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | + $texte = entites_html($texte, false, false); |
|
| 986 | + // mais bien echapper les double quotes ! |
|
| 987 | + $texte = str_replace('"', '"', $texte); |
|
| 988 | 988 | |
| 989 | - // verifier le charset |
|
| 990 | - $texte = charset2unicode($texte); |
|
| 989 | + // verifier le charset |
|
| 990 | + $texte = charset2unicode($texte); |
|
| 991 | 991 | |
| 992 | - // Caracteres problematiques en iso-latin 1 |
|
| 993 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | - } |
|
| 992 | + // Caracteres problematiques en iso-latin 1 |
|
| 993 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | + } |
|
| 998 | 998 | |
| 999 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | - // ==> on les remplace par l'entite HTML |
|
| 1002 | - return str_replace($apostrophe, "'", $texte); |
|
| 999 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | + // ==> on les remplace par l'entite HTML |
|
| 1002 | + return str_replace($apostrophe, "'", $texte); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | * Texte encodé et quote pour XML |
| 1017 | 1017 | */ |
| 1018 | 1018 | function texte_backendq(string $texte): string { |
| 1019 | - return addslashes(texte_backend($texte)); |
|
| 1019 | + return addslashes(texte_backend($texte)); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | |
@@ -1039,11 +1039,11 @@ discard block |
||
| 1039 | 1039 | * Numéro de titre, sinon chaîne vide |
| 1040 | 1040 | **/ |
| 1041 | 1041 | function supprimer_numero($texte) { |
| 1042 | - return preg_replace( |
|
| 1043 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | - '', |
|
| 1045 | - $texte |
|
| 1046 | - ); |
|
| 1042 | + return preg_replace( |
|
| 1043 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | + '', |
|
| 1045 | + $texte |
|
| 1046 | + ); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1066,17 +1066,17 @@ discard block |
||
| 1066 | 1066 | * Numéro de titre, sinon chaîne vide |
| 1067 | 1067 | **/ |
| 1068 | 1068 | function recuperer_numero($texte) { |
| 1069 | - if ( |
|
| 1070 | - preg_match( |
|
| 1071 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | - $texte, |
|
| 1073 | - $regs |
|
| 1074 | - ) |
|
| 1075 | - ) { |
|
| 1076 | - return strval($regs[1]); |
|
| 1077 | - } else { |
|
| 1078 | - return ''; |
|
| 1079 | - } |
|
| 1069 | + if ( |
|
| 1070 | + preg_match( |
|
| 1071 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | + $texte, |
|
| 1073 | + $regs |
|
| 1074 | + ) |
|
| 1075 | + ) { |
|
| 1076 | + return strval($regs[1]); |
|
| 1077 | + } else { |
|
| 1078 | + return ''; |
|
| 1079 | + } |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * Texte converti |
| 1104 | 1104 | **/ |
| 1105 | 1105 | function supprimer_tags(?string $texte, $rempl = ''): string { |
| 1106 | - if ($texte === null || !strlen($texte)) { |
|
| 1107 | - return ''; |
|
| 1108 | - } |
|
| 1109 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | - // ne pas oublier un < final non ferme car coupe |
|
| 1111 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | - $texte = str_replace('<', '<', $texte); |
|
| 1106 | + if ($texte === null || !strlen($texte)) { |
|
| 1107 | + return ''; |
|
| 1108 | + } |
|
| 1109 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | + // ne pas oublier un < final non ferme car coupe |
|
| 1111 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | + $texte = str_replace('<', '<', $texte); |
|
| 1114 | 1114 | |
| 1115 | - return $texte; |
|
| 1115 | + return $texte; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1135,9 +1135,9 @@ discard block |
||
| 1135 | 1135 | * Texte converti |
| 1136 | 1136 | **/ |
| 1137 | 1137 | function echapper_tags($texte, $rempl = '') { |
| 1138 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1138 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1139 | 1139 | |
| 1140 | - return $texte; |
|
| 1140 | + return $texte; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1158,18 +1158,18 @@ discard block |
||
| 1158 | 1158 | * Texte converti |
| 1159 | 1159 | **/ |
| 1160 | 1160 | function textebrut($texte) { |
| 1161 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | - $texte = supprimer_tags($texte); |
|
| 1168 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | - $texte = str_replace('’', "'", $texte); |
|
| 1161 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | + $texte = supprimer_tags($texte); |
|
| 1168 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | + $texte = str_replace('’', "'", $texte); |
|
| 1171 | 1171 | |
| 1172 | - return $texte; |
|
| 1172 | + return $texte; |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1185,23 +1185,23 @@ discard block |
||
| 1185 | 1185 | * Texte avec liens ouvrants |
| 1186 | 1186 | **/ |
| 1187 | 1187 | function liens_ouvrants($texte) { |
| 1188 | - if ( |
|
| 1189 | - preg_match_all( |
|
| 1190 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | - $texte, |
|
| 1192 | - $liens, |
|
| 1193 | - PREG_PATTERN_ORDER |
|
| 1194 | - ) |
|
| 1195 | - ) { |
|
| 1196 | - foreach ($liens[0] as $a) { |
|
| 1197 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - return $texte; |
|
| 1188 | + if ( |
|
| 1189 | + preg_match_all( |
|
| 1190 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | + $texte, |
|
| 1192 | + $liens, |
|
| 1193 | + PREG_PATTERN_ORDER |
|
| 1194 | + ) |
|
| 1195 | + ) { |
|
| 1196 | + foreach ($liens[0] as $a) { |
|
| 1197 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return $texte; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | /** |
@@ -1211,22 +1211,22 @@ discard block |
||
| 1211 | 1211 | * @return string |
| 1212 | 1212 | */ |
| 1213 | 1213 | function liens_nofollow($texte) { |
| 1214 | - if (stripos($texte, '<a') === false) { |
|
| 1215 | - return $texte; |
|
| 1216 | - } |
|
| 1214 | + if (stripos($texte, '<a') === false) { |
|
| 1215 | + return $texte; |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | - foreach ($regs[0] as $a) { |
|
| 1220 | - $rel = extraire_attribut($a, 'rel'); |
|
| 1221 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | - } |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1218 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | + foreach ($regs[0] as $a) { |
|
| 1220 | + $rel = extraire_attribut($a, 'rel'); |
|
| 1221 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | + } |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | 1228 | |
| 1229 | - return $texte; |
|
| 1229 | + return $texte; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1245,12 +1245,12 @@ discard block |
||
| 1245 | 1245 | * Texte sans paraghaphes |
| 1246 | 1246 | **/ |
| 1247 | 1247 | function PtoBR($texte) { |
| 1248 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1248 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1252 | 1252 | |
| 1253 | - return $texte; |
|
| 1253 | + return $texte; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1275,14 +1275,14 @@ discard block |
||
| 1275 | 1275 | * @return string Texte encadré du style CSS |
| 1276 | 1276 | */ |
| 1277 | 1277 | function lignes_longues($texte) { |
| 1278 | - if (!strlen(trim($texte))) { |
|
| 1279 | - return $texte; |
|
| 1280 | - } |
|
| 1281 | - include_spip('inc/texte'); |
|
| 1282 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | - 'div' : 'span'; |
|
| 1278 | + if (!strlen(trim($texte))) { |
|
| 1279 | + return $texte; |
|
| 1280 | + } |
|
| 1281 | + include_spip('inc/texte'); |
|
| 1282 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | + 'div' : 'span'; |
|
| 1284 | 1284 | |
| 1285 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1285 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1301,30 +1301,30 @@ discard block |
||
| 1301 | 1301 | * @return string Texte en majuscule |
| 1302 | 1302 | */ |
| 1303 | 1303 | function majuscules($texte) { |
| 1304 | - if (!strlen($texte)) { |
|
| 1305 | - return ''; |
|
| 1306 | - } |
|
| 1304 | + if (!strlen($texte)) { |
|
| 1305 | + return ''; |
|
| 1306 | + } |
|
| 1307 | 1307 | |
| 1308 | - // Cas du turc |
|
| 1309 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | - # remplacer hors des tags et des entites |
|
| 1311 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | - foreach ($regs as $n => $match) { |
|
| 1313 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1308 | + // Cas du turc |
|
| 1309 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | + # remplacer hors des tags et des entites |
|
| 1311 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | + foreach ($regs as $n => $match) { |
|
| 1313 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | 1316 | |
| 1317 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1317 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1318 | 1318 | |
| 1319 | - if ($regs) { |
|
| 1320 | - foreach ($regs as $n => $match) { |
|
| 1321 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1319 | + if ($regs) { |
|
| 1320 | + foreach ($regs as $n => $match) { |
|
| 1321 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - // Cas general |
|
| 1327 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1326 | + // Cas general |
|
| 1327 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
@@ -1342,29 +1342,29 @@ discard block |
||
| 1342 | 1342 | * @return string |
| 1343 | 1343 | **/ |
| 1344 | 1344 | function taille_en_octets($taille) { |
| 1345 | - if (!defined('_KILOBYTE')) { |
|
| 1346 | - /** |
|
| 1347 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | - * |
|
| 1349 | - * @var int |
|
| 1350 | - **/ |
|
| 1351 | - define('_KILOBYTE', 1024); |
|
| 1352 | - } |
|
| 1345 | + if (!defined('_KILOBYTE')) { |
|
| 1346 | + /** |
|
| 1347 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | + * |
|
| 1349 | + * @var int |
|
| 1350 | + **/ |
|
| 1351 | + define('_KILOBYTE', 1024); |
|
| 1352 | + } |
|
| 1353 | 1353 | |
| 1354 | - if ($taille < 1) { |
|
| 1355 | - return ''; |
|
| 1356 | - } |
|
| 1357 | - if ($taille < _KILOBYTE) { |
|
| 1358 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | - } else { |
|
| 1364 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | - } |
|
| 1354 | + if ($taille < 1) { |
|
| 1355 | + return ''; |
|
| 1356 | + } |
|
| 1357 | + if ($taille < _KILOBYTE) { |
|
| 1358 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | + } else { |
|
| 1364 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | - return $taille; |
|
| 1367 | + return $taille; |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1386,21 +1386,21 @@ discard block |
||
| 1386 | 1386 | * Texte prêt pour être utilisé en attribut HTML |
| 1387 | 1387 | **/ |
| 1388 | 1388 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1389 | - if ($texte === null) { |
|
| 1390 | - return ''; |
|
| 1391 | - } |
|
| 1392 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | - if ($textebrut) { |
|
| 1394 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | - } |
|
| 1396 | - $texte = texte_backend($texte); |
|
| 1397 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1389 | + if ($texte === null) { |
|
| 1390 | + return ''; |
|
| 1391 | + } |
|
| 1392 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | + if ($textebrut) { |
|
| 1394 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | + } |
|
| 1396 | + $texte = texte_backend($texte); |
|
| 1397 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1398 | 1398 | |
| 1399 | - return preg_replace( |
|
| 1400 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | - ['&', '&'], |
|
| 1402 | - $texte |
|
| 1403 | - ); |
|
| 1399 | + return preg_replace( |
|
| 1400 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | + ['&', '&'], |
|
| 1402 | + $texte |
|
| 1403 | + ); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | |
@@ -1420,15 +1420,15 @@ discard block |
||
| 1420 | 1420 | * URL ou chaîne vide |
| 1421 | 1421 | **/ |
| 1422 | 1422 | function vider_url(?string $url, $entites = true): string { |
| 1423 | - if ($url === null) { |
|
| 1424 | - return ''; |
|
| 1425 | - } |
|
| 1426 | - # un message pour abs_url |
|
| 1427 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | - $url = trim($url); |
|
| 1429 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1423 | + if ($url === null) { |
|
| 1424 | + return ''; |
|
| 1425 | + } |
|
| 1426 | + # un message pour abs_url |
|
| 1427 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | + $url = trim($url); |
|
| 1429 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1430 | 1430 | |
| 1431 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1431 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | |
@@ -1443,10 +1443,10 @@ discard block |
||
| 1443 | 1443 | * @return string Adresse email maquillée |
| 1444 | 1444 | **/ |
| 1445 | 1445 | function antispam($texte) { |
| 1446 | - include_spip('inc/acces'); |
|
| 1447 | - $masque = creer_pass_aleatoire(3); |
|
| 1446 | + include_spip('inc/acces'); |
|
| 1447 | + $masque = creer_pass_aleatoire(3); |
|
| 1448 | 1448 | |
| 1449 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1449 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1478,8 +1478,8 @@ discard block |
||
| 1478 | 1478 | * True si on a le droit d'accès, false sinon. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1481 | - include_spip('inc/acces'); |
|
| 1482 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1481 | + include_spip('inc/acces'); |
|
| 1482 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1504,13 +1504,13 @@ discard block |
||
| 1504 | 1504 | * Retourne $texte, sinon $sinon. |
| 1505 | 1505 | **/ |
| 1506 | 1506 | function sinon($texte, $sinon = '') { |
| 1507 | - if ($texte) { |
|
| 1508 | - return $texte; |
|
| 1509 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | - return $texte; |
|
| 1511 | - } else { |
|
| 1512 | - return $sinon; |
|
| 1513 | - } |
|
| 1507 | + if ($texte) { |
|
| 1508 | + return $texte; |
|
| 1509 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | + return $texte; |
|
| 1511 | + } else { |
|
| 1512 | + return $sinon; |
|
| 1513 | + } |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | /** |
@@ -1534,7 +1534,7 @@ discard block |
||
| 1534 | 1534 | * @return mixed |
| 1535 | 1535 | **/ |
| 1536 | 1536 | function choixsivide($a, $vide, $pasvide) { |
| 1537 | - return $a ? $pasvide : $vide; |
|
| 1537 | + return $a ? $pasvide : $vide; |
|
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | /** |
@@ -1558,7 +1558,7 @@ discard block |
||
| 1558 | 1558 | * @return mixed |
| 1559 | 1559 | **/ |
| 1560 | 1560 | function choixsiegal($a1, $a2, $v, $f) { |
| 1561 | - return ($a1 == $a2) ? $v : $f; |
|
| 1561 | + return ($a1 == $a2) ? $v : $f; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | // |
@@ -1577,13 +1577,13 @@ discard block |
||
| 1577 | 1577 | * @return string |
| 1578 | 1578 | **/ |
| 1579 | 1579 | function filtrer_ical($texte) { |
| 1580 | - #include_spip('inc/charsets'); |
|
| 1581 | - $texte = html2unicode($texte); |
|
| 1582 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1580 | + #include_spip('inc/charsets'); |
|
| 1581 | + $texte = html2unicode($texte); |
|
| 1582 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1585 | 1585 | |
| 1586 | - return $texte; |
|
| 1586 | + return $texte; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | |
@@ -1608,54 +1608,54 @@ discard block |
||
| 1608 | 1608 | * @return string |
| 1609 | 1609 | **/ |
| 1610 | 1610 | function post_autobr($texte, $delim = "\n_ ") { |
| 1611 | - if (!function_exists('echappe_html')) { |
|
| 1612 | - include_spip('inc/texte_mini'); |
|
| 1613 | - } |
|
| 1614 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | - |
|
| 1617 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | - } else { |
|
| 1620 | - $fin = ''; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - $texte = echappe_html($texte, '', true); |
|
| 1624 | - |
|
| 1625 | - // echapper les modeles |
|
| 1626 | - if (strpos($texte, '<') !== false) { |
|
| 1627 | - include_spip('inc/lien'); |
|
| 1628 | - if (defined('_PREG_MODELE')) { |
|
| 1629 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | - } |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - $debut = ''; |
|
| 1635 | - $suite = $texte; |
|
| 1636 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | - $suite = substr($suite, $t); |
|
| 1639 | - $car = substr($suite, 0, 1); |
|
| 1640 | - if ( |
|
| 1641 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | - ) { |
|
| 1645 | - $debut .= $delim; |
|
| 1646 | - } else { |
|
| 1647 | - $debut .= "\n"; |
|
| 1648 | - } |
|
| 1649 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | - $debut .= $regs[0]; |
|
| 1651 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - $texte = $debut . $suite; |
|
| 1655 | - |
|
| 1656 | - $texte = echappe_retour($texte); |
|
| 1657 | - |
|
| 1658 | - return $texte . $fin; |
|
| 1611 | + if (!function_exists('echappe_html')) { |
|
| 1612 | + include_spip('inc/texte_mini'); |
|
| 1613 | + } |
|
| 1614 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | + |
|
| 1617 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | + } else { |
|
| 1620 | + $fin = ''; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + $texte = echappe_html($texte, '', true); |
|
| 1624 | + |
|
| 1625 | + // echapper les modeles |
|
| 1626 | + if (strpos($texte, '<') !== false) { |
|
| 1627 | + include_spip('inc/lien'); |
|
| 1628 | + if (defined('_PREG_MODELE')) { |
|
| 1629 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | + } |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + $debut = ''; |
|
| 1635 | + $suite = $texte; |
|
| 1636 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | + $suite = substr($suite, $t); |
|
| 1639 | + $car = substr($suite, 0, 1); |
|
| 1640 | + if ( |
|
| 1641 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | + ) { |
|
| 1645 | + $debut .= $delim; |
|
| 1646 | + } else { |
|
| 1647 | + $debut .= "\n"; |
|
| 1648 | + } |
|
| 1649 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | + $debut .= $regs[0]; |
|
| 1651 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + $texte = $debut . $suite; |
|
| 1655 | + |
|
| 1656 | + $texte = echappe_retour($texte); |
|
| 1657 | + |
|
| 1658 | + return $texte . $fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1696,47 +1696,47 @@ discard block |
||
| 1696 | 1696 | * @return string |
| 1697 | 1697 | **/ |
| 1698 | 1698 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1699 | - static $traduire = false; |
|
| 1700 | - if ( |
|
| 1701 | - $letexte |
|
| 1702 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | - ) { |
|
| 1704 | - if (!$traduire) { |
|
| 1705 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | - include_spip('inc/lang'); |
|
| 1707 | - } |
|
| 1708 | - if (!$lang) { |
|
| 1709 | - $lang = $GLOBALS['spip_lang']; |
|
| 1710 | - } |
|
| 1711 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | - if (is_bool($options)) { |
|
| 1713 | - $options = ['echappe_span' => $options]; |
|
| 1714 | - } |
|
| 1715 | - if (!isset($options['echappe_span'])) { |
|
| 1716 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - foreach ($regs as $reg) { |
|
| 1720 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | - $desc = $traduire($cle, $lang, true); |
|
| 1722 | - $l = $desc->langue; |
|
| 1723 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | - if (strlen($desc->texte)) { |
|
| 1725 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | - if ($l !== $lang) { |
|
| 1727 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | - } |
|
| 1729 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | - } |
|
| 1732 | - if (!$options['echappe_span']) { |
|
| 1733 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | - } |
|
| 1735 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - return $letexte; |
|
| 1699 | + static $traduire = false; |
|
| 1700 | + if ( |
|
| 1701 | + $letexte |
|
| 1702 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | + ) { |
|
| 1704 | + if (!$traduire) { |
|
| 1705 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | + include_spip('inc/lang'); |
|
| 1707 | + } |
|
| 1708 | + if (!$lang) { |
|
| 1709 | + $lang = $GLOBALS['spip_lang']; |
|
| 1710 | + } |
|
| 1711 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | + if (is_bool($options)) { |
|
| 1713 | + $options = ['echappe_span' => $options]; |
|
| 1714 | + } |
|
| 1715 | + if (!isset($options['echappe_span'])) { |
|
| 1716 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + foreach ($regs as $reg) { |
|
| 1720 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | + $desc = $traduire($cle, $lang, true); |
|
| 1722 | + $l = $desc->langue; |
|
| 1723 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | + if (strlen($desc->texte)) { |
|
| 1725 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | + if ($l !== $lang) { |
|
| 1727 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | + } |
|
| 1729 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | + } |
|
| 1732 | + if (!$options['echappe_span']) { |
|
| 1733 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | + } |
|
| 1735 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + return $letexte; |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | /** |
@@ -1788,68 +1788,68 @@ discard block |
||
| 1788 | 1788 | **/ |
| 1789 | 1789 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1790 | 1790 | |
| 1791 | - if ( |
|
| 1792 | - $letexte |
|
| 1793 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | - ) { |
|
| 1795 | - if (!$lang) { |
|
| 1796 | - $lang = $GLOBALS['spip_lang']; |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | - if (is_bool($options)) { |
|
| 1801 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | - } |
|
| 1803 | - if (!isset($options['echappe_span'])) { |
|
| 1804 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | - } |
|
| 1806 | - if (!isset($options['lang_defaut'])) { |
|
| 1807 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - include_spip('inc/lang'); |
|
| 1811 | - foreach ($regs as $reg) { |
|
| 1812 | - // chercher la version de la langue courante |
|
| 1813 | - $trads = extraire_trads($reg[1]); |
|
| 1814 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | - $trad = $trads[$l]; |
|
| 1816 | - } else { |
|
| 1817 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | - $trad = ''; |
|
| 1819 | - } else { |
|
| 1820 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | - // ou la premiere dispo |
|
| 1822 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | - $l = key($trads); |
|
| 1826 | - } |
|
| 1827 | - $trad = $trads[$l]; |
|
| 1828 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | - $trad = $typographie($trad); |
|
| 1830 | - // Tester si on echappe en span ou en div |
|
| 1831 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | - include_spip('inc/texte'); |
|
| 1833 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | - if ($mode === 'div') { |
|
| 1836 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | - } |
|
| 1838 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | - } |
|
| 1843 | - if (!$options['echappe_span']) { |
|
| 1844 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | - } |
|
| 1846 | - } |
|
| 1847 | - } |
|
| 1848 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | - } |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - return $letexte; |
|
| 1791 | + if ( |
|
| 1792 | + $letexte |
|
| 1793 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | + ) { |
|
| 1795 | + if (!$lang) { |
|
| 1796 | + $lang = $GLOBALS['spip_lang']; |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | + if (is_bool($options)) { |
|
| 1801 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | + } |
|
| 1803 | + if (!isset($options['echappe_span'])) { |
|
| 1804 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | + } |
|
| 1806 | + if (!isset($options['lang_defaut'])) { |
|
| 1807 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + include_spip('inc/lang'); |
|
| 1811 | + foreach ($regs as $reg) { |
|
| 1812 | + // chercher la version de la langue courante |
|
| 1813 | + $trads = extraire_trads($reg[1]); |
|
| 1814 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | + $trad = $trads[$l]; |
|
| 1816 | + } else { |
|
| 1817 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | + $trad = ''; |
|
| 1819 | + } else { |
|
| 1820 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | + // ou la premiere dispo |
|
| 1822 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | + $l = key($trads); |
|
| 1826 | + } |
|
| 1827 | + $trad = $trads[$l]; |
|
| 1828 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | + $trad = $typographie($trad); |
|
| 1830 | + // Tester si on echappe en span ou en div |
|
| 1831 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | + include_spip('inc/texte'); |
|
| 1833 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | + if ($mode === 'div') { |
|
| 1836 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | + } |
|
| 1838 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | + } |
|
| 1843 | + if (!$options['echappe_span']) { |
|
| 1844 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | + } |
|
| 1846 | + } |
|
| 1847 | + } |
|
| 1848 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | + } |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + return $letexte; |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | /** |
@@ -1865,21 +1865,21 @@ discard block |
||
| 1865 | 1865 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function extraire_trads($bloc) { |
| 1868 | - $trads = []; |
|
| 1869 | - $lang = ''; |
|
| 1868 | + $trads = []; |
|
| 1869 | + $lang = ''; |
|
| 1870 | 1870 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1871 | 1871 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1872 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | - $texte = trim($regs[1]); |
|
| 1874 | - if ($texte or $lang) { |
|
| 1875 | - $trads[$lang] = $texte; |
|
| 1876 | - } |
|
| 1877 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | - $lang = $regs[2]; |
|
| 1879 | - } |
|
| 1880 | - $trads[$lang] = $bloc; |
|
| 1872 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | + $texte = trim($regs[1]); |
|
| 1874 | + if ($texte or $lang) { |
|
| 1875 | + $trads[$lang] = $texte; |
|
| 1876 | + } |
|
| 1877 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | + $lang = $regs[2]; |
|
| 1879 | + } |
|
| 1880 | + $trads[$lang] = $bloc; |
|
| 1881 | 1881 | |
| 1882 | - return $trads; |
|
| 1882 | + return $trads; |
|
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | * @return string L'initiale en majuscule |
| 1891 | 1891 | */ |
| 1892 | 1892 | function filtre_initiale($nom) { |
| 1893 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1893 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | |
@@ -1935,33 +1935,33 @@ discard block |
||
| 1935 | 1935 | * - null (interne) : si on empile |
| 1936 | 1936 | **/ |
| 1937 | 1937 | function unique($donnee, $famille = '', $cpt = false) { |
| 1938 | - static $mem = []; |
|
| 1939 | - // permettre de vider la pile et de la restaurer |
|
| 1940 | - // pour le calcul de introduction... |
|
| 1941 | - if ($famille == '_spip_raz_') { |
|
| 1942 | - $tmp = $mem; |
|
| 1943 | - $mem = []; |
|
| 1944 | - |
|
| 1945 | - return $tmp; |
|
| 1946 | - } elseif ($famille == '_spip_set_') { |
|
| 1947 | - $mem = $donnee; |
|
| 1948 | - |
|
| 1949 | - return; |
|
| 1950 | - } |
|
| 1951 | - // eviter une notice |
|
| 1952 | - if (!isset($mem[$famille])) { |
|
| 1953 | - $mem[$famille] = []; |
|
| 1954 | - } |
|
| 1955 | - if ($cpt) { |
|
| 1956 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | - } |
|
| 1958 | - // eviter une notice |
|
| 1959 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | - $mem[$famille][$donnee] = 0; |
|
| 1961 | - } |
|
| 1962 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | - return $donnee; |
|
| 1964 | - } |
|
| 1938 | + static $mem = []; |
|
| 1939 | + // permettre de vider la pile et de la restaurer |
|
| 1940 | + // pour le calcul de introduction... |
|
| 1941 | + if ($famille == '_spip_raz_') { |
|
| 1942 | + $tmp = $mem; |
|
| 1943 | + $mem = []; |
|
| 1944 | + |
|
| 1945 | + return $tmp; |
|
| 1946 | + } elseif ($famille == '_spip_set_') { |
|
| 1947 | + $mem = $donnee; |
|
| 1948 | + |
|
| 1949 | + return; |
|
| 1950 | + } |
|
| 1951 | + // eviter une notice |
|
| 1952 | + if (!isset($mem[$famille])) { |
|
| 1953 | + $mem[$famille] = []; |
|
| 1954 | + } |
|
| 1955 | + if ($cpt) { |
|
| 1956 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | + } |
|
| 1958 | + // eviter une notice |
|
| 1959 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | + $mem[$famille][$donnee] = 0; |
|
| 1961 | + } |
|
| 1962 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | + return $donnee; |
|
| 1964 | + } |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | |
@@ -1991,16 +1991,16 @@ discard block |
||
| 1991 | 1991 | * Une des valeurs en fonction du compteur. |
| 1992 | 1992 | **/ |
| 1993 | 1993 | function alterner($i, ...$args) { |
| 1994 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | - $num = count($args); |
|
| 1994 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | + $num = count($args); |
|
| 1996 | 1996 | |
| 1997 | - if ($num === 1 && is_array($args[0])) { |
|
| 1998 | - $args = $args[0]; |
|
| 1999 | - $num = count($args); |
|
| 2000 | - } |
|
| 1997 | + if ($num === 1 && is_array($args[0])) { |
|
| 1998 | + $args = $args[0]; |
|
| 1999 | + $num = count($args); |
|
| 2000 | + } |
|
| 2001 | 2001 | |
| 2002 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2003 | - return $args[(intval($i) - 1) % $num]; |
|
| 2002 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2003 | + return $args[(intval($i) - 1) % $num]; |
|
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | 2006 | |
@@ -2026,51 +2026,51 @@ discard block |
||
| 2026 | 2026 | * - null lorsque l’attribut n’existe pas. |
| 2027 | 2027 | **/ |
| 2028 | 2028 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 2029 | - if (is_array($balise)) { |
|
| 2030 | - array_walk( |
|
| 2031 | - $balise, |
|
| 2032 | - function (&$a, $key, $t) { |
|
| 2033 | - $a = extraire_attribut($a, $t); |
|
| 2034 | - }, |
|
| 2035 | - $attribut |
|
| 2036 | - ); |
|
| 2037 | - |
|
| 2038 | - return $balise; |
|
| 2039 | - } |
|
| 2040 | - if ( |
|
| 2041 | - $balise |
|
| 2042 | - && preg_match( |
|
| 2043 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2044 | - . $attribut |
|
| 2045 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2046 | - $balise, |
|
| 2047 | - $r |
|
| 2048 | - ) |
|
| 2049 | - ) { |
|
| 2050 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2051 | - $r[4] = substr($r[3], 1, -1); |
|
| 2052 | - $r[3] = $r[3][0]; |
|
| 2053 | - } elseif ($r[3] !== '') { |
|
| 2054 | - $r[4] = $r[3]; |
|
| 2055 | - $r[3] = ''; |
|
| 2056 | - } else { |
|
| 2057 | - $r[4] = trim($r[2]); |
|
| 2058 | - } |
|
| 2059 | - $att = $r[4]; |
|
| 2060 | - if (strpos($att, '&#') !== false) { |
|
| 2061 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2062 | - } |
|
| 2063 | - $att = filtrer_entites($att); |
|
| 2064 | - } else { |
|
| 2065 | - $att = null; |
|
| 2066 | - $r = []; |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - if ($complet) { |
|
| 2070 | - return [$att, $r]; |
|
| 2071 | - } else { |
|
| 2072 | - return $att; |
|
| 2073 | - } |
|
| 2029 | + if (is_array($balise)) { |
|
| 2030 | + array_walk( |
|
| 2031 | + $balise, |
|
| 2032 | + function (&$a, $key, $t) { |
|
| 2033 | + $a = extraire_attribut($a, $t); |
|
| 2034 | + }, |
|
| 2035 | + $attribut |
|
| 2036 | + ); |
|
| 2037 | + |
|
| 2038 | + return $balise; |
|
| 2039 | + } |
|
| 2040 | + if ( |
|
| 2041 | + $balise |
|
| 2042 | + && preg_match( |
|
| 2043 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2044 | + . $attribut |
|
| 2045 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2046 | + $balise, |
|
| 2047 | + $r |
|
| 2048 | + ) |
|
| 2049 | + ) { |
|
| 2050 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2051 | + $r[4] = substr($r[3], 1, -1); |
|
| 2052 | + $r[3] = $r[3][0]; |
|
| 2053 | + } elseif ($r[3] !== '') { |
|
| 2054 | + $r[4] = $r[3]; |
|
| 2055 | + $r[3] = ''; |
|
| 2056 | + } else { |
|
| 2057 | + $r[4] = trim($r[2]); |
|
| 2058 | + } |
|
| 2059 | + $att = $r[4]; |
|
| 2060 | + if (strpos($att, '&#') !== false) { |
|
| 2061 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2062 | + } |
|
| 2063 | + $att = filtrer_entites($att); |
|
| 2064 | + } else { |
|
| 2065 | + $att = null; |
|
| 2066 | + $r = []; |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + if ($complet) { |
|
| 2070 | + return [$att, $r]; |
|
| 2071 | + } else { |
|
| 2072 | + return $att; |
|
| 2073 | + } |
|
| 2074 | 2074 | } |
| 2075 | 2075 | |
| 2076 | 2076 | /** |
@@ -2103,41 +2103,41 @@ discard block |
||
| 2103 | 2103 | **/ |
| 2104 | 2104 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2105 | 2105 | |
| 2106 | - if ($balise === null or $balise === '') { |
|
| 2107 | - return ''; |
|
| 2108 | - } |
|
| 2106 | + if ($balise === null or $balise === '') { |
|
| 2107 | + return ''; |
|
| 2108 | + } |
|
| 2109 | 2109 | |
| 2110 | - // preparer l'attribut |
|
| 2111 | - // supprimer les etc mais pas les balises html |
|
| 2112 | - // qui ont un sens dans un attribut value d'un input |
|
| 2113 | - if ($proteger) { |
|
| 2114 | - $val = attribut_html($val, false); |
|
| 2115 | - } |
|
| 2110 | + // preparer l'attribut |
|
| 2111 | + // supprimer les etc mais pas les balises html |
|
| 2112 | + // qui ont un sens dans un attribut value d'un input |
|
| 2113 | + if ($proteger) { |
|
| 2114 | + $val = attribut_html($val, false); |
|
| 2115 | + } |
|
| 2116 | 2116 | |
| 2117 | - // echapper les ' pour eviter tout bug |
|
| 2118 | - $val = str_replace("'", ''', $val); |
|
| 2119 | - if ($vider and strlen($val) === 0) { |
|
| 2120 | - $insert = ''; |
|
| 2121 | - } else { |
|
| 2122 | - $insert = " $attribut='$val'"; |
|
| 2123 | - } |
|
| 2117 | + // echapper les ' pour eviter tout bug |
|
| 2118 | + $val = str_replace("'", ''', $val); |
|
| 2119 | + if ($vider and strlen($val) === 0) { |
|
| 2120 | + $insert = ''; |
|
| 2121 | + } else { |
|
| 2122 | + $insert = " $attribut='$val'"; |
|
| 2123 | + } |
|
| 2124 | 2124 | |
| 2125 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2125 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2126 | 2126 | |
| 2127 | - if ($old !== null) { |
|
| 2128 | - // Remplacer l'ancien attribut du meme nom |
|
| 2129 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2130 | - } else { |
|
| 2131 | - // preferer une balise " />" (comme <img />) |
|
| 2132 | - if (preg_match(',/>,', $balise)) { |
|
| 2133 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2134 | - } // sinon une balise <a ...> ... </a> |
|
| 2135 | - else { |
|
| 2136 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2137 | - } |
|
| 2138 | - } |
|
| 2127 | + if ($old !== null) { |
|
| 2128 | + // Remplacer l'ancien attribut du meme nom |
|
| 2129 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2130 | + } else { |
|
| 2131 | + // preferer une balise " />" (comme <img />) |
|
| 2132 | + if (preg_match(',/>,', $balise)) { |
|
| 2133 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2134 | + } // sinon une balise <a ...> ... </a> |
|
| 2135 | + else { |
|
| 2136 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2137 | + } |
|
| 2138 | + } |
|
| 2139 | 2139 | |
| 2140 | - return $balise; |
|
| 2140 | + return $balise; |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | /** |
@@ -2155,7 +2155,7 @@ discard block |
||
| 2155 | 2155 | * @return string Code HTML sans l'attribut |
| 2156 | 2156 | **/ |
| 2157 | 2157 | function vider_attribut(?string $balise, string $attribut): string { |
| 2158 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2158 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2167,53 +2167,53 @@ discard block |
||
| 2167 | 2167 | * @return string |
| 2168 | 2168 | */ |
| 2169 | 2169 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2170 | - if (is_string($class)) { |
|
| 2171 | - $class = explode(' ', trim($class)); |
|
| 2172 | - } |
|
| 2173 | - $class = array_filter($class); |
|
| 2174 | - $class = array_unique($class); |
|
| 2175 | - if (!$class) { |
|
| 2176 | - return $balise; |
|
| 2177 | - } |
|
| 2178 | - |
|
| 2179 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2180 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2181 | - return $balise; |
|
| 2182 | - } |
|
| 2183 | - |
|
| 2184 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2185 | - $class_new = $class_courante; |
|
| 2186 | - foreach ($class as $c) { |
|
| 2187 | - $is_class_presente = false; |
|
| 2188 | - if ( |
|
| 2189 | - $class_courante |
|
| 2190 | - and strpos($class_courante, (string) $c) !== false |
|
| 2191 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2192 | - ) { |
|
| 2193 | - $is_class_presente = true; |
|
| 2194 | - } |
|
| 2195 | - if ( |
|
| 2196 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2197 | - and !$is_class_presente |
|
| 2198 | - ) { |
|
| 2199 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2200 | - } elseif ( |
|
| 2201 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2202 | - and $is_class_presente |
|
| 2203 | - ) { |
|
| 2204 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2205 | - } |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - if ($class_new !== $class_courante) { |
|
| 2209 | - if (strlen($class_new)) { |
|
| 2210 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2211 | - } elseif ($class_courante) { |
|
| 2212 | - $balise = vider_attribut($balise, 'class'); |
|
| 2213 | - } |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - return $balise; |
|
| 2170 | + if (is_string($class)) { |
|
| 2171 | + $class = explode(' ', trim($class)); |
|
| 2172 | + } |
|
| 2173 | + $class = array_filter($class); |
|
| 2174 | + $class = array_unique($class); |
|
| 2175 | + if (!$class) { |
|
| 2176 | + return $balise; |
|
| 2177 | + } |
|
| 2178 | + |
|
| 2179 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2180 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2181 | + return $balise; |
|
| 2182 | + } |
|
| 2183 | + |
|
| 2184 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2185 | + $class_new = $class_courante; |
|
| 2186 | + foreach ($class as $c) { |
|
| 2187 | + $is_class_presente = false; |
|
| 2188 | + if ( |
|
| 2189 | + $class_courante |
|
| 2190 | + and strpos($class_courante, (string) $c) !== false |
|
| 2191 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2192 | + ) { |
|
| 2193 | + $is_class_presente = true; |
|
| 2194 | + } |
|
| 2195 | + if ( |
|
| 2196 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2197 | + and !$is_class_presente |
|
| 2198 | + ) { |
|
| 2199 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2200 | + } elseif ( |
|
| 2201 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2202 | + and $is_class_presente |
|
| 2203 | + ) { |
|
| 2204 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2205 | + } |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + if ($class_new !== $class_courante) { |
|
| 2209 | + if (strlen($class_new)) { |
|
| 2210 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2211 | + } elseif ($class_courante) { |
|
| 2212 | + $balise = vider_attribut($balise, 'class'); |
|
| 2213 | + } |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + return $balise; |
|
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | 2219 | /** |
@@ -2223,7 +2223,7 @@ discard block |
||
| 2223 | 2223 | * @return string |
| 2224 | 2224 | */ |
| 2225 | 2225 | function ajouter_class($balise, $class) { |
| 2226 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2226 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | 2229 | /** |
@@ -2233,7 +2233,7 @@ discard block |
||
| 2233 | 2233 | * @return string |
| 2234 | 2234 | */ |
| 2235 | 2235 | function supprimer_class($balise, $class) { |
| 2236 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2236 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2237 | 2237 | } |
| 2238 | 2238 | |
| 2239 | 2239 | /** |
@@ -2244,7 +2244,7 @@ discard block |
||
| 2244 | 2244 | * @return string |
| 2245 | 2245 | */ |
| 2246 | 2246 | function commuter_class($balise, $class) { |
| 2247 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2247 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2248 | 2248 | } |
| 2249 | 2249 | |
| 2250 | 2250 | /** |
@@ -2255,19 +2255,19 @@ discard block |
||
| 2255 | 2255 | * @return string |
| 2256 | 2256 | */ |
| 2257 | 2257 | function tester_config($id, $mode = '') { |
| 2258 | - include_spip('action/inscrire_auteur'); |
|
| 2258 | + include_spip('action/inscrire_auteur'); |
|
| 2259 | 2259 | |
| 2260 | - return tester_statut_inscription($mode, $id); |
|
| 2260 | + return tester_statut_inscription($mode, $id); |
|
| 2261 | 2261 | } |
| 2262 | 2262 | |
| 2263 | 2263 | // |
| 2264 | 2264 | // Quelques fonctions de calcul arithmetique |
| 2265 | 2265 | // |
| 2266 | 2266 | function floatstr($a) { |
| 2267 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2267 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2268 | 2268 | } |
| 2269 | 2269 | function strize($f, $a, $b) { |
| 2270 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2270 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | /** |
@@ -2286,7 +2286,7 @@ discard block |
||
| 2286 | 2286 | * @return int $a+$b |
| 2287 | 2287 | **/ |
| 2288 | 2288 | function plus($a, $b) { |
| 2289 | - return $a + $b; |
|
| 2289 | + return $a + $b; |
|
| 2290 | 2290 | } |
| 2291 | 2291 | function strplus($a, $b) { |
| 2292 | 2292 | return strize('plus', $a, $b); |
@@ -2307,7 +2307,7 @@ discard block |
||
| 2307 | 2307 | * @return int $a-$b |
| 2308 | 2308 | **/ |
| 2309 | 2309 | function moins($a, $b) { |
| 2310 | - return $a - $b; |
|
| 2310 | + return $a - $b; |
|
| 2311 | 2311 | } |
| 2312 | 2312 | function strmoins($a, $b) { |
| 2313 | 2313 | return strize('moins', $a, $b); |
@@ -2330,7 +2330,7 @@ discard block |
||
| 2330 | 2330 | * @return int $a*$b |
| 2331 | 2331 | **/ |
| 2332 | 2332 | function mult($a, $b) { |
| 2333 | - return $a * $b; |
|
| 2333 | + return $a * $b; |
|
| 2334 | 2334 | } |
| 2335 | 2335 | function strmult($a, $b) { |
| 2336 | 2336 | return strize('mult', $a, $b); |
@@ -2353,7 +2353,7 @@ discard block |
||
| 2353 | 2353 | * @return int $a/$b (ou 0 si $b est nul) |
| 2354 | 2354 | **/ |
| 2355 | 2355 | function div($a, $b) { |
| 2356 | - return $b ? $a / $b : 0; |
|
| 2356 | + return $b ? $a / $b : 0; |
|
| 2357 | 2357 | } |
| 2358 | 2358 | function strdiv($a, $b) { |
| 2359 | 2359 | return strize('div', $a, $b); |
@@ -2377,7 +2377,7 @@ discard block |
||
| 2377 | 2377 | * @return int ($nb % $mod) + $add |
| 2378 | 2378 | **/ |
| 2379 | 2379 | function modulo($nb, $mod, $add = 0) { |
| 2380 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2380 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2381 | 2381 | } |
| 2382 | 2382 | |
| 2383 | 2383 | |
@@ -2392,26 +2392,26 @@ discard block |
||
| 2392 | 2392 | * - true sinon |
| 2393 | 2393 | **/ |
| 2394 | 2394 | function nom_acceptable($nom) { |
| 2395 | - $remp2 = []; |
|
| 2396 | - $remp1 = []; |
|
| 2397 | - if (!is_string($nom)) { |
|
| 2398 | - return false; |
|
| 2399 | - } |
|
| 2400 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2401 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2402 | - } |
|
| 2403 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2404 | - foreach ($tags_acceptes as $tag) { |
|
| 2405 | - if (strlen($tag)) { |
|
| 2406 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2407 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2408 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2409 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2410 | - } |
|
| 2411 | - } |
|
| 2412 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2413 | - |
|
| 2414 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2395 | + $remp2 = []; |
|
| 2396 | + $remp1 = []; |
|
| 2397 | + if (!is_string($nom)) { |
|
| 2398 | + return false; |
|
| 2399 | + } |
|
| 2400 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2401 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2402 | + } |
|
| 2403 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2404 | + foreach ($tags_acceptes as $tag) { |
|
| 2405 | + if (strlen($tag)) { |
|
| 2406 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2407 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2408 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2409 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2410 | + } |
|
| 2411 | + } |
|
| 2412 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2413 | + |
|
| 2414 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2415 | 2415 | } |
| 2416 | 2416 | |
| 2417 | 2417 | |
@@ -2427,14 +2427,14 @@ discard block |
||
| 2427 | 2427 | * - renvoie un tableau si l'entree est un tableau |
| 2428 | 2428 | **/ |
| 2429 | 2429 | function email_valide($adresses) { |
| 2430 | - if (is_array($adresses)) { |
|
| 2431 | - $adresses = array_map('email_valide', $adresses); |
|
| 2432 | - $adresses = array_filter($adresses); |
|
| 2433 | - return $adresses; |
|
| 2434 | - } |
|
| 2430 | + if (is_array($adresses)) { |
|
| 2431 | + $adresses = array_map('email_valide', $adresses); |
|
| 2432 | + $adresses = array_filter($adresses); |
|
| 2433 | + return $adresses; |
|
| 2434 | + } |
|
| 2435 | 2435 | |
| 2436 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2437 | - return $email_valide($adresses); |
|
| 2436 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2437 | + return $email_valide($adresses); |
|
| 2438 | 2438 | } |
| 2439 | 2439 | |
| 2440 | 2440 | /** |
@@ -2448,27 +2448,27 @@ discard block |
||
| 2448 | 2448 | * @return string Texte |
| 2449 | 2449 | **/ |
| 2450 | 2450 | function afficher_enclosures($tags) { |
| 2451 | - $s = []; |
|
| 2452 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2453 | - if ( |
|
| 2454 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2455 | - and $t = extraire_attribut($tag, 'href') |
|
| 2456 | - ) { |
|
| 2457 | - $s[] = preg_replace( |
|
| 2458 | - ',>[^<]+</a>,S', |
|
| 2459 | - '>' |
|
| 2460 | - . http_img_pack( |
|
| 2461 | - 'attachment-16.png', |
|
| 2462 | - $t, |
|
| 2463 | - 'title="' . attribut_html($t) . '"' |
|
| 2464 | - ) |
|
| 2465 | - . '</a>', |
|
| 2466 | - $tag |
|
| 2467 | - ); |
|
| 2468 | - } |
|
| 2469 | - } |
|
| 2470 | - |
|
| 2471 | - return join(' ', $s); |
|
| 2451 | + $s = []; |
|
| 2452 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2453 | + if ( |
|
| 2454 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2455 | + and $t = extraire_attribut($tag, 'href') |
|
| 2456 | + ) { |
|
| 2457 | + $s[] = preg_replace( |
|
| 2458 | + ',>[^<]+</a>,S', |
|
| 2459 | + '>' |
|
| 2460 | + . http_img_pack( |
|
| 2461 | + 'attachment-16.png', |
|
| 2462 | + $t, |
|
| 2463 | + 'title="' . attribut_html($t) . '"' |
|
| 2464 | + ) |
|
| 2465 | + . '</a>', |
|
| 2466 | + $tag |
|
| 2467 | + ); |
|
| 2468 | + } |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + return join(' ', $s); |
|
| 2472 | 2472 | } |
| 2473 | 2473 | |
| 2474 | 2474 | /** |
@@ -2483,15 +2483,15 @@ discard block |
||
| 2483 | 2483 | * @return string Liens trouvés |
| 2484 | 2484 | **/ |
| 2485 | 2485 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2486 | - $s = []; |
|
| 2487 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2488 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2489 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2490 | - $s[] = $tag; |
|
| 2491 | - } |
|
| 2492 | - } |
|
| 2486 | + $s = []; |
|
| 2487 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2488 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2489 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2490 | + $s[] = $tag; |
|
| 2491 | + } |
|
| 2492 | + } |
|
| 2493 | 2493 | |
| 2494 | - return join(', ', $s); |
|
| 2494 | + return join(', ', $s); |
|
| 2495 | 2495 | } |
| 2496 | 2496 | |
| 2497 | 2497 | |
@@ -2513,21 +2513,21 @@ discard block |
||
| 2513 | 2513 | * @return string Tag HTML `<a>` avec microformat. |
| 2514 | 2514 | **/ |
| 2515 | 2515 | function enclosure2microformat($e) { |
| 2516 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2517 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2518 | - } |
|
| 2519 | - $type = extraire_attribut($e, 'type'); |
|
| 2520 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2521 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2522 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2523 | - } |
|
| 2524 | - $fichier = basename($url); |
|
| 2516 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2517 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2518 | + } |
|
| 2519 | + $type = extraire_attribut($e, 'type'); |
|
| 2520 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2521 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2522 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2523 | + } |
|
| 2524 | + $fichier = basename($url); |
|
| 2525 | 2525 | |
| 2526 | - return '<a rel="enclosure"' |
|
| 2527 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2528 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2529 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2530 | - . '>' . $fichier . '</a>'; |
|
| 2526 | + return '<a rel="enclosure"' |
|
| 2527 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2528 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2529 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2530 | + . '>' . $fichier . '</a>'; |
|
| 2531 | 2531 | } |
| 2532 | 2532 | |
| 2533 | 2533 | /** |
@@ -2545,24 +2545,24 @@ discard block |
||
| 2545 | 2545 | * @return string Tags RSS `<enclosure>`. |
| 2546 | 2546 | **/ |
| 2547 | 2547 | function microformat2enclosure($tags) { |
| 2548 | - $enclosures = []; |
|
| 2549 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2550 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2551 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2552 | - $type = extraire_attribut($e, 'type'); |
|
| 2553 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2554 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2555 | - } # vieux data |
|
| 2556 | - $fichier = basename($url); |
|
| 2557 | - $enclosures[] = '<enclosure' |
|
| 2558 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2559 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2560 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2561 | - . ' />'; |
|
| 2562 | - } |
|
| 2563 | - } |
|
| 2548 | + $enclosures = []; |
|
| 2549 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2550 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2551 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2552 | + $type = extraire_attribut($e, 'type'); |
|
| 2553 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2554 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2555 | + } # vieux data |
|
| 2556 | + $fichier = basename($url); |
|
| 2557 | + $enclosures[] = '<enclosure' |
|
| 2558 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2559 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2560 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2561 | + . ' />'; |
|
| 2562 | + } |
|
| 2563 | + } |
|
| 2564 | 2564 | |
| 2565 | - return join("\n", $enclosures); |
|
| 2565 | + return join("\n", $enclosures); |
|
| 2566 | 2566 | } |
| 2567 | 2567 | |
| 2568 | 2568 | |
@@ -2578,16 +2578,16 @@ discard block |
||
| 2578 | 2578 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2579 | 2579 | **/ |
| 2580 | 2580 | function tags2dcsubject($tags) { |
| 2581 | - $subjects = ''; |
|
| 2582 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2583 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2584 | - $subjects .= '<dc:subject>' |
|
| 2585 | - . texte_backend(textebrut($e)) |
|
| 2586 | - . '</dc:subject>' . "\n"; |
|
| 2587 | - } |
|
| 2588 | - } |
|
| 2581 | + $subjects = ''; |
|
| 2582 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2583 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2584 | + $subjects .= '<dc:subject>' |
|
| 2585 | + . texte_backend(textebrut($e)) |
|
| 2586 | + . '</dc:subject>' . "\n"; |
|
| 2587 | + } |
|
| 2588 | + } |
|
| 2589 | 2589 | |
| 2590 | - return $subjects; |
|
| 2590 | + return $subjects; |
|
| 2591 | 2591 | } |
| 2592 | 2592 | |
| 2593 | 2593 | /** |
@@ -2616,27 +2616,27 @@ discard block |
||
| 2616 | 2616 | * - Tableau de résultats, si tableau en entrée. |
| 2617 | 2617 | **/ |
| 2618 | 2618 | function extraire_balise($texte, $tag = 'a') { |
| 2619 | - if (is_array($texte)) { |
|
| 2620 | - array_walk( |
|
| 2621 | - $texte, |
|
| 2622 | - function (&$a, $key, $t) { |
|
| 2623 | - $a = extraire_balise($a, $t); |
|
| 2624 | - }, |
|
| 2625 | - $tag |
|
| 2626 | - ); |
|
| 2627 | - |
|
| 2628 | - return $texte; |
|
| 2629 | - } |
|
| 2630 | - |
|
| 2631 | - if ( |
|
| 2632 | - preg_match( |
|
| 2633 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2634 | - $texte, |
|
| 2635 | - $regs |
|
| 2636 | - ) |
|
| 2637 | - ) { |
|
| 2638 | - return $regs[0]; |
|
| 2639 | - } |
|
| 2619 | + if (is_array($texte)) { |
|
| 2620 | + array_walk( |
|
| 2621 | + $texte, |
|
| 2622 | + function (&$a, $key, $t) { |
|
| 2623 | + $a = extraire_balise($a, $t); |
|
| 2624 | + }, |
|
| 2625 | + $tag |
|
| 2626 | + ); |
|
| 2627 | + |
|
| 2628 | + return $texte; |
|
| 2629 | + } |
|
| 2630 | + |
|
| 2631 | + if ( |
|
| 2632 | + preg_match( |
|
| 2633 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2634 | + $texte, |
|
| 2635 | + $regs |
|
| 2636 | + ) |
|
| 2637 | + ) { |
|
| 2638 | + return $regs[0]; |
|
| 2639 | + } |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | /** |
@@ -2664,30 +2664,30 @@ discard block |
||
| 2664 | 2664 | * - Tableau de résultats, si tableau en entrée. |
| 2665 | 2665 | **/ |
| 2666 | 2666 | function extraire_balises($texte, $tag = 'a') { |
| 2667 | - if (is_array($texte)) { |
|
| 2668 | - array_walk( |
|
| 2669 | - $texte, |
|
| 2670 | - function (&$a, $key, $t) { |
|
| 2671 | - $a = extraire_balises($a, $t); |
|
| 2672 | - }, |
|
| 2673 | - $tag |
|
| 2674 | - ); |
|
| 2675 | - |
|
| 2676 | - return $texte; |
|
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - if ( |
|
| 2680 | - preg_match_all( |
|
| 2681 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2682 | - $texte, |
|
| 2683 | - $regs, |
|
| 2684 | - PREG_PATTERN_ORDER |
|
| 2685 | - ) |
|
| 2686 | - ) { |
|
| 2687 | - return $regs[0]; |
|
| 2688 | - } else { |
|
| 2689 | - return []; |
|
| 2690 | - } |
|
| 2667 | + if (is_array($texte)) { |
|
| 2668 | + array_walk( |
|
| 2669 | + $texte, |
|
| 2670 | + function (&$a, $key, $t) { |
|
| 2671 | + $a = extraire_balises($a, $t); |
|
| 2672 | + }, |
|
| 2673 | + $tag |
|
| 2674 | + ); |
|
| 2675 | + |
|
| 2676 | + return $texte; |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + if ( |
|
| 2680 | + preg_match_all( |
|
| 2681 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2682 | + $texte, |
|
| 2683 | + $regs, |
|
| 2684 | + PREG_PATTERN_ORDER |
|
| 2685 | + ) |
|
| 2686 | + ) { |
|
| 2687 | + return $regs[0]; |
|
| 2688 | + } else { |
|
| 2689 | + return []; |
|
| 2690 | + } |
|
| 2691 | 2691 | } |
| 2692 | 2692 | |
| 2693 | 2693 | /** |
@@ -2716,11 +2716,11 @@ discard block |
||
| 2716 | 2716 | * - `$def` si on n'a pas transmis de tableau |
| 2717 | 2717 | **/ |
| 2718 | 2718 | function in_any($val, $vals, $def = '') { |
| 2719 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2720 | - $vals = $v; |
|
| 2721 | - } |
|
| 2719 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2720 | + $vals = $v; |
|
| 2721 | + } |
|
| 2722 | 2722 | |
| 2723 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2723 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2724 | 2724 | } |
| 2725 | 2725 | |
| 2726 | 2726 | |
@@ -2741,12 +2741,12 @@ discard block |
||
| 2741 | 2741 | * Résultat du calcul |
| 2742 | 2742 | **/ |
| 2743 | 2743 | function valeur_numerique($expr) { |
| 2744 | - $a = 0; |
|
| 2745 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2746 | - eval("\$a = $expr;"); |
|
| 2747 | - } |
|
| 2744 | + $a = 0; |
|
| 2745 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2746 | + eval("\$a = $expr;"); |
|
| 2747 | + } |
|
| 2748 | 2748 | |
| 2749 | - return intval($a); |
|
| 2749 | + return intval($a); |
|
| 2750 | 2750 | } |
| 2751 | 2751 | |
| 2752 | 2752 | /** |
@@ -2765,7 +2765,7 @@ discard block |
||
| 2765 | 2765 | * Retourne `$a*$b/$c` |
| 2766 | 2766 | **/ |
| 2767 | 2767 | function regledetrois($a, $b, $c) { |
| 2768 | - return round($a * $b / $c); |
|
| 2768 | + return round($a * $b / $c); |
|
| 2769 | 2769 | } |
| 2770 | 2770 | |
| 2771 | 2771 | |
@@ -2788,79 +2788,79 @@ discard block |
||
| 2788 | 2788 | * @return string Suite de champs input hidden |
| 2789 | 2789 | **/ |
| 2790 | 2790 | function form_hidden(?string $action = ''): string { |
| 2791 | - $action ??= ''; |
|
| 2792 | - |
|
| 2793 | - $contexte = []; |
|
| 2794 | - include_spip('inc/urls'); |
|
| 2795 | - if ( |
|
| 2796 | - $p = urls_decoder_url($action, '') |
|
| 2797 | - and reset($p) |
|
| 2798 | - ) { |
|
| 2799 | - $fond = array_shift($p); |
|
| 2800 | - if ($fond != '404') { |
|
| 2801 | - $contexte = array_shift($p); |
|
| 2802 | - $contexte['page'] = $fond; |
|
| 2803 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2804 | - } |
|
| 2805 | - } |
|
| 2806 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2807 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2808 | - unset($contexte['type']); |
|
| 2809 | - } |
|
| 2810 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2811 | - unset($contexte['type-page']); |
|
| 2812 | - } |
|
| 2813 | - |
|
| 2814 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2815 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2816 | - $values = []; |
|
| 2817 | - |
|
| 2818 | - // d'abord avec celles de l'url |
|
| 2819 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2820 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2821 | - $c = explode('=', $c, 2); |
|
| 2822 | - $var = array_shift($c); |
|
| 2823 | - $val = array_shift($c); |
|
| 2824 | - if ($var) { |
|
| 2825 | - $val = rawurldecode($val); |
|
| 2826 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2827 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2828 | - $values[] = [$var, $val]; |
|
| 2829 | - } else { |
|
| 2830 | - if (!isset($values[$var])) { |
|
| 2831 | - $values[$var] = [$var, $val]; |
|
| 2832 | - } |
|
| 2833 | - } |
|
| 2834 | - } |
|
| 2835 | - } |
|
| 2836 | - } |
|
| 2837 | - |
|
| 2838 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2839 | - foreach ($contexte as $var => $val) { |
|
| 2840 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2841 | - $values[] = [$var, $val]; |
|
| 2842 | - } else { |
|
| 2843 | - if (!isset($values[$var])) { |
|
| 2844 | - $values[$var] = [$var, $val]; |
|
| 2845 | - } |
|
| 2846 | - } |
|
| 2847 | - } |
|
| 2848 | - |
|
| 2849 | - // puis on rassemble le tout |
|
| 2850 | - $hidden = []; |
|
| 2851 | - foreach ($values as $value) { |
|
| 2852 | - [$var, $val] = $value; |
|
| 2853 | - $hidden[] = '<input name="' |
|
| 2854 | - . entites_html($var) |
|
| 2855 | - . '"' |
|
| 2856 | - . (is_null($val) |
|
| 2857 | - ? '' |
|
| 2858 | - : ' value="' . entites_html($val) . '"' |
|
| 2859 | - ) |
|
| 2860 | - . ' type="hidden"' . "\n/>"; |
|
| 2861 | - } |
|
| 2862 | - |
|
| 2863 | - return join('', $hidden); |
|
| 2791 | + $action ??= ''; |
|
| 2792 | + |
|
| 2793 | + $contexte = []; |
|
| 2794 | + include_spip('inc/urls'); |
|
| 2795 | + if ( |
|
| 2796 | + $p = urls_decoder_url($action, '') |
|
| 2797 | + and reset($p) |
|
| 2798 | + ) { |
|
| 2799 | + $fond = array_shift($p); |
|
| 2800 | + if ($fond != '404') { |
|
| 2801 | + $contexte = array_shift($p); |
|
| 2802 | + $contexte['page'] = $fond; |
|
| 2803 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2804 | + } |
|
| 2805 | + } |
|
| 2806 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2807 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2808 | + unset($contexte['type']); |
|
| 2809 | + } |
|
| 2810 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2811 | + unset($contexte['type-page']); |
|
| 2812 | + } |
|
| 2813 | + |
|
| 2814 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2815 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2816 | + $values = []; |
|
| 2817 | + |
|
| 2818 | + // d'abord avec celles de l'url |
|
| 2819 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2820 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2821 | + $c = explode('=', $c, 2); |
|
| 2822 | + $var = array_shift($c); |
|
| 2823 | + $val = array_shift($c); |
|
| 2824 | + if ($var) { |
|
| 2825 | + $val = rawurldecode($val); |
|
| 2826 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2827 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2828 | + $values[] = [$var, $val]; |
|
| 2829 | + } else { |
|
| 2830 | + if (!isset($values[$var])) { |
|
| 2831 | + $values[$var] = [$var, $val]; |
|
| 2832 | + } |
|
| 2833 | + } |
|
| 2834 | + } |
|
| 2835 | + } |
|
| 2836 | + } |
|
| 2837 | + |
|
| 2838 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2839 | + foreach ($contexte as $var => $val) { |
|
| 2840 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2841 | + $values[] = [$var, $val]; |
|
| 2842 | + } else { |
|
| 2843 | + if (!isset($values[$var])) { |
|
| 2844 | + $values[$var] = [$var, $val]; |
|
| 2845 | + } |
|
| 2846 | + } |
|
| 2847 | + } |
|
| 2848 | + |
|
| 2849 | + // puis on rassemble le tout |
|
| 2850 | + $hidden = []; |
|
| 2851 | + foreach ($values as $value) { |
|
| 2852 | + [$var, $val] = $value; |
|
| 2853 | + $hidden[] = '<input name="' |
|
| 2854 | + . entites_html($var) |
|
| 2855 | + . '"' |
|
| 2856 | + . (is_null($val) |
|
| 2857 | + ? '' |
|
| 2858 | + : ' value="' . entites_html($val) . '"' |
|
| 2859 | + ) |
|
| 2860 | + . ' type="hidden"' . "\n/>"; |
|
| 2861 | + } |
|
| 2862 | + |
|
| 2863 | + return join('', $hidden); |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | |
@@ -2882,7 +2882,7 @@ discard block |
||
| 2882 | 2882 | * - la première valeur du tableau sinon. |
| 2883 | 2883 | **/ |
| 2884 | 2884 | function filtre_reset($array) { |
| 2885 | - return !is_array($array) ? null : reset($array); |
|
| 2885 | + return !is_array($array) ? null : reset($array); |
|
| 2886 | 2886 | } |
| 2887 | 2887 | |
| 2888 | 2888 | /** |
@@ -2903,7 +2903,7 @@ discard block |
||
| 2903 | 2903 | * - la dernière valeur du tableau sinon. |
| 2904 | 2904 | **/ |
| 2905 | 2905 | function filtre_end($array) { |
| 2906 | - return !is_array($array) ? null : end($array); |
|
| 2906 | + return !is_array($array) ? null : end($array); |
|
| 2907 | 2907 | } |
| 2908 | 2908 | |
| 2909 | 2909 | /** |
@@ -2923,11 +2923,11 @@ discard block |
||
| 2923 | 2923 | * |
| 2924 | 2924 | **/ |
| 2925 | 2925 | function filtre_push($array, $val) { |
| 2926 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2927 | - return ''; |
|
| 2928 | - } |
|
| 2926 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2927 | + return ''; |
|
| 2928 | + } |
|
| 2929 | 2929 | |
| 2930 | - return $array; |
|
| 2930 | + return $array; |
|
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | /** |
@@ -2946,7 +2946,7 @@ discard block |
||
| 2946 | 2946 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2947 | 2947 | **/ |
| 2948 | 2948 | function filtre_find($array, $val) { |
| 2949 | - return (is_array($array) and in_array($val, $array)); |
|
| 2949 | + return (is_array($array) and in_array($val, $array)); |
|
| 2950 | 2950 | } |
| 2951 | 2951 | |
| 2952 | 2952 | |
@@ -2963,13 +2963,13 @@ discard block |
||
| 2963 | 2963 | * Contenu avec urls en absolus |
| 2964 | 2964 | **/ |
| 2965 | 2965 | function urls_absolues_css($contenu, $source) { |
| 2966 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2966 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2967 | 2967 | |
| 2968 | - return preg_replace_callback( |
|
| 2969 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2970 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2971 | - $contenu |
|
| 2972 | - ); |
|
| 2968 | + return preg_replace_callback( |
|
| 2969 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2970 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2971 | + $contenu |
|
| 2972 | + ); |
|
| 2973 | 2973 | } |
| 2974 | 2974 | |
| 2975 | 2975 | |
@@ -2998,119 +2998,119 @@ discard block |
||
| 2998 | 2998 | * Chemin du fichier CSS inversé |
| 2999 | 2999 | **/ |
| 3000 | 3000 | function direction_css($css, $voulue = '') { |
| 3001 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3002 | - return $css; |
|
| 3003 | - } |
|
| 3004 | - include_spip('inc/lang'); |
|
| 3005 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3006 | - if ($voulue = strtolower($voulue)) { |
|
| 3007 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3008 | - $voulue = lang_dir($voulue); |
|
| 3009 | - } |
|
| 3010 | - } else { |
|
| 3011 | - $voulue = lang_dir(); |
|
| 3012 | - } |
|
| 3013 | - |
|
| 3014 | - $r = count($r) > 1; |
|
| 3015 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3016 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 3017 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3018 | - |
|
| 3019 | - if ($voulue == $dir) { |
|
| 3020 | - return $css; |
|
| 3021 | - } |
|
| 3022 | - |
|
| 3023 | - if ( |
|
| 3024 | - // url absolue |
|
| 3025 | - preg_match(',^https?:,i', $css) |
|
| 3026 | - // ou qui contient un ? |
|
| 3027 | - or (($p = strpos($css, '?')) !== false) |
|
| 3028 | - ) { |
|
| 3029 | - $distant = true; |
|
| 3030 | - $cssf = parse_url($css); |
|
| 3031 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3032 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3033 | - } else { |
|
| 3034 | - $distant = false; |
|
| 3035 | - $cssf = $css; |
|
| 3036 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3037 | - //propose (rien a faire dans ce cas) |
|
| 3038 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3039 | - if (@file_exists($f)) { |
|
| 3040 | - return $f; |
|
| 3041 | - } |
|
| 3042 | - } |
|
| 3043 | - |
|
| 3044 | - // 2. |
|
| 3045 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3046 | - $f = $dir_var |
|
| 3047 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3048 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3049 | - |
|
| 3050 | - // la css peut etre distante (url absolue !) |
|
| 3051 | - if ($distant) { |
|
| 3052 | - include_spip('inc/distant'); |
|
| 3053 | - $res = recuperer_url($css); |
|
| 3054 | - if (!$res or !$contenu = $res['page']) { |
|
| 3055 | - return $css; |
|
| 3056 | - } |
|
| 3057 | - } else { |
|
| 3058 | - if ( |
|
| 3059 | - (@filemtime($f) > @filemtime($css)) |
|
| 3060 | - and (_VAR_MODE != 'recalcul') |
|
| 3061 | - ) { |
|
| 3062 | - return $f; |
|
| 3063 | - } |
|
| 3064 | - if (!lire_fichier($css, $contenu)) { |
|
| 3065 | - return $css; |
|
| 3066 | - } |
|
| 3067 | - } |
|
| 3068 | - |
|
| 3069 | - |
|
| 3070 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3071 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3072 | - $parser = new csstidy(); |
|
| 3073 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3074 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3075 | - $parser->parse($contenu); |
|
| 3076 | - |
|
| 3077 | - $contenu = $parser->print->plain(); |
|
| 3078 | - |
|
| 3079 | - |
|
| 3080 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3081 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3082 | - $src = []; |
|
| 3083 | - $src_direction_css = []; |
|
| 3084 | - $src_faux_abs = []; |
|
| 3085 | - $d = dirname($css); |
|
| 3086 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3087 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3088 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3089 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3090 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3091 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3092 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3093 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3094 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3095 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3096 | - } |
|
| 3097 | - $src[] = $regs[0][$k]; |
|
| 3098 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3099 | - } |
|
| 3100 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3101 | - |
|
| 3102 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3103 | - |
|
| 3104 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3105 | - if (count($src_faux_abs)) { |
|
| 3106 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3107 | - } |
|
| 3108 | - |
|
| 3109 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3110 | - return $css; |
|
| 3111 | - } |
|
| 3112 | - |
|
| 3113 | - return $f; |
|
| 3001 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3002 | + return $css; |
|
| 3003 | + } |
|
| 3004 | + include_spip('inc/lang'); |
|
| 3005 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3006 | + if ($voulue = strtolower($voulue)) { |
|
| 3007 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3008 | + $voulue = lang_dir($voulue); |
|
| 3009 | + } |
|
| 3010 | + } else { |
|
| 3011 | + $voulue = lang_dir(); |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + $r = count($r) > 1; |
|
| 3015 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3016 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 3017 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3018 | + |
|
| 3019 | + if ($voulue == $dir) { |
|
| 3020 | + return $css; |
|
| 3021 | + } |
|
| 3022 | + |
|
| 3023 | + if ( |
|
| 3024 | + // url absolue |
|
| 3025 | + preg_match(',^https?:,i', $css) |
|
| 3026 | + // ou qui contient un ? |
|
| 3027 | + or (($p = strpos($css, '?')) !== false) |
|
| 3028 | + ) { |
|
| 3029 | + $distant = true; |
|
| 3030 | + $cssf = parse_url($css); |
|
| 3031 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3032 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3033 | + } else { |
|
| 3034 | + $distant = false; |
|
| 3035 | + $cssf = $css; |
|
| 3036 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3037 | + //propose (rien a faire dans ce cas) |
|
| 3038 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3039 | + if (@file_exists($f)) { |
|
| 3040 | + return $f; |
|
| 3041 | + } |
|
| 3042 | + } |
|
| 3043 | + |
|
| 3044 | + // 2. |
|
| 3045 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3046 | + $f = $dir_var |
|
| 3047 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3048 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3049 | + |
|
| 3050 | + // la css peut etre distante (url absolue !) |
|
| 3051 | + if ($distant) { |
|
| 3052 | + include_spip('inc/distant'); |
|
| 3053 | + $res = recuperer_url($css); |
|
| 3054 | + if (!$res or !$contenu = $res['page']) { |
|
| 3055 | + return $css; |
|
| 3056 | + } |
|
| 3057 | + } else { |
|
| 3058 | + if ( |
|
| 3059 | + (@filemtime($f) > @filemtime($css)) |
|
| 3060 | + and (_VAR_MODE != 'recalcul') |
|
| 3061 | + ) { |
|
| 3062 | + return $f; |
|
| 3063 | + } |
|
| 3064 | + if (!lire_fichier($css, $contenu)) { |
|
| 3065 | + return $css; |
|
| 3066 | + } |
|
| 3067 | + } |
|
| 3068 | + |
|
| 3069 | + |
|
| 3070 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3071 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3072 | + $parser = new csstidy(); |
|
| 3073 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3074 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3075 | + $parser->parse($contenu); |
|
| 3076 | + |
|
| 3077 | + $contenu = $parser->print->plain(); |
|
| 3078 | + |
|
| 3079 | + |
|
| 3080 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3081 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3082 | + $src = []; |
|
| 3083 | + $src_direction_css = []; |
|
| 3084 | + $src_faux_abs = []; |
|
| 3085 | + $d = dirname($css); |
|
| 3086 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3087 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3088 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3089 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3090 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3091 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3092 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3093 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3094 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3095 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3096 | + } |
|
| 3097 | + $src[] = $regs[0][$k]; |
|
| 3098 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3099 | + } |
|
| 3100 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3101 | + |
|
| 3102 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3103 | + |
|
| 3104 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3105 | + if (count($src_faux_abs)) { |
|
| 3106 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3107 | + } |
|
| 3108 | + |
|
| 3109 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3110 | + return $css; |
|
| 3111 | + } |
|
| 3112 | + |
|
| 3113 | + return $f; |
|
| 3114 | 3114 | } |
| 3115 | 3115 | |
| 3116 | 3116 | |
@@ -3133,46 +3133,46 @@ discard block |
||
| 3133 | 3133 | * - Chemin ou URL du fichier CSS source sinon. |
| 3134 | 3134 | **/ |
| 3135 | 3135 | function url_absolue_css($css) { |
| 3136 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3137 | - return $css; |
|
| 3138 | - } |
|
| 3136 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3137 | + return $css; |
|
| 3138 | + } |
|
| 3139 | 3139 | |
| 3140 | - $url_absolue_css = url_absolue($css); |
|
| 3140 | + $url_absolue_css = url_absolue($css); |
|
| 3141 | 3141 | |
| 3142 | - $f = basename($css, '.css'); |
|
| 3143 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3144 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3145 | - . '.css'; |
|
| 3142 | + $f = basename($css, '.css'); |
|
| 3143 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3144 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3145 | + . '.css'; |
|
| 3146 | 3146 | |
| 3147 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3148 | - return $f; |
|
| 3149 | - } |
|
| 3147 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3148 | + return $f; |
|
| 3149 | + } |
|
| 3150 | 3150 | |
| 3151 | - if ($url_absolue_css == $css) { |
|
| 3152 | - if ( |
|
| 3153 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3154 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3155 | - ) { |
|
| 3156 | - include_spip('inc/distant'); |
|
| 3157 | - $contenu = recuperer_url($css); |
|
| 3158 | - $contenu = $contenu['page'] ?? ''; |
|
| 3159 | - if (!$contenu) { |
|
| 3160 | - return $css; |
|
| 3161 | - } |
|
| 3162 | - } |
|
| 3163 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3164 | - return $css; |
|
| 3165 | - } |
|
| 3151 | + if ($url_absolue_css == $css) { |
|
| 3152 | + if ( |
|
| 3153 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3154 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3155 | + ) { |
|
| 3156 | + include_spip('inc/distant'); |
|
| 3157 | + $contenu = recuperer_url($css); |
|
| 3158 | + $contenu = $contenu['page'] ?? ''; |
|
| 3159 | + if (!$contenu) { |
|
| 3160 | + return $css; |
|
| 3161 | + } |
|
| 3162 | + } |
|
| 3163 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3164 | + return $css; |
|
| 3165 | + } |
|
| 3166 | 3166 | |
| 3167 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3168 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3167 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3168 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3169 | 3169 | |
| 3170 | - // ecrire la css |
|
| 3171 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3172 | - return $css; |
|
| 3173 | - } |
|
| 3170 | + // ecrire la css |
|
| 3171 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3172 | + return $css; |
|
| 3173 | + } |
|
| 3174 | 3174 | |
| 3175 | - return $f; |
|
| 3175 | + return $f; |
|
| 3176 | 3176 | } |
| 3177 | 3177 | |
| 3178 | 3178 | |
@@ -3206,24 +3206,24 @@ discard block |
||
| 3206 | 3206 | * Valeur trouvée ou valeur par défaut. |
| 3207 | 3207 | **/ |
| 3208 | 3208 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3209 | - foreach (explode('/', $cle) as $k) { |
|
| 3210 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3209 | + foreach (explode('/', $cle) as $k) { |
|
| 3210 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3211 | 3211 | |
| 3212 | - if (is_object($table)) { |
|
| 3213 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3214 | - } elseif (is_array($table)) { |
|
| 3215 | - if ($conserver_null) { |
|
| 3216 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3217 | - } else { |
|
| 3218 | - $table = ($table[$k] ?? $defaut); |
|
| 3219 | - } |
|
| 3220 | - } else { |
|
| 3221 | - $table = $defaut; |
|
| 3222 | - break; |
|
| 3223 | - } |
|
| 3224 | - } |
|
| 3212 | + if (is_object($table)) { |
|
| 3213 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3214 | + } elseif (is_array($table)) { |
|
| 3215 | + if ($conserver_null) { |
|
| 3216 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3217 | + } else { |
|
| 3218 | + $table = ($table[$k] ?? $defaut); |
|
| 3219 | + } |
|
| 3220 | + } else { |
|
| 3221 | + $table = $defaut; |
|
| 3222 | + break; |
|
| 3223 | + } |
|
| 3224 | + } |
|
| 3225 | 3225 | |
| 3226 | - return $table; |
|
| 3226 | + return $table; |
|
| 3227 | 3227 | } |
| 3228 | 3228 | |
| 3229 | 3229 | /** |
@@ -3256,22 +3256,22 @@ discard block |
||
| 3256 | 3256 | * - string : expression trouvée. |
| 3257 | 3257 | **/ |
| 3258 | 3258 | function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3259 | - if (intval($modif) and $capte == 0) { |
|
| 3260 | - $capte = $modif; |
|
| 3261 | - $modif = 'UimsS'; |
|
| 3262 | - } |
|
| 3263 | - $expression = str_replace('\/', '/', $expression); |
|
| 3264 | - $expression = str_replace('/', '\/', $expression); |
|
| 3259 | + if (intval($modif) and $capte == 0) { |
|
| 3260 | + $capte = $modif; |
|
| 3261 | + $modif = 'UimsS'; |
|
| 3262 | + } |
|
| 3263 | + $expression = str_replace('\/', '/', $expression); |
|
| 3264 | + $expression = str_replace('/', '\/', $expression); |
|
| 3265 | 3265 | |
| 3266 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3267 | - if (isset($r[$capte])) { |
|
| 3268 | - return $r[$capte]; |
|
| 3269 | - } else { |
|
| 3270 | - return true; |
|
| 3271 | - } |
|
| 3272 | - } |
|
| 3266 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3267 | + if (isset($r[$capte])) { |
|
| 3268 | + return $r[$capte]; |
|
| 3269 | + } else { |
|
| 3270 | + return true; |
|
| 3271 | + } |
|
| 3272 | + } |
|
| 3273 | 3273 | |
| 3274 | - return false; |
|
| 3274 | + return false; |
|
| 3275 | 3275 | } |
| 3276 | 3276 | |
| 3277 | 3277 | |
@@ -3298,10 +3298,10 @@ discard block |
||
| 3298 | 3298 | * Texte |
| 3299 | 3299 | **/ |
| 3300 | 3300 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3301 | - $expression = str_replace('\/', '/', $expression); |
|
| 3302 | - $expression = str_replace('/', '\/', $expression); |
|
| 3301 | + $expression = str_replace('\/', '/', $expression); |
|
| 3302 | + $expression = str_replace('/', '\/', $expression); |
|
| 3303 | 3303 | |
| 3304 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3304 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3305 | 3305 | } |
| 3306 | 3306 | |
| 3307 | 3307 | |
@@ -3319,25 +3319,25 @@ discard block |
||
| 3319 | 3319 | **/ |
| 3320 | 3320 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3321 | 3321 | |
| 3322 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3323 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3322 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3323 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3324 | 3324 | |
| 3325 | - if ( |
|
| 3326 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3327 | - and preg_match_all( |
|
| 3328 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3329 | - $t, |
|
| 3330 | - $matches, |
|
| 3331 | - PREG_PATTERN_ORDER |
|
| 3332 | - ) |
|
| 3333 | - ) { |
|
| 3334 | - if (!isset($doublons['documents'])) { |
|
| 3335 | - $doublons['documents'] = ''; |
|
| 3336 | - } |
|
| 3337 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3338 | - } |
|
| 3325 | + if ( |
|
| 3326 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3327 | + and preg_match_all( |
|
| 3328 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3329 | + $t, |
|
| 3330 | + $matches, |
|
| 3331 | + PREG_PATTERN_ORDER |
|
| 3332 | + ) |
|
| 3333 | + ) { |
|
| 3334 | + if (!isset($doublons['documents'])) { |
|
| 3335 | + $doublons['documents'] = ''; |
|
| 3336 | + } |
|
| 3337 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3338 | + } |
|
| 3339 | 3339 | |
| 3340 | - return $letexte; |
|
| 3340 | + return $letexte; |
|
| 3341 | 3341 | } |
| 3342 | 3342 | |
| 3343 | 3343 | /** |
@@ -3351,7 +3351,7 @@ discard block |
||
| 3351 | 3351 | * @return string Chaîne vide |
| 3352 | 3352 | **/ |
| 3353 | 3353 | function vide($texte) { |
| 3354 | - return ''; |
|
| 3354 | + return ''; |
|
| 3355 | 3355 | } |
| 3356 | 3356 | |
| 3357 | 3357 | // |
@@ -3380,23 +3380,23 @@ discard block |
||
| 3380 | 3380 | * Code HTML résultant |
| 3381 | 3381 | **/ |
| 3382 | 3382 | function env_to_params($env, $ignore_params = []) { |
| 3383 | - $ignore_params = array_merge( |
|
| 3384 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3385 | - $ignore_params |
|
| 3386 | - ); |
|
| 3387 | - if (!is_array($env)) { |
|
| 3388 | - $env = unserialize($env); |
|
| 3389 | - } |
|
| 3390 | - $texte = ''; |
|
| 3391 | - if ($env) { |
|
| 3392 | - foreach ($env as $i => $j) { |
|
| 3393 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3394 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3395 | - } |
|
| 3396 | - } |
|
| 3397 | - } |
|
| 3398 | - |
|
| 3399 | - return $texte; |
|
| 3383 | + $ignore_params = array_merge( |
|
| 3384 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3385 | + $ignore_params |
|
| 3386 | + ); |
|
| 3387 | + if (!is_array($env)) { |
|
| 3388 | + $env = unserialize($env); |
|
| 3389 | + } |
|
| 3390 | + $texte = ''; |
|
| 3391 | + if ($env) { |
|
| 3392 | + foreach ($env as $i => $j) { |
|
| 3393 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3394 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3395 | + } |
|
| 3396 | + } |
|
| 3397 | + } |
|
| 3398 | + |
|
| 3399 | + return $texte; |
|
| 3400 | 3400 | } |
| 3401 | 3401 | |
| 3402 | 3402 | /** |
@@ -3419,23 +3419,23 @@ discard block |
||
| 3419 | 3419 | * Code HTML résultant |
| 3420 | 3420 | **/ |
| 3421 | 3421 | function env_to_attributs($env, $ignore_params = []) { |
| 3422 | - $ignore_params = array_merge( |
|
| 3423 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3424 | - $ignore_params |
|
| 3425 | - ); |
|
| 3426 | - if (!is_array($env)) { |
|
| 3427 | - $env = unserialize($env); |
|
| 3428 | - } |
|
| 3429 | - $texte = ''; |
|
| 3430 | - if ($env) { |
|
| 3431 | - foreach ($env as $i => $j) { |
|
| 3432 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3433 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3434 | - } |
|
| 3435 | - } |
|
| 3436 | - } |
|
| 3422 | + $ignore_params = array_merge( |
|
| 3423 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3424 | + $ignore_params |
|
| 3425 | + ); |
|
| 3426 | + if (!is_array($env)) { |
|
| 3427 | + $env = unserialize($env); |
|
| 3428 | + } |
|
| 3429 | + $texte = ''; |
|
| 3430 | + if ($env) { |
|
| 3431 | + foreach ($env as $i => $j) { |
|
| 3432 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3433 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3434 | + } |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | 3437 | |
| 3438 | - return $texte; |
|
| 3438 | + return $texte; |
|
| 3439 | 3439 | } |
| 3440 | 3440 | |
| 3441 | 3441 | |
@@ -3453,7 +3453,7 @@ discard block |
||
| 3453 | 3453 | * @return string Chaînes concaténés |
| 3454 | 3454 | **/ |
| 3455 | 3455 | function concat(...$args): string { |
| 3456 | - return join('', $args); |
|
| 3456 | + return join('', $args); |
|
| 3457 | 3457 | } |
| 3458 | 3458 | |
| 3459 | 3459 | |
@@ -3473,23 +3473,23 @@ discard block |
||
| 3473 | 3473 | * Contenu du ou des fichiers, concaténé |
| 3474 | 3474 | **/ |
| 3475 | 3475 | function charge_scripts($files, $script = true) { |
| 3476 | - $flux = ''; |
|
| 3477 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3478 | - if (!is_string($file)) { |
|
| 3479 | - continue; |
|
| 3480 | - } |
|
| 3481 | - if ($script) { |
|
| 3482 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3483 | - } |
|
| 3484 | - if ($file) { |
|
| 3485 | - $path = find_in_path($file); |
|
| 3486 | - if ($path) { |
|
| 3487 | - $flux .= spip_file_get_contents($path); |
|
| 3488 | - } |
|
| 3489 | - } |
|
| 3490 | - } |
|
| 3491 | - |
|
| 3492 | - return $flux; |
|
| 3476 | + $flux = ''; |
|
| 3477 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3478 | + if (!is_string($file)) { |
|
| 3479 | + continue; |
|
| 3480 | + } |
|
| 3481 | + if ($script) { |
|
| 3482 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3483 | + } |
|
| 3484 | + if ($file) { |
|
| 3485 | + $path = find_in_path($file); |
|
| 3486 | + if ($path) { |
|
| 3487 | + $flux .= spip_file_get_contents($path); |
|
| 3488 | + } |
|
| 3489 | + } |
|
| 3490 | + } |
|
| 3491 | + |
|
| 3492 | + return $flux; |
|
| 3493 | 3493 | } |
| 3494 | 3494 | |
| 3495 | 3495 | /** |
@@ -3500,22 +3500,22 @@ discard block |
||
| 3500 | 3500 | * @return string |
| 3501 | 3501 | */ |
| 3502 | 3502 | function http_img_variante_svg_si_possible($img_file) { |
| 3503 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3504 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3505 | - if ( |
|
| 3506 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3507 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3508 | - and file_exists($variante_svg_generique) |
|
| 3509 | - ) { |
|
| 3510 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3511 | - $img_file = $variante_svg_size; |
|
| 3512 | - } |
|
| 3513 | - else { |
|
| 3514 | - $img_file = $variante_svg_generique; |
|
| 3515 | - } |
|
| 3516 | - } |
|
| 3503 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3504 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3505 | + if ( |
|
| 3506 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3507 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3508 | + and file_exists($variante_svg_generique) |
|
| 3509 | + ) { |
|
| 3510 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3511 | + $img_file = $variante_svg_size; |
|
| 3512 | + } |
|
| 3513 | + else { |
|
| 3514 | + $img_file = $variante_svg_generique; |
|
| 3515 | + } |
|
| 3516 | + } |
|
| 3517 | 3517 | |
| 3518 | - return $img_file; |
|
| 3518 | + return $img_file; |
|
| 3519 | 3519 | } |
| 3520 | 3520 | |
| 3521 | 3521 | /** |
@@ -3536,54 +3536,54 @@ discard block |
||
| 3536 | 3536 | */ |
| 3537 | 3537 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3538 | 3538 | |
| 3539 | - $img_file = $img; |
|
| 3540 | - if ($p = strpos($img_file, '?')) { |
|
| 3541 | - $img_file = substr($img_file, 0, $p); |
|
| 3542 | - } |
|
| 3543 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3544 | - $img_file = chemin_image($img); |
|
| 3545 | - } |
|
| 3546 | - else { |
|
| 3547 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3548 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3549 | - } |
|
| 3550 | - } |
|
| 3551 | - if (stripos($atts, 'width') === false) { |
|
| 3552 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3553 | - if ( |
|
| 3554 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3555 | - or $options['utiliser_suffixe_size'] == true |
|
| 3556 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3557 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3558 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3559 | - ) { |
|
| 3560 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3561 | - } else { |
|
| 3562 | - $taille = taille_image($img_file); |
|
| 3563 | - [$hauteur, $largeur] = $taille; |
|
| 3564 | - if (!$hauteur or !$largeur) { |
|
| 3565 | - return ''; |
|
| 3566 | - } |
|
| 3567 | - } |
|
| 3568 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3569 | - } |
|
| 3570 | - |
|
| 3571 | - if (file_exists($img_file)) { |
|
| 3572 | - $img_file = timestamp($img_file); |
|
| 3573 | - } |
|
| 3574 | - if ($alt === false) { |
|
| 3575 | - $alt = ''; |
|
| 3576 | - } |
|
| 3577 | - elseif ($alt or $alt === '') { |
|
| 3578 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3579 | - } |
|
| 3580 | - else { |
|
| 3581 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3582 | - } |
|
| 3583 | - return "<img src='$img_file'$alt" |
|
| 3584 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3585 | - . ' ' . ltrim($atts) |
|
| 3586 | - . ' />'; |
|
| 3539 | + $img_file = $img; |
|
| 3540 | + if ($p = strpos($img_file, '?')) { |
|
| 3541 | + $img_file = substr($img_file, 0, $p); |
|
| 3542 | + } |
|
| 3543 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3544 | + $img_file = chemin_image($img); |
|
| 3545 | + } |
|
| 3546 | + else { |
|
| 3547 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3548 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3549 | + } |
|
| 3550 | + } |
|
| 3551 | + if (stripos($atts, 'width') === false) { |
|
| 3552 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3553 | + if ( |
|
| 3554 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3555 | + or $options['utiliser_suffixe_size'] == true |
|
| 3556 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3557 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3558 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3559 | + ) { |
|
| 3560 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3561 | + } else { |
|
| 3562 | + $taille = taille_image($img_file); |
|
| 3563 | + [$hauteur, $largeur] = $taille; |
|
| 3564 | + if (!$hauteur or !$largeur) { |
|
| 3565 | + return ''; |
|
| 3566 | + } |
|
| 3567 | + } |
|
| 3568 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3569 | + } |
|
| 3570 | + |
|
| 3571 | + if (file_exists($img_file)) { |
|
| 3572 | + $img_file = timestamp($img_file); |
|
| 3573 | + } |
|
| 3574 | + if ($alt === false) { |
|
| 3575 | + $alt = ''; |
|
| 3576 | + } |
|
| 3577 | + elseif ($alt or $alt === '') { |
|
| 3578 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3579 | + } |
|
| 3580 | + else { |
|
| 3581 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3582 | + } |
|
| 3583 | + return "<img src='$img_file'$alt" |
|
| 3584 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3585 | + . ' ' . ltrim($atts) |
|
| 3586 | + . ' />'; |
|
| 3587 | 3587 | } |
| 3588 | 3588 | |
| 3589 | 3589 | /** |
@@ -3595,70 +3595,70 @@ discard block |
||
| 3595 | 3595 | * @return string |
| 3596 | 3596 | */ |
| 3597 | 3597 | function http_style_background($img, $att = '', $size = null) { |
| 3598 | - if ($size and is_numeric($size)) { |
|
| 3599 | - $size = trim($size) . 'px'; |
|
| 3600 | - } |
|
| 3601 | - return " style='background" . |
|
| 3602 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3603 | - . ($size ? "background-size:{$size};" : '') |
|
| 3604 | - . "'"; |
|
| 3598 | + if ($size and is_numeric($size)) { |
|
| 3599 | + $size = trim($size) . 'px'; |
|
| 3600 | + } |
|
| 3601 | + return " style='background" . |
|
| 3602 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3603 | + . ($size ? "background-size:{$size};" : '') |
|
| 3604 | + . "'"; |
|
| 3605 | 3605 | } |
| 3606 | 3606 | |
| 3607 | 3607 | |
| 3608 | 3608 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3609 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3610 | - while (is_null(end($args)) and count($args)) { |
|
| 3611 | - array_pop($args); |
|
| 3612 | - } |
|
| 3613 | - if (!count($args)) { |
|
| 3614 | - return [null, null, null]; |
|
| 3615 | - } |
|
| 3616 | - if (count($args) < 3) { |
|
| 3617 | - $maybe_size = array_pop($args); |
|
| 3618 | - // @2x |
|
| 3619 | - // @1.5x |
|
| 3620 | - // 512 |
|
| 3621 | - // 512x* |
|
| 3622 | - // 512x300 |
|
| 3623 | - if ( |
|
| 3624 | - !strlen($maybe_size) |
|
| 3625 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3626 | - ) { |
|
| 3627 | - $args[] = $maybe_size; |
|
| 3628 | - $maybe_size = null; |
|
| 3629 | - } |
|
| 3630 | - while (count($args) < 2) { |
|
| 3631 | - $args[] = null; // default alt or class |
|
| 3632 | - } |
|
| 3633 | - $args[] = $maybe_size; |
|
| 3634 | - } |
|
| 3635 | - return $args; |
|
| 3609 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3610 | + while (is_null(end($args)) and count($args)) { |
|
| 3611 | + array_pop($args); |
|
| 3612 | + } |
|
| 3613 | + if (!count($args)) { |
|
| 3614 | + return [null, null, null]; |
|
| 3615 | + } |
|
| 3616 | + if (count($args) < 3) { |
|
| 3617 | + $maybe_size = array_pop($args); |
|
| 3618 | + // @2x |
|
| 3619 | + // @1.5x |
|
| 3620 | + // 512 |
|
| 3621 | + // 512x* |
|
| 3622 | + // 512x300 |
|
| 3623 | + if ( |
|
| 3624 | + !strlen($maybe_size) |
|
| 3625 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3626 | + ) { |
|
| 3627 | + $args[] = $maybe_size; |
|
| 3628 | + $maybe_size = null; |
|
| 3629 | + } |
|
| 3630 | + while (count($args) < 2) { |
|
| 3631 | + $args[] = null; // default alt or class |
|
| 3632 | + } |
|
| 3633 | + $args[] = $maybe_size; |
|
| 3634 | + } |
|
| 3635 | + return $args; |
|
| 3636 | 3636 | } |
| 3637 | 3637 | |
| 3638 | 3638 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3639 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3640 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3641 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3642 | - [$h, $w] = taille_image($img); |
|
| 3643 | - $height = intval(round($h / $coef)); |
|
| 3644 | - $width = intval(round($w / $coef)); |
|
| 3645 | - } |
|
| 3646 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3647 | - else { |
|
| 3648 | - $size = explode('x', $size, 2); |
|
| 3649 | - $size = array_map('trim', $size); |
|
| 3650 | - $height = $width = intval(array_shift($size)); |
|
| 3651 | - |
|
| 3652 | - if (count($size) and reset($size)) { |
|
| 3653 | - $height = array_shift($size); |
|
| 3654 | - if ($height === '*') { |
|
| 3655 | - [$h, $w] = taille_image($img); |
|
| 3656 | - $height = intval(round($h * $width / $w)); |
|
| 3657 | - } |
|
| 3658 | - } |
|
| 3659 | - } |
|
| 3660 | - |
|
| 3661 | - return [$width, $height]; |
|
| 3639 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3640 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3641 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3642 | + [$h, $w] = taille_image($img); |
|
| 3643 | + $height = intval(round($h / $coef)); |
|
| 3644 | + $width = intval(round($w / $coef)); |
|
| 3645 | + } |
|
| 3646 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3647 | + else { |
|
| 3648 | + $size = explode('x', $size, 2); |
|
| 3649 | + $size = array_map('trim', $size); |
|
| 3650 | + $height = $width = intval(array_shift($size)); |
|
| 3651 | + |
|
| 3652 | + if (count($size) and reset($size)) { |
|
| 3653 | + $height = array_shift($size); |
|
| 3654 | + if ($height === '*') { |
|
| 3655 | + [$h, $w] = taille_image($img); |
|
| 3656 | + $height = intval(round($h * $width / $w)); |
|
| 3657 | + } |
|
| 3658 | + } |
|
| 3659 | + } |
|
| 3660 | + |
|
| 3661 | + return [$width, $height]; |
|
| 3662 | 3662 | } |
| 3663 | 3663 | |
| 3664 | 3664 | /** |
@@ -3694,43 +3694,43 @@ discard block |
||
| 3694 | 3694 | */ |
| 3695 | 3695 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3696 | 3696 | |
| 3697 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3698 | - |
|
| 3699 | - $img = trim((string) $img); |
|
| 3700 | - if (strpos($img, '<img') === 0) { |
|
| 3701 | - if (!is_null($alt)) { |
|
| 3702 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3703 | - } |
|
| 3704 | - if (!is_null($class)) { |
|
| 3705 | - if (strlen($class)) { |
|
| 3706 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3707 | - } |
|
| 3708 | - else { |
|
| 3709 | - $img = vider_attribut($img, 'class'); |
|
| 3710 | - } |
|
| 3711 | - } |
|
| 3712 | - } |
|
| 3713 | - else { |
|
| 3714 | - $img = http_img_pack( |
|
| 3715 | - $img, |
|
| 3716 | - $alt, |
|
| 3717 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3718 | - '', |
|
| 3719 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3720 | - ); |
|
| 3721 | - if (is_null($alt)) { |
|
| 3722 | - $img = vider_attribut($img, 'alt'); |
|
| 3723 | - } |
|
| 3724 | - } |
|
| 3725 | - |
|
| 3726 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3727 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3728 | - |
|
| 3729 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3730 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3731 | - } |
|
| 3732 | - |
|
| 3733 | - return $img; |
|
| 3697 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3698 | + |
|
| 3699 | + $img = trim((string) $img); |
|
| 3700 | + if (strpos($img, '<img') === 0) { |
|
| 3701 | + if (!is_null($alt)) { |
|
| 3702 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3703 | + } |
|
| 3704 | + if (!is_null($class)) { |
|
| 3705 | + if (strlen($class)) { |
|
| 3706 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3707 | + } |
|
| 3708 | + else { |
|
| 3709 | + $img = vider_attribut($img, 'class'); |
|
| 3710 | + } |
|
| 3711 | + } |
|
| 3712 | + } |
|
| 3713 | + else { |
|
| 3714 | + $img = http_img_pack( |
|
| 3715 | + $img, |
|
| 3716 | + $alt, |
|
| 3717 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3718 | + '', |
|
| 3719 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3720 | + ); |
|
| 3721 | + if (is_null($alt)) { |
|
| 3722 | + $img = vider_attribut($img, 'alt'); |
|
| 3723 | + } |
|
| 3724 | + } |
|
| 3725 | + |
|
| 3726 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3727 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3728 | + |
|
| 3729 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3730 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3731 | + } |
|
| 3732 | + |
|
| 3733 | + return $img; |
|
| 3734 | 3734 | } |
| 3735 | 3735 | |
| 3736 | 3736 | |
@@ -3764,80 +3764,80 @@ discard block |
||
| 3764 | 3764 | */ |
| 3765 | 3765 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3766 | 3766 | |
| 3767 | - $svg = null; |
|
| 3768 | - $img = trim($img); |
|
| 3769 | - $img_file = $img; |
|
| 3770 | - if (strpos($img, '<svg') === false) { |
|
| 3771 | - if ($p = strpos($img_file, '?')) { |
|
| 3772 | - $img_file = substr($img_file, 0, $p); |
|
| 3773 | - } |
|
| 3774 | - |
|
| 3775 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3776 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3777 | - if (tester_url_absolue($img_file)) { |
|
| 3778 | - include_spip('inc/distant'); |
|
| 3779 | - $fichier = copie_locale($img_file); |
|
| 3780 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3781 | - } |
|
| 3782 | - |
|
| 3783 | - if ( |
|
| 3784 | - !$img_file |
|
| 3785 | - or !file_exists($img_file) |
|
| 3786 | - or !$svg = file_get_contents($img_file) |
|
| 3787 | - ) { |
|
| 3788 | - return ''; |
|
| 3789 | - } |
|
| 3790 | - } |
|
| 3791 | - |
|
| 3792 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3793 | - return ''; |
|
| 3794 | - } |
|
| 3795 | - |
|
| 3796 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3797 | - |
|
| 3798 | - $balise_svg = $match[0]; |
|
| 3799 | - $balise_svg_source = $balise_svg; |
|
| 3800 | - |
|
| 3801 | - // entete XML à supprimer |
|
| 3802 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3803 | - |
|
| 3804 | - // IE est toujours mon ami |
|
| 3805 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3806 | - |
|
| 3807 | - // regler la classe |
|
| 3808 | - if (!is_null($class)) { |
|
| 3809 | - if (strlen($class)) { |
|
| 3810 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3811 | - } |
|
| 3812 | - else { |
|
| 3813 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3814 | - } |
|
| 3815 | - } |
|
| 3816 | - |
|
| 3817 | - // regler le alt |
|
| 3818 | - if ($alt) { |
|
| 3819 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3820 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3821 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3822 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3823 | - $balise_svg .= $title; |
|
| 3824 | - } |
|
| 3825 | - else { |
|
| 3826 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3827 | - } |
|
| 3828 | - |
|
| 3829 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3830 | - |
|
| 3831 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3832 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3833 | - |
|
| 3834 | - if (!function_exists('svg_redimensionner')) { |
|
| 3835 | - include_spip('inc/svg'); |
|
| 3836 | - } |
|
| 3837 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3838 | - } |
|
| 3839 | - |
|
| 3840 | - return $svg; |
|
| 3767 | + $svg = null; |
|
| 3768 | + $img = trim($img); |
|
| 3769 | + $img_file = $img; |
|
| 3770 | + if (strpos($img, '<svg') === false) { |
|
| 3771 | + if ($p = strpos($img_file, '?')) { |
|
| 3772 | + $img_file = substr($img_file, 0, $p); |
|
| 3773 | + } |
|
| 3774 | + |
|
| 3775 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3776 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3777 | + if (tester_url_absolue($img_file)) { |
|
| 3778 | + include_spip('inc/distant'); |
|
| 3779 | + $fichier = copie_locale($img_file); |
|
| 3780 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3781 | + } |
|
| 3782 | + |
|
| 3783 | + if ( |
|
| 3784 | + !$img_file |
|
| 3785 | + or !file_exists($img_file) |
|
| 3786 | + or !$svg = file_get_contents($img_file) |
|
| 3787 | + ) { |
|
| 3788 | + return ''; |
|
| 3789 | + } |
|
| 3790 | + } |
|
| 3791 | + |
|
| 3792 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3793 | + return ''; |
|
| 3794 | + } |
|
| 3795 | + |
|
| 3796 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3797 | + |
|
| 3798 | + $balise_svg = $match[0]; |
|
| 3799 | + $balise_svg_source = $balise_svg; |
|
| 3800 | + |
|
| 3801 | + // entete XML à supprimer |
|
| 3802 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3803 | + |
|
| 3804 | + // IE est toujours mon ami |
|
| 3805 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3806 | + |
|
| 3807 | + // regler la classe |
|
| 3808 | + if (!is_null($class)) { |
|
| 3809 | + if (strlen($class)) { |
|
| 3810 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3811 | + } |
|
| 3812 | + else { |
|
| 3813 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3814 | + } |
|
| 3815 | + } |
|
| 3816 | + |
|
| 3817 | + // regler le alt |
|
| 3818 | + if ($alt) { |
|
| 3819 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3820 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3821 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3822 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3823 | + $balise_svg .= $title; |
|
| 3824 | + } |
|
| 3825 | + else { |
|
| 3826 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3827 | + } |
|
| 3828 | + |
|
| 3829 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3830 | + |
|
| 3831 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3832 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3833 | + |
|
| 3834 | + if (!function_exists('svg_redimensionner')) { |
|
| 3835 | + include_spip('inc/svg'); |
|
| 3836 | + } |
|
| 3837 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3838 | + } |
|
| 3839 | + |
|
| 3840 | + return $svg; |
|
| 3841 | 3841 | } |
| 3842 | 3842 | |
| 3843 | 3843 | |
@@ -3863,18 +3863,18 @@ discard block |
||
| 3863 | 3863 | * Code HTML résultant |
| 3864 | 3864 | **/ |
| 3865 | 3865 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3866 | - $texte = ''; |
|
| 3867 | - if (is_array($tableau)) { |
|
| 3868 | - foreach ($tableau as $k => $v) { |
|
| 3869 | - $res = recuperer_fond( |
|
| 3870 | - 'modeles/' . $modele, |
|
| 3871 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3872 | - ); |
|
| 3873 | - $texte .= $res; |
|
| 3874 | - } |
|
| 3875 | - } |
|
| 3866 | + $texte = ''; |
|
| 3867 | + if (is_array($tableau)) { |
|
| 3868 | + foreach ($tableau as $k => $v) { |
|
| 3869 | + $res = recuperer_fond( |
|
| 3870 | + 'modeles/' . $modele, |
|
| 3871 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3872 | + ); |
|
| 3873 | + $texte .= $res; |
|
| 3874 | + } |
|
| 3875 | + } |
|
| 3876 | 3876 | |
| 3877 | - return $texte; |
|
| 3877 | + return $texte; |
|
| 3878 | 3878 | } |
| 3879 | 3879 | |
| 3880 | 3880 | |
@@ -3899,37 +3899,37 @@ discard block |
||
| 3899 | 3899 | * - tout : retourne toutes les informations du plugin actif |
| 3900 | 3900 | **/ |
| 3901 | 3901 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3902 | - include_spip('inc/plugin'); |
|
| 3903 | - $plugin = strtoupper($plugin); |
|
| 3904 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3905 | - |
|
| 3906 | - if (!$plugin) { |
|
| 3907 | - return serialize(array_keys($plugins_actifs)); |
|
| 3908 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3909 | - return ''; |
|
| 3910 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3911 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3912 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3913 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3914 | - } else { |
|
| 3915 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3916 | - // On prend en compte les extensions |
|
| 3917 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3918 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3919 | - } else { |
|
| 3920 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3921 | - } |
|
| 3922 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3923 | - return ''; |
|
| 3924 | - } |
|
| 3925 | - if ($type_info == 'tout') { |
|
| 3926 | - return $infos; |
|
| 3927 | - } elseif ($type_info == 'est_actif') { |
|
| 3928 | - return $infos ? 1 : 0; |
|
| 3929 | - } else { |
|
| 3930 | - return strval($infos[$type_info]); |
|
| 3931 | - } |
|
| 3932 | - } |
|
| 3902 | + include_spip('inc/plugin'); |
|
| 3903 | + $plugin = strtoupper($plugin); |
|
| 3904 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3905 | + |
|
| 3906 | + if (!$plugin) { |
|
| 3907 | + return serialize(array_keys($plugins_actifs)); |
|
| 3908 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3909 | + return ''; |
|
| 3910 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3911 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3912 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3913 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3914 | + } else { |
|
| 3915 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3916 | + // On prend en compte les extensions |
|
| 3917 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3918 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3919 | + } else { |
|
| 3920 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3921 | + } |
|
| 3922 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3923 | + return ''; |
|
| 3924 | + } |
|
| 3925 | + if ($type_info == 'tout') { |
|
| 3926 | + return $infos; |
|
| 3927 | + } elseif ($type_info == 'est_actif') { |
|
| 3928 | + return $infos ? 1 : 0; |
|
| 3929 | + } else { |
|
| 3930 | + return strval($infos[$type_info]); |
|
| 3931 | + } |
|
| 3932 | + } |
|
| 3933 | 3933 | } |
| 3934 | 3934 | |
| 3935 | 3935 | |
@@ -3956,9 +3956,9 @@ discard block |
||
| 3956 | 3956 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3957 | 3957 | */ |
| 3958 | 3958 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3959 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3959 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3960 | 3960 | |
| 3961 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3961 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3962 | 3962 | } |
| 3963 | 3963 | |
| 3964 | 3964 | |
@@ -3988,19 +3988,19 @@ discard block |
||
| 3988 | 3988 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3989 | 3989 | */ |
| 3990 | 3990 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3991 | - static $puce_statut = null; |
|
| 3992 | - if (!$puce_statut) { |
|
| 3993 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3994 | - } |
|
| 3991 | + static $puce_statut = null; |
|
| 3992 | + if (!$puce_statut) { |
|
| 3993 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3994 | + } |
|
| 3995 | 3995 | |
| 3996 | - return $puce_statut( |
|
| 3997 | - $id_objet, |
|
| 3998 | - $statut, |
|
| 3999 | - $id_parent, |
|
| 4000 | - $objet, |
|
| 4001 | - false, |
|
| 4002 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4003 | - ); |
|
| 3996 | + return $puce_statut( |
|
| 3997 | + $id_objet, |
|
| 3998 | + $statut, |
|
| 3999 | + $id_parent, |
|
| 4000 | + $objet, |
|
| 4001 | + false, |
|
| 4002 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4003 | + ); |
|
| 4004 | 4004 | } |
| 4005 | 4005 | |
| 4006 | 4006 | |
@@ -4027,98 +4027,98 @@ discard block |
||
| 4027 | 4027 | * hash du contexte |
| 4028 | 4028 | */ |
| 4029 | 4029 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 4030 | - $env = null; |
|
| 4031 | - if ( |
|
| 4032 | - is_string($c) |
|
| 4033 | - and @unserialize($c) !== false |
|
| 4034 | - ) { |
|
| 4035 | - $c = unserialize($c); |
|
| 4036 | - } |
|
| 4037 | - |
|
| 4038 | - // supprimer les parametres debut_x |
|
| 4039 | - // pour que la pagination ajax ne soit pas plantee |
|
| 4040 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4041 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4042 | - if (is_array($c)) { |
|
| 4043 | - foreach ($c as $k => $v) { |
|
| 4044 | - if (strpos($k, 'debut_') === 0) { |
|
| 4045 | - unset($c[$k]); |
|
| 4046 | - } |
|
| 4047 | - } |
|
| 4048 | - } |
|
| 4049 | - |
|
| 4050 | - if (!function_exists('calculer_cle_action')) { |
|
| 4051 | - include_spip('inc/securiser_action'); |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - $c = serialize($c); |
|
| 4055 | - $cle = calculer_cle_action($form . $c); |
|
| 4056 | - $c = "$cle:$c"; |
|
| 4057 | - |
|
| 4058 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4059 | - // par defaut, sauf si cette configuration a été forcée |
|
| 4060 | - // OU que la longueur de l’argument géneré est plus long |
|
| 4061 | - // que ce qui est toléré. |
|
| 4062 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4063 | - if (!$cache_contextes_ajax) { |
|
| 4064 | - $env = $c; |
|
| 4065 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4066 | - $env = gzdeflate($env); |
|
| 4067 | - } |
|
| 4068 | - $env = _xor($env); |
|
| 4069 | - $env = base64_encode($env); |
|
| 4070 | - $len = strlen($env); |
|
| 4071 | - // Si l’url est trop longue pour le navigateur |
|
| 4072 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4073 | - if ($len > $max_len) { |
|
| 4074 | - $cache_contextes_ajax = true; |
|
| 4075 | - spip_log( |
|
| 4076 | - 'Contextes AJAX forces en fichiers !' |
|
| 4077 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4078 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4079 | - _LOG_AVERTISSEMENT |
|
| 4080 | - ); |
|
| 4081 | - } |
|
| 4082 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4083 | - elseif ( |
|
| 4084 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4085 | - and $max_len < $len |
|
| 4086 | - ) { |
|
| 4087 | - $cache_contextes_ajax = true; |
|
| 4088 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4089 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4090 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4091 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4092 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4093 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4094 | - } |
|
| 4095 | - } |
|
| 4096 | - |
|
| 4097 | - if ($cache_contextes_ajax) { |
|
| 4098 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4099 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4100 | - $md5 = md5($c); |
|
| 4101 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4102 | - $env = $md5; |
|
| 4103 | - } |
|
| 4104 | - |
|
| 4105 | - if ($emboite === null) { |
|
| 4106 | - return $env; |
|
| 4107 | - } |
|
| 4108 | - if (!trim($emboite)) { |
|
| 4109 | - return ''; |
|
| 4110 | - } |
|
| 4111 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4112 | - $r = self(); |
|
| 4113 | - $r = ' data-origin="' . $r . '"'; |
|
| 4114 | - $class = 'ajaxbloc'; |
|
| 4115 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4116 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4117 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4118 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4119 | - } |
|
| 4120 | - |
|
| 4121 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4030 | + $env = null; |
|
| 4031 | + if ( |
|
| 4032 | + is_string($c) |
|
| 4033 | + and @unserialize($c) !== false |
|
| 4034 | + ) { |
|
| 4035 | + $c = unserialize($c); |
|
| 4036 | + } |
|
| 4037 | + |
|
| 4038 | + // supprimer les parametres debut_x |
|
| 4039 | + // pour que la pagination ajax ne soit pas plantee |
|
| 4040 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4041 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4042 | + if (is_array($c)) { |
|
| 4043 | + foreach ($c as $k => $v) { |
|
| 4044 | + if (strpos($k, 'debut_') === 0) { |
|
| 4045 | + unset($c[$k]); |
|
| 4046 | + } |
|
| 4047 | + } |
|
| 4048 | + } |
|
| 4049 | + |
|
| 4050 | + if (!function_exists('calculer_cle_action')) { |
|
| 4051 | + include_spip('inc/securiser_action'); |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + $c = serialize($c); |
|
| 4055 | + $cle = calculer_cle_action($form . $c); |
|
| 4056 | + $c = "$cle:$c"; |
|
| 4057 | + |
|
| 4058 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4059 | + // par defaut, sauf si cette configuration a été forcée |
|
| 4060 | + // OU que la longueur de l’argument géneré est plus long |
|
| 4061 | + // que ce qui est toléré. |
|
| 4062 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4063 | + if (!$cache_contextes_ajax) { |
|
| 4064 | + $env = $c; |
|
| 4065 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4066 | + $env = gzdeflate($env); |
|
| 4067 | + } |
|
| 4068 | + $env = _xor($env); |
|
| 4069 | + $env = base64_encode($env); |
|
| 4070 | + $len = strlen($env); |
|
| 4071 | + // Si l’url est trop longue pour le navigateur |
|
| 4072 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4073 | + if ($len > $max_len) { |
|
| 4074 | + $cache_contextes_ajax = true; |
|
| 4075 | + spip_log( |
|
| 4076 | + 'Contextes AJAX forces en fichiers !' |
|
| 4077 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4078 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4079 | + _LOG_AVERTISSEMENT |
|
| 4080 | + ); |
|
| 4081 | + } |
|
| 4082 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4083 | + elseif ( |
|
| 4084 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4085 | + and $max_len < $len |
|
| 4086 | + ) { |
|
| 4087 | + $cache_contextes_ajax = true; |
|
| 4088 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4089 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4090 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4091 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4092 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4093 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4094 | + } |
|
| 4095 | + } |
|
| 4096 | + |
|
| 4097 | + if ($cache_contextes_ajax) { |
|
| 4098 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4099 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4100 | + $md5 = md5($c); |
|
| 4101 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4102 | + $env = $md5; |
|
| 4103 | + } |
|
| 4104 | + |
|
| 4105 | + if ($emboite === null) { |
|
| 4106 | + return $env; |
|
| 4107 | + } |
|
| 4108 | + if (!trim($emboite)) { |
|
| 4109 | + return ''; |
|
| 4110 | + } |
|
| 4111 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4112 | + $r = self(); |
|
| 4113 | + $r = ' data-origin="' . $r . '"'; |
|
| 4114 | + $class = 'ajaxbloc'; |
|
| 4115 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4116 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4117 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4118 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4119 | + } |
|
| 4120 | + |
|
| 4121 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4122 | 4122 | } |
| 4123 | 4123 | |
| 4124 | 4124 | /** |
@@ -4138,37 +4138,37 @@ discard block |
||
| 4138 | 4138 | * - false : erreur de décodage |
| 4139 | 4139 | */ |
| 4140 | 4140 | function decoder_contexte_ajax($c, $form = '') { |
| 4141 | - if (!function_exists('calculer_cle_action')) { |
|
| 4142 | - include_spip('inc/securiser_action'); |
|
| 4143 | - } |
|
| 4144 | - if ( |
|
| 4145 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4146 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4147 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4148 | - ) { |
|
| 4149 | - $c = $contexte; |
|
| 4150 | - } else { |
|
| 4151 | - $c = @base64_decode($c); |
|
| 4152 | - $c = _xor($c); |
|
| 4153 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4154 | - $c = @gzinflate($c); |
|
| 4155 | - } |
|
| 4156 | - } |
|
| 4157 | - |
|
| 4158 | - // extraire la signature en debut de contexte |
|
| 4159 | - // et la verifier avant de deserializer |
|
| 4160 | - // format : signature:donneesserializees |
|
| 4161 | - if ($p = strpos($c, ':')) { |
|
| 4162 | - $cle = substr($c, 0, $p); |
|
| 4163 | - $c = substr($c, $p + 1); |
|
| 4164 | - |
|
| 4165 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4166 | - $env = @unserialize($c); |
|
| 4167 | - return $env; |
|
| 4168 | - } |
|
| 4169 | - } |
|
| 4170 | - |
|
| 4171 | - return false; |
|
| 4141 | + if (!function_exists('calculer_cle_action')) { |
|
| 4142 | + include_spip('inc/securiser_action'); |
|
| 4143 | + } |
|
| 4144 | + if ( |
|
| 4145 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4146 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4147 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4148 | + ) { |
|
| 4149 | + $c = $contexte; |
|
| 4150 | + } else { |
|
| 4151 | + $c = @base64_decode($c); |
|
| 4152 | + $c = _xor($c); |
|
| 4153 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4154 | + $c = @gzinflate($c); |
|
| 4155 | + } |
|
| 4156 | + } |
|
| 4157 | + |
|
| 4158 | + // extraire la signature en debut de contexte |
|
| 4159 | + // et la verifier avant de deserializer |
|
| 4160 | + // format : signature:donneesserializees |
|
| 4161 | + if ($p = strpos($c, ':')) { |
|
| 4162 | + $cle = substr($c, 0, $p); |
|
| 4163 | + $c = substr($c, $p + 1); |
|
| 4164 | + |
|
| 4165 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4166 | + $env = @unserialize($c); |
|
| 4167 | + return $env; |
|
| 4168 | + } |
|
| 4169 | + } |
|
| 4170 | + |
|
| 4171 | + return false; |
|
| 4172 | 4172 | } |
| 4173 | 4173 | |
| 4174 | 4174 | |
@@ -4186,20 +4186,20 @@ discard block |
||
| 4186 | 4186 | * Message décrypté ou encrypté |
| 4187 | 4187 | **/ |
| 4188 | 4188 | function _xor($message, $key = null) { |
| 4189 | - if (is_null($key)) { |
|
| 4190 | - if (!function_exists('calculer_cle_action')) { |
|
| 4191 | - include_spip('inc/securiser_action'); |
|
| 4192 | - } |
|
| 4193 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4194 | - } |
|
| 4189 | + if (is_null($key)) { |
|
| 4190 | + if (!function_exists('calculer_cle_action')) { |
|
| 4191 | + include_spip('inc/securiser_action'); |
|
| 4192 | + } |
|
| 4193 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4194 | + } |
|
| 4195 | 4195 | |
| 4196 | - $keylen = strlen($key); |
|
| 4197 | - $messagelen = strlen($message); |
|
| 4198 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4199 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4200 | - } |
|
| 4196 | + $keylen = strlen($key); |
|
| 4197 | + $messagelen = strlen($message); |
|
| 4198 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4199 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4200 | + } |
|
| 4201 | 4201 | |
| 4202 | - return $message; |
|
| 4202 | + return $message; |
|
| 4203 | 4203 | } |
| 4204 | 4204 | |
| 4205 | 4205 | /** |
@@ -4213,7 +4213,7 @@ discard block |
||
| 4213 | 4213 | * @return string |
| 4214 | 4214 | */ |
| 4215 | 4215 | function url_reponse_forum($texte) { |
| 4216 | - return $texte; |
|
| 4216 | + return $texte; |
|
| 4217 | 4217 | } |
| 4218 | 4218 | |
| 4219 | 4219 | /** |
@@ -4227,7 +4227,7 @@ discard block |
||
| 4227 | 4227 | * @return string |
| 4228 | 4228 | */ |
| 4229 | 4229 | function url_rss_forum($texte) { |
| 4230 | - return $texte; |
|
| 4230 | + return $texte; |
|
| 4231 | 4231 | } |
| 4232 | 4232 | |
| 4233 | 4233 | |
@@ -4266,37 +4266,37 @@ discard block |
||
| 4266 | 4266 | * Code HTML |
| 4267 | 4267 | */ |
| 4268 | 4268 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4269 | - if ($on) { |
|
| 4270 | - $bal = 'strong'; |
|
| 4271 | - $class = ''; |
|
| 4272 | - $att = ''; |
|
| 4273 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4274 | - // a.active span.selected.active etc.... |
|
| 4275 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4276 | - $on = explode('.', $on); |
|
| 4277 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4278 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4279 | - $bal = array_shift($on); |
|
| 4280 | - $class = implode(' ', $on); |
|
| 4281 | - if ($bal == 'a') { |
|
| 4282 | - $att = 'href="#" '; |
|
| 4283 | - } |
|
| 4284 | - } |
|
| 4285 | - } |
|
| 4286 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4287 | - } else { |
|
| 4288 | - $bal = 'a'; |
|
| 4289 | - $att = "href='$url'" |
|
| 4290 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4291 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4292 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4293 | - . $evt; |
|
| 4294 | - } |
|
| 4295 | - if ($libelle === null) { |
|
| 4296 | - $libelle = $url; |
|
| 4297 | - } |
|
| 4298 | - |
|
| 4299 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4269 | + if ($on) { |
|
| 4270 | + $bal = 'strong'; |
|
| 4271 | + $class = ''; |
|
| 4272 | + $att = ''; |
|
| 4273 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4274 | + // a.active span.selected.active etc.... |
|
| 4275 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4276 | + $on = explode('.', $on); |
|
| 4277 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4278 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4279 | + $bal = array_shift($on); |
|
| 4280 | + $class = implode(' ', $on); |
|
| 4281 | + if ($bal == 'a') { |
|
| 4282 | + $att = 'href="#" '; |
|
| 4283 | + } |
|
| 4284 | + } |
|
| 4285 | + } |
|
| 4286 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4287 | + } else { |
|
| 4288 | + $bal = 'a'; |
|
| 4289 | + $att = "href='$url'" |
|
| 4290 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4291 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4292 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4293 | + . $evt; |
|
| 4294 | + } |
|
| 4295 | + if ($libelle === null) { |
|
| 4296 | + $libelle = $url; |
|
| 4297 | + } |
|
| 4298 | + |
|
| 4299 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4300 | 4300 | } |
| 4301 | 4301 | |
| 4302 | 4302 | |
@@ -4313,39 +4313,39 @@ discard block |
||
| 4313 | 4313 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4314 | 4314 | */ |
| 4315 | 4315 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4316 | - static $local_singulier_ou_pluriel = []; |
|
| 4317 | - |
|
| 4318 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4319 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4320 | - return ''; |
|
| 4321 | - } |
|
| 4322 | - if (!is_array($vars)) { |
|
| 4323 | - return ''; |
|
| 4324 | - } |
|
| 4325 | - |
|
| 4326 | - $langue = $GLOBALS['spip_lang']; |
|
| 4327 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4328 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4329 | - if ( |
|
| 4330 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4331 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4332 | - ) { |
|
| 4333 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4334 | - } |
|
| 4335 | - } |
|
| 4336 | - |
|
| 4337 | - // si on a une surcharge on l'utilise |
|
| 4338 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4339 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4340 | - } |
|
| 4341 | - |
|
| 4342 | - // sinon traitement par defaut |
|
| 4343 | - $vars[$var] = $nb; |
|
| 4344 | - if ($nb >= 2) { |
|
| 4345 | - return _T($chaine_plusieurs, $vars); |
|
| 4346 | - } else { |
|
| 4347 | - return _T($chaine_un, $vars); |
|
| 4348 | - } |
|
| 4316 | + static $local_singulier_ou_pluriel = []; |
|
| 4317 | + |
|
| 4318 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4319 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4320 | + return ''; |
|
| 4321 | + } |
|
| 4322 | + if (!is_array($vars)) { |
|
| 4323 | + return ''; |
|
| 4324 | + } |
|
| 4325 | + |
|
| 4326 | + $langue = $GLOBALS['spip_lang']; |
|
| 4327 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4328 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4329 | + if ( |
|
| 4330 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4331 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4332 | + ) { |
|
| 4333 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4334 | + } |
|
| 4335 | + } |
|
| 4336 | + |
|
| 4337 | + // si on a une surcharge on l'utilise |
|
| 4338 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4339 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4340 | + } |
|
| 4341 | + |
|
| 4342 | + // sinon traitement par defaut |
|
| 4343 | + $vars[$var] = $nb; |
|
| 4344 | + if ($nb >= 2) { |
|
| 4345 | + return _T($chaine_plusieurs, $vars); |
|
| 4346 | + } else { |
|
| 4347 | + return _T($chaine_un, $vars); |
|
| 4348 | + } |
|
| 4349 | 4349 | } |
| 4350 | 4350 | |
| 4351 | 4351 | |
@@ -4373,73 +4373,73 @@ discard block |
||
| 4373 | 4373 | */ |
| 4374 | 4374 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4375 | 4375 | |
| 4376 | - $class_lien = $class_bouton = $class; |
|
| 4377 | - |
|
| 4378 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4379 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4380 | - $class_lien .= ' danger'; |
|
| 4381 | - $class_bouton .= ' btn_danger'; |
|
| 4382 | - } elseif ($fonction == 'rien.gif') { |
|
| 4383 | - $fonction = ''; |
|
| 4384 | - } elseif ($fonction == 'delsafe') { |
|
| 4385 | - $fonction = 'del'; |
|
| 4386 | - } |
|
| 4387 | - |
|
| 4388 | - $fond_origine = $fond; |
|
| 4389 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4390 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4391 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4392 | - } |
|
| 4393 | - |
|
| 4394 | - // Ajouter le type d'objet dans la classe |
|
| 4395 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4396 | - $class_lien .= " $objet_type"; |
|
| 4397 | - $class_bouton .= " $objet_type"; |
|
| 4398 | - |
|
| 4399 | - // Texte |
|
| 4400 | - $alt = attribut_html($texte); |
|
| 4401 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4402 | - |
|
| 4403 | - // Liens : préparer les classes ajax |
|
| 4404 | - $ajax = ''; |
|
| 4405 | - if ($type === 'lien') { |
|
| 4406 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4407 | - $ajax = 'ajax'; |
|
| 4408 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4409 | - $ajax .= ' preload'; |
|
| 4410 | - } |
|
| 4411 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4412 | - $ajax .= ' nocache'; |
|
| 4413 | - } |
|
| 4414 | - $ajax = " class='$ajax'"; |
|
| 4415 | - } |
|
| 4416 | - } |
|
| 4417 | - |
|
| 4418 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4419 | - $size = 24; |
|
| 4420 | - if ( |
|
| 4421 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4422 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4423 | - ) { |
|
| 4424 | - $size = $match[1]; |
|
| 4425 | - } |
|
| 4426 | - $class_lien .= " s$size"; |
|
| 4427 | - $class_bouton .= " s$size"; |
|
| 4428 | - |
|
| 4429 | - // Icône |
|
| 4430 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4431 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4432 | - |
|
| 4433 | - // Markup final |
|
| 4434 | - if ($type == 'lien') { |
|
| 4435 | - return "<span class='icone $class_lien'>" |
|
| 4436 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4437 | - . $icone |
|
| 4438 | - . "<b>$texte</b>" |
|
| 4439 | - . "</a></span>\n"; |
|
| 4440 | - } else { |
|
| 4441 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4442 | - } |
|
| 4376 | + $class_lien = $class_bouton = $class; |
|
| 4377 | + |
|
| 4378 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4379 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4380 | + $class_lien .= ' danger'; |
|
| 4381 | + $class_bouton .= ' btn_danger'; |
|
| 4382 | + } elseif ($fonction == 'rien.gif') { |
|
| 4383 | + $fonction = ''; |
|
| 4384 | + } elseif ($fonction == 'delsafe') { |
|
| 4385 | + $fonction = 'del'; |
|
| 4386 | + } |
|
| 4387 | + |
|
| 4388 | + $fond_origine = $fond; |
|
| 4389 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4390 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4391 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4392 | + } |
|
| 4393 | + |
|
| 4394 | + // Ajouter le type d'objet dans la classe |
|
| 4395 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4396 | + $class_lien .= " $objet_type"; |
|
| 4397 | + $class_bouton .= " $objet_type"; |
|
| 4398 | + |
|
| 4399 | + // Texte |
|
| 4400 | + $alt = attribut_html($texte); |
|
| 4401 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4402 | + |
|
| 4403 | + // Liens : préparer les classes ajax |
|
| 4404 | + $ajax = ''; |
|
| 4405 | + if ($type === 'lien') { |
|
| 4406 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4407 | + $ajax = 'ajax'; |
|
| 4408 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4409 | + $ajax .= ' preload'; |
|
| 4410 | + } |
|
| 4411 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4412 | + $ajax .= ' nocache'; |
|
| 4413 | + } |
|
| 4414 | + $ajax = " class='$ajax'"; |
|
| 4415 | + } |
|
| 4416 | + } |
|
| 4417 | + |
|
| 4418 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4419 | + $size = 24; |
|
| 4420 | + if ( |
|
| 4421 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4422 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4423 | + ) { |
|
| 4424 | + $size = $match[1]; |
|
| 4425 | + } |
|
| 4426 | + $class_lien .= " s$size"; |
|
| 4427 | + $class_bouton .= " s$size"; |
|
| 4428 | + |
|
| 4429 | + // Icône |
|
| 4430 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4431 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4432 | + |
|
| 4433 | + // Markup final |
|
| 4434 | + if ($type == 'lien') { |
|
| 4435 | + return "<span class='icone $class_lien'>" |
|
| 4436 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4437 | + . $icone |
|
| 4438 | + . "<b>$texte</b>" |
|
| 4439 | + . "</a></span>\n"; |
|
| 4440 | + } else { |
|
| 4441 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4442 | + } |
|
| 4443 | 4443 | } |
| 4444 | 4444 | |
| 4445 | 4445 | /** |
@@ -4463,7 +4463,7 @@ discard block |
||
| 4463 | 4463 | * Code HTML du lien |
| 4464 | 4464 | **/ |
| 4465 | 4465 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4466 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4466 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4467 | 4467 | } |
| 4468 | 4468 | |
| 4469 | 4469 | /** |
@@ -4498,7 +4498,7 @@ discard block |
||
| 4498 | 4498 | * Code HTML du lien |
| 4499 | 4499 | **/ |
| 4500 | 4500 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4501 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4501 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4502 | 4502 | } |
| 4503 | 4503 | |
| 4504 | 4504 | /** |
@@ -4543,7 +4543,7 @@ discard block |
||
| 4543 | 4543 | * Code HTML du lien |
| 4544 | 4544 | **/ |
| 4545 | 4545 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4546 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4546 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4547 | 4547 | } |
| 4548 | 4548 | |
| 4549 | 4549 | /** |
@@ -4574,7 +4574,7 @@ discard block |
||
| 4574 | 4574 | * Code HTML du lien |
| 4575 | 4575 | **/ |
| 4576 | 4576 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4577 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4577 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4578 | 4578 | } |
| 4579 | 4579 | |
| 4580 | 4580 | /** |
@@ -4605,7 +4605,7 @@ discard block |
||
| 4605 | 4605 | * Code HTML du lien |
| 4606 | 4606 | */ |
| 4607 | 4607 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4608 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4608 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4609 | 4609 | } |
| 4610 | 4610 | |
| 4611 | 4611 | |
@@ -4627,7 +4627,7 @@ discard block |
||
| 4627 | 4627 | * @return array Liste des éléments |
| 4628 | 4628 | */ |
| 4629 | 4629 | function filtre_explode_dist($a, $b) { |
| 4630 | - return explode($b, (string) $a); |
|
| 4630 | + return explode($b, (string) $a); |
|
| 4631 | 4631 | } |
| 4632 | 4632 | |
| 4633 | 4633 | /** |
@@ -4648,7 +4648,7 @@ discard block |
||
| 4648 | 4648 | * @return string Texte |
| 4649 | 4649 | */ |
| 4650 | 4650 | function filtre_implode_dist($a, $b) { |
| 4651 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4651 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4652 | 4652 | } |
| 4653 | 4653 | |
| 4654 | 4654 | /** |
@@ -4657,24 +4657,24 @@ discard block |
||
| 4657 | 4657 | * @return string Code CSS |
| 4658 | 4658 | */ |
| 4659 | 4659 | function bando_images_background() { |
| 4660 | - include_spip('inc/bandeau'); |
|
| 4661 | - // recuperer tous les boutons et leurs images |
|
| 4662 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4660 | + include_spip('inc/bandeau'); |
|
| 4661 | + // recuperer tous les boutons et leurs images |
|
| 4662 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4663 | 4663 | |
| 4664 | - $res = ''; |
|
| 4665 | - foreach ($boutons as $page => $detail) { |
|
| 4666 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4667 | - if (is_array($detail->sousmenu)) { |
|
| 4668 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4669 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4670 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4671 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4672 | - } |
|
| 4673 | - } |
|
| 4674 | - } |
|
| 4675 | - } |
|
| 4664 | + $res = ''; |
|
| 4665 | + foreach ($boutons as $page => $detail) { |
|
| 4666 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4667 | + if (is_array($detail->sousmenu)) { |
|
| 4668 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4669 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4670 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4671 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4672 | + } |
|
| 4673 | + } |
|
| 4674 | + } |
|
| 4675 | + } |
|
| 4676 | 4676 | |
| 4677 | - return $res; |
|
| 4677 | + return $res; |
|
| 4678 | 4678 | } |
| 4679 | 4679 | |
| 4680 | 4680 | /** |
@@ -4699,27 +4699,27 @@ discard block |
||
| 4699 | 4699 | */ |
| 4700 | 4700 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4701 | 4701 | |
| 4702 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4703 | - $class_form = ''; |
|
| 4704 | - if (strpos($class, 'ajax') !== false) { |
|
| 4705 | - $class_form = 'ajax'; |
|
| 4706 | - $class = str_replace('ajax', '', $class); |
|
| 4707 | - } |
|
| 4708 | - $class_btn = 'submit ' . trim($class); |
|
| 4702 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4703 | + $class_form = ''; |
|
| 4704 | + if (strpos($class, 'ajax') !== false) { |
|
| 4705 | + $class_form = 'ajax'; |
|
| 4706 | + $class = str_replace('ajax', '', $class); |
|
| 4707 | + } |
|
| 4708 | + $class_btn = 'submit ' . trim($class); |
|
| 4709 | 4709 | |
| 4710 | - if ($confirm) { |
|
| 4711 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4712 | - if ($callback) { |
|
| 4713 | - $callback = "$confirm?($callback):false"; |
|
| 4714 | - } else { |
|
| 4715 | - $callback = $confirm; |
|
| 4716 | - } |
|
| 4717 | - } |
|
| 4718 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4719 | - $title = $title ? " title='$title'" : ''; |
|
| 4710 | + if ($confirm) { |
|
| 4711 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4712 | + if ($callback) { |
|
| 4713 | + $callback = "$confirm?($callback):false"; |
|
| 4714 | + } else { |
|
| 4715 | + $callback = $confirm; |
|
| 4716 | + } |
|
| 4717 | + } |
|
| 4718 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4719 | + $title = $title ? " title='$title'" : ''; |
|
| 4720 | 4720 | |
| 4721 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4722 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4721 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4722 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4723 | 4723 | } |
| 4724 | 4724 | |
| 4725 | 4725 | /** |
@@ -4742,101 +4742,101 @@ discard block |
||
| 4742 | 4742 | * @return string |
| 4743 | 4743 | */ |
| 4744 | 4744 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4745 | - static $trouver_table = null; |
|
| 4746 | - static $objets; |
|
| 4747 | - |
|
| 4748 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4749 | - $id_objet = intval($id_objet); |
|
| 4750 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4751 | - return ''; |
|
| 4752 | - } |
|
| 4753 | - |
|
| 4754 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4755 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4756 | - return ''; |
|
| 4757 | - } |
|
| 4758 | - |
|
| 4759 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4760 | - if ($info == 'url') { |
|
| 4761 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4762 | - } |
|
| 4763 | - |
|
| 4764 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4765 | - $demande_titre = ($info === 'titre'); |
|
| 4766 | - $demande_introduction = ($info === 'introduction'); |
|
| 4767 | - |
|
| 4768 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4769 | - if ( |
|
| 4770 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4771 | - or |
|
| 4772 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4773 | - ) { |
|
| 4774 | - if (!$trouver_table) { |
|
| 4775 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4776 | - } |
|
| 4777 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4778 | - if (!$desc) { |
|
| 4779 | - return $objets[$type_objet] = false; |
|
| 4780 | - } |
|
| 4781 | - |
|
| 4782 | - // Si on demande le titre, on le gere en interne |
|
| 4783 | - $champ_titre = ''; |
|
| 4784 | - if ($demande_titre) { |
|
| 4785 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4786 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4787 | - } |
|
| 4788 | - include_spip('base/abstract_sql'); |
|
| 4789 | - include_spip('base/connect_sql'); |
|
| 4790 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4791 | - '*' . $champ_titre, |
|
| 4792 | - $desc['table_sql'], |
|
| 4793 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4794 | - ); |
|
| 4795 | - |
|
| 4796 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4797 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4798 | - } |
|
| 4799 | - |
|
| 4800 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4801 | - // ajouter la longueur au début des params supplémentaires |
|
| 4802 | - if ($demande_introduction) { |
|
| 4803 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4804 | - array_unshift($params, $introduction_longueur); |
|
| 4805 | - } |
|
| 4806 | - |
|
| 4807 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4808 | - if ( |
|
| 4809 | - $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4810 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4811 | - or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4812 | - ) { |
|
| 4813 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4814 | - } |
|
| 4815 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4816 | - elseif ( |
|
| 4817 | - $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4818 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4819 | - or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4820 | - ) { |
|
| 4821 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4822 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4823 | - else { |
|
| 4824 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4825 | - } |
|
| 4826 | - |
|
| 4827 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4828 | - if (!$etoile) { |
|
| 4829 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4830 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4831 | - $info_generee = appliquer_traitement_champ( |
|
| 4832 | - $info_generee, |
|
| 4833 | - $info, |
|
| 4834 | - table_objet($type_objet), |
|
| 4835 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4836 | - ); |
|
| 4837 | - } |
|
| 4838 | - |
|
| 4839 | - return $info_generee; |
|
| 4745 | + static $trouver_table = null; |
|
| 4746 | + static $objets; |
|
| 4747 | + |
|
| 4748 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4749 | + $id_objet = intval($id_objet); |
|
| 4750 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4751 | + return ''; |
|
| 4752 | + } |
|
| 4753 | + |
|
| 4754 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4755 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4756 | + return ''; |
|
| 4757 | + } |
|
| 4758 | + |
|
| 4759 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4760 | + if ($info == 'url') { |
|
| 4761 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4762 | + } |
|
| 4763 | + |
|
| 4764 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4765 | + $demande_titre = ($info === 'titre'); |
|
| 4766 | + $demande_introduction = ($info === 'introduction'); |
|
| 4767 | + |
|
| 4768 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4769 | + if ( |
|
| 4770 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4771 | + or |
|
| 4772 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4773 | + ) { |
|
| 4774 | + if (!$trouver_table) { |
|
| 4775 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4776 | + } |
|
| 4777 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4778 | + if (!$desc) { |
|
| 4779 | + return $objets[$type_objet] = false; |
|
| 4780 | + } |
|
| 4781 | + |
|
| 4782 | + // Si on demande le titre, on le gere en interne |
|
| 4783 | + $champ_titre = ''; |
|
| 4784 | + if ($demande_titre) { |
|
| 4785 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4786 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4787 | + } |
|
| 4788 | + include_spip('base/abstract_sql'); |
|
| 4789 | + include_spip('base/connect_sql'); |
|
| 4790 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4791 | + '*' . $champ_titre, |
|
| 4792 | + $desc['table_sql'], |
|
| 4793 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4794 | + ); |
|
| 4795 | + |
|
| 4796 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4797 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4798 | + } |
|
| 4799 | + |
|
| 4800 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4801 | + // ajouter la longueur au début des params supplémentaires |
|
| 4802 | + if ($demande_introduction) { |
|
| 4803 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4804 | + array_unshift($params, $introduction_longueur); |
|
| 4805 | + } |
|
| 4806 | + |
|
| 4807 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4808 | + if ( |
|
| 4809 | + $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4810 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4811 | + or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4812 | + ) { |
|
| 4813 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4814 | + } |
|
| 4815 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4816 | + elseif ( |
|
| 4817 | + $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4818 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4819 | + or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4820 | + ) { |
|
| 4821 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4822 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4823 | + else { |
|
| 4824 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4825 | + } |
|
| 4826 | + |
|
| 4827 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4828 | + if (!$etoile) { |
|
| 4829 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4830 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4831 | + $info_generee = appliquer_traitement_champ( |
|
| 4832 | + $info_generee, |
|
| 4833 | + $info, |
|
| 4834 | + table_objet($type_objet), |
|
| 4835 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4836 | + ); |
|
| 4837 | + } |
|
| 4838 | + |
|
| 4839 | + return $info_generee; |
|
| 4840 | 4840 | } |
| 4841 | 4841 | |
| 4842 | 4842 | /** |
@@ -4844,7 +4844,7 @@ discard block |
||
| 4844 | 4844 | * @see generer_objet_info |
| 4845 | 4845 | */ |
| 4846 | 4846 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4847 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4847 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4848 | 4848 | } |
| 4849 | 4849 | |
| 4850 | 4850 | /** |
@@ -4877,36 +4877,36 @@ discard block |
||
| 4877 | 4877 | */ |
| 4878 | 4878 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4879 | 4879 | |
| 4880 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4881 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4882 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4883 | - if (isset($ligne_sql['chapo'])) { |
|
| 4884 | - $chapo = $ligne_sql['chapo']; |
|
| 4885 | - $texte = strlen($descriptif) ? |
|
| 4886 | - '' : |
|
| 4887 | - "$chapo \n\n $texte"; |
|
| 4888 | - } |
|
| 4880 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4881 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4882 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4883 | + if (isset($ligne_sql['chapo'])) { |
|
| 4884 | + $chapo = $ligne_sql['chapo']; |
|
| 4885 | + $texte = strlen($descriptif) ? |
|
| 4886 | + '' : |
|
| 4887 | + "$chapo \n\n $texte"; |
|
| 4888 | + } |
|
| 4889 | 4889 | |
| 4890 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4891 | - if (!intval($longueur_ou_suite)) { |
|
| 4892 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4893 | - } else { |
|
| 4894 | - $longueur = intval($longueur_ou_suite); |
|
| 4895 | - } |
|
| 4890 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4891 | + if (!intval($longueur_ou_suite)) { |
|
| 4892 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4893 | + } else { |
|
| 4894 | + $longueur = intval($longueur_ou_suite); |
|
| 4895 | + } |
|
| 4896 | 4896 | |
| 4897 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4898 | - // Ex : #INTRODUCTION{...} |
|
| 4899 | - if ( |
|
| 4900 | - is_null($suite) |
|
| 4901 | - and !intval($longueur_ou_suite) |
|
| 4902 | - ) { |
|
| 4903 | - $suite = $longueur_ou_suite; |
|
| 4904 | - } |
|
| 4897 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4898 | + // Ex : #INTRODUCTION{...} |
|
| 4899 | + if ( |
|
| 4900 | + is_null($suite) |
|
| 4901 | + and !intval($longueur_ou_suite) |
|
| 4902 | + ) { |
|
| 4903 | + $suite = $longueur_ou_suite; |
|
| 4904 | + } |
|
| 4905 | 4905 | |
| 4906 | - $f = chercher_filtre('introduction'); |
|
| 4907 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4906 | + $f = chercher_filtre('introduction'); |
|
| 4907 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4908 | 4908 | |
| 4909 | - return $introduction; |
|
| 4909 | + return $introduction; |
|
| 4910 | 4910 | } |
| 4911 | 4911 | |
| 4912 | 4912 | /** |
@@ -4914,7 +4914,7 @@ discard block |
||
| 4914 | 4914 | * @see generer_objet_introduction |
| 4915 | 4915 | */ |
| 4916 | 4916 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4917 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4917 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4918 | 4918 | } |
| 4919 | 4919 | |
| 4920 | 4920 | /** |
@@ -4928,44 +4928,44 @@ discard block |
||
| 4928 | 4928 | * @return string |
| 4929 | 4929 | */ |
| 4930 | 4930 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4931 | - if (!$champ) { |
|
| 4932 | - return $texte; |
|
| 4933 | - } |
|
| 4931 | + if (!$champ) { |
|
| 4932 | + return $texte; |
|
| 4933 | + } |
|
| 4934 | 4934 | |
| 4935 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4936 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4937 | - include_fichiers_fonctions(); |
|
| 4935 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4936 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4937 | + include_fichiers_fonctions(); |
|
| 4938 | 4938 | |
| 4939 | - $champ = strtoupper($champ); |
|
| 4940 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4941 | - if (!$traitements or !is_array($traitements)) { |
|
| 4942 | - return $texte; |
|
| 4943 | - } |
|
| 4939 | + $champ = strtoupper($champ); |
|
| 4940 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4941 | + if (!$traitements or !is_array($traitements)) { |
|
| 4942 | + return $texte; |
|
| 4943 | + } |
|
| 4944 | 4944 | |
| 4945 | - $traitement = ''; |
|
| 4946 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4947 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4948 | - $table_objet = table_objet($table_objet); |
|
| 4949 | - if (isset($traitements[$table_objet])) { |
|
| 4950 | - $traitement = $traitements[$table_objet]; |
|
| 4951 | - } |
|
| 4952 | - } |
|
| 4953 | - if (!$traitement and isset($traitements[0])) { |
|
| 4954 | - $traitement = $traitements[0]; |
|
| 4955 | - } |
|
| 4956 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4945 | + $traitement = ''; |
|
| 4946 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4947 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4948 | + $table_objet = table_objet($table_objet); |
|
| 4949 | + if (isset($traitements[$table_objet])) { |
|
| 4950 | + $traitement = $traitements[$table_objet]; |
|
| 4951 | + } |
|
| 4952 | + } |
|
| 4953 | + if (!$traitement and isset($traitements[0])) { |
|
| 4954 | + $traitement = $traitements[0]; |
|
| 4955 | + } |
|
| 4956 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4957 | 4957 | |
| 4958 | - if (!$traitement) { |
|
| 4959 | - return $texte; |
|
| 4960 | - } |
|
| 4958 | + if (!$traitement) { |
|
| 4959 | + return $texte; |
|
| 4960 | + } |
|
| 4961 | 4961 | |
| 4962 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4962 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4963 | 4963 | |
| 4964 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4965 | - $Pile = [0 => $env]; |
|
| 4966 | - eval("\$texte = $traitement;"); |
|
| 4964 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4965 | + $Pile = [0 => $env]; |
|
| 4966 | + eval("\$texte = $traitement;"); |
|
| 4967 | 4967 | |
| 4968 | - return $texte; |
|
| 4968 | + return $texte; |
|
| 4969 | 4969 | } |
| 4970 | 4970 | |
| 4971 | 4971 | |
@@ -4979,21 +4979,21 @@ discard block |
||
| 4979 | 4979 | * @return string |
| 4980 | 4980 | */ |
| 4981 | 4981 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4982 | - include_spip('inc/liens'); |
|
| 4983 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4984 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4985 | - // le raccourcis n'est plus valide |
|
| 4986 | - $titre = typo($titre['titre']) ?? ''; |
|
| 4987 | - // on essaye avec generer_info_entite ? |
|
| 4988 | - if (!strlen($titre) and !$connect) { |
|
| 4989 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4990 | - } |
|
| 4991 | - if (!strlen($titre)) { |
|
| 4992 | - $titre = _T('info_sans_titre'); |
|
| 4993 | - } |
|
| 4994 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4982 | + include_spip('inc/liens'); |
|
| 4983 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4984 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4985 | + // le raccourcis n'est plus valide |
|
| 4986 | + $titre = typo($titre['titre']) ?? ''; |
|
| 4987 | + // on essaye avec generer_info_entite ? |
|
| 4988 | + if (!strlen($titre) and !$connect) { |
|
| 4989 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4990 | + } |
|
| 4991 | + if (!strlen($titre)) { |
|
| 4992 | + $titre = _T('info_sans_titre'); |
|
| 4993 | + } |
|
| 4994 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4995 | 4995 | |
| 4996 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4996 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4997 | 4997 | } |
| 4998 | 4998 | |
| 4999 | 4999 | /** |
@@ -5001,7 +5001,7 @@ discard block |
||
| 5001 | 5001 | * @see generer_objet_lien |
| 5002 | 5002 | */ |
| 5003 | 5003 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 5004 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5004 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5005 | 5005 | } |
| 5006 | 5006 | |
| 5007 | 5007 | /** |
@@ -5017,15 +5017,15 @@ discard block |
||
| 5017 | 5017 | * @return string |
| 5018 | 5018 | */ |
| 5019 | 5019 | function wrap($texte, $wrap) { |
| 5020 | - $balises = extraire_balises($wrap); |
|
| 5021 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5022 | - $texte = $wrap . $texte; |
|
| 5023 | - $regs = array_reverse($regs[1]); |
|
| 5024 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5025 | - $texte = $texte . $wrap; |
|
| 5026 | - } |
|
| 5020 | + $balises = extraire_balises($wrap); |
|
| 5021 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5022 | + $texte = $wrap . $texte; |
|
| 5023 | + $regs = array_reverse($regs[1]); |
|
| 5024 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5025 | + $texte = $texte . $wrap; |
|
| 5026 | + } |
|
| 5027 | 5027 | |
| 5028 | - return $texte; |
|
| 5028 | + return $texte; |
|
| 5029 | 5029 | } |
| 5030 | 5030 | |
| 5031 | 5031 | |
@@ -5045,44 +5045,44 @@ discard block |
||
| 5045 | 5045 | * @return array|mixed|string |
| 5046 | 5046 | */ |
| 5047 | 5047 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 5048 | - if (is_string($u)) { |
|
| 5049 | - $u = typo($u); |
|
| 5048 | + if (is_string($u)) { |
|
| 5049 | + $u = typo($u); |
|
| 5050 | 5050 | |
| 5051 | - return $u; |
|
| 5052 | - } |
|
| 5051 | + return $u; |
|
| 5052 | + } |
|
| 5053 | 5053 | |
| 5054 | - // caster $u en array si besoin |
|
| 5055 | - if (is_object($u)) { |
|
| 5056 | - $u = (array)$u; |
|
| 5057 | - } |
|
| 5054 | + // caster $u en array si besoin |
|
| 5055 | + if (is_object($u)) { |
|
| 5056 | + $u = (array)$u; |
|
| 5057 | + } |
|
| 5058 | 5058 | |
| 5059 | - if (is_array($u)) { |
|
| 5060 | - $out = ''; |
|
| 5061 | - // toutes les cles sont numeriques ? |
|
| 5062 | - // et aucun enfant n'est un tableau |
|
| 5063 | - // liste simple separee par des virgules |
|
| 5064 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5065 | - $array_values = array_map('is_array', $u); |
|
| 5066 | - $object_values = array_map('is_object', $u); |
|
| 5067 | - if ( |
|
| 5068 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 5069 | - and !array_sum($array_values) |
|
| 5070 | - and !array_sum($object_values) |
|
| 5071 | - ) { |
|
| 5072 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5073 | - } |
|
| 5059 | + if (is_array($u)) { |
|
| 5060 | + $out = ''; |
|
| 5061 | + // toutes les cles sont numeriques ? |
|
| 5062 | + // et aucun enfant n'est un tableau |
|
| 5063 | + // liste simple separee par des virgules |
|
| 5064 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5065 | + $array_values = array_map('is_array', $u); |
|
| 5066 | + $object_values = array_map('is_object', $u); |
|
| 5067 | + if ( |
|
| 5068 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 5069 | + and !array_sum($array_values) |
|
| 5070 | + and !array_sum($object_values) |
|
| 5071 | + ) { |
|
| 5072 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5073 | + } |
|
| 5074 | 5074 | |
| 5075 | - // sinon on passe a la ligne et on indente |
|
| 5076 | - $i_str = str_pad('', $indent, ' '); |
|
| 5077 | - foreach ($u as $k => $v) { |
|
| 5078 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5079 | - } |
|
| 5075 | + // sinon on passe a la ligne et on indente |
|
| 5076 | + $i_str = str_pad('', $indent, ' '); |
|
| 5077 | + foreach ($u as $k => $v) { |
|
| 5078 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5079 | + } |
|
| 5080 | 5080 | |
| 5081 | - return $out; |
|
| 5082 | - } |
|
| 5081 | + return $out; |
|
| 5082 | + } |
|
| 5083 | 5083 | |
| 5084 | - // on sait pas quoi faire... |
|
| 5085 | - return $u; |
|
| 5084 | + // on sait pas quoi faire... |
|
| 5085 | + return $u; |
|
| 5086 | 5086 | } |
| 5087 | 5087 | |
| 5088 | 5088 | |
@@ -5095,10 +5095,10 @@ discard block |
||
| 5095 | 5095 | * @return string|array |
| 5096 | 5096 | */ |
| 5097 | 5097 | function objet_info($objet, $info) { |
| 5098 | - $table = table_objet_sql($objet); |
|
| 5099 | - $infos = lister_tables_objets_sql($table); |
|
| 5098 | + $table = table_objet_sql($objet); |
|
| 5099 | + $infos = lister_tables_objets_sql($table); |
|
| 5100 | 5100 | |
| 5101 | - return ($infos[$info] ?? ''); |
|
| 5101 | + return ($infos[$info] ?? ''); |
|
| 5102 | 5102 | } |
| 5103 | 5103 | |
| 5104 | 5104 | /** |
@@ -5113,11 +5113,11 @@ discard block |
||
| 5113 | 5113 | * Texte traduit du comptage, tel que '3 articles' |
| 5114 | 5114 | */ |
| 5115 | 5115 | function objet_afficher_nb($nb, $objet) { |
| 5116 | - if (!$nb) { |
|
| 5117 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5118 | - } else { |
|
| 5119 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5120 | - } |
|
| 5116 | + if (!$nb) { |
|
| 5117 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5118 | + } else { |
|
| 5119 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5120 | + } |
|
| 5121 | 5121 | } |
| 5122 | 5122 | |
| 5123 | 5123 | /** |
@@ -5129,11 +5129,11 @@ discard block |
||
| 5129 | 5129 | * @return string |
| 5130 | 5130 | */ |
| 5131 | 5131 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5132 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5133 | - $icone = chemin_image($icone); |
|
| 5134 | - $balise_img = charger_filtre('balise_img'); |
|
| 5132 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5133 | + $icone = chemin_image($icone); |
|
| 5134 | + $balise_img = charger_filtre('balise_img'); |
|
| 5135 | 5135 | |
| 5136 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5136 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5137 | 5137 | } |
| 5138 | 5138 | |
| 5139 | 5139 | /** |
@@ -5154,12 +5154,12 @@ discard block |
||
| 5154 | 5154 | * @return string |
| 5155 | 5155 | */ |
| 5156 | 5156 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5157 | - $chaine = explode(':', $chaine); |
|
| 5158 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5159 | - return $t; |
|
| 5160 | - } |
|
| 5161 | - $chaine = implode(':', $chaine); |
|
| 5162 | - return _T($chaine, $args, $options); |
|
| 5157 | + $chaine = explode(':', $chaine); |
|
| 5158 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5159 | + return $t; |
|
| 5160 | + } |
|
| 5161 | + $chaine = implode(':', $chaine); |
|
| 5162 | + return _T($chaine, $args, $options); |
|
| 5163 | 5163 | } |
| 5164 | 5164 | |
| 5165 | 5165 | /** |
@@ -5173,18 +5173,18 @@ discard block |
||
| 5173 | 5173 | * @return string Code HTML |
| 5174 | 5174 | */ |
| 5175 | 5175 | function insert_head_css_conditionnel($flux) { |
| 5176 | - if ( |
|
| 5177 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5178 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5179 | - ) { |
|
| 5180 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5181 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5182 | - $p = $p1; |
|
| 5183 | - } |
|
| 5184 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5185 | - } |
|
| 5176 | + if ( |
|
| 5177 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5178 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5179 | + ) { |
|
| 5180 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5181 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5182 | + $p = $p1; |
|
| 5183 | + } |
|
| 5184 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5185 | + } |
|
| 5186 | 5186 | |
| 5187 | - return $flux; |
|
| 5187 | + return $flux; |
|
| 5188 | 5188 | } |
| 5189 | 5189 | |
| 5190 | 5190 | /** |
@@ -5207,72 +5207,72 @@ discard block |
||
| 5207 | 5207 | * @return string |
| 5208 | 5208 | */ |
| 5209 | 5209 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5210 | - if (isset($contexte['format'])) { |
|
| 5211 | - $extension = $contexte['format']; |
|
| 5212 | - unset($contexte['format']); |
|
| 5213 | - } else { |
|
| 5214 | - $extension = 'html'; |
|
| 5215 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5216 | - $extension = $m[1]; |
|
| 5217 | - } |
|
| 5218 | - } |
|
| 5219 | - // recuperer le contenu produit par le squelette |
|
| 5220 | - $options['raw'] = true; |
|
| 5221 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5222 | - |
|
| 5223 | - // calculer le nom de la css |
|
| 5224 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5225 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5226 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5227 | - |
|
| 5228 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5229 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5230 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5231 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5232 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5233 | - } |
|
| 5234 | - else { |
|
| 5235 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5236 | - ksort($contexte); |
|
| 5237 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5238 | - } |
|
| 5239 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5240 | - |
|
| 5241 | - // mettre a jour le fichier si il n'existe pas |
|
| 5242 | - // ou trop ancien |
|
| 5243 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5244 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5245 | - if ( |
|
| 5246 | - !file_exists($filename) |
|
| 5247 | - or !file_exists($filename . '.last') |
|
| 5248 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5249 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5250 | - ) { |
|
| 5251 | - $contenu = $cache['texte']; |
|
| 5252 | - // passer les urls en absolu si c'est une css |
|
| 5253 | - if ($extension == 'css') { |
|
| 5254 | - $contenu = urls_absolues_css( |
|
| 5255 | - $contenu, |
|
| 5256 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5257 | - ); |
|
| 5258 | - } |
|
| 5259 | - |
|
| 5260 | - $comment = ''; |
|
| 5261 | - // ne pas insérer de commentaire sur certains formats |
|
| 5262 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5263 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5264 | - foreach ($contexte as $k => $v) { |
|
| 5265 | - $comment .= ",$k=$v"; |
|
| 5266 | - } |
|
| 5267 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5268 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5269 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5270 | - } |
|
| 5271 | - // et ecrire le fichier si il change |
|
| 5272 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5273 | - } |
|
| 5274 | - |
|
| 5275 | - return timestamp($filename); |
|
| 5210 | + if (isset($contexte['format'])) { |
|
| 5211 | + $extension = $contexte['format']; |
|
| 5212 | + unset($contexte['format']); |
|
| 5213 | + } else { |
|
| 5214 | + $extension = 'html'; |
|
| 5215 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5216 | + $extension = $m[1]; |
|
| 5217 | + } |
|
| 5218 | + } |
|
| 5219 | + // recuperer le contenu produit par le squelette |
|
| 5220 | + $options['raw'] = true; |
|
| 5221 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5222 | + |
|
| 5223 | + // calculer le nom de la css |
|
| 5224 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5225 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5226 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5227 | + |
|
| 5228 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5229 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5230 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5231 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5232 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5233 | + } |
|
| 5234 | + else { |
|
| 5235 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5236 | + ksort($contexte); |
|
| 5237 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5238 | + } |
|
| 5239 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5240 | + |
|
| 5241 | + // mettre a jour le fichier si il n'existe pas |
|
| 5242 | + // ou trop ancien |
|
| 5243 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5244 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5245 | + if ( |
|
| 5246 | + !file_exists($filename) |
|
| 5247 | + or !file_exists($filename . '.last') |
|
| 5248 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5249 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5250 | + ) { |
|
| 5251 | + $contenu = $cache['texte']; |
|
| 5252 | + // passer les urls en absolu si c'est une css |
|
| 5253 | + if ($extension == 'css') { |
|
| 5254 | + $contenu = urls_absolues_css( |
|
| 5255 | + $contenu, |
|
| 5256 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5257 | + ); |
|
| 5258 | + } |
|
| 5259 | + |
|
| 5260 | + $comment = ''; |
|
| 5261 | + // ne pas insérer de commentaire sur certains formats |
|
| 5262 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5263 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5264 | + foreach ($contexte as $k => $v) { |
|
| 5265 | + $comment .= ",$k=$v"; |
|
| 5266 | + } |
|
| 5267 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5268 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5269 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5270 | + } |
|
| 5271 | + // et ecrire le fichier si il change |
|
| 5272 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5273 | + } |
|
| 5274 | + |
|
| 5275 | + return timestamp($filename); |
|
| 5276 | 5276 | } |
| 5277 | 5277 | |
| 5278 | 5278 | /** |
@@ -5285,15 +5285,15 @@ discard block |
||
| 5285 | 5285 | * $fichier auquel on a ajouté le timestamp |
| 5286 | 5286 | */ |
| 5287 | 5287 | function timestamp($fichier) { |
| 5288 | - if ( |
|
| 5289 | - !$fichier |
|
| 5290 | - or !file_exists($fichier) |
|
| 5291 | - or !$m = filemtime($fichier) |
|
| 5292 | - ) { |
|
| 5293 | - return $fichier; |
|
| 5294 | - } |
|
| 5288 | + if ( |
|
| 5289 | + !$fichier |
|
| 5290 | + or !file_exists($fichier) |
|
| 5291 | + or !$m = filemtime($fichier) |
|
| 5292 | + ) { |
|
| 5293 | + return $fichier; |
|
| 5294 | + } |
|
| 5295 | 5295 | |
| 5296 | - return "$fichier?$m"; |
|
| 5296 | + return "$fichier?$m"; |
|
| 5297 | 5297 | } |
| 5298 | 5298 | |
| 5299 | 5299 | /** |
@@ -5303,11 +5303,11 @@ discard block |
||
| 5303 | 5303 | * @return string |
| 5304 | 5304 | */ |
| 5305 | 5305 | function supprimer_timestamp($url) { |
| 5306 | - if (strpos($url, '?') === false) { |
|
| 5307 | - return $url; |
|
| 5308 | - } |
|
| 5306 | + if (strpos($url, '?') === false) { |
|
| 5307 | + return $url; |
|
| 5308 | + } |
|
| 5309 | 5309 | |
| 5310 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5310 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5311 | 5311 | } |
| 5312 | 5312 | |
| 5313 | 5313 | /** |
@@ -5322,9 +5322,9 @@ discard block |
||
| 5322 | 5322 | * @return string |
| 5323 | 5323 | */ |
| 5324 | 5324 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5325 | - include_spip('inc/envoyer_mail'); |
|
| 5325 | + include_spip('inc/envoyer_mail'); |
|
| 5326 | 5326 | |
| 5327 | - return nettoyer_titre_email($titre); |
|
| 5327 | + return nettoyer_titre_email($titre); |
|
| 5328 | 5328 | } |
| 5329 | 5329 | |
| 5330 | 5330 | /** |
@@ -5346,27 +5346,27 @@ discard block |
||
| 5346 | 5346 | * @return string |
| 5347 | 5347 | */ |
| 5348 | 5348 | function filtre_chercher_rubrique_dist( |
| 5349 | - $titre, |
|
| 5350 | - $id_objet, |
|
| 5351 | - $id_parent, |
|
| 5352 | - $objet, |
|
| 5353 | - $id_secteur, |
|
| 5354 | - $restreint, |
|
| 5355 | - $actionable = false, |
|
| 5356 | - $retour_sans_cadre = false |
|
| 5349 | + $titre, |
|
| 5350 | + $id_objet, |
|
| 5351 | + $id_parent, |
|
| 5352 | + $objet, |
|
| 5353 | + $id_secteur, |
|
| 5354 | + $restreint, |
|
| 5355 | + $actionable = false, |
|
| 5356 | + $retour_sans_cadre = false |
|
| 5357 | 5357 | ) { |
| 5358 | - include_spip('inc/filtres_ecrire'); |
|
| 5358 | + include_spip('inc/filtres_ecrire'); |
|
| 5359 | 5359 | |
| 5360 | - return chercher_rubrique( |
|
| 5361 | - $titre, |
|
| 5362 | - $id_objet, |
|
| 5363 | - $id_parent, |
|
| 5364 | - $objet, |
|
| 5365 | - $id_secteur, |
|
| 5366 | - $restreint, |
|
| 5367 | - $actionable, |
|
| 5368 | - $retour_sans_cadre |
|
| 5369 | - ); |
|
| 5360 | + return chercher_rubrique( |
|
| 5361 | + $titre, |
|
| 5362 | + $id_objet, |
|
| 5363 | + $id_parent, |
|
| 5364 | + $objet, |
|
| 5365 | + $id_secteur, |
|
| 5366 | + $restreint, |
|
| 5367 | + $actionable, |
|
| 5368 | + $retour_sans_cadre |
|
| 5369 | + ); |
|
| 5370 | 5370 | } |
| 5371 | 5371 | |
| 5372 | 5372 | /** |
@@ -5395,56 +5395,56 @@ discard block |
||
| 5395 | 5395 | * Chaîne vide si l'accès est autorisé |
| 5396 | 5396 | */ |
| 5397 | 5397 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5398 | - if ($ok) { |
|
| 5399 | - return ''; |
|
| 5400 | - } |
|
| 5401 | - |
|
| 5402 | - // Vider tous les tampons |
|
| 5403 | - $level = @ob_get_level(); |
|
| 5404 | - while ($level--) { |
|
| 5405 | - @ob_end_clean(); |
|
| 5406 | - } |
|
| 5407 | - |
|
| 5408 | - include_spip('inc/headers'); |
|
| 5409 | - |
|
| 5410 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5411 | - if ($url) { |
|
| 5412 | - redirige_par_entete($url, '', $statut); |
|
| 5413 | - } |
|
| 5414 | - |
|
| 5415 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5416 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5417 | - $message = $statut; |
|
| 5418 | - $statut = 0; |
|
| 5419 | - } |
|
| 5420 | - if (!$message) { |
|
| 5421 | - $message = ''; |
|
| 5422 | - } |
|
| 5423 | - $statut = intval($statut); |
|
| 5424 | - |
|
| 5425 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5426 | - if (test_espace_prive()) { |
|
| 5427 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5428 | - $statut = 403; |
|
| 5429 | - } |
|
| 5430 | - http_response_code(403); |
|
| 5431 | - $echec = charger_fonction('403', 'exec'); |
|
| 5432 | - $echec($message); |
|
| 5433 | - } else { |
|
| 5434 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5435 | - if (!$statut) { |
|
| 5436 | - $statut = 404; |
|
| 5437 | - } |
|
| 5438 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5439 | - http_response_code($statut); |
|
| 5440 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5441 | - if ($statut >= 400) { |
|
| 5442 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5443 | - } |
|
| 5444 | - } |
|
| 5445 | - |
|
| 5446 | - |
|
| 5447 | - exit; |
|
| 5398 | + if ($ok) { |
|
| 5399 | + return ''; |
|
| 5400 | + } |
|
| 5401 | + |
|
| 5402 | + // Vider tous les tampons |
|
| 5403 | + $level = @ob_get_level(); |
|
| 5404 | + while ($level--) { |
|
| 5405 | + @ob_end_clean(); |
|
| 5406 | + } |
|
| 5407 | + |
|
| 5408 | + include_spip('inc/headers'); |
|
| 5409 | + |
|
| 5410 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5411 | + if ($url) { |
|
| 5412 | + redirige_par_entete($url, '', $statut); |
|
| 5413 | + } |
|
| 5414 | + |
|
| 5415 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5416 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5417 | + $message = $statut; |
|
| 5418 | + $statut = 0; |
|
| 5419 | + } |
|
| 5420 | + if (!$message) { |
|
| 5421 | + $message = ''; |
|
| 5422 | + } |
|
| 5423 | + $statut = intval($statut); |
|
| 5424 | + |
|
| 5425 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5426 | + if (test_espace_prive()) { |
|
| 5427 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5428 | + $statut = 403; |
|
| 5429 | + } |
|
| 5430 | + http_response_code(403); |
|
| 5431 | + $echec = charger_fonction('403', 'exec'); |
|
| 5432 | + $echec($message); |
|
| 5433 | + } else { |
|
| 5434 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5435 | + if (!$statut) { |
|
| 5436 | + $statut = 404; |
|
| 5437 | + } |
|
| 5438 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5439 | + http_response_code($statut); |
|
| 5440 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5441 | + if ($statut >= 400) { |
|
| 5442 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5443 | + } |
|
| 5444 | + } |
|
| 5445 | + |
|
| 5446 | + |
|
| 5447 | + exit; |
|
| 5448 | 5448 | } |
| 5449 | 5449 | |
| 5450 | 5450 | /** |
@@ -5455,11 +5455,11 @@ discard block |
||
| 5455 | 5455 | * @return string |
| 5456 | 5456 | */ |
| 5457 | 5457 | function filtre_compacte_dist($source, $format = null) { |
| 5458 | - if (function_exists('minifier')) { |
|
| 5459 | - return minifier($source, $format); |
|
| 5460 | - } |
|
| 5458 | + if (function_exists('minifier')) { |
|
| 5459 | + return minifier($source, $format); |
|
| 5460 | + } |
|
| 5461 | 5461 | |
| 5462 | - return $source; |
|
| 5462 | + return $source; |
|
| 5463 | 5463 | } |
| 5464 | 5464 | |
| 5465 | 5465 | |
@@ -5471,31 +5471,31 @@ discard block |
||
| 5471 | 5471 | * @return string |
| 5472 | 5472 | */ |
| 5473 | 5473 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5474 | - $l = strlen($passe); |
|
| 5475 | - |
|
| 5476 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5477 | - if (!$l) { |
|
| 5478 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5479 | - } |
|
| 5480 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5481 | - } |
|
| 5482 | - |
|
| 5483 | - if (is_null($portion_pourcent)) { |
|
| 5484 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5485 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5486 | - } |
|
| 5487 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5488 | - } |
|
| 5489 | - if ($portion_pourcent >= 100) { |
|
| 5490 | - return $passe; |
|
| 5491 | - } |
|
| 5492 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5493 | - $e = max($e, 0); |
|
| 5494 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5495 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5496 | - $mid = '***...***'; |
|
| 5497 | - } |
|
| 5498 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5474 | + $l = strlen($passe); |
|
| 5475 | + |
|
| 5476 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5477 | + if (!$l) { |
|
| 5478 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5479 | + } |
|
| 5480 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5481 | + } |
|
| 5482 | + |
|
| 5483 | + if (is_null($portion_pourcent)) { |
|
| 5484 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5485 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5486 | + } |
|
| 5487 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5488 | + } |
|
| 5489 | + if ($portion_pourcent >= 100) { |
|
| 5490 | + return $passe; |
|
| 5491 | + } |
|
| 5492 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5493 | + $e = max($e, 0); |
|
| 5494 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5495 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5496 | + $mid = '***...***'; |
|
| 5497 | + } |
|
| 5498 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5499 | 5499 | } |
| 5500 | 5500 | |
| 5501 | 5501 | |
@@ -5516,64 +5516,64 @@ discard block |
||
| 5516 | 5516 | */ |
| 5517 | 5517 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5518 | 5518 | |
| 5519 | - $original = $texte; |
|
| 5520 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5521 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5522 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5519 | + $original = $texte; |
|
| 5520 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5521 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5522 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5523 | 5523 | |
| 5524 | - if (!function_exists('translitteration')) { |
|
| 5525 | - include_spip('inc/charsets'); |
|
| 5526 | - } |
|
| 5524 | + if (!function_exists('translitteration')) { |
|
| 5525 | + include_spip('inc/charsets'); |
|
| 5526 | + } |
|
| 5527 | 5527 | |
| 5528 | - // pas de balise html |
|
| 5529 | - if (strpos($texte, '<') !== false) { |
|
| 5530 | - $texte = strip_tags($texte); |
|
| 5531 | - } |
|
| 5532 | - if (strpos($texte, '&') !== false) { |
|
| 5533 | - $texte = unicode2charset($texte); |
|
| 5534 | - } |
|
| 5535 | - // On enlève les espaces indésirables |
|
| 5536 | - $texte = trim($texte); |
|
| 5528 | + // pas de balise html |
|
| 5529 | + if (strpos($texte, '<') !== false) { |
|
| 5530 | + $texte = strip_tags($texte); |
|
| 5531 | + } |
|
| 5532 | + if (strpos($texte, '&') !== false) { |
|
| 5533 | + $texte = unicode2charset($texte); |
|
| 5534 | + } |
|
| 5535 | + // On enlève les espaces indésirables |
|
| 5536 | + $texte = trim($texte); |
|
| 5537 | 5537 | |
| 5538 | - // On enlève les accents et cie |
|
| 5539 | - $texte = translitteration($texte); |
|
| 5538 | + // On enlève les accents et cie |
|
| 5539 | + $texte = translitteration($texte); |
|
| 5540 | 5540 | |
| 5541 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5542 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5541 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5542 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5543 | 5543 | |
| 5544 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5545 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5546 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5547 | - } |
|
| 5544 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5545 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5546 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5547 | + } |
|
| 5548 | 5548 | |
| 5549 | - // pas de separateur au debut ni a la fin |
|
| 5550 | - $texte = trim($texte, $separateur); |
|
| 5549 | + // pas de separateur au debut ni a la fin |
|
| 5550 | + $texte = trim($texte, $separateur); |
|
| 5551 | 5551 | |
| 5552 | - // en minuscules |
|
| 5553 | - $texte = strtolower($texte); |
|
| 5552 | + // en minuscules |
|
| 5553 | + $texte = strtolower($texte); |
|
| 5554 | 5554 | |
| 5555 | - switch ($type) { |
|
| 5556 | - case 'class': |
|
| 5557 | - case 'id': |
|
| 5558 | - case 'anchor': |
|
| 5559 | - if (preg_match(',^\d,', $texte)) { |
|
| 5560 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5561 | - } |
|
| 5562 | - } |
|
| 5555 | + switch ($type) { |
|
| 5556 | + case 'class': |
|
| 5557 | + case 'id': |
|
| 5558 | + case 'anchor': |
|
| 5559 | + if (preg_match(',^\d,', $texte)) { |
|
| 5560 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5561 | + } |
|
| 5562 | + } |
|
| 5563 | 5563 | |
| 5564 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5565 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5566 | - } |
|
| 5564 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5565 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5566 | + } |
|
| 5567 | 5567 | |
| 5568 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5569 | - if (preg_match(',^\d,', $texte)) { |
|
| 5570 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5571 | - } |
|
| 5572 | - $texte .= $separateur . md5($original); |
|
| 5573 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5574 | - } |
|
| 5568 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5569 | + if (preg_match(',^\d,', $texte)) { |
|
| 5570 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5571 | + } |
|
| 5572 | + $texte .= $separateur . md5($original); |
|
| 5573 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5574 | + } |
|
| 5575 | 5575 | |
| 5576 | - return $texte; |
|
| 5576 | + return $texte; |
|
| 5577 | 5577 | } |
| 5578 | 5578 | |
| 5579 | 5579 | |
@@ -5594,11 +5594,11 @@ discard block |
||
| 5594 | 5594 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5595 | 5595 | */ |
| 5596 | 5596 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5597 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5598 | - if ($ucfirst) { |
|
| 5599 | - $label = spip_ucfirst($label); |
|
| 5600 | - } |
|
| 5601 | - return $label; |
|
| 5597 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5598 | + if ($ucfirst) { |
|
| 5599 | + $label = spip_ucfirst($label); |
|
| 5600 | + } |
|
| 5601 | + return $label; |
|
| 5602 | 5602 | } |
| 5603 | 5603 | |
| 5604 | 5604 | /** |
@@ -5611,8 +5611,8 @@ discard block |
||
| 5611 | 5611 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5612 | 5612 | */ |
| 5613 | 5613 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5614 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5615 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5614 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5615 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5616 | 5616 | } |
| 5617 | 5617 | |
| 5618 | 5618 | |
@@ -5625,19 +5625,19 @@ discard block |
||
| 5625 | 5625 | * @return array |
| 5626 | 5626 | */ |
| 5627 | 5627 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5628 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5629 | - return []; |
|
| 5630 | - } |
|
| 5628 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5629 | + return []; |
|
| 5630 | + } |
|
| 5631 | 5631 | |
| 5632 | - // compatibilite signature inversee |
|
| 5633 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5634 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5635 | - } |
|
| 5632 | + // compatibilite signature inversee |
|
| 5633 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5634 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5635 | + } |
|
| 5636 | 5636 | |
| 5637 | - if (!function_exists($fonction)) { |
|
| 5638 | - include_spip('base/objets'); |
|
| 5639 | - } |
|
| 5640 | - return $fonction($objet, $id_objet); |
|
| 5637 | + if (!function_exists($fonction)) { |
|
| 5638 | + include_spip('base/objets'); |
|
| 5639 | + } |
|
| 5640 | + return $fonction($objet, $id_objet); |
|
| 5641 | 5641 | } |
| 5642 | 5642 | |
| 5643 | 5643 | |
@@ -5652,7 +5652,7 @@ discard block |
||
| 5652 | 5652 | * @return array |
| 5653 | 5653 | */ |
| 5654 | 5654 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5655 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5655 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5656 | 5656 | } |
| 5657 | 5657 | |
| 5658 | 5658 | /** |
@@ -5666,7 +5666,7 @@ discard block |
||
| 5666 | 5666 | * @return array |
| 5667 | 5667 | */ |
| 5668 | 5668 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5669 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5669 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5670 | 5670 | } |
| 5671 | 5671 | |
| 5672 | 5672 | /** |
@@ -5680,7 +5680,7 @@ discard block |
||
| 5680 | 5680 | * @return array |
| 5681 | 5681 | */ |
| 5682 | 5682 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5683 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5683 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5684 | 5684 | } |
| 5685 | 5685 | |
| 5686 | 5686 | /** |
@@ -5694,5 +5694,5 @@ discard block |
||
| 5694 | 5694 | * @return array |
| 5695 | 5695 | */ |
| 5696 | 5696 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5697 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5697 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5698 | 5698 | } |