@@ -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('compacte')) { |
|
| 70 | - $file = compacte($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('compacte')) { |
|
| 70 | + $file = compacte($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 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -48,66 +48,66 @@ discard block |
||
| 48 | 48 | * Nom de la fonction, ou false. |
| 49 | 49 | */ |
| 50 | 50 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 51 | - static $echecs = []; |
|
| 52 | - |
|
| 53 | - if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | - $dossier .= '/'; |
|
| 55 | - } |
|
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | - |
|
| 58 | - if (function_exists($f)) { |
|
| 59 | - return $f; |
|
| 60 | - } |
|
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 62 | - return $g; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (isset($echecs[$f])) { |
|
| 66 | - return $echecs[$f]; |
|
| 67 | - } |
|
| 68 | - // Sinon charger le fichier de declaration si plausible |
|
| 69 | - |
|
| 70 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | - if ($continue) { |
|
| 72 | - return false; |
|
| 73 | - } //appel interne, on passe |
|
| 74 | - include_spip('inc/minipres'); |
|
| 75 | - echo minipres(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // passer en minuscules (cf les balises de formulaires) |
|
| 80 | - // et inclure le fichier |
|
| 81 | - if ( |
|
| 82 | - !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | - ) { |
|
| 87 | - include_spip(substr($dossier, 0, -1)); |
|
| 88 | - } |
|
| 89 | - if (function_exists($f)) { |
|
| 90 | - return $f; |
|
| 91 | - } |
|
| 92 | - if (function_exists($g)) { |
|
| 93 | - return $g; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($continue) { |
|
| 97 | - return $echecs[$f] = false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Echec : message d'erreur |
|
| 101 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | - |
|
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres( |
|
| 106 | - _T('forum_titre_erreur'), |
|
| 107 | - _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 108 | - ['all_inline' => true,'status' => 404] |
|
| 109 | - ); |
|
| 110 | - exit; |
|
| 51 | + static $echecs = []; |
|
| 52 | + |
|
| 53 | + if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | + $dossier .= '/'; |
|
| 55 | + } |
|
| 56 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | + |
|
| 58 | + if (function_exists($f)) { |
|
| 59 | + return $f; |
|
| 60 | + } |
|
| 61 | + if (function_exists($g = $f . '_dist')) { |
|
| 62 | + return $g; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (isset($echecs[$f])) { |
|
| 66 | + return $echecs[$f]; |
|
| 67 | + } |
|
| 68 | + // Sinon charger le fichier de declaration si plausible |
|
| 69 | + |
|
| 70 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | + if ($continue) { |
|
| 72 | + return false; |
|
| 73 | + } //appel interne, on passe |
|
| 74 | + include_spip('inc/minipres'); |
|
| 75 | + echo minipres(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // passer en minuscules (cf les balises de formulaires) |
|
| 80 | + // et inclure le fichier |
|
| 81 | + if ( |
|
| 82 | + !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | + ) { |
|
| 87 | + include_spip(substr($dossier, 0, -1)); |
|
| 88 | + } |
|
| 89 | + if (function_exists($f)) { |
|
| 90 | + return $f; |
|
| 91 | + } |
|
| 92 | + if (function_exists($g)) { |
|
| 93 | + return $g; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($continue) { |
|
| 97 | + return $echecs[$f] = false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Echec : message d'erreur |
|
| 101 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | + |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres( |
|
| 106 | + _T('forum_titre_erreur'), |
|
| 107 | + _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 108 | + ['all_inline' => true,'status' => 404] |
|
| 109 | + ); |
|
| 110 | + exit; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | 119 | function include_once_check($file) { |
| 120 | - if (file_exists($file)) { |
|
| 121 | - include_once $file; |
|
| 120 | + if (file_exists($file)) { |
|
| 121 | + include_once $file; |
|
| 122 | 122 | |
| 123 | - return true; |
|
| 124 | - } |
|
| 125 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 126 | - $crash = ($crash ?: []); |
|
| 127 | - $crash[$file] = true; |
|
| 128 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 123 | + return true; |
|
| 124 | + } |
|
| 125 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 126 | + $crash = ($crash ?: []); |
|
| 127 | + $crash[$file] = true; |
|
| 128 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 129 | 129 | |
| 130 | - return false; |
|
| 130 | + return false; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * - string : chemin du fichier trouvé |
| 152 | 152 | **/ |
| 153 | 153 | function include_spip($f, $include = true) { |
| 154 | - return find_in_path($f . '.php', '', $include); |
|
| 154 | + return find_in_path($f . '.php', '', $include); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * - string : chemin du fichier trouvé |
| 172 | 172 | **/ |
| 173 | 173 | function require_spip($f) { |
| 174 | - return find_in_path($f . '.php', '', 'required'); |
|
| 174 | + return find_in_path($f . '.php', '', 'required'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -180,27 +180,27 @@ discard block |
||
| 180 | 180 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 181 | 181 | */ |
| 182 | 182 | function include_fichiers_fonctions() { |
| 183 | - static $done = false; |
|
| 184 | - if (!$done) { |
|
| 185 | - include_spip('inc/lang'); |
|
| 186 | - |
|
| 187 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 188 | - // donc il faut l'inclure "en globals" |
|
| 189 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 190 | - global $dossier_squelettes; |
|
| 191 | - include_once(_ROOT_CWD . $f); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 195 | - // chargement optimise precompile |
|
| 196 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 197 | - } |
|
| 198 | - if (test_espace_prive()) { |
|
| 199 | - include_spip('inc/filtres_ecrire'); |
|
| 200 | - } |
|
| 201 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 202 | - $done = true; |
|
| 203 | - } |
|
| 183 | + static $done = false; |
|
| 184 | + if (!$done) { |
|
| 185 | + include_spip('inc/lang'); |
|
| 186 | + |
|
| 187 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 188 | + // donc il faut l'inclure "en globals" |
|
| 189 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 190 | + global $dossier_squelettes; |
|
| 191 | + include_once(_ROOT_CWD . $f); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 195 | + // chargement optimise precompile |
|
| 196 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 197 | + } |
|
| 198 | + if (test_espace_prive()) { |
|
| 199 | + include_spip('inc/filtres_ecrire'); |
|
| 200 | + } |
|
| 201 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 202 | + $done = true; |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -226,23 +226,23 @@ discard block |
||
| 226 | 226 | * Les paramètres du pipeline modifiés |
| 227 | 227 | **/ |
| 228 | 228 | function minipipe($fonc, &$val) { |
| 229 | - // fonction |
|
| 230 | - if (function_exists($fonc)) { |
|
| 231 | - $val = call_user_func($fonc, $val); |
|
| 232 | - } // Class::Methode |
|
| 233 | - else { |
|
| 234 | - if ( |
|
| 235 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 236 | - and $methode = [$regs[1], $regs[2]] |
|
| 237 | - and is_callable($methode) |
|
| 238 | - ) { |
|
| 239 | - $val = call_user_func($methode, $val); |
|
| 240 | - } else { |
|
| 241 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $val; |
|
| 229 | + // fonction |
|
| 230 | + if (function_exists($fonc)) { |
|
| 231 | + $val = call_user_func($fonc, $val); |
|
| 232 | + } // Class::Methode |
|
| 233 | + else { |
|
| 234 | + if ( |
|
| 235 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 236 | + and $methode = [$regs[1], $regs[2]] |
|
| 237 | + and is_callable($methode) |
|
| 238 | + ) { |
|
| 239 | + $val = call_user_func($methode, $val); |
|
| 240 | + } else { |
|
| 241 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $val; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -273,46 +273,46 @@ discard block |
||
| 273 | 273 | * Résultat |
| 274 | 274 | */ |
| 275 | 275 | function pipeline($action, $val = null) { |
| 276 | - static $charger; |
|
| 277 | - |
|
| 278 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 279 | - if (!$charger) { |
|
| 280 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 281 | - include_spip('inc/plugin'); |
|
| 282 | - // generer les fichiers php precompiles |
|
| 283 | - // de chargement des plugins et des pipelines |
|
| 284 | - actualise_plugins_actifs(); |
|
| 285 | - if (!($ok = @is_readable($charger))) { |
|
| 286 | - spip_log("fichier $charger pas cree"); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - if ($ok) { |
|
| 291 | - include_once $charger; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // appliquer notre fonction si elle existe |
|
| 296 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 297 | - if (function_exists($fonc)) { |
|
| 298 | - $val = $fonc($val); |
|
| 299 | - } // plantage ? |
|
| 300 | - else { |
|
| 301 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // si le flux est une table avec 2 cle args&data |
|
| 305 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 306 | - // array_key_exists pour php 4.1.0 |
|
| 307 | - if ( |
|
| 308 | - is_array($val) |
|
| 309 | - and count($val) == 2 |
|
| 310 | - and (array_key_exists('data', $val)) |
|
| 311 | - ) { |
|
| 312 | - $val = $val['data']; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $val; |
|
| 276 | + static $charger; |
|
| 277 | + |
|
| 278 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 279 | + if (!$charger) { |
|
| 280 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 281 | + include_spip('inc/plugin'); |
|
| 282 | + // generer les fichiers php precompiles |
|
| 283 | + // de chargement des plugins et des pipelines |
|
| 284 | + actualise_plugins_actifs(); |
|
| 285 | + if (!($ok = @is_readable($charger))) { |
|
| 286 | + spip_log("fichier $charger pas cree"); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + if ($ok) { |
|
| 291 | + include_once $charger; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // appliquer notre fonction si elle existe |
|
| 296 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 297 | + if (function_exists($fonc)) { |
|
| 298 | + $val = $fonc($val); |
|
| 299 | + } // plantage ? |
|
| 300 | + else { |
|
| 301 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // si le flux est une table avec 2 cle args&data |
|
| 305 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 306 | + // array_key_exists pour php 4.1.0 |
|
| 307 | + if ( |
|
| 308 | + is_array($val) |
|
| 309 | + and count($val) == 2 |
|
| 310 | + and (array_key_exists('data', $val)) |
|
| 311 | + ) { |
|
| 312 | + $val = $val['data']; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $val; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -356,38 +356,38 @@ discard block |
||
| 356 | 356 | * paramètre est planté pour cause de compatibilité ascendante. |
| 357 | 357 | */ |
| 358 | 358 | function spip_log($message = null, $name = null) { |
| 359 | - static $pre = []; |
|
| 360 | - static $log; |
|
| 361 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 362 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 363 | - $logname = null; |
|
| 364 | - } |
|
| 365 | - if (!isset($regs[2])) { |
|
| 366 | - $niveau = _LOG_INFO; |
|
| 367 | - } |
|
| 368 | - else { |
|
| 369 | - $niveau = intval($regs[2]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 373 | - if (!$pre) { |
|
| 374 | - $pre = [ |
|
| 375 | - _LOG_HS => 'HS:', |
|
| 376 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 377 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 378 | - _LOG_ERREUR => 'ERREUR:', |
|
| 379 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 380 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 381 | - _LOG_INFO => 'info:', |
|
| 382 | - _LOG_DEBUG => 'debug:' |
|
| 383 | - ]; |
|
| 384 | - $log = charger_fonction('log', 'inc'); |
|
| 385 | - } |
|
| 386 | - if (!is_string($message)) { |
|
| 387 | - $message = print_r($message, true); |
|
| 388 | - } |
|
| 389 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 390 | - } |
|
| 359 | + static $pre = []; |
|
| 360 | + static $log; |
|
| 361 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 362 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 363 | + $logname = null; |
|
| 364 | + } |
|
| 365 | + if (!isset($regs[2])) { |
|
| 366 | + $niveau = _LOG_INFO; |
|
| 367 | + } |
|
| 368 | + else { |
|
| 369 | + $niveau = intval($regs[2]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 373 | + if (!$pre) { |
|
| 374 | + $pre = [ |
|
| 375 | + _LOG_HS => 'HS:', |
|
| 376 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 377 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 378 | + _LOG_ERREUR => 'ERREUR:', |
|
| 379 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 380 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 381 | + _LOG_INFO => 'info:', |
|
| 382 | + _LOG_DEBUG => 'debug:' |
|
| 383 | + ]; |
|
| 384 | + $log = charger_fonction('log', 'inc'); |
|
| 385 | + } |
|
| 386 | + if (!is_string($message)) { |
|
| 387 | + $message = print_r($message, true); |
|
| 388 | + } |
|
| 389 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 390 | + } |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param array $opt Tableau d'options |
| 399 | 399 | **/ |
| 400 | 400 | function journal($phrase, $opt = []) { |
| 401 | - $journal = charger_fonction('journal', 'inc'); |
|
| 402 | - $journal($phrase, $opt); |
|
| 401 | + $journal = charger_fonction('journal', 'inc'); |
|
| 402 | + $journal($phrase, $opt); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -418,37 +418,37 @@ discard block |
||
| 418 | 418 | **/ |
| 419 | 419 | function _request($var, $c = false) { |
| 420 | 420 | |
| 421 | - if (is_array($c)) { |
|
| 422 | - return $c[$var] ?? null; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (isset($_GET[$var])) { |
|
| 426 | - $a = $_GET[$var]; |
|
| 427 | - } elseif (isset($_POST[$var])) { |
|
| 428 | - $a = $_POST[$var]; |
|
| 429 | - } else { |
|
| 430 | - return null; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // Si on est en ajax et en POST tout a ete encode |
|
| 434 | - // via encodeURIComponent, il faut donc repasser |
|
| 435 | - // dans le charset local... |
|
| 436 | - if ( |
|
| 437 | - defined('_AJAX') |
|
| 438 | - and _AJAX |
|
| 439 | - and isset($GLOBALS['meta']['charset']) |
|
| 440 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 441 | - and is_string($a) |
|
| 442 | - // check rapide mais pas fiable |
|
| 443 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 444 | - // check fiable |
|
| 445 | - and include_spip('inc/charsets') |
|
| 446 | - and is_utf8($a) |
|
| 447 | - ) { |
|
| 448 | - return importer_charset($a, 'utf-8'); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return $a; |
|
| 421 | + if (is_array($c)) { |
|
| 422 | + return $c[$var] ?? null; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (isset($_GET[$var])) { |
|
| 426 | + $a = $_GET[$var]; |
|
| 427 | + } elseif (isset($_POST[$var])) { |
|
| 428 | + $a = $_POST[$var]; |
|
| 429 | + } else { |
|
| 430 | + return null; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // Si on est en ajax et en POST tout a ete encode |
|
| 434 | + // via encodeURIComponent, il faut donc repasser |
|
| 435 | + // dans le charset local... |
|
| 436 | + if ( |
|
| 437 | + defined('_AJAX') |
|
| 438 | + and _AJAX |
|
| 439 | + and isset($GLOBALS['meta']['charset']) |
|
| 440 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 441 | + and is_string($a) |
|
| 442 | + // check rapide mais pas fiable |
|
| 443 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 444 | + // check fiable |
|
| 445 | + and include_spip('inc/charsets') |
|
| 446 | + and is_utf8($a) |
|
| 447 | + ) { |
|
| 448 | + return importer_charset($a, 'utf-8'); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return $a; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
@@ -466,22 +466,22 @@ discard block |
||
| 466 | 466 | * - false sinon |
| 467 | 467 | **/ |
| 468 | 468 | function set_request($var, $val = null, $c = false) { |
| 469 | - if (is_array($c)) { |
|
| 470 | - unset($c[$var]); |
|
| 471 | - if ($val !== null) { |
|
| 472 | - $c[$var] = $val; |
|
| 473 | - } |
|
| 469 | + if (is_array($c)) { |
|
| 470 | + unset($c[$var]); |
|
| 471 | + if ($val !== null) { |
|
| 472 | + $c[$var] = $val; |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - return $c; |
|
| 476 | - } |
|
| 475 | + return $c; |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - unset($_GET[$var]); |
|
| 479 | - unset($_POST[$var]); |
|
| 480 | - if ($val !== null) { |
|
| 481 | - $_GET[$var] = $val; |
|
| 482 | - } |
|
| 478 | + unset($_GET[$var]); |
|
| 479 | + unset($_POST[$var]); |
|
| 480 | + if ($val !== null) { |
|
| 481 | + $_GET[$var] = $val; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - return false; # n'affecte pas $c |
|
| 484 | + return false; # n'affecte pas $c |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -501,25 +501,25 @@ discard block |
||
| 501 | 501 | * @return array|mixed|string |
| 502 | 502 | */ |
| 503 | 503 | function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') { |
| 504 | - if (is_array($value)) { |
|
| 505 | - if ($key == '*') { |
|
| 506 | - $key = array_keys($value); |
|
| 507 | - } |
|
| 508 | - if (!is_array($key)) { |
|
| 509 | - $key = [$key]; |
|
| 510 | - } |
|
| 511 | - foreach ($key as $k) { |
|
| 512 | - if (!empty($value[$k])) { |
|
| 513 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - return $value; |
|
| 517 | - } |
|
| 518 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 519 | - if (!empty($value) and $value == _request($key)) { |
|
| 520 | - $value = $sanitize_function($value); |
|
| 521 | - } |
|
| 522 | - return $value; |
|
| 504 | + if (is_array($value)) { |
|
| 505 | + if ($key == '*') { |
|
| 506 | + $key = array_keys($value); |
|
| 507 | + } |
|
| 508 | + if (!is_array($key)) { |
|
| 509 | + $key = [$key]; |
|
| 510 | + } |
|
| 511 | + foreach ($key as $k) { |
|
| 512 | + if (!empty($value[$k])) { |
|
| 513 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + return $value; |
|
| 517 | + } |
|
| 518 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 519 | + if (!empty($value) and $value == _request($key)) { |
|
| 520 | + $value = $sanitize_function($value); |
|
| 521 | + } |
|
| 522 | + return $value; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
@@ -527,23 +527,22 @@ discard block |
||
| 527 | 527 | * |
| 528 | 528 | * On est sur le web, on exclut certains protocoles, |
| 529 | 529 | * notamment 'file://', 'php://' et d'autres… |
| 530 | - |
|
| 531 | 530 | * @param string $url |
| 532 | 531 | * @return bool |
| 533 | 532 | */ |
| 534 | 533 | function tester_url_absolue($url) { |
| 535 | - $url = trim($url); |
|
| 536 | - if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 537 | - if ( |
|
| 538 | - isset($m[1]) |
|
| 539 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 540 | - and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 541 | - ) { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - return true; |
|
| 545 | - } |
|
| 546 | - return false; |
|
| 534 | + $url = trim($url); |
|
| 535 | + if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 536 | + if ( |
|
| 537 | + isset($m[1]) |
|
| 538 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 539 | + and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 540 | + ) { |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + return true; |
|
| 544 | + } |
|
| 545 | + return false; |
|
| 547 | 546 | } |
| 548 | 547 | |
| 549 | 548 | /** |
@@ -565,95 +564,95 @@ discard block |
||
| 565 | 564 | * @return string URL |
| 566 | 565 | */ |
| 567 | 566 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 568 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 569 | - if (strpos($c, '|') !== false and is_null($v)) { |
|
| 570 | - return null; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // lever l'#ancre |
|
| 574 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 575 | - $url = $r[1]; |
|
| 576 | - $ancre = $r[2]; |
|
| 577 | - } else { |
|
| 578 | - $ancre = ''; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // eclater |
|
| 582 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 583 | - |
|
| 584 | - // recuperer la base |
|
| 585 | - $a = array_shift($url); |
|
| 586 | - if (!$a) { |
|
| 587 | - $a = './'; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 591 | - $ajouts = array_flip(explode('|', $c)); |
|
| 592 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 593 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 594 | - $v_read = null; |
|
| 595 | - // lire les variables et agir |
|
| 596 | - foreach ($url as $n => $val) { |
|
| 597 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 598 | - $r = array_pad($r, 3, null); |
|
| 599 | - if ($v === null) { |
|
| 600 | - // c'est un tableau, on memorise les valeurs |
|
| 601 | - if (substr($r[1], -2) == '[]') { |
|
| 602 | - if (!$v_read) { |
|
| 603 | - $v_read = []; |
|
| 604 | - } |
|
| 605 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 606 | - } // c'est un scalaire, on retourne direct |
|
| 607 | - else { |
|
| 608 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 609 | - } |
|
| 610 | - } // suppression |
|
| 611 | - elseif (!$testv) { |
|
| 612 | - unset($url[$n]); |
|
| 613 | - } |
|
| 614 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 615 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 616 | - elseif (substr($r[1], -2) != '[]') { |
|
| 617 | - $url[$n] = $r[1] . '=' . $u; |
|
| 618 | - unset($ajouts[$r[1]]); |
|
| 619 | - } |
|
| 620 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 621 | - // départ, on remplira à l'étape suivante |
|
| 622 | - else { |
|
| 623 | - unset($url[$n]); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // traiter les parametres pas encore trouves |
|
| 629 | - if ( |
|
| 630 | - $v === null |
|
| 631 | - and $args = func_get_args() |
|
| 632 | - and count($args) == 2 |
|
| 633 | - ) { |
|
| 634 | - return $v_read; // rien trouve ou un tableau |
|
| 635 | - } elseif ($testv) { |
|
| 636 | - foreach ($ajouts as $k => $n) { |
|
| 637 | - if (!is_array($v)) { |
|
| 638 | - $url[] = $k . '=' . $u; |
|
| 639 | - } else { |
|
| 640 | - $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 641 | - foreach ($v as $w) { |
|
| 642 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // eliminer les vides |
|
| 649 | - $url = array_filter($url); |
|
| 650 | - |
|
| 651 | - // recomposer l'adresse |
|
| 652 | - if ($url) { |
|
| 653 | - $a .= '?' . join($sep, $url); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return $a . $ancre; |
|
| 567 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 568 | + if (strpos($c, '|') !== false and is_null($v)) { |
|
| 569 | + return null; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // lever l'#ancre |
|
| 573 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 574 | + $url = $r[1]; |
|
| 575 | + $ancre = $r[2]; |
|
| 576 | + } else { |
|
| 577 | + $ancre = ''; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // eclater |
|
| 581 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 582 | + |
|
| 583 | + // recuperer la base |
|
| 584 | + $a = array_shift($url); |
|
| 585 | + if (!$a) { |
|
| 586 | + $a = './'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 590 | + $ajouts = array_flip(explode('|', $c)); |
|
| 591 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 592 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 593 | + $v_read = null; |
|
| 594 | + // lire les variables et agir |
|
| 595 | + foreach ($url as $n => $val) { |
|
| 596 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 597 | + $r = array_pad($r, 3, null); |
|
| 598 | + if ($v === null) { |
|
| 599 | + // c'est un tableau, on memorise les valeurs |
|
| 600 | + if (substr($r[1], -2) == '[]') { |
|
| 601 | + if (!$v_read) { |
|
| 602 | + $v_read = []; |
|
| 603 | + } |
|
| 604 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 605 | + } // c'est un scalaire, on retourne direct |
|
| 606 | + else { |
|
| 607 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 608 | + } |
|
| 609 | + } // suppression |
|
| 610 | + elseif (!$testv) { |
|
| 611 | + unset($url[$n]); |
|
| 612 | + } |
|
| 613 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 614 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 615 | + elseif (substr($r[1], -2) != '[]') { |
|
| 616 | + $url[$n] = $r[1] . '=' . $u; |
|
| 617 | + unset($ajouts[$r[1]]); |
|
| 618 | + } |
|
| 619 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 620 | + // départ, on remplira à l'étape suivante |
|
| 621 | + else { |
|
| 622 | + unset($url[$n]); |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // traiter les parametres pas encore trouves |
|
| 628 | + if ( |
|
| 629 | + $v === null |
|
| 630 | + and $args = func_get_args() |
|
| 631 | + and count($args) == 2 |
|
| 632 | + ) { |
|
| 633 | + return $v_read; // rien trouve ou un tableau |
|
| 634 | + } elseif ($testv) { |
|
| 635 | + foreach ($ajouts as $k => $n) { |
|
| 636 | + if (!is_array($v)) { |
|
| 637 | + $url[] = $k . '=' . $u; |
|
| 638 | + } else { |
|
| 639 | + $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 640 | + foreach ($v as $w) { |
|
| 641 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // eliminer les vides |
|
| 648 | + $url = array_filter($url); |
|
| 649 | + |
|
| 650 | + // recomposer l'adresse |
|
| 651 | + if ($url) { |
|
| 652 | + $a .= '?' . join($sep, $url); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return $a . $ancre; |
|
| 657 | 656 | } |
| 658 | 657 | |
| 659 | 658 | /** |
@@ -671,21 +670,21 @@ discard block |
||
| 671 | 670 | * @return string |
| 672 | 671 | */ |
| 673 | 672 | function ancre_url($url, $ancre) { |
| 674 | - // lever l'#ancre |
|
| 675 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 676 | - $url = $r[1]; |
|
| 677 | - } |
|
| 678 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 679 | - if (!function_exists('translitteration')) { |
|
| 680 | - include_spip('inc/charsets'); |
|
| 681 | - } |
|
| 682 | - $ancre = preg_replace( |
|
| 683 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 684 | - ['', '-'], |
|
| 685 | - translitteration($ancre) |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 673 | + // lever l'#ancre |
|
| 674 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 675 | + $url = $r[1]; |
|
| 676 | + } |
|
| 677 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 678 | + if (!function_exists('translitteration')) { |
|
| 679 | + include_spip('inc/charsets'); |
|
| 680 | + } |
|
| 681 | + $ancre = preg_replace( |
|
| 682 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 683 | + ['', '-'], |
|
| 684 | + translitteration($ancre) |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 689 | 688 | } |
| 690 | 689 | |
| 691 | 690 | /** |
@@ -695,16 +694,16 @@ discard block |
||
| 695 | 694 | * @return string |
| 696 | 695 | */ |
| 697 | 696 | function nettoyer_uri($reset = null) { |
| 698 | - static $done = false; |
|
| 699 | - static $propre = ''; |
|
| 700 | - if (!is_null($reset)) { |
|
| 701 | - return $propre = $reset; |
|
| 702 | - } |
|
| 703 | - if ($done) { |
|
| 704 | - return $propre; |
|
| 705 | - } |
|
| 706 | - $done = true; |
|
| 707 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 697 | + static $done = false; |
|
| 698 | + static $propre = ''; |
|
| 699 | + if (!is_null($reset)) { |
|
| 700 | + return $propre = $reset; |
|
| 701 | + } |
|
| 702 | + if ($done) { |
|
| 703 | + return $propre; |
|
| 704 | + } |
|
| 705 | + $done = true; |
|
| 706 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 708 | 707 | } |
| 709 | 708 | |
| 710 | 709 | /** |
@@ -716,16 +715,16 @@ discard block |
||
| 716 | 715 | * @return string |
| 717 | 716 | */ |
| 718 | 717 | function nettoyer_uri_var($request_uri) { |
| 719 | - $uri1 = $request_uri; |
|
| 720 | - do { |
|
| 721 | - $uri = $uri1; |
|
| 722 | - $uri1 = preg_replace( |
|
| 723 | - ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 724 | - '\1', |
|
| 725 | - $uri |
|
| 726 | - ); |
|
| 727 | - } while ($uri <> $uri1); |
|
| 728 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 718 | + $uri1 = $request_uri; |
|
| 719 | + do { |
|
| 720 | + $uri = $uri1; |
|
| 721 | + $uri1 = preg_replace( |
|
| 722 | + ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 723 | + '\1', |
|
| 724 | + $uri |
|
| 725 | + ); |
|
| 726 | + } while ($uri <> $uri1); |
|
| 727 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 729 | 728 | } |
| 730 | 729 | |
| 731 | 730 | |
@@ -739,48 +738,48 @@ discard block |
||
| 739 | 738 | * URL vers soi-même |
| 740 | 739 | **/ |
| 741 | 740 | function self($amp = '&', $root = false) { |
| 742 | - $url = nettoyer_uri(); |
|
| 743 | - if ( |
|
| 744 | - !$root |
|
| 745 | - and ( |
|
| 746 | - // si pas de profondeur on peut tronquer |
|
| 747 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 748 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 749 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 750 | - ) { |
|
| 751 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 752 | - } |
|
| 753 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 754 | - foreach ($_POST as $v => $c) { |
|
| 755 | - if (substr($v, 0, 3) == 'id_') { |
|
| 756 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - // supprimer les variables sans interet |
|
| 761 | - if (test_espace_prive()) { |
|
| 762 | - $url = preg_replace(',([?&])(' |
|
| 763 | - . 'lang|show_docs|' |
|
| 764 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 765 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 766 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - // eviter les hacks |
|
| 770 | - include_spip('inc/filtres_mini'); |
|
| 771 | - $url = spip_htmlspecialchars($url); |
|
| 772 | - |
|
| 773 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 774 | - |
|
| 775 | - // & ? |
|
| 776 | - if ($amp != '&') { |
|
| 777 | - $url = str_replace('&', $amp, $url); |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Si ca demarre par ? ou vide, donner './' |
|
| 781 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 782 | - |
|
| 783 | - return $url; |
|
| 741 | + $url = nettoyer_uri(); |
|
| 742 | + if ( |
|
| 743 | + !$root |
|
| 744 | + and ( |
|
| 745 | + // si pas de profondeur on peut tronquer |
|
| 746 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 747 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 748 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 749 | + ) { |
|
| 750 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 751 | + } |
|
| 752 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 753 | + foreach ($_POST as $v => $c) { |
|
| 754 | + if (substr($v, 0, 3) == 'id_') { |
|
| 755 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + // supprimer les variables sans interet |
|
| 760 | + if (test_espace_prive()) { |
|
| 761 | + $url = preg_replace(',([?&])(' |
|
| 762 | + . 'lang|show_docs|' |
|
| 763 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 764 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 765 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // eviter les hacks |
|
| 769 | + include_spip('inc/filtres_mini'); |
|
| 770 | + $url = spip_htmlspecialchars($url); |
|
| 771 | + |
|
| 772 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 773 | + |
|
| 774 | + // & ? |
|
| 775 | + if ($amp != '&') { |
|
| 776 | + $url = str_replace('&', $amp, $url); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + // Si ca demarre par ? ou vide, donner './' |
|
| 780 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 781 | + |
|
| 782 | + return $url; |
|
| 784 | 783 | } |
| 785 | 784 | |
| 786 | 785 | |
@@ -791,7 +790,7 @@ discard block |
||
| 791 | 790 | * true si c'est le cas, false sinon. |
| 792 | 791 | */ |
| 793 | 792 | function test_espace_prive() { |
| 794 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 793 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 795 | 794 | } |
| 796 | 795 | |
| 797 | 796 | /** |
@@ -801,7 +800,7 @@ discard block |
||
| 801 | 800 | * @return bool |
| 802 | 801 | */ |
| 803 | 802 | function test_plugin_actif($plugin) { |
| 804 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 803 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 805 | 804 | } |
| 806 | 805 | |
| 807 | 806 | /** |
@@ -832,52 +831,52 @@ discard block |
||
| 832 | 831 | * Texte |
| 833 | 832 | */ |
| 834 | 833 | function _T($texte, $args = [], $options = []) { |
| 835 | - static $traduire = false; |
|
| 836 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 837 | - if ($options) { |
|
| 838 | - // support de l'ancien argument $class |
|
| 839 | - if (is_string($options)) { |
|
| 840 | - $options = ['class' => $options]; |
|
| 841 | - } |
|
| 842 | - $o = array_merge($o, $options); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - if (!$traduire) { |
|
| 846 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 847 | - include_spip('inc/lang'); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // On peut passer explicitement la langue dans le tableau |
|
| 851 | - // On utilise le même nom de variable que la globale |
|
| 852 | - if (isset($args['spip_lang'])) { |
|
| 853 | - $lang = $args['spip_lang']; |
|
| 854 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 855 | - unset($args['spip_lang']); |
|
| 856 | - } // Sinon on prend la langue du contexte |
|
| 857 | - else { |
|
| 858 | - $lang = $GLOBALS['spip_lang']; |
|
| 859 | - } |
|
| 860 | - $text = $traduire($texte, $lang); |
|
| 861 | - |
|
| 862 | - if ($text === null || !strlen($text)) { |
|
| 863 | - if (!$o['force']) { |
|
| 864 | - return ''; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $text = $texte; |
|
| 868 | - |
|
| 869 | - // pour les chaines non traduites, assurer un service minimum |
|
| 870 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 871 | - $n = strpos($text, ':'); |
|
| 872 | - if ($n !== false) { |
|
| 873 | - $text = substr($text, $n + 1); |
|
| 874 | - } |
|
| 875 | - $text = str_replace('_', ' ', $text); |
|
| 876 | - } |
|
| 877 | - $o['class'] = null; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - return _L($text, $args, $o); |
|
| 834 | + static $traduire = false; |
|
| 835 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 836 | + if ($options) { |
|
| 837 | + // support de l'ancien argument $class |
|
| 838 | + if (is_string($options)) { |
|
| 839 | + $options = ['class' => $options]; |
|
| 840 | + } |
|
| 841 | + $o = array_merge($o, $options); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + if (!$traduire) { |
|
| 845 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 846 | + include_spip('inc/lang'); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + // On peut passer explicitement la langue dans le tableau |
|
| 850 | + // On utilise le même nom de variable que la globale |
|
| 851 | + if (isset($args['spip_lang'])) { |
|
| 852 | + $lang = $args['spip_lang']; |
|
| 853 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 854 | + unset($args['spip_lang']); |
|
| 855 | + } // Sinon on prend la langue du contexte |
|
| 856 | + else { |
|
| 857 | + $lang = $GLOBALS['spip_lang']; |
|
| 858 | + } |
|
| 859 | + $text = $traduire($texte, $lang); |
|
| 860 | + |
|
| 861 | + if ($text === null || !strlen($text)) { |
|
| 862 | + if (!$o['force']) { |
|
| 863 | + return ''; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $text = $texte; |
|
| 867 | + |
|
| 868 | + // pour les chaines non traduites, assurer un service minimum |
|
| 869 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 870 | + $n = strpos($text, ':'); |
|
| 871 | + if ($n !== false) { |
|
| 872 | + $text = substr($text, $n + 1); |
|
| 873 | + } |
|
| 874 | + $text = str_replace('_', ' ', $text); |
|
| 875 | + } |
|
| 876 | + $o['class'] = null; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + return _L($text, $args, $o); |
|
| 881 | 880 | } |
| 882 | 881 | |
| 883 | 882 | |
@@ -904,53 +903,53 @@ discard block |
||
| 904 | 903 | * Texte |
| 905 | 904 | */ |
| 906 | 905 | function _L($text, $args = [], $options = []) { |
| 907 | - $f = $text; |
|
| 908 | - $defaut_options = [ |
|
| 909 | - 'class' => null, |
|
| 910 | - 'sanitize' => true, |
|
| 911 | - ]; |
|
| 912 | - // support de l'ancien argument $class |
|
| 913 | - if ($options and is_string($options)) { |
|
| 914 | - $options = ['class' => $options]; |
|
| 915 | - } |
|
| 916 | - if (is_array($options)) { |
|
| 917 | - $options += $defaut_options; |
|
| 918 | - } else { |
|
| 919 | - $options = $defaut_options; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if (is_array($args) and count($args)) { |
|
| 923 | - if (!function_exists('interdire_scripts')) { |
|
| 924 | - include_spip('inc/texte'); |
|
| 925 | - } |
|
| 926 | - if (!function_exists('echapper_html_suspect')) { |
|
| 927 | - include_spip('inc/texte_mini'); |
|
| 928 | - } |
|
| 929 | - foreach ($args as $name => $value) { |
|
| 930 | - if (strpos($text, (string) "@$name@") !== false) { |
|
| 931 | - if ($options['sanitize']) { |
|
| 932 | - $value = echapper_html_suspect($value); |
|
| 933 | - $value = interdire_scripts($value, -1); |
|
| 934 | - } |
|
| 935 | - if (!empty($options['class'])) { |
|
| 936 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 937 | - } |
|
| 938 | - $text = str_replace("@$name@", $value, $text); |
|
| 939 | - unset($args[$name]); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 943 | - // (chaines de langues pas a jour) |
|
| 944 | - if ($args) { |
|
| 945 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 946 | - } |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 950 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 951 | - } else { |
|
| 952 | - return $text; |
|
| 953 | - } |
|
| 906 | + $f = $text; |
|
| 907 | + $defaut_options = [ |
|
| 908 | + 'class' => null, |
|
| 909 | + 'sanitize' => true, |
|
| 910 | + ]; |
|
| 911 | + // support de l'ancien argument $class |
|
| 912 | + if ($options and is_string($options)) { |
|
| 913 | + $options = ['class' => $options]; |
|
| 914 | + } |
|
| 915 | + if (is_array($options)) { |
|
| 916 | + $options += $defaut_options; |
|
| 917 | + } else { |
|
| 918 | + $options = $defaut_options; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + if (is_array($args) and count($args)) { |
|
| 922 | + if (!function_exists('interdire_scripts')) { |
|
| 923 | + include_spip('inc/texte'); |
|
| 924 | + } |
|
| 925 | + if (!function_exists('echapper_html_suspect')) { |
|
| 926 | + include_spip('inc/texte_mini'); |
|
| 927 | + } |
|
| 928 | + foreach ($args as $name => $value) { |
|
| 929 | + if (strpos($text, (string) "@$name@") !== false) { |
|
| 930 | + if ($options['sanitize']) { |
|
| 931 | + $value = echapper_html_suspect($value); |
|
| 932 | + $value = interdire_scripts($value, -1); |
|
| 933 | + } |
|
| 934 | + if (!empty($options['class'])) { |
|
| 935 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 936 | + } |
|
| 937 | + $text = str_replace("@$name@", $value, $text); |
|
| 938 | + unset($args[$name]); |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 942 | + // (chaines de langues pas a jour) |
|
| 943 | + if ($args) { |
|
| 944 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 949 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 950 | + } else { |
|
| 951 | + return $text; |
|
| 952 | + } |
|
| 954 | 953 | } |
| 955 | 954 | |
| 956 | 955 | |
@@ -964,13 +963,13 @@ discard block |
||
| 964 | 963 | * @return string |
| 965 | 964 | */ |
| 966 | 965 | function joli_repertoire($rep) { |
| 967 | - $a = substr($rep, 0, 1); |
|
| 968 | - if ($a <> '.' and $a <> '/') { |
|
| 969 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 970 | - } |
|
| 971 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 966 | + $a = substr($rep, 0, 1); |
|
| 967 | + if ($a <> '.' and $a <> '/') { |
|
| 968 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 969 | + } |
|
| 970 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 972 | 971 | |
| 973 | - return $rep; |
|
| 972 | + return $rep; |
|
| 974 | 973 | } |
| 975 | 974 | |
| 976 | 975 | |
@@ -995,54 +994,54 @@ discard block |
||
| 995 | 994 | * @return float|int|string|void |
| 996 | 995 | */ |
| 997 | 996 | function spip_timer($t = 'rien', $raw = false) { |
| 998 | - static $time; |
|
| 999 | - $a = time(); |
|
| 1000 | - $b = microtime(); |
|
| 1001 | - // microtime peut contenir les microsecondes et le temps |
|
| 1002 | - $b = explode(' ', $b); |
|
| 1003 | - if (count($b) == 2) { |
|
| 1004 | - $a = end($b); |
|
| 1005 | - } // plus precis ! |
|
| 1006 | - $b = reset($b); |
|
| 1007 | - if (!isset($time[$t])) { |
|
| 1008 | - $time[$t] = $a + $b; |
|
| 1009 | - } else { |
|
| 1010 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1011 | - unset($time[$t]); |
|
| 997 | + static $time; |
|
| 998 | + $a = time(); |
|
| 999 | + $b = microtime(); |
|
| 1000 | + // microtime peut contenir les microsecondes et le temps |
|
| 1001 | + $b = explode(' ', $b); |
|
| 1002 | + if (count($b) == 2) { |
|
| 1003 | + $a = end($b); |
|
| 1004 | + } // plus precis ! |
|
| 1005 | + $b = reset($b); |
|
| 1006 | + if (!isset($time[$t])) { |
|
| 1007 | + $time[$t] = $a + $b; |
|
| 1008 | + } else { |
|
| 1009 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 1010 | + unset($time[$t]); |
|
| 1012 | 1011 | # echo "'$p'";exit; |
| 1013 | - if ($raw) { |
|
| 1014 | - return $p; |
|
| 1015 | - } |
|
| 1016 | - if ($p < 1000) { |
|
| 1017 | - $s = ''; |
|
| 1018 | - } else { |
|
| 1019 | - $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1020 | - $p -= ($x * 1000); |
|
| 1021 | - } |
|
| 1012 | + if ($raw) { |
|
| 1013 | + return $p; |
|
| 1014 | + } |
|
| 1015 | + if ($p < 1000) { |
|
| 1016 | + $s = ''; |
|
| 1017 | + } else { |
|
| 1018 | + $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1019 | + $p -= ($x * 1000); |
|
| 1020 | + } |
|
| 1022 | 1021 | |
| 1023 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1024 | - } |
|
| 1022 | + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1023 | + } |
|
| 1025 | 1024 | } |
| 1026 | 1025 | |
| 1027 | 1026 | |
| 1028 | 1027 | // Renvoie False si un fichier n'est pas plus vieux que $duree secondes, |
| 1029 | 1028 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1030 | 1029 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1031 | - if ($duree) { |
|
| 1032 | - clearstatcache(); |
|
| 1033 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1034 | - return false; |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - if ($touch !== false) { |
|
| 1038 | - if (!@touch($fichier)) { |
|
| 1039 | - spip_unlink($fichier); |
|
| 1040 | - @touch($fichier); |
|
| 1041 | - }; |
|
| 1042 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1043 | - } |
|
| 1030 | + if ($duree) { |
|
| 1031 | + clearstatcache(); |
|
| 1032 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + if ($touch !== false) { |
|
| 1037 | + if (!@touch($fichier)) { |
|
| 1038 | + spip_unlink($fichier); |
|
| 1039 | + @touch($fichier); |
|
| 1040 | + }; |
|
| 1041 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1042 | + } |
|
| 1044 | 1043 | |
| 1045 | - return true; |
|
| 1044 | + return true; |
|
| 1046 | 1045 | } |
| 1047 | 1046 | |
| 1048 | 1047 | |
@@ -1053,11 +1052,11 @@ discard block |
||
| 1053 | 1052 | * @uses cron() |
| 1054 | 1053 | **/ |
| 1055 | 1054 | function action_cron() { |
| 1056 | - include_spip('inc/headers'); |
|
| 1057 | - http_response_code(204); // No Content |
|
| 1058 | - header('Connection: close'); |
|
| 1059 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1060 | - cron(); |
|
| 1055 | + include_spip('inc/headers'); |
|
| 1056 | + http_response_code(204); // No Content |
|
| 1057 | + header('Connection: close'); |
|
| 1058 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1059 | + cron(); |
|
| 1061 | 1060 | } |
| 1062 | 1061 | |
| 1063 | 1062 | /** |
@@ -1073,26 +1072,26 @@ discard block |
||
| 1073 | 1072 | * True si la tache a pu être effectuée |
| 1074 | 1073 | */ |
| 1075 | 1074 | function cron($taches = [], $taches_old = []) { |
| 1076 | - // si pas en mode cron force, laisser tomber. |
|
| 1077 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1078 | - return false; |
|
| 1079 | - } |
|
| 1080 | - if (!is_array($taches)) { |
|
| 1081 | - $taches = $taches_old; |
|
| 1082 | - } // compat anciens appels |
|
| 1083 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1084 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1085 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1086 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1087 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1088 | - return false; |
|
| 1089 | - } |
|
| 1090 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1091 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1092 | - return $genie($taches); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - return false; |
|
| 1075 | + // si pas en mode cron force, laisser tomber. |
|
| 1076 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1077 | + return false; |
|
| 1078 | + } |
|
| 1079 | + if (!is_array($taches)) { |
|
| 1080 | + $taches = $taches_old; |
|
| 1081 | + } // compat anciens appels |
|
| 1082 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1083 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1084 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1085 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1086 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1089 | + spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1090 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1091 | + return $genie($taches); |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + return false; |
|
| 1096 | 1095 | } |
| 1097 | 1096 | |
| 1098 | 1097 | /** |
@@ -1124,17 +1123,17 @@ discard block |
||
| 1124 | 1123 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1125 | 1124 | */ |
| 1126 | 1125 | function job_queue_add( |
| 1127 | - $function, |
|
| 1128 | - $description, |
|
| 1129 | - $arguments = [], |
|
| 1130 | - $file = '', |
|
| 1131 | - $no_duplicate = false, |
|
| 1132 | - $time = 0, |
|
| 1133 | - $priority = 0 |
|
| 1126 | + $function, |
|
| 1127 | + $description, |
|
| 1128 | + $arguments = [], |
|
| 1129 | + $file = '', |
|
| 1130 | + $no_duplicate = false, |
|
| 1131 | + $time = 0, |
|
| 1132 | + $priority = 0 |
|
| 1134 | 1133 | ) { |
| 1135 | - include_spip('inc/queue'); |
|
| 1134 | + include_spip('inc/queue'); |
|
| 1136 | 1135 | |
| 1137 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1136 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1138 | 1137 | } |
| 1139 | 1138 | |
| 1140 | 1139 | /** |
@@ -1145,9 +1144,9 @@ discard block |
||
| 1145 | 1144 | * @return bool |
| 1146 | 1145 | */ |
| 1147 | 1146 | function job_queue_remove($id_job) { |
| 1148 | - include_spip('inc/queue'); |
|
| 1147 | + include_spip('inc/queue'); |
|
| 1149 | 1148 | |
| 1150 | - return queue_remove_job($id_job); |
|
| 1149 | + return queue_remove_job($id_job); |
|
| 1151 | 1150 | } |
| 1152 | 1151 | |
| 1153 | 1152 | /** |
@@ -1160,9 +1159,9 @@ discard block |
||
| 1160 | 1159 | * or an array of simple array to link multiples objet in one time |
| 1161 | 1160 | */ |
| 1162 | 1161 | function job_queue_link($id_job, $objets) { |
| 1163 | - include_spip('inc/queue'); |
|
| 1162 | + include_spip('inc/queue'); |
|
| 1164 | 1163 | |
| 1165 | - return queue_link_job($id_job, $objets); |
|
| 1164 | + return queue_link_job($id_job, $objets); |
|
| 1166 | 1165 | } |
| 1167 | 1166 | |
| 1168 | 1167 | |
@@ -1182,36 +1181,36 @@ discard block |
||
| 1182 | 1181 | * - `null` si la queue n'est pas encore initialisée |
| 1183 | 1182 | */ |
| 1184 | 1183 | function queue_sleep_time_to_next_job($force = null) { |
| 1185 | - static $queue_next_job_time = -1; |
|
| 1186 | - if ($force === true) { |
|
| 1187 | - $queue_next_job_time = -1; |
|
| 1188 | - } elseif ($force) { |
|
| 1189 | - $queue_next_job_time = $force; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - if ($queue_next_job_time == -1) { |
|
| 1193 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1194 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1195 | - } |
|
| 1196 | - // utiliser un cache memoire si dispo |
|
| 1197 | - if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1198 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1199 | - } else { |
|
| 1200 | - $queue_next_job_time = null; |
|
| 1201 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1202 | - $queue_next_job_time = intval($contenu); |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - if (is_null($queue_next_job_time)) { |
|
| 1208 | - return null; |
|
| 1209 | - } |
|
| 1210 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1211 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1184 | + static $queue_next_job_time = -1; |
|
| 1185 | + if ($force === true) { |
|
| 1186 | + $queue_next_job_time = -1; |
|
| 1187 | + } elseif ($force) { |
|
| 1188 | + $queue_next_job_time = $force; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + if ($queue_next_job_time == -1) { |
|
| 1192 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1193 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1194 | + } |
|
| 1195 | + // utiliser un cache memoire si dispo |
|
| 1196 | + if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1197 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1198 | + } else { |
|
| 1199 | + $queue_next_job_time = null; |
|
| 1200 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1201 | + $queue_next_job_time = intval($contenu); |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + if (is_null($queue_next_job_time)) { |
|
| 1207 | + return null; |
|
| 1208 | + } |
|
| 1209 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1210 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1215 | 1214 | } |
| 1216 | 1215 | |
| 1217 | 1216 | |
@@ -1223,11 +1222,11 @@ discard block |
||
| 1223 | 1222 | * @return string |
| 1224 | 1223 | */ |
| 1225 | 1224 | function quote_amp($u) { |
| 1226 | - return preg_replace( |
|
| 1227 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1228 | - '&', |
|
| 1229 | - $u |
|
| 1230 | - ); |
|
| 1225 | + return preg_replace( |
|
| 1226 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1227 | + '&', |
|
| 1228 | + $u |
|
| 1229 | + ); |
|
| 1231 | 1230 | } |
| 1232 | 1231 | |
| 1233 | 1232 | |
@@ -1250,27 +1249,27 @@ discard block |
||
| 1250 | 1249 | * Balise HTML `<script>` et son contenu |
| 1251 | 1250 | **/ |
| 1252 | 1251 | function http_script($script, $src = '', $noscript = '') { |
| 1253 | - static $done = []; |
|
| 1252 | + static $done = []; |
|
| 1254 | 1253 | |
| 1255 | - if ($src && !isset($done[$src])) { |
|
| 1256 | - $done[$src] = true; |
|
| 1257 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1258 | - $src = " src='$src'"; |
|
| 1259 | - } else { |
|
| 1260 | - $src = ''; |
|
| 1261 | - } |
|
| 1262 | - if ($script) { |
|
| 1263 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1264 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1265 | - '/*]]>*/'); |
|
| 1266 | - } |
|
| 1267 | - if ($noscript) { |
|
| 1268 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1269 | - } |
|
| 1254 | + if ($src && !isset($done[$src])) { |
|
| 1255 | + $done[$src] = true; |
|
| 1256 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1257 | + $src = " src='$src'"; |
|
| 1258 | + } else { |
|
| 1259 | + $src = ''; |
|
| 1260 | + } |
|
| 1261 | + if ($script) { |
|
| 1262 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1263 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1264 | + '/*]]>*/'); |
|
| 1265 | + } |
|
| 1266 | + if ($noscript) { |
|
| 1267 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1268 | + } |
|
| 1270 | 1269 | |
| 1271 | - return ($src or $script or $noscript) |
|
| 1272 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1273 | - : ''; |
|
| 1270 | + return ($src or $script or $noscript) |
|
| 1271 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1272 | + : ''; |
|
| 1274 | 1273 | } |
| 1275 | 1274 | |
| 1276 | 1275 | |
@@ -1305,7 +1304,7 @@ discard block |
||
| 1305 | 1304 | * Texte échappé |
| 1306 | 1305 | **/ |
| 1307 | 1306 | function texte_script(string $texte): string { |
| 1308 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1307 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1309 | 1308 | } |
| 1310 | 1309 | |
| 1311 | 1310 | |
@@ -1342,68 +1341,68 @@ discard block |
||
| 1342 | 1341 | * Liste des chemins, par ordre de priorité. |
| 1343 | 1342 | **/ |
| 1344 | 1343 | function _chemin($dir_path = null) { |
| 1345 | - static $path_base = null; |
|
| 1346 | - static $path_full = null; |
|
| 1347 | - if ($path_base == null) { |
|
| 1348 | - // Chemin standard depuis l'espace public |
|
| 1349 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1350 | - _DIR_RACINE . ':' . |
|
| 1351 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1352 | - _DIR_RACINE . 'prive/:' . |
|
| 1353 | - _DIR_RESTREINT; |
|
| 1354 | - // Ajouter squelettes/ |
|
| 1355 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1356 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1357 | - } |
|
| 1358 | - foreach (explode(':', $path) as $dir) { |
|
| 1359 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1360 | - $dir .= '/'; |
|
| 1361 | - } |
|
| 1362 | - $path_base[] = $dir; |
|
| 1363 | - } |
|
| 1364 | - $path_full = $path_base; |
|
| 1365 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1366 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1367 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1368 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1372 | - } |
|
| 1373 | - if ($dir_path === null) { |
|
| 1374 | - return $path_full; |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1378 | - $tete = ''; |
|
| 1379 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1380 | - $tete = array_shift($path_base); |
|
| 1381 | - } |
|
| 1382 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1383 | - $dirs = array_reverse($dirs); |
|
| 1384 | - foreach ($dirs as $dir_path) { |
|
| 1385 | - if (substr($dir_path, -1) != '/') { |
|
| 1386 | - $dir_path .= '/'; |
|
| 1387 | - } |
|
| 1388 | - if (!in_array($dir_path, $path_base)) { |
|
| 1389 | - array_unshift($path_base, $dir_path); |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - if (strlen($tete)) { |
|
| 1393 | - array_unshift($path_base, $tete); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - $path_full = $path_base; |
|
| 1397 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1398 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1399 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1400 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1401 | - } |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1405 | - |
|
| 1406 | - return $path_full; |
|
| 1344 | + static $path_base = null; |
|
| 1345 | + static $path_full = null; |
|
| 1346 | + if ($path_base == null) { |
|
| 1347 | + // Chemin standard depuis l'espace public |
|
| 1348 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1349 | + _DIR_RACINE . ':' . |
|
| 1350 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1351 | + _DIR_RACINE . 'prive/:' . |
|
| 1352 | + _DIR_RESTREINT; |
|
| 1353 | + // Ajouter squelettes/ |
|
| 1354 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1355 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1356 | + } |
|
| 1357 | + foreach (explode(':', $path) as $dir) { |
|
| 1358 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1359 | + $dir .= '/'; |
|
| 1360 | + } |
|
| 1361 | + $path_base[] = $dir; |
|
| 1362 | + } |
|
| 1363 | + $path_full = $path_base; |
|
| 1364 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1365 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1366 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1367 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1371 | + } |
|
| 1372 | + if ($dir_path === null) { |
|
| 1373 | + return $path_full; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1377 | + $tete = ''; |
|
| 1378 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1379 | + $tete = array_shift($path_base); |
|
| 1380 | + } |
|
| 1381 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1382 | + $dirs = array_reverse($dirs); |
|
| 1383 | + foreach ($dirs as $dir_path) { |
|
| 1384 | + if (substr($dir_path, -1) != '/') { |
|
| 1385 | + $dir_path .= '/'; |
|
| 1386 | + } |
|
| 1387 | + if (!in_array($dir_path, $path_base)) { |
|
| 1388 | + array_unshift($path_base, $dir_path); |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | + if (strlen($tete)) { |
|
| 1392 | + array_unshift($path_base, $tete); |
|
| 1393 | + } |
|
| 1394 | + } |
|
| 1395 | + $path_full = $path_base; |
|
| 1396 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1397 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1398 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1399 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1400 | + } |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1404 | + |
|
| 1405 | + return $path_full; |
|
| 1407 | 1406 | } |
| 1408 | 1407 | |
| 1409 | 1408 | /** |
@@ -1416,78 +1415,78 @@ discard block |
||
| 1416 | 1415 | * @return array Liste de chemins |
| 1417 | 1416 | **/ |
| 1418 | 1417 | function creer_chemin() { |
| 1419 | - $path_a = _chemin(); |
|
| 1420 | - static $c = ''; |
|
| 1418 | + $path_a = _chemin(); |
|
| 1419 | + static $c = ''; |
|
| 1421 | 1420 | |
| 1422 | - // on calcule le chemin si le dossier skel a change |
|
| 1423 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1424 | - // assurer le non plantage lors de la montee de version : |
|
| 1425 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1426 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1427 | - } |
|
| 1421 | + // on calcule le chemin si le dossier skel a change |
|
| 1422 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1423 | + // assurer le non plantage lors de la montee de version : |
|
| 1424 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1425 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1426 | + } |
|
| 1428 | 1427 | |
| 1429 | - return $path_a; |
|
| 1428 | + return $path_a; |
|
| 1430 | 1429 | } |
| 1431 | 1430 | |
| 1432 | 1431 | |
| 1433 | 1432 | function lister_themes_prives() { |
| 1434 | - static $themes = null; |
|
| 1435 | - if (is_null($themes)) { |
|
| 1436 | - // si pas encore definie |
|
| 1437 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1438 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1439 | - } |
|
| 1440 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 1441 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1442 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1443 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1444 | - } else { |
|
| 1445 | - $prefs = []; |
|
| 1446 | - } |
|
| 1447 | - if (is_string($prefs)) { |
|
| 1448 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1449 | - } |
|
| 1450 | - if ( |
|
| 1451 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1452 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1453 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1454 | - ) { |
|
| 1455 | - array_unshift($themes, $theme); |
|
| 1456 | - } // placer le theme choisi en tete |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - return $themes; |
|
| 1433 | + static $themes = null; |
|
| 1434 | + if (is_null($themes)) { |
|
| 1435 | + // si pas encore definie |
|
| 1436 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1437 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1438 | + } |
|
| 1439 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 1440 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1441 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1442 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1443 | + } else { |
|
| 1444 | + $prefs = []; |
|
| 1445 | + } |
|
| 1446 | + if (is_string($prefs)) { |
|
| 1447 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1448 | + } |
|
| 1449 | + if ( |
|
| 1450 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1451 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1452 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1453 | + ) { |
|
| 1454 | + array_unshift($themes, $theme); |
|
| 1455 | + } // placer le theme choisi en tete |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + return $themes; |
|
| 1460 | 1459 | } |
| 1461 | 1460 | |
| 1462 | 1461 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1463 | - static $themefiles = []; |
|
| 1464 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1465 | - return $themefiles["$subdir$file"]; |
|
| 1466 | - } |
|
| 1467 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1468 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1469 | - if ( |
|
| 1470 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1471 | - and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1472 | - and $f = find_in_theme("$file_svg_generique") |
|
| 1473 | - ) { |
|
| 1474 | - if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1475 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1476 | - } |
|
| 1477 | - else { |
|
| 1478 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1479 | - } |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - $themes = lister_themes_prives(); |
|
| 1483 | - foreach ($themes as $theme) { |
|
| 1484 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1485 | - return $themefiles["$subdir$file"] = $f; |
|
| 1486 | - } |
|
| 1487 | - } |
|
| 1488 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1489 | - |
|
| 1490 | - return $themefiles["$subdir$file"] = ''; |
|
| 1462 | + static $themefiles = []; |
|
| 1463 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1464 | + return $themefiles["$subdir$file"]; |
|
| 1465 | + } |
|
| 1466 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1467 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1468 | + if ( |
|
| 1469 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1470 | + and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1471 | + and $f = find_in_theme("$file_svg_generique") |
|
| 1472 | + ) { |
|
| 1473 | + if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1474 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1475 | + } |
|
| 1476 | + else { |
|
| 1477 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + $themes = lister_themes_prives(); |
|
| 1482 | + foreach ($themes as $theme) { |
|
| 1483 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1484 | + return $themefiles["$subdir$file"] = $f; |
|
| 1485 | + } |
|
| 1486 | + } |
|
| 1487 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1488 | + |
|
| 1489 | + return $themefiles["$subdir$file"] = ''; |
|
| 1491 | 1490 | } |
| 1492 | 1491 | |
| 1493 | 1492 | |
@@ -1511,31 +1510,31 @@ discard block |
||
| 1511 | 1510 | * sinon chaîne vide. |
| 1512 | 1511 | **/ |
| 1513 | 1512 | function chemin_image($icone) { |
| 1514 | - static $icone_renommer; |
|
| 1515 | - if ($p = strpos($icone, '?')) { |
|
| 1516 | - $icone = substr($icone, 0, $p); |
|
| 1517 | - } |
|
| 1518 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1519 | - if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1520 | - return $icone; |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1524 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1525 | - return $f; |
|
| 1526 | - } |
|
| 1527 | - // sinon passer par le module de renommage |
|
| 1528 | - if (is_null($icone_renommer)) { |
|
| 1529 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1530 | - } |
|
| 1531 | - if ($icone_renommer) { |
|
| 1532 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1533 | - if (file_exists($icone)) { |
|
| 1534 | - return $icone; |
|
| 1535 | - } |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1513 | + static $icone_renommer; |
|
| 1514 | + if ($p = strpos($icone, '?')) { |
|
| 1515 | + $icone = substr($icone, 0, $p); |
|
| 1516 | + } |
|
| 1517 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1518 | + if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1519 | + return $icone; |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1523 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1524 | + return $f; |
|
| 1525 | + } |
|
| 1526 | + // sinon passer par le module de renommage |
|
| 1527 | + if (is_null($icone_renommer)) { |
|
| 1528 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1529 | + } |
|
| 1530 | + if ($icone_renommer) { |
|
| 1531 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1532 | + if (file_exists($icone)) { |
|
| 1533 | + return $icone; |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1539 | 1538 | } |
| 1540 | 1539 | |
| 1541 | 1540 | // |
@@ -1573,128 +1572,128 @@ discard block |
||
| 1573 | 1572 | * - false : fichier introuvable |
| 1574 | 1573 | **/ |
| 1575 | 1574 | function find_in_path($file, $dirname = '', $include = false) { |
| 1576 | - static $dirs = []; |
|
| 1577 | - static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1578 | - static $c = ''; |
|
| 1579 | - |
|
| 1580 | - if (!$file and !strlen($file)) { |
|
| 1581 | - return false; |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - // on calcule le chemin si le dossier skel a change |
|
| 1585 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1586 | - // assurer le non plantage lors de la montee de version : |
|
| 1587 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1588 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1589 | - } |
|
| 1590 | - |
|
| 1591 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1592 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1593 | - return false; |
|
| 1594 | - } |
|
| 1595 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1596 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1597 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - $a = strrpos($file, '/'); |
|
| 1604 | - if ($a !== false) { |
|
| 1605 | - $dirname .= substr($file, 0, ++$a); |
|
| 1606 | - $file = substr($file, $a); |
|
| 1607 | - } |
|
| 1608 | - |
|
| 1609 | - foreach (creer_chemin() as $dir) { |
|
| 1610 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1611 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1612 | - } |
|
| 1613 | - if ($dirs[$a]) { |
|
| 1614 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1615 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1616 | - include_once _ROOT_CWD . $a; |
|
| 1617 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1618 | - } |
|
| 1619 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1620 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1621 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1622 | - return $a; |
|
| 1623 | - } |
|
| 1624 | - define('_SAUVER_CHEMIN', true); |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - if ($include) { |
|
| 1633 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1634 | - if ($include === 'required') { |
|
| 1635 | - echo '<pre>', |
|
| 1636 | - '<strong>Erreur Fatale</strong><br />'; |
|
| 1637 | - if (function_exists('debug_print_backtrace')) { |
|
| 1638 | - echo debug_print_backtrace(); |
|
| 1639 | - } |
|
| 1640 | - echo '</pre>'; |
|
| 1641 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1642 | - } |
|
| 1643 | - } |
|
| 1644 | - |
|
| 1645 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1646 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1647 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1648 | - return false; |
|
| 1649 | - } |
|
| 1650 | - define('_SAUVER_CHEMIN', true); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1575 | + static $dirs = []; |
|
| 1576 | + static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1577 | + static $c = ''; |
|
| 1578 | + |
|
| 1579 | + if (!$file and !strlen($file)) { |
|
| 1580 | + return false; |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + // on calcule le chemin si le dossier skel a change |
|
| 1584 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1585 | + // assurer le non plantage lors de la montee de version : |
|
| 1586 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1587 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1591 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1592 | + return false; |
|
| 1593 | + } |
|
| 1594 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1595 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1596 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + $a = strrpos($file, '/'); |
|
| 1603 | + if ($a !== false) { |
|
| 1604 | + $dirname .= substr($file, 0, ++$a); |
|
| 1605 | + $file = substr($file, $a); |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + foreach (creer_chemin() as $dir) { |
|
| 1609 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1610 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1611 | + } |
|
| 1612 | + if ($dirs[$a]) { |
|
| 1613 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1614 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1615 | + include_once _ROOT_CWD . $a; |
|
| 1616 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1617 | + } |
|
| 1618 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1619 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1620 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1621 | + return $a; |
|
| 1622 | + } |
|
| 1623 | + define('_SAUVER_CHEMIN', true); |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + if ($include) { |
|
| 1632 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1633 | + if ($include === 'required') { |
|
| 1634 | + echo '<pre>', |
|
| 1635 | + '<strong>Erreur Fatale</strong><br />'; |
|
| 1636 | + if (function_exists('debug_print_backtrace')) { |
|
| 1637 | + echo debug_print_backtrace(); |
|
| 1638 | + } |
|
| 1639 | + echo '</pre>'; |
|
| 1640 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1641 | + } |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1645 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1646 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1647 | + return false; |
|
| 1648 | + } |
|
| 1649 | + define('_SAUVER_CHEMIN', true); |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1654 | 1653 | } |
| 1655 | 1654 | |
| 1656 | 1655 | function clear_path_cache() { |
| 1657 | - $GLOBALS['path_files'] = []; |
|
| 1658 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1656 | + $GLOBALS['path_files'] = []; |
|
| 1657 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1659 | 1658 | } |
| 1660 | 1659 | |
| 1661 | 1660 | function load_path_cache() { |
| 1662 | - // charger le path des plugins |
|
| 1663 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1664 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1665 | - } |
|
| 1666 | - $GLOBALS['path_files'] = []; |
|
| 1667 | - // si le visiteur est admin, |
|
| 1668 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1669 | - if ( |
|
| 1670 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1671 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1672 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1673 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1674 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1675 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1676 | - !_request('var_mode') |
|
| 1677 | - ) { |
|
| 1678 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1679 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1680 | - // mais si semble corrompu on relit avec un verrou |
|
| 1681 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1682 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1683 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1684 | - $GLOBALS['path_files'] = []; |
|
| 1685 | - } |
|
| 1686 | - } |
|
| 1687 | - } |
|
| 1688 | - } |
|
| 1661 | + // charger le path des plugins |
|
| 1662 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1663 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1664 | + } |
|
| 1665 | + $GLOBALS['path_files'] = []; |
|
| 1666 | + // si le visiteur est admin, |
|
| 1667 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1668 | + if ( |
|
| 1669 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1670 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1671 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1672 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1673 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1674 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1675 | + !_request('var_mode') |
|
| 1676 | + ) { |
|
| 1677 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1678 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1679 | + // mais si semble corrompu on relit avec un verrou |
|
| 1680 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1681 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1682 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1683 | + $GLOBALS['path_files'] = []; |
|
| 1684 | + } |
|
| 1685 | + } |
|
| 1686 | + } |
|
| 1687 | + } |
|
| 1689 | 1688 | } |
| 1690 | 1689 | |
| 1691 | 1690 | function save_path_cache() { |
| 1692 | - if ( |
|
| 1693 | - defined('_SAUVER_CHEMIN') |
|
| 1694 | - and _SAUVER_CHEMIN |
|
| 1695 | - ) { |
|
| 1696 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1697 | - } |
|
| 1691 | + if ( |
|
| 1692 | + defined('_SAUVER_CHEMIN') |
|
| 1693 | + and _SAUVER_CHEMIN |
|
| 1694 | + ) { |
|
| 1695 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1696 | + } |
|
| 1698 | 1697 | } |
| 1699 | 1698 | |
| 1700 | 1699 | |
@@ -1714,33 +1713,33 @@ discard block |
||
| 1714 | 1713 | * @return array |
| 1715 | 1714 | */ |
| 1716 | 1715 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1717 | - $liste_fichiers = []; |
|
| 1718 | - $maxfiles = 10000; |
|
| 1719 | - |
|
| 1720 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1721 | - // on a pas encore inclus flock.php |
|
| 1722 | - if (!function_exists('preg_files')) { |
|
| 1723 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - // Parcourir le chemin |
|
| 1727 | - foreach (creer_chemin() as $d) { |
|
| 1728 | - $f = $d . $dir; |
|
| 1729 | - if (@is_dir($f)) { |
|
| 1730 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1731 | - foreach ($liste as $chemin) { |
|
| 1732 | - $nom = basename($chemin); |
|
| 1733 | - // ne prendre que les fichiers pas deja trouves |
|
| 1734 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1735 | - // les autres sont donc masques |
|
| 1736 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1737 | - $liste_fichiers[$nom] = $chemin; |
|
| 1738 | - } |
|
| 1739 | - } |
|
| 1740 | - } |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - return $liste_fichiers; |
|
| 1716 | + $liste_fichiers = []; |
|
| 1717 | + $maxfiles = 10000; |
|
| 1718 | + |
|
| 1719 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1720 | + // on a pas encore inclus flock.php |
|
| 1721 | + if (!function_exists('preg_files')) { |
|
| 1722 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + // Parcourir le chemin |
|
| 1726 | + foreach (creer_chemin() as $d) { |
|
| 1727 | + $f = $d . $dir; |
|
| 1728 | + if (@is_dir($f)) { |
|
| 1729 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1730 | + foreach ($liste as $chemin) { |
|
| 1731 | + $nom = basename($chemin); |
|
| 1732 | + // ne prendre que les fichiers pas deja trouves |
|
| 1733 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1734 | + // les autres sont donc masques |
|
| 1735 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1736 | + $liste_fichiers[$nom] = $chemin; |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + } |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + return $liste_fichiers; |
|
| 1744 | 1743 | } |
| 1745 | 1744 | |
| 1746 | 1745 | /** |
@@ -1752,17 +1751,17 @@ discard block |
||
| 1752 | 1751 | * @return bool |
| 1753 | 1752 | */ |
| 1754 | 1753 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1755 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 1754 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 1756 | 1755 | |
| 1757 | - if (in_array($nom, $autsanscookie)) { |
|
| 1758 | - if (test_espace_prive()) { |
|
| 1759 | - include_spip('base/connect_sql'); |
|
| 1760 | - if (!$strict or !spip_connect()) { |
|
| 1761 | - return true; |
|
| 1762 | - } |
|
| 1763 | - } |
|
| 1764 | - } |
|
| 1765 | - return false; |
|
| 1756 | + if (in_array($nom, $autsanscookie)) { |
|
| 1757 | + if (test_espace_prive()) { |
|
| 1758 | + include_spip('base/connect_sql'); |
|
| 1759 | + if (!$strict or !spip_connect()) { |
|
| 1760 | + return true; |
|
| 1761 | + } |
|
| 1762 | + } |
|
| 1763 | + } |
|
| 1764 | + return false; |
|
| 1766 | 1765 | } |
| 1767 | 1766 | |
| 1768 | 1767 | /** |
@@ -1772,56 +1771,56 @@ discard block |
||
| 1772 | 1771 | * @return string |
| 1773 | 1772 | */ |
| 1774 | 1773 | function charger_fonction_url(string $quoi, string $type = '') { |
| 1775 | - if ($type === 'defaut') { |
|
| 1776 | - $objet = objet_type($quoi); |
|
| 1777 | - if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true) |
|
| 1778 | - // deprecated |
|
| 1779 | - or $f = charger_fonction('generer_url_' . $objet, 'urls', true) |
|
| 1780 | - ) { |
|
| 1781 | - return $f; |
|
| 1782 | - } |
|
| 1783 | - return ''; |
|
| 1784 | - } |
|
| 1785 | - |
|
| 1786 | - if (!$type) { |
|
| 1787 | - $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - // inclure le module d'url |
|
| 1791 | - include_spip('urls/'.$type); |
|
| 1792 | - |
|
| 1793 | - switch ($quoi) { |
|
| 1794 | - case 'page': |
|
| 1795 | - if ( |
|
| 1796 | - function_exists($f = "urls_{$type}_generer_url_page") |
|
| 1797 | - or function_exists($f .= "_dist") |
|
| 1798 | - // ou une fonction custom utilisateur independante du type d'url |
|
| 1799 | - or function_exists($f = "generer_url_page") |
|
| 1800 | - or function_exists($f .= "_dist") |
|
| 1801 | - ) { |
|
| 1802 | - return $f; |
|
| 1803 | - } |
|
| 1804 | - // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1805 | - return ''; |
|
| 1806 | - case 'objet': |
|
| 1807 | - case 'decoder': |
|
| 1808 | - default: |
|
| 1809 | - $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1810 | - if (function_exists($f = "urls_{$type}_{$fquoi}") |
|
| 1811 | - or function_exists($f .= "_dist")) { |
|
| 1812 | - return $f; |
|
| 1813 | - } |
|
| 1814 | - // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1815 | - // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1816 | - if ($f = charger_fonction($type, 'urls', true)) { |
|
| 1817 | - return $f; |
|
| 1818 | - } |
|
| 1819 | - // sinon on se rabat sur les urls page |
|
| 1820 | - if ($type !== 'page') { |
|
| 1821 | - return charger_fonction_url($quoi, 'page'); |
|
| 1822 | - } |
|
| 1823 | - return ''; |
|
| 1824 | - } |
|
| 1774 | + if ($type === 'defaut') { |
|
| 1775 | + $objet = objet_type($quoi); |
|
| 1776 | + if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true) |
|
| 1777 | + // deprecated |
|
| 1778 | + or $f = charger_fonction('generer_url_' . $objet, 'urls', true) |
|
| 1779 | + ) { |
|
| 1780 | + return $f; |
|
| 1781 | + } |
|
| 1782 | + return ''; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + if (!$type) { |
|
| 1786 | + $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1787 | + } |
|
| 1788 | + |
|
| 1789 | + // inclure le module d'url |
|
| 1790 | + include_spip('urls/'.$type); |
|
| 1791 | + |
|
| 1792 | + switch ($quoi) { |
|
| 1793 | + case 'page': |
|
| 1794 | + if ( |
|
| 1795 | + function_exists($f = "urls_{$type}_generer_url_page") |
|
| 1796 | + or function_exists($f .= "_dist") |
|
| 1797 | + // ou une fonction custom utilisateur independante du type d'url |
|
| 1798 | + or function_exists($f = "generer_url_page") |
|
| 1799 | + or function_exists($f .= "_dist") |
|
| 1800 | + ) { |
|
| 1801 | + return $f; |
|
| 1802 | + } |
|
| 1803 | + // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1804 | + return ''; |
|
| 1805 | + case 'objet': |
|
| 1806 | + case 'decoder': |
|
| 1807 | + default: |
|
| 1808 | + $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1809 | + if (function_exists($f = "urls_{$type}_{$fquoi}") |
|
| 1810 | + or function_exists($f .= "_dist")) { |
|
| 1811 | + return $f; |
|
| 1812 | + } |
|
| 1813 | + // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1814 | + // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1815 | + if ($f = charger_fonction($type, 'urls', true)) { |
|
| 1816 | + return $f; |
|
| 1817 | + } |
|
| 1818 | + // sinon on se rabat sur les urls page |
|
| 1819 | + if ($type !== 'page') { |
|
| 1820 | + return charger_fonction_url($quoi, 'page'); |
|
| 1821 | + } |
|
| 1822 | + return ''; |
|
| 1823 | + } |
|
| 1825 | 1824 | } |
| 1826 | 1825 | |
| 1827 | 1826 | |
@@ -1850,47 +1849,47 @@ discard block |
||
| 1850 | 1849 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire) |
| 1851 | 1850 | */ |
| 1852 | 1851 | function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 1853 | - if ($public === null) { |
|
| 1854 | - $public = !test_espace_prive(); |
|
| 1855 | - } |
|
| 1856 | - $id = intval($id); |
|
| 1857 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1858 | - |
|
| 1859 | - if (!$public) { |
|
| 1860 | - if (!$entite) { |
|
| 1861 | - return ''; |
|
| 1862 | - } |
|
| 1863 | - if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1864 | - include_spip('inc/urls'); |
|
| 1865 | - } |
|
| 1866 | - $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1867 | - } else { |
|
| 1868 | - $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1869 | - |
|
| 1870 | - // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1871 | - // @see charger_fonction_url |
|
| 1872 | - if (!$entite) { |
|
| 1873 | - return $f; |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1877 | - // base distante |
|
| 1878 | - if ($connect |
|
| 1879 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1880 | - ) { |
|
| 1881 | - $f = $g; |
|
| 1882 | - } |
|
| 1883 | - |
|
| 1884 | - $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1885 | - } |
|
| 1886 | - if ($res) { |
|
| 1887 | - return $res; |
|
| 1888 | - } |
|
| 1889 | - |
|
| 1890 | - // On a ete gentil mais la .... |
|
| 1891 | - spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1892 | - |
|
| 1893 | - return ''; |
|
| 1852 | + if ($public === null) { |
|
| 1853 | + $public = !test_espace_prive(); |
|
| 1854 | + } |
|
| 1855 | + $id = intval($id); |
|
| 1856 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1857 | + |
|
| 1858 | + if (!$public) { |
|
| 1859 | + if (!$entite) { |
|
| 1860 | + return ''; |
|
| 1861 | + } |
|
| 1862 | + if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1863 | + include_spip('inc/urls'); |
|
| 1864 | + } |
|
| 1865 | + $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1866 | + } else { |
|
| 1867 | + $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1868 | + |
|
| 1869 | + // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1870 | + // @see charger_fonction_url |
|
| 1871 | + if (!$entite) { |
|
| 1872 | + return $f; |
|
| 1873 | + } |
|
| 1874 | + |
|
| 1875 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1876 | + // base distante |
|
| 1877 | + if ($connect |
|
| 1878 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1879 | + ) { |
|
| 1880 | + $f = $g; |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1884 | + } |
|
| 1885 | + if ($res) { |
|
| 1886 | + return $res; |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + // On a ete gentil mais la .... |
|
| 1890 | + spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1891 | + |
|
| 1892 | + return ''; |
|
| 1894 | 1893 | } |
| 1895 | 1894 | |
| 1896 | 1895 | /** |
@@ -1898,10 +1897,10 @@ discard block |
||
| 1898 | 1897 | * @see generer_objet_url |
| 1899 | 1898 | */ |
| 1900 | 1899 | function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null){ |
| 1901 | - if ($public and is_string($public)) { |
|
| 1902 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1903 | - } |
|
| 1904 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1900 | + if ($public and is_string($public)) { |
|
| 1901 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1902 | + } |
|
| 1903 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1905 | 1904 | } |
| 1906 | 1905 | |
| 1907 | 1906 | /** |
@@ -1913,19 +1912,19 @@ discard block |
||
| 1913 | 1912 | * @return string |
| 1914 | 1913 | */ |
| 1915 | 1914 | function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string { |
| 1916 | - $id = intval($id); |
|
| 1917 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1918 | - $url = generer_url_ecrire($exec, $args); |
|
| 1919 | - if (intval($id)) { |
|
| 1920 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1921 | - } else { |
|
| 1922 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1923 | - } |
|
| 1924 | - if ($ancre) { |
|
| 1925 | - $url = ancre_url($url, $ancre); |
|
| 1926 | - } |
|
| 1915 | + $id = intval($id); |
|
| 1916 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1917 | + $url = generer_url_ecrire($exec, $args); |
|
| 1918 | + if (intval($id)) { |
|
| 1919 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1920 | + } else { |
|
| 1921 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1922 | + } |
|
| 1923 | + if ($ancre) { |
|
| 1924 | + $url = ancre_url($url, $ancre); |
|
| 1925 | + } |
|
| 1927 | 1926 | |
| 1928 | - return $url; |
|
| 1927 | + return $url; |
|
| 1929 | 1928 | } |
| 1930 | 1929 | |
| 1931 | 1930 | /** |
@@ -1933,18 +1932,18 @@ discard block |
||
| 1933 | 1932 | * @see generer_objet_url_ecrire_edit |
| 1934 | 1933 | */ |
| 1935 | 1934 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = ''){ |
| 1936 | - return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1935 | + return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1937 | 1936 | } |
| 1938 | 1937 | |
| 1939 | 1938 | |
| 1940 | 1939 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1941 | - include_spip('base/connect_sql'); |
|
| 1942 | - $id_type = id_table_objet($entite, $public); |
|
| 1940 | + include_spip('base/connect_sql'); |
|
| 1941 | + $id_type = id_table_objet($entite, $public); |
|
| 1943 | 1942 | |
| 1944 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1945 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1946 | - . (!$args ? '' : "&$args") |
|
| 1947 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1943 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1944 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1945 | + . (!$args ? '' : "&$args") |
|
| 1946 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1948 | 1947 | } |
| 1949 | 1948 | |
| 1950 | 1949 | |
@@ -1955,18 +1954,18 @@ discard block |
||
| 1955 | 1954 | * @return string |
| 1956 | 1955 | */ |
| 1957 | 1956 | function urlencode_1738($url) { |
| 1958 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1959 | - $uri = ''; |
|
| 1960 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1961 | - if (ord($a = $url[$i]) > 127) { |
|
| 1962 | - $a = rawurlencode($a); |
|
| 1963 | - } |
|
| 1964 | - $uri .= $a; |
|
| 1965 | - } |
|
| 1966 | - $url = $uri; |
|
| 1967 | - } |
|
| 1957 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1958 | + $uri = ''; |
|
| 1959 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1960 | + if (ord($a = $url[$i]) > 127) { |
|
| 1961 | + $a = rawurlencode($a); |
|
| 1962 | + } |
|
| 1963 | + $uri .= $a; |
|
| 1964 | + } |
|
| 1965 | + $url = $uri; |
|
| 1966 | + } |
|
| 1968 | 1967 | |
| 1969 | - return quote_amp($url); |
|
| 1968 | + return quote_amp($url); |
|
| 1970 | 1969 | } |
| 1971 | 1970 | |
| 1972 | 1971 | /** |
@@ -1982,14 +1981,14 @@ discard block |
||
| 1982 | 1981 | * @return string |
| 1983 | 1982 | */ |
| 1984 | 1983 | function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 1985 | - $id = intval($id); |
|
| 1986 | - $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 1987 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1988 | - include_spip('inc/filtres_mini'); |
|
| 1989 | - $h = url_absolue($h); |
|
| 1990 | - } |
|
| 1984 | + $id = intval($id); |
|
| 1985 | + $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 1986 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1987 | + include_spip('inc/filtres_mini'); |
|
| 1988 | + $h = url_absolue($h); |
|
| 1989 | + } |
|
| 1991 | 1990 | |
| 1992 | - return $h; |
|
| 1991 | + return $h; |
|
| 1993 | 1992 | } |
| 1994 | 1993 | |
| 1995 | 1994 | /** |
@@ -1997,7 +1996,7 @@ discard block |
||
| 1997 | 1996 | * @see generer_objet_url_absolue |
| 1998 | 1997 | */ |
| 1999 | 1998 | function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null){ |
| 2000 | - return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect); |
|
| 1999 | + return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect); |
|
| 2001 | 2000 | } |
| 2002 | 2001 | |
| 2003 | 2002 | |
@@ -2013,11 +2012,11 @@ discard block |
||
| 2013 | 2012 | * true si la valeur est considérée active ; false sinon. |
| 2014 | 2013 | **/ |
| 2015 | 2014 | function test_valeur_serveur($truc) { |
| 2016 | - if (!$truc) { |
|
| 2017 | - return false; |
|
| 2018 | - } |
|
| 2015 | + if (!$truc) { |
|
| 2016 | + return false; |
|
| 2017 | + } |
|
| 2019 | 2018 | |
| 2020 | - return (strtolower($truc) !== 'off'); |
|
| 2019 | + return (strtolower($truc) !== 'off'); |
|
| 2021 | 2020 | } |
| 2022 | 2021 | |
| 2023 | 2022 | // |
@@ -2045,82 +2044,82 @@ discard block |
||
| 2045 | 2044 | */ |
| 2046 | 2045 | function url_de_base($profondeur = null) { |
| 2047 | 2046 | |
| 2048 | - static $url = []; |
|
| 2049 | - if (is_array($profondeur)) { |
|
| 2050 | - return $url = $profondeur; |
|
| 2051 | - } |
|
| 2052 | - if ($profondeur === false) { |
|
| 2053 | - return $url; |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - if (is_null($profondeur)) { |
|
| 2057 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2058 | - } |
|
| 2059 | - |
|
| 2060 | - if (isset($url[$profondeur])) { |
|
| 2061 | - return $url[$profondeur]; |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - $http = 'http'; |
|
| 2065 | - |
|
| 2066 | - if ( |
|
| 2067 | - isset($_SERVER['SCRIPT_URI']) |
|
| 2068 | - and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 2069 | - ) { |
|
| 2070 | - $http = 'https'; |
|
| 2071 | - } elseif ( |
|
| 2072 | - isset($_SERVER['HTTPS']) |
|
| 2073 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2074 | - ) { |
|
| 2075 | - $http = 'https'; |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 2079 | - $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 2080 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2081 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2082 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 2083 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2084 | - $http = $scheme; |
|
| 2085 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - if ( |
|
| 2089 | - isset($_SERVER['SERVER_PORT']) |
|
| 2090 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 2091 | - and strpos($host, ':') == false |
|
| 2092 | - ) { |
|
| 2093 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2094 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 2095 | - } |
|
| 2096 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2097 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2098 | - } |
|
| 2099 | - if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2100 | - $host .= ":$port"; |
|
| 2101 | - } |
|
| 2102 | - if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2103 | - $host .= ":$port"; |
|
| 2104 | - } |
|
| 2105 | - } |
|
| 2106 | - |
|
| 2107 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2108 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2109 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2110 | - } else { |
|
| 2111 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2112 | - if ( |
|
| 2113 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2114 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2115 | - ) { |
|
| 2116 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2117 | - } |
|
| 2118 | - } |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2122 | - |
|
| 2123 | - return $url[$profondeur]; |
|
| 2047 | + static $url = []; |
|
| 2048 | + if (is_array($profondeur)) { |
|
| 2049 | + return $url = $profondeur; |
|
| 2050 | + } |
|
| 2051 | + if ($profondeur === false) { |
|
| 2052 | + return $url; |
|
| 2053 | + } |
|
| 2054 | + |
|
| 2055 | + if (is_null($profondeur)) { |
|
| 2056 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + if (isset($url[$profondeur])) { |
|
| 2060 | + return $url[$profondeur]; |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + $http = 'http'; |
|
| 2064 | + |
|
| 2065 | + if ( |
|
| 2066 | + isset($_SERVER['SCRIPT_URI']) |
|
| 2067 | + and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 2068 | + ) { |
|
| 2069 | + $http = 'https'; |
|
| 2070 | + } elseif ( |
|
| 2071 | + isset($_SERVER['HTTPS']) |
|
| 2072 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2073 | + ) { |
|
| 2074 | + $http = 'https'; |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 2078 | + $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 2079 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2080 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2081 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 2082 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2083 | + $http = $scheme; |
|
| 2084 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 2085 | + } |
|
| 2086 | + } |
|
| 2087 | + if ( |
|
| 2088 | + isset($_SERVER['SERVER_PORT']) |
|
| 2089 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 2090 | + and strpos($host, ':') == false |
|
| 2091 | + ) { |
|
| 2092 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2093 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 2094 | + } |
|
| 2095 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2096 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2097 | + } |
|
| 2098 | + if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2099 | + $host .= ":$port"; |
|
| 2100 | + } |
|
| 2101 | + if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2102 | + $host .= ":$port"; |
|
| 2103 | + } |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2107 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2108 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2109 | + } else { |
|
| 2110 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2111 | + if ( |
|
| 2112 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2113 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2114 | + ) { |
|
| 2115 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2116 | + } |
|
| 2117 | + } |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2121 | + |
|
| 2122 | + return $url[$profondeur]; |
|
| 2124 | 2123 | } |
| 2125 | 2124 | |
| 2126 | 2125 | /** |
@@ -2133,26 +2132,26 @@ discard block |
||
| 2133 | 2132 | * @return string |
| 2134 | 2133 | */ |
| 2135 | 2134 | function url_de_($http, $host, $request, $prof = 0) { |
| 2136 | - $prof = max($prof, 0); |
|
| 2135 | + $prof = max($prof, 0); |
|
| 2137 | 2136 | |
| 2138 | - $myself = ltrim($request, '/'); |
|
| 2139 | - # supprimer la chaine de GET |
|
| 2140 | - [$myself] = explode('?', $myself); |
|
| 2141 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2142 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2143 | - if (strpos($myself, '://') !== false) { |
|
| 2144 | - $myself = explode('://', $myself); |
|
| 2145 | - array_shift($myself); |
|
| 2146 | - $myself = implode('://', $myself); |
|
| 2147 | - $myself = explode('/', $myself); |
|
| 2148 | - array_shift($myself); |
|
| 2149 | - $myself = implode('/', $myself); |
|
| 2150 | - } |
|
| 2151 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2137 | + $myself = ltrim($request, '/'); |
|
| 2138 | + # supprimer la chaine de GET |
|
| 2139 | + [$myself] = explode('?', $myself); |
|
| 2140 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2141 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2142 | + if (strpos($myself, '://') !== false) { |
|
| 2143 | + $myself = explode('://', $myself); |
|
| 2144 | + array_shift($myself); |
|
| 2145 | + $myself = implode('://', $myself); |
|
| 2146 | + $myself = explode('/', $myself); |
|
| 2147 | + array_shift($myself); |
|
| 2148 | + $myself = implode('/', $myself); |
|
| 2149 | + } |
|
| 2150 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2152 | 2151 | |
| 2153 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2152 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2154 | 2153 | |
| 2155 | - return $url; |
|
| 2154 | + return $url; |
|
| 2156 | 2155 | } |
| 2157 | 2156 | |
| 2158 | 2157 | |
@@ -2187,25 +2186,25 @@ discard block |
||
| 2187 | 2186 | * @return string URL |
| 2188 | 2187 | **/ |
| 2189 | 2188 | function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) { |
| 2190 | - if (!$rel) { |
|
| 2191 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2192 | - } else { |
|
| 2193 | - if (!is_string($rel)) { |
|
| 2194 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2195 | - } |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2199 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2200 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2201 | - } elseif ($args) { |
|
| 2202 | - $args = "?$args"; |
|
| 2203 | - } |
|
| 2204 | - if ($ancre) { |
|
| 2205 | - $args .= "#$ancre"; |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2189 | + if (!$rel) { |
|
| 2190 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2191 | + } else { |
|
| 2192 | + if (!is_string($rel)) { |
|
| 2193 | + $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2194 | + } |
|
| 2195 | + } |
|
| 2196 | + |
|
| 2197 | + [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2198 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2199 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2200 | + } elseif ($args) { |
|
| 2201 | + $args = "?$args"; |
|
| 2202 | + } |
|
| 2203 | + if ($ancre) { |
|
| 2204 | + $args .= "#$ancre"; |
|
| 2205 | + } |
|
| 2206 | + |
|
| 2207 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2209 | 2208 | } |
| 2210 | 2209 | |
| 2211 | 2210 | // |
@@ -2227,15 +2226,15 @@ discard block |
||
| 2227 | 2226 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2228 | 2227 | **/ |
| 2229 | 2228 | function get_spip_script($default = '') { |
| 2230 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2231 | - return 'spip.php'; |
|
| 2232 | - } |
|
| 2233 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2234 | - if (_SPIP_SCRIPT) { |
|
| 2235 | - return _SPIP_SCRIPT; |
|
| 2236 | - } else { |
|
| 2237 | - return $default; |
|
| 2238 | - } |
|
| 2229 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2230 | + return 'spip.php'; |
|
| 2231 | + } |
|
| 2232 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2233 | + if (_SPIP_SCRIPT) { |
|
| 2234 | + return _SPIP_SCRIPT; |
|
| 2235 | + } else { |
|
| 2236 | + return $default; |
|
| 2237 | + } |
|
| 2239 | 2238 | } |
| 2240 | 2239 | |
| 2241 | 2240 | /** |
@@ -2264,45 +2263,45 @@ discard block |
||
| 2264 | 2263 | * @return string URL |
| 2265 | 2264 | **/ |
| 2266 | 2265 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 2267 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2268 | - // standardiser vers la nouvelle API |
|
| 2269 | - |
|
| 2270 | - if (is_array($args)) { |
|
| 2271 | - $args = http_build_query($args); |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - $url = ''; |
|
| 2275 | - if ($f = charger_fonction_url('page')) { |
|
| 2276 | - $url = $f($script, $args); |
|
| 2277 | - if ($url and !$rel) { |
|
| 2278 | - include_spip('inc/filtres_mini'); |
|
| 2279 | - $url = url_absolue($url); |
|
| 2280 | - } |
|
| 2281 | - } |
|
| 2282 | - if (!$url) { |
|
| 2283 | - if (!$action) { |
|
| 2284 | - $action = get_spip_script(); |
|
| 2285 | - } |
|
| 2286 | - if ($script) { |
|
| 2287 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2288 | - } |
|
| 2289 | - if ($args) { |
|
| 2290 | - $action .= (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2291 | - } |
|
| 2292 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2293 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - if (!$no_entities) { |
|
| 2297 | - $url = quote_amp($url); |
|
| 2298 | - } |
|
| 2299 | - |
|
| 2300 | - return $url; |
|
| 2266 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2267 | + // standardiser vers la nouvelle API |
|
| 2268 | + |
|
| 2269 | + if (is_array($args)) { |
|
| 2270 | + $args = http_build_query($args); |
|
| 2271 | + } |
|
| 2272 | + |
|
| 2273 | + $url = ''; |
|
| 2274 | + if ($f = charger_fonction_url('page')) { |
|
| 2275 | + $url = $f($script, $args); |
|
| 2276 | + if ($url and !$rel) { |
|
| 2277 | + include_spip('inc/filtres_mini'); |
|
| 2278 | + $url = url_absolue($url); |
|
| 2279 | + } |
|
| 2280 | + } |
|
| 2281 | + if (!$url) { |
|
| 2282 | + if (!$action) { |
|
| 2283 | + $action = get_spip_script(); |
|
| 2284 | + } |
|
| 2285 | + if ($script) { |
|
| 2286 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2287 | + } |
|
| 2288 | + if ($args) { |
|
| 2289 | + $action .= (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2290 | + } |
|
| 2291 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2292 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2293 | + } |
|
| 2294 | + |
|
| 2295 | + if (!$no_entities) { |
|
| 2296 | + $url = quote_amp($url); |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + return $url; |
|
| 2301 | 2300 | } |
| 2302 | 2301 | |
| 2303 | 2302 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2304 | 2303 | |
| 2305 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2304 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2306 | 2305 | } |
| 2307 | 2306 | |
| 2308 | 2307 | // Pour les formulaires en methode POST, |
@@ -2327,19 +2326,19 @@ discard block |
||
| 2327 | 2326 | **/ |
| 2328 | 2327 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2329 | 2328 | |
| 2330 | - $script1 = explode('&', $script); |
|
| 2331 | - $script1 = reset($script1); |
|
| 2329 | + $script1 = explode('&', $script); |
|
| 2330 | + $script1 = reset($script1); |
|
| 2332 | 2331 | |
| 2333 | - return "<form action='" |
|
| 2334 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2335 | - . "' " |
|
| 2336 | - . ($atts ?: " method='post'") |
|
| 2337 | - . "><div>\n" |
|
| 2338 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2339 | - . $corps |
|
| 2340 | - . (!$submit ? '' : |
|
| 2341 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2342 | - . "</div></form>\n"; |
|
| 2332 | + return "<form action='" |
|
| 2333 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2334 | + . "' " |
|
| 2335 | + . ($atts ?: " method='post'") |
|
| 2336 | + . "><div>\n" |
|
| 2337 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2338 | + . $corps |
|
| 2339 | + . (!$submit ? '' : |
|
| 2340 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2341 | + . "</div></form>\n"; |
|
| 2343 | 2342 | } |
| 2344 | 2343 | |
| 2345 | 2344 | /** |
@@ -2356,22 +2355,22 @@ discard block |
||
| 2356 | 2355 | * @return string |
| 2357 | 2356 | */ |
| 2358 | 2357 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2359 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2360 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2361 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2362 | - $h = (_DIR_RACINE and !$public) |
|
| 2363 | - ? generer_url_ecrire(_request('exec')) |
|
| 2364 | - : generer_url_public(); |
|
| 2358 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2359 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2360 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2361 | + $h = (_DIR_RACINE and !$public) |
|
| 2362 | + ? generer_url_ecrire(_request('exec')) |
|
| 2363 | + : generer_url_public(); |
|
| 2365 | 2364 | |
| 2366 | - return "\n<form action='" . |
|
| 2367 | - $h . |
|
| 2368 | - "'" . |
|
| 2369 | - $atts . |
|
| 2370 | - ">\n" . |
|
| 2371 | - '<div>' . |
|
| 2372 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2373 | - $corps . |
|
| 2374 | - '</div></form>'; |
|
| 2365 | + return "\n<form action='" . |
|
| 2366 | + $h . |
|
| 2367 | + "'" . |
|
| 2368 | + $atts . |
|
| 2369 | + ">\n" . |
|
| 2370 | + '<div>' . |
|
| 2371 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2372 | + $corps . |
|
| 2373 | + '</div></form>'; |
|
| 2375 | 2374 | } |
| 2376 | 2375 | |
| 2377 | 2376 | /** |
@@ -2390,22 +2389,22 @@ discard block |
||
| 2390 | 2389 | * URL |
| 2391 | 2390 | */ |
| 2392 | 2391 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 2393 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2394 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2395 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2396 | - $url = (_DIR_RACINE and !$public) |
|
| 2397 | - ? generer_url_ecrire(_request('exec')) |
|
| 2398 | - : generer_url_public('', '', false, false); |
|
| 2399 | - $url = parametre_url($url, 'action', $script); |
|
| 2400 | - if ($args) { |
|
| 2401 | - $url .= quote_amp('&' . $args); |
|
| 2402 | - } |
|
| 2392 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2393 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2394 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2395 | + $url = (_DIR_RACINE and !$public) |
|
| 2396 | + ? generer_url_ecrire(_request('exec')) |
|
| 2397 | + : generer_url_public('', '', false, false); |
|
| 2398 | + $url = parametre_url($url, 'action', $script); |
|
| 2399 | + if ($args) { |
|
| 2400 | + $url .= quote_amp('&' . $args); |
|
| 2401 | + } |
|
| 2403 | 2402 | |
| 2404 | - if ($no_entities) { |
|
| 2405 | - $url = str_replace('&', '&', $url); |
|
| 2406 | - } |
|
| 2403 | + if ($no_entities) { |
|
| 2404 | + $url = str_replace('&', '&', $url); |
|
| 2405 | + } |
|
| 2407 | 2406 | |
| 2408 | - return $url; |
|
| 2407 | + return $url; |
|
| 2409 | 2408 | } |
| 2410 | 2409 | |
| 2411 | 2410 | |
@@ -2424,23 +2423,23 @@ discard block |
||
| 2424 | 2423 | * URL |
| 2425 | 2424 | */ |
| 2426 | 2425 | function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 2427 | - if (is_null($public)) { |
|
| 2428 | - $public = (_DIR_RACINE ? false : ''); |
|
| 2429 | - } |
|
| 2430 | - if (substr($script, -4) !== '.api') { |
|
| 2431 | - $script .= '.api'; |
|
| 2432 | - } |
|
| 2433 | - $url = |
|
| 2434 | - (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2435 | - . $script . '/' |
|
| 2436 | - . ($path ? trim($path, '/') : '') |
|
| 2437 | - . ($args ? "?" . quote_amp($args) : ''); |
|
| 2426 | + if (is_null($public)) { |
|
| 2427 | + $public = (_DIR_RACINE ? false : ''); |
|
| 2428 | + } |
|
| 2429 | + if (substr($script, -4) !== '.api') { |
|
| 2430 | + $script .= '.api'; |
|
| 2431 | + } |
|
| 2432 | + $url = |
|
| 2433 | + (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2434 | + . $script . '/' |
|
| 2435 | + . ($path ? trim($path, '/') : '') |
|
| 2436 | + . ($args ? "?" . quote_amp($args) : ''); |
|
| 2438 | 2437 | |
| 2439 | - if ($no_entities) { |
|
| 2440 | - $url = str_replace('&', '&', $url); |
|
| 2441 | - } |
|
| 2438 | + if ($no_entities) { |
|
| 2439 | + $url = str_replace('&', '&', $url); |
|
| 2440 | + } |
|
| 2442 | 2441 | |
| 2443 | - return $url; |
|
| 2442 | + return $url; |
|
| 2444 | 2443 | } |
| 2445 | 2444 | |
| 2446 | 2445 | |
@@ -2453,8 +2452,8 @@ discard block |
||
| 2453 | 2452 | * @param string $ta Répertoire temporaire accessible |
| 2454 | 2453 | */ |
| 2455 | 2454 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2456 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2457 | - spip_initialisation_suite(); |
|
| 2455 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2456 | + spip_initialisation_suite(); |
|
| 2458 | 2457 | } |
| 2459 | 2458 | |
| 2460 | 2459 | /** |
@@ -2474,322 +2473,322 @@ discard block |
||
| 2474 | 2473 | * @param string $ta Répertoire temporaire accessible |
| 2475 | 2474 | */ |
| 2476 | 2475 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2477 | - static $too_late = 0; |
|
| 2478 | - if ($too_late++) { |
|
| 2479 | - return; |
|
| 2480 | - } |
|
| 2481 | - |
|
| 2482 | - // Declaration des repertoires |
|
| 2483 | - |
|
| 2484 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2485 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2486 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2487 | - } |
|
| 2488 | - |
|
| 2489 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2490 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2491 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2492 | - } |
|
| 2493 | - |
|
| 2494 | - // le nom du repertoire des librairies |
|
| 2495 | - if (!defined('_DIR_LIB')) { |
|
| 2496 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2497 | - } |
|
| 2498 | - |
|
| 2499 | - if (!defined('_DIR_IMG')) { |
|
| 2500 | - define('_DIR_IMG', $pa); |
|
| 2501 | - } |
|
| 2502 | - if (!defined('_DIR_LOGOS')) { |
|
| 2503 | - define('_DIR_LOGOS', $pa); |
|
| 2504 | - } |
|
| 2505 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2506 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2507 | - } |
|
| 2508 | - |
|
| 2509 | - if (!defined('_DIR_DUMP')) { |
|
| 2510 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2511 | - } |
|
| 2512 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2513 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2514 | - } |
|
| 2515 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2516 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2517 | - } |
|
| 2518 | - if (!defined('_DIR_CACHE')) { |
|
| 2519 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2520 | - } |
|
| 2521 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2522 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2523 | - } |
|
| 2524 | - if (!defined('_DIR_SKELS')) { |
|
| 2525 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2526 | - } |
|
| 2527 | - if (!defined('_DIR_AIDE')) { |
|
| 2528 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2529 | - } |
|
| 2530 | - if (!defined('_DIR_TMP')) { |
|
| 2531 | - define('_DIR_TMP', $ti); |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - if (!defined('_DIR_VAR')) { |
|
| 2535 | - define('_DIR_VAR', $ta); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - if (!defined('_DIR_ETC')) { |
|
| 2539 | - define('_DIR_ETC', $pi); |
|
| 2540 | - } |
|
| 2541 | - if (!defined('_DIR_CONNECT')) { |
|
| 2542 | - define('_DIR_CONNECT', $pi); |
|
| 2543 | - } |
|
| 2544 | - if (!defined('_DIR_CHMOD')) { |
|
| 2545 | - define('_DIR_CHMOD', $pi); |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 2549 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2550 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2551 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - // Declaration des fichiers |
|
| 2555 | - |
|
| 2556 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2557 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2558 | - } |
|
| 2559 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2560 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2561 | - } |
|
| 2562 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2563 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2564 | - } |
|
| 2565 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2566 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2567 | - } |
|
| 2568 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2569 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2573 | - if (!defined('_FILE_META')) { |
|
| 2574 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2575 | - } |
|
| 2576 | - if (!defined('_DIR_LOG')) { |
|
| 2577 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2578 | - } |
|
| 2579 | - if (!defined('_FILE_LOG')) { |
|
| 2580 | - define('_FILE_LOG', 'spip'); |
|
| 2581 | - } |
|
| 2582 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2583 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - // Le fichier de connexion a la base de donnees |
|
| 2587 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2588 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2589 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2590 | - } |
|
| 2591 | - if (!defined('_FILE_CONNECT')) { |
|
| 2592 | - define( |
|
| 2593 | - '_FILE_CONNECT', |
|
| 2594 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2595 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2596 | - : false)) |
|
| 2597 | - ); |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - // Le fichier de reglages des droits |
|
| 2601 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2602 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2603 | - } |
|
| 2604 | - if (!defined('_FILE_CHMOD')) { |
|
| 2605 | - define( |
|
| 2606 | - '_FILE_CHMOD', |
|
| 2607 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2608 | - : false) |
|
| 2609 | - ); |
|
| 2610 | - } |
|
| 2611 | - |
|
| 2612 | - if (!defined('_FILE_LDAP')) { |
|
| 2613 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2614 | - } |
|
| 2615 | - |
|
| 2616 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2617 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2618 | - } |
|
| 2619 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2620 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2621 | - } |
|
| 2622 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2623 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2624 | - } |
|
| 2625 | - |
|
| 2626 | - // Definition des droits d'acces en ecriture |
|
| 2627 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2628 | - include_once _FILE_CHMOD; |
|
| 2629 | - } |
|
| 2630 | - |
|
| 2631 | - // Se mefier des fichiers mal remplis! |
|
| 2632 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2633 | - define('_SPIP_CHMOD', 0777); |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2637 | - /** Le charset par défaut lors de l'installation */ |
|
| 2638 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2639 | - } |
|
| 2640 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2641 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2642 | - } |
|
| 2643 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2644 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2645 | - } |
|
| 2646 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2647 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2648 | - } |
|
| 2649 | - |
|
| 2650 | - // La taille des Log |
|
| 2651 | - if (!defined('_MAX_LOG')) { |
|
| 2652 | - define('_MAX_LOG', 100); |
|
| 2653 | - } |
|
| 2654 | - |
|
| 2655 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2656 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2657 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2658 | - if (!defined('_OS_SERVEUR')) { |
|
| 2659 | - define('_OS_SERVEUR', 'windows'); |
|
| 2660 | - } |
|
| 2661 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2662 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2663 | - } // utiliser le flock php |
|
| 2664 | - } else { |
|
| 2665 | - if (!defined('_OS_SERVEUR')) { |
|
| 2666 | - define('_OS_SERVEUR', ''); |
|
| 2667 | - } |
|
| 2668 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2669 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2670 | - } // utiliser le flock php |
|
| 2671 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2672 | - } |
|
| 2673 | - |
|
| 2674 | - // Langue par defaut |
|
| 2675 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2676 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - // |
|
| 2680 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2681 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2682 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2683 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2684 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2685 | - |
|
| 2686 | - // charger tout de suite le path et son cache |
|
| 2687 | - load_path_cache(); |
|
| 2688 | - |
|
| 2689 | - // *********** traiter les variables ************ |
|
| 2690 | - |
|
| 2691 | - // |
|
| 2692 | - // Securite |
|
| 2693 | - // |
|
| 2694 | - |
|
| 2695 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2696 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2697 | - die(); |
|
| 2698 | - } |
|
| 2699 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2700 | - spip_desinfecte($_GET); |
|
| 2701 | - spip_desinfecte($_POST); |
|
| 2702 | - spip_desinfecte($_COOKIE); |
|
| 2703 | - spip_desinfecte($_REQUEST); |
|
| 2704 | - |
|
| 2705 | - // appliquer le cookie_prefix |
|
| 2706 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2707 | - include_spip('inc/cookie'); |
|
| 2708 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2709 | - } |
|
| 2710 | - |
|
| 2711 | - // |
|
| 2712 | - // Capacites php (en fonction de la version) |
|
| 2713 | - // |
|
| 2714 | - $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2715 | - && function_exists('ini_get') |
|
| 2716 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2717 | - $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2718 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2719 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2720 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2721 | - |
|
| 2722 | - |
|
| 2723 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2724 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2725 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2726 | - } else { |
|
| 2727 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2728 | - if ( |
|
| 2729 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2730 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2731 | - ) { |
|
| 2732 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2733 | - } |
|
| 2734 | - } |
|
| 2735 | - |
|
| 2736 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2737 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2738 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2739 | - } |
|
| 2740 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2741 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2742 | - } |
|
| 2743 | - |
|
| 2744 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2745 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2746 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2747 | - $inc_meta(); |
|
| 2748 | - |
|
| 2749 | - // nombre de repertoires depuis la racine |
|
| 2750 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2751 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2752 | - // le calcul est faux) |
|
| 2753 | - if (!_DIR_RESTREINT) { |
|
| 2754 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2755 | - } else { |
|
| 2756 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2757 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2758 | - if ( |
|
| 2759 | - !$uri_ref |
|
| 2760 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2761 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2762 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2763 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2764 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2765 | - ) { |
|
| 2766 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2767 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2768 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2769 | - } else { |
|
| 2770 | - $uri_ref = ''; |
|
| 2771 | - } |
|
| 2772 | - } |
|
| 2773 | - if (!$uri or !$uri_ref) { |
|
| 2774 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2775 | - } else { |
|
| 2776 | - $GLOBALS['profondeur_url'] = max( |
|
| 2777 | - 0, |
|
| 2778 | - substr_count($uri[0], '/') |
|
| 2779 | - - substr_count($uri_ref, '/') |
|
| 2780 | - ); |
|
| 2781 | - } |
|
| 2782 | - } |
|
| 2783 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2784 | - if (_FILE_CONNECT) { |
|
| 2785 | - if ( |
|
| 2786 | - verifier_visiteur() == '0minirezo' |
|
| 2787 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2788 | - and !isset($_COOKIE['spip_admin']) |
|
| 2789 | - ) { |
|
| 2790 | - clear_path_cache(); |
|
| 2791 | - } |
|
| 2792 | - } |
|
| 2476 | + static $too_late = 0; |
|
| 2477 | + if ($too_late++) { |
|
| 2478 | + return; |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + // Declaration des repertoires |
|
| 2482 | + |
|
| 2483 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2484 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2485 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2486 | + } |
|
| 2487 | + |
|
| 2488 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2489 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2490 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2491 | + } |
|
| 2492 | + |
|
| 2493 | + // le nom du repertoire des librairies |
|
| 2494 | + if (!defined('_DIR_LIB')) { |
|
| 2495 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2496 | + } |
|
| 2497 | + |
|
| 2498 | + if (!defined('_DIR_IMG')) { |
|
| 2499 | + define('_DIR_IMG', $pa); |
|
| 2500 | + } |
|
| 2501 | + if (!defined('_DIR_LOGOS')) { |
|
| 2502 | + define('_DIR_LOGOS', $pa); |
|
| 2503 | + } |
|
| 2504 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2505 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2506 | + } |
|
| 2507 | + |
|
| 2508 | + if (!defined('_DIR_DUMP')) { |
|
| 2509 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2510 | + } |
|
| 2511 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2512 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2513 | + } |
|
| 2514 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2515 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2516 | + } |
|
| 2517 | + if (!defined('_DIR_CACHE')) { |
|
| 2518 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2519 | + } |
|
| 2520 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2521 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2522 | + } |
|
| 2523 | + if (!defined('_DIR_SKELS')) { |
|
| 2524 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2525 | + } |
|
| 2526 | + if (!defined('_DIR_AIDE')) { |
|
| 2527 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2528 | + } |
|
| 2529 | + if (!defined('_DIR_TMP')) { |
|
| 2530 | + define('_DIR_TMP', $ti); |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + if (!defined('_DIR_VAR')) { |
|
| 2534 | + define('_DIR_VAR', $ta); |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + if (!defined('_DIR_ETC')) { |
|
| 2538 | + define('_DIR_ETC', $pi); |
|
| 2539 | + } |
|
| 2540 | + if (!defined('_DIR_CONNECT')) { |
|
| 2541 | + define('_DIR_CONNECT', $pi); |
|
| 2542 | + } |
|
| 2543 | + if (!defined('_DIR_CHMOD')) { |
|
| 2544 | + define('_DIR_CHMOD', $pi); |
|
| 2545 | + } |
|
| 2546 | + |
|
| 2547 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2548 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2549 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2550 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + // Declaration des fichiers |
|
| 2554 | + |
|
| 2555 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2556 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2557 | + } |
|
| 2558 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2559 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2560 | + } |
|
| 2561 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2562 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2563 | + } |
|
| 2564 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2565 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2566 | + } |
|
| 2567 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2568 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2569 | + } |
|
| 2570 | + |
|
| 2571 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2572 | + if (!defined('_FILE_META')) { |
|
| 2573 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2574 | + } |
|
| 2575 | + if (!defined('_DIR_LOG')) { |
|
| 2576 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2577 | + } |
|
| 2578 | + if (!defined('_FILE_LOG')) { |
|
| 2579 | + define('_FILE_LOG', 'spip'); |
|
| 2580 | + } |
|
| 2581 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2582 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + // Le fichier de connexion a la base de donnees |
|
| 2586 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2587 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2588 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2589 | + } |
|
| 2590 | + if (!defined('_FILE_CONNECT')) { |
|
| 2591 | + define( |
|
| 2592 | + '_FILE_CONNECT', |
|
| 2593 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2594 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2595 | + : false)) |
|
| 2596 | + ); |
|
| 2597 | + } |
|
| 2598 | + |
|
| 2599 | + // Le fichier de reglages des droits |
|
| 2600 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2601 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2602 | + } |
|
| 2603 | + if (!defined('_FILE_CHMOD')) { |
|
| 2604 | + define( |
|
| 2605 | + '_FILE_CHMOD', |
|
| 2606 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2607 | + : false) |
|
| 2608 | + ); |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + if (!defined('_FILE_LDAP')) { |
|
| 2612 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2616 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2617 | + } |
|
| 2618 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2619 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2620 | + } |
|
| 2621 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2622 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + // Definition des droits d'acces en ecriture |
|
| 2626 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2627 | + include_once _FILE_CHMOD; |
|
| 2628 | + } |
|
| 2629 | + |
|
| 2630 | + // Se mefier des fichiers mal remplis! |
|
| 2631 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2632 | + define('_SPIP_CHMOD', 0777); |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2636 | + /** Le charset par défaut lors de l'installation */ |
|
| 2637 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2638 | + } |
|
| 2639 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2640 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2641 | + } |
|
| 2642 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2643 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2644 | + } |
|
| 2645 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2646 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + // La taille des Log |
|
| 2650 | + if (!defined('_MAX_LOG')) { |
|
| 2651 | + define('_MAX_LOG', 100); |
|
| 2652 | + } |
|
| 2653 | + |
|
| 2654 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2655 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2656 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2657 | + if (!defined('_OS_SERVEUR')) { |
|
| 2658 | + define('_OS_SERVEUR', 'windows'); |
|
| 2659 | + } |
|
| 2660 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2661 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2662 | + } // utiliser le flock php |
|
| 2663 | + } else { |
|
| 2664 | + if (!defined('_OS_SERVEUR')) { |
|
| 2665 | + define('_OS_SERVEUR', ''); |
|
| 2666 | + } |
|
| 2667 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2668 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2669 | + } // utiliser le flock php |
|
| 2670 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2671 | + } |
|
| 2672 | + |
|
| 2673 | + // Langue par defaut |
|
| 2674 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2675 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2676 | + } |
|
| 2677 | + |
|
| 2678 | + // |
|
| 2679 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2680 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2681 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2682 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2683 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2684 | + |
|
| 2685 | + // charger tout de suite le path et son cache |
|
| 2686 | + load_path_cache(); |
|
| 2687 | + |
|
| 2688 | + // *********** traiter les variables ************ |
|
| 2689 | + |
|
| 2690 | + // |
|
| 2691 | + // Securite |
|
| 2692 | + // |
|
| 2693 | + |
|
| 2694 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2695 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2696 | + die(); |
|
| 2697 | + } |
|
| 2698 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2699 | + spip_desinfecte($_GET); |
|
| 2700 | + spip_desinfecte($_POST); |
|
| 2701 | + spip_desinfecte($_COOKIE); |
|
| 2702 | + spip_desinfecte($_REQUEST); |
|
| 2703 | + |
|
| 2704 | + // appliquer le cookie_prefix |
|
| 2705 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2706 | + include_spip('inc/cookie'); |
|
| 2707 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2708 | + } |
|
| 2709 | + |
|
| 2710 | + // |
|
| 2711 | + // Capacites php (en fonction de la version) |
|
| 2712 | + // |
|
| 2713 | + $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2714 | + && function_exists('ini_get') |
|
| 2715 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2716 | + $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2717 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2718 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2719 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2720 | + |
|
| 2721 | + |
|
| 2722 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2723 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2724 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2725 | + } else { |
|
| 2726 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2727 | + if ( |
|
| 2728 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2729 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2730 | + ) { |
|
| 2731 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2732 | + } |
|
| 2733 | + } |
|
| 2734 | + |
|
| 2735 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2736 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2737 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2738 | + } |
|
| 2739 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2740 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2741 | + } |
|
| 2742 | + |
|
| 2743 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2744 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2745 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2746 | + $inc_meta(); |
|
| 2747 | + |
|
| 2748 | + // nombre de repertoires depuis la racine |
|
| 2749 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2750 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2751 | + // le calcul est faux) |
|
| 2752 | + if (!_DIR_RESTREINT) { |
|
| 2753 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2754 | + } else { |
|
| 2755 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2756 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2757 | + if ( |
|
| 2758 | + !$uri_ref |
|
| 2759 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2760 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2761 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2762 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2763 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2764 | + ) { |
|
| 2765 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2766 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2767 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2768 | + } else { |
|
| 2769 | + $uri_ref = ''; |
|
| 2770 | + } |
|
| 2771 | + } |
|
| 2772 | + if (!$uri or !$uri_ref) { |
|
| 2773 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2774 | + } else { |
|
| 2775 | + $GLOBALS['profondeur_url'] = max( |
|
| 2776 | + 0, |
|
| 2777 | + substr_count($uri[0], '/') |
|
| 2778 | + - substr_count($uri_ref, '/') |
|
| 2779 | + ); |
|
| 2780 | + } |
|
| 2781 | + } |
|
| 2782 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2783 | + if (_FILE_CONNECT) { |
|
| 2784 | + if ( |
|
| 2785 | + verifier_visiteur() == '0minirezo' |
|
| 2786 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2787 | + and !isset($_COOKIE['spip_admin']) |
|
| 2788 | + ) { |
|
| 2789 | + clear_path_cache(); |
|
| 2790 | + } |
|
| 2791 | + } |
|
| 2793 | 2792 | } |
| 2794 | 2793 | |
| 2795 | 2794 | /** |
@@ -2798,190 +2797,190 @@ discard block |
||
| 2798 | 2797 | * |
| 2799 | 2798 | */ |
| 2800 | 2799 | function spip_initialisation_suite() { |
| 2801 | - static $too_late = 0; |
|
| 2802 | - if ($too_late++) { |
|
| 2803 | - return; |
|
| 2804 | - } |
|
| 2805 | - |
|
| 2806 | - // taille mini des login |
|
| 2807 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2808 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2809 | - } |
|
| 2810 | - |
|
| 2811 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2812 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2813 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2814 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2815 | - |
|
| 2816 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2817 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2818 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2819 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2820 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2821 | - |
|
| 2822 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2823 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2824 | - } |
|
| 2825 | - |
|
| 2826 | - // largeur maximale des images dans l'administration |
|
| 2827 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2828 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2829 | - } |
|
| 2830 | - |
|
| 2831 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2832 | - if (!defined('_IMG_QUALITE')) { |
|
| 2833 | - define('_IMG_QUALITE', 85); |
|
| 2834 | - } # valeur par defaut |
|
| 2835 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2836 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2837 | - } # surcharge pour la lib GD |
|
| 2838 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2839 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2840 | - } # surcharge pour imagick en ligne de commande |
|
| 2841 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2842 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2843 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2844 | - } # surcharge pour imagick en PHP |
|
| 2845 | - |
|
| 2846 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2847 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2848 | - } // poids en octet |
|
| 2849 | - |
|
| 2850 | - // qq chaines standard |
|
| 2851 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2852 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2853 | - } |
|
| 2854 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2855 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2856 | - } |
|
| 2857 | - if (!defined('_SPIP_DUMP')) { |
|
| 2858 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2859 | - } |
|
| 2860 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2861 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2862 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2863 | - } |
|
| 2864 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2865 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2866 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2867 | - } |
|
| 2868 | - |
|
| 2869 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2870 | - /** |
|
| 2871 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2872 | - * @var int Nombre de caractères */ |
|
| 2873 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2874 | - } |
|
| 2875 | - |
|
| 2876 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2877 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2878 | - } |
|
| 2879 | - |
|
| 2880 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2881 | - /** Définit le doctype de l’espace privé */ |
|
| 2882 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2883 | - } |
|
| 2884 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2885 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2886 | - define( |
|
| 2887 | - '_DOCTYPE_AIDE', |
|
| 2888 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2889 | - ); |
|
| 2890 | - } |
|
| 2891 | - |
|
| 2892 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2893 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2894 | - * le script de l'espace public, alias index.php */ |
|
| 2895 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2896 | - } |
|
| 2897 | - if (!defined('_SPIP_PAGE')) { |
|
| 2898 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2899 | - define('_SPIP_PAGE', 'page'); |
|
| 2900 | - } |
|
| 2901 | - |
|
| 2902 | - // le script de l'espace prive |
|
| 2903 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2904 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2905 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2906 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2907 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2908 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2909 | - } else { |
|
| 2910 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2911 | - } |
|
| 2912 | - } |
|
| 2913 | - |
|
| 2914 | - |
|
| 2915 | - if (!defined('_SPIP_AJAX')) { |
|
| 2916 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2917 | - ? 1 |
|
| 2918 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2919 | - } |
|
| 2920 | - |
|
| 2921 | - // La requete est-elle en ajax ? |
|
| 2922 | - if (!defined('_AJAX')) { |
|
| 2923 | - define( |
|
| 2924 | - '_AJAX', |
|
| 2925 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2926 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2927 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2928 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2929 | - ) |
|
| 2930 | - and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2931 | - ); |
|
| 2932 | - } |
|
| 2933 | - |
|
| 2934 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2935 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2936 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2937 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2938 | - define( |
|
| 2939 | - '_IMG_GD_MAX_PIXELS', |
|
| 2940 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2941 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2942 | - : 0 |
|
| 2943 | - ); |
|
| 2944 | - } |
|
| 2945 | - |
|
| 2946 | - if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2947 | - define('_MEMORY_LIMIT_MIN', 16); |
|
| 2948 | - } // en Mo |
|
| 2949 | - // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2950 | - // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2951 | - // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2952 | - if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2953 | - if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2954 | - $unit = strtolower(substr($memory, -1)); |
|
| 2955 | - $memory = substr($memory, 0, -1); |
|
| 2956 | - switch ($unit) { |
|
| 2957 | - // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2958 | - case 'g': |
|
| 2959 | - $memory *= 1024; |
|
| 2960 | - case 'm': |
|
| 2961 | - $memory *= 1024; |
|
| 2962 | - case 'k': |
|
| 2963 | - $memory *= 1024; |
|
| 2964 | - } |
|
| 2965 | - if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2966 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2967 | - if (trim(ini_get('memory_limit')) != $m) { |
|
| 2968 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2969 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2970 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2971 | - } |
|
| 2972 | - } |
|
| 2973 | - } else { |
|
| 2974 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2975 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2976 | - } |
|
| 2977 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2978 | - } |
|
| 2979 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2980 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2981 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2982 | - } |
|
| 2983 | - |
|
| 2984 | - init_var_mode(); |
|
| 2800 | + static $too_late = 0; |
|
| 2801 | + if ($too_late++) { |
|
| 2802 | + return; |
|
| 2803 | + } |
|
| 2804 | + |
|
| 2805 | + // taille mini des login |
|
| 2806 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2807 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2808 | + } |
|
| 2809 | + |
|
| 2810 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2811 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2812 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2813 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2814 | + |
|
| 2815 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2816 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2817 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2818 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2819 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2820 | + |
|
| 2821 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2822 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2823 | + } |
|
| 2824 | + |
|
| 2825 | + // largeur maximale des images dans l'administration |
|
| 2826 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2827 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2828 | + } |
|
| 2829 | + |
|
| 2830 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2831 | + if (!defined('_IMG_QUALITE')) { |
|
| 2832 | + define('_IMG_QUALITE', 85); |
|
| 2833 | + } # valeur par defaut |
|
| 2834 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2835 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2836 | + } # surcharge pour la lib GD |
|
| 2837 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2838 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2839 | + } # surcharge pour imagick en ligne de commande |
|
| 2840 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2841 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2842 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2843 | + } # surcharge pour imagick en PHP |
|
| 2844 | + |
|
| 2845 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2846 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2847 | + } // poids en octet |
|
| 2848 | + |
|
| 2849 | + // qq chaines standard |
|
| 2850 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2851 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2852 | + } |
|
| 2853 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2854 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2855 | + } |
|
| 2856 | + if (!defined('_SPIP_DUMP')) { |
|
| 2857 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2858 | + } |
|
| 2859 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2860 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2861 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2862 | + } |
|
| 2863 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2864 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2865 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2866 | + } |
|
| 2867 | + |
|
| 2868 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2869 | + /** |
|
| 2870 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2871 | + * @var int Nombre de caractères */ |
|
| 2872 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2876 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2877 | + } |
|
| 2878 | + |
|
| 2879 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2880 | + /** Définit le doctype de l’espace privé */ |
|
| 2881 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2882 | + } |
|
| 2883 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2884 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2885 | + define( |
|
| 2886 | + '_DOCTYPE_AIDE', |
|
| 2887 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2888 | + ); |
|
| 2889 | + } |
|
| 2890 | + |
|
| 2891 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2892 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2893 | + * le script de l'espace public, alias index.php */ |
|
| 2894 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2895 | + } |
|
| 2896 | + if (!defined('_SPIP_PAGE')) { |
|
| 2897 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2898 | + define('_SPIP_PAGE', 'page'); |
|
| 2899 | + } |
|
| 2900 | + |
|
| 2901 | + // le script de l'espace prive |
|
| 2902 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2903 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2904 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2905 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2906 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2907 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2908 | + } else { |
|
| 2909 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2910 | + } |
|
| 2911 | + } |
|
| 2912 | + |
|
| 2913 | + |
|
| 2914 | + if (!defined('_SPIP_AJAX')) { |
|
| 2915 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2916 | + ? 1 |
|
| 2917 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2918 | + } |
|
| 2919 | + |
|
| 2920 | + // La requete est-elle en ajax ? |
|
| 2921 | + if (!defined('_AJAX')) { |
|
| 2922 | + define( |
|
| 2923 | + '_AJAX', |
|
| 2924 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2925 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2926 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2927 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2928 | + ) |
|
| 2929 | + and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2930 | + ); |
|
| 2931 | + } |
|
| 2932 | + |
|
| 2933 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2934 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2935 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2936 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2937 | + define( |
|
| 2938 | + '_IMG_GD_MAX_PIXELS', |
|
| 2939 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2940 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2941 | + : 0 |
|
| 2942 | + ); |
|
| 2943 | + } |
|
| 2944 | + |
|
| 2945 | + if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2946 | + define('_MEMORY_LIMIT_MIN', 16); |
|
| 2947 | + } // en Mo |
|
| 2948 | + // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2949 | + // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2950 | + // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2951 | + if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2952 | + if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2953 | + $unit = strtolower(substr($memory, -1)); |
|
| 2954 | + $memory = substr($memory, 0, -1); |
|
| 2955 | + switch ($unit) { |
|
| 2956 | + // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2957 | + case 'g': |
|
| 2958 | + $memory *= 1024; |
|
| 2959 | + case 'm': |
|
| 2960 | + $memory *= 1024; |
|
| 2961 | + case 'k': |
|
| 2962 | + $memory *= 1024; |
|
| 2963 | + } |
|
| 2964 | + if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2965 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2966 | + if (trim(ini_get('memory_limit')) != $m) { |
|
| 2967 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2968 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2969 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2970 | + } |
|
| 2971 | + } |
|
| 2972 | + } else { |
|
| 2973 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2974 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2975 | + } |
|
| 2976 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2977 | + } |
|
| 2978 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2979 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2980 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2981 | + } |
|
| 2982 | + |
|
| 2983 | + init_var_mode(); |
|
| 2985 | 2984 | } |
| 2986 | 2985 | |
| 2987 | 2986 | /** |
@@ -3015,219 +3014,219 @@ discard block |
||
| 3015 | 3014 | * ` var_mode` (calcul ou recalcul). |
| 3016 | 3015 | */ |
| 3017 | 3016 | function init_var_mode() { |
| 3018 | - static $done = false; |
|
| 3019 | - if (!$done) { |
|
| 3020 | - if (isset($_GET['var_mode'])) { |
|
| 3021 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 3022 | - // tout le monde peut calcul/recalcul |
|
| 3023 | - if (!defined('_VAR_MODE')) { |
|
| 3024 | - if (in_array('recalcul', $var_mode)) { |
|
| 3025 | - define('_VAR_MODE', 'recalcul'); |
|
| 3026 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 3027 | - define('_VAR_MODE', 'calcul'); |
|
| 3028 | - } |
|
| 3029 | - } |
|
| 3030 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3031 | - if ($var_mode) { |
|
| 3032 | - include_spip('inc/autoriser'); |
|
| 3033 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3034 | - if ( |
|
| 3035 | - autoriser( |
|
| 3036 | - ($_GET['var_mode'] == 'preview') |
|
| 3037 | - ? 'previsualiser' |
|
| 3038 | - : 'debug' |
|
| 3039 | - ) |
|
| 3040 | - ) { |
|
| 3041 | - if (in_array('traduction', $var_mode)) { |
|
| 3042 | - // forcer le calcul pour passer dans traduire |
|
| 3043 | - if (!defined('_VAR_MODE')) { |
|
| 3044 | - define('_VAR_MODE', 'calcul'); |
|
| 3045 | - } |
|
| 3046 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3047 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3048 | - define('_VAR_NOCACHE', true); |
|
| 3049 | - } |
|
| 3050 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3051 | - } |
|
| 3052 | - if (in_array('preview', $var_mode)) { |
|
| 3053 | - // basculer sur les criteres de preview dans les boucles |
|
| 3054 | - if (!defined('_VAR_PREVIEW')) { |
|
| 3055 | - define('_VAR_PREVIEW', true); |
|
| 3056 | - } |
|
| 3057 | - // forcer le calcul |
|
| 3058 | - if (!defined('_VAR_MODE')) { |
|
| 3059 | - define('_VAR_MODE', 'calcul'); |
|
| 3060 | - } |
|
| 3061 | - // et ne pas enregistrer de cache |
|
| 3062 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3063 | - define('_VAR_NOCACHE', true); |
|
| 3064 | - } |
|
| 3065 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 3066 | - } |
|
| 3067 | - if (in_array('inclure', $var_mode)) { |
|
| 3068 | - // forcer le compilo et ignorer les caches existants |
|
| 3069 | - if (!defined('_VAR_MODE')) { |
|
| 3070 | - define('_VAR_MODE', 'calcul'); |
|
| 3071 | - } |
|
| 3072 | - if (!defined('_VAR_INCLURE')) { |
|
| 3073 | - define('_VAR_INCLURE', true); |
|
| 3074 | - } |
|
| 3075 | - // et ne pas enregistrer de cache |
|
| 3076 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3077 | - define('_VAR_NOCACHE', true); |
|
| 3078 | - } |
|
| 3079 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3080 | - } |
|
| 3081 | - if (in_array('urls', $var_mode)) { |
|
| 3082 | - // forcer le compilo et ignorer les caches existants |
|
| 3083 | - if (!defined('_VAR_MODE')) { |
|
| 3084 | - define('_VAR_MODE', 'calcul'); |
|
| 3085 | - } |
|
| 3086 | - if (!defined('_VAR_URLS')) { |
|
| 3087 | - define('_VAR_URLS', true); |
|
| 3088 | - } |
|
| 3089 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 3090 | - } |
|
| 3091 | - if (in_array('images', $var_mode)) { |
|
| 3092 | - // forcer le compilo et ignorer les caches existants |
|
| 3093 | - if (!defined('_VAR_MODE')) { |
|
| 3094 | - define('_VAR_MODE', 'calcul'); |
|
| 3095 | - } |
|
| 3096 | - // indiquer qu'on doit recalculer les images |
|
| 3097 | - if (!defined('_VAR_IMAGES')) { |
|
| 3098 | - define('_VAR_IMAGES', true); |
|
| 3099 | - } |
|
| 3100 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 3101 | - } |
|
| 3102 | - if (in_array('debug', $var_mode)) { |
|
| 3103 | - if (!defined('_VAR_MODE')) { |
|
| 3104 | - define('_VAR_MODE', 'debug'); |
|
| 3105 | - } |
|
| 3106 | - // et ne pas enregistrer de cache |
|
| 3107 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3108 | - define('_VAR_NOCACHE', true); |
|
| 3109 | - } |
|
| 3110 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 3111 | - } |
|
| 3112 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 3113 | - define('_VAR_MODE', reset($var_mode)); |
|
| 3114 | - } |
|
| 3115 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3116 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3117 | - . ' ' . _VAR_MODE); |
|
| 3118 | - } |
|
| 3119 | - } // pas autorise ? |
|
| 3120 | - else { |
|
| 3121 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3122 | - if ( |
|
| 3123 | - !$GLOBALS['visiteur_session'] |
|
| 3124 | - and !empty($_SERVER['HTTP_HOST']) |
|
| 3125 | - and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3126 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3127 | - ) { |
|
| 3128 | - $self = self('&', true); |
|
| 3129 | - if (strpos($self, 'page=login') === false) { |
|
| 3130 | - include_spip('inc/headers'); |
|
| 3131 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3132 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3133 | - } |
|
| 3134 | - } |
|
| 3135 | - // sinon tant pis |
|
| 3136 | - } |
|
| 3137 | - } |
|
| 3138 | - } |
|
| 3139 | - if (!defined('_VAR_MODE')) { |
|
| 3140 | - /** |
|
| 3141 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 3142 | - * @see init_var_mode() |
|
| 3143 | - */ |
|
| 3144 | - define('_VAR_MODE', false); |
|
| 3145 | - } |
|
| 3146 | - $done = true; |
|
| 3147 | - } |
|
| 3017 | + static $done = false; |
|
| 3018 | + if (!$done) { |
|
| 3019 | + if (isset($_GET['var_mode'])) { |
|
| 3020 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 3021 | + // tout le monde peut calcul/recalcul |
|
| 3022 | + if (!defined('_VAR_MODE')) { |
|
| 3023 | + if (in_array('recalcul', $var_mode)) { |
|
| 3024 | + define('_VAR_MODE', 'recalcul'); |
|
| 3025 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 3026 | + define('_VAR_MODE', 'calcul'); |
|
| 3027 | + } |
|
| 3028 | + } |
|
| 3029 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3030 | + if ($var_mode) { |
|
| 3031 | + include_spip('inc/autoriser'); |
|
| 3032 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3033 | + if ( |
|
| 3034 | + autoriser( |
|
| 3035 | + ($_GET['var_mode'] == 'preview') |
|
| 3036 | + ? 'previsualiser' |
|
| 3037 | + : 'debug' |
|
| 3038 | + ) |
|
| 3039 | + ) { |
|
| 3040 | + if (in_array('traduction', $var_mode)) { |
|
| 3041 | + // forcer le calcul pour passer dans traduire |
|
| 3042 | + if (!defined('_VAR_MODE')) { |
|
| 3043 | + define('_VAR_MODE', 'calcul'); |
|
| 3044 | + } |
|
| 3045 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3046 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3047 | + define('_VAR_NOCACHE', true); |
|
| 3048 | + } |
|
| 3049 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3050 | + } |
|
| 3051 | + if (in_array('preview', $var_mode)) { |
|
| 3052 | + // basculer sur les criteres de preview dans les boucles |
|
| 3053 | + if (!defined('_VAR_PREVIEW')) { |
|
| 3054 | + define('_VAR_PREVIEW', true); |
|
| 3055 | + } |
|
| 3056 | + // forcer le calcul |
|
| 3057 | + if (!defined('_VAR_MODE')) { |
|
| 3058 | + define('_VAR_MODE', 'calcul'); |
|
| 3059 | + } |
|
| 3060 | + // et ne pas enregistrer de cache |
|
| 3061 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3062 | + define('_VAR_NOCACHE', true); |
|
| 3063 | + } |
|
| 3064 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 3065 | + } |
|
| 3066 | + if (in_array('inclure', $var_mode)) { |
|
| 3067 | + // forcer le compilo et ignorer les caches existants |
|
| 3068 | + if (!defined('_VAR_MODE')) { |
|
| 3069 | + define('_VAR_MODE', 'calcul'); |
|
| 3070 | + } |
|
| 3071 | + if (!defined('_VAR_INCLURE')) { |
|
| 3072 | + define('_VAR_INCLURE', true); |
|
| 3073 | + } |
|
| 3074 | + // et ne pas enregistrer de cache |
|
| 3075 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3076 | + define('_VAR_NOCACHE', true); |
|
| 3077 | + } |
|
| 3078 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3079 | + } |
|
| 3080 | + if (in_array('urls', $var_mode)) { |
|
| 3081 | + // forcer le compilo et ignorer les caches existants |
|
| 3082 | + if (!defined('_VAR_MODE')) { |
|
| 3083 | + define('_VAR_MODE', 'calcul'); |
|
| 3084 | + } |
|
| 3085 | + if (!defined('_VAR_URLS')) { |
|
| 3086 | + define('_VAR_URLS', true); |
|
| 3087 | + } |
|
| 3088 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 3089 | + } |
|
| 3090 | + if (in_array('images', $var_mode)) { |
|
| 3091 | + // forcer le compilo et ignorer les caches existants |
|
| 3092 | + if (!defined('_VAR_MODE')) { |
|
| 3093 | + define('_VAR_MODE', 'calcul'); |
|
| 3094 | + } |
|
| 3095 | + // indiquer qu'on doit recalculer les images |
|
| 3096 | + if (!defined('_VAR_IMAGES')) { |
|
| 3097 | + define('_VAR_IMAGES', true); |
|
| 3098 | + } |
|
| 3099 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 3100 | + } |
|
| 3101 | + if (in_array('debug', $var_mode)) { |
|
| 3102 | + if (!defined('_VAR_MODE')) { |
|
| 3103 | + define('_VAR_MODE', 'debug'); |
|
| 3104 | + } |
|
| 3105 | + // et ne pas enregistrer de cache |
|
| 3106 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3107 | + define('_VAR_NOCACHE', true); |
|
| 3108 | + } |
|
| 3109 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 3110 | + } |
|
| 3111 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 3112 | + define('_VAR_MODE', reset($var_mode)); |
|
| 3113 | + } |
|
| 3114 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3115 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3116 | + . ' ' . _VAR_MODE); |
|
| 3117 | + } |
|
| 3118 | + } // pas autorise ? |
|
| 3119 | + else { |
|
| 3120 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3121 | + if ( |
|
| 3122 | + !$GLOBALS['visiteur_session'] |
|
| 3123 | + and !empty($_SERVER['HTTP_HOST']) |
|
| 3124 | + and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3125 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3126 | + ) { |
|
| 3127 | + $self = self('&', true); |
|
| 3128 | + if (strpos($self, 'page=login') === false) { |
|
| 3129 | + include_spip('inc/headers'); |
|
| 3130 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3131 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3132 | + } |
|
| 3133 | + } |
|
| 3134 | + // sinon tant pis |
|
| 3135 | + } |
|
| 3136 | + } |
|
| 3137 | + } |
|
| 3138 | + if (!defined('_VAR_MODE')) { |
|
| 3139 | + /** |
|
| 3140 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 3141 | + * @see init_var_mode() |
|
| 3142 | + */ |
|
| 3143 | + define('_VAR_MODE', false); |
|
| 3144 | + } |
|
| 3145 | + $done = true; |
|
| 3146 | + } |
|
| 3148 | 3147 | } |
| 3149 | 3148 | |
| 3150 | 3149 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
| 3151 | 3150 | // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper |
| 3152 | 3151 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 3153 | 3152 | function spip_desinfecte(&$t, $deep = true) { |
| 3154 | - foreach ($t as $key => $val) { |
|
| 3155 | - if (is_string($t[$key])) { |
|
| 3156 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3157 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3158 | - else { |
|
| 3159 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3160 | - spip_desinfecte($t[$key], $deep); |
|
| 3161 | - } |
|
| 3162 | - } |
|
| 3163 | - } |
|
| 3153 | + foreach ($t as $key => $val) { |
|
| 3154 | + if (is_string($t[$key])) { |
|
| 3155 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3156 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3157 | + else { |
|
| 3158 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3159 | + spip_desinfecte($t[$key], $deep); |
|
| 3160 | + } |
|
| 3161 | + } |
|
| 3162 | + } |
|
| 3164 | 3163 | } |
| 3165 | 3164 | |
| 3166 | 3165 | // retourne le statut du visiteur s'il s'annonce |
| 3167 | 3166 | |
| 3168 | 3167 | function verifier_visiteur() { |
| 3169 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 3170 | - // il faut forcer l'init si ce n'est fait |
|
| 3171 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3172 | - // certaines constantes |
|
| 3173 | - @spip_initialisation_core( |
|
| 3174 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3175 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3176 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3177 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3178 | - ); |
|
| 3179 | - |
|
| 3180 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3181 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3182 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3183 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3184 | - $variables_session = ['session_nom', 'session_email']; |
|
| 3185 | - foreach ($variables_session as $var) { |
|
| 3186 | - if (_request($var) !== null) { |
|
| 3187 | - $init = true; |
|
| 3188 | - break; |
|
| 3189 | - } |
|
| 3190 | - } |
|
| 3191 | - if (isset($init)) { |
|
| 3192 | - #@spip_initialisation_suite(); |
|
| 3193 | - $session = charger_fonction('session', 'inc'); |
|
| 3194 | - $session(); |
|
| 3195 | - include_spip('inc/texte'); |
|
| 3196 | - foreach ($variables_session as $var) { |
|
| 3197 | - if (($a = _request($var)) !== null) { |
|
| 3198 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3199 | - } |
|
| 3200 | - } |
|
| 3201 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3202 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3203 | - } |
|
| 3204 | - $session($GLOBALS['visiteur_session']); |
|
| 3205 | - |
|
| 3206 | - return 0; |
|
| 3207 | - } |
|
| 3208 | - |
|
| 3209 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3210 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3211 | - $session = charger_fonction('session', 'inc'); |
|
| 3212 | - if ($session()) { |
|
| 3213 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3214 | - } |
|
| 3215 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3216 | - include_spip('inc/auth'); |
|
| 3217 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3218 | - } |
|
| 3219 | - if ($h) { |
|
| 3220 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3221 | - |
|
| 3222 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3223 | - } |
|
| 3224 | - } |
|
| 3225 | - |
|
| 3226 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3227 | - include_spip('inc/lang'); |
|
| 3228 | - utiliser_langue_visiteur(); |
|
| 3229 | - |
|
| 3230 | - return false; |
|
| 3168 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 3169 | + // il faut forcer l'init si ce n'est fait |
|
| 3170 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3171 | + // certaines constantes |
|
| 3172 | + @spip_initialisation_core( |
|
| 3173 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3174 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3175 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3176 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3177 | + ); |
|
| 3178 | + |
|
| 3179 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3180 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3181 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3182 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3183 | + $variables_session = ['session_nom', 'session_email']; |
|
| 3184 | + foreach ($variables_session as $var) { |
|
| 3185 | + if (_request($var) !== null) { |
|
| 3186 | + $init = true; |
|
| 3187 | + break; |
|
| 3188 | + } |
|
| 3189 | + } |
|
| 3190 | + if (isset($init)) { |
|
| 3191 | + #@spip_initialisation_suite(); |
|
| 3192 | + $session = charger_fonction('session', 'inc'); |
|
| 3193 | + $session(); |
|
| 3194 | + include_spip('inc/texte'); |
|
| 3195 | + foreach ($variables_session as $var) { |
|
| 3196 | + if (($a = _request($var)) !== null) { |
|
| 3197 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3198 | + } |
|
| 3199 | + } |
|
| 3200 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3201 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3202 | + } |
|
| 3203 | + $session($GLOBALS['visiteur_session']); |
|
| 3204 | + |
|
| 3205 | + return 0; |
|
| 3206 | + } |
|
| 3207 | + |
|
| 3208 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3209 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3210 | + $session = charger_fonction('session', 'inc'); |
|
| 3211 | + if ($session()) { |
|
| 3212 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3213 | + } |
|
| 3214 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3215 | + include_spip('inc/auth'); |
|
| 3216 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3217 | + } |
|
| 3218 | + if ($h) { |
|
| 3219 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3220 | + |
|
| 3221 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3222 | + } |
|
| 3223 | + } |
|
| 3224 | + |
|
| 3225 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3226 | + include_spip('inc/lang'); |
|
| 3227 | + utiliser_langue_visiteur(); |
|
| 3228 | + |
|
| 3229 | + return false; |
|
| 3231 | 3230 | } |
| 3232 | 3231 | |
| 3233 | 3232 | |
@@ -3250,21 +3249,21 @@ discard block |
||
| 3250 | 3249 | * - string Langue utilisée. |
| 3251 | 3250 | **/ |
| 3252 | 3251 | function lang_select($lang = null) { |
| 3253 | - static $pile_langues = []; |
|
| 3254 | - if (!function_exists('changer_langue')) { |
|
| 3255 | - include_spip('inc/lang'); |
|
| 3256 | - } |
|
| 3257 | - if ($lang === null) { |
|
| 3258 | - $lang = array_pop($pile_langues); |
|
| 3259 | - } else { |
|
| 3260 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3261 | - } |
|
| 3262 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3263 | - return $lang; |
|
| 3264 | - } |
|
| 3265 | - changer_langue($lang); |
|
| 3252 | + static $pile_langues = []; |
|
| 3253 | + if (!function_exists('changer_langue')) { |
|
| 3254 | + include_spip('inc/lang'); |
|
| 3255 | + } |
|
| 3256 | + if ($lang === null) { |
|
| 3257 | + $lang = array_pop($pile_langues); |
|
| 3258 | + } else { |
|
| 3259 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3260 | + } |
|
| 3261 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3262 | + return $lang; |
|
| 3263 | + } |
|
| 3264 | + changer_langue($lang); |
|
| 3266 | 3265 | |
| 3267 | - return $lang; |
|
| 3266 | + return $lang; |
|
| 3268 | 3267 | } |
| 3269 | 3268 | |
| 3270 | 3269 | /** |
@@ -3281,20 +3280,20 @@ discard block |
||
| 3281 | 3280 | * Identifiant de la session |
| 3282 | 3281 | **/ |
| 3283 | 3282 | function spip_session($force = false) { |
| 3284 | - static $session; |
|
| 3285 | - if ($force or !isset($session)) { |
|
| 3286 | - $s = pipeline( |
|
| 3287 | - 'definir_session', |
|
| 3288 | - $GLOBALS['visiteur_session'] |
|
| 3289 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3290 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3291 | - : '' |
|
| 3292 | - ); |
|
| 3293 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3294 | - } |
|
| 3283 | + static $session; |
|
| 3284 | + if ($force or !isset($session)) { |
|
| 3285 | + $s = pipeline( |
|
| 3286 | + 'definir_session', |
|
| 3287 | + $GLOBALS['visiteur_session'] |
|
| 3288 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3289 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3290 | + : '' |
|
| 3291 | + ); |
|
| 3292 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3293 | + } |
|
| 3295 | 3294 | |
| 3296 | - #spip_log('session: '.$session); |
|
| 3297 | - return $session; |
|
| 3295 | + #spip_log('session: '.$session); |
|
| 3296 | + return $session; |
|
| 3298 | 3297 | } |
| 3299 | 3298 | |
| 3300 | 3299 | |
@@ -3313,9 +3312,9 @@ discard block |
||
| 3313 | 3312 | * Lien sur une icone d'aide |
| 3314 | 3313 | **/ |
| 3315 | 3314 | function aider($aide = '', $distante = false) { |
| 3316 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3315 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3317 | 3316 | |
| 3318 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3317 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3319 | 3318 | } |
| 3320 | 3319 | |
| 3321 | 3320 | /** |
@@ -3325,24 +3324,24 @@ discard block |
||
| 3325 | 3324 | */ |
| 3326 | 3325 | function exec_info_dist() { |
| 3327 | 3326 | |
| 3328 | - include_spip('inc/autoriser'); |
|
| 3329 | - if (autoriser('phpinfos')) { |
|
| 3330 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3331 | - $cookies_backup = []; |
|
| 3332 | - foreach ($cookies_masques as $k) { |
|
| 3333 | - if (!empty($_COOKIE[$k])) { |
|
| 3334 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3335 | - $_COOKIE[$k] = '******************************'; |
|
| 3336 | - } |
|
| 3337 | - } |
|
| 3338 | - phpinfo(); |
|
| 3339 | - foreach ($cookies_backup as $k => $v) { |
|
| 3340 | - $_COOKIE[$k] = $v; |
|
| 3341 | - } |
|
| 3342 | - } else { |
|
| 3343 | - include_spip('inc/filtres'); |
|
| 3344 | - sinon_interdire_acces(); |
|
| 3345 | - } |
|
| 3327 | + include_spip('inc/autoriser'); |
|
| 3328 | + if (autoriser('phpinfos')) { |
|
| 3329 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3330 | + $cookies_backup = []; |
|
| 3331 | + foreach ($cookies_masques as $k) { |
|
| 3332 | + if (!empty($_COOKIE[$k])) { |
|
| 3333 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3334 | + $_COOKIE[$k] = '******************************'; |
|
| 3335 | + } |
|
| 3336 | + } |
|
| 3337 | + phpinfo(); |
|
| 3338 | + foreach ($cookies_backup as $k => $v) { |
|
| 3339 | + $_COOKIE[$k] = $v; |
|
| 3340 | + } |
|
| 3341 | + } else { |
|
| 3342 | + include_spip('inc/filtres'); |
|
| 3343 | + sinon_interdire_acces(); |
|
| 3344 | + } |
|
| 3346 | 3345 | } |
| 3347 | 3346 | |
| 3348 | 3347 | /** |
@@ -3362,13 +3361,13 @@ discard block |
||
| 3362 | 3361 | * - string si $message à false. |
| 3363 | 3362 | **/ |
| 3364 | 3363 | function erreur_squelette($message = '', $lieu = '') { |
| 3365 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3366 | - if (is_array($lieu)) { |
|
| 3367 | - include_spip('public/compiler'); |
|
| 3368 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3369 | - } |
|
| 3364 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3365 | + if (is_array($lieu)) { |
|
| 3366 | + include_spip('public/compiler'); |
|
| 3367 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3368 | + } |
|
| 3370 | 3369 | |
| 3371 | - return $debusquer($message, $lieu); |
|
| 3370 | + return $debusquer($message, $lieu); |
|
| 3372 | 3371 | } |
| 3373 | 3372 | |
| 3374 | 3373 | /** |
@@ -3405,108 +3404,108 @@ discard block |
||
| 3405 | 3404 | * - ou tableau d'information sur le squelette. |
| 3406 | 3405 | */ |
| 3407 | 3406 | function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') { |
| 3408 | - if (!function_exists('evaluer_fond')) { |
|
| 3409 | - include_spip('public/assembler'); |
|
| 3410 | - } |
|
| 3411 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3412 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3413 | - if (!is_array($options)) { |
|
| 3414 | - $options = ['trim' => $options]; |
|
| 3415 | - } |
|
| 3416 | - if (!isset($options['trim'])) { |
|
| 3417 | - $options['trim'] = true; |
|
| 3418 | - } |
|
| 3419 | - |
|
| 3420 | - if (isset($contexte['connect'])) { |
|
| 3421 | - $connect = $contexte['connect']; |
|
| 3422 | - unset($contexte['connect']); |
|
| 3423 | - } |
|
| 3424 | - |
|
| 3425 | - $texte = ''; |
|
| 3426 | - $pages = []; |
|
| 3427 | - $lang_select = ''; |
|
| 3428 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3429 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3430 | - if (!isset($contexte['lang'])) { |
|
| 3431 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3432 | - } |
|
| 3433 | - |
|
| 3434 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3435 | - $lang_select = lang_select($contexte['lang']); |
|
| 3436 | - } |
|
| 3437 | - } |
|
| 3438 | - |
|
| 3439 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3440 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3441 | - } |
|
| 3442 | - |
|
| 3443 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3444 | - |
|
| 3445 | - // fix #4235 |
|
| 3446 | - $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3447 | - |
|
| 3448 | - |
|
| 3449 | - foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3450 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3451 | - |
|
| 3452 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3453 | - if ($page === '') { |
|
| 3454 | - $c = $options['compil'] ?? ''; |
|
| 3455 | - $a = ['fichier' => $f]; |
|
| 3456 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3457 | - erreur_squelette($erreur, $c); |
|
| 3458 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3459 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3460 | - } |
|
| 3461 | - |
|
| 3462 | - $page = pipeline('recuperer_fond', [ |
|
| 3463 | - 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3464 | - 'data' => $page |
|
| 3465 | - ]); |
|
| 3466 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3467 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3468 | - include_spip('inc/filtres'); |
|
| 3469 | - } |
|
| 3470 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3471 | - array_merge( |
|
| 3472 | - $contexte, |
|
| 3473 | - ['fond' => $f], |
|
| 3474 | - ($connect ? ['connect' => $connect] : []) |
|
| 3475 | - ), |
|
| 3476 | - '', |
|
| 3477 | - $page['texte'], |
|
| 3478 | - $options['ajax'] |
|
| 3479 | - ); |
|
| 3480 | - } |
|
| 3481 | - |
|
| 3482 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3483 | - $pages[] = $page; |
|
| 3484 | - } else { |
|
| 3485 | - $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3486 | - } |
|
| 3487 | - |
|
| 3488 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3489 | - if (isset($page['invalideurs']['session'])) { |
|
| 3490 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3491 | - } |
|
| 3492 | - } |
|
| 3493 | - |
|
| 3494 | - // restaurer le sessionnement du contexte appelant, |
|
| 3495 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3496 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3497 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3498 | - } |
|
| 3499 | - |
|
| 3500 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3501 | - |
|
| 3502 | - if ($lang_select) { |
|
| 3503 | - lang_select(); |
|
| 3504 | - } |
|
| 3505 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3506 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3507 | - } else { |
|
| 3508 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3509 | - } |
|
| 3407 | + if (!function_exists('evaluer_fond')) { |
|
| 3408 | + include_spip('public/assembler'); |
|
| 3409 | + } |
|
| 3410 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3411 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3412 | + if (!is_array($options)) { |
|
| 3413 | + $options = ['trim' => $options]; |
|
| 3414 | + } |
|
| 3415 | + if (!isset($options['trim'])) { |
|
| 3416 | + $options['trim'] = true; |
|
| 3417 | + } |
|
| 3418 | + |
|
| 3419 | + if (isset($contexte['connect'])) { |
|
| 3420 | + $connect = $contexte['connect']; |
|
| 3421 | + unset($contexte['connect']); |
|
| 3422 | + } |
|
| 3423 | + |
|
| 3424 | + $texte = ''; |
|
| 3425 | + $pages = []; |
|
| 3426 | + $lang_select = ''; |
|
| 3427 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3428 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3429 | + if (!isset($contexte['lang'])) { |
|
| 3430 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3431 | + } |
|
| 3432 | + |
|
| 3433 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3434 | + $lang_select = lang_select($contexte['lang']); |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | + |
|
| 3438 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3439 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3440 | + } |
|
| 3441 | + |
|
| 3442 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3443 | + |
|
| 3444 | + // fix #4235 |
|
| 3445 | + $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3446 | + |
|
| 3447 | + |
|
| 3448 | + foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3449 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3450 | + |
|
| 3451 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3452 | + if ($page === '') { |
|
| 3453 | + $c = $options['compil'] ?? ''; |
|
| 3454 | + $a = ['fichier' => $f]; |
|
| 3455 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3456 | + erreur_squelette($erreur, $c); |
|
| 3457 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3458 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3459 | + } |
|
| 3460 | + |
|
| 3461 | + $page = pipeline('recuperer_fond', [ |
|
| 3462 | + 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3463 | + 'data' => $page |
|
| 3464 | + ]); |
|
| 3465 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3466 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3467 | + include_spip('inc/filtres'); |
|
| 3468 | + } |
|
| 3469 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3470 | + array_merge( |
|
| 3471 | + $contexte, |
|
| 3472 | + ['fond' => $f], |
|
| 3473 | + ($connect ? ['connect' => $connect] : []) |
|
| 3474 | + ), |
|
| 3475 | + '', |
|
| 3476 | + $page['texte'], |
|
| 3477 | + $options['ajax'] |
|
| 3478 | + ); |
|
| 3479 | + } |
|
| 3480 | + |
|
| 3481 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3482 | + $pages[] = $page; |
|
| 3483 | + } else { |
|
| 3484 | + $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3485 | + } |
|
| 3486 | + |
|
| 3487 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3488 | + if (isset($page['invalideurs']['session'])) { |
|
| 3489 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3490 | + } |
|
| 3491 | + } |
|
| 3492 | + |
|
| 3493 | + // restaurer le sessionnement du contexte appelant, |
|
| 3494 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3495 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3496 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3497 | + } |
|
| 3498 | + |
|
| 3499 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3500 | + |
|
| 3501 | + if ($lang_select) { |
|
| 3502 | + lang_select(); |
|
| 3503 | + } |
|
| 3504 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3505 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3506 | + } else { |
|
| 3507 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3508 | + } |
|
| 3510 | 3509 | } |
| 3511 | 3510 | |
| 3512 | 3511 | /** |
@@ -3516,7 +3515,7 @@ discard block |
||
| 3516 | 3515 | * @return string |
| 3517 | 3516 | */ |
| 3518 | 3517 | function trouve_modele($nom) { |
| 3519 | - return trouver_fond($nom, 'modeles/'); |
|
| 3518 | + return trouver_fond($nom, 'modeles/'); |
|
| 3520 | 3519 | } |
| 3521 | 3520 | |
| 3522 | 3521 | /** |
@@ -3532,21 +3531,21 @@ discard block |
||
| 3532 | 3531 | * @return array|string |
| 3533 | 3532 | */ |
| 3534 | 3533 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3535 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3536 | - if (!$pathinfo) { |
|
| 3537 | - return $f; |
|
| 3538 | - } |
|
| 3539 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3540 | - $p = pathinfo($f); |
|
| 3541 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3542 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3543 | - } |
|
| 3544 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3545 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3546 | - } |
|
| 3547 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3534 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3535 | + if (!$pathinfo) { |
|
| 3536 | + return $f; |
|
| 3537 | + } |
|
| 3538 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3539 | + $p = pathinfo($f); |
|
| 3540 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3541 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3542 | + } |
|
| 3543 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3544 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3545 | + } |
|
| 3546 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3548 | 3547 | |
| 3549 | - return $p; |
|
| 3548 | + return $p; |
|
| 3550 | 3549 | } |
| 3551 | 3550 | |
| 3552 | 3551 | /** |
@@ -3566,21 +3565,21 @@ discard block |
||
| 3566 | 3565 | * Nom de l'exec, sinon chaîne vide. |
| 3567 | 3566 | **/ |
| 3568 | 3567 | function tester_url_ecrire($nom) { |
| 3569 | - static $exec = []; |
|
| 3570 | - if (isset($exec[$nom])) { |
|
| 3571 | - return $exec[$nom]; |
|
| 3572 | - } |
|
| 3573 | - // tester si c'est une page en squelette |
|
| 3574 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3575 | - return $exec[$nom] = 'fond'; |
|
| 3576 | - } // echafaudage d'un fond ! |
|
| 3577 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3578 | - return $exec[$nom] = 'fond'; |
|
| 3579 | - } |
|
| 3580 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3581 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3582 | - // et des define intrusifs potentiels |
|
| 3583 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3568 | + static $exec = []; |
|
| 3569 | + if (isset($exec[$nom])) { |
|
| 3570 | + return $exec[$nom]; |
|
| 3571 | + } |
|
| 3572 | + // tester si c'est une page en squelette |
|
| 3573 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3574 | + return $exec[$nom] = 'fond'; |
|
| 3575 | + } // echafaudage d'un fond ! |
|
| 3576 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3577 | + return $exec[$nom] = 'fond'; |
|
| 3578 | + } |
|
| 3579 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3580 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3581 | + // et des define intrusifs potentiels |
|
| 3582 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3584 | 3583 | } |
| 3585 | 3584 | |
| 3586 | 3585 | /** |
@@ -3590,8 +3589,8 @@ discard block |
||
| 3590 | 3589 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3591 | 3590 | **/ |
| 3592 | 3591 | function html5_permis() { |
| 3593 | - return (!defined('_VERSION_HTML') |
|
| 3594 | - or _VERSION_HTML !== 'html4'); |
|
| 3592 | + return (!defined('_VERSION_HTML') |
|
| 3593 | + or _VERSION_HTML !== 'html4'); |
|
| 3595 | 3594 | } |
| 3596 | 3595 | |
| 3597 | 3596 | /** |
@@ -3601,30 +3600,30 @@ discard block |
||
| 3601 | 3600 | * @return array |
| 3602 | 3601 | */ |
| 3603 | 3602 | function formats_image_acceptables($gd = null, $svg_allowed = true) { |
| 3604 | - $formats = null; |
|
| 3605 | - if (!is_null($gd)) { |
|
| 3606 | - $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3607 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3608 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3609 | - $formats = explode(',', $formats); |
|
| 3610 | - $formats = array_filter($formats); |
|
| 3611 | - $formats = array_map('trim', $formats); |
|
| 3612 | - } |
|
| 3613 | - } |
|
| 3614 | - if (is_null($formats)) { |
|
| 3615 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3616 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3617 | - } |
|
| 3618 | - |
|
| 3619 | - if ($svg_allowed) { |
|
| 3620 | - if (!in_array('svg', $formats)) { |
|
| 3621 | - $formats[] = 'svg'; |
|
| 3622 | - } |
|
| 3623 | - } |
|
| 3624 | - else { |
|
| 3625 | - $formats = array_diff($formats, ['svg']); |
|
| 3626 | - } |
|
| 3627 | - return $formats; |
|
| 3603 | + $formats = null; |
|
| 3604 | + if (!is_null($gd)) { |
|
| 3605 | + $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3606 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3607 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3608 | + $formats = explode(',', $formats); |
|
| 3609 | + $formats = array_filter($formats); |
|
| 3610 | + $formats = array_map('trim', $formats); |
|
| 3611 | + } |
|
| 3612 | + } |
|
| 3613 | + if (is_null($formats)) { |
|
| 3614 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3615 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3616 | + } |
|
| 3617 | + |
|
| 3618 | + if ($svg_allowed) { |
|
| 3619 | + if (!in_array('svg', $formats)) { |
|
| 3620 | + $formats[] = 'svg'; |
|
| 3621 | + } |
|
| 3622 | + } |
|
| 3623 | + else { |
|
| 3624 | + $formats = array_diff($formats, ['svg']); |
|
| 3625 | + } |
|
| 3626 | + return $formats; |
|
| 3628 | 3627 | } |
| 3629 | 3628 | |
| 3630 | 3629 | /** |
@@ -3633,20 +3632,20 @@ discard block |
||
| 3633 | 3632 | * @return array|bool |
| 3634 | 3633 | */ |
| 3635 | 3634 | function spip_getimagesize($fichier) { |
| 3636 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3637 | - include_spip('inc/svg'); |
|
| 3638 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3639 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3640 | - $imagesize = [ |
|
| 3641 | - $width, |
|
| 3642 | - $height, |
|
| 3643 | - IMAGETYPE_SVG, |
|
| 3644 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3645 | - 'mime' => 'image/svg+xml' |
|
| 3646 | - ]; |
|
| 3647 | - } |
|
| 3648 | - } |
|
| 3649 | - return $imagesize; |
|
| 3635 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3636 | + include_spip('inc/svg'); |
|
| 3637 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3638 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3639 | + $imagesize = [ |
|
| 3640 | + $width, |
|
| 3641 | + $height, |
|
| 3642 | + IMAGETYPE_SVG, |
|
| 3643 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3644 | + 'mime' => 'image/svg+xml' |
|
| 3645 | + ]; |
|
| 3646 | + } |
|
| 3647 | + } |
|
| 3648 | + return $imagesize; |
|
| 3650 | 3649 | } |
| 3651 | 3650 | |
| 3652 | 3651 | /** |
@@ -3660,19 +3659,19 @@ discard block |
||
| 3660 | 3659 | * @param string $statut |
| 3661 | 3660 | */ |
| 3662 | 3661 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3663 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3664 | - if ( |
|
| 3665 | - !$alertes |
|
| 3666 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3667 | - ) { |
|
| 3668 | - $alertes = []; |
|
| 3669 | - } |
|
| 3662 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3663 | + if ( |
|
| 3664 | + !$alertes |
|
| 3665 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3666 | + ) { |
|
| 3667 | + $alertes = []; |
|
| 3668 | + } |
|
| 3670 | 3669 | |
| 3671 | - if (!isset($alertes[$statut])) { |
|
| 3672 | - $alertes[$statut] = []; |
|
| 3673 | - } |
|
| 3674 | - $alertes[$statut][$nom] = $message; |
|
| 3675 | - ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3670 | + if (!isset($alertes[$statut])) { |
|
| 3671 | + $alertes[$statut] = []; |
|
| 3672 | + } |
|
| 3673 | + $alertes[$statut][$nom] = $message; |
|
| 3674 | + ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3676 | 3675 | } |
| 3677 | 3676 | |
| 3678 | 3677 | /** |
@@ -3686,10 +3685,10 @@ discard block |
||
| 3686 | 3685 | * @return string|string[] |
| 3687 | 3686 | */ |
| 3688 | 3687 | function spip_sanitize_classname($classes) { |
| 3689 | - if (is_array($classes)) { |
|
| 3690 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3691 | - } |
|
| 3692 | - return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3688 | + if (is_array($classes)) { |
|
| 3689 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3690 | + } |
|
| 3691 | + return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3693 | 3692 | } |
| 3694 | 3693 | |
| 3695 | 3694 | |
@@ -3714,32 +3713,32 @@ discard block |
||
| 3714 | 3713 | * Avec operateur : bool. |
| 3715 | 3714 | **/ |
| 3716 | 3715 | function spip_version_compare($v1, $v2, $op = null) { |
| 3717 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3718 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3719 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3720 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3721 | - |
|
| 3722 | - $v1 = explode('.', $v1); |
|
| 3723 | - $v2 = explode('.', $v2); |
|
| 3724 | - // $v1 est toujours une version, donc sans etoile |
|
| 3725 | - while (count($v1) < count($v2)) { |
|
| 3726 | - $v1[] = '0'; |
|
| 3727 | - } |
|
| 3728 | - |
|
| 3729 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3730 | - $etoile = false; |
|
| 3731 | - foreach ($v1 as $k => $v) { |
|
| 3732 | - if (!isset($v2[$k])) { |
|
| 3733 | - $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3734 | - } else { |
|
| 3735 | - if ($v2[$k] == '*') { |
|
| 3736 | - $etoile = true; |
|
| 3737 | - $v2[$k] = $v; |
|
| 3738 | - } |
|
| 3739 | - } |
|
| 3740 | - } |
|
| 3741 | - $v1 = implode('.', $v1); |
|
| 3742 | - $v2 = implode('.', $v2); |
|
| 3743 | - |
|
| 3744 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3716 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3717 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3718 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3719 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3720 | + |
|
| 3721 | + $v1 = explode('.', $v1); |
|
| 3722 | + $v2 = explode('.', $v2); |
|
| 3723 | + // $v1 est toujours une version, donc sans etoile |
|
| 3724 | + while (count($v1) < count($v2)) { |
|
| 3725 | + $v1[] = '0'; |
|
| 3726 | + } |
|
| 3727 | + |
|
| 3728 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3729 | + $etoile = false; |
|
| 3730 | + foreach ($v1 as $k => $v) { |
|
| 3731 | + if (!isset($v2[$k])) { |
|
| 3732 | + $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3733 | + } else { |
|
| 3734 | + if ($v2[$k] == '*') { |
|
| 3735 | + $etoile = true; |
|
| 3736 | + $v2[$k] = $v; |
|
| 3737 | + } |
|
| 3738 | + } |
|
| 3739 | + } |
|
| 3740 | + $v1 = implode('.', $v1); |
|
| 3741 | + $v2 = implode('.', $v2); |
|
| 3742 | + |
|
| 3743 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3745 | 3744 | } |
@@ -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/filtres_boites'); |
@@ -41,25 +41,25 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function parametres_css_prive() { |
| 43 | 43 | |
| 44 | - $args = []; |
|
| 45 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | - $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 44 | + $args = []; |
|
| 45 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | + $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 51 | 51 | |
| 52 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 53 | 53 | |
| 54 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | - parse_str($couleurs($c), $c); |
|
| 56 | - $args = array_merge($args, $c); |
|
| 54 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | + parse_str($couleurs($c), $c); |
|
| 56 | + $args = array_merge($args, $c); |
|
| 57 | 57 | |
| 58 | - if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | - $args['var_mode'] = 'recalcul'; |
|
| 60 | - } |
|
| 58 | + if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | + $args['var_mode'] = 'recalcul'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return http_build_query($args); |
|
| 62 | + return http_build_query($args); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
@@ -82,91 +82,91 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | 84 | function chercher_rubrique( |
| 85 | - $titre, |
|
| 86 | - $id_objet, |
|
| 87 | - $id_parent, |
|
| 88 | - $objet, |
|
| 89 | - $id_secteur, |
|
| 90 | - $restreint, |
|
| 91 | - $actionable = false, |
|
| 92 | - $retour_sans_cadre = false |
|
| 85 | + $titre, |
|
| 86 | + $id_objet, |
|
| 87 | + $id_parent, |
|
| 88 | + $objet, |
|
| 89 | + $id_secteur, |
|
| 90 | + $restreint, |
|
| 91 | + $actionable = false, |
|
| 92 | + $retour_sans_cadre = false |
|
| 93 | 93 | ) { |
| 94 | 94 | |
| 95 | - include_spip('inc/autoriser'); |
|
| 96 | - if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | - return ''; |
|
| 98 | - } |
|
| 99 | - if (!sql_countsel('spip_rubriques')) { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 102 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | - |
|
| 105 | - if ($id_parent == 0) { |
|
| 106 | - $logo = 'racine-24.png'; |
|
| 107 | - } elseif ($id_secteur == $id_parent) { |
|
| 108 | - $logo = 'secteur-24.png'; |
|
| 109 | - } else { |
|
| 110 | - $logo = 'rubrique-24.png'; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $confirm = ''; |
|
| 114 | - if ($objet == 'rubrique') { |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | - |
|
| 119 | - if ($contient_breves > 0) { |
|
| 120 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | - $scb = _T( |
|
| 122 | - 'avis_deplacement_rubrique', |
|
| 123 | - [ |
|
| 124 | - 'contient_breves' => $contient_breves, |
|
| 125 | - 'scb' => $scb |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | - . $scb . |
|
| 131 | - "</label></div></div>\n"; |
|
| 132 | - } else { |
|
| 133 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $form .= $confirm; |
|
| 137 | - if ($actionable) { |
|
| 138 | - if (strpos($form, '<select') !== false) { |
|
| 139 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | - . '</div>'; |
|
| 142 | - } |
|
| 143 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | - $form = generer_action_auteur( |
|
| 146 | - "editer_$objet", |
|
| 147 | - $id_objet, |
|
| 148 | - self(), |
|
| 149 | - $form, |
|
| 150 | - " method='post' class='submit_plongeur'" |
|
| 151 | - ); |
|
| 152 | - } else { |
|
| 153 | - $form = generer_action_auteur( |
|
| 154 | - 'editer_objet', |
|
| 155 | - "$objet/$id_objet", |
|
| 156 | - self(), |
|
| 157 | - $form, |
|
| 158 | - " method='post' class='submit_plongeur'" |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($retour_sans_cadre) { |
|
| 164 | - return $form; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - include_spip('inc/presentation'); |
|
| 168 | - |
|
| 169 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 95 | + include_spip('inc/autoriser'); |
|
| 96 | + if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | + return ''; |
|
| 98 | + } |
|
| 99 | + if (!sql_countsel('spip_rubriques')) { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 102 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | + |
|
| 105 | + if ($id_parent == 0) { |
|
| 106 | + $logo = 'racine-24.png'; |
|
| 107 | + } elseif ($id_secteur == $id_parent) { |
|
| 108 | + $logo = 'secteur-24.png'; |
|
| 109 | + } else { |
|
| 110 | + $logo = 'rubrique-24.png'; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $confirm = ''; |
|
| 114 | + if ($objet == 'rubrique') { |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | + |
|
| 119 | + if ($contient_breves > 0) { |
|
| 120 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | + $scb = _T( |
|
| 122 | + 'avis_deplacement_rubrique', |
|
| 123 | + [ |
|
| 124 | + 'contient_breves' => $contient_breves, |
|
| 125 | + 'scb' => $scb |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | + . $scb . |
|
| 131 | + "</label></div></div>\n"; |
|
| 132 | + } else { |
|
| 133 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $form .= $confirm; |
|
| 137 | + if ($actionable) { |
|
| 138 | + if (strpos($form, '<select') !== false) { |
|
| 139 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | + . '</div>'; |
|
| 142 | + } |
|
| 143 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | + $form = generer_action_auteur( |
|
| 146 | + "editer_$objet", |
|
| 147 | + $id_objet, |
|
| 148 | + self(), |
|
| 149 | + $form, |
|
| 150 | + " method='post' class='submit_plongeur'" |
|
| 151 | + ); |
|
| 152 | + } else { |
|
| 153 | + $form = generer_action_auteur( |
|
| 154 | + 'editer_objet', |
|
| 155 | + "$objet/$id_objet", |
|
| 156 | + self(), |
|
| 157 | + $form, |
|
| 158 | + " method='post' class='submit_plongeur'" |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($retour_sans_cadre) { |
|
| 164 | + return $form; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + include_spip('inc/presentation'); |
|
| 168 | + |
|
| 169 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -180,24 +180,24 @@ discard block |
||
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | 182 | function avoir_visiteurs($past = false, $accepter = true) { |
| 183 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | - return true; |
|
| 185 | - } |
|
| 186 | - if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (!$past) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return sql_countsel( |
|
| 197 | - 'spip_auteurs', |
|
| 198 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 183 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | + return true; |
|
| 185 | + } |
|
| 186 | + if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (!$past) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return sql_countsel( |
|
| 197 | + 'spip_auteurs', |
|
| 198 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 199 | 199 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 200 | - ); |
|
| 200 | + ); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function statuts_articles_visibles($statut_auteur) { |
| 216 | - static $auth = []; |
|
| 217 | - if (!isset($auth[$statut_auteur])) { |
|
| 218 | - $auth[$statut_auteur] = []; |
|
| 219 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | - foreach ($statuts as $s) { |
|
| 221 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | - $auth[$statut_auteur][] = $s; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $auth[$statut_auteur]; |
|
| 216 | + static $auth = []; |
|
| 217 | + if (!isset($auth[$statut_auteur])) { |
|
| 218 | + $auth[$statut_auteur] = []; |
|
| 219 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | + foreach ($statuts as $s) { |
|
| 221 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | + $auth[$statut_auteur][] = $s; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $auth[$statut_auteur]; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -238,38 +238,38 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function traduire_statut_auteur($statut, $attente = '') { |
| 241 | - $plus = ''; |
|
| 242 | - if ($statut == 'nouveau') { |
|
| 243 | - if ($attente) { |
|
| 244 | - $statut = $attente; |
|
| 245 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | - } else { |
|
| 247 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $recom = [ |
|
| 252 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | - ]; |
|
| 257 | - if (isset($recom[$statut])) { |
|
| 258 | - return $recom[$statut] . $plus; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // retrouver directement par le statut sinon |
|
| 262 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | - if (isset($recom[$t])) { |
|
| 264 | - return $recom[$t] . $plus; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return _T($t) . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | - // c'est toujours plus informatif que rien du tout |
|
| 272 | - return $statut; |
|
| 241 | + $plus = ''; |
|
| 242 | + if ($statut == 'nouveau') { |
|
| 243 | + if ($attente) { |
|
| 244 | + $statut = $attente; |
|
| 245 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | + } else { |
|
| 247 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $recom = [ |
|
| 252 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | + ]; |
|
| 257 | + if (isset($recom[$statut])) { |
|
| 258 | + return $recom[$statut] . $plus; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // retrouver directement par le statut sinon |
|
| 262 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | + if (isset($recom[$t])) { |
|
| 264 | + return $recom[$t] . $plus; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return _T($t) . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | + // c'est toujours plus informatif que rien du tout |
|
| 272 | + return $statut; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -280,28 +280,28 @@ discard block |
||
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | 282 | function afficher_qui_edite($id_objet, $objet) { |
| 283 | - static $qui = []; |
|
| 284 | - if (isset($qui[$objet][$id_objet])) { |
|
| 285 | - return $qui[$objet][$id_objet]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | - return $qui[$objet][$id_objet] = ''; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - include_spip('inc/drapeau_edition'); |
|
| 293 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | - if (!$modif) { |
|
| 295 | - return $qui[$objet][$id_objet] = ''; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - include_spip('base/objets'); |
|
| 299 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | - if (isset($infos['texte_signale_edition'])) { |
|
| 301 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 283 | + static $qui = []; |
|
| 284 | + if (isset($qui[$objet][$id_objet])) { |
|
| 285 | + return $qui[$objet][$id_objet]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | + return $qui[$objet][$id_objet] = ''; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + include_spip('inc/drapeau_edition'); |
|
| 293 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | + if (!$modif) { |
|
| 295 | + return $qui[$objet][$id_objet] = ''; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + include_spip('base/objets'); |
|
| 299 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | + if (isset($infos['texte_signale_edition'])) { |
|
| 301 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,57 +319,57 @@ discard block |
||
| 319 | 319 | * @return array |
| 320 | 320 | */ |
| 321 | 321 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true) { |
| 322 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - switch ($quoi) { |
|
| 327 | - case 'redacteurs': |
|
| 328 | - $statut = AUTEURS_MIN_REDAC; |
|
| 329 | - $statut = explode(',', $statut); |
|
| 330 | - if ($en_base) { |
|
| 331 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | - $retire = array_diff($statut, $check); |
|
| 333 | - $statut = array_diff($statut, $retire); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return array_unique($statut); |
|
| 337 | - break; |
|
| 338 | - case 'visiteurs': |
|
| 339 | - $statut = []; |
|
| 340 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | - $exclus = explode(',', $exclus); |
|
| 342 | - if (!$en_base) { |
|
| 343 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | - } |
|
| 346 | - $s_complement = array_column( |
|
| 347 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | - 'statut' |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | - break; |
|
| 353 | - default: |
|
| 354 | - case 'tous': |
|
| 355 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | - $s_complement = array_column( |
|
| 357 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | - 'statut' |
|
| 359 | - ); |
|
| 360 | - $statut = array_merge($statut, $s_complement); |
|
| 361 | - if ($en_base) { |
|
| 362 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | - $retire = array_diff($statut, $check); |
|
| 364 | - $statut = array_diff($statut, $retire); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return array_unique($statut); |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // on arrive jamais ici |
|
| 372 | - return array_values($GLOBALS['liste_des_statuts']); |
|
| 322 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + switch ($quoi) { |
|
| 327 | + case 'redacteurs': |
|
| 328 | + $statut = AUTEURS_MIN_REDAC; |
|
| 329 | + $statut = explode(',', $statut); |
|
| 330 | + if ($en_base) { |
|
| 331 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | + $retire = array_diff($statut, $check); |
|
| 333 | + $statut = array_diff($statut, $retire); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return array_unique($statut); |
|
| 337 | + break; |
|
| 338 | + case 'visiteurs': |
|
| 339 | + $statut = []; |
|
| 340 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | + $exclus = explode(',', $exclus); |
|
| 342 | + if (!$en_base) { |
|
| 343 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | + } |
|
| 346 | + $s_complement = array_column( |
|
| 347 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | + 'statut' |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | + break; |
|
| 353 | + default: |
|
| 354 | + case 'tous': |
|
| 355 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | + $s_complement = array_column( |
|
| 357 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | + 'statut' |
|
| 359 | + ); |
|
| 360 | + $statut = array_merge($statut, $s_complement); |
|
| 361 | + if ($en_base) { |
|
| 362 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | + $retire = array_diff($statut, $check); |
|
| 364 | + $statut = array_diff($statut, $retire); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return array_unique($statut); |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // on arrive jamais ici |
|
| 372 | + return array_values($GLOBALS['liste_des_statuts']); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? '' |
|
| 391 | - : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? '' |
|
| 391 | + : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - return propre('[->' . $virtuel . ']'); |
|
| 425 | + return propre('[->' . $virtuel . ']'); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | * @filtre |
| 446 | 446 | */ |
| 447 | 447 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 448 | - include_spip('inc/acces'); |
|
| 449 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 448 | + include_spip('inc/acces'); |
|
| 449 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 450 | 450 | |
| 451 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 451 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | |
@@ -461,74 +461,74 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | function alertes_auteur($id_auteur) { |
| 463 | 463 | |
| 464 | - $alertes = []; |
|
| 465 | - |
|
| 466 | - if ( |
|
| 467 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | - and autoriser('detruire', null, null, $id_auteur) |
|
| 469 | - ) { |
|
| 470 | - include_spip('genie/maintenance'); |
|
| 471 | - if ($msg = message_crash_tables()) { |
|
| 472 | - $alertes[] = $msg; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if ( |
|
| 477 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | - and $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | - and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | - ) { |
|
| 482 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | - if ( |
|
| 488 | - $a |
|
| 489 | - and is_array($a = unserialize($a)) |
|
| 490 | - and count($a) |
|
| 491 | - ) { |
|
| 492 | - $update = false; |
|
| 493 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 494 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 495 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | - $update = true; |
|
| 497 | - } |
|
| 498 | - if (isset($a[''])) { |
|
| 499 | - $alertes = array_merge($alertes, $a['']); |
|
| 500 | - unset($a['']); |
|
| 501 | - $update = true; |
|
| 502 | - } |
|
| 503 | - if ($update) { |
|
| 504 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - if ( |
|
| 509 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 510 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 511 | - ) { |
|
| 512 | - include_spip('inc/plugin'); |
|
| 513 | - $alertes[] = plugin_donne_erreurs(); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - $alertes = pipeline( |
|
| 517 | - 'alertes_auteur', |
|
| 518 | - [ |
|
| 519 | - 'args' => [ |
|
| 520 | - 'id_auteur' => $id_auteur, |
|
| 521 | - 'exec' => _request('exec'), |
|
| 522 | - ], |
|
| 523 | - 'data' => $alertes |
|
| 524 | - ] |
|
| 525 | - ); |
|
| 526 | - |
|
| 527 | - if ($alertes = array_filter($alertes)) { |
|
| 528 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 529 | - join(' | ', $alertes) |
|
| 530 | - . '</div></div>'; |
|
| 531 | - } |
|
| 464 | + $alertes = []; |
|
| 465 | + |
|
| 466 | + if ( |
|
| 467 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | + and autoriser('detruire', null, null, $id_auteur) |
|
| 469 | + ) { |
|
| 470 | + include_spip('genie/maintenance'); |
|
| 471 | + if ($msg = message_crash_tables()) { |
|
| 472 | + $alertes[] = $msg; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if ( |
|
| 477 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | + and $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | + and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | + ) { |
|
| 482 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | + if ( |
|
| 488 | + $a |
|
| 489 | + and is_array($a = unserialize($a)) |
|
| 490 | + and count($a) |
|
| 491 | + ) { |
|
| 492 | + $update = false; |
|
| 493 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 494 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 495 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | + $update = true; |
|
| 497 | + } |
|
| 498 | + if (isset($a[''])) { |
|
| 499 | + $alertes = array_merge($alertes, $a['']); |
|
| 500 | + unset($a['']); |
|
| 501 | + $update = true; |
|
| 502 | + } |
|
| 503 | + if ($update) { |
|
| 504 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + if ( |
|
| 509 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 510 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 511 | + ) { |
|
| 512 | + include_spip('inc/plugin'); |
|
| 513 | + $alertes[] = plugin_donne_erreurs(); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $alertes = pipeline( |
|
| 517 | + 'alertes_auteur', |
|
| 518 | + [ |
|
| 519 | + 'args' => [ |
|
| 520 | + 'id_auteur' => $id_auteur, |
|
| 521 | + 'exec' => _request('exec'), |
|
| 522 | + ], |
|
| 523 | + 'data' => $alertes |
|
| 524 | + ] |
|
| 525 | + ); |
|
| 526 | + |
|
| 527 | + if ($alertes = array_filter($alertes)) { |
|
| 528 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 529 | + join(' | ', $alertes) |
|
| 530 | + . '</div></div>'; |
|
| 531 | + } |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -538,9 +538,9 @@ discard block |
||
| 538 | 538 | * @return string |
| 539 | 539 | */ |
| 540 | 540 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 541 | - include_spip('inc/presenter_enfants'); |
|
| 541 | + include_spip('inc/presenter_enfants'); |
|
| 542 | 542 | |
| 543 | - return afficher_enfant_rub(intval($id_rubrique)); |
|
| 543 | + return afficher_enfant_rub(intval($id_rubrique)); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -558,15 +558,15 @@ discard block |
||
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | 560 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 561 | - $titre = attribut_html($titre); |
|
| 562 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 563 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 564 | - |
|
| 565 | - if (!$titre_lien) { |
|
| 566 | - return $icone; |
|
| 567 | - } else { |
|
| 568 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 569 | - } |
|
| 561 | + $titre = attribut_html($titre); |
|
| 562 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 563 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 564 | + |
|
| 565 | + if (!$titre_lien) { |
|
| 566 | + return $icone; |
|
| 567 | + } else { |
|
| 568 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 569 | + } |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -585,17 +585,17 @@ discard block |
||
| 585 | 585 | * @return array |
| 586 | 586 | */ |
| 587 | 587 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 588 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 589 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 590 | - return []; |
|
| 591 | - } |
|
| 592 | - $r = reset($res); |
|
| 593 | - if (isset($r['rang_lien'])) { |
|
| 594 | - $l = array_column($res, 'rang_lien', $objet_source); |
|
| 595 | - asort($l); |
|
| 596 | - $l = array_keys($l); |
|
| 597 | - } else { |
|
| 598 | - $l = array_column($res, $objet_source); |
|
| 599 | - } |
|
| 600 | - return $l; |
|
| 588 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 589 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 590 | + return []; |
|
| 591 | + } |
|
| 592 | + $r = reset($res); |
|
| 593 | + if (isset($r['rang_lien'])) { |
|
| 594 | + $l = array_column($res, 'rang_lien', $objet_source); |
|
| 595 | + asort($l); |
|
| 596 | + $l = array_keys($l); |
|
| 597 | + } else { |
|
| 598 | + $l = array_column($res, $objet_source); |
|
| 599 | + } |
|
| 600 | + return $l; |
|
| 601 | 601 | } |
@@ -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('compacte')) { |
|
| 5459 | - return compacte($source, $format); |
|
| 5460 | - } |
|
| 5458 | + if (function_exists('compacte')) { |
|
| 5459 | + return compacte($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 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api( $script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api( $script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | * @return void|bool |
| 326 | 326 | */ |
| 327 | 327 | function initialiser_sel() { |
| 328 | - if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | - if (CRYPT_MD5) { |
|
| 330 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 331 | - } else { |
|
| 332 | - $GLOBALS['htsalt'] = ''; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - return $GLOBALS['htsalt']; |
|
| 328 | + if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | + if (CRYPT_MD5) { |
|
| 330 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 331 | + } else { |
|
| 332 | + $GLOBALS['htsalt'] = ''; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + return $GLOBALS['htsalt']; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -349,32 +349,32 @@ discard block |
||
| 349 | 349 | * - void sinon. |
| 350 | 350 | **/ |
| 351 | 351 | function ecrire_acces() { |
| 352 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 353 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 354 | - |
|
| 355 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 356 | - // par exemple acces_restreint ; |
|
| 357 | - // si .htaccess existe, outrepasser spip_meta |
|
| 358 | - if ( |
|
| 359 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 360 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 361 | - and !@file_exists($htaccess) |
|
| 362 | - ) { |
|
| 363 | - spip_unlink($htpasswd); |
|
| 364 | - spip_unlink($htpasswd . '-admin'); |
|
| 365 | - return; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 369 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 370 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 371 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 372 | - |
|
| 373 | - if (spip_connect_ldap()) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 352 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 353 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 354 | + |
|
| 355 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 356 | + // par exemple acces_restreint ; |
|
| 357 | + // si .htaccess existe, outrepasser spip_meta |
|
| 358 | + if ( |
|
| 359 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 360 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 361 | + and !@file_exists($htaccess) |
|
| 362 | + ) { |
|
| 363 | + spip_unlink($htpasswd); |
|
| 364 | + spip_unlink($htpasswd . '-admin'); |
|
| 365 | + return; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 369 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 370 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 371 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 372 | + |
|
| 373 | + if (spip_connect_ldap()) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -383,29 +383,29 @@ discard block |
||
| 383 | 383 | * @param $htpasswd_admin |
| 384 | 384 | */ |
| 385 | 385 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 386 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 387 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - $pwd_all = ''; // login:htpass pour tous |
|
| 391 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 392 | - |
|
| 393 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 394 | - while ($row = sql_fetch($res)) { |
|
| 395 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 396 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 397 | - $pwd_all .= $ligne; |
|
| 398 | - if ($row['statut'] == '0minirezo') { |
|
| 399 | - $pwd_admin .= $ligne; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($pwd_all) { |
|
| 405 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 406 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 407 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 408 | - } |
|
| 386 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 387 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + $pwd_all = ''; // login:htpass pour tous |
|
| 391 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 392 | + |
|
| 393 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 394 | + while ($row = sql_fetch($res)) { |
|
| 395 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 396 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 397 | + $pwd_all .= $ligne; |
|
| 398 | + if ($row['statut'] == '0minirezo') { |
|
| 399 | + $pwd_admin .= $ligne; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($pwd_all) { |
|
| 405 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 406 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 407 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -419,13 +419,13 @@ discard block |
||
| 419 | 419 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 420 | 420 | */ |
| 421 | 421 | function generer_htpass($pass) { |
| 422 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 423 | - return $generer_htpass($pass); |
|
| 424 | - } |
|
| 425 | - elseif (function_exists('crypt')) { |
|
| 426 | - return crypt($pass, initialiser_sel()); |
|
| 427 | - } |
|
| 428 | - return ''; |
|
| 422 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 423 | + return $generer_htpass($pass); |
|
| 424 | + } |
|
| 425 | + elseif (function_exists('crypt')) { |
|
| 426 | + return crypt($pass, initialiser_sel()); |
|
| 427 | + } |
|
| 428 | + return ''; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | * @return boolean |
| 439 | 439 | */ |
| 440 | 440 | function verifier_htaccess($rep, $force = false) { |
| 441 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 442 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 443 | - return true; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // directive deny compatible Apache 2.0+ |
|
| 447 | - $deny = |
|
| 448 | - '# Deny all requests from Apache 2.4+. |
|
| 441 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 442 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 443 | + return true; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // directive deny compatible Apache 2.0+ |
|
| 447 | + $deny = |
|
| 448 | + '# Deny all requests from Apache 2.4+. |
|
| 449 | 449 | <IfModule mod_authz_core.c> |
| 450 | 450 | Require all denied |
| 451 | 451 | </IfModule> |
@@ -454,32 +454,32 @@ discard block |
||
| 454 | 454 | Deny from all |
| 455 | 455 | </IfModule> |
| 456 | 456 | '; |
| 457 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 458 | - if ( |
|
| 459 | - function_exists('apache_get_version') |
|
| 460 | - and $v = apache_get_version() |
|
| 461 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 462 | - ) { |
|
| 463 | - $deny = "deny from all\n"; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 467 | - fputs($ht, $deny); |
|
| 468 | - fclose($ht); |
|
| 469 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 470 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 471 | - if ($ht = @fopen($t, 'w')) { |
|
| 472 | - @fclose($ht); |
|
| 473 | - include_spip('inc/distant'); |
|
| 474 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 475 | - $t = url_de_base() . $t; |
|
| 476 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 477 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 481 | - |
|
| 482 | - return $ht; |
|
| 457 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 458 | + if ( |
|
| 459 | + function_exists('apache_get_version') |
|
| 460 | + and $v = apache_get_version() |
|
| 461 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 462 | + ) { |
|
| 463 | + $deny = "deny from all\n"; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 467 | + fputs($ht, $deny); |
|
| 468 | + fclose($ht); |
|
| 469 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 470 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 471 | + if ($ht = @fopen($t, 'w')) { |
|
| 472 | + @fclose($ht); |
|
| 473 | + include_spip('inc/distant'); |
|
| 474 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 475 | + $t = url_de_base() . $t; |
|
| 476 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 477 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 481 | + |
|
| 482 | + return $ht; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -497,20 +497,20 @@ discard block |
||
| 497 | 497 | * Valeur de la configuration `creer_htaccess` |
| 498 | 498 | */ |
| 499 | 499 | function gerer_htaccess() { |
| 500 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 501 | - // par exemple acces_restreint |
|
| 502 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 503 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 504 | - $dirs[] = ['extension' => 'distant']; |
|
| 505 | - foreach ($dirs as $e) { |
|
| 506 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 507 | - if ($f) { |
|
| 508 | - verifier_htaccess($dir); |
|
| 509 | - } else { |
|
| 510 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 500 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 501 | + // par exemple acces_restreint |
|
| 502 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 503 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 504 | + $dirs[] = ['extension' => 'distant']; |
|
| 505 | + foreach ($dirs as $e) { |
|
| 506 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 507 | + if ($f) { |
|
| 508 | + verifier_htaccess($dir); |
|
| 509 | + } else { |
|
| 510 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 516 | 516 | } |