@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
@@ -21,64 +21,64 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // https://code.spip.net/@install_etape_fin_dist |
| 23 | 23 | function install_etape_fin_dist() { |
| 24 | - ecrire_acces(); |
|
| 24 | + ecrire_acces(); |
|
| 25 | 25 | |
| 26 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 27 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 28 | - if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | - if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 30 | - spip_unlink(_FILE_CHMOD_TMP); |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - } |
|
| 26 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 27 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 28 | + if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | + if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 30 | + spip_unlink(_FILE_CHMOD_TMP); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 36 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 37 | - spip_log("renomme $f"); |
|
| 38 | - if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | - if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 40 | - @spip_unlink(_FILE_CONNECT_TMP); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 35 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 36 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 37 | + spip_log("renomme $f"); |
|
| 38 | + if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | + if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 40 | + @spip_unlink(_FILE_CONNECT_TMP); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // creer le repertoire cache, qui sert partout ! |
|
| 46 | - // deja fait en etape 4 en principe, on garde au cas ou |
|
| 47 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 48 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 49 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 50 | - } |
|
| 45 | + // creer le repertoire cache, qui sert partout ! |
|
| 46 | + // deja fait en etape 4 en principe, on garde au cas ou |
|
| 47 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 48 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 49 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Verifier la securite des htaccess |
|
| 53 | - // Si elle ne fonctionne pas, prevenir |
|
| 54 | - $msg = install_verifier_htaccess(); |
|
| 55 | - if ($msg) { |
|
| 56 | - $cible = _T('public:accueil_site'); |
|
| 57 | - $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 58 | - echo minipres('AUTO', $msg . $cible); |
|
| 59 | - // ok, deboucher dans l'espace prive |
|
| 60 | - } else { |
|
| 61 | - redirige_url_ecrire('accueil'); |
|
| 62 | - } |
|
| 52 | + // Verifier la securite des htaccess |
|
| 53 | + // Si elle ne fonctionne pas, prevenir |
|
| 54 | + $msg = install_verifier_htaccess(); |
|
| 55 | + if ($msg) { |
|
| 56 | + $cible = _T('public:accueil_site'); |
|
| 57 | + $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 58 | + echo minipres('AUTO', $msg . $cible); |
|
| 59 | + // ok, deboucher dans l'espace prive |
|
| 60 | + } else { |
|
| 61 | + redirige_url_ecrire('accueil'); |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function install_verifier_htaccess() { |
| 66 | - if (verifier_htaccess(_DIR_TMP, true) |
|
| 67 | - and verifier_htaccess(_DIR_CONNECT, true) |
|
| 68 | - ) { |
|
| 69 | - return ''; |
|
| 70 | - } |
|
| 66 | + if (verifier_htaccess(_DIR_TMP, true) |
|
| 67 | + and verifier_htaccess(_DIR_CONNECT, true) |
|
| 68 | + ) { |
|
| 69 | + return ''; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $titre = _T('htaccess_inoperant'); |
|
| 72 | + $titre = _T('htaccess_inoperant'); |
|
| 73 | 73 | |
| 74 | - $averti = _T( |
|
| 75 | - 'htaccess_a_simuler', |
|
| 76 | - array( |
|
| 77 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 78 | - 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 79 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 74 | + $averti = _T( |
|
| 75 | + 'htaccess_a_simuler', |
|
| 76 | + array( |
|
| 77 | + 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 78 | + 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 79 | + 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | 82 | |
| 83 | - return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 83 | + return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 84 | 84 | } |
@@ -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 | |
@@ -27,42 +27,42 @@ discard block |
||
| 27 | 27 | // |
| 28 | 28 | // https://code.spip.net/@test_ecrire |
| 29 | 29 | function test_ecrire($my_dir) { |
| 30 | - static $chmod = 0; |
|
| 31 | - |
|
| 32 | - $ok = false; |
|
| 33 | - $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | - $self = basename($script); |
|
| 35 | - $uid = @fileowner('.'); |
|
| 36 | - $uid2 = @fileowner($self); |
|
| 37 | - $gid = @filegroup('.'); |
|
| 38 | - $gid2 = @filegroup($self); |
|
| 39 | - $perms = @fileperms($self); |
|
| 40 | - |
|
| 41 | - // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | - // avec celle du script et du repertoire courant |
|
| 43 | - if (!$chmod) { |
|
| 44 | - @rmdir('test'); |
|
| 45 | - spip_unlink('test'); // effacer au cas ou |
|
| 46 | - @touch('test'); |
|
| 47 | - if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | - $chmod = 0700; |
|
| 49 | - } else { |
|
| 50 | - if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | - $chmod = 0770; |
|
| 52 | - } else { |
|
| 53 | - $chmod = 0777; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - // Appliquer de plus les droits d'acces du script |
|
| 57 | - if ($perms > 0) { |
|
| 58 | - $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | - $chmod |= $perms; |
|
| 60 | - } |
|
| 61 | - spip_unlink('test'); |
|
| 62 | - } |
|
| 63 | - $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | - |
|
| 65 | - return $ok ? $chmod : false; |
|
| 30 | + static $chmod = 0; |
|
| 31 | + |
|
| 32 | + $ok = false; |
|
| 33 | + $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | + $self = basename($script); |
|
| 35 | + $uid = @fileowner('.'); |
|
| 36 | + $uid2 = @fileowner($self); |
|
| 37 | + $gid = @filegroup('.'); |
|
| 38 | + $gid2 = @filegroup($self); |
|
| 39 | + $perms = @fileperms($self); |
|
| 40 | + |
|
| 41 | + // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | + // avec celle du script et du repertoire courant |
|
| 43 | + if (!$chmod) { |
|
| 44 | + @rmdir('test'); |
|
| 45 | + spip_unlink('test'); // effacer au cas ou |
|
| 46 | + @touch('test'); |
|
| 47 | + if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | + $chmod = 0700; |
|
| 49 | + } else { |
|
| 50 | + if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | + $chmod = 0770; |
|
| 52 | + } else { |
|
| 53 | + $chmod = 0777; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + // Appliquer de plus les droits d'acces du script |
|
| 57 | + if ($perms > 0) { |
|
| 58 | + $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | + $chmod |= $perms; |
|
| 60 | + } |
|
| 61 | + spip_unlink('test'); |
|
| 62 | + } |
|
| 63 | + $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | + |
|
| 65 | + return $ok ? $chmod : false; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // |
@@ -73,83 +73,83 @@ discard block |
||
| 73 | 73 | // https://code.spip.net/@install_etape_chmod_dist |
| 74 | 74 | function install_etape_chmod_dist() { |
| 75 | 75 | |
| 76 | - $test_dir = _request('test_dir'); |
|
| 77 | - $chmod = 0; |
|
| 78 | - |
|
| 79 | - if ($test_dir) { |
|
| 80 | - if (substr($test_dir, -1) !== '/') { |
|
| 81 | - $test_dir .= '/'; |
|
| 82 | - } |
|
| 83 | - if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - if (!_FILE_CONNECT) { |
|
| 88 | - $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | - $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $bad_dirs = array(); |
|
| 94 | - $absent_dirs = array(); |
|
| 95 | - |
|
| 96 | - foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | - $test = test_ecrire($my_dir); |
|
| 98 | - if (!$test) { |
|
| 99 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | - if (@file_exists($my_dir)) { |
|
| 101 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | - } else { |
|
| 103 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | - } |
|
| 105 | - } else { |
|
| 106 | - $chmod = max($chmod, $test); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($bad_dirs or $absent_dirs) { |
|
| 111 | - if (!_FILE_CONNECT) { |
|
| 112 | - $titre = _T('dirs_preliminaire'); |
|
| 113 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | - } else { |
|
| 115 | - $titre = _T('dirs_probleme_droits'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | - |
|
| 121 | - if ($bad_dirs) { |
|
| 122 | - $res .= |
|
| 123 | - _T( |
|
| 124 | - 'dirs_repertoires_suivants', |
|
| 125 | - array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | - ) . |
|
| 127 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($absent_dirs) { |
|
| 131 | - $res .= |
|
| 132 | - _T( |
|
| 133 | - 'dirs_repertoires_absents', |
|
| 134 | - array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | - ) . |
|
| 136 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | - } |
|
| 138 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | - |
|
| 140 | - $t = _T('login_recharger'); |
|
| 141 | - $t = (!$test_dir ? '' : |
|
| 142 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | - . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | - |
|
| 146 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | - } else { |
|
| 148 | - $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | - if (!$deja) { |
|
| 150 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | - } else { |
|
| 152 | - redirige_url_ecrire(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 76 | + $test_dir = _request('test_dir'); |
|
| 77 | + $chmod = 0; |
|
| 78 | + |
|
| 79 | + if ($test_dir) { |
|
| 80 | + if (substr($test_dir, -1) !== '/') { |
|
| 81 | + $test_dir .= '/'; |
|
| 82 | + } |
|
| 83 | + if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | + $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + if (!_FILE_CONNECT) { |
|
| 88 | + $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | + $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $bad_dirs = array(); |
|
| 94 | + $absent_dirs = array(); |
|
| 95 | + |
|
| 96 | + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | + $test = test_ecrire($my_dir); |
|
| 98 | + if (!$test) { |
|
| 99 | + $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | + if (@file_exists($my_dir)) { |
|
| 101 | + $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | + } else { |
|
| 103 | + $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | + } |
|
| 105 | + } else { |
|
| 106 | + $chmod = max($chmod, $test); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($bad_dirs or $absent_dirs) { |
|
| 111 | + if (!_FILE_CONNECT) { |
|
| 112 | + $titre = _T('dirs_preliminaire'); |
|
| 113 | + $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | + } else { |
|
| 115 | + $titre = _T('dirs_probleme_droits'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | + |
|
| 121 | + if ($bad_dirs) { |
|
| 122 | + $res .= |
|
| 123 | + _T( |
|
| 124 | + 'dirs_repertoires_suivants', |
|
| 125 | + array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | + ) . |
|
| 127 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($absent_dirs) { |
|
| 131 | + $res .= |
|
| 132 | + _T( |
|
| 133 | + 'dirs_repertoires_absents', |
|
| 134 | + array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | + ) . |
|
| 136 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | + } |
|
| 138 | + $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | + |
|
| 140 | + $t = _T('login_recharger'); |
|
| 141 | + $t = (!$test_dir ? '' : |
|
| 142 | + "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | + . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | + . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | + |
|
| 146 | + echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | + } else { |
|
| 148 | + $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | + if (!$deja) { |
|
| 150 | + redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | + } else { |
|
| 152 | + redirige_url_ecrire(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Installation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/acces'); |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | 35 | function base_determine_autoinc($table, $desc = array()) { |
| 36 | - if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | - $autoinc = true; |
|
| 38 | - } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | - $autoinc = false; |
|
| 40 | - } else { |
|
| 41 | - // essayer de faire au mieux ! |
|
| 42 | - $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | - and strpos($desc['key']['PRIMARY KEY'], ',') === false |
|
| 44 | - and strpos($desc['field'][$desc['key']['PRIMARY KEY']], 'default') === false); |
|
| 45 | - } |
|
| 36 | + if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | + $autoinc = true; |
|
| 38 | + } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | + $autoinc = false; |
|
| 40 | + } else { |
|
| 41 | + // essayer de faire au mieux ! |
|
| 42 | + $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | + and strpos($desc['key']['PRIMARY KEY'], ',') === false |
|
| 44 | + and strpos($desc['field'][$desc['key']['PRIMARY KEY']], 'default') === false); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $autoinc; |
|
| 47 | + return $autoinc; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -61,59 +61,59 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
| 64 | - #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | - $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | - #if (!$sql_desc) $sql_desc = false; |
|
| 67 | - #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | - if (!$sql_desc) { |
|
| 69 | - if ($autoinc === 'auto') { |
|
| 70 | - $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | - } |
|
| 72 | - #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | - if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | - } |
|
| 76 | - // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | - #if (!$sql_desc) $sql_desc = false; |
|
| 79 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | - if (!$sql_desc) { |
|
| 81 | - // on retente avec un sleep ? |
|
| 82 | - sleep(1); |
|
| 83 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | - #if (!$sql_desc) $sql_desc = false; |
|
| 86 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | - if (!$sql_desc) { |
|
| 88 | - spip_log("Echec creation table $table", "maj" . _LOG_CRITIQUE); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | - // ajouter les champs manquants |
|
| 94 | - // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | - // c'est toujours a faire manuellement |
|
| 96 | - $last = ''; |
|
| 97 | - if (isset($desc['field'])) { |
|
| 98 | - foreach ($desc['field'] as $field => $type) { |
|
| 99 | - if (!isset($sql_desc['field'][$field])) { |
|
| 100 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ""), $serveur); |
|
| 101 | - } |
|
| 102 | - $last = $field; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - if (isset($desc['key'])) { |
|
| 106 | - foreach ($desc['key'] as $key => $type) { |
|
| 107 | - // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | - // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | - if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | - sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | - } |
|
| 112 | - $last = $field; |
|
| 113 | - } |
|
| 114 | - } |
|
| 64 | + #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | + #if (!$sql_desc) $sql_desc = false; |
|
| 67 | + #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | + if (!$sql_desc) { |
|
| 69 | + if ($autoinc === 'auto') { |
|
| 70 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | + } |
|
| 72 | + #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | + if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | + } |
|
| 76 | + // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | + #if (!$sql_desc) $sql_desc = false; |
|
| 79 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | + if (!$sql_desc) { |
|
| 81 | + // on retente avec un sleep ? |
|
| 82 | + sleep(1); |
|
| 83 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | + #if (!$sql_desc) $sql_desc = false; |
|
| 86 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | + if (!$sql_desc) { |
|
| 88 | + spip_log("Echec creation table $table", "maj" . _LOG_CRITIQUE); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | + // ajouter les champs manquants |
|
| 94 | + // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | + // c'est toujours a faire manuellement |
|
| 96 | + $last = ''; |
|
| 97 | + if (isset($desc['field'])) { |
|
| 98 | + foreach ($desc['field'] as $field => $type) { |
|
| 99 | + if (!isset($sql_desc['field'][$field])) { |
|
| 100 | + sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ""), $serveur); |
|
| 101 | + } |
|
| 102 | + $last = $field; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + if (isset($desc['key'])) { |
|
| 106 | + foreach ($desc['key'] as $key => $type) { |
|
| 107 | + // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | + // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | + if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | + } |
|
| 112 | + $last = $field; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -135,26 +135,26 @@ discard block |
||
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | 137 | function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') { |
| 138 | - if ($up === false) { |
|
| 139 | - $old = false; |
|
| 140 | - $up = array(); |
|
| 141 | - } else { |
|
| 142 | - $old = true; |
|
| 143 | - if (!is_array($up)) { |
|
| 144 | - $up = array($up); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($tables_inc as $k => $v) { |
|
| 148 | - if (!$old or in_array($k, $up)) { |
|
| 149 | - creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 150 | - } |
|
| 151 | - } |
|
| 138 | + if ($up === false) { |
|
| 139 | + $old = false; |
|
| 140 | + $up = array(); |
|
| 141 | + } else { |
|
| 142 | + $old = true; |
|
| 143 | + if (!is_array($up)) { |
|
| 144 | + $up = array($up); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($tables_inc as $k => $v) { |
|
| 148 | + if (!$old or in_array($k, $up)) { |
|
| 149 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - foreach ($tables_noinc as $k => $v) { |
|
| 154 | - if (!$old or in_array($k, $up)) { |
|
| 155 | - creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 156 | - } |
|
| 157 | - } |
|
| 153 | + foreach ($tables_noinc as $k => $v) { |
|
| 154 | + if (!$old or in_array($k, $up)) { |
|
| 155 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | function creer_base($serveur = '') { |
| 176 | 176 | |
| 177 | - // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 178 | - // de la conformite de la base |
|
| 179 | - // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 177 | + // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 178 | + // de la conformite de la base |
|
| 179 | + // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 180 | 180 | |
| 181 | - alterer_base( |
|
| 182 | - lister_tables_principales(), |
|
| 183 | - lister_tables_auxiliaires(), |
|
| 184 | - false, |
|
| 185 | - $serveur |
|
| 186 | - ); |
|
| 181 | + alterer_base( |
|
| 182 | + lister_tables_principales(), |
|
| 183 | + lister_tables_auxiliaires(), |
|
| 184 | + false, |
|
| 185 | + $serveur |
|
| 186 | + ); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | * @return void |
| 204 | 204 | */ |
| 205 | 205 | function maj_tables($upgrade_tables = array(), $serveur = '') { |
| 206 | - alterer_base( |
|
| 207 | - lister_tables_principales(), |
|
| 208 | - lister_tables_auxiliaires(), |
|
| 209 | - $upgrade_tables, |
|
| 210 | - $serveur |
|
| 211 | - ); |
|
| 206 | + alterer_base( |
|
| 207 | + lister_tables_principales(), |
|
| 208 | + lister_tables_auxiliaires(), |
|
| 209 | + $upgrade_tables, |
|
| 210 | + $serveur |
|
| 211 | + ); |
|
| 212 | 212 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | 31 | function action_etre_webmestre_dist() { |
| 32 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | - $time = $securiser_action(); |
|
| 34 | - |
|
| 35 | - if (time() - $time < 15 * 60 |
|
| 36 | - and $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | - and $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | - ) { |
|
| 39 | - $action = _T('info_admin_etre_webmestre'); |
|
| 40 | - $admin = charger_fonction('admin', 'inc'); |
|
| 41 | - // lance la verif par ftp et l'appel |
|
| 42 | - // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | - if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | - echo $r; |
|
| 45 | - exit; |
|
| 46 | - } |
|
| 47 | - } |
|
| 32 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | + $time = $securiser_action(); |
|
| 34 | + |
|
| 35 | + if (time() - $time < 15 * 60 |
|
| 36 | + and $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | + and $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | + ) { |
|
| 39 | + $action = _T('info_admin_etre_webmestre'); |
|
| 40 | + $admin = charger_fonction('admin', 'inc'); |
|
| 41 | + // lance la verif par ftp et l'appel |
|
| 42 | + // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | + if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | + echo $r; |
|
| 45 | + exit; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @return void |
| 55 | 55 | */ |
| 56 | 56 | function base_etre_webmestre_dist() { |
| 57 | - if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 58 | - include_spip('action/editer_auteur'); |
|
| 59 | - auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true); |
|
| 60 | - } |
|
| 57 | + if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 58 | + include_spip('action/editer_auteur'); |
|
| 59 | + auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -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/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
@@ -25,189 +25,189 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // https://code.spip.net/@ligne_plug |
| 27 | 27 | function plugins_afficher_plugin_dist( |
| 28 | - $url_page, |
|
| 29 | - $plug_file, |
|
| 30 | - $checked, |
|
| 31 | - $actif, |
|
| 32 | - $expose = false, |
|
| 33 | - $class_li = "item", |
|
| 34 | - $dir_plugins = _DIR_PLUGINS |
|
| 28 | + $url_page, |
|
| 29 | + $plug_file, |
|
| 30 | + $checked, |
|
| 31 | + $actif, |
|
| 32 | + $expose = false, |
|
| 33 | + $class_li = "item", |
|
| 34 | + $dir_plugins = _DIR_PLUGINS |
|
| 35 | 35 | ) { |
| 36 | 36 | |
| 37 | - static $id_input = 0; |
|
| 38 | - static $versions = array(); |
|
| 39 | - |
|
| 40 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | - $prefix = $info['prefix']; |
|
| 44 | - $cfg = ""; |
|
| 45 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | - $erreur = ""; |
|
| 48 | - |
|
| 49 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | - $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | - _T('plugin_info_non_compatible_spip')); |
|
| 53 | - $class_li .= " disabled"; |
|
| 54 | - $checkable = false; |
|
| 55 | - } elseif (isset($info['erreur'])) { |
|
| 56 | - $class_li .= " error"; |
|
| 57 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | - _T('plugin_info_erreur_xml')) |
|
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | - $checkable = false; |
|
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | - $class_li .= " error"; |
|
| 63 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | - " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | - } else { |
|
| 68 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // numerotons les occurrences d'un meme prefix |
|
| 72 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | - |
|
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | - |
|
| 76 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | - . ((!$checkable and !$checked) |
|
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | - . $cfg |
|
| 81 | - . $erreur |
|
| 82 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | - . "</div>" |
|
| 87 | - . "</li>"; |
|
| 37 | + static $id_input = 0; |
|
| 38 | + static $versions = array(); |
|
| 39 | + |
|
| 40 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | + $prefix = $info['prefix']; |
|
| 44 | + $cfg = ""; |
|
| 45 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | + $erreur = ""; |
|
| 48 | + |
|
| 49 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | + _T('plugin_info_non_compatible_spip')); |
|
| 53 | + $class_li .= " disabled"; |
|
| 54 | + $checkable = false; |
|
| 55 | + } elseif (isset($info['erreur'])) { |
|
| 56 | + $class_li .= " error"; |
|
| 57 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | + _T('plugin_info_erreur_xml')) |
|
| 59 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | + $checkable = false; |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | + $class_li .= " error"; |
|
| 63 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | + " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | + . "<div class='erreur'>" . implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | + } else { |
|
| 68 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // numerotons les occurrences d'un meme prefix |
|
| 72 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | + |
|
| 74 | + $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | + |
|
| 76 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | + . ((!$checkable and !$checked) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | + . $cfg |
|
| 81 | + . $erreur |
|
| 82 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | + . "</div>" |
|
| 87 | + . "</li>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function plugin_bouton_config($nom, $infos, $dir) { |
| 91 | - // la verification se base sur le filesystem |
|
| 92 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | - $prefix = strtolower($infos['prefix']); |
|
| 94 | - // si paquet.xml fournit un squelette, le prendre |
|
| 95 | - if (isset($infos['config']) and $infos['config']) { |
|
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | - array( |
|
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 99 | - 'nom' => $nom |
|
| 100 | - )); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si le plugin CFG est la, l'essayer |
|
| 104 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | - { |
|
| 107 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // sinon prendre le squelette std sur le nom std |
|
| 114 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | - array( |
|
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 117 | - 'nom' => $nom |
|
| 118 | - )); |
|
| 91 | + // la verification se base sur le filesystem |
|
| 92 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | + $prefix = strtolower($infos['prefix']); |
|
| 94 | + // si paquet.xml fournit un squelette, le prendre |
|
| 95 | + if (isset($infos['config']) and $infos['config']) { |
|
| 96 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | + array( |
|
| 98 | + 'script' => 'configurer_' . $prefix, |
|
| 99 | + 'nom' => $nom |
|
| 100 | + )); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si le plugin CFG est la, l'essayer |
|
| 104 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | + { |
|
| 107 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // sinon prendre le squelette std sur le nom std |
|
| 114 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | + array( |
|
| 116 | + 'script' => 'configurer_' . $prefix, |
|
| 117 | + 'nom' => $nom |
|
| 118 | + )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | 124 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | - $name = substr(md5($file), 0, 16); |
|
| 126 | - |
|
| 127 | - return "<div class='check'>\n" |
|
| 128 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | - . ($actif ? " checked='checked'" : "") |
|
| 130 | - . " class='checkbox' value='O' />" |
|
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | - . "</div>"; |
|
| 125 | + $name = substr(md5($file), 0, 16); |
|
| 126 | + |
|
| 127 | + return "<div class='check'>\n" |
|
| 128 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | + . ($actif ? " checked='checked'" : "") |
|
| 130 | + . " class='checkbox' value='O' />" |
|
| 131 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | + . "</div>"; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 136 | - $prefix = $info['prefix']; |
|
| 137 | - $dir = "$dir_plugins$plug_file"; |
|
| 138 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | - if ($info['dtd'] == "paquet") { |
|
| 140 | - $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 141 | - if (!$nom) { |
|
| 142 | - $nom = typo($info['nom']); |
|
| 143 | - } |
|
| 144 | - } else { |
|
| 145 | - $nom = typo(attribut_html($info['nom'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return trim($nom); |
|
| 136 | + $prefix = $info['prefix']; |
|
| 137 | + $dir = "$dir_plugins$plug_file"; |
|
| 138 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | + if ($info['dtd'] == "paquet") { |
|
| 140 | + $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 141 | + if (!$nom) { |
|
| 142 | + $nom = typo($info['nom']); |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $nom = typo(attribut_html($info['nom'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return trim($nom); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Cartouche Resume |
| 152 | 152 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 153 | - $prefix = $info['prefix']; |
|
| 154 | - $dir = "$dir_plugins$plug_file"; |
|
| 155 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | - // une seule ligne dans le slogan : couper si besoin |
|
| 157 | - if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | - $slogan = substr($slogan, 0, $p); |
|
| 159 | - } |
|
| 160 | - // couper par securite |
|
| 161 | - $slogan = couper($slogan, 80); |
|
| 162 | - |
|
| 163 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | - |
|
| 165 | - $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | - |
|
| 167 | - $icon_class = 'icon'; |
|
| 168 | - $img = ''; |
|
| 169 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 170 | - if ($img = chemin_image("$dir/$i")) { |
|
| 171 | - $img = http_img_pack($img, '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - if (!$img) { |
|
| 175 | - $img = http_img_pack("plugin-xx.svg", '', " width='32' height='32'"); |
|
| 176 | - $icon_class .= ' no-logo'; |
|
| 177 | - } |
|
| 178 | - else { |
|
| 153 | + $prefix = $info['prefix']; |
|
| 154 | + $dir = "$dir_plugins$plug_file"; |
|
| 155 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | + // une seule ligne dans le slogan : couper si besoin |
|
| 157 | + if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | + $slogan = substr($slogan, 0, $p); |
|
| 159 | + } |
|
| 160 | + // couper par securite |
|
| 161 | + $slogan = couper($slogan, 80); |
|
| 162 | + |
|
| 163 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | + |
|
| 165 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | + |
|
| 167 | + $icon_class = 'icon'; |
|
| 168 | + $img = ''; |
|
| 169 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 170 | + if ($img = chemin_image("$dir/$i")) { |
|
| 171 | + $img = http_img_pack($img, '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + if (!$img) { |
|
| 175 | + $img = http_img_pack("plugin-xx.svg", '', " width='32' height='32'"); |
|
| 176 | + $icon_class .= ' no-logo'; |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | 179 | # $img = "<img src='$img' width='32' height='32' alt='' />"; |
| 180 | - } |
|
| 181 | - $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 182 | - |
|
| 183 | - return "<div class='resume'>" |
|
| 184 | - . "<h3><a href='$url' rel='info'>" |
|
| 185 | - . $nom |
|
| 186 | - . "</a></h3>" |
|
| 187 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 188 | - . " <span class='etat'> - " |
|
| 189 | - . plugin_etat_en_clair($info['etat']) |
|
| 190 | - . "</span>" |
|
| 191 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 192 | - . $i |
|
| 193 | - . "</div>"; |
|
| 180 | + } |
|
| 181 | + $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 182 | + |
|
| 183 | + return "<div class='resume'>" |
|
| 184 | + . "<h3><a href='$url' rel='info'>" |
|
| 185 | + . $nom |
|
| 186 | + . "</a></h3>" |
|
| 187 | + . " <span class='version'>" . $info['version'] . "</span>" |
|
| 188 | + . " <span class='etat'> - " |
|
| 189 | + . plugin_etat_en_clair($info['etat']) |
|
| 190 | + . "</span>" |
|
| 191 | + . "<div class='short'>" . $slogan . "</div>" |
|
| 192 | + . $i |
|
| 193 | + . "</div>"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 197 | - if (!$dir_plugins) { |
|
| 198 | - $dir_plugins = _DIR_PLUGINS; |
|
| 199 | - } |
|
| 197 | + if (!$dir_plugins) { |
|
| 198 | + $dir_plugins = _DIR_PLUGINS; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 202 | - $text = _T('bouton_desinstaller'); |
|
| 203 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 204 | - $file = basename($plug_file); |
|
| 201 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 202 | + $text = _T('bouton_desinstaller'); |
|
| 203 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 204 | + $file = basename($plug_file); |
|
| 205 | 205 | |
| 206 | - return "<div class='actions'>[" . |
|
| 207 | - "<a href='$action' |
|
| 206 | + return "<div class='actions'>[" . |
|
| 207 | + "<a href='$action' |
|
| 208 | 208 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 209 | - . $text |
|
| 210 | - . "</a>]</div>"; |
|
| 209 | + . $text |
|
| 210 | + . "</a>]</div>"; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -221,137 +221,137 @@ discard block |
||
| 221 | 221 | * Traduction de l'état dans la langue en cours |
| 222 | 222 | **/ |
| 223 | 223 | function plugin_etat_en_clair($etat) { |
| 224 | - if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 225 | - $etat = 'developpement'; |
|
| 226 | - } |
|
| 224 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 225 | + $etat = 'developpement'; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return _T('plugin_etat_' . $etat); |
|
| 228 | + return _T('plugin_etat_' . $etat); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // https://code.spip.net/@plugin_propre |
| 232 | 232 | function plugin_propre($texte, $module = '',$propre='propre') { |
| 233 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 234 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 235 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 236 | - } |
|
| 237 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 238 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return $propre($texte); |
|
| 233 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 234 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 235 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 236 | + } |
|
| 237 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 238 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return $propre($texte); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | function plugin_typo($texte, $module = '') { |
| 245 | - return plugin_propre($texte, $module, 'typo'); |
|
| 245 | + return plugin_propre($texte, $module, 'typo'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | // https://code.spip.net/@affiche_bloc_plugin |
| 250 | 250 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 251 | - if (!$dir_plugins) { |
|
| 252 | - $dir_plugins = _DIR_PLUGINS; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $prefix = $info['prefix']; |
|
| 256 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 257 | - |
|
| 258 | - $s = ""; |
|
| 259 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 260 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 261 | - // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 262 | - $description = ""; |
|
| 263 | - if (isset($info['description'])) { |
|
| 264 | - $description = plugin_propre($info['description'], $dir); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if (isset($info['documentation']) |
|
| 268 | - and $lien = $info['documentation'] |
|
| 269 | - ) { |
|
| 270 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 271 | - } |
|
| 272 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 273 | - |
|
| 274 | - if (isset($info['auteur'])) { |
|
| 275 | - if (is_array($info['auteur'])) { |
|
| 276 | - $a = formater_credits($info['auteur'], ', '); |
|
| 277 | - } // pour compat mais ne doit plus arriver |
|
| 278 | - else { |
|
| 279 | - $a = trim($info['auteur']); |
|
| 280 | - } |
|
| 281 | - if ($a) { |
|
| 282 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 283 | - $dir)) . "</dd>\n"; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (isset($info['credit'])) { |
|
| 288 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 289 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($info['licence'])) { |
|
| 295 | - if (is_array($info['licence'])) { |
|
| 296 | - $a = formater_credits($info['licence'], ', '); |
|
| 297 | - } // pour compat mais ne doit plus arriver |
|
| 298 | - else { |
|
| 299 | - $a = trim($info['licence']); |
|
| 300 | - } |
|
| 301 | - if ($a) { |
|
| 302 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 303 | - $dir)) . "</dd>\n"; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $s = "<dl class='description'>$s</dl>"; |
|
| 308 | - |
|
| 309 | - // |
|
| 310 | - // Ajouter les infos techniques |
|
| 311 | - // |
|
| 312 | - $infotech = array(); |
|
| 313 | - |
|
| 314 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 315 | - // Version VCS |
|
| 316 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 317 | - $version .= ' ' . $vcs; |
|
| 318 | - } |
|
| 319 | - $version .= "</dd>"; |
|
| 320 | - $infotech[] = $version; |
|
| 321 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 322 | - // source zip le cas echeant |
|
| 323 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 324 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 325 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 326 | - : ''; |
|
| 327 | - |
|
| 328 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 329 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 330 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 331 | - |
|
| 332 | - $s .= "<dl class='tech'>" |
|
| 333 | - . join('', $infotech) |
|
| 334 | - . "</dl>"; |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - return $s; |
|
| 251 | + if (!$dir_plugins) { |
|
| 252 | + $dir_plugins = _DIR_PLUGINS; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $prefix = $info['prefix']; |
|
| 256 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 257 | + |
|
| 258 | + $s = ""; |
|
| 259 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 260 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 261 | + // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 262 | + $description = ""; |
|
| 263 | + if (isset($info['description'])) { |
|
| 264 | + $description = plugin_propre($info['description'], $dir); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if (isset($info['documentation']) |
|
| 268 | + and $lien = $info['documentation'] |
|
| 269 | + ) { |
|
| 270 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 271 | + } |
|
| 272 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 273 | + |
|
| 274 | + if (isset($info['auteur'])) { |
|
| 275 | + if (is_array($info['auteur'])) { |
|
| 276 | + $a = formater_credits($info['auteur'], ', '); |
|
| 277 | + } // pour compat mais ne doit plus arriver |
|
| 278 | + else { |
|
| 279 | + $a = trim($info['auteur']); |
|
| 280 | + } |
|
| 281 | + if ($a) { |
|
| 282 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 283 | + $dir)) . "</dd>\n"; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (isset($info['credit'])) { |
|
| 288 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 289 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 290 | + $dir)) . "</dd>\n"; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($info['licence'])) { |
|
| 295 | + if (is_array($info['licence'])) { |
|
| 296 | + $a = formater_credits($info['licence'], ', '); |
|
| 297 | + } // pour compat mais ne doit plus arriver |
|
| 298 | + else { |
|
| 299 | + $a = trim($info['licence']); |
|
| 300 | + } |
|
| 301 | + if ($a) { |
|
| 302 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 303 | + $dir)) . "</dd>\n"; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $s = "<dl class='description'>$s</dl>"; |
|
| 308 | + |
|
| 309 | + // |
|
| 310 | + // Ajouter les infos techniques |
|
| 311 | + // |
|
| 312 | + $infotech = array(); |
|
| 313 | + |
|
| 314 | + $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 315 | + // Version VCS |
|
| 316 | + if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 317 | + $version .= ' ' . $vcs; |
|
| 318 | + } |
|
| 319 | + $version .= "</dd>"; |
|
| 320 | + $infotech[] = $version; |
|
| 321 | + $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 322 | + // source zip le cas echeant |
|
| 323 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 324 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 325 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 326 | + : ''; |
|
| 327 | + |
|
| 328 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 329 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 330 | + array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 331 | + |
|
| 332 | + $s .= "<dl class='tech'>" |
|
| 333 | + . join('', $infotech) |
|
| 334 | + . "</dl>"; |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + return $s; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | function formater_credits($infos, $sep = ', ') { |
| 341 | - $texte = ''; |
|
| 342 | - |
|
| 343 | - foreach ($infos as $_credit) { |
|
| 344 | - if ($texte) { |
|
| 345 | - $texte .= $sep; |
|
| 346 | - } |
|
| 347 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 348 | - $texte .= |
|
| 349 | - (!is_array($_credit)) |
|
| 350 | - ? PtoBR(propre($_credit)) |
|
| 351 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 352 | - $_credit['nom'] . |
|
| 353 | - ($_credit['url'] ? '</a>' : ''); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $texte; |
|
| 341 | + $texte = ''; |
|
| 342 | + |
|
| 343 | + foreach ($infos as $_credit) { |
|
| 344 | + if ($texte) { |
|
| 345 | + $texte .= $sep; |
|
| 346 | + } |
|
| 347 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 348 | + $texte .= |
|
| 349 | + (!is_array($_credit)) |
|
| 350 | + ? PtoBR(propre($_credit)) |
|
| 351 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 352 | + $_credit['nom'] . |
|
| 353 | + ($_credit['url'] ? '</a>' : ''); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $texte; |
|
| 357 | 357 | } |
@@ -11,126 +11,126 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = " />"; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = " />"; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | - } else { |
|
| 36 | - $t = "{fond=" . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | - |
|
| 40 | - return ("<INCLURE" . $t . $args . ">"); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | + } else { |
|
| 36 | + $t = "{fond=" . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | + |
|
| 40 | + return ("<INCLURE" . $t . $args . ">"); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = array(); |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = array(); |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 49 | + return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 58 | + return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = "#" |
|
| 63 | - . ($boucle ? ($boucle . ":") : "") |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = "#" |
|
| 63 | + . ($boucle ? ($boucle . ":") : "") |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - list($type, $valeur) = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + list($type, $valeur) = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | - list($texte, $type) = $args[$i]; |
|
| 105 | - list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | - ) { |
|
| 126 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return join("", array_map(function($arg) { return reset($arg); }, $args)); |
|
| 103 | + for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | + list($texte, $type) = $args[$i]; |
|
| 105 | + list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | + ) { |
|
| 126 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return join("", array_map(function($arg) { return reset($arg); }, $args)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | function format_texte_html($texte) { |
| 135 | - return $texte; |
|
| 135 | + return $texte; |
|
| 136 | 136 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | * Environnement du formulaire |
| 29 | 29 | **/ |
| 30 | 30 | function formulaires_configurer_reducteur_charger_dist() { |
| 31 | - $valeurs = array(); |
|
| 32 | - foreach (array( |
|
| 33 | - 'image_process', |
|
| 34 | - 'formats_graphiques', |
|
| 35 | - 'creer_preview', |
|
| 36 | - 'taille_preview', |
|
| 37 | - ) as $m) { |
|
| 38 | - $valeurs[$m] = isset($GLOBALS['meta'][$m]) ? $GLOBALS['meta'][$m] : null; |
|
| 39 | - } |
|
| 31 | + $valeurs = array(); |
|
| 32 | + foreach (array( |
|
| 33 | + 'image_process', |
|
| 34 | + 'formats_graphiques', |
|
| 35 | + 'creer_preview', |
|
| 36 | + 'taille_preview', |
|
| 37 | + ) as $m) { |
|
| 38 | + $valeurs[$m] = isset($GLOBALS['meta'][$m]) ? $GLOBALS['meta'][$m] : null; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $valeurs['taille_preview'] = intval($valeurs['taille_preview']); |
|
| 42 | - if ($valeurs['taille_preview'] < 10) { |
|
| 43 | - $valeurs['taille_preview'] = 120; |
|
| 44 | - } |
|
| 41 | + $valeurs['taille_preview'] = intval($valeurs['taille_preview']); |
|
| 42 | + if ($valeurs['taille_preview'] < 10) { |
|
| 43 | + $valeurs['taille_preview'] = 120; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return $valeurs; |
|
| 46 | + return $valeurs; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -54,51 +54,51 @@ discard block |
||
| 54 | 54 | * Retours des traitements |
| 55 | 55 | **/ |
| 56 | 56 | function formulaires_configurer_reducteur_traiter_dist() { |
| 57 | - $res = array('editable' => true); |
|
| 57 | + $res = array('editable' => true); |
|
| 58 | 58 | |
| 59 | - if (is_array($image_process = _request('image_process_'))) { |
|
| 60 | - $image_process = array_keys($image_process); |
|
| 61 | - $image_process = reset($image_process); |
|
| 59 | + if (is_array($image_process = _request('image_process_'))) { |
|
| 60 | + $image_process = array_keys($image_process); |
|
| 61 | + $image_process = reset($image_process); |
|
| 62 | 62 | |
| 63 | - // application du choix de vignette |
|
| 64 | - if ($image_process) { |
|
| 65 | - // mettre a jour les formats graphiques lisibles |
|
| 66 | - switch ($image_process) { |
|
| 67 | - case 'gd1': |
|
| 68 | - case 'gd2': |
|
| 69 | - $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 70 | - break; |
|
| 71 | - case 'netpbm': |
|
| 72 | - $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 73 | - break; |
|
| 74 | - case 'convert': |
|
| 75 | - case 'imagick': |
|
| 76 | - $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 77 | - break; |
|
| 78 | - default: #debug |
|
| 79 | - $formats_graphiques = ''; |
|
| 80 | - $image_process = 'non'; |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 84 | - ecrire_meta('image_process', $image_process, 'non'); |
|
| 85 | - } |
|
| 86 | - } |
|
| 63 | + // application du choix de vignette |
|
| 64 | + if ($image_process) { |
|
| 65 | + // mettre a jour les formats graphiques lisibles |
|
| 66 | + switch ($image_process) { |
|
| 67 | + case 'gd1': |
|
| 68 | + case 'gd2': |
|
| 69 | + $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 70 | + break; |
|
| 71 | + case 'netpbm': |
|
| 72 | + $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 73 | + break; |
|
| 74 | + case 'convert': |
|
| 75 | + case 'imagick': |
|
| 76 | + $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 77 | + break; |
|
| 78 | + default: #debug |
|
| 79 | + $formats_graphiques = ''; |
|
| 80 | + $image_process = 'non'; |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 84 | + ecrire_meta('image_process', $image_process, 'non'); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - foreach (array( |
|
| 89 | - 'creer_preview' |
|
| 90 | - ) as $m) { |
|
| 91 | - if (!is_null($v = _request($m))) { |
|
| 92 | - ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - if (!is_null($v = _request('taille_preview'))) { |
|
| 96 | - ecrire_meta('taille_preview', intval($v)); |
|
| 97 | - } |
|
| 88 | + foreach (array( |
|
| 89 | + 'creer_preview' |
|
| 90 | + ) as $m) { |
|
| 91 | + if (!is_null($v = _request($m))) { |
|
| 92 | + ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + if (!is_null($v = _request('taille_preview'))) { |
|
| 96 | + ecrire_meta('taille_preview', intval($v)); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 99 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 100 | 100 | |
| 101 | - return $res; |
|
| 101 | + return $res; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * URL d'action pour tester la librairie graphique en créant une vignette |
| 112 | 112 | **/ |
| 113 | 113 | function url_vignette_choix($process) { |
| 114 | - switch ($process) { |
|
| 115 | - case 'gd2': |
|
| 116 | - if (!function_exists('ImageCreateTrueColor')) { |
|
| 117 | - return ''; |
|
| 118 | - } |
|
| 119 | - break; |
|
| 120 | - case 'gd1': |
|
| 121 | - if (!function_exists('ImageGif') |
|
| 122 | - and !function_exists('ImageJpeg') |
|
| 123 | - and !function_exists('ImagePng') |
|
| 124 | - ) { |
|
| 125 | - return ''; |
|
| 126 | - } |
|
| 127 | - break; |
|
| 128 | - case 'netpbm': |
|
| 129 | - if (defined('_PNMSCALE_COMMAND') and _PNMSCALE_COMMAND == '') { |
|
| 130 | - return ''; |
|
| 131 | - } |
|
| 132 | - break; |
|
| 133 | - case 'imagick': |
|
| 134 | - if (!method_exists('Imagick', 'readImage')) { |
|
| 135 | - return ''; |
|
| 136 | - } |
|
| 137 | - break; |
|
| 138 | - case 'convert': |
|
| 139 | - if (defined('_CONVERT_COMMAND') and _CONVERT_COMMAND == '') { |
|
| 140 | - return ''; |
|
| 141 | - } |
|
| 142 | - break; |
|
| 143 | - } |
|
| 114 | + switch ($process) { |
|
| 115 | + case 'gd2': |
|
| 116 | + if (!function_exists('ImageCreateTrueColor')) { |
|
| 117 | + return ''; |
|
| 118 | + } |
|
| 119 | + break; |
|
| 120 | + case 'gd1': |
|
| 121 | + if (!function_exists('ImageGif') |
|
| 122 | + and !function_exists('ImageJpeg') |
|
| 123 | + and !function_exists('ImagePng') |
|
| 124 | + ) { |
|
| 125 | + return ''; |
|
| 126 | + } |
|
| 127 | + break; |
|
| 128 | + case 'netpbm': |
|
| 129 | + if (defined('_PNMSCALE_COMMAND') and _PNMSCALE_COMMAND == '') { |
|
| 130 | + return ''; |
|
| 131 | + } |
|
| 132 | + break; |
|
| 133 | + case 'imagick': |
|
| 134 | + if (!method_exists('Imagick', 'readImage')) { |
|
| 135 | + return ''; |
|
| 136 | + } |
|
| 137 | + break; |
|
| 138 | + case 'convert': |
|
| 139 | + if (defined('_CONVERT_COMMAND') and _CONVERT_COMMAND == '') { |
|
| 140 | + return ''; |
|
| 141 | + } |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 145 | + return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 146 | 146 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = array(); |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = array()) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, ".php") !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, ".php") !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,23 +330,23 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force=false, $use_copy=false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)){ |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ($force |
|
| 338 | - or !file_exists($fichier) |
|
| 339 | - or md5_file($fichier) != md5_file($fichier_tmp)) { |
|
| 340 | - if ($use_copy) { |
|
| 341 | - @copy($fichier_tmp, $fichier); |
|
| 342 | - } |
|
| 343 | - else { |
|
| 344 | - @rename($fichier_tmp, $fichier); |
|
| 345 | - } |
|
| 346 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 347 | - clearstatcache(true, $fichier); |
|
| 348 | - } |
|
| 349 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)){ |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ($force |
|
| 338 | + or !file_exists($fichier) |
|
| 339 | + or md5_file($fichier) != md5_file($fichier_tmp)) { |
|
| 340 | + if ($use_copy) { |
|
| 341 | + @copy($fichier_tmp, $fichier); |
|
| 342 | + } |
|
| 343 | + else { |
|
| 344 | + @rename($fichier_tmp, $fichier); |
|
| 345 | + } |
|
| 346 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 347 | + clearstatcache(true, $fichier); |
|
| 348 | + } |
|
| 349 | + return true; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -367,11 +367,11 @@ discard block |
||
| 367 | 367 | * true si l'opération a réussie, false sinon. |
| 368 | 368 | */ |
| 369 | 369 | function lire_fichier_securise($fichier, &$contenu, $options = array()) { |
| 370 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 371 | - $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 372 | - } |
|
| 370 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 371 | + $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - return $res; |
|
| 374 | + return $res; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -386,20 +386,20 @@ discard block |
||
| 386 | 386 | * Chemin du fichier |
| 387 | 387 | **/ |
| 388 | 388 | function raler_fichier($fichier) { |
| 389 | - include_spip('inc/minipres'); |
|
| 390 | - $dir = dirname($fichier); |
|
| 391 | - http_status(401); |
|
| 392 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 393 | - . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 394 | - . " <a href='" |
|
| 395 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 396 | - . "'>" |
|
| 397 | - . _T('texte_inc_meta_2') |
|
| 398 | - . "</a> " |
|
| 399 | - . _T('texte_inc_meta_3', |
|
| 400 | - array('repertoire' => joli_repertoire($dir))) |
|
| 401 | - . "</h4>\n"); |
|
| 402 | - exit; |
|
| 389 | + include_spip('inc/minipres'); |
|
| 390 | + $dir = dirname($fichier); |
|
| 391 | + http_status(401); |
|
| 392 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 393 | + . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 394 | + . " <a href='" |
|
| 395 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 396 | + . "'>" |
|
| 397 | + . _T('texte_inc_meta_2') |
|
| 398 | + . "</a> " |
|
| 399 | + . _T('texte_inc_meta_3', |
|
| 400 | + array('repertoire' => joli_repertoire($dir))) |
|
| 401 | + . "</h4>\n"); |
|
| 402 | + exit; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -414,14 +414,14 @@ discard block |
||
| 414 | 414 | * - true si récent, false sinon |
| 415 | 415 | */ |
| 416 | 416 | function jeune_fichier($fichier, $n) { |
| 417 | - if (!file_exists($fichier)) { |
|
| 418 | - return false; |
|
| 419 | - } |
|
| 420 | - if (!$c = @filemtime($fichier)) { |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return (time() - $n <= $c); |
|
| 417 | + if (!file_exists($fichier)) { |
|
| 418 | + return false; |
|
| 419 | + } |
|
| 420 | + if (!$c = @filemtime($fichier)) { |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return (time() - $n <= $c); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -436,22 +436,22 @@ discard block |
||
| 436 | 436 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 437 | 437 | */ |
| 438 | 438 | function supprimer_fichier($fichier, $lock = true) { |
| 439 | - if (!@file_exists($fichier)) { |
|
| 440 | - return true; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if ($lock) { |
|
| 444 | - // verrouiller le fichier destination |
|
| 445 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 446 | - return false; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - // liberer le verrou |
|
| 450 | - spip_fclose_unlock($fp); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // supprimer |
|
| 454 | - return @unlink($fichier); |
|
| 439 | + if (!@file_exists($fichier)) { |
|
| 440 | + return true; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if ($lock) { |
|
| 444 | + // verrouiller le fichier destination |
|
| 445 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 446 | + return false; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + // liberer le verrou |
|
| 450 | + spip_fclose_unlock($fp); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // supprimer |
|
| 454 | + return @unlink($fichier); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | * Chemin du fichier |
| 462 | 462 | */ |
| 463 | 463 | function spip_unlink($f) { |
| 464 | - if (!is_dir($f)) { |
|
| 465 | - supprimer_fichier($f, false); |
|
| 466 | - } else { |
|
| 467 | - @unlink("$f/.ok"); |
|
| 468 | - @rmdir($f); |
|
| 469 | - } |
|
| 464 | + if (!is_dir($f)) { |
|
| 465 | + supprimer_fichier($f, false); |
|
| 466 | + } else { |
|
| 467 | + @unlink("$f/.ok"); |
|
| 468 | + @rmdir($f); |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,26 +480,26 @@ discard block |
||
| 480 | 480 | * The absolute path of the PHP file to invalidate. |
| 481 | 481 | */ |
| 482 | 482 | function spip_clear_opcode_cache($filepath) { |
| 483 | - clearstatcache(true, $filepath); |
|
| 484 | - |
|
| 485 | - // Zend OPcache |
|
| 486 | - if (function_exists('opcache_invalidate')) { |
|
| 487 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 488 | - // si l'invalidation a echoue lever un flag |
|
| 489 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 490 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 491 | - } |
|
| 492 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 493 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 494 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 495 | - } |
|
| 496 | - // APC. |
|
| 497 | - if (function_exists('apc_delete_file')) { |
|
| 498 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 499 | - // not compiled yet. |
|
| 500 | - // @see http://php.net/apc-delete-file |
|
| 501 | - @apc_delete_file($filepath); |
|
| 502 | - } |
|
| 483 | + clearstatcache(true, $filepath); |
|
| 484 | + |
|
| 485 | + // Zend OPcache |
|
| 486 | + if (function_exists('opcache_invalidate')) { |
|
| 487 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 488 | + // si l'invalidation a echoue lever un flag |
|
| 489 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 490 | + define('_spip_attend_invalidation_opcode_cache',true); |
|
| 491 | + } |
|
| 492 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 493 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 494 | + define('_spip_attend_invalidation_opcode_cache',true); |
|
| 495 | + } |
|
| 496 | + // APC. |
|
| 497 | + if (function_exists('apc_delete_file')) { |
|
| 498 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 499 | + // not compiled yet. |
|
| 500 | + // @see http://php.net/apc-delete-file |
|
| 501 | + @apc_delete_file($filepath); |
|
| 502 | + } |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -522,24 +522,24 @@ discard block |
||
| 522 | 522 | * |
| 523 | 523 | */ |
| 524 | 524 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 525 | - if (function_exists('opcache_get_configuration') |
|
| 526 | - and @ini_get('opcache.enable') |
|
| 527 | - and @ini_get('opcache.validate_timestamps') |
|
| 528 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 529 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 530 | - ) { |
|
| 531 | - $wait = $duree + 1; |
|
| 532 | - if ($timestamp) { |
|
| 533 | - $wait -= (time() - $timestamp); |
|
| 534 | - if ($wait<0) { |
|
| 535 | - $wait = 0; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 539 | - if ($wait) { |
|
| 540 | - sleep($duree + 1); |
|
| 541 | - } |
|
| 542 | - } |
|
| 525 | + if (function_exists('opcache_get_configuration') |
|
| 526 | + and @ini_get('opcache.enable') |
|
| 527 | + and @ini_get('opcache.validate_timestamps') |
|
| 528 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 529 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 530 | + ) { |
|
| 531 | + $wait = $duree + 1; |
|
| 532 | + if ($timestamp) { |
|
| 533 | + $wait -= (time() - $timestamp); |
|
| 534 | + if ($wait<0) { |
|
| 535 | + $wait = 0; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 539 | + if ($wait) { |
|
| 540 | + sleep($duree + 1); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -552,26 +552,26 @@ discard block |
||
| 552 | 552 | * @return bool Suppression reussie. |
| 553 | 553 | */ |
| 554 | 554 | function supprimer_repertoire($dir) { |
| 555 | - if (!file_exists($dir)) { |
|
| 556 | - return true; |
|
| 557 | - } |
|
| 558 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 559 | - return @unlink($dir); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - foreach (scandir($dir) as $item) { |
|
| 563 | - if ($item == '.' || $item == '..') { |
|
| 564 | - continue; |
|
| 565 | - } |
|
| 566 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 567 | - @chmod($dir . "/" . $item, 0777); |
|
| 568 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 569 | - return false; |
|
| 570 | - } |
|
| 571 | - }; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - return @rmdir($dir); |
|
| 555 | + if (!file_exists($dir)) { |
|
| 556 | + return true; |
|
| 557 | + } |
|
| 558 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 559 | + return @unlink($dir); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + foreach (scandir($dir) as $item) { |
|
| 563 | + if ($item == '.' || $item == '..') { |
|
| 564 | + continue; |
|
| 565 | + } |
|
| 566 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 567 | + @chmod($dir . "/" . $item, 0777); |
|
| 568 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + }; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + return @rmdir($dir); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | |
@@ -600,57 +600,57 @@ discard block |
||
| 600 | 600 | * Chemin du répertoire créé. |
| 601 | 601 | **/ |
| 602 | 602 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 603 | - static $dirs = array(); |
|
| 604 | - |
|
| 605 | - $base = str_replace("//", "/", $base); |
|
| 606 | - |
|
| 607 | - # suppr le dernier caractere si c'est un / |
|
| 608 | - $base = rtrim($base, '/'); |
|
| 609 | - |
|
| 610 | - if (!strlen($subdir)) { |
|
| 611 | - $n = strrpos($base, "/"); |
|
| 612 | - if ($n === false) { |
|
| 613 | - return $nobase ? '' : ($base . '/'); |
|
| 614 | - } |
|
| 615 | - $subdir = substr($base, $n + 1); |
|
| 616 | - $base = substr($base, 0, $n + 1); |
|
| 617 | - } else { |
|
| 618 | - $base .= '/'; |
|
| 619 | - $subdir = str_replace("/", "", $subdir); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - $baseaff = $nobase ? '' : $base; |
|
| 623 | - if (isset($dirs[$base . $subdir])) { |
|
| 624 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 628 | - |
|
| 629 | - if (file_exists("$path/.ok")) { |
|
| 630 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - @mkdir($path, _SPIP_CHMOD); |
|
| 634 | - @chmod($path, _SPIP_CHMOD); |
|
| 635 | - |
|
| 636 | - if (is_dir($path) && is_writable($path)) { |
|
| 637 | - @touch("$path/.ok"); |
|
| 638 | - spip_log("creation $base$subdir/"); |
|
| 639 | - |
|
| 640 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 644 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 645 | - spip_log("echec creation $base${subdir}"); |
|
| 646 | - if ($tantpis) { |
|
| 647 | - return ''; |
|
| 648 | - } |
|
| 649 | - if (!_DIR_RESTREINT) { |
|
| 650 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 651 | - } |
|
| 652 | - $base .= $subdir; |
|
| 653 | - raler_fichier($base . '/.ok'); |
|
| 603 | + static $dirs = array(); |
|
| 604 | + |
|
| 605 | + $base = str_replace("//", "/", $base); |
|
| 606 | + |
|
| 607 | + # suppr le dernier caractere si c'est un / |
|
| 608 | + $base = rtrim($base, '/'); |
|
| 609 | + |
|
| 610 | + if (!strlen($subdir)) { |
|
| 611 | + $n = strrpos($base, "/"); |
|
| 612 | + if ($n === false) { |
|
| 613 | + return $nobase ? '' : ($base . '/'); |
|
| 614 | + } |
|
| 615 | + $subdir = substr($base, $n + 1); |
|
| 616 | + $base = substr($base, 0, $n + 1); |
|
| 617 | + } else { |
|
| 618 | + $base .= '/'; |
|
| 619 | + $subdir = str_replace("/", "", $subdir); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + $baseaff = $nobase ? '' : $base; |
|
| 623 | + if (isset($dirs[$base . $subdir])) { |
|
| 624 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 628 | + |
|
| 629 | + if (file_exists("$path/.ok")) { |
|
| 630 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + @mkdir($path, _SPIP_CHMOD); |
|
| 634 | + @chmod($path, _SPIP_CHMOD); |
|
| 635 | + |
|
| 636 | + if (is_dir($path) && is_writable($path)) { |
|
| 637 | + @touch("$path/.ok"); |
|
| 638 | + spip_log("creation $base$subdir/"); |
|
| 639 | + |
|
| 640 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 644 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 645 | + spip_log("echec creation $base${subdir}"); |
|
| 646 | + if ($tantpis) { |
|
| 647 | + return ''; |
|
| 648 | + } |
|
| 649 | + if (!_DIR_RESTREINT) { |
|
| 650 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 651 | + } |
|
| 652 | + $base .= $subdir; |
|
| 653 | + raler_fichier($base . '/.ok'); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | |
@@ -683,51 +683,51 @@ discard block |
||
| 683 | 683 | * Chemins des fichiers trouvés. |
| 684 | 684 | **/ |
| 685 | 685 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) { |
| 686 | - $nbfiles = 0; |
|
| 687 | - if ($pattern == -1) { |
|
| 688 | - $pattern = "^$dir"; |
|
| 689 | - } |
|
| 690 | - $fichiers = array(); |
|
| 691 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 692 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 693 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 694 | - if ($dir == '') { |
|
| 695 | - $dir = '.'; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 699 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 700 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 701 | - and $f != 'CVS' |
|
| 702 | - and $f != 'remove.txt' |
|
| 703 | - and is_readable($f = "$dir/$f") |
|
| 704 | - ) { |
|
| 705 | - if (is_file($f)) { |
|
| 706 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 707 | - $fichiers[] = $f; |
|
| 708 | - $nbfiles++; |
|
| 709 | - } |
|
| 710 | - } else { |
|
| 711 | - if (is_dir($f) and is_array($recurs)) { |
|
| 712 | - $rp = @realpath($f); |
|
| 713 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 714 | - $rp = $f; |
|
| 715 | - } # realpath n'est peut etre pas autorise |
|
| 716 | - if (!isset($recurs[$rp])) { |
|
| 717 | - $recurs[$rp] = true; |
|
| 718 | - $beginning = $fichiers; |
|
| 719 | - $end = preg_files("$f/", $pattern, |
|
| 720 | - $maxfiles - $nbfiles, $recurs); |
|
| 721 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 722 | - $nbfiles = count($fichiers); |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - closedir($d); |
|
| 729 | - } |
|
| 730 | - sort($fichiers); |
|
| 731 | - |
|
| 732 | - return $fichiers; |
|
| 686 | + $nbfiles = 0; |
|
| 687 | + if ($pattern == -1) { |
|
| 688 | + $pattern = "^$dir"; |
|
| 689 | + } |
|
| 690 | + $fichiers = array(); |
|
| 691 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 692 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 693 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 694 | + if ($dir == '') { |
|
| 695 | + $dir = '.'; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 699 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 700 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 701 | + and $f != 'CVS' |
|
| 702 | + and $f != 'remove.txt' |
|
| 703 | + and is_readable($f = "$dir/$f") |
|
| 704 | + ) { |
|
| 705 | + if (is_file($f)) { |
|
| 706 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 707 | + $fichiers[] = $f; |
|
| 708 | + $nbfiles++; |
|
| 709 | + } |
|
| 710 | + } else { |
|
| 711 | + if (is_dir($f) and is_array($recurs)) { |
|
| 712 | + $rp = @realpath($f); |
|
| 713 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 714 | + $rp = $f; |
|
| 715 | + } # realpath n'est peut etre pas autorise |
|
| 716 | + if (!isset($recurs[$rp])) { |
|
| 717 | + $recurs[$rp] = true; |
|
| 718 | + $beginning = $fichiers; |
|
| 719 | + $end = preg_files("$f/", $pattern, |
|
| 720 | + $maxfiles - $nbfiles, $recurs); |
|
| 721 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 722 | + $nbfiles = count($fichiers); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + closedir($d); |
|
| 729 | + } |
|
| 730 | + sort($fichiers); |
|
| 731 | + |
|
| 732 | + return $fichiers; |
|
| 733 | 733 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,135 +66,135 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()) { |
| 69 | - static $tableau_des_erreurs = array(); |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = array(); |
|
| 78 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = array($message, $lieu); |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if (ob_get_length() |
|
| 119 | - and |
|
| 120 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | - ) { |
|
| 122 | - ob_end_clean(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | - $fonc = _request('var_mode_objet'); |
|
| 127 | - $mode = _request('var_mode_affiche'); |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_status(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 69 | + static $tableau_des_erreurs = array(); |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = array(); |
|
| 78 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = array($message, $lieu); |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if (ob_get_length() |
|
| 119 | + and |
|
| 120 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | + ) { |
|
| 122 | + ob_end_clean(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | + $fonc = _request('var_mode_objet'); |
|
| 127 | + $mode = _request('var_mode_affiche'); |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_status(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -204,42 +204,42 @@ discard block |
||
| 204 | 204 | * @return string Code HTML |
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | - $env = $env_tab; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!$env) { |
|
| 212 | - return ''; |
|
| 213 | - } |
|
| 214 | - $res = ""; |
|
| 215 | - foreach ($env as $nom => $valeur) { |
|
| 216 | - if (is_array($valeur)) { |
|
| 217 | - $valeur_simple = array(); |
|
| 218 | - foreach ($valeur as $v) { |
|
| 219 | - if (is_array($v)) { |
|
| 220 | - $valeur_simple[] = 'array:' . count($v); |
|
| 221 | - } elseif (is_object($v)) { |
|
| 222 | - $valeur_simple[] = get_class($v); |
|
| 223 | - } elseif (is_string($v)) { |
|
| 224 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | - } else { |
|
| 226 | - $valeur_simple[] = $v; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - $n = count($valeur); |
|
| 230 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | - } elseif (is_object($valeur)) { |
|
| 233 | - $valeur = get_class($valeur); |
|
| 234 | - } elseif (is_string($valeur)) { |
|
| 235 | - $valeur = "'" . $valeur . "'"; |
|
| 236 | - } |
|
| 237 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 238 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 239 | - . "</td></tr>\n"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 207 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | + $env = $env_tab; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!$env) { |
|
| 212 | + return ''; |
|
| 213 | + } |
|
| 214 | + $res = ""; |
|
| 215 | + foreach ($env as $nom => $valeur) { |
|
| 216 | + if (is_array($valeur)) { |
|
| 217 | + $valeur_simple = array(); |
|
| 218 | + foreach ($valeur as $v) { |
|
| 219 | + if (is_array($v)) { |
|
| 220 | + $valeur_simple[] = 'array:' . count($v); |
|
| 221 | + } elseif (is_object($v)) { |
|
| 222 | + $valeur_simple[] = get_class($v); |
|
| 223 | + } elseif (is_string($v)) { |
|
| 224 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | + } else { |
|
| 226 | + $valeur_simple[] = $v; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + $n = count($valeur); |
|
| 230 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | + } elseif (is_object($valeur)) { |
|
| 233 | + $valeur = get_class($valeur); |
|
| 234 | + } elseif (is_string($valeur)) { |
|
| 235 | + $valeur = "'" . $valeur . "'"; |
|
| 236 | + } |
|
| 237 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 238 | + . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 239 | + . "</td></tr>\n"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -247,67 +247,67 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav') { |
| 249 | 249 | |
| 250 | - if (_request('exec') == 'valider_xml') { |
|
| 251 | - return ''; |
|
| 252 | - } |
|
| 253 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 254 | - $res = ''; |
|
| 255 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 256 | - foreach ($tableau as $i => $err) { |
|
| 257 | - $boucle = $ligne = $skel = ''; |
|
| 258 | - list($msg, $lieu) = $err; |
|
| 259 | - if (is_object($lieu)) { |
|
| 260 | - $ligne = $lieu->ligne; |
|
| 261 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 262 | - if (isset($lieu->descr['nom'])) { |
|
| 263 | - $nom_code = $lieu->descr['nom']; |
|
| 264 | - $skel = $lieu->descr['sourcefile']; |
|
| 265 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 266 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 267 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 268 | - if ($boucle) { |
|
| 269 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 270 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $j = ($i + 1); |
|
| 276 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 277 | - . $j |
|
| 278 | - . " </td><td style='text-align: left'>" |
|
| 279 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 280 | - . "</td><td style='text-align: left'>" |
|
| 281 | - . ($skel ? $skel : " / ") |
|
| 282 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 283 | - . ($boucle ? $boucle : " / ") |
|
| 284 | - . "</td><td style='text-align: right'>" |
|
| 285 | - . $ligne |
|
| 286 | - . "</td></tr>\n"; |
|
| 287 | - |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return "\n<table id='$id'>" |
|
| 291 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | - . $caption[0] |
|
| 250 | + if (_request('exec') == 'valider_xml') { |
|
| 251 | + return ''; |
|
| 252 | + } |
|
| 253 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 254 | + $res = ''; |
|
| 255 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 256 | + foreach ($tableau as $i => $err) { |
|
| 257 | + $boucle = $ligne = $skel = ''; |
|
| 258 | + list($msg, $lieu) = $err; |
|
| 259 | + if (is_object($lieu)) { |
|
| 260 | + $ligne = $lieu->ligne; |
|
| 261 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 262 | + if (isset($lieu->descr['nom'])) { |
|
| 263 | + $nom_code = $lieu->descr['nom']; |
|
| 264 | + $skel = $lieu->descr['sourcefile']; |
|
| 265 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 266 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 267 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 268 | + if ($boucle) { |
|
| 269 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 270 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $j = ($i + 1); |
|
| 276 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 277 | + . $j |
|
| 278 | + . " </td><td style='text-align: left'>" |
|
| 279 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 280 | + . "</td><td style='text-align: left'>" |
|
| 281 | + . ($skel ? $skel : " / ") |
|
| 282 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 283 | + . ($boucle ? $boucle : " / ") |
|
| 284 | + . "</td><td style='text-align: right'>" |
|
| 285 | + . $ligne |
|
| 286 | + . "</td></tr>\n"; |
|
| 287 | + |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return "\n<table id='$id'>" |
|
| 291 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | + . $caption[0] |
|
| 293 | 293 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 294 | 294 | # aider('erreur_compilation'), |
| 295 | - . "</caption>" |
|
| 296 | - // fausse caption du chrono (mais vraie nav) |
|
| 297 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | - . "<tr><th>" |
|
| 299 | - . _T('numero') |
|
| 300 | - . "</th><th>" |
|
| 301 | - . _T('public:message') |
|
| 302 | - . "</th><th>" |
|
| 303 | - . _T('squelette') |
|
| 304 | - . "</th><th>" |
|
| 305 | - . _T('zbug_boucle') |
|
| 306 | - . "</th><th>" |
|
| 307 | - . _T('ligne') |
|
| 308 | - . "</th></tr>" |
|
| 309 | - . $res |
|
| 310 | - . "</table>"; |
|
| 295 | + . "</caption>" |
|
| 296 | + // fausse caption du chrono (mais vraie nav) |
|
| 297 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | + . "<tr><th>" |
|
| 299 | + . _T('numero') |
|
| 300 | + . "</th><th>" |
|
| 301 | + . _T('public:message') |
|
| 302 | + . "</th><th>" |
|
| 303 | + . _T('squelette') |
|
| 304 | + . "</th><th>" |
|
| 305 | + . _T('zbug_boucle') |
|
| 306 | + . "</th><th>" |
|
| 307 | + . _T('ligne') |
|
| 308 | + . "</th></tr>" |
|
| 309 | + . $res |
|
| 310 | + . "</table>"; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -327,125 +327,125 @@ discard block |
||
| 327 | 327 | * ou un tableau si l'erreur est critique |
| 328 | 328 | **/ |
| 329 | 329 | function debusquer_requete($message) { |
| 330 | - list($errno, $msg, $query) = $message; |
|
| 331 | - |
|
| 332 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | - $errno = $regs[2]; |
|
| 336 | - } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 337 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 338 | - ) { |
|
| 339 | - $errno = $regs[1]; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // Erreur systeme |
|
| 343 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 344 | - $retour = "<tt><br /><br /><blink>" |
|
| 345 | - . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 346 | - . "</blink><br />\n<b>" |
|
| 347 | - . _T('info_erreur_systeme2', |
|
| 348 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 349 | - . '</b><br />'; |
|
| 350 | - spip_log("Erreur systeme $errno"); |
|
| 351 | - |
|
| 352 | - return array($retour, ''); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // Requete erronee |
|
| 356 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 357 | - . spip_htmlspecialchars($msg) |
|
| 358 | - . "\n<br /><span style='color: red'><b>" |
|
| 359 | - . spip_htmlspecialchars($query) |
|
| 360 | - . "</b></span></tt><br />"; |
|
| 361 | - |
|
| 362 | - //. aider('erreur_mysql'); |
|
| 363 | - |
|
| 364 | - return $err; |
|
| 330 | + list($errno, $msg, $query) = $message; |
|
| 331 | + |
|
| 332 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | + $errno = $regs[2]; |
|
| 336 | + } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 337 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 338 | + ) { |
|
| 339 | + $errno = $regs[1]; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // Erreur systeme |
|
| 343 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 344 | + $retour = "<tt><br /><br /><blink>" |
|
| 345 | + . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 346 | + . "</blink><br />\n<b>" |
|
| 347 | + . _T('info_erreur_systeme2', |
|
| 348 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 349 | + . '</b><br />'; |
|
| 350 | + spip_log("Erreur systeme $errno"); |
|
| 351 | + |
|
| 352 | + return array($retour, ''); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // Requete erronee |
|
| 356 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 357 | + . spip_htmlspecialchars($msg) |
|
| 358 | + . "\n<br /><span style='color: red'><b>" |
|
| 359 | + . spip_htmlspecialchars($query) |
|
| 360 | + . "</b></span></tt><br />"; |
|
| 361 | + |
|
| 362 | + //. aider('erreur_mysql'); |
|
| 363 | + |
|
| 364 | + return $err; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
| 368 | 368 | // https://code.spip.net/@trouve_boucle_debug |
| 369 | 369 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 370 | 370 | |
| 371 | - $id = $nom . $boucle; |
|
| 372 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 373 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 374 | - |
|
| 375 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 376 | - $y = substr_count($v[0], "\n"); |
|
| 377 | - } else { |
|
| 378 | - if ($v[1][0] == '#') // balise dynamique |
|
| 379 | - { |
|
| 380 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 381 | - } else // inclusion |
|
| 382 | - { |
|
| 383 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 384 | - } |
|
| 385 | - $y = substr_count($incl, "\n") |
|
| 386 | - + substr_count($r[1], "\n") |
|
| 387 | - + substr_count($r[3], "\n"); |
|
| 388 | - } |
|
| 389 | - if ($n <= ($y + $debut)) { |
|
| 390 | - if ($v[1][0] == '?') { |
|
| 391 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 392 | - } elseif ($v[1][0] == '!') { |
|
| 393 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 394 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 399 | - } |
|
| 400 | - $debut += $y; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return array($nom, $boucle, $n - $debut); |
|
| 371 | + $id = $nom . $boucle; |
|
| 372 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 373 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 374 | + |
|
| 375 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 376 | + $y = substr_count($v[0], "\n"); |
|
| 377 | + } else { |
|
| 378 | + if ($v[1][0] == '#') // balise dynamique |
|
| 379 | + { |
|
| 380 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 381 | + } else // inclusion |
|
| 382 | + { |
|
| 383 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 384 | + } |
|
| 385 | + $y = substr_count($incl, "\n") |
|
| 386 | + + substr_count($r[1], "\n") |
|
| 387 | + + substr_count($r[3], "\n"); |
|
| 388 | + } |
|
| 389 | + if ($n <= ($y + $debut)) { |
|
| 390 | + if ($v[1][0] == '?') { |
|
| 391 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 392 | + } elseif ($v[1][0] == '!') { |
|
| 393 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 394 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 399 | + } |
|
| 400 | + $debut += $y; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return array($nom, $boucle, $n - $debut); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // https://code.spip.net/@trouve_squelette_inclus |
| 408 | 408 | function trouve_squelette_inclus($script) { |
| 409 | 409 | |
| 410 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 411 | - // si le script X.php n'est pas ecrire/public.php |
|
| 412 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 413 | - if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 414 | - { |
|
| 415 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 416 | - { |
|
| 417 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 418 | - $reg[1] = "inconnu"; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 423 | - |
|
| 424 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 425 | - if (preg_match($incl, $v)) { |
|
| 426 | - return $k; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return ""; |
|
| 410 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 411 | + // si le script X.php n'est pas ecrire/public.php |
|
| 412 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 413 | + if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 414 | + { |
|
| 415 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 416 | + { |
|
| 417 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 418 | + $reg[1] = "inconnu"; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 423 | + |
|
| 424 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 425 | + if (preg_match($incl, $v)) { |
|
| 426 | + return $k; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return ""; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | // https://code.spip.net/@reference_boucle_debug |
| 434 | 434 | function reference_boucle_debug($n, $nom, $self) { |
| 435 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 436 | - |
|
| 437 | - if (!$boucle) { |
|
| 438 | - return !$ligne ? "" : |
|
| 439 | - (" (" . |
|
| 440 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 441 | - _T('squelette_ligne')) . |
|
| 442 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 443 | - } else { |
|
| 444 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 445 | - |
|
| 446 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 447 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 448 | - } |
|
| 435 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 436 | + |
|
| 437 | + if (!$boucle) { |
|
| 438 | + return !$ligne ? "" : |
|
| 439 | + (" (" . |
|
| 440 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 441 | + _T('squelette_ligne')) . |
|
| 442 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 443 | + } else { |
|
| 444 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 445 | + |
|
| 446 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 447 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // affiche un texte avec numero de ligne et ancre. |
@@ -453,395 +453,395 @@ discard block |
||
| 453 | 453 | // https://code.spip.net/@ancre_texte |
| 454 | 454 | function ancre_texte($texte, $fautifs = array(), $nocpt = false) { |
| 455 | 455 | |
| 456 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 457 | - if ($var_mode_ligne) { |
|
| 458 | - $fautifs[] = array($var_mode_ligne); |
|
| 459 | - } |
|
| 460 | - $res = ''; |
|
| 461 | - |
|
| 462 | - $s = highlight_string($texte, true); |
|
| 463 | - if (substr($s, 0, 6) == '<code>') { |
|
| 464 | - $s = substr($s, 6); |
|
| 465 | - $res = '<code>'; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | - $s); |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - $tableau = explode("<br />", $s); |
|
| 474 | - |
|
| 475 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 476 | - |
|
| 477 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 478 | - $formaterr = "color: red;"; |
|
| 479 | - $i = 1; |
|
| 480 | - $flignes = array(); |
|
| 481 | - $loc = array(0, 0); |
|
| 482 | - foreach ($fautifs as $lc) { |
|
| 483 | - if (is_array($lc)) { |
|
| 484 | - $l = array_shift($lc); |
|
| 485 | - $flignes[$l] = $lc; |
|
| 486 | - } else { |
|
| 487 | - $flignes[$lc] = $loc; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $ancre = md5($texte); |
|
| 492 | - foreach ($tableau as $ligne) { |
|
| 493 | - if (isset($flignes[$i])) { |
|
| 494 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 495 | - $indexmesg = $flignes[$i][1]; |
|
| 496 | - $err = textebrut($flignes[$i][2]); |
|
| 497 | - // tentative de pointer sur la colonne fautive; |
|
| 498 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 499 | - // $m = $flignes[$i][0]; |
|
| 500 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 501 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 502 | - $bg = $formaterr; |
|
| 503 | - } else { |
|
| 504 | - $indexmesg = $ancre; |
|
| 505 | - $err = $bg = ''; |
|
| 506 | - } |
|
| 507 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 508 | - $i++; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - return "<div id='T$ancre'>" |
|
| 512 | - . '<div onclick="' |
|
| 513 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 514 | - . '" title="' |
|
| 515 | - . _T('masquer_colonne') |
|
| 516 | - . '" style="cursor: pointer;">' |
|
| 517 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 518 | - . "</div> |
|
| 456 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 457 | + if ($var_mode_ligne) { |
|
| 458 | + $fautifs[] = array($var_mode_ligne); |
|
| 459 | + } |
|
| 460 | + $res = ''; |
|
| 461 | + |
|
| 462 | + $s = highlight_string($texte, true); |
|
| 463 | + if (substr($s, 0, 6) == '<code>') { |
|
| 464 | + $s = substr($s, 6); |
|
| 465 | + $res = '<code>'; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | + $s); |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + $tableau = explode("<br />", $s); |
|
| 474 | + |
|
| 475 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 476 | + |
|
| 477 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 478 | + $formaterr = "color: red;"; |
|
| 479 | + $i = 1; |
|
| 480 | + $flignes = array(); |
|
| 481 | + $loc = array(0, 0); |
|
| 482 | + foreach ($fautifs as $lc) { |
|
| 483 | + if (is_array($lc)) { |
|
| 484 | + $l = array_shift($lc); |
|
| 485 | + $flignes[$l] = $lc; |
|
| 486 | + } else { |
|
| 487 | + $flignes[$lc] = $loc; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $ancre = md5($texte); |
|
| 492 | + foreach ($tableau as $ligne) { |
|
| 493 | + if (isset($flignes[$i])) { |
|
| 494 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 495 | + $indexmesg = $flignes[$i][1]; |
|
| 496 | + $err = textebrut($flignes[$i][2]); |
|
| 497 | + // tentative de pointer sur la colonne fautive; |
|
| 498 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 499 | + // $m = $flignes[$i][0]; |
|
| 500 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 501 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 502 | + $bg = $formaterr; |
|
| 503 | + } else { |
|
| 504 | + $indexmesg = $ancre; |
|
| 505 | + $err = $bg = ''; |
|
| 506 | + } |
|
| 507 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 508 | + $i++; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + return "<div id='T$ancre'>" |
|
| 512 | + . '<div onclick="' |
|
| 513 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 514 | + . '" title="' |
|
| 515 | + . _T('masquer_colonne') |
|
| 516 | + . '" style="cursor: pointer;">' |
|
| 517 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 518 | + . "</div> |
|
| 519 | 519 | " . $res . "</div>\n"; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // l'environnement graphique du debuggueur |
| 523 | 523 | |
| 524 | 524 | function debusquer_squelette($fonc, $mode, $self) { |
| 525 | - $texte = ''; |
|
| 526 | - |
|
| 527 | - if ($mode !== 'validation') { |
|
| 528 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 529 | - $res = "<div id='spip-boucles'>\n" |
|
| 530 | - . debusquer_navigation_squelettes($self) |
|
| 531 | - . "</div>"; |
|
| 532 | - } else { |
|
| 533 | - $res = ''; |
|
| 534 | - } |
|
| 535 | - if ($fonc) { |
|
| 536 | - $id = " id='$fonc'"; |
|
| 537 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 538 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 539 | - $texte .= $res2; |
|
| 540 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 541 | - $legend = _T('zbug_' . $mode); |
|
| 542 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 543 | - $texte = ancre_texte($texte, array('', '')); |
|
| 544 | - } |
|
| 545 | - } else { |
|
| 546 | - if (strlen(trim($res))) { |
|
| 547 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 548 | - } else { |
|
| 549 | - // cas de l'appel sur erreur: montre la page |
|
| 550 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 551 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 552 | - : ''; |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - } else { |
|
| 556 | - $valider = charger_fonction('valider', 'xml'); |
|
| 557 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 558 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 559 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 560 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 561 | - if ($err === false) { |
|
| 562 | - $err = _T('impossible'); |
|
| 563 | - } elseif ($err === true) { |
|
| 564 | - $err = _T('correcte'); |
|
| 565 | - } else { |
|
| 566 | - $err = ": $err"; |
|
| 567 | - } |
|
| 568 | - $legend = _T('validation') . ' ' . $err; |
|
| 569 | - $res = $id = ''; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return !trim($texte) ? '' : ( |
|
| 573 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 574 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 575 | - . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 576 | - . ($legend ? $legend : $mode) |
|
| 577 | - . "</a></legend>" |
|
| 578 | - . $texte |
|
| 579 | - . "</fieldset></div>" |
|
| 580 | - . "</div>"); |
|
| 525 | + $texte = ''; |
|
| 526 | + |
|
| 527 | + if ($mode !== 'validation') { |
|
| 528 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 529 | + $res = "<div id='spip-boucles'>\n" |
|
| 530 | + . debusquer_navigation_squelettes($self) |
|
| 531 | + . "</div>"; |
|
| 532 | + } else { |
|
| 533 | + $res = ''; |
|
| 534 | + } |
|
| 535 | + if ($fonc) { |
|
| 536 | + $id = " id='$fonc'"; |
|
| 537 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 538 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 539 | + $texte .= $res2; |
|
| 540 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 541 | + $legend = _T('zbug_' . $mode); |
|
| 542 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 543 | + $texte = ancre_texte($texte, array('', '')); |
|
| 544 | + } |
|
| 545 | + } else { |
|
| 546 | + if (strlen(trim($res))) { |
|
| 547 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 548 | + } else { |
|
| 549 | + // cas de l'appel sur erreur: montre la page |
|
| 550 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 551 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 552 | + : ''; |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + } else { |
|
| 556 | + $valider = charger_fonction('valider', 'xml'); |
|
| 557 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 558 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 559 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 560 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 561 | + if ($err === false) { |
|
| 562 | + $err = _T('impossible'); |
|
| 563 | + } elseif ($err === true) { |
|
| 564 | + $err = _T('correcte'); |
|
| 565 | + } else { |
|
| 566 | + $err = ": $err"; |
|
| 567 | + } |
|
| 568 | + $legend = _T('validation') . ' ' . $err; |
|
| 569 | + $res = $id = ''; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return !trim($texte) ? '' : ( |
|
| 573 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 574 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 575 | + . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 576 | + . ($legend ? $legend : $mode) |
|
| 577 | + . "</a></legend>" |
|
| 578 | + . $texte |
|
| 579 | + . "</fieldset></div>" |
|
| 580 | + . "</div>"); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
| 584 | 584 | // https://code.spip.net/@emboite_texte |
| 585 | 585 | function emboite_texte($res, $fonc = '', $self = '') { |
| 586 | - $errs = $res->err; |
|
| 587 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 588 | - |
|
| 589 | - if (!$texte and !$errs) { |
|
| 590 | - return array(ancre_texte('', array('', '')), false); |
|
| 591 | - } |
|
| 592 | - if (!$errs) { |
|
| 593 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 597 | - |
|
| 598 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 599 | - $encore = count_occ($errs); |
|
| 600 | - $encore2 = array(); |
|
| 601 | - $fautifs = array(); |
|
| 602 | - |
|
| 603 | - $err = '<tr><th>' |
|
| 604 | - . _T('numero') |
|
| 605 | - . "</th><th>" |
|
| 606 | - . _T('occurence') |
|
| 607 | - . "</th><th>" |
|
| 608 | - . _T('ligne') |
|
| 609 | - . "</th><th>" |
|
| 610 | - . _T('colonne') |
|
| 611 | - . "</th><th>" |
|
| 612 | - . _T('erreur') |
|
| 613 | - . "</th></tr>"; |
|
| 614 | - |
|
| 615 | - $i = 0; |
|
| 616 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | - foreach ($errs as $r) { |
|
| 618 | - $i++; |
|
| 619 | - list($msg, $ligne, $col) = $r; |
|
| 620 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | - if (isset($encore2[$msg])) { |
|
| 622 | - $ref = ++$encore2[$msg]; |
|
| 623 | - } else { |
|
| 624 | - $encore2[$msg] = $ref = 1; |
|
| 625 | - } |
|
| 626 | - $err .= "<tr style='background-color: " |
|
| 627 | - . $colors[$i % 2] |
|
| 628 | - . "'><td $style><a href='#debut_err'>" |
|
| 629 | - . $i |
|
| 630 | - . "</a></td><td $style>" |
|
| 631 | - . "$ref/$encore[$msg]</td>" |
|
| 632 | - . "<td $style><a href='#L" |
|
| 633 | - . $ligne |
|
| 634 | - . "' id='T$i'>" |
|
| 635 | - . $ligne |
|
| 636 | - . "</a></td><td $style>" |
|
| 637 | - . $col |
|
| 638 | - . "</td><td>$msg</td></tr>\n"; |
|
| 639 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 640 | - } |
|
| 641 | - $err = "<h2 style='text-align: center'>" |
|
| 642 | - . $i |
|
| 643 | - . "<a href='#fin_err'>" |
|
| 644 | - . " " . _T('erreur_texte') |
|
| 645 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | - . $err |
|
| 647 | - . " </table><a id='fin_err'></a>"; |
|
| 648 | - |
|
| 649 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 650 | - } else { |
|
| 651 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | - |
|
| 658 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 659 | - } |
|
| 586 | + $errs = $res->err; |
|
| 587 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 588 | + |
|
| 589 | + if (!$texte and !$errs) { |
|
| 590 | + return array(ancre_texte('', array('', '')), false); |
|
| 591 | + } |
|
| 592 | + if (!$errs) { |
|
| 593 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 597 | + |
|
| 598 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 599 | + $encore = count_occ($errs); |
|
| 600 | + $encore2 = array(); |
|
| 601 | + $fautifs = array(); |
|
| 602 | + |
|
| 603 | + $err = '<tr><th>' |
|
| 604 | + . _T('numero') |
|
| 605 | + . "</th><th>" |
|
| 606 | + . _T('occurence') |
|
| 607 | + . "</th><th>" |
|
| 608 | + . _T('ligne') |
|
| 609 | + . "</th><th>" |
|
| 610 | + . _T('colonne') |
|
| 611 | + . "</th><th>" |
|
| 612 | + . _T('erreur') |
|
| 613 | + . "</th></tr>"; |
|
| 614 | + |
|
| 615 | + $i = 0; |
|
| 616 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | + foreach ($errs as $r) { |
|
| 618 | + $i++; |
|
| 619 | + list($msg, $ligne, $col) = $r; |
|
| 620 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | + if (isset($encore2[$msg])) { |
|
| 622 | + $ref = ++$encore2[$msg]; |
|
| 623 | + } else { |
|
| 624 | + $encore2[$msg] = $ref = 1; |
|
| 625 | + } |
|
| 626 | + $err .= "<tr style='background-color: " |
|
| 627 | + . $colors[$i % 2] |
|
| 628 | + . "'><td $style><a href='#debut_err'>" |
|
| 629 | + . $i |
|
| 630 | + . "</a></td><td $style>" |
|
| 631 | + . "$ref/$encore[$msg]</td>" |
|
| 632 | + . "<td $style><a href='#L" |
|
| 633 | + . $ligne |
|
| 634 | + . "' id='T$i'>" |
|
| 635 | + . $ligne |
|
| 636 | + . "</a></td><td $style>" |
|
| 637 | + . $col |
|
| 638 | + . "</td><td>$msg</td></tr>\n"; |
|
| 639 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 640 | + } |
|
| 641 | + $err = "<h2 style='text-align: center'>" |
|
| 642 | + . $i |
|
| 643 | + . "<a href='#fin_err'>" |
|
| 644 | + . " " . _T('erreur_texte') |
|
| 645 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | + . $err |
|
| 647 | + . " </table><a id='fin_err'></a>"; |
|
| 648 | + |
|
| 649 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 650 | + } else { |
|
| 651 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | + $err = $msg . |
|
| 655 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | + |
|
| 658 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | // https://code.spip.net/@count_occ |
| 663 | 663 | function count_occ($regs) { |
| 664 | - $encore = array(); |
|
| 665 | - foreach ($regs as $r) { |
|
| 666 | - if (isset($encore[$r[0]])) { |
|
| 667 | - $encore[$r[0]]++; |
|
| 668 | - } else { |
|
| 669 | - $encore[$r[0]] = 1; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $encore; |
|
| 664 | + $encore = array(); |
|
| 665 | + foreach ($regs as $r) { |
|
| 666 | + if (isset($encore[$r[0]])) { |
|
| 667 | + $encore[$r[0]]++; |
|
| 668 | + } else { |
|
| 669 | + $encore[$r[0]] = 1; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $encore; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | function debusquer_navigation_squelettes($self) { |
| 677 | 677 | |
| 678 | - $res = ''; |
|
| 679 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | - $t_skel = _T('squelette'); |
|
| 682 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 686 | - array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 687 | - |
|
| 688 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 689 | - . $t_skel |
|
| 690 | - . ' ' |
|
| 691 | - . $sourcefile |
|
| 692 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 693 | - . $t_skel |
|
| 694 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 695 | - . _T('zbug_resultat') |
|
| 696 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 697 | - . _T('zbug_code') |
|
| 698 | - . "</a>\n<a href='" |
|
| 699 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 700 | - . "'>" |
|
| 701 | - . _T('zbug_calcul') |
|
| 702 | - . "</a></legend>" |
|
| 703 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 704 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 705 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 706 | - . "</fieldset>\n"; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return $res; |
|
| 678 | + $res = ''; |
|
| 679 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | + $t_skel = _T('squelette'); |
|
| 682 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 686 | + array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 687 | + |
|
| 688 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 689 | + . $t_skel |
|
| 690 | + . ' ' |
|
| 691 | + . $sourcefile |
|
| 692 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 693 | + . $t_skel |
|
| 694 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 695 | + . _T('zbug_resultat') |
|
| 696 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 697 | + . _T('zbug_code') |
|
| 698 | + . "</a>\n<a href='" |
|
| 699 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 700 | + . "'>" |
|
| 701 | + . _T('zbug_calcul') |
|
| 702 | + . "</a></legend>" |
|
| 703 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 704 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 705 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 706 | + . "</fieldset>\n"; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return $res; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 713 | - $i = 0; |
|
| 714 | - $res = ''; |
|
| 715 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 716 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 717 | - |
|
| 718 | - foreach ($boucles as $objet => $boucle) { |
|
| 719 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 720 | - $i++; |
|
| 721 | - $nom = $boucle->id_boucle; |
|
| 722 | - $req = $boucle->type_requete; |
|
| 723 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 724 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 725 | - |
|
| 726 | - $res .= "\n<tr style='background-color: " . |
|
| 727 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 728 | - "'><td align='right'>$i</td><td>\n" . |
|
| 729 | - "<a class='debug_link_boucle' href='" . |
|
| 730 | - $self2 . |
|
| 731 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 732 | - _T('zbug_boucle') . |
|
| 733 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 734 | - $self2 . |
|
| 735 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 736 | - _T('zbug_resultat') . |
|
| 737 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 738 | - $self2 . |
|
| 739 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 740 | - _T('zbug_code') . |
|
| 741 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 742 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 743 | - "'>" . |
|
| 744 | - _T('zbug_calcul') . |
|
| 745 | - "</a></td><td>\n" . |
|
| 746 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 747 | - "</td><td>\n" . |
|
| 748 | - $req . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - spip_htmlspecialchars($crit) . |
|
| 751 | - "</td></tr>"; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - return $res; |
|
| 713 | + $i = 0; |
|
| 714 | + $res = ''; |
|
| 715 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 716 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 717 | + |
|
| 718 | + foreach ($boucles as $objet => $boucle) { |
|
| 719 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 720 | + $i++; |
|
| 721 | + $nom = $boucle->id_boucle; |
|
| 722 | + $req = $boucle->type_requete; |
|
| 723 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 724 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 725 | + |
|
| 726 | + $res .= "\n<tr style='background-color: " . |
|
| 727 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 728 | + "'><td align='right'>$i</td><td>\n" . |
|
| 729 | + "<a class='debug_link_boucle' href='" . |
|
| 730 | + $self2 . |
|
| 731 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 732 | + _T('zbug_boucle') . |
|
| 733 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 734 | + $self2 . |
|
| 735 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 736 | + _T('zbug_resultat') . |
|
| 737 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 738 | + $self2 . |
|
| 739 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 740 | + _T('zbug_code') . |
|
| 741 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 742 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 743 | + "'>" . |
|
| 744 | + _T('zbug_calcul') . |
|
| 745 | + "</a></td><td>\n" . |
|
| 746 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 747 | + "</td><td>\n" . |
|
| 748 | + $req . |
|
| 749 | + "</td><td>\n" . |
|
| 750 | + spip_htmlspecialchars($crit) . |
|
| 751 | + "</td></tr>"; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + return $res; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | function debusquer_source($objet, $affiche) { |
| 759 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 760 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 761 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 762 | - } else { |
|
| 763 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 764 | - } |
|
| 765 | - $res2 = ""; |
|
| 766 | - |
|
| 767 | - if ($affiche == 'resultat') { |
|
| 768 | - $legend = $nom; |
|
| 769 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 770 | - if (function_exists('_mysql_traite_query')) { |
|
| 771 | - $c = strtolower(_request('connect')); |
|
| 772 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 773 | - $req = _mysql_traite_query($req, '', $c); |
|
| 774 | - } |
|
| 775 | - // permettre le copier/coller facile |
|
| 776 | - // $res = ancre_texte($req, array(), true); |
|
| 777 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 778 | - // formatage et affichage des resultats bruts de la requete |
|
| 779 | - $ress_req = spip_query($req); |
|
| 780 | - $brut_sql = ''; |
|
| 781 | - $num = 1; |
|
| 782 | - // eviter l'affichage de milliers de lignes |
|
| 783 | - // personnalisation possible dans mes_options |
|
| 784 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 785 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 786 | - if ($num <= $max_aff) { |
|
| 787 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 788 | - $brut_sql .= "<p>"; |
|
| 789 | - foreach ($retours_sql as $key => $val) { |
|
| 790 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 791 | - } |
|
| 792 | - $brut_sql .= "</p>"; |
|
| 793 | - } |
|
| 794 | - $num++; |
|
| 795 | - } |
|
| 796 | - $res2 = interdire_scripts($brut_sql); |
|
| 797 | - foreach ($quoi as $view) { |
|
| 798 | - // ne pas afficher les $contexte_inclus |
|
| 799 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 800 | - if ($view) { |
|
| 801 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - } elseif ($affiche == 'code') { |
|
| 806 | - $legend = $nom; |
|
| 807 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 808 | - } elseif ($affiche == 'boucle') { |
|
| 809 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 810 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 811 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 812 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 813 | - } elseif ($affiche == 'squelette') { |
|
| 814 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 815 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return array($legend, $res, $res2); |
|
| 759 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 760 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 761 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 762 | + } else { |
|
| 763 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 764 | + } |
|
| 765 | + $res2 = ""; |
|
| 766 | + |
|
| 767 | + if ($affiche == 'resultat') { |
|
| 768 | + $legend = $nom; |
|
| 769 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 770 | + if (function_exists('_mysql_traite_query')) { |
|
| 771 | + $c = strtolower(_request('connect')); |
|
| 772 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 773 | + $req = _mysql_traite_query($req, '', $c); |
|
| 774 | + } |
|
| 775 | + // permettre le copier/coller facile |
|
| 776 | + // $res = ancre_texte($req, array(), true); |
|
| 777 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 778 | + // formatage et affichage des resultats bruts de la requete |
|
| 779 | + $ress_req = spip_query($req); |
|
| 780 | + $brut_sql = ''; |
|
| 781 | + $num = 1; |
|
| 782 | + // eviter l'affichage de milliers de lignes |
|
| 783 | + // personnalisation possible dans mes_options |
|
| 784 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 785 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 786 | + if ($num <= $max_aff) { |
|
| 787 | + $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 788 | + $brut_sql .= "<p>"; |
|
| 789 | + foreach ($retours_sql as $key => $val) { |
|
| 790 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 791 | + } |
|
| 792 | + $brut_sql .= "</p>"; |
|
| 793 | + } |
|
| 794 | + $num++; |
|
| 795 | + } |
|
| 796 | + $res2 = interdire_scripts($brut_sql); |
|
| 797 | + foreach ($quoi as $view) { |
|
| 798 | + // ne pas afficher les $contexte_inclus |
|
| 799 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 800 | + if ($view) { |
|
| 801 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + } elseif ($affiche == 'code') { |
|
| 806 | + $legend = $nom; |
|
| 807 | + $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 808 | + } elseif ($affiche == 'boucle') { |
|
| 809 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 810 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 811 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 812 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 813 | + } elseif ($affiche == 'squelette') { |
|
| 814 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 815 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return array($legend, $res, $res2); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | // https://code.spip.net/@debusquer_entete |
| 822 | 822 | function debusquer_entete($titre, $corps) { |
| 823 | 823 | |
| 824 | - include_spip('balise/formulaire_admin'); |
|
| 825 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 826 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 827 | - |
|
| 828 | - return _DOCTYPE_ECRIRE . |
|
| 829 | - html_lang_attributes() . |
|
| 830 | - "<head>\n<title>" . |
|
| 831 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 832 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 833 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 834 | - ")</title>\n" . |
|
| 835 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 836 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 837 | - "' />\n" . |
|
| 838 | - http_script('', 'jquery.js') |
|
| 839 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 840 | - . "' type='text/css' />" . |
|
| 841 | - "</head>\n" . |
|
| 842 | - "<body style='margin:0 10px;'>\n" . |
|
| 843 | - "<div id='spip-debug-header'>" . |
|
| 844 | - $corps . |
|
| 845 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 846 | - '</div></body></html>'; |
|
| 824 | + include_spip('balise/formulaire_admin'); |
|
| 825 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 826 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 827 | + |
|
| 828 | + return _DOCTYPE_ECRIRE . |
|
| 829 | + html_lang_attributes() . |
|
| 830 | + "<head>\n<title>" . |
|
| 831 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 832 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 833 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 834 | + ")</title>\n" . |
|
| 835 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 836 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 837 | + "' />\n" . |
|
| 838 | + http_script('', 'jquery.js') |
|
| 839 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 840 | + . "' type='text/css' />" . |
|
| 841 | + "</head>\n" . |
|
| 842 | + "<body style='margin:0 10px;'>\n" . |
|
| 843 | + "<div id='spip-debug-header'>" . |
|
| 844 | + $corps . |
|
| 845 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 846 | + '</div></body></html>'; |
|
| 847 | 847 | } |