@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | if (defined('_TEST_DIRS')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | define('_TEST_DIRS', '1'); |
| 21 | 21 | |
@@ -26,42 +26,42 @@ discard block |
||
| 26 | 26 | // Tente d'ecrire |
| 27 | 27 | // |
| 28 | 28 | function test_ecrire($my_dir) { |
| 29 | - static $chmod = 0; |
|
| 30 | - |
|
| 31 | - $ok = false; |
|
| 32 | - $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 33 | - $self = basename($script); |
|
| 34 | - $uid = @fileowner('.'); |
|
| 35 | - $uid2 = @fileowner($self); |
|
| 36 | - $gid = @filegroup('.'); |
|
| 37 | - $gid2 = @filegroup($self); |
|
| 38 | - $perms = @fileperms($self); |
|
| 39 | - |
|
| 40 | - // Comparer l'appartenance d'un fichier cree par PHP |
|
| 41 | - // avec celle du script et du repertoire courant |
|
| 42 | - if (!$chmod) { |
|
| 43 | - @rmdir('test'); |
|
| 44 | - spip_unlink('test'); // effacer au cas ou |
|
| 45 | - @touch('test'); |
|
| 46 | - if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 47 | - $chmod = 0700; |
|
| 48 | - } else { |
|
| 49 | - if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 50 | - $chmod = 0770; |
|
| 51 | - } else { |
|
| 52 | - $chmod = 0777; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - // Appliquer de plus les droits d'acces du script |
|
| 56 | - if ($perms > 0) { |
|
| 57 | - $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 58 | - $chmod |= $perms; |
|
| 59 | - } |
|
| 60 | - spip_unlink('test'); |
|
| 61 | - } |
|
| 62 | - $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 63 | - |
|
| 64 | - return $ok ? $chmod : false; |
|
| 29 | + static $chmod = 0; |
|
| 30 | + |
|
| 31 | + $ok = false; |
|
| 32 | + $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 33 | + $self = basename($script); |
|
| 34 | + $uid = @fileowner('.'); |
|
| 35 | + $uid2 = @fileowner($self); |
|
| 36 | + $gid = @filegroup('.'); |
|
| 37 | + $gid2 = @filegroup($self); |
|
| 38 | + $perms = @fileperms($self); |
|
| 39 | + |
|
| 40 | + // Comparer l'appartenance d'un fichier cree par PHP |
|
| 41 | + // avec celle du script et du repertoire courant |
|
| 42 | + if (!$chmod) { |
|
| 43 | + @rmdir('test'); |
|
| 44 | + spip_unlink('test'); // effacer au cas ou |
|
| 45 | + @touch('test'); |
|
| 46 | + if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 47 | + $chmod = 0700; |
|
| 48 | + } else { |
|
| 49 | + if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 50 | + $chmod = 0770; |
|
| 51 | + } else { |
|
| 52 | + $chmod = 0777; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + // Appliquer de plus les droits d'acces du script |
|
| 56 | + if ($perms > 0) { |
|
| 57 | + $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 58 | + $chmod |= $perms; |
|
| 59 | + } |
|
| 60 | + spip_unlink('test'); |
|
| 61 | + } |
|
| 62 | + $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 63 | + |
|
| 64 | + return $ok ? $chmod : false; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // |
@@ -71,84 +71,84 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | function install_etape_chmod_dist() { |
| 73 | 73 | |
| 74 | - $continuer = null; |
|
| 75 | - $test_dir = _request('test_dir'); |
|
| 76 | - $chmod = 0; |
|
| 77 | - |
|
| 78 | - if ($test_dir and strpos($test_dir, '..') === false) { |
|
| 79 | - if (substr($test_dir, -1) !== '/') { |
|
| 80 | - $test_dir .= '/'; |
|
| 81 | - } |
|
| 82 | - if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 83 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | - } |
|
| 85 | - } else { |
|
| 86 | - if (!_FILE_CONNECT) { |
|
| 87 | - $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 88 | - $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $bad_dirs = []; |
|
| 93 | - $absent_dirs = []; |
|
| 94 | - |
|
| 95 | - foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 96 | - $test = test_ecrire($my_dir); |
|
| 97 | - if (!$test) { |
|
| 98 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | - if (@file_exists($my_dir)) { |
|
| 100 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | - } else { |
|
| 102 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $chmod = max($chmod, $test); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($bad_dirs or $absent_dirs) { |
|
| 110 | - if (!_FILE_CONNECT) { |
|
| 111 | - $titre = _T('dirs_preliminaire'); |
|
| 112 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | - } else { |
|
| 114 | - $titre = _T('dirs_probleme_droits'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | - |
|
| 120 | - if ($bad_dirs) { |
|
| 121 | - $res .= |
|
| 122 | - _T( |
|
| 123 | - 'dirs_repertoires_suivants', |
|
| 124 | - ['bad_dirs' => join("\n", array_keys($bad_dirs))] |
|
| 125 | - ) . |
|
| 126 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($absent_dirs) { |
|
| 130 | - $res .= |
|
| 131 | - _T( |
|
| 132 | - 'dirs_repertoires_absents', |
|
| 133 | - ['bad_dirs' => join("\n", array_keys($absent_dirs))] |
|
| 134 | - ) . |
|
| 135 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 136 | - } |
|
| 137 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | - |
|
| 139 | - $t = _T('login_recharger'); |
|
| 140 | - $t = (!$test_dir ? '' : |
|
| 141 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 142 | - . "<input type='hidden' name='etape' value='chmod' />" |
|
| 143 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 144 | - |
|
| 145 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 146 | - } else { |
|
| 147 | - $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 148 | - if (!$deja) { |
|
| 149 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 150 | - } else { |
|
| 151 | - redirige_url_ecrire(); |
|
| 152 | - } |
|
| 153 | - } |
|
| 74 | + $continuer = null; |
|
| 75 | + $test_dir = _request('test_dir'); |
|
| 76 | + $chmod = 0; |
|
| 77 | + |
|
| 78 | + if ($test_dir and strpos($test_dir, '..') === false) { |
|
| 79 | + if (substr($test_dir, -1) !== '/') { |
|
| 80 | + $test_dir .= '/'; |
|
| 81 | + } |
|
| 82 | + if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 83 | + $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | + } |
|
| 85 | + } else { |
|
| 86 | + if (!_FILE_CONNECT) { |
|
| 87 | + $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 88 | + $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $bad_dirs = []; |
|
| 93 | + $absent_dirs = []; |
|
| 94 | + |
|
| 95 | + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 96 | + $test = test_ecrire($my_dir); |
|
| 97 | + if (!$test) { |
|
| 98 | + $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | + if (@file_exists($my_dir)) { |
|
| 100 | + $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | + } else { |
|
| 102 | + $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $chmod = max($chmod, $test); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($bad_dirs or $absent_dirs) { |
|
| 110 | + if (!_FILE_CONNECT) { |
|
| 111 | + $titre = _T('dirs_preliminaire'); |
|
| 112 | + $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | + } else { |
|
| 114 | + $titre = _T('dirs_probleme_droits'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | + |
|
| 120 | + if ($bad_dirs) { |
|
| 121 | + $res .= |
|
| 122 | + _T( |
|
| 123 | + 'dirs_repertoires_suivants', |
|
| 124 | + ['bad_dirs' => join("\n", array_keys($bad_dirs))] |
|
| 125 | + ) . |
|
| 126 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($absent_dirs) { |
|
| 130 | + $res .= |
|
| 131 | + _T( |
|
| 132 | + 'dirs_repertoires_absents', |
|
| 133 | + ['bad_dirs' => join("\n", array_keys($absent_dirs))] |
|
| 134 | + ) . |
|
| 135 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 136 | + } |
|
| 137 | + $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | + |
|
| 139 | + $t = _T('login_recharger'); |
|
| 140 | + $t = (!$test_dir ? '' : |
|
| 141 | + "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 142 | + . "<input type='hidden' name='etape' value='chmod' />" |
|
| 143 | + . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 144 | + |
|
| 145 | + echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 146 | + } else { |
|
| 147 | + $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 148 | + if (!$deja) { |
|
| 149 | + redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 150 | + } else { |
|
| 151 | + redirige_url_ecrire(); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -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 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define( |
|
| 65 | - '_BALISES_BLOCS', |
|
| 66 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | - ); |
|
| 64 | + define( |
|
| 65 | + '_BALISES_BLOCS', |
|
| 66 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 71 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -79,106 +79,106 @@ discard block |
||
| 79 | 79 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 80 | 80 | // echappe est un div ou un span |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ''; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ''; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | // Echapper les <html>...</ html> |
| 106 | 106 | function traiter_echap_html_dist($regs) { |
| 107 | - return $regs[3]; |
|
| 107 | + return $regs[3]; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Echapper les <pre>...</ pre> |
| 111 | 111 | function traiter_echap_pre_dist($regs) { |
| 112 | - // echapper les <code> dans <pre> |
|
| 113 | - $pre = $regs[3]; |
|
| 114 | - |
|
| 115 | - // echapper les < dans <code> |
|
| 116 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | - if ( |
|
| 118 | - strpos($pre, '<') !== false |
|
| 119 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | - ) { |
|
| 121 | - foreach ($matches as $m) { |
|
| 122 | - if ($m[1] === 'code') { |
|
| 123 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | - $pre = str_replace($m[0], $code, $pre); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return "<pre>$pre</pre>"; |
|
| 112 | + // echapper les <code> dans <pre> |
|
| 113 | + $pre = $regs[3]; |
|
| 114 | + |
|
| 115 | + // echapper les < dans <code> |
|
| 116 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | + if ( |
|
| 118 | + strpos($pre, '<') !== false |
|
| 119 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | + ) { |
|
| 121 | + foreach ($matches as $m) { |
|
| 122 | + if ($m[1] === 'code') { |
|
| 123 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | + $pre = str_replace($m[0], $code, $pre); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return "<pre>$pre</pre>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Echapper les <code>...</ code> |
| 132 | 132 | function traiter_echap_code_dist($regs) { |
| 133 | - [, , $att, $corps] = $regs; |
|
| 134 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | - |
|
| 136 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | - if (is_int(strpos($echap, "\n"))) { |
|
| 138 | - // supprimer les sauts de ligne debut/fin |
|
| 139 | - // (mais pas les espaces => ascii art). |
|
| 140 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | - $echap = nl2br($echap); |
|
| 142 | - $echap = "<div style='text-align: left;' " |
|
| 143 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | - . $echap . '</code></div>'; |
|
| 145 | - } else { |
|
| 146 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $echap = str_replace("\t", ' ', $echap); |
|
| 150 | - $echap = str_replace(' ', ' ', $echap); |
|
| 151 | - |
|
| 152 | - return $echap; |
|
| 133 | + [, , $att, $corps] = $regs; |
|
| 134 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | + |
|
| 136 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | + if (is_int(strpos($echap, "\n"))) { |
|
| 138 | + // supprimer les sauts de ligne debut/fin |
|
| 139 | + // (mais pas les espaces => ascii art). |
|
| 140 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | + $echap = nl2br($echap); |
|
| 142 | + $echap = "<div style='text-align: left;' " |
|
| 143 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | + . $echap . '</code></div>'; |
|
| 145 | + } else { |
|
| 146 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $echap = str_replace("\t", ' ', $echap); |
|
| 150 | + $echap = str_replace(' ', ' ', $echap); |
|
| 151 | + |
|
| 152 | + return $echap; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 156 | 156 | function traiter_echap_cadre_dist($regs) { |
| 157 | - $echap = trim(entites_html($regs[3])); |
|
| 158 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | - $lignes = explode("\n", trim($echap)); |
|
| 160 | - $n = 0; |
|
| 161 | - foreach ($lignes as $l) { |
|
| 162 | - $n += floor(strlen($l) / 60) + 1; |
|
| 163 | - } |
|
| 164 | - $n = max($n, 2); |
|
| 165 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | - |
|
| 167 | - return $echap; |
|
| 157 | + $echap = trim(entites_html($regs[3])); |
|
| 158 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | + $lignes = explode("\n", trim($echap)); |
|
| 160 | + $n = 0; |
|
| 161 | + foreach ($lignes as $l) { |
|
| 162 | + $n += floor(strlen($l) / 60) + 1; |
|
| 163 | + } |
|
| 164 | + $n = max($n, 2); |
|
| 165 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | + |
|
| 167 | + return $echap; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function traiter_echap_frame_dist($regs) { |
| 171 | - return traiter_echap_cadre_dist($regs); |
|
| 171 | + return traiter_echap_cadre_dist($regs); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function traiter_echap_script_dist($regs) { |
| 175 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | - return highlight_string($regs[0], true); |
|
| 178 | - } |
|
| 175 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | + return highlight_string($regs[0], true); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // Cas normal : le script passe tel quel |
|
| 181 | - return $regs[0]; |
|
| 180 | + // Cas normal : le script passe tel quel |
|
| 181 | + return $regs[0]; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -196,67 +196,67 @@ discard block |
||
| 196 | 196 | * @return string|string[] |
| 197 | 197 | */ |
| 198 | 198 | function echappe_html( |
| 199 | - $letexte, |
|
| 200 | - $source = '', |
|
| 201 | - $no_transform = false, |
|
| 202 | - $preg = '', |
|
| 203 | - $callback_prefix = '' |
|
| 199 | + $letexte, |
|
| 200 | + $source = '', |
|
| 201 | + $no_transform = false, |
|
| 202 | + $preg = '', |
|
| 203 | + $callback_prefix = '' |
|
| 204 | 204 | ) { |
| 205 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 206 | - return $letexte; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ( |
|
| 210 | - ($preg or strpos($letexte, '<') !== false) |
|
| 211 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 212 | - ) { |
|
| 213 | - foreach ($matches as $regs) { |
|
| 214 | - // echappements tels quels ? |
|
| 215 | - if ($no_transform) { |
|
| 216 | - $echap = $regs[0]; |
|
| 217 | - } // sinon les traiter selon le cas |
|
| 218 | - else { |
|
| 219 | - if ( |
|
| 220 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 221 | - or function_exists($f = $f . '_dist') |
|
| 222 | - ) { |
|
| 223 | - $echap = $f($regs); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 228 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ($no_transform) { |
|
| 233 | - return $letexte; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 237 | - // seulement si on a echappe les <script> |
|
| 238 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 239 | - // dans une callback autonommee |
|
| 240 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 241 | - if ( |
|
| 242 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 243 | - ',<[?].*($|[?]>),UisS', |
|
| 244 | - $letexte, |
|
| 245 | - $matches, |
|
| 246 | - PREG_SET_ORDER |
|
| 247 | - ) |
|
| 248 | - ) { |
|
| 249 | - foreach ($matches as $regs) { |
|
| 250 | - $letexte = str_replace( |
|
| 251 | - $regs[0], |
|
| 252 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 253 | - $letexte |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $letexte; |
|
| 205 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 206 | + return $letexte; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ( |
|
| 210 | + ($preg or strpos($letexte, '<') !== false) |
|
| 211 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 212 | + ) { |
|
| 213 | + foreach ($matches as $regs) { |
|
| 214 | + // echappements tels quels ? |
|
| 215 | + if ($no_transform) { |
|
| 216 | + $echap = $regs[0]; |
|
| 217 | + } // sinon les traiter selon le cas |
|
| 218 | + else { |
|
| 219 | + if ( |
|
| 220 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 221 | + or function_exists($f = $f . '_dist') |
|
| 222 | + ) { |
|
| 223 | + $echap = $f($regs); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 228 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ($no_transform) { |
|
| 233 | + return $letexte; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 237 | + // seulement si on a echappe les <script> |
|
| 238 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 239 | + // dans une callback autonommee |
|
| 240 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 241 | + if ( |
|
| 242 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 243 | + ',<[?].*($|[?]>),UisS', |
|
| 244 | + $letexte, |
|
| 245 | + $matches, |
|
| 246 | + PREG_SET_ORDER |
|
| 247 | + ) |
|
| 248 | + ) { |
|
| 249 | + foreach ($matches as $regs) { |
|
| 250 | + $letexte = str_replace( |
|
| 251 | + $regs[0], |
|
| 252 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 253 | + $letexte |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $letexte; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // |
@@ -264,57 +264,57 @@ discard block |
||
| 264 | 264 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 265 | 265 | // par propre() : exemple dans multi et dans typo() |
| 266 | 266 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 267 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 268 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 269 | - $max_prof = 5; |
|
| 270 | - while ( |
|
| 271 | - strpos($letexte, '<') !== false |
|
| 272 | - and |
|
| 273 | - preg_match_all( |
|
| 274 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 275 | - $letexte, |
|
| 276 | - $regs, |
|
| 277 | - PREG_SET_ORDER |
|
| 278 | - ) |
|
| 279 | - and $max_prof-- |
|
| 280 | - ) { |
|
| 281 | - foreach ($regs as $reg) { |
|
| 282 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 283 | - // recherche d'attributs supplementaires |
|
| 284 | - $at = []; |
|
| 285 | - foreach (['lang', 'dir'] as $attr) { |
|
| 286 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 287 | - $at[$attr] = $a; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - if ($at) { |
|
| 291 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 292 | - foreach ($at as $attr => $a) { |
|
| 293 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if ($filtre) { |
|
| 297 | - $rempl = $filtre($rempl); |
|
| 298 | - } |
|
| 299 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $letexte; |
|
| 267 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 268 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 269 | + $max_prof = 5; |
|
| 270 | + while ( |
|
| 271 | + strpos($letexte, '<') !== false |
|
| 272 | + and |
|
| 273 | + preg_match_all( |
|
| 274 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 275 | + $letexte, |
|
| 276 | + $regs, |
|
| 277 | + PREG_SET_ORDER |
|
| 278 | + ) |
|
| 279 | + and $max_prof-- |
|
| 280 | + ) { |
|
| 281 | + foreach ($regs as $reg) { |
|
| 282 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 283 | + // recherche d'attributs supplementaires |
|
| 284 | + $at = []; |
|
| 285 | + foreach (['lang', 'dir'] as $attr) { |
|
| 286 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 287 | + $at[$attr] = $a; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + if ($at) { |
|
| 291 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 292 | + foreach ($at as $attr => $a) { |
|
| 293 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if ($filtre) { |
|
| 297 | + $rempl = $filtre($rempl); |
|
| 298 | + } |
|
| 299 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $letexte; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Reinserer le javascript de confiance (venant des modeles) |
| 308 | 308 | |
| 309 | 309 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 310 | - $letexte = echappe_retour($letexte); |
|
| 310 | + $letexte = echappe_retour($letexte); |
|
| 311 | 311 | |
| 312 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 313 | - if ($interdire_scripts) { |
|
| 314 | - $letexte = interdire_scripts($letexte); |
|
| 315 | - } |
|
| 312 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 313 | + if ($interdire_scripts) { |
|
| 314 | + $letexte = interdire_scripts($letexte); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - return trim($letexte); |
|
| 317 | + return trim($letexte); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -342,131 +342,131 @@ discard block |
||
| 342 | 342 | * Texte coupé |
| 343 | 343 | **/ |
| 344 | 344 | function couper($texte, $taille = 50, $suite = null) { |
| 345 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 346 | - return ''; |
|
| 347 | - } |
|
| 348 | - $offset = 400 + 2 * $taille; |
|
| 349 | - while ( |
|
| 350 | - $offset < $length |
|
| 351 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 352 | - ) { |
|
| 353 | - $offset = 2 * $offset; |
|
| 354 | - } |
|
| 355 | - if ( |
|
| 356 | - $offset < $length |
|
| 357 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 358 | - ) { |
|
| 359 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 360 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 361 | - $offset = $p_tag_fermant + 1; |
|
| 362 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 363 | - } |
|
| 364 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 365 | - |
|
| 366 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 367 | - include_spip('inc/lien'); |
|
| 368 | - } |
|
| 369 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 370 | - |
|
| 371 | - // balises de sauts de ligne et paragraphe |
|
| 372 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 373 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 374 | - |
|
| 375 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 376 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 377 | - |
|
| 378 | - // supprimer les tags |
|
| 379 | - $texte = supprimer_tags($texte); |
|
| 380 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 381 | - $texte .= "\n"; // marquer la fin |
|
| 382 | - |
|
| 383 | - // corriger la longueur de coupe |
|
| 384 | - // en fonction de la presence de caracteres utf |
|
| 385 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 386 | - $long = charset2unicode($texte); |
|
| 387 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 388 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 389 | - $taille += $nbcharutf; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - // couper au mot precedent |
|
| 394 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 395 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 396 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 397 | - if (is_null($suite)) { |
|
| 398 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 399 | - } |
|
| 400 | - $points = $suite; |
|
| 401 | - |
|
| 402 | - // trop court ? ne pas faire de (...) |
|
| 403 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 404 | - $points = ''; |
|
| 405 | - $long = spip_substr($texte, 0, $taille); |
|
| 406 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 407 | - // encore trop court ? couper au caractere |
|
| 408 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 409 | - $texte = $long; |
|
| 410 | - } |
|
| 411 | - } else { |
|
| 412 | - $texte = $court; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 416 | - $points = ''; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // remettre les paragraphes |
|
| 420 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 421 | - |
|
| 422 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 423 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 424 | - |
|
| 425 | - return quote_amp(trim($texte)) . $points; |
|
| 345 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 346 | + return ''; |
|
| 347 | + } |
|
| 348 | + $offset = 400 + 2 * $taille; |
|
| 349 | + while ( |
|
| 350 | + $offset < $length |
|
| 351 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 352 | + ) { |
|
| 353 | + $offset = 2 * $offset; |
|
| 354 | + } |
|
| 355 | + if ( |
|
| 356 | + $offset < $length |
|
| 357 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 358 | + ) { |
|
| 359 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 360 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 361 | + $offset = $p_tag_fermant + 1; |
|
| 362 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 363 | + } |
|
| 364 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 365 | + |
|
| 366 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 367 | + include_spip('inc/lien'); |
|
| 368 | + } |
|
| 369 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 370 | + |
|
| 371 | + // balises de sauts de ligne et paragraphe |
|
| 372 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 373 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 374 | + |
|
| 375 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 376 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 377 | + |
|
| 378 | + // supprimer les tags |
|
| 379 | + $texte = supprimer_tags($texte); |
|
| 380 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 381 | + $texte .= "\n"; // marquer la fin |
|
| 382 | + |
|
| 383 | + // corriger la longueur de coupe |
|
| 384 | + // en fonction de la presence de caracteres utf |
|
| 385 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 386 | + $long = charset2unicode($texte); |
|
| 387 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 388 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 389 | + $taille += $nbcharutf; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + // couper au mot precedent |
|
| 394 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 395 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 396 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 397 | + if (is_null($suite)) { |
|
| 398 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 399 | + } |
|
| 400 | + $points = $suite; |
|
| 401 | + |
|
| 402 | + // trop court ? ne pas faire de (...) |
|
| 403 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 404 | + $points = ''; |
|
| 405 | + $long = spip_substr($texte, 0, $taille); |
|
| 406 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 407 | + // encore trop court ? couper au caractere |
|
| 408 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 409 | + $texte = $long; |
|
| 410 | + } |
|
| 411 | + } else { |
|
| 412 | + $texte = $court; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 416 | + $points = ''; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // remettre les paragraphes |
|
| 420 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 421 | + |
|
| 422 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 423 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 424 | + |
|
| 425 | + return quote_amp(trim($texte)) . $points; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
| 429 | 429 | function protege_js_modeles($t) { |
| 430 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 431 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 432 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 433 | - include_spip('inc/acces'); |
|
| 434 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 435 | - } |
|
| 436 | - foreach ($r as $regs) { |
|
| 437 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 441 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 442 | - include_spip('inc/acces'); |
|
| 443 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 444 | - } |
|
| 445 | - foreach ($r as $regs) { |
|
| 446 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return $t; |
|
| 430 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 431 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 432 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 433 | + include_spip('inc/acces'); |
|
| 434 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 435 | + } |
|
| 436 | + foreach ($r as $regs) { |
|
| 437 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 441 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 442 | + include_spip('inc/acces'); |
|
| 443 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 444 | + } |
|
| 445 | + foreach ($r as $regs) { |
|
| 446 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return $t; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
| 455 | 455 | function echapper_faux_tags($letexte) { |
| 456 | - if (strpos($letexte, '<') === false) { |
|
| 457 | - return $letexte; |
|
| 458 | - } |
|
| 459 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 460 | - |
|
| 461 | - $letexte = ''; |
|
| 462 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 463 | - // un texte a echapper |
|
| 464 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 465 | - // un tag html qui a servit a faite le split |
|
| 466 | - $letexte .= array_shift($textMatches); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return $letexte; |
|
| 456 | + if (strpos($letexte, '<') === false) { |
|
| 457 | + return $letexte; |
|
| 458 | + } |
|
| 459 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 460 | + |
|
| 461 | + $letexte = ''; |
|
| 462 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 463 | + // un texte a echapper |
|
| 464 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 465 | + // un tag html qui a servit a faite le split |
|
| 466 | + $letexte .= array_shift($textMatches); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return $letexte; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -479,47 +479,47 @@ discard block |
||
| 479 | 479 | * @return string |
| 480 | 480 | */ |
| 481 | 481 | function echapper_html_suspect($texte, $strict = true) { |
| 482 | - static $echapper_html_suspect; |
|
| 483 | - if (!$texte or !is_string($texte)) { |
|
| 484 | - return $texte; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - if (!isset($echapper_html_suspect)) { |
|
| 488 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 489 | - } |
|
| 490 | - // si fonction personalisee, on delegue |
|
| 491 | - if ($echapper_html_suspect) { |
|
| 492 | - return $echapper_html_suspect($texte, $strict); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ( |
|
| 496 | - strpos($texte, '<') === false |
|
| 497 | - or strpos($texte, '=') === false |
|
| 498 | - ) { |
|
| 499 | - return $texte; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 503 | - // car sinon on declenche sur les modeles ou ressources |
|
| 504 | - if ( |
|
| 505 | - !$strict and |
|
| 506 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 507 | - ) { |
|
| 508 | - return $texte; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 512 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 513 | - // donc un test d'egalite est trop strict |
|
| 514 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 515 | - $texte = str_replace('<', '<', $texte); |
|
| 516 | - if (!function_exists('attribut_html')) { |
|
| 517 | - include_spip('inc/filtres'); |
|
| 518 | - } |
|
| 519 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - return $texte; |
|
| 482 | + static $echapper_html_suspect; |
|
| 483 | + if (!$texte or !is_string($texte)) { |
|
| 484 | + return $texte; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + if (!isset($echapper_html_suspect)) { |
|
| 488 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 489 | + } |
|
| 490 | + // si fonction personalisee, on delegue |
|
| 491 | + if ($echapper_html_suspect) { |
|
| 492 | + return $echapper_html_suspect($texte, $strict); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ( |
|
| 496 | + strpos($texte, '<') === false |
|
| 497 | + or strpos($texte, '=') === false |
|
| 498 | + ) { |
|
| 499 | + return $texte; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 503 | + // car sinon on declenche sur les modeles ou ressources |
|
| 504 | + if ( |
|
| 505 | + !$strict and |
|
| 506 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 507 | + ) { |
|
| 508 | + return $texte; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 512 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 513 | + // donc un test d'egalite est trop strict |
|
| 514 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 515 | + $texte = str_replace('<', '<', $texte); |
|
| 516 | + if (!function_exists('attribut_html')) { |
|
| 517 | + include_spip('inc/filtres'); |
|
| 518 | + } |
|
| 519 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + return $texte; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | |
@@ -540,30 +540,30 @@ discard block |
||
| 540 | 540 | * Texte sécurisé |
| 541 | 541 | **/ |
| 542 | 542 | function safehtml($t) { |
| 543 | - static $safehtml; |
|
| 544 | - |
|
| 545 | - if (!$t or !is_string($t)) { |
|
| 546 | - return $t; |
|
| 547 | - } |
|
| 548 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 549 | - if (strpos($t, '<') === false) { |
|
| 550 | - return str_replace("\x00", '', $t); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if (!function_exists('interdire_scripts')) { |
|
| 554 | - include_spip('inc/texte'); |
|
| 555 | - } |
|
| 556 | - $t = interdire_scripts($t); // jolifier le php |
|
| 557 | - $t = echappe_js($t); |
|
| 558 | - |
|
| 559 | - if (!isset($safehtml)) { |
|
| 560 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 561 | - } |
|
| 562 | - if ($safehtml) { |
|
| 563 | - $t = $safehtml($t); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 543 | + static $safehtml; |
|
| 544 | + |
|
| 545 | + if (!$t or !is_string($t)) { |
|
| 546 | + return $t; |
|
| 547 | + } |
|
| 548 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 549 | + if (strpos($t, '<') === false) { |
|
| 550 | + return str_replace("\x00", '', $t); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if (!function_exists('interdire_scripts')) { |
|
| 554 | + include_spip('inc/texte'); |
|
| 555 | + } |
|
| 556 | + $t = interdire_scripts($t); // jolifier le php |
|
| 557 | + $t = echappe_js($t); |
|
| 558 | + |
|
| 559 | + if (!isset($safehtml)) { |
|
| 560 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 561 | + } |
|
| 562 | + if ($safehtml) { |
|
| 563 | + $t = $safehtml($t); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | |
@@ -585,13 +585,13 @@ discard block |
||
| 585 | 585 | * Texte sans les modèles d'image |
| 586 | 586 | **/ |
| 587 | 587 | function supprime_img($letexte, $message = null) { |
| 588 | - if ($message === null) { |
|
| 589 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - return preg_replace( |
|
| 593 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 594 | - $message, |
|
| 595 | - $letexte |
|
| 596 | - ); |
|
| 588 | + if ($message === null) { |
|
| 589 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + return preg_replace( |
|
| 593 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 594 | + $message, |
|
| 595 | + $letexte |
|
| 596 | + ); |
|
| 597 | 597 | } |
@@ -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 | |
@@ -52,68 +52,68 @@ discard block |
||
| 52 | 52 | * cookie sécurisé ou non ? |
| 53 | 53 | **/ |
| 54 | 54 | function spip_setcookie($name = '', $value = '', $options = []) { |
| 55 | - static $to_secure_list = ['spip_session']; |
|
| 56 | - if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | - $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!is_array($options)) { |
|
| 61 | - // anciens paramètres : |
|
| 62 | - # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $opt = func_get_args(); |
|
| 64 | - $opt = array_slice($opt, 2); |
|
| 65 | - $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | - if (isset($opt[0])) { |
|
| 67 | - $options['expires'] = $opt[0]; |
|
| 68 | - } |
|
| 69 | - if (isset($opt[1])) { |
|
| 70 | - $options['path'] = $opt[1]; |
|
| 71 | - } |
|
| 72 | - if (isset($opt[2])) { |
|
| 73 | - $options['domain'] = $opt[2]; |
|
| 74 | - } |
|
| 75 | - if (isset($opt[3])) { |
|
| 76 | - $options['secure'] = $opt[3]; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // expires |
|
| 81 | - if (!isset($options['expires'])) { |
|
| 82 | - $options['expires'] = 0; |
|
| 83 | - } |
|
| 84 | - if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | - if (defined('_COOKIE_PATH')) { |
|
| 86 | - $options['path'] = _COOKIE_PATH; |
|
| 87 | - } else { |
|
| 88 | - $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | - $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | - } |
|
| 94 | - if (in_array($name, $to_secure_list)) { |
|
| 95 | - if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | - $options['secure'] = true; |
|
| 97 | - } |
|
| 98 | - if (empty($options['httponly'])) { |
|
| 99 | - $options['httponly'] = true; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - if (empty($options['samesite'])) { |
|
| 103 | - $options['samesite'] = 'Lax'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // in fine renommer le prefixe si besoin |
|
| 107 | - if (strpos($name, 'spip_') === 0) { |
|
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | - $a = @setcookie($name, $value, $options); |
|
| 113 | - |
|
| 114 | - spip_cookie_envoye(true); |
|
| 115 | - |
|
| 116 | - return $a; |
|
| 55 | + static $to_secure_list = ['spip_session']; |
|
| 56 | + if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | + $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!is_array($options)) { |
|
| 61 | + // anciens paramètres : |
|
| 62 | + # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $opt = func_get_args(); |
|
| 64 | + $opt = array_slice($opt, 2); |
|
| 65 | + $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | + if (isset($opt[0])) { |
|
| 67 | + $options['expires'] = $opt[0]; |
|
| 68 | + } |
|
| 69 | + if (isset($opt[1])) { |
|
| 70 | + $options['path'] = $opt[1]; |
|
| 71 | + } |
|
| 72 | + if (isset($opt[2])) { |
|
| 73 | + $options['domain'] = $opt[2]; |
|
| 74 | + } |
|
| 75 | + if (isset($opt[3])) { |
|
| 76 | + $options['secure'] = $opt[3]; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // expires |
|
| 81 | + if (!isset($options['expires'])) { |
|
| 82 | + $options['expires'] = 0; |
|
| 83 | + } |
|
| 84 | + if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | + if (defined('_COOKIE_PATH')) { |
|
| 86 | + $options['path'] = _COOKIE_PATH; |
|
| 87 | + } else { |
|
| 88 | + $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | + $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | + } |
|
| 94 | + if (in_array($name, $to_secure_list)) { |
|
| 95 | + if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | + $options['secure'] = true; |
|
| 97 | + } |
|
| 98 | + if (empty($options['httponly'])) { |
|
| 99 | + $options['httponly'] = true; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + if (empty($options['samesite'])) { |
|
| 103 | + $options['samesite'] = 'Lax'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // in fine renommer le prefixe si besoin |
|
| 107 | + if (strpos($name, 'spip_') === 0) { |
|
| 108 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | + $a = @setcookie($name, $value, $options); |
|
| 113 | + |
|
| 114 | + spip_cookie_envoye(true); |
|
| 115 | + |
|
| 116 | + return $a; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @return bool |
| 130 | 130 | **/ |
| 131 | 131 | function spip_cookie_envoye($set = '') { |
| 132 | - static $envoye = false; |
|
| 133 | - if ($set) { |
|
| 134 | - $envoye = true; |
|
| 135 | - } |
|
| 132 | + static $envoye = false; |
|
| 133 | + if ($set) { |
|
| 134 | + $envoye = true; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $envoye; |
|
| 137 | + return $envoye; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * Préfixe des cookies de SPIP |
| 154 | 154 | **/ |
| 155 | 155 | function recuperer_cookies_spip($cookie_prefix) { |
| 156 | - $prefix_long = strlen($cookie_prefix); |
|
| 157 | - |
|
| 158 | - foreach ($_COOKIE as $name => $value) { |
|
| 159 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | - unset($_COOKIE[$name]); |
|
| 161 | - unset($GLOBALS[$name]); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - foreach ($_COOKIE as $name => $value) { |
|
| 165 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | - $_COOKIE[$spipname] = $value; |
|
| 168 | - $GLOBALS[$spipname] = $value; |
|
| 169 | - } |
|
| 170 | - } |
|
| 156 | + $prefix_long = strlen($cookie_prefix); |
|
| 157 | + |
|
| 158 | + foreach ($_COOKIE as $name => $value) { |
|
| 159 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | + unset($_COOKIE[$name]); |
|
| 161 | + unset($GLOBALS[$name]); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + foreach ($_COOKIE as $name => $value) { |
|
| 165 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | + $_COOKIE[$spipname] = $value; |
|
| 168 | + $GLOBALS[$spipname] = $value; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | **/ |
| 188 | 188 | function exec_test_ajax_dist() { |
| 189 | - switch (_request('js')) { |
|
| 190 | - // on est appele par <noscript> |
|
| 191 | - case -1: |
|
| 192 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | - include_spip('inc/headers'); |
|
| 194 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | - break; |
|
| 196 | - |
|
| 197 | - // ou par ajax |
|
| 198 | - case 1: |
|
| 199 | - default: |
|
| 200 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | - break; |
|
| 202 | - } |
|
| 189 | + switch (_request('js')) { |
|
| 190 | + // on est appele par <noscript> |
|
| 191 | + case -1: |
|
| 192 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | + include_spip('inc/headers'); |
|
| 194 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | + break; |
|
| 196 | + |
|
| 197 | + // ou par ajax |
|
| 198 | + case 1: |
|
| 199 | + default: |
|
| 200 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | + break; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -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,29 +280,29 @@ discard block |
||
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | 282 | function afficher_qui_edite($id_objet, $objet): string { |
| 283 | - static $qui = []; |
|
| 284 | - if (isset($qui[$objet][$id_objet])) { |
|
| 285 | - return $qui[$objet][$id_objet]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - include_spip('inc/config'); |
|
| 289 | - if (lire_config('articles_modif', 'non') === 'non') { |
|
| 290 | - return $qui[$objet][$id_objet] = ''; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - include_spip('inc/drapeau_edition'); |
|
| 294 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 295 | - if (!$modif) { |
|
| 296 | - return $qui[$objet][$id_objet] = ''; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - include_spip('base/objets'); |
|
| 300 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 301 | - if (isset($infos['texte_signale_edition'])) { |
|
| 302 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - 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 | + include_spip('inc/config'); |
|
| 289 | + if (lire_config('articles_modif', 'non') === 'non') { |
|
| 290 | + return $qui[$objet][$id_objet] = ''; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + include_spip('inc/drapeau_edition'); |
|
| 294 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 295 | + if (!$modif) { |
|
| 296 | + return $qui[$objet][$id_objet] = ''; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + include_spip('base/objets'); |
|
| 300 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 301 | + if (isset($infos['texte_signale_edition'])) { |
|
| 302 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -320,53 +320,53 @@ discard block |
||
| 320 | 320 | * @return array |
| 321 | 321 | */ |
| 322 | 322 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array { |
| 323 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 324 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - switch ($quoi) { |
|
| 328 | - case 'redacteurs': |
|
| 329 | - $statut = AUTEURS_MIN_REDAC; |
|
| 330 | - $statut = explode(',', $statut); |
|
| 331 | - if ($en_base) { |
|
| 332 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 333 | - $retire = array_diff($statut, $check); |
|
| 334 | - $statut = array_diff($statut, $retire); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return array_unique($statut); |
|
| 338 | - |
|
| 339 | - case 'visiteurs': |
|
| 340 | - $statut = []; |
|
| 341 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 342 | - $exclus = explode(',', $exclus); |
|
| 343 | - if (!$en_base) { |
|
| 344 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 345 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 346 | - } |
|
| 347 | - $s_complement = array_column( |
|
| 348 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 349 | - 'statut' |
|
| 350 | - ); |
|
| 351 | - |
|
| 352 | - return array_unique(array_merge($statut, $s_complement)); |
|
| 353 | - |
|
| 354 | - default: |
|
| 355 | - case 'tous': |
|
| 356 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 357 | - $s_complement = array_column( |
|
| 358 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 359 | - 'statut' |
|
| 360 | - ); |
|
| 361 | - $statut = array_merge($statut, $s_complement); |
|
| 362 | - if ($en_base) { |
|
| 363 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 364 | - $retire = array_diff($statut, $check); |
|
| 365 | - $statut = array_diff($statut, $retire); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return array_unique($statut); |
|
| 369 | - } |
|
| 323 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 324 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + switch ($quoi) { |
|
| 328 | + case 'redacteurs': |
|
| 329 | + $statut = AUTEURS_MIN_REDAC; |
|
| 330 | + $statut = explode(',', $statut); |
|
| 331 | + if ($en_base) { |
|
| 332 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 333 | + $retire = array_diff($statut, $check); |
|
| 334 | + $statut = array_diff($statut, $retire); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return array_unique($statut); |
|
| 338 | + |
|
| 339 | + case 'visiteurs': |
|
| 340 | + $statut = []; |
|
| 341 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 342 | + $exclus = explode(',', $exclus); |
|
| 343 | + if (!$en_base) { |
|
| 344 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 345 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 346 | + } |
|
| 347 | + $s_complement = array_column( |
|
| 348 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 349 | + 'statut' |
|
| 350 | + ); |
|
| 351 | + |
|
| 352 | + return array_unique(array_merge($statut, $s_complement)); |
|
| 353 | + |
|
| 354 | + default: |
|
| 355 | + case 'tous': |
|
| 356 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 357 | + $s_complement = array_column( |
|
| 358 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 359 | + 'statut' |
|
| 360 | + ); |
|
| 361 | + $statut = array_merge($statut, $s_complement); |
|
| 362 | + if ($en_base) { |
|
| 363 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 364 | + $retire = array_diff($statut, $check); |
|
| 365 | + $statut = array_diff($statut, $retire); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return array_unique($statut); |
|
| 369 | + } |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -382,28 +382,28 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 384 | 384 | |
| 385 | - if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 386 | - $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 387 | - ? '' |
|
| 388 | - : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 389 | - |
|
| 390 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 391 | - if ($objet == 'rubrique') { |
|
| 392 | - $id_rubrique = 0; |
|
| 393 | - } else { |
|
| 394 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 398 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 399 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 400 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 401 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return $id_rubrique; |
|
| 385 | + if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 386 | + $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 387 | + ? '' |
|
| 388 | + : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 389 | + |
|
| 390 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 391 | + if ($objet == 'rubrique') { |
|
| 392 | + $id_rubrique = 0; |
|
| 393 | + } else { |
|
| 394 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 398 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 399 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 400 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 401 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return $id_rubrique; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -414,12 +414,12 @@ discard block |
||
| 414 | 414 | * @return string |
| 415 | 415 | */ |
| 416 | 416 | function lien_article_virtuel($virtuel) { |
| 417 | - include_spip('inc/lien'); |
|
| 418 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 419 | - return ''; |
|
| 420 | - } |
|
| 417 | + include_spip('inc/lien'); |
|
| 418 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 419 | + return ''; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - return propre('[->' . $virtuel . ']'); |
|
| 422 | + return propre('[->' . $virtuel . ']'); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -442,11 +442,11 @@ discard block |
||
| 442 | 442 | * @filtre |
| 443 | 443 | */ |
| 444 | 444 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 445 | - include_spip('inc/acces'); |
|
| 446 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 445 | + include_spip('inc/acces'); |
|
| 446 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 447 | 447 | |
| 448 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 449 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 448 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 449 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -458,76 +458,76 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | function alertes_auteur($id_auteur): string { |
| 460 | 460 | |
| 461 | - $alertes = []; |
|
| 462 | - |
|
| 463 | - if ( |
|
| 464 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 465 | - and autoriser('detruire', null, null, $id_auteur) |
|
| 466 | - ) { |
|
| 467 | - include_spip('genie/maintenance'); |
|
| 468 | - if ($msg = message_crash_tables()) { |
|
| 469 | - $alertes[] = $msg; |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - if ( |
|
| 474 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 475 | - and $GLOBALS['meta']['message_crash_plugins'] |
|
| 476 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 477 | - and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 478 | - ) { |
|
| 479 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 480 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 484 | - if ( |
|
| 485 | - $a |
|
| 486 | - and is_array($a = unserialize($a)) |
|
| 487 | - and count($a) |
|
| 488 | - ) { |
|
| 489 | - $update = false; |
|
| 490 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 491 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 492 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 493 | - $update = true; |
|
| 494 | - } |
|
| 495 | - if (isset($a[''])) { |
|
| 496 | - $alertes = array_merge($alertes, $a['']); |
|
| 497 | - unset($a['']); |
|
| 498 | - $update = true; |
|
| 499 | - } |
|
| 500 | - if ($update) { |
|
| 501 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - if ( |
|
| 506 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 507 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 508 | - ) { |
|
| 509 | - include_spip('inc/plugin'); |
|
| 510 | - $alertes[] = plugin_donne_erreurs(); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $alertes = pipeline( |
|
| 514 | - 'alertes_auteur', |
|
| 515 | - [ |
|
| 516 | - 'args' => [ |
|
| 517 | - 'id_auteur' => $id_auteur, |
|
| 518 | - 'exec' => _request('exec'), |
|
| 519 | - ], |
|
| 520 | - 'data' => $alertes |
|
| 521 | - ] |
|
| 522 | - ); |
|
| 523 | - |
|
| 524 | - if ($alertes = array_filter($alertes)) { |
|
| 525 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 526 | - join(' | ', $alertes) |
|
| 527 | - . '</div></div>'; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return ''; |
|
| 461 | + $alertes = []; |
|
| 462 | + |
|
| 463 | + if ( |
|
| 464 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 465 | + and autoriser('detruire', null, null, $id_auteur) |
|
| 466 | + ) { |
|
| 467 | + include_spip('genie/maintenance'); |
|
| 468 | + if ($msg = message_crash_tables()) { |
|
| 469 | + $alertes[] = $msg; |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + if ( |
|
| 474 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 475 | + and $GLOBALS['meta']['message_crash_plugins'] |
|
| 476 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 477 | + and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 478 | + ) { |
|
| 479 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 480 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 484 | + if ( |
|
| 485 | + $a |
|
| 486 | + and is_array($a = unserialize($a)) |
|
| 487 | + and count($a) |
|
| 488 | + ) { |
|
| 489 | + $update = false; |
|
| 490 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 491 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 492 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 493 | + $update = true; |
|
| 494 | + } |
|
| 495 | + if (isset($a[''])) { |
|
| 496 | + $alertes = array_merge($alertes, $a['']); |
|
| 497 | + unset($a['']); |
|
| 498 | + $update = true; |
|
| 499 | + } |
|
| 500 | + if ($update) { |
|
| 501 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + if ( |
|
| 506 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 507 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 508 | + ) { |
|
| 509 | + include_spip('inc/plugin'); |
|
| 510 | + $alertes[] = plugin_donne_erreurs(); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + $alertes = pipeline( |
|
| 514 | + 'alertes_auteur', |
|
| 515 | + [ |
|
| 516 | + 'args' => [ |
|
| 517 | + 'id_auteur' => $id_auteur, |
|
| 518 | + 'exec' => _request('exec'), |
|
| 519 | + ], |
|
| 520 | + 'data' => $alertes |
|
| 521 | + ] |
|
| 522 | + ); |
|
| 523 | + |
|
| 524 | + if ($alertes = array_filter($alertes)) { |
|
| 525 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 526 | + join(' | ', $alertes) |
|
| 527 | + . '</div></div>'; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return ''; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | /** |
@@ -537,9 +537,9 @@ discard block |
||
| 537 | 537 | * @return string |
| 538 | 538 | */ |
| 539 | 539 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 540 | - include_spip('inc/presenter_enfants'); |
|
| 540 | + include_spip('inc/presenter_enfants'); |
|
| 541 | 541 | |
| 542 | - return afficher_enfant_rub(intval($id_rubrique)); |
|
| 542 | + return afficher_enfant_rub(intval($id_rubrique)); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -557,15 +557,15 @@ discard block |
||
| 557 | 557 | * @return string |
| 558 | 558 | */ |
| 559 | 559 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 560 | - $titre = attribut_html($titre); |
|
| 561 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 562 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 563 | - |
|
| 564 | - if (!$titre_lien) { |
|
| 565 | - return $icone; |
|
| 566 | - } else { |
|
| 567 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 568 | - } |
|
| 560 | + $titre = attribut_html($titre); |
|
| 561 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 562 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 563 | + |
|
| 564 | + if (!$titre_lien) { |
|
| 565 | + return $icone; |
|
| 566 | + } else { |
|
| 567 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 568 | + } |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -584,22 +584,22 @@ discard block |
||
| 584 | 584 | * @return array |
| 585 | 585 | */ |
| 586 | 586 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 587 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 588 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 589 | - return []; |
|
| 590 | - } |
|
| 591 | - $r = reset($res); |
|
| 592 | - if (isset($r['rang_lien'])) { |
|
| 593 | - $l = array_column($res, 'rang_lien', $objet_source); |
|
| 594 | - asort($l); |
|
| 595 | - $l = array_keys($l); |
|
| 596 | - } else { |
|
| 597 | - // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 598 | - // Sinon c'est dans "id_objet" |
|
| 599 | - $l = array_column( |
|
| 600 | - $res, |
|
| 601 | - $objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet' |
|
| 602 | - ); |
|
| 603 | - } |
|
| 604 | - return $l; |
|
| 587 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 588 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 589 | + return []; |
|
| 590 | + } |
|
| 591 | + $r = reset($res); |
|
| 592 | + if (isset($r['rang_lien'])) { |
|
| 593 | + $l = array_column($res, 'rang_lien', $objet_source); |
|
| 594 | + asort($l); |
|
| 595 | + $l = array_keys($l); |
|
| 596 | + } else { |
|
| 597 | + // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 598 | + // Sinon c'est dans "id_objet" |
|
| 599 | + $l = array_column( |
|
| 600 | + $res, |
|
| 601 | + $objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet' |
|
| 602 | + ); |
|
| 603 | + } |
|
| 604 | + return $l; |
|
| 605 | 605 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return string Code HTML |
| 26 | 26 | */ |
| 27 | 27 | function debut_grand_cadre() { |
| 28 | - return "\n<div class = 'table_page'>\n"; |
|
| 28 | + return "\n<div class = 'table_page'>\n"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return string Code HTML |
| 35 | 35 | */ |
| 36 | 36 | function fin_grand_cadre() { |
| 37 | - return "\n</div>"; |
|
| 37 | + return "\n</div>"; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Debut de la colonne de gauche |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string Code HTML |
| 50 | 50 | */ |
| 51 | 51 | function debut_gauche() { |
| 52 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string Code HTML |
| 59 | 59 | */ |
| 60 | 60 | function fin_gauche() { |
| 61 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string Code HTML |
| 68 | 68 | */ |
| 69 | 69 | function creer_colonne_droite() { |
| 70 | - static $deja_colonne_droite; |
|
| 71 | - if ($deja_colonne_droite) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 74 | - $deja_colonne_droite = true; |
|
| 70 | + static $deja_colonne_droite; |
|
| 71 | + if ($deja_colonne_droite) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | + $deja_colonne_droite = true; |
|
| 75 | 75 | |
| 76 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string Code HTML |
| 83 | 83 | */ |
| 84 | 84 | function debut_droite() { |
| 85 | - return liste_objets_bloques(_request('exec')) |
|
| 86 | - . creer_colonne_droite() |
|
| 87 | - . '</div>' |
|
| 88 | - . "\n<div id='contenu'>"; |
|
| 85 | + return liste_objets_bloques(_request('exec')) |
|
| 86 | + . creer_colonne_droite() |
|
| 87 | + . '</div>' |
|
| 88 | + . "\n<div id='contenu'>"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | * Code HTML |
| 108 | 108 | **/ |
| 109 | 109 | function liste_objets_bloques($exec, $contexte = [], $auteur = null): string { |
| 110 | - $res = ''; |
|
| 111 | - include_spip('inc/config'); |
|
| 112 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 113 | - include_spip('inc/drapeau_edition'); |
|
| 114 | - if (is_null($auteur)) { |
|
| 115 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 116 | - } |
|
| 117 | - if ( |
|
| 118 | - $en_cours = trouver_objet_exec($exec) |
|
| 119 | - and $en_cours['edition'] |
|
| 120 | - and $type = $en_cours['type'] |
|
| 121 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 122 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 123 | - ) { |
|
| 124 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 125 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 126 | - signale_edition($id, $auteur, $type); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 130 | - if (count($objets_ouverts)) { |
|
| 131 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $res; |
|
| 110 | + $res = ''; |
|
| 111 | + include_spip('inc/config'); |
|
| 112 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 113 | + include_spip('inc/drapeau_edition'); |
|
| 114 | + if (is_null($auteur)) { |
|
| 115 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 116 | + } |
|
| 117 | + if ( |
|
| 118 | + $en_cours = trouver_objet_exec($exec) |
|
| 119 | + and $en_cours['edition'] |
|
| 120 | + and $type = $en_cours['type'] |
|
| 121 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 122 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 123 | + ) { |
|
| 124 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 125 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 126 | + signale_edition($id, $auteur, $type); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 130 | + if (count($objets_ouverts)) { |
|
| 131 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $res; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | * @return string Code HTML |
| 147 | 147 | **/ |
| 148 | 148 | function fin_page() { |
| 149 | - include_spip('inc/pipelines'); |
|
| 150 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 151 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 152 | - and ((_request('var_mode') == 'debug') |
|
| 153 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 154 | - and isset($_COOKIE['spip_admin']))); |
|
| 155 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 156 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 157 | - . '</div>' |
|
| 158 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 159 | - . ($debug ? erreur_squelette() : '') |
|
| 160 | - . "</body></html>\n"; |
|
| 161 | - |
|
| 162 | - return f_queue($t); |
|
| 149 | + include_spip('inc/pipelines'); |
|
| 150 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 151 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 152 | + and ((_request('var_mode') == 'debug') |
|
| 153 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 154 | + and isset($_COOKIE['spip_admin']))); |
|
| 155 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 156 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 157 | + . '</div>' |
|
| 158 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 159 | + . ($debug ? erreur_squelette() : '') |
|
| 160 | + . "</body></html>\n"; |
|
| 161 | + |
|
| 162 | + return f_queue($t); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -174,22 +174,22 @@ discard block |
||
| 174 | 174 | * @return string Code HTML |
| 175 | 175 | **/ |
| 176 | 176 | function html_tests_js() { |
| 177 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 178 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 179 | - define( |
|
| 180 | - '_TESTER_NOSCRIPT', |
|
| 181 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 182 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 183 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 184 | - ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $rejouer = ''; |
|
| 188 | - if (defined('_SESSION_REJOUER')) { |
|
| 189 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 177 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 178 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 179 | + define( |
|
| 180 | + '_TESTER_NOSCRIPT', |
|
| 181 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 182 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 183 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 184 | + ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $rejouer = ''; |
|
| 188 | + if (defined('_SESSION_REJOUER')) { |
|
| 189 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -199,25 +199,25 @@ discard block |
||
| 199 | 199 | **/ |
| 200 | 200 | function info_maj_spip() { |
| 201 | 201 | |
| 202 | - $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 203 | - if (!$maj) { |
|
| 204 | - return ''; |
|
| 205 | - } |
|
| 202 | + $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 203 | + if (!$maj) { |
|
| 204 | + return ''; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $maj = explode('|', $maj); |
|
| 208 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 209 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 210 | - return ''; |
|
| 211 | - } |
|
| 207 | + $maj = explode('|', $maj); |
|
| 208 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 209 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 210 | + return ''; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - if (!autoriser('webmestre')) { |
|
| 214 | - return ''; |
|
| 215 | - } |
|
| 213 | + if (!autoriser('webmestre')) { |
|
| 214 | + return ''; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - array_shift($maj); |
|
| 218 | - $maj = implode('|', $maj); |
|
| 217 | + array_shift($maj); |
|
| 218 | + $maj = implode('|', $maj); |
|
| 219 | 219 | |
| 220 | - return "$maj<br />"; |
|
| 220 | + return "$maj<br />"; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -228,47 +228,47 @@ discard block |
||
| 228 | 228 | **/ |
| 229 | 229 | function info_copyright() { |
| 230 | 230 | |
| 231 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 232 | - |
|
| 233 | - // |
|
| 234 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 235 | - // |
|
| 236 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 237 | - if ($vcs['vcs'] === 'GIT') { |
|
| 238 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 239 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 240 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 241 | - } else { |
|
| 242 | - $url = ''; |
|
| 243 | - } |
|
| 244 | - // affichage "GIT [master: abcdef]" |
|
| 245 | - $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 246 | - if ($url) { |
|
| 247 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 248 | - } |
|
| 249 | - if ($vcs['branch']) { |
|
| 250 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 251 | - } |
|
| 252 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // et la version de l'ecran de securite |
|
| 256 | - $secu = defined('_ECRAN_SECURITE') |
|
| 257 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 258 | - : ''; |
|
| 259 | - |
|
| 260 | - return _T( |
|
| 261 | - 'info_copyright', |
|
| 262 | - [ |
|
| 263 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 264 | - 'lien_gpl' => |
|
| 265 | - "<a href='" . generer_url_ecrire( |
|
| 266 | - 'aide', |
|
| 267 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 268 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 269 | - ] |
|
| 270 | - ) |
|
| 271 | - . $secu; |
|
| 231 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 232 | + |
|
| 233 | + // |
|
| 234 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 235 | + // |
|
| 236 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 237 | + if ($vcs['vcs'] === 'GIT') { |
|
| 238 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 239 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 240 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 241 | + } else { |
|
| 242 | + $url = ''; |
|
| 243 | + } |
|
| 244 | + // affichage "GIT [master: abcdef]" |
|
| 245 | + $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 246 | + if ($url) { |
|
| 247 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 248 | + } |
|
| 249 | + if ($vcs['branch']) { |
|
| 250 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 251 | + } |
|
| 252 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // et la version de l'ecran de securite |
|
| 256 | + $secu = defined('_ECRAN_SECURITE') |
|
| 257 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 258 | + : ''; |
|
| 259 | + |
|
| 260 | + return _T( |
|
| 261 | + 'info_copyright', |
|
| 262 | + [ |
|
| 263 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 264 | + 'lien_gpl' => |
|
| 265 | + "<a href='" . generer_url_ecrire( |
|
| 266 | + 'aide', |
|
| 267 | + 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 268 | + ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 269 | + ] |
|
| 270 | + ) |
|
| 271 | + . $secu; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -283,17 +283,17 @@ discard block |
||
| 283 | 283 | * @return string Code HTML |
| 284 | 284 | **/ |
| 285 | 285 | function formulaire_recherche($page, $complement = '') { |
| 286 | - $recherche = _request('recherche'); |
|
| 287 | - $recherche_aff = entites_html($recherche); |
|
| 288 | - if (!strlen($recherche)) { |
|
| 289 | - $recherche_aff = _T('info_rechercher'); |
|
| 290 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 291 | - } else { |
|
| 292 | - $onfocus = ''; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 296 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 297 | - |
|
| 298 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 286 | + $recherche = _request('recherche'); |
|
| 287 | + $recherche_aff = entites_html($recherche); |
|
| 288 | + if (!strlen($recherche)) { |
|
| 289 | + $recherche_aff = _T('info_rechercher'); |
|
| 290 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 291 | + } else { |
|
| 292 | + $onfocus = ''; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 296 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 297 | + |
|
| 298 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 299 | 299 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Formulaires |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/filtres'); |
@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | * Saisie protégée |
| 36 | 36 | **/ |
| 37 | 37 | function protege_champ($texte) { |
| 38 | - if (is_array($texte)) { |
|
| 39 | - return array_map('protege_champ', $texte); |
|
| 40 | - } elseif ($texte === null) { |
|
| 41 | - return $texte; |
|
| 42 | - } elseif (is_bool($texte)) { |
|
| 43 | - return $texte ? '1' : ''; |
|
| 44 | - } elseif (is_string($texte) and $texte) { |
|
| 45 | - if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | - // ne pas corrompre une valeur serialize |
|
| 47 | - return $texte; |
|
| 48 | - } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | - return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $texte; |
|
| 38 | + if (is_array($texte)) { |
|
| 39 | + return array_map('protege_champ', $texte); |
|
| 40 | + } elseif ($texte === null) { |
|
| 41 | + return $texte; |
|
| 42 | + } elseif (is_bool($texte)) { |
|
| 43 | + return $texte ? '1' : ''; |
|
| 44 | + } elseif (is_string($texte) and $texte) { |
|
| 45 | + if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | + // ne pas corrompre une valeur serialize |
|
| 47 | + return $texte; |
|
| 48 | + } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | + return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $texte; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * - false : pas de squelette trouvé |
| 65 | 65 | **/ |
| 66 | 66 | function existe_formulaire($form) { |
| 67 | - if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | - $form = strtolower(substr($form, 11)); |
|
| 69 | - } else { |
|
| 70 | - $form = strtolower($form); |
|
| 71 | - } |
|
| 67 | + if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | + $form = strtolower(substr($form, 11)); |
|
| 69 | + } else { |
|
| 70 | + $form = strtolower($form); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if (!$form) { |
|
| 74 | - return ''; |
|
| 75 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 73 | + if (!$form) { |
|
| 74 | + return ''; |
|
| 75 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 76 | 76 | |
| 77 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 77 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | * @return false|array |
| 84 | 84 | */ |
| 85 | 85 | function test_formulaire_inclus_par_modele() { |
| 86 | - $trace = debug_backtrace(0, 20); |
|
| 87 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | - |
|
| 90 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | - if ( |
|
| 92 | - function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | - and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | - ) { |
|
| 95 | - if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | - if ($trace[$k]['args'][0] === $form) { |
|
| 98 | - return $trace[$k]['args']; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | - if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | - return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | - } |
|
| 110 | - return false; |
|
| 86 | + $trace = debug_backtrace(0, 20); |
|
| 87 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | + |
|
| 90 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | + if ( |
|
| 92 | + function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | + and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | + ) { |
|
| 95 | + if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | + if ($trace[$k]['args'][0] === $form) { |
|
| 98 | + return $trace[$k]['args']; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | + if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | + } |
|
| 110 | + return false; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -122,32 +122,32 @@ discard block |
||
| 122 | 122 | **/ |
| 123 | 123 | function balise_FORMULAIRE__dist($p) { |
| 124 | 124 | |
| 125 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | - $p->code = "''"; |
|
| 129 | - $p->interdire_scripts = false; |
|
| 130 | - |
|
| 131 | - return $p; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // sinon renvoyer un code php dynamique |
|
| 135 | - $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 136 | - |
|
| 137 | - if ( |
|
| 138 | - !test_espace_prive() |
|
| 139 | - and !empty($p->descr['sourcefile']) |
|
| 140 | - and $f = $p->descr['sourcefile'] |
|
| 141 | - and basename(dirname($f)) === 'modeles' |
|
| 142 | - ) { |
|
| 143 | - // un modele est toujours inséré en texte dans son contenant |
|
| 144 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 145 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 146 | - // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 147 | - $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'"; |
|
| 148 | - // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave) |
|
| 149 | - } |
|
| 150 | - return $p; |
|
| 125 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | + $p->code = "''"; |
|
| 129 | + $p->interdire_scripts = false; |
|
| 130 | + |
|
| 131 | + return $p; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // sinon renvoyer un code php dynamique |
|
| 135 | + $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 136 | + |
|
| 137 | + if ( |
|
| 138 | + !test_espace_prive() |
|
| 139 | + and !empty($p->descr['sourcefile']) |
|
| 140 | + and $f = $p->descr['sourcefile'] |
|
| 141 | + and basename(dirname($f)) === 'modeles' |
|
| 142 | + ) { |
|
| 143 | + // un modele est toujours inséré en texte dans son contenant |
|
| 144 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 145 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 146 | + // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 147 | + $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'"; |
|
| 148 | + // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave) |
|
| 149 | + } |
|
| 150 | + return $p; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | * - string : texte à afficher directement |
| 168 | 168 | */ |
| 169 | 169 | function balise_FORMULAIRE__dyn($form, ...$args) { |
| 170 | - $form = existe_formulaire($form); |
|
| 171 | - if (!$form) { |
|
| 172 | - return ''; |
|
| 173 | - } |
|
| 170 | + $form = existe_formulaire($form); |
|
| 171 | + if (!$form) { |
|
| 172 | + return ''; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 176 | - if (!is_array($contexte)) { |
|
| 177 | - return $contexte; |
|
| 178 | - } |
|
| 175 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 176 | + if (!is_array($contexte)) { |
|
| 177 | + return $contexte; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - return ["formulaires/$form", 3600, $contexte]; |
|
| 180 | + return ["formulaires/$form", 3600, $contexte]; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -192,85 +192,85 @@ discard block |
||
| 192 | 192 | * string: Formulaire non applicable (message d’explication) |
| 193 | 193 | **/ |
| 194 | 194 | function balise_FORMULAIRE__contexte($form, $args) { |
| 195 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 196 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 197 | - // si poste, on recupere les erreurs |
|
| 198 | - |
|
| 199 | - $je_suis_poste = false; |
|
| 200 | - if ( |
|
| 201 | - $post_form = _request('formulaire_action') |
|
| 202 | - and $post_form == $form |
|
| 203 | - and $p = _request('formulaire_action_args') |
|
| 204 | - and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 205 | - ) { |
|
| 206 | - // enlever le faux attribut de langue masque |
|
| 207 | - array_shift($p); |
|
| 208 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 209 | - $je_suis_poste = true; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $editable = true; |
|
| 214 | - $erreurs = $post = []; |
|
| 215 | - if ($je_suis_poste) { |
|
| 216 | - $post = traiter_formulaires_dynamiques(true); |
|
| 217 | - $e = "erreurs_$form"; |
|
| 218 | - $erreurs = $post[$e] ?? []; |
|
| 219 | - $editable = "editable_$form"; |
|
| 220 | - $editable = (!isset($post[$e])) |
|
| 221 | - || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 222 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 226 | - |
|
| 227 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 228 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 229 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 230 | - if (!is_array($valeurs)) { |
|
| 231 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 235 | - // ou une action vide si elle ne sert pas |
|
| 236 | - $action = $valeurs['action'] ?? self('&', true); |
|
| 237 | - // bug IEx : si action finit par / |
|
| 238 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 239 | - if (substr($action, -1) == '/') { |
|
| 240 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 241 | - $action .= '#'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // recuperer la saisie en cours si erreurs |
|
| 245 | - // seulement si c'est ce formulaire qui est poste |
|
| 246 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 247 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 248 | - foreach (array_keys($valeurs) as $champ) { |
|
| 249 | - if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 250 | - if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 251 | - $valeurs[$champ] = $v; |
|
| 252 | - } |
|
| 253 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 254 | - if ($action) { |
|
| 255 | - $action = parametre_url($action, $champ, ''); |
|
| 256 | - } |
|
| 257 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 258 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($action) { |
|
| 263 | - // nettoyer l'url |
|
| 264 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 265 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 266 | - $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @deprecated 4.0 |
|
| 271 | - * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 272 | - */ |
|
| 273 | - /* |
|
| 195 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 196 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 197 | + // si poste, on recupere les erreurs |
|
| 198 | + |
|
| 199 | + $je_suis_poste = false; |
|
| 200 | + if ( |
|
| 201 | + $post_form = _request('formulaire_action') |
|
| 202 | + and $post_form == $form |
|
| 203 | + and $p = _request('formulaire_action_args') |
|
| 204 | + and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 205 | + ) { |
|
| 206 | + // enlever le faux attribut de langue masque |
|
| 207 | + array_shift($p); |
|
| 208 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 209 | + $je_suis_poste = true; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $editable = true; |
|
| 214 | + $erreurs = $post = []; |
|
| 215 | + if ($je_suis_poste) { |
|
| 216 | + $post = traiter_formulaires_dynamiques(true); |
|
| 217 | + $e = "erreurs_$form"; |
|
| 218 | + $erreurs = $post[$e] ?? []; |
|
| 219 | + $editable = "editable_$form"; |
|
| 220 | + $editable = (!isset($post[$e])) |
|
| 221 | + || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 222 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 226 | + |
|
| 227 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 228 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 229 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 230 | + if (!is_array($valeurs)) { |
|
| 231 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 235 | + // ou une action vide si elle ne sert pas |
|
| 236 | + $action = $valeurs['action'] ?? self('&', true); |
|
| 237 | + // bug IEx : si action finit par / |
|
| 238 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 239 | + if (substr($action, -1) == '/') { |
|
| 240 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 241 | + $action .= '#'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // recuperer la saisie en cours si erreurs |
|
| 245 | + // seulement si c'est ce formulaire qui est poste |
|
| 246 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 247 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 248 | + foreach (array_keys($valeurs) as $champ) { |
|
| 249 | + if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 250 | + if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 251 | + $valeurs[$champ] = $v; |
|
| 252 | + } |
|
| 253 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 254 | + if ($action) { |
|
| 255 | + $action = parametre_url($action, $champ, ''); |
|
| 256 | + } |
|
| 257 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 258 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($action) { |
|
| 263 | + // nettoyer l'url |
|
| 264 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 265 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 266 | + $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @deprecated 4.0 |
|
| 271 | + * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 272 | + */ |
|
| 273 | + /* |
|
| 274 | 274 | if (isset($valeurs['_action'])) { |
| 275 | 275 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 276 | 276 | $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
@@ -280,59 +280,59 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | */ |
| 282 | 282 | |
| 283 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 284 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 285 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 286 | - |
|
| 287 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 288 | - $valeurs['erreurs'] = $erreurs; |
|
| 289 | - $valeurs['action'] = $action; |
|
| 290 | - $valeurs['form'] = $form; |
|
| 291 | - |
|
| 292 | - $valeurs['formulaire_sign'] = ''; |
|
| 293 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 294 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 295 | - $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 296 | - $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - if (!isset($valeurs['id'])) { |
|
| 300 | - $valeurs['id'] = 'new'; |
|
| 301 | - } |
|
| 302 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 303 | - if (!isset($valeurs['editable'])) { |
|
| 304 | - $valeurs['editable'] = $editable; |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 307 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 308 | - |
|
| 309 | - if ($je_suis_poste) { |
|
| 310 | - $valeurs['message_erreur'] = ''; |
|
| 311 | - if (isset($erreurs['message_erreur'])) { |
|
| 312 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $valeurs['message_ok'] = ''; |
|
| 316 | - if (isset($post["message_ok_$form"])) { |
|
| 317 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 318 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 319 | - $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 323 | - // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 324 | - // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 325 | - if (html5_permis()) { |
|
| 326 | - foreach ($erreurs as $k => $v) { |
|
| 327 | - if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 328 | - // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 329 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $valeurs; |
|
| 283 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 284 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 285 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 286 | + |
|
| 287 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 288 | + $valeurs['erreurs'] = $erreurs; |
|
| 289 | + $valeurs['action'] = $action; |
|
| 290 | + $valeurs['form'] = $form; |
|
| 291 | + |
|
| 292 | + $valeurs['formulaire_sign'] = ''; |
|
| 293 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 294 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 295 | + $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 296 | + $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + if (!isset($valeurs['id'])) { |
|
| 300 | + $valeurs['id'] = 'new'; |
|
| 301 | + } |
|
| 302 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 303 | + if (!isset($valeurs['editable'])) { |
|
| 304 | + $valeurs['editable'] = $editable; |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 307 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 308 | + |
|
| 309 | + if ($je_suis_poste) { |
|
| 310 | + $valeurs['message_erreur'] = ''; |
|
| 311 | + if (isset($erreurs['message_erreur'])) { |
|
| 312 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $valeurs['message_ok'] = ''; |
|
| 316 | + if (isset($post["message_ok_$form"])) { |
|
| 317 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 318 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 319 | + $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 323 | + // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 324 | + // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 325 | + if (html5_permis()) { |
|
| 326 | + foreach ($erreurs as $k => $v) { |
|
| 327 | + if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 328 | + // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 329 | + $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $valeurs; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -344,51 +344,51 @@ discard block |
||
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | 346 | function formulaire__charger($form, $args, $poste) { |
| 347 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 348 | - $valeurs = $charger_valeurs(...$args); |
|
| 349 | - } else { |
|
| 350 | - $valeurs = []; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $valeurs = pipeline( |
|
| 354 | - 'formulaire_charger', |
|
| 355 | - [ |
|
| 356 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 357 | - 'data' => $valeurs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - // prise en charge CVT multi etape |
|
| 362 | - if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 363 | - include_spip('inc/cvt_multietapes'); |
|
| 364 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 365 | - ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 366 | - $valeurs |
|
| 367 | - ); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 371 | - if (is_array($valeurs)) { |
|
| 372 | - if (!isset($valeurs['_pipelines'])) { |
|
| 373 | - $valeurs['_pipelines'] = []; |
|
| 374 | - } |
|
| 375 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 376 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 377 | - if (isset($valeurs['_pipeline'])) { |
|
| 378 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 379 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 380 | - |
|
| 381 | - $pipelines = [$pipe => $args]; |
|
| 382 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 386 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 387 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 388 | - $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return $valeurs; |
|
| 347 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 348 | + $valeurs = $charger_valeurs(...$args); |
|
| 349 | + } else { |
|
| 350 | + $valeurs = []; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $valeurs = pipeline( |
|
| 354 | + 'formulaire_charger', |
|
| 355 | + [ |
|
| 356 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 357 | + 'data' => $valeurs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + // prise en charge CVT multi etape |
|
| 362 | + if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 363 | + include_spip('inc/cvt_multietapes'); |
|
| 364 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 365 | + ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 366 | + $valeurs |
|
| 367 | + ); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 371 | + if (is_array($valeurs)) { |
|
| 372 | + if (!isset($valeurs['_pipelines'])) { |
|
| 373 | + $valeurs['_pipelines'] = []; |
|
| 374 | + } |
|
| 375 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 376 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 377 | + if (isset($valeurs['_pipeline'])) { |
|
| 378 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 379 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 380 | + |
|
| 381 | + $pipelines = [$pipe => $args]; |
|
| 382 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 386 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 387 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 388 | + $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return $valeurs; |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -407,9 +407,9 @@ discard block |
||
| 407 | 407 | * @return bool |
| 408 | 408 | */ |
| 409 | 409 | function formulaire__identifier($form, $args, $p) { |
| 410 | - if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 411 | - return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 412 | - } |
|
| 410 | + if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 411 | + return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - return $args === $p; |
|
| 414 | + return $args === $p; |
|
| 415 | 415 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Fichier |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -36,28 +36,28 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream', $options = []) { |
| 38 | 38 | |
| 39 | - $defaut = [ |
|
| 40 | - 'attachment' => false, |
|
| 41 | - 'expires' => 3600, |
|
| 42 | - 'range' => null |
|
| 43 | - ]; |
|
| 44 | - $options = array_merge($defaut, $options); |
|
| 45 | - if (is_numeric($options['expires']) and $options['expires'] > 0) { |
|
| 46 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) { |
|
| 50 | - $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']); |
|
| 54 | - |
|
| 55 | - if (!is_null($options['range'])) { |
|
| 56 | - spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 57 | - } |
|
| 58 | - else { |
|
| 59 | - spip_livrer_fichier_entier($fichier); |
|
| 60 | - } |
|
| 39 | + $defaut = [ |
|
| 40 | + 'attachment' => false, |
|
| 41 | + 'expires' => 3600, |
|
| 42 | + 'range' => null |
|
| 43 | + ]; |
|
| 44 | + $options = array_merge($defaut, $options); |
|
| 45 | + if (is_numeric($options['expires']) and $options['expires'] > 0) { |
|
| 46 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) { |
|
| 50 | + $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']); |
|
| 54 | + |
|
| 55 | + if (!is_null($options['range'])) { |
|
| 56 | + spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 57 | + } |
|
| 58 | + else { |
|
| 59 | + spip_livrer_fichier_entier($fichier); |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -70,28 +70,28 @@ discard block |
||
| 70 | 70 | * @param int|string $expires |
| 71 | 71 | */ |
| 72 | 72 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 73 | - // toujours envoyer un content type, meme vide ! |
|
| 74 | - header('Accept-Ranges: bytes'); |
|
| 75 | - header('Content-Type: ' . $content_type); |
|
| 76 | - |
|
| 77 | - if ($attachment) { |
|
| 78 | - $f = basename($fichier); |
|
| 79 | - // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 80 | - header('Content-Type: application/octet-stream'); |
|
| 81 | - |
|
| 82 | - header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 83 | - header('Content-Transfer-Encoding: binary'); |
|
| 84 | - |
|
| 85 | - // fix for IE caching or PHP bug issue |
|
| 86 | - header('Expires: 0'); // set expiration time |
|
| 87 | - header('Pragma: public'); |
|
| 88 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 89 | - } |
|
| 90 | - else { |
|
| 91 | - $f = basename($fichier); |
|
| 92 | - header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 93 | - header('Expires: ' . $expires); // set expiration time |
|
| 94 | - } |
|
| 73 | + // toujours envoyer un content type, meme vide ! |
|
| 74 | + header('Accept-Ranges: bytes'); |
|
| 75 | + header('Content-Type: ' . $content_type); |
|
| 76 | + |
|
| 77 | + if ($attachment) { |
|
| 78 | + $f = basename($fichier); |
|
| 79 | + // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 80 | + header('Content-Type: application/octet-stream'); |
|
| 81 | + |
|
| 82 | + header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 83 | + header('Content-Transfer-Encoding: binary'); |
|
| 84 | + |
|
| 85 | + // fix for IE caching or PHP bug issue |
|
| 86 | + header('Expires: 0'); // set expiration time |
|
| 87 | + header('Pragma: public'); |
|
| 88 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 89 | + } |
|
| 90 | + else { |
|
| 91 | + $f = basename($fichier); |
|
| 92 | + header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 93 | + header('Expires: ' . $expires); // set expiration time |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -99,20 +99,20 @@ discard block |
||
| 99 | 99 | * @param string $fichier |
| 100 | 100 | */ |
| 101 | 101 | function spip_livrer_fichier_entier($fichier) { |
| 102 | - if (!file_exists($fichier)) { |
|
| 103 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 104 | - } |
|
| 102 | + if (!file_exists($fichier)) { |
|
| 103 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if (!is_readable($fichier)) { |
|
| 107 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 108 | - } |
|
| 106 | + if (!is_readable($fichier)) { |
|
| 107 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if ($size = filesize($fichier)) { |
|
| 111 | - header(sprintf('Content-Length: %d', $size)); |
|
| 112 | - } |
|
| 110 | + if ($size = filesize($fichier)) { |
|
| 111 | + header(sprintf('Content-Length: %d', $size)); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - readfile($fichier); |
|
| 115 | - exit(); |
|
| 114 | + readfile($fichier); |
|
| 115 | + exit(); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -125,98 +125,98 @@ discard block |
||
| 125 | 125 | * @throws Exception |
| 126 | 126 | */ |
| 127 | 127 | function spip_livrer_fichier_partie($fichier, $range = null) { |
| 128 | - if (!file_exists($fichier)) { |
|
| 129 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 130 | - } |
|
| 128 | + if (!file_exists($fichier)) { |
|
| 129 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (!is_readable($fichier)) { |
|
| 133 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 134 | - } |
|
| 132 | + if (!is_readable($fichier)) { |
|
| 133 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | - // Par defaut on envoie tout |
|
| 138 | - $byteOffset = 0; |
|
| 139 | - $byteLength = $fileSize = filesize($fichier); |
|
| 137 | + // Par defaut on envoie tout |
|
| 138 | + $byteOffset = 0; |
|
| 139 | + $byteLength = $fileSize = filesize($fichier); |
|
| 140 | 140 | |
| 141 | 141 | |
| 142 | - // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 143 | - if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 144 | - ### Offset signifies where we should begin to read the file |
|
| 145 | - $byteOffset = (int)$match[1]; |
|
| 142 | + // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 143 | + if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 144 | + ### Offset signifies where we should begin to read the file |
|
| 145 | + $byteOffset = (int)$match[1]; |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | - ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 149 | - if (isset($match[2])) { |
|
| 150 | - $finishBytes = (int)$match[2]; |
|
| 151 | - $byteLength = $finishBytes + 1; |
|
| 152 | - } else { |
|
| 153 | - $finishBytes = $fileSize - 1; |
|
| 154 | - } |
|
| 148 | + ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 149 | + if (isset($match[2])) { |
|
| 150 | + $finishBytes = (int)$match[2]; |
|
| 151 | + $byteLength = $finishBytes + 1; |
|
| 152 | + } else { |
|
| 153 | + $finishBytes = $fileSize - 1; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 157 | - } |
|
| 158 | - else { |
|
| 159 | - // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 160 | - spip_livrer_fichier_entier($fichier); |
|
| 161 | - // redondant, mais facilite la comprehension du code |
|
| 162 | - exit(); |
|
| 163 | - } |
|
| 156 | + $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 157 | + } |
|
| 158 | + else { |
|
| 159 | + // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 160 | + spip_livrer_fichier_entier($fichier); |
|
| 161 | + // redondant, mais facilite la comprehension du code |
|
| 162 | + exit(); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Remove headers that might unnecessarily clutter up the output |
|
| 166 | - header_remove('Cache-Control'); |
|
| 167 | - header_remove('Pragma'); |
|
| 165 | + // Remove headers that might unnecessarily clutter up the output |
|
| 166 | + header_remove('Cache-Control'); |
|
| 167 | + header_remove('Pragma'); |
|
| 168 | 168 | |
| 169 | - // partial content |
|
| 170 | - header('HTTP/1.1 206 Partial content'); |
|
| 171 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 169 | + // partial content |
|
| 170 | + header('HTTP/1.1 206 Partial content'); |
|
| 171 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - $byteRange = $byteLength - $byteOffset; |
|
| 174 | + $byteRange = $byteLength - $byteOffset; |
|
| 175 | 175 | |
| 176 | - header(sprintf('Content-Length: %d', $byteRange)); |
|
| 176 | + header(sprintf('Content-Length: %d', $byteRange)); |
|
| 177 | 177 | |
| 178 | - // Variable containing the buffer |
|
| 179 | - $buffer = ''; |
|
| 180 | - // Just a reasonable buffer size |
|
| 181 | - $bufferSize = 512 * 16; |
|
| 182 | - // Contains how much is left to read of the byteRange |
|
| 183 | - $bytePool = $byteRange; |
|
| 178 | + // Variable containing the buffer |
|
| 179 | + $buffer = ''; |
|
| 180 | + // Just a reasonable buffer size |
|
| 181 | + $bufferSize = 512 * 16; |
|
| 182 | + // Contains how much is left to read of the byteRange |
|
| 183 | + $bytePool = $byteRange; |
|
| 184 | 184 | |
| 185 | - if (!$handle = fopen($fichier, 'r')) { |
|
| 186 | - throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 187 | - } |
|
| 185 | + if (!$handle = fopen($fichier, 'r')) { |
|
| 186 | + throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 190 | - throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 191 | - } |
|
| 189 | + if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 190 | + throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - while ($bytePool > 0) { |
|
| 195 | - // How many bytes we request on this iteration |
|
| 196 | - $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 194 | + while ($bytePool > 0) { |
|
| 195 | + // How many bytes we request on this iteration |
|
| 196 | + $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 197 | 197 | |
| 198 | - // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 199 | - $buffer = fread($handle, $chunkSizeRequested); |
|
| 198 | + // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 199 | + $buffer = fread($handle, $chunkSizeRequested); |
|
| 200 | 200 | |
| 201 | - // Store how many bytes were actually read |
|
| 202 | - $chunkSizeActual = strlen($buffer); |
|
| 201 | + // Store how many bytes were actually read |
|
| 202 | + $chunkSizeActual = strlen($buffer); |
|
| 203 | 203 | |
| 204 | - // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 205 | - if ($chunkSizeActual == 0) { |
|
| 206 | - // For production servers this should go in your php error log, since it will break the output |
|
| 207 | - trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 208 | - break; |
|
| 209 | - } |
|
| 204 | + // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 205 | + if ($chunkSizeActual == 0) { |
|
| 206 | + // For production servers this should go in your php error log, since it will break the output |
|
| 207 | + trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 208 | + break; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 212 | - $bytePool -= $chunkSizeActual; |
|
| 211 | + // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 212 | + $bytePool -= $chunkSizeActual; |
|
| 213 | 213 | |
| 214 | - // Write the buffer to output |
|
| 215 | - print $buffer; |
|
| 214 | + // Write the buffer to output |
|
| 215 | + print $buffer; |
|
| 216 | 216 | |
| 217 | - // Try to output the data to the client immediately |
|
| 218 | - flush(); |
|
| 219 | - } |
|
| 217 | + // Try to output the data to the client immediately |
|
| 218 | + flush(); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - exit(); |
|
| 221 | + exit(); |
|
| 222 | 222 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 55 | - |
|
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - '&' |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - redirige_par_entete($redirect); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return [$id_rubrique, $err]; |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | + |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + '&' |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + redirige_par_entete($redirect); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return [$id_rubrique, $err]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -80,42 +80,42 @@ discard block |
||
| 80 | 80 | * Identifiant de la rubrique crée |
| 81 | 81 | */ |
| 82 | 82 | function rubrique_inserer($id_parent, $set = null) { |
| 83 | - $champs = [ |
|
| 84 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | - 'id_parent' => intval($id_parent), |
|
| 86 | - 'statut' => 'prepa' |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if ($set) { |
|
| 90 | - $champs = array_merge($champs, $set); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Envoyer aux plugins |
|
| 94 | - $champs = pipeline( |
|
| 95 | - 'pre_insertion', |
|
| 96 | - [ |
|
| 97 | - 'args' => [ |
|
| 98 | - 'table' => 'spip_rubriques', |
|
| 99 | - ], |
|
| 100 | - 'data' => $champs |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | - pipeline( |
|
| 106 | - 'post_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_rubriques', |
|
| 110 | - 'id_objet' => $id_rubrique |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - propager_les_secteurs(); |
|
| 116 | - calculer_langues_rubriques(); |
|
| 117 | - |
|
| 118 | - return $id_rubrique; |
|
| 83 | + $champs = [ |
|
| 84 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | + 'id_parent' => intval($id_parent), |
|
| 86 | + 'statut' => 'prepa' |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if ($set) { |
|
| 90 | + $champs = array_merge($champs, $set); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Envoyer aux plugins |
|
| 94 | + $champs = pipeline( |
|
| 95 | + 'pre_insertion', |
|
| 96 | + [ |
|
| 97 | + 'args' => [ |
|
| 98 | + 'table' => 'spip_rubriques', |
|
| 99 | + ], |
|
| 100 | + 'data' => $champs |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | + pipeline( |
|
| 106 | + 'post_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_rubriques', |
|
| 110 | + 'id_objet' => $id_rubrique |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + propager_les_secteurs(); |
|
| 116 | + calculer_langues_rubriques(); |
|
| 117 | + |
|
| 118 | + return $id_rubrique; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,46 +131,46 @@ discard block |
||
| 131 | 131 | * - chaîne : Texte d'un message d'erreur |
| 132 | 132 | */ |
| 133 | 133 | function rubrique_modifier($id_rubrique, $set = null) { |
| 134 | - include_spip('inc/autoriser'); |
|
| 135 | - include_spip('inc/filtres'); |
|
| 136 | - |
|
| 137 | - include_spip('inc/modifier'); |
|
| 138 | - $c = collecter_requests( |
|
| 139 | - // include list |
|
| 140 | - objet_info('rubrique', 'champs_editables'), |
|
| 141 | - // exclude list |
|
| 142 | - ['id_parent', 'confirme_deplace'], |
|
| 143 | - // donnees eventuellement fournies |
|
| 144 | - $set |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - if ( |
|
| 148 | - $err = objet_modifier_champs( |
|
| 149 | - 'rubrique', |
|
| 150 | - $id_rubrique, |
|
| 151 | - [ |
|
| 152 | - 'data' => $set, |
|
| 153 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | - ], |
|
| 155 | - $c |
|
| 156 | - ) |
|
| 157 | - ) { |
|
| 158 | - return $err; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | - // Deplacer la rubrique |
|
| 163 | - if (isset($c['id_parent'])) { |
|
| 164 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // invalider les caches marques de cette rubrique |
|
| 168 | - include_spip('inc/invalideur'); |
|
| 169 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | - // et celui de menu_rubriques |
|
| 171 | - effacer_meta('date_calcul_rubriques'); |
|
| 172 | - |
|
| 173 | - return $err; |
|
| 134 | + include_spip('inc/autoriser'); |
|
| 135 | + include_spip('inc/filtres'); |
|
| 136 | + |
|
| 137 | + include_spip('inc/modifier'); |
|
| 138 | + $c = collecter_requests( |
|
| 139 | + // include list |
|
| 140 | + objet_info('rubrique', 'champs_editables'), |
|
| 141 | + // exclude list |
|
| 142 | + ['id_parent', 'confirme_deplace'], |
|
| 143 | + // donnees eventuellement fournies |
|
| 144 | + $set |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + if ( |
|
| 148 | + $err = objet_modifier_champs( |
|
| 149 | + 'rubrique', |
|
| 150 | + $id_rubrique, |
|
| 151 | + [ |
|
| 152 | + 'data' => $set, |
|
| 153 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | + ], |
|
| 155 | + $c |
|
| 156 | + ) |
|
| 157 | + ) { |
|
| 158 | + return $err; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | + // Deplacer la rubrique |
|
| 163 | + if (isset($c['id_parent'])) { |
|
| 164 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // invalider les caches marques de cette rubrique |
|
| 168 | + include_spip('inc/invalideur'); |
|
| 169 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | + // et celui de menu_rubriques |
|
| 171 | + effacer_meta('date_calcul_rubriques'); |
|
| 172 | + |
|
| 173 | + return $err; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -193,25 +193,25 @@ discard block |
||
| 193 | 193 | * false si la confirmation du déplacement n'est pas présente |
| 194 | 194 | */ |
| 195 | 195 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 196 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ( |
|
| 205 | - $id_secteur = sql_getfetsel( |
|
| 206 | - 'id_secteur', |
|
| 207 | - 'spip_rubriques', |
|
| 208 | - "id_rubrique=$id_parent" |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return true; |
|
| 196 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ( |
|
| 205 | + $id_secteur = sql_getfetsel( |
|
| 206 | + 'id_secteur', |
|
| 207 | + 'spip_rubriques', |
|
| 208 | + "id_rubrique=$id_parent" |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return true; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -233,50 +233,50 @@ discard block |
||
| 233 | 233 | * Chaîne : Texte du message d'erreur |
| 234 | 234 | */ |
| 235 | 235 | function rubrique_instituer($id_rubrique, $c) { |
| 236 | - // traitement de la rubrique parente |
|
| 237 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | - // qu'on n'administre pas. |
|
| 239 | - |
|
| 240 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | - $id_parent = intval($id_parent); |
|
| 242 | - $filles = calcul_branche_in($id_rubrique); |
|
| 243 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | - } else { |
|
| 246 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | - $old_parent = $s['id_parent']; |
|
| 248 | - |
|
| 249 | - if ( |
|
| 250 | - !($id_parent != $old_parent |
|
| 251 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | - ) |
|
| 255 | - ) { |
|
| 256 | - if ($s['statut'] != 'prepa') { |
|
| 257 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | - } |
|
| 259 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | - $statut_ancien = $s['statut']; |
|
| 261 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - propager_les_secteurs(); |
|
| 265 | - |
|
| 266 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | - if ($statut_ancien == 'publie') { |
|
| 268 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 269 | - } |
|
| 270 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | - // invalider le cache de leur menu |
|
| 272 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | - effacer_meta('date_calcul_rubriques'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - calculer_langues_rubriques(); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return ''; // pas d'erreur |
|
| 236 | + // traitement de la rubrique parente |
|
| 237 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | + // qu'on n'administre pas. |
|
| 239 | + |
|
| 240 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | + $id_parent = intval($id_parent); |
|
| 242 | + $filles = calcul_branche_in($id_rubrique); |
|
| 243 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | + } else { |
|
| 246 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | + $old_parent = $s['id_parent']; |
|
| 248 | + |
|
| 249 | + if ( |
|
| 250 | + !($id_parent != $old_parent |
|
| 251 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | + ) |
|
| 255 | + ) { |
|
| 256 | + if ($s['statut'] != 'prepa') { |
|
| 257 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | + } |
|
| 259 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | + $statut_ancien = $s['statut']; |
|
| 261 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + propager_les_secteurs(); |
|
| 265 | + |
|
| 266 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | + if ($statut_ancien == 'publie') { |
|
| 268 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 269 | + } |
|
| 270 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | + // invalider le cache de leur menu |
|
| 272 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | + effacer_meta('date_calcul_rubriques'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + calculer_langues_rubriques(); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return ''; // pas d'erreur |
|
| 282 | 282 | } |
@@ -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 | |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte; |
|
| 46 | + $texte = '<' . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte; |
|
| 49 | 49 | |
| 50 | - ecrire_fichier($nom, $texte); |
|
| 50 | + ecrire_fichier($nom, $texte); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -76,20 +76,20 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | **/ |
| 78 | 78 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 79 | - $adr = addcslashes($adr, "'\\"); |
|
| 80 | - $port = addcslashes($port, "'\\"); |
|
| 81 | - $login = addcslashes($login, "'\\"); |
|
| 82 | - $pass = addcslashes($pass, "'\\"); |
|
| 83 | - $base = addcslashes($base, "'\\"); |
|
| 84 | - $type = addcslashes($type, "'\\"); |
|
| 85 | - $pref = addcslashes($pref, "'\\"); |
|
| 86 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 87 | - $charset = addcslashes($charset, "'\\"); |
|
| 88 | - |
|
| 89 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 90 | - . 'spip_connect_db(' |
|
| 91 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 92 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 79 | + $adr = addcslashes($adr, "'\\"); |
|
| 80 | + $port = addcslashes($port, "'\\"); |
|
| 81 | + $login = addcslashes($login, "'\\"); |
|
| 82 | + $pass = addcslashes($pass, "'\\"); |
|
| 83 | + $base = addcslashes($base, "'\\"); |
|
| 84 | + $type = addcslashes($type, "'\\"); |
|
| 85 | + $pref = addcslashes($pref, "'\\"); |
|
| 86 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 87 | + $charset = addcslashes($charset, "'\\"); |
|
| 88 | + |
|
| 89 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 90 | + . 'spip_connect_db(' |
|
| 91 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 92 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -105,29 +105,29 @@ discard block |
||
| 105 | 105 | * Tableau des informations sur la connexion |
| 106 | 106 | **/ |
| 107 | 107 | function analyse_fichier_connection(string $file): array { |
| 108 | - if (!file_exists($file)) { |
|
| 109 | - return []; |
|
| 110 | - } |
|
| 111 | - $s = file_get_contents($file); |
|
| 112 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 113 | - array_shift($regs); |
|
| 114 | - |
|
| 115 | - return $regs; |
|
| 116 | - } else { |
|
| 117 | - $ar = '\s*\'([^\']*)\''; |
|
| 118 | - $r = '\s*,' . $ar; |
|
| 119 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 120 | - if (preg_match($r, $s, $regs)) { |
|
| 121 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 122 | - array_shift($regs); |
|
| 123 | - array_shift($regs); |
|
| 124 | - |
|
| 125 | - return $regs; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 129 | - |
|
| 130 | - return []; |
|
| 108 | + if (!file_exists($file)) { |
|
| 109 | + return []; |
|
| 110 | + } |
|
| 111 | + $s = file_get_contents($file); |
|
| 112 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 113 | + array_shift($regs); |
|
| 114 | + |
|
| 115 | + return $regs; |
|
| 116 | + } else { |
|
| 117 | + $ar = '\s*\'([^\']*)\''; |
|
| 118 | + $r = '\s*,' . $ar; |
|
| 119 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 120 | + if (preg_match($r, $s, $regs)) { |
|
| 121 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 122 | + array_shift($regs); |
|
| 123 | + array_shift($regs); |
|
| 124 | + |
|
| 125 | + return $regs; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 129 | + |
|
| 130 | + return []; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -144,75 +144,75 @@ discard block |
||
| 144 | 144 | * Liste des noms de connecteurs |
| 145 | 145 | **/ |
| 146 | 146 | function bases_referencees($exclu = '') { |
| 147 | - $tables = []; |
|
| 148 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 149 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 150 | - $tables[] = basename($f, '.php'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $tables; |
|
| 147 | + $tables = []; |
|
| 148 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 149 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 150 | + $tables[] = basename($f, '.php'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $tables; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | function install_mode_appel($server_db, $tout = true) { |
| 159 | - return ($server_db != 'mysql') ? '' |
|
| 160 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 161 | - . test_sql_mode_mysql($server_db)); |
|
| 159 | + return ($server_db != 'mysql') ? '' |
|
| 160 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 161 | + . test_sql_mode_mysql($server_db)); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // |
| 165 | 165 | // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-) |
| 166 | 166 | // (sert a l'etape 1 de l'installation) |
| 167 | 167 | function tester_compatibilite_hebergement() { |
| 168 | - $err = []; |
|
| 169 | - |
|
| 170 | - $p = phpversion(); |
|
| 171 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 172 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 173 | - } |
|
| 174 | - if (version_compare($p, _PHP_MAX, '>')) { |
|
| 175 | - $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 179 | - if (!empty($diff)) { |
|
| 180 | - $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 184 | - if ($err) { |
|
| 185 | - die("<div class='error'>" |
|
| 186 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 187 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Il faut une base de donnees tout de meme ... |
|
| 191 | - $serveurs = install_select_serveur(); |
|
| 192 | - if (!$serveurs) { |
|
| 193 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 194 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 195 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 196 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 200 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 201 | - $err[] = _T('install_extension_mbstring') |
|
| 202 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if ($err) { |
|
| 206 | - echo "<div class='error'>" |
|
| 207 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 208 | - foreach ($err as $e) { |
|
| 209 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 213 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 214 | - echo "</ul></div>\n"; |
|
| 215 | - } |
|
| 168 | + $err = []; |
|
| 169 | + |
|
| 170 | + $p = phpversion(); |
|
| 171 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 172 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 173 | + } |
|
| 174 | + if (version_compare($p, _PHP_MAX, '>')) { |
|
| 175 | + $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 179 | + if (!empty($diff)) { |
|
| 180 | + $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 184 | + if ($err) { |
|
| 185 | + die("<div class='error'>" |
|
| 186 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 187 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Il faut une base de donnees tout de meme ... |
|
| 191 | + $serveurs = install_select_serveur(); |
|
| 192 | + if (!$serveurs) { |
|
| 193 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 194 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 195 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 196 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 200 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 201 | + $err[] = _T('install_extension_mbstring') |
|
| 202 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if ($err) { |
|
| 206 | + echo "<div class='error'>" |
|
| 207 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 208 | + foreach ($err as $e) { |
|
| 209 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 213 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 214 | + echo "</ul></div>\n"; |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @note superflu ?? |
| 223 | 223 | */ |
| 224 | 224 | function login_hebergeur() { |
| 225 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 225 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 226 | 226 | |
| 227 | - // Free |
|
| 228 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 229 | - $base_hebergeur = 'sql.free.fr'; |
|
| 230 | - $login_hebergeur = $regs[1]; |
|
| 231 | - } else { |
|
| 232 | - $login_hebergeur = ''; |
|
| 233 | - } |
|
| 227 | + // Free |
|
| 228 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 229 | + $base_hebergeur = 'sql.free.fr'; |
|
| 230 | + $login_hebergeur = $regs[1]; |
|
| 231 | + } else { |
|
| 232 | + $login_hebergeur = ''; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - return [$base_hebergeur, $login_hebergeur]; |
|
| 235 | + return [$base_hebergeur, $login_hebergeur]; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | function info_etape($titre, $complement = '') { |
| 240 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 241 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 240 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 241 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,154 +248,154 @@ discard block |
||
| 248 | 248 | * @return string Code HTML du bouton |
| 249 | 249 | **/ |
| 250 | 250 | function bouton_suivant($code = '') { |
| 251 | - if ($code == '') { |
|
| 252 | - $code = _T('bouton_suivant'); |
|
| 253 | - } |
|
| 254 | - static $suivant = 0; |
|
| 255 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 256 | - $suivant += 1; |
|
| 257 | - |
|
| 258 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 259 | - $code . |
|
| 260 | - " >>\" /></p>\n"; |
|
| 251 | + if ($code == '') { |
|
| 252 | + $code = _T('bouton_suivant'); |
|
| 253 | + } |
|
| 254 | + static $suivant = 0; |
|
| 255 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 256 | + $suivant += 1; |
|
| 257 | + |
|
| 258 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 259 | + $code . |
|
| 260 | + " >>\" /></p>\n"; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 264 | - $intitule_etat = []; |
|
| 265 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 266 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 267 | - $debut = 1; |
|
| 268 | - $etat = 'ok'; |
|
| 269 | - $last = count($liste); |
|
| 264 | + $intitule_etat = []; |
|
| 265 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 266 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 267 | + $debut = 1; |
|
| 268 | + $etat = 'ok'; |
|
| 269 | + $last = count($liste); |
|
| 270 | 270 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 271 | 271 | |
| 272 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 273 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 274 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 275 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 272 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 273 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 274 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 275 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 276 | 276 | |
| 277 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 278 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 279 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 280 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 281 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 277 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 278 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 279 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 280 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 281 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 282 | 282 | |
| 283 | 283 | // $aff_etapes = "<span id='etapes'>"; |
| 284 | 284 | |
| 285 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 286 | - |
|
| 287 | - foreach ($liste as $etape => $fichier) { |
|
| 288 | - if ($debut < $last) { |
|
| 289 | - if ($debut == $en_cours && $erreur) { |
|
| 290 | - $class = 'on erreur'; |
|
| 291 | - } else { |
|
| 292 | - if ($debut == $en_cours) { |
|
| 293 | - $class = 'on'; |
|
| 294 | - } else { |
|
| 295 | - if ($debut > $en_cours) { |
|
| 296 | - $class = 'prochains'; |
|
| 297 | - } else { |
|
| 298 | - $class = 'valides'; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 304 | - $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 305 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 306 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 307 | - $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 308 | - $aff_etapes .= '</div></li>'; |
|
| 309 | - } |
|
| 310 | - $debut++; |
|
| 311 | - } |
|
| 312 | - $aff_etapes .= '</ul>'; |
|
| 313 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 314 | - |
|
| 315 | - return $aff_etapes; |
|
| 285 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 286 | + |
|
| 287 | + foreach ($liste as $etape => $fichier) { |
|
| 288 | + if ($debut < $last) { |
|
| 289 | + if ($debut == $en_cours && $erreur) { |
|
| 290 | + $class = 'on erreur'; |
|
| 291 | + } else { |
|
| 292 | + if ($debut == $en_cours) { |
|
| 293 | + $class = 'on'; |
|
| 294 | + } else { |
|
| 295 | + if ($debut > $en_cours) { |
|
| 296 | + $class = 'prochains'; |
|
| 297 | + } else { |
|
| 298 | + $class = 'valides'; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 304 | + $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 305 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 306 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 307 | + $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 308 | + $aff_etapes .= '</div></li>'; |
|
| 309 | + } |
|
| 310 | + $debut++; |
|
| 311 | + } |
|
| 312 | + $aff_etapes .= '</ul>'; |
|
| 313 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 314 | + |
|
| 315 | + return $aff_etapes; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 320 | - return "<fieldset>\n" . |
|
| 321 | - $avant . |
|
| 322 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | - fieldset_champs($champs) . |
|
| 324 | - $apres . |
|
| 325 | - "</fieldset>\n"; |
|
| 320 | + return "<fieldset>\n" . |
|
| 321 | + $avant . |
|
| 322 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | + fieldset_champs($champs) . |
|
| 324 | + $apres . |
|
| 325 | + "</fieldset>\n"; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | function fieldset_champs($champs = []) { |
| 329 | - $fieldset = ''; |
|
| 330 | - foreach ($champs as $nom => $contenu) { |
|
| 331 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | - if (isset($contenu['alternatives'])) { |
|
| 334 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | - . "/>\n"; |
|
| 340 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | - } |
|
| 342 | - $fieldset .= "<br />\n"; |
|
| 343 | - } else { |
|
| 344 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | - . " />\n"; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return $fieldset; |
|
| 329 | + $fieldset = ''; |
|
| 330 | + foreach ($champs as $nom => $contenu) { |
|
| 331 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | + if (isset($contenu['alternatives'])) { |
|
| 334 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | + . "/>\n"; |
|
| 340 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | + } |
|
| 342 | + $fieldset .= "<br />\n"; |
|
| 343 | + } else { |
|
| 344 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | + . " />\n"; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return $fieldset; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | function install_select_serveur() { |
| 356 | - $options = []; |
|
| 357 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | - $d = opendir($dir); |
|
| 359 | - if (!$d) { |
|
| 360 | - return []; |
|
| 361 | - } |
|
| 362 | - while (($f = readdir($d)) !== false) { |
|
| 363 | - if ( |
|
| 364 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | - and is_readable($f = $dir . $f) |
|
| 366 | - ) { |
|
| 367 | - require_once($f); |
|
| 368 | - $s = $s[1]; |
|
| 369 | - $v = 'spip_versions_' . $s; |
|
| 370 | - if (function_exists($v) and $v()) { |
|
| 371 | - $titre = _T("install_select_type_$s"); |
|
| 372 | - // proposer mysql par defaut si dispo |
|
| 373 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | - } else { |
|
| 377 | - spip_log("$s: portage indisponible"); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - sort($options); |
|
| 382 | - |
|
| 383 | - return $options; |
|
| 356 | + $options = []; |
|
| 357 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | + $d = opendir($dir); |
|
| 359 | + if (!$d) { |
|
| 360 | + return []; |
|
| 361 | + } |
|
| 362 | + while (($f = readdir($d)) !== false) { |
|
| 363 | + if ( |
|
| 364 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | + and is_readable($f = $dir . $f) |
|
| 366 | + ) { |
|
| 367 | + require_once($f); |
|
| 368 | + $s = $s[1]; |
|
| 369 | + $v = 'spip_versions_' . $s; |
|
| 370 | + if (function_exists($v) and $v()) { |
|
| 371 | + $titre = _T("install_select_type_$s"); |
|
| 372 | + // proposer mysql par defaut si dispo |
|
| 373 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | + . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | + } else { |
|
| 377 | + spip_log("$s: portage indisponible"); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + sort($options); |
|
| 382 | + |
|
| 383 | + return $options; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 387 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | - |
|
| 389 | - return generer_form_ecrire('install', ( |
|
| 390 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | - . $hidden |
|
| 392 | - . (_request('echec') ? |
|
| 393 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | - : '') |
|
| 396 | - |
|
| 397 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | - . http_script(' |
|
| 387 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | + |
|
| 389 | + return generer_form_ecrire('install', ( |
|
| 390 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | + . $hidden |
|
| 392 | + . (_request('echec') ? |
|
| 393 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | + : '') |
|
| 396 | + |
|
| 397 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | + . http_script(' |
|
| 399 | 399 | jQuery(function($) { |
| 400 | 400 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 401 | 401 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -428,145 +428,145 @@ discard block |
||
| 428 | 428 | }); |
| 429 | 429 | });') |
| 430 | 430 | |
| 431 | - . ($server_db |
|
| 432 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | - . (($predef[0]) |
|
| 434 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | - : '') |
|
| 436 | - : ('<fieldset><legend>' |
|
| 437 | - . _T('install_select_type_db') |
|
| 438 | - . '</legend>' |
|
| 439 | - . '<p class="explication">' |
|
| 440 | - . _T('install_types_db_connus') |
|
| 441 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | - . '</p>' |
|
| 444 | - . "\n<div class='p'>\n<ul>\n" |
|
| 445 | - . join("\n", install_select_serveur()) |
|
| 446 | - . "\n</ul>\n</div></fieldset>") |
|
| 447 | - ) |
|
| 448 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | - . ($predef[1] |
|
| 451 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | - : fieldset( |
|
| 453 | - _T('entree_base_donnee_1'), |
|
| 454 | - [ |
|
| 455 | - 'adresse_db' => [ |
|
| 456 | - 'label' => $db[1], |
|
| 457 | - 'valeur' => $db[0] |
|
| 458 | - ], |
|
| 459 | - ] |
|
| 460 | - ) |
|
| 461 | - ) |
|
| 462 | - . '</div>' |
|
| 463 | - |
|
| 464 | - . '<div id="install_login_base_hebergeur">' |
|
| 465 | - . ($predef[2] |
|
| 466 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | - : fieldset( |
|
| 468 | - _T('entree_login_connexion_1'), |
|
| 469 | - [ |
|
| 470 | - 'login_db' => [ |
|
| 471 | - 'label' => $login[1], |
|
| 472 | - 'valeur' => $login[0] |
|
| 473 | - ], |
|
| 474 | - ] |
|
| 475 | - ) |
|
| 476 | - ) |
|
| 477 | - . '</div>' |
|
| 478 | - |
|
| 479 | - . '<div id="install_pass_base_hebergeur">' |
|
| 480 | - . ($predef[3] |
|
| 481 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | - : fieldset( |
|
| 483 | - _T('entree_mot_passe_1'), |
|
| 484 | - [ |
|
| 485 | - 'pass_db' => [ |
|
| 486 | - 'label' => $pass[1], |
|
| 487 | - 'valeur' => $pass[0] |
|
| 488 | - ], |
|
| 489 | - ] |
|
| 490 | - ) |
|
| 491 | - ) |
|
| 492 | - . '</div>' |
|
| 493 | - |
|
| 494 | - . bouton_suivant())); |
|
| 431 | + . ($server_db |
|
| 432 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | + . (($predef[0]) |
|
| 434 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | + : '') |
|
| 436 | + : ('<fieldset><legend>' |
|
| 437 | + . _T('install_select_type_db') |
|
| 438 | + . '</legend>' |
|
| 439 | + . '<p class="explication">' |
|
| 440 | + . _T('install_types_db_connus') |
|
| 441 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | + . '</p>' |
|
| 444 | + . "\n<div class='p'>\n<ul>\n" |
|
| 445 | + . join("\n", install_select_serveur()) |
|
| 446 | + . "\n</ul>\n</div></fieldset>") |
|
| 447 | + ) |
|
| 448 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | + . ($predef[1] |
|
| 451 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | + : fieldset( |
|
| 453 | + _T('entree_base_donnee_1'), |
|
| 454 | + [ |
|
| 455 | + 'adresse_db' => [ |
|
| 456 | + 'label' => $db[1], |
|
| 457 | + 'valeur' => $db[0] |
|
| 458 | + ], |
|
| 459 | + ] |
|
| 460 | + ) |
|
| 461 | + ) |
|
| 462 | + . '</div>' |
|
| 463 | + |
|
| 464 | + . '<div id="install_login_base_hebergeur">' |
|
| 465 | + . ($predef[2] |
|
| 466 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | + : fieldset( |
|
| 468 | + _T('entree_login_connexion_1'), |
|
| 469 | + [ |
|
| 470 | + 'login_db' => [ |
|
| 471 | + 'label' => $login[1], |
|
| 472 | + 'valeur' => $login[0] |
|
| 473 | + ], |
|
| 474 | + ] |
|
| 475 | + ) |
|
| 476 | + ) |
|
| 477 | + . '</div>' |
|
| 478 | + |
|
| 479 | + . '<div id="install_pass_base_hebergeur">' |
|
| 480 | + . ($predef[3] |
|
| 481 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | + : fieldset( |
|
| 483 | + _T('entree_mot_passe_1'), |
|
| 484 | + [ |
|
| 485 | + 'pass_db' => [ |
|
| 486 | + 'label' => $pass[1], |
|
| 487 | + 'valeur' => $pass[0] |
|
| 488 | + ], |
|
| 489 | + ] |
|
| 490 | + ) |
|
| 491 | + ) |
|
| 492 | + . '</div>' |
|
| 493 | + |
|
| 494 | + . bouton_suivant())); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // 4 valeurs qu'on reconduit d'un script a l'autre |
| 498 | 498 | // sauf s'ils sont predefinis. |
| 499 | 499 | |
| 500 | 500 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 501 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 502 | - ? '' |
|
| 503 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 504 | - ) |
|
| 505 | - . ((defined('_INSTALL_USER_DB')) |
|
| 506 | - ? '' |
|
| 507 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 508 | - ) |
|
| 509 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 510 | - ? '' |
|
| 511 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 512 | - ) |
|
| 513 | - |
|
| 514 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 515 | - ? '' |
|
| 516 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 517 | - ); |
|
| 501 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 502 | + ? '' |
|
| 503 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 504 | + ) |
|
| 505 | + . ((defined('_INSTALL_USER_DB')) |
|
| 506 | + ? '' |
|
| 507 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 508 | + ) |
|
| 509 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 510 | + ? '' |
|
| 511 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 512 | + ) |
|
| 513 | + |
|
| 514 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 515 | + ? '' |
|
| 516 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 517 | + ); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // presentation des bases existantes |
| 521 | 521 | |
| 522 | 522 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 523 | - $bases = $checked = []; |
|
| 524 | - $noms = sql_listdbs($server_db); |
|
| 525 | - if (!$noms) { |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - foreach ($noms as $nom) { |
|
| 530 | - $id = spip_htmlspecialchars($nom); |
|
| 531 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 532 | - $base = ' name="choix_db" value="' |
|
| 533 | - . $nom |
|
| 534 | - . '"' |
|
| 535 | - . $dis |
|
| 536 | - . " type='radio' id='$id'"; |
|
| 537 | - $label = "<label for='$id'>" |
|
| 538 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 539 | - . '</label>'; |
|
| 540 | - |
|
| 541 | - if ( |
|
| 542 | - !$checked and !$dis and |
|
| 543 | - (($nom == $login_db) or |
|
| 544 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 545 | - ) { |
|
| 546 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 547 | - } else { |
|
| 548 | - $bases[] = "<input$base />\n$label"; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if (!$bases && !$checked) { |
|
| 553 | - return false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - if ($checked) { |
|
| 557 | - array_unshift($bases, $checked); |
|
| 558 | - $checked = true; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return [$checked, $bases]; |
|
| 523 | + $bases = $checked = []; |
|
| 524 | + $noms = sql_listdbs($server_db); |
|
| 525 | + if (!$noms) { |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + foreach ($noms as $nom) { |
|
| 530 | + $id = spip_htmlspecialchars($nom); |
|
| 531 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 532 | + $base = ' name="choix_db" value="' |
|
| 533 | + . $nom |
|
| 534 | + . '"' |
|
| 535 | + . $dis |
|
| 536 | + . " type='radio' id='$id'"; |
|
| 537 | + $label = "<label for='$id'>" |
|
| 538 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 539 | + . '</label>'; |
|
| 540 | + |
|
| 541 | + if ( |
|
| 542 | + !$checked and !$dis and |
|
| 543 | + (($nom == $login_db) or |
|
| 544 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 545 | + ) { |
|
| 546 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 547 | + } else { |
|
| 548 | + $bases[] = "<input$base />\n$label"; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if (!$bases && !$checked) { |
|
| 553 | + return false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + if ($checked) { |
|
| 557 | + array_unshift($bases, $checked); |
|
| 558 | + $checked = true; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return [$checked, $bases]; |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | function install_propager($hidden) { |
| 565 | - $res = ''; |
|
| 566 | - foreach ($hidden as $k) { |
|
| 567 | - $v = spip_htmlentities(_request($k)); |
|
| 568 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 569 | - } |
|
| 565 | + $res = ''; |
|
| 566 | + foreach ($hidden as $k) { |
|
| 567 | + $v = spip_htmlentities(_request($k)); |
|
| 568 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - return $res; |
|
| 571 | + return $res; |
|
| 572 | 572 | } |