@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $test_dir .= '/'; |
| 82 | 82 | } |
| 83 | 83 | if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
| 84 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | + $GLOBALS['test_dirs'][] = _DIR_RACINE.$test_dir; |
|
| 85 | 85 | } |
| 86 | 86 | } else { |
| 87 | 87 | if (!_FILE_CONNECT) { |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
| 97 | 97 | $test = test_ecrire($my_dir); |
| 98 | 98 | if (!$test) { |
| 99 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | + $m = preg_replace(',^'._DIR_RACINE.',', '', $my_dir); |
|
| 100 | 100 | if (@file_exists($my_dir)) { |
| 101 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | + $bad_dirs['<li>'.$m.'</li>'] = 1; |
|
| 102 | 102 | } else { |
| 103 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | + $absent_dirs['<li>'.$m.'</li>'] = 1; |
|
| 104 | 104 | } |
| 105 | 105 | } else { |
| 106 | 106 | $chmod = max($chmod, $test); |
@@ -110,21 +110,21 @@ discard block |
||
| 110 | 110 | if ($bad_dirs or $absent_dirs) { |
| 111 | 111 | if (!_FILE_CONNECT) { |
| 112 | 112 | $titre = _T('dirs_preliminaire'); |
| 113 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | + $continuer = ' '._T('dirs_commencer').'.'; |
|
| 114 | 114 | } else { |
| 115 | 115 | $titre = _T('dirs_probleme_droits'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | + $res = "<div align='right'>".menu_langues('var_lang_ecrire')."</div>\n"; |
|
| 120 | 120 | |
| 121 | 121 | if ($bad_dirs) { |
| 122 | 122 | $res .= |
| 123 | 123 | _T( |
| 124 | 124 | 'dirs_repertoires_suivants', |
| 125 | 125 | ['bad_dirs' => join("\n", array_keys($bad_dirs))] |
| 126 | - ) . |
|
| 127 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 126 | + ). |
|
| 127 | + '<b>'._T('login_recharger').'</b>.'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ($absent_dirs) { |
@@ -132,22 +132,21 @@ discard block |
||
| 132 | 132 | _T( |
| 133 | 133 | 'dirs_repertoires_absents', |
| 134 | 134 | ['bad_dirs' => join("\n", array_keys($absent_dirs))] |
| 135 | - ) . |
|
| 136 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 135 | + ). |
|
| 136 | + '<b>'._T('login_recharger').'</b>.'; |
|
| 137 | 137 | } |
| 138 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | + $res = '<p>'.$continuer.$res.aider('install0', true).'</p>'; |
|
| 139 | 139 | |
| 140 | 140 | $t = _T('login_recharger'); |
| 141 | - $t = (!$test_dir ? '' : |
|
| 142 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 141 | + $t = (!$test_dir ? '' : "<input type='hidden' name='test_dir' value='".spip_htmlspecialchars($test_dir, ENT_QUOTES)."' />") |
|
| 143 | 142 | . "<input type='hidden' name='etape' value='chmod' />" |
| 144 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 143 | + . "<div style='text-align: right'><input type='submit' value='".attribut_html($t)."' /></div>"; |
|
| 145 | 144 | |
| 146 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 145 | + echo minipres($titre, $res.generer_form_ecrire('install', $t)); |
|
| 147 | 146 | } else { |
| 148 | 147 | $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
| 149 | 148 | if (!$deja) { |
| 150 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 149 | + redirige_url_ecrire('install', 'etape=1&chmod='.$chmod); |
|
| 151 | 150 | } else { |
| 152 | 151 | redirige_url_ecrire(); |
| 153 | 152 | } |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | if (defined('_TEST_DIRS')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | define('_TEST_DIRS', '1'); |
| 21 | 21 | |
@@ -26,42 +26,42 @@ discard block |
||
| 26 | 26 | // Tente d'ecrire |
| 27 | 27 | // |
| 28 | 28 | function test_ecrire($my_dir) { |
| 29 | - static $chmod = 0; |
|
| 30 | - |
|
| 31 | - $ok = false; |
|
| 32 | - $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 33 | - $self = basename($script); |
|
| 34 | - $uid = @fileowner('.'); |
|
| 35 | - $uid2 = @fileowner($self); |
|
| 36 | - $gid = @filegroup('.'); |
|
| 37 | - $gid2 = @filegroup($self); |
|
| 38 | - $perms = @fileperms($self); |
|
| 39 | - |
|
| 40 | - // Comparer l'appartenance d'un fichier cree par PHP |
|
| 41 | - // avec celle du script et du repertoire courant |
|
| 42 | - if (!$chmod) { |
|
| 43 | - @rmdir('test'); |
|
| 44 | - spip_unlink('test'); // effacer au cas ou |
|
| 45 | - @touch('test'); |
|
| 46 | - if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 47 | - $chmod = 0700; |
|
| 48 | - } else { |
|
| 49 | - if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 50 | - $chmod = 0770; |
|
| 51 | - } else { |
|
| 52 | - $chmod = 0777; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - // Appliquer de plus les droits d'acces du script |
|
| 56 | - if ($perms > 0) { |
|
| 57 | - $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 58 | - $chmod |= $perms; |
|
| 59 | - } |
|
| 60 | - spip_unlink('test'); |
|
| 61 | - } |
|
| 62 | - $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 63 | - |
|
| 64 | - return $ok ? $chmod : false; |
|
| 29 | + static $chmod = 0; |
|
| 30 | + |
|
| 31 | + $ok = false; |
|
| 32 | + $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 33 | + $self = basename($script); |
|
| 34 | + $uid = @fileowner('.'); |
|
| 35 | + $uid2 = @fileowner($self); |
|
| 36 | + $gid = @filegroup('.'); |
|
| 37 | + $gid2 = @filegroup($self); |
|
| 38 | + $perms = @fileperms($self); |
|
| 39 | + |
|
| 40 | + // Comparer l'appartenance d'un fichier cree par PHP |
|
| 41 | + // avec celle du script et du repertoire courant |
|
| 42 | + if (!$chmod) { |
|
| 43 | + @rmdir('test'); |
|
| 44 | + spip_unlink('test'); // effacer au cas ou |
|
| 45 | + @touch('test'); |
|
| 46 | + if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 47 | + $chmod = 0700; |
|
| 48 | + } else { |
|
| 49 | + if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 50 | + $chmod = 0770; |
|
| 51 | + } else { |
|
| 52 | + $chmod = 0777; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + // Appliquer de plus les droits d'acces du script |
|
| 56 | + if ($perms > 0) { |
|
| 57 | + $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 58 | + $chmod |= $perms; |
|
| 59 | + } |
|
| 60 | + spip_unlink('test'); |
|
| 61 | + } |
|
| 62 | + $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 63 | + |
|
| 64 | + return $ok ? $chmod : false; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // |
@@ -71,84 +71,84 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | function install_etape_chmod_dist() { |
| 73 | 73 | |
| 74 | - $continuer = null; |
|
| 75 | - $test_dir = _request('test_dir'); |
|
| 76 | - $chmod = 0; |
|
| 77 | - |
|
| 78 | - if ($test_dir and strpos($test_dir, '..') === false) { |
|
| 79 | - if (substr($test_dir, -1) !== '/') { |
|
| 80 | - $test_dir .= '/'; |
|
| 81 | - } |
|
| 82 | - if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 83 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | - } |
|
| 85 | - } else { |
|
| 86 | - if (!_FILE_CONNECT) { |
|
| 87 | - $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 88 | - $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $bad_dirs = []; |
|
| 93 | - $absent_dirs = []; |
|
| 94 | - |
|
| 95 | - foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 96 | - $test = test_ecrire($my_dir); |
|
| 97 | - if (!$test) { |
|
| 98 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | - if (@file_exists($my_dir)) { |
|
| 100 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | - } else { |
|
| 102 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $chmod = max($chmod, $test); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($bad_dirs or $absent_dirs) { |
|
| 110 | - if (!_FILE_CONNECT) { |
|
| 111 | - $titre = _T('dirs_preliminaire'); |
|
| 112 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | - } else { |
|
| 114 | - $titre = _T('dirs_probleme_droits'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | - |
|
| 120 | - if ($bad_dirs) { |
|
| 121 | - $res .= |
|
| 122 | - _T( |
|
| 123 | - 'dirs_repertoires_suivants', |
|
| 124 | - ['bad_dirs' => join("\n", array_keys($bad_dirs))] |
|
| 125 | - ) . |
|
| 126 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($absent_dirs) { |
|
| 130 | - $res .= |
|
| 131 | - _T( |
|
| 132 | - 'dirs_repertoires_absents', |
|
| 133 | - ['bad_dirs' => join("\n", array_keys($absent_dirs))] |
|
| 134 | - ) . |
|
| 135 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 136 | - } |
|
| 137 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | - |
|
| 139 | - $t = _T('login_recharger'); |
|
| 140 | - $t = (!$test_dir ? '' : |
|
| 141 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 142 | - . "<input type='hidden' name='etape' value='chmod' />" |
|
| 143 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 144 | - |
|
| 145 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 146 | - } else { |
|
| 147 | - $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 148 | - if (!$deja) { |
|
| 149 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 150 | - } else { |
|
| 151 | - redirige_url_ecrire(); |
|
| 152 | - } |
|
| 153 | - } |
|
| 74 | + $continuer = null; |
|
| 75 | + $test_dir = _request('test_dir'); |
|
| 76 | + $chmod = 0; |
|
| 77 | + |
|
| 78 | + if ($test_dir and strpos($test_dir, '..') === false) { |
|
| 79 | + if (substr($test_dir, -1) !== '/') { |
|
| 80 | + $test_dir .= '/'; |
|
| 81 | + } |
|
| 82 | + if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 83 | + $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | + } |
|
| 85 | + } else { |
|
| 86 | + if (!_FILE_CONNECT) { |
|
| 87 | + $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 88 | + $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $bad_dirs = []; |
|
| 93 | + $absent_dirs = []; |
|
| 94 | + |
|
| 95 | + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 96 | + $test = test_ecrire($my_dir); |
|
| 97 | + if (!$test) { |
|
| 98 | + $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | + if (@file_exists($my_dir)) { |
|
| 100 | + $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | + } else { |
|
| 102 | + $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $chmod = max($chmod, $test); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($bad_dirs or $absent_dirs) { |
|
| 110 | + if (!_FILE_CONNECT) { |
|
| 111 | + $titre = _T('dirs_preliminaire'); |
|
| 112 | + $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | + } else { |
|
| 114 | + $titre = _T('dirs_probleme_droits'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | + |
|
| 120 | + if ($bad_dirs) { |
|
| 121 | + $res .= |
|
| 122 | + _T( |
|
| 123 | + 'dirs_repertoires_suivants', |
|
| 124 | + ['bad_dirs' => join("\n", array_keys($bad_dirs))] |
|
| 125 | + ) . |
|
| 126 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($absent_dirs) { |
|
| 130 | + $res .= |
|
| 131 | + _T( |
|
| 132 | + 'dirs_repertoires_absents', |
|
| 133 | + ['bad_dirs' => join("\n", array_keys($absent_dirs))] |
|
| 134 | + ) . |
|
| 135 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 136 | + } |
|
| 137 | + $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | + |
|
| 139 | + $t = _T('login_recharger'); |
|
| 140 | + $t = (!$test_dir ? '' : |
|
| 141 | + "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 142 | + . "<input type='hidden' name='etape' value='chmod' />" |
|
| 143 | + . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 144 | + |
|
| 145 | + echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 146 | + } else { |
|
| 147 | + $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 148 | + if (!$deja) { |
|
| 149 | + redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 150 | + } else { |
|
| 151 | + redirige_url_ecrire(); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | // creer le repertoire cache, qui sert partout ! |
| 46 | 46 | // deja fait en etape 4 en principe, on garde au cas ou |
| 47 | 47 | if (!@file_exists(_DIR_CACHE)) { |
| 48 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 48 | + $rep = preg_replace(','._DIR_TMP.',', '', _DIR_CACHE); |
|
| 49 | 49 | $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if ($msg) { |
| 56 | 56 | $cible = _T('public:accueil_site'); |
| 57 | 57 | $cible = generer_form_ecrire('accueil', '', '', $cible); |
| 58 | - echo minipres('AUTO', $msg . $cible); |
|
| 58 | + echo minipres('AUTO', $msg.$cible); |
|
| 59 | 59 | // ok, deboucher dans l'espace prive |
| 60 | 60 | } else { |
| 61 | 61 | redirige_url_ecrire('accueil'); |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $averti = _T( |
| 76 | 76 | 'htaccess_a_simuler', |
| 77 | 77 | [ |
| 78 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 78 | + 'htaccess' => '<tt>'._ACCESS_FILE_NAME.'</tt>', |
|
| 79 | 79 | 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
| 80 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 80 | + 'document_root' => '<tt>'.$_SERVER['DOCUMENT_ROOT'].'</tt>' |
|
| 81 | 81 | ] |
| 82 | 82 | ); |
| 83 | 83 | |
@@ -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'); |
@@ -20,65 +20,65 @@ discard block |
||
| 20 | 20 | // Mise en place des fichiers de configuration si ce n'est fait |
| 21 | 21 | |
| 22 | 22 | function install_etape_fin_dist() { |
| 23 | - ecrire_acces(); |
|
| 23 | + ecrire_acces(); |
|
| 24 | 24 | |
| 25 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 26 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 27 | - if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 28 | - if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | - spip_unlink(_FILE_CHMOD_TMP); |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - } |
|
| 25 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 26 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 27 | + if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 28 | + if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | + spip_unlink(_FILE_CHMOD_TMP); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 35 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 36 | - spip_log("renomme $f"); |
|
| 37 | - if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 38 | - if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | - @spip_unlink(_FILE_CONNECT_TMP); |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - } |
|
| 34 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 35 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 36 | + spip_log("renomme $f"); |
|
| 37 | + if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 38 | + if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | + @spip_unlink(_FILE_CONNECT_TMP); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // creer le repertoire cache, qui sert partout ! |
|
| 45 | - // deja fait en etape 4 en principe, on garde au cas ou |
|
| 46 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 47 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 48 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 49 | - } |
|
| 44 | + // creer le repertoire cache, qui sert partout ! |
|
| 45 | + // deja fait en etape 4 en principe, on garde au cas ou |
|
| 46 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 47 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 48 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - // Verifier la securite des htaccess |
|
| 52 | - // Si elle ne fonctionne pas, prevenir |
|
| 53 | - $msg = install_verifier_htaccess(); |
|
| 54 | - if ($msg) { |
|
| 55 | - $cible = _T('public:accueil_site'); |
|
| 56 | - $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 57 | - echo minipres('AUTO', $msg . $cible); |
|
| 58 | - // ok, deboucher dans l'espace prive |
|
| 59 | - } else { |
|
| 60 | - redirige_url_ecrire('accueil'); |
|
| 61 | - } |
|
| 51 | + // Verifier la securite des htaccess |
|
| 52 | + // Si elle ne fonctionne pas, prevenir |
|
| 53 | + $msg = install_verifier_htaccess(); |
|
| 54 | + if ($msg) { |
|
| 55 | + $cible = _T('public:accueil_site'); |
|
| 56 | + $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 57 | + echo minipres('AUTO', $msg . $cible); |
|
| 58 | + // ok, deboucher dans l'espace prive |
|
| 59 | + } else { |
|
| 60 | + redirige_url_ecrire('accueil'); |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | function install_verifier_htaccess() { |
| 65 | - if ( |
|
| 66 | - verifier_htaccess(_DIR_TMP, true) |
|
| 67 | - and verifier_htaccess(_DIR_CONNECT, true) |
|
| 68 | - ) { |
|
| 69 | - return ''; |
|
| 70 | - } |
|
| 65 | + if ( |
|
| 66 | + 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 | - [ |
|
| 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 | + [ |
|
| 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 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // creer le repertoire cache, qui sert partout ! |
| 23 | 23 | if (!@file_exists(_DIR_CACHE)) { |
| 24 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 24 | + $rep = preg_replace(','._DIR_TMP.',', '', _DIR_CACHE); |
|
| 25 | 25 | $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | echo '<p>' |
| 40 | 40 | . _T( |
| 41 | 41 | 'plugin_info_plugins_dist_1', |
| 42 | - ['plugins_dist' => '<tt>' . joli_repertoire(_DIR_PLUGINS_DIST) . '</tt>'] |
|
| 42 | + ['plugins_dist' => '<tt>'.joli_repertoire(_DIR_PLUGINS_DIST).'</tt>'] |
|
| 43 | 43 | ) |
| 44 | 44 | . '</p>'; |
| 45 | 45 | |
@@ -11,69 +11,69 @@ |
||
| 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'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_4_dist() { |
| 20 | 20 | |
| 21 | - // creer le repertoire cache, qui sert partout ! |
|
| 22 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 23 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 24 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 25 | - } |
|
| 21 | + // creer le repertoire cache, qui sert partout ! |
|
| 22 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 23 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 24 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 29 | - echo info_progression_etape(4, 'etape_', 'install/'); |
|
| 28 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 29 | + echo info_progression_etape(4, 'etape_', 'install/'); |
|
| 30 | 30 | |
| 31 | - echo "<div class='success'><b>" |
|
| 32 | - . _T('info_derniere_etape') |
|
| 33 | - . '</b><p>' |
|
| 34 | - . _T('info_utilisation_spip') |
|
| 35 | - . '</p></div>'; |
|
| 31 | + echo "<div class='success'><b>" |
|
| 32 | + . _T('info_derniere_etape') |
|
| 33 | + . '</b><p>' |
|
| 34 | + . _T('info_utilisation_spip') |
|
| 35 | + . '</p></div>'; |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - echo '<p>' |
|
| 39 | - . _T( |
|
| 40 | - 'plugin_info_plugins_dist_1', |
|
| 41 | - ['plugins_dist' => '<tt>' . joli_repertoire(_DIR_PLUGINS_DIST) . '</tt>'] |
|
| 42 | - ) |
|
| 43 | - . '</p>'; |
|
| 38 | + echo '<p>' |
|
| 39 | + . _T( |
|
| 40 | + 'plugin_info_plugins_dist_1', |
|
| 41 | + ['plugins_dist' => '<tt>' . joli_repertoire(_DIR_PLUGINS_DIST) . '</tt>'] |
|
| 42 | + ) |
|
| 43 | + . '</p>'; |
|
| 44 | 44 | |
| 45 | - // installer les extensions |
|
| 46 | - include_spip('inc/plugin'); |
|
| 47 | - $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 48 | - echo $afficher( |
|
| 49 | - self(), |
|
| 50 | - liste_plugin_files(_DIR_PLUGINS_DIST), |
|
| 51 | - [], |
|
| 52 | - [], |
|
| 53 | - _DIR_PLUGINS_DIST, |
|
| 54 | - 'afficher_nom_plugin' |
|
| 55 | - ); |
|
| 45 | + // installer les extensions |
|
| 46 | + include_spip('inc/plugin'); |
|
| 47 | + $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 48 | + echo $afficher( |
|
| 49 | + self(), |
|
| 50 | + liste_plugin_files(_DIR_PLUGINS_DIST), |
|
| 51 | + [], |
|
| 52 | + [], |
|
| 53 | + _DIR_PLUGINS_DIST, |
|
| 54 | + 'afficher_nom_plugin' |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - // si la base de SPIP est up, on peut installer les plugins, sinon on passe cette etape |
|
| 58 | - // car les plugins supposent que la base de SPIP est dans son etat normal (mise a jour) |
|
| 59 | - // au premier passage dans l'espace prive on aura une demande d'upgrade qui se poursuit sur la page plugin |
|
| 60 | - // et procede alors a l'installation |
|
| 61 | - if ( |
|
| 62 | - !isset($GLOBALS['meta']['version_installee']) |
|
| 63 | - or ($GLOBALS['spip_version_base'] == (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 64 | - ) { |
|
| 65 | - plugin_installes_meta(); |
|
| 66 | - } |
|
| 57 | + // si la base de SPIP est up, on peut installer les plugins, sinon on passe cette etape |
|
| 58 | + // car les plugins supposent que la base de SPIP est dans son etat normal (mise a jour) |
|
| 59 | + // au premier passage dans l'espace prive on aura une demande d'upgrade qui se poursuit sur la page plugin |
|
| 60 | + // et procede alors a l'installation |
|
| 61 | + if ( |
|
| 62 | + !isset($GLOBALS['meta']['version_installee']) |
|
| 63 | + or ($GLOBALS['spip_version_base'] == (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 64 | + ) { |
|
| 65 | + plugin_installes_meta(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // mettre a jour si necessaire l'adresse du site |
|
| 69 | - // securite si on arrive plus a se loger |
|
| 70 | - include_spip('inc/config'); |
|
| 71 | - appliquer_adresse_site(''); |
|
| 68 | + // mettre a jour si necessaire l'adresse du site |
|
| 69 | + // securite si on arrive plus a se loger |
|
| 70 | + include_spip('inc/config'); |
|
| 71 | + appliquer_adresse_site(''); |
|
| 72 | 72 | |
| 73 | - // aller a la derniere etape qui clos l'install et redirige |
|
| 74 | - $suite = "\n<input type='hidden' name='etape' value='fin' />" |
|
| 75 | - . bouton_suivant(_T('login_espace_prive')); |
|
| 73 | + // aller a la derniere etape qui clos l'install et redirige |
|
| 74 | + $suite = "\n<input type='hidden' name='etape' value='fin' />" |
|
| 75 | + . bouton_suivant(_T('login_espace_prive')); |
|
| 76 | 76 | |
| 77 | - echo generer_form_ecrire('install', $suite); |
|
| 78 | - echo install_fin_html(); |
|
| 77 | + echo generer_form_ecrire('install', $suite); |
|
| 78 | + echo install_fin_html(); |
|
| 79 | 79 | } |
@@ -52,29 +52,28 @@ discard block |
||
| 52 | 52 | $conn = "\$GLOBALS['ldap_base'] = '$base_ldap';\n" |
| 53 | 53 | . "\$GLOBALS['ldap_link'] = @ldap_connect('$adresse_ldap','$port_ldap');\n" |
| 54 | 54 | . "@ldap_set_option(\$GLOBALS['ldap_link'],LDAP_OPT_PROTOCOL_VERSION,'$protocole_ldap');\n" |
| 55 | - . (($tls_ldap != 'oui') ? '' : |
|
| 56 | - "@ldap_start_tls(\$GLOBALS['ldap_link']);\n") |
|
| 55 | + . (($tls_ldap != 'oui') ? '' : "@ldap_start_tls(\$GLOBALS['ldap_link']);\n") |
|
| 57 | 56 | . "@ldap_bind(\$GLOBALS['ldap_link'],'$login_ldap','$pass_ldap');\n"; |
| 58 | 57 | |
| 59 | 58 | $champs = is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : []; |
| 60 | 59 | $res = ''; |
| 61 | 60 | foreach ($champs as $champ => $v) { |
| 62 | - $nom = 'ldap_' . $champ; |
|
| 61 | + $nom = 'ldap_'.$champ; |
|
| 63 | 62 | $val = trim(_request($nom)); |
| 64 | 63 | if (preg_match('/^\w*$/', $val)) { |
| 65 | 64 | if ($val) { |
| 66 | 65 | $val = _q($val); |
| 67 | 66 | } |
| 68 | 67 | } else { |
| 69 | - $val = 'array(' . _q(preg_split('/\W+/', $val)) . ')'; |
|
| 68 | + $val = 'array('._q(preg_split('/\W+/', $val)).')'; |
|
| 70 | 69 | }; |
| 71 | 70 | if ($val) { |
| 72 | - $res .= "'$champ' => " . $val . ','; |
|
| 71 | + $res .= "'$champ' => ".$val.','; |
|
| 73 | 72 | } |
| 74 | 73 | } |
| 75 | 74 | $conn .= "\$GLOBALS['ldap_champs'] = array($res);\n"; |
| 76 | 75 | |
| 77 | - install_fichier_connexion(_DIR_CONNECT . _FILE_LDAP, $conn); |
|
| 76 | + install_fichier_connexion(_DIR_CONNECT._FILE_LDAP, $conn); |
|
| 78 | 77 | } |
| 79 | 78 | |
| 80 | 79 | function etape_ldap5_suite() { |
@@ -87,7 +86,7 @@ discard block |
||
| 87 | 86 | ); |
| 88 | 87 | |
| 89 | 88 | echo generer_form_ecrire('install', ( |
| 90 | - "<input type='hidden' name='etape' value='3' />" . |
|
| 89 | + "<input type='hidden' name='etape' value='3' />". |
|
| 91 | 90 | "<input type='hidden' name='ldap_present' value='true' />" |
| 92 | 91 | . bouton_suivant())); |
| 93 | 92 | |
@@ -11,84 +11,84 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | include_spip('inc/headers'); |
| 17 | 17 | include_spip('auth/ldap'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_ldap5_dist() { |
| 20 | - etape_ldap5_save(); |
|
| 21 | - etape_ldap5_suite(); |
|
| 20 | + etape_ldap5_save(); |
|
| 21 | + etape_ldap5_suite(); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function etape_ldap5_save() { |
| 25 | - $conn = null; |
|
| 26 | - if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 27 | - redirige_url_ecrire('install'); |
|
| 28 | - } |
|
| 25 | + $conn = null; |
|
| 26 | + if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 27 | + redirige_url_ecrire('install'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - ecrire_meta('ldap_statut_import', _request('statut_ldap')); |
|
| 30 | + ecrire_meta('ldap_statut_import', _request('statut_ldap')); |
|
| 31 | 31 | |
| 32 | - lire_fichier(_FILE_CONNECT_TMP, $conn); |
|
| 32 | + lire_fichier(_FILE_CONNECT_TMP, $conn); |
|
| 33 | 33 | |
| 34 | - if ($p = strpos($conn, "'');")) { |
|
| 35 | - ecrire_fichier( |
|
| 36 | - _FILE_CONNECT_TMP, |
|
| 37 | - substr($conn, 0, $p + 1) |
|
| 38 | - . _FILE_LDAP |
|
| 39 | - . substr($conn, $p + 1) |
|
| 40 | - ); |
|
| 41 | - } |
|
| 34 | + if ($p = strpos($conn, "'');")) { |
|
| 35 | + ecrire_fichier( |
|
| 36 | + _FILE_CONNECT_TMP, |
|
| 37 | + substr($conn, 0, $p + 1) |
|
| 38 | + . _FILE_LDAP |
|
| 39 | + . substr($conn, $p + 1) |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $adresse_ldap = addcslashes(_request('adresse_ldap'), "'\\"); |
|
| 44 | - $login_ldap = addcslashes(_request('login_ldap'), "'\\"); |
|
| 45 | - $pass_ldap = addcslashes(_request('pass_ldap'), "'\\"); |
|
| 46 | - $port_ldap = addcslashes(_request('port_ldap'), "'\\"); |
|
| 47 | - $tls_ldap = addcslashes(_request('tls_ldap'), "'\\"); |
|
| 48 | - $protocole_ldap = addcslashes(_request('protocole_ldap'), "'\\"); |
|
| 49 | - $base_ldap = addcslashes(_request('base_ldap'), "'\\"); |
|
| 50 | - $base_ldap_text = addcslashes(_request('base_ldap_text'), "'\\"); |
|
| 43 | + $adresse_ldap = addcslashes(_request('adresse_ldap'), "'\\"); |
|
| 44 | + $login_ldap = addcslashes(_request('login_ldap'), "'\\"); |
|
| 45 | + $pass_ldap = addcslashes(_request('pass_ldap'), "'\\"); |
|
| 46 | + $port_ldap = addcslashes(_request('port_ldap'), "'\\"); |
|
| 47 | + $tls_ldap = addcslashes(_request('tls_ldap'), "'\\"); |
|
| 48 | + $protocole_ldap = addcslashes(_request('protocole_ldap'), "'\\"); |
|
| 49 | + $base_ldap = addcslashes(_request('base_ldap'), "'\\"); |
|
| 50 | + $base_ldap_text = addcslashes(_request('base_ldap_text'), "'\\"); |
|
| 51 | 51 | |
| 52 | - $conn = "\$GLOBALS['ldap_base'] = '$base_ldap';\n" |
|
| 53 | - . "\$GLOBALS['ldap_link'] = @ldap_connect('$adresse_ldap','$port_ldap');\n" |
|
| 54 | - . "@ldap_set_option(\$GLOBALS['ldap_link'],LDAP_OPT_PROTOCOL_VERSION,'$protocole_ldap');\n" |
|
| 55 | - . (($tls_ldap != 'oui') ? '' : |
|
| 56 | - "@ldap_start_tls(\$GLOBALS['ldap_link']);\n") |
|
| 57 | - . "@ldap_bind(\$GLOBALS['ldap_link'],'$login_ldap','$pass_ldap');\n"; |
|
| 52 | + $conn = "\$GLOBALS['ldap_base'] = '$base_ldap';\n" |
|
| 53 | + . "\$GLOBALS['ldap_link'] = @ldap_connect('$adresse_ldap','$port_ldap');\n" |
|
| 54 | + . "@ldap_set_option(\$GLOBALS['ldap_link'],LDAP_OPT_PROTOCOL_VERSION,'$protocole_ldap');\n" |
|
| 55 | + . (($tls_ldap != 'oui') ? '' : |
|
| 56 | + "@ldap_start_tls(\$GLOBALS['ldap_link']);\n") |
|
| 57 | + . "@ldap_bind(\$GLOBALS['ldap_link'],'$login_ldap','$pass_ldap');\n"; |
|
| 58 | 58 | |
| 59 | - $champs = is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : []; |
|
| 60 | - $res = ''; |
|
| 61 | - foreach ($champs as $champ => $v) { |
|
| 62 | - $nom = 'ldap_' . $champ; |
|
| 63 | - $val = trim(_request($nom)); |
|
| 64 | - if (preg_match('/^\w*$/', $val)) { |
|
| 65 | - if ($val) { |
|
| 66 | - $val = _q($val); |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - $val = 'array(' . _q(preg_split('/\W+/', $val)) . ')'; |
|
| 70 | - }; |
|
| 71 | - if ($val) { |
|
| 72 | - $res .= "'$champ' => " . $val . ','; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - $conn .= "\$GLOBALS['ldap_champs'] = array($res);\n"; |
|
| 59 | + $champs = is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : []; |
|
| 60 | + $res = ''; |
|
| 61 | + foreach ($champs as $champ => $v) { |
|
| 62 | + $nom = 'ldap_' . $champ; |
|
| 63 | + $val = trim(_request($nom)); |
|
| 64 | + if (preg_match('/^\w*$/', $val)) { |
|
| 65 | + if ($val) { |
|
| 66 | + $val = _q($val); |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + $val = 'array(' . _q(preg_split('/\W+/', $val)) . ')'; |
|
| 70 | + }; |
|
| 71 | + if ($val) { |
|
| 72 | + $res .= "'$champ' => " . $val . ','; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + $conn .= "\$GLOBALS['ldap_champs'] = array($res);\n"; |
|
| 76 | 76 | |
| 77 | - install_fichier_connexion(_DIR_CONNECT . _FILE_LDAP, $conn); |
|
| 77 | + install_fichier_connexion(_DIR_CONNECT . _FILE_LDAP, $conn); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | function etape_ldap5_suite() { |
| 81 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 81 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 82 | 82 | |
| 83 | - echo info_etape( |
|
| 84 | - _T('info_ldap_ok'), |
|
| 85 | - info_progression_etape(5, 'etape_ldap', 'install/') |
|
| 86 | - ); |
|
| 83 | + echo info_etape( |
|
| 84 | + _T('info_ldap_ok'), |
|
| 85 | + info_progression_etape(5, 'etape_ldap', 'install/') |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | - echo generer_form_ecrire('install', ( |
|
| 89 | - "<input type='hidden' name='etape' value='3' />" . |
|
| 90 | - "<input type='hidden' name='ldap_present' value='true' />" |
|
| 91 | - . bouton_suivant())); |
|
| 88 | + echo generer_form_ecrire('install', ( |
|
| 89 | + "<input type='hidden' name='etape' value='3' />" . |
|
| 90 | + "<input type='hidden' name='ldap_present' value='true' />" |
|
| 91 | + . bouton_suivant())); |
|
| 92 | 92 | |
| 93 | - echo install_fin_html(); |
|
| 93 | + echo install_fin_html(); |
|
| 94 | 94 | } |
@@ -107,8 +107,8 @@ |
||
| 107 | 107 | function message_crash_tables() { |
| 108 | 108 | if ($crash = verifier_crash_tables()) { |
| 109 | 109 | return |
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 110 | + '<strong>'._T('texte_recuperer_base').'</strong><br />' |
|
| 111 | + . ' <tt>'.join(', ', $crash).'</tt><br />' |
|
| 112 | 112 | . generer_form_ecrire( |
| 113 | 113 | 'base_repair', |
| 114 | 114 | _T('texte_crash_base'), |
@@ -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 | /** |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | 43 | |
| 44 | - // Verifier qu'aucune table n'est crashee |
|
| 45 | - if (!_request('reinstall')) { |
|
| 46 | - verifier_crash_tables(); |
|
| 47 | - } |
|
| 44 | + // Verifier qu'aucune table n'est crashee |
|
| 45 | + if (!_request('reinstall')) { |
|
| 46 | + verifier_crash_tables(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 1; |
|
| 49 | + return 1; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,33 +63,33 @@ discard block |
||
| 63 | 63 | * des tables qui ont crashé. |
| 64 | 64 | */ |
| 65 | 65 | function verifier_crash_tables() { |
| 66 | - if (spip_connect()) { |
|
| 67 | - include_spip('base/serial'); |
|
| 68 | - include_spip('base/auxiliaires'); |
|
| 69 | - $crash = []; |
|
| 70 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | - if ( |
|
| 73 | - !sql_select('*', $table, '', '', '', 1) |
|
| 74 | - and !defined('spip_interdire_cache') |
|
| 75 | - ) { # cas "LOST CONNECTION" |
|
| 76 | - $crash[] = $table; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - #$crash[] = 'test'; |
|
| 81 | - if ($crash) { |
|
| 82 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | - spip_log('crash des tables', 'err'); |
|
| 84 | - spip_log($crash, 'err'); |
|
| 85 | - } else { |
|
| 86 | - effacer_meta('message_crash_tables'); |
|
| 87 | - } |
|
| 66 | + if (spip_connect()) { |
|
| 67 | + include_spip('base/serial'); |
|
| 68 | + include_spip('base/auxiliaires'); |
|
| 69 | + $crash = []; |
|
| 70 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | + if ( |
|
| 73 | + !sql_select('*', $table, '', '', '', 1) |
|
| 74 | + and !defined('spip_interdire_cache') |
|
| 75 | + ) { # cas "LOST CONNECTION" |
|
| 76 | + $crash[] = $table; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + #$crash[] = 'test'; |
|
| 81 | + if ($crash) { |
|
| 82 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | + spip_log('crash des tables', 'err'); |
|
| 84 | + spip_log($crash, 'err'); |
|
| 85 | + } else { |
|
| 86 | + effacer_meta('message_crash_tables'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return $crash; |
|
| 90 | - } |
|
| 89 | + return $crash; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return false; |
|
| 92 | + return false; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | 107 | function message_crash_tables() { |
| 108 | - if ($crash = verifier_crash_tables()) { |
|
| 109 | - return |
|
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | - . generer_form_ecrire( |
|
| 113 | - 'base_repair', |
|
| 114 | - _T('texte_crash_base'), |
|
| 115 | - '', |
|
| 116 | - _T('bouton_tenter_recuperation') |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - return ''; |
|
| 108 | + if ($crash = verifier_crash_tables()) { |
|
| 109 | + return |
|
| 110 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | + . generer_form_ecrire( |
|
| 113 | + 'base_repair', |
|
| 114 | + _T('texte_crash_base'), |
|
| 115 | + '', |
|
| 116 | + _T('bouton_tenter_recuperation') |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + return ''; |
|
| 120 | 120 | } |
@@ -561,11 +561,9 @@ discard block |
||
| 561 | 561 | if (!isset($msg[$p])) { |
| 562 | 562 | if (isset($resume['erreur']) and $resume['erreur']) { |
| 563 | 563 | $msg[$p] = [$resume['erreur']]; |
| 564 | - } |
|
| 565 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 564 | + } elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 566 | 565 | $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
| 567 | - } |
|
| 568 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 566 | + } elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 569 | 567 | $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
| 570 | 568 | } |
| 571 | 569 | } else { |
@@ -954,8 +952,7 @@ discard block |
||
| 954 | 952 | if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
| 955 | 953 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 956 | 954 | } |
| 957 | - } |
|
| 958 | - else { |
|
| 955 | + } else { |
|
| 959 | 956 | foreach ($info['chemin'] as $chemin) { |
| 960 | 957 | if ( |
| 961 | 958 | !isset($chemin['version']) or plugin_version_compatible( |
@@ -1425,8 +1422,7 @@ discard block |
||
| 1425 | 1422 | echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
| 1426 | 1423 | $trace, |
| 1427 | 1424 | "\n"; |
| 1428 | - } |
|
| 1429 | - else { |
|
| 1425 | + } else { |
|
| 1430 | 1426 | include_spip('inc/filtres_boites'); |
| 1431 | 1427 | echo "<div class='install-plugins svp_retour'>" |
| 1432 | 1428 | . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
@@ -1463,8 +1459,7 @@ discard block |
||
| 1463 | 1459 | if (file_exists($nom)) { |
| 1464 | 1460 | if (substr($nom, -4) == '.php') { |
| 1465 | 1461 | $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
| 1466 | - } |
|
| 1467 | - else { |
|
| 1462 | + } else { |
|
| 1468 | 1463 | $fichier_tmp = $nom . '.tmp'; |
| 1469 | 1464 | } |
| 1470 | 1465 | file_put_contents($fichier_tmp, $contenu); |
@@ -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 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -47,27 +47,27 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | **/ |
| 49 | 49 | function liste_plugin_files($dir_plugins = null) { |
| 50 | - static $plugin_files = []; |
|
| 51 | - if (is_null($dir_plugins)) { |
|
| 52 | - $dir_plugins = _DIR_PLUGINS; |
|
| 53 | - } |
|
| 54 | - if ( |
|
| 55 | - !isset($plugin_files[$dir_plugins]) |
|
| 56 | - or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | - ) { |
|
| 58 | - $plugin_files[$dir_plugins] = []; |
|
| 59 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - sort($plugin_files[$dir_plugins]); |
|
| 64 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return $plugin_files[$dir_plugins]; |
|
| 50 | + static $plugin_files = []; |
|
| 51 | + if (is_null($dir_plugins)) { |
|
| 52 | + $dir_plugins = _DIR_PLUGINS; |
|
| 53 | + } |
|
| 54 | + if ( |
|
| 55 | + !isset($plugin_files[$dir_plugins]) |
|
| 56 | + or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | + ) { |
|
| 58 | + $plugin_files[$dir_plugins] = []; |
|
| 59 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + sort($plugin_files[$dir_plugins]); |
|
| 64 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return $plugin_files[$dir_plugins]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -83,45 +83,45 @@ discard block |
||
| 83 | 83 | * Liste complète des répeertoires |
| 84 | 84 | **/ |
| 85 | 85 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 86 | - $fichiers = []; |
|
| 87 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | - if ($dir == '') { |
|
| 91 | - $dir = '.'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (!is_dir($dir)) { |
|
| 95 | - return $fichiers; |
|
| 96 | - } |
|
| 97 | - if (is_plugin_dir($dir, '')) { |
|
| 98 | - $fichiers[] = $dir; |
|
| 99 | - |
|
| 100 | - return $fichiers; |
|
| 101 | - } |
|
| 102 | - if ($max_prof <= 0) { |
|
| 103 | - return $fichiers; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $subdirs = []; |
|
| 107 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | - while (($f = readdir($d)) !== false) { |
|
| 109 | - if ( |
|
| 110 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | - and $f != 'CVS' |
|
| 112 | - and is_dir($f = "$dir/$f") |
|
| 113 | - ) { |
|
| 114 | - $subdirs[] = $f; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - closedir($d); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - foreach ($subdirs as $d) { |
|
| 121 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $fichiers; |
|
| 86 | + $fichiers = []; |
|
| 87 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | + if ($dir == '') { |
|
| 91 | + $dir = '.'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (!is_dir($dir)) { |
|
| 95 | + return $fichiers; |
|
| 96 | + } |
|
| 97 | + if (is_plugin_dir($dir, '')) { |
|
| 98 | + $fichiers[] = $dir; |
|
| 99 | + |
|
| 100 | + return $fichiers; |
|
| 101 | + } |
|
| 102 | + if ($max_prof <= 0) { |
|
| 103 | + return $fichiers; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $subdirs = []; |
|
| 107 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | + while (($f = readdir($d)) !== false) { |
|
| 109 | + if ( |
|
| 110 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | + and $f != 'CVS' |
|
| 112 | + and is_dir($f = "$dir/$f") |
|
| 113 | + ) { |
|
| 114 | + $subdirs[] = $f; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + closedir($d); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + foreach ($subdirs as $d) { |
|
| 121 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $fichiers; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -142,27 +142,27 @@ discard block |
||
| 142 | 142 | **/ |
| 143 | 143 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 144 | 144 | |
| 145 | - if (is_array($dir)) { |
|
| 146 | - foreach ($dir as $k => $d) { |
|
| 147 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | - unset($dir[$k]); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $dir; |
|
| 153 | - } |
|
| 154 | - if (is_null($dir_plugins)) { |
|
| 155 | - $dir_plugins = _DIR_PLUGINS; |
|
| 156 | - } |
|
| 157 | - $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | - |
|
| 159 | - foreach ($search as $s) { |
|
| 160 | - if (file_exists($s)) { |
|
| 161 | - return $dir; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return ''; |
|
| 145 | + if (is_array($dir)) { |
|
| 146 | + foreach ($dir as $k => $d) { |
|
| 147 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | + unset($dir[$k]); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $dir; |
|
| 153 | + } |
|
| 154 | + if (is_null($dir_plugins)) { |
|
| 155 | + $dir_plugins = _DIR_PLUGINS; |
|
| 156 | + } |
|
| 157 | + $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | + |
|
| 159 | + foreach ($search as $s) { |
|
| 160 | + if (file_exists($s)) { |
|
| 161 | + return $dir; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return ''; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -189,51 +189,51 @@ discard block |
||
| 189 | 189 | **/ |
| 190 | 190 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 191 | 191 | |
| 192 | - if (!strlen($intervalle)) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | - $minimum = $regs[1]; |
|
| 201 | - $maximum = $regs[2]; |
|
| 202 | - |
|
| 203 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | - // entre plugins) |
|
| 208 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $minimum_inc = $intervalle[0] == '['; |
|
| 217 | - $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | - |
|
| 219 | - if (strlen($minimum)) { |
|
| 220 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | - return false; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - if (strlen($maximum)) { |
|
| 228 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return true; |
|
| 192 | + if (!strlen($intervalle)) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | + $minimum = $regs[1]; |
|
| 201 | + $maximum = $regs[2]; |
|
| 202 | + |
|
| 203 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | + // entre plugins) |
|
| 208 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $minimum_inc = $intervalle[0] == '['; |
|
| 217 | + $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | + |
|
| 219 | + if (strlen($minimum)) { |
|
| 220 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + if (strlen($maximum)) { |
|
| 228 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return true; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,62 +250,62 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function liste_plugin_valides($liste_plug, $force = false) { |
| 253 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | - $infos = [ |
|
| 256 | - // lister les extensions qui sont automatiquement actives |
|
| 257 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | - ]; |
|
| 260 | - |
|
| 261 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | - $liste_non_classee = [ |
|
| 267 | - 'SPIP' => [ |
|
| 268 | - 'nom' => 'SPIP', |
|
| 269 | - 'etat' => 'stable', |
|
| 270 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | - 'dir' => '', |
|
| 273 | - ] |
|
| 274 | - ]; |
|
| 275 | - |
|
| 276 | - $invalides = []; |
|
| 277 | - foreach ($liste_ext as $plug) { |
|
| 278 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - foreach ($liste_plug as $plug) { |
|
| 283 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | - if (is_array($r)) { |
|
| 286 | - $invalides = array_merge($invalides, $r); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | - foreach ($liste_plug as $plug) { |
|
| 294 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | - if (is_array($r)) { |
|
| 297 | - $invalides = array_merge($invalides, $r); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | - |
|
| 305 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | - |
|
| 308 | - return [$infos, $liste_non_classee, $invalides]; |
|
| 253 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | + $infos = [ |
|
| 256 | + // lister les extensions qui sont automatiquement actives |
|
| 257 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | + ]; |
|
| 260 | + |
|
| 261 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | + $liste_non_classee = [ |
|
| 267 | + 'SPIP' => [ |
|
| 268 | + 'nom' => 'SPIP', |
|
| 269 | + 'etat' => 'stable', |
|
| 270 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | + 'dir' => '', |
|
| 273 | + ] |
|
| 274 | + ]; |
|
| 275 | + |
|
| 276 | + $invalides = []; |
|
| 277 | + foreach ($liste_ext as $plug) { |
|
| 278 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + foreach ($liste_plug as $plug) { |
|
| 283 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | + if (is_array($r)) { |
|
| 286 | + $invalides = array_merge($invalides, $r); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | + foreach ($liste_plug as $plug) { |
|
| 294 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | + if (is_array($r)) { |
|
| 297 | + $invalides = array_merge($invalides, $r); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | + |
|
| 305 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | + |
|
| 308 | + return [$infos, $liste_non_classee, $invalides]; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -325,38 +325,38 @@ discard block |
||
| 325 | 325 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 326 | 326 | */ |
| 327 | 327 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 328 | - $i = $infos[$dir_type][$plug]; |
|
| 329 | - // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | - $short_desc = [ |
|
| 331 | - 'dir' => $plug, |
|
| 332 | - 'dir_type' => $dir_type |
|
| 333 | - ]; |
|
| 334 | - if (empty($i['prefix'])) { |
|
| 335 | - // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | - $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | - return [$plug => $short_desc]; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $p = strtoupper($i['prefix']); |
|
| 341 | - $short_desc['nom'] = $i['nom']; |
|
| 342 | - $short_desc['etat'] = $i['etat']; |
|
| 343 | - $short_desc['version'] = $i['version']; |
|
| 344 | - |
|
| 345 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | - $short_desc['erreur'] = $i['erreur']; |
|
| 347 | - return [$p => $short_desc]; |
|
| 348 | - } |
|
| 349 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | - return [$p => $short_desc]; |
|
| 351 | - } |
|
| 352 | - if ( |
|
| 353 | - !isset($liste[$p]) |
|
| 354 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | - ) { |
|
| 356 | - $liste[$p] = $short_desc; |
|
| 357 | - } |
|
| 358 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | - return $p; |
|
| 328 | + $i = $infos[$dir_type][$plug]; |
|
| 329 | + // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | + $short_desc = [ |
|
| 331 | + 'dir' => $plug, |
|
| 332 | + 'dir_type' => $dir_type |
|
| 333 | + ]; |
|
| 334 | + if (empty($i['prefix'])) { |
|
| 335 | + // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | + $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | + return [$plug => $short_desc]; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $p = strtoupper($i['prefix']); |
|
| 341 | + $short_desc['nom'] = $i['nom']; |
|
| 342 | + $short_desc['etat'] = $i['etat']; |
|
| 343 | + $short_desc['version'] = $i['version']; |
|
| 344 | + |
|
| 345 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | + $short_desc['erreur'] = $i['erreur']; |
|
| 347 | + return [$p => $short_desc]; |
|
| 348 | + } |
|
| 349 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | + return [$p => $short_desc]; |
|
| 351 | + } |
|
| 352 | + if ( |
|
| 353 | + !isset($liste[$p]) |
|
| 354 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | + ) { |
|
| 356 | + $liste[$p] = $short_desc; |
|
| 357 | + } |
|
| 358 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | + return $p; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -372,47 +372,47 @@ discard block |
||
| 372 | 372 | * @param array $infos |
| 373 | 373 | */ |
| 374 | 374 | function plugin_fixer_procure(&$liste, &$infos) { |
| 375 | - foreach ($liste as $p => $resume) { |
|
| 376 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | - if (isset($i['procure']) and $i['procure']) { |
|
| 378 | - foreach ($i['procure'] as $procure) { |
|
| 379 | - $p = strtoupper($procure['nom']); |
|
| 380 | - $dir = $resume['dir']; |
|
| 381 | - if ($dir) { |
|
| 382 | - $dir .= '/'; |
|
| 383 | - } |
|
| 384 | - $dir .= 'procure:' . $procure['nom']; |
|
| 385 | - |
|
| 386 | - $procure['etat'] = '?'; |
|
| 387 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | - $procure['dir'] = $dir; |
|
| 389 | - |
|
| 390 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | - // on ajoute cette version a la liste |
|
| 392 | - if ( |
|
| 393 | - !isset($liste[$p]) |
|
| 394 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | - ) { |
|
| 396 | - $liste[$p] = $procure; |
|
| 397 | - |
|
| 398 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | - 'prefix' => $procure['nom'], |
|
| 401 | - 'nom' => $procure['nom'], |
|
| 402 | - 'etat' => $procure['etat'], |
|
| 403 | - 'version' => $procure['version'], |
|
| 404 | - 'chemin' => [], |
|
| 405 | - 'necessite' => [], |
|
| 406 | - 'utilise' => [], |
|
| 407 | - 'lib' => [], |
|
| 408 | - 'menu' => [], |
|
| 409 | - 'onglet' => [], |
|
| 410 | - 'procure' => [], |
|
| 411 | - ]; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 375 | + foreach ($liste as $p => $resume) { |
|
| 376 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | + if (isset($i['procure']) and $i['procure']) { |
|
| 378 | + foreach ($i['procure'] as $procure) { |
|
| 379 | + $p = strtoupper($procure['nom']); |
|
| 380 | + $dir = $resume['dir']; |
|
| 381 | + if ($dir) { |
|
| 382 | + $dir .= '/'; |
|
| 383 | + } |
|
| 384 | + $dir .= 'procure:' . $procure['nom']; |
|
| 385 | + |
|
| 386 | + $procure['etat'] = '?'; |
|
| 387 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | + $procure['dir'] = $dir; |
|
| 389 | + |
|
| 390 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | + // on ajoute cette version a la liste |
|
| 392 | + if ( |
|
| 393 | + !isset($liste[$p]) |
|
| 394 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | + ) { |
|
| 396 | + $liste[$p] = $procure; |
|
| 397 | + |
|
| 398 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | + 'prefix' => $procure['nom'], |
|
| 401 | + 'nom' => $procure['nom'], |
|
| 402 | + 'etat' => $procure['etat'], |
|
| 403 | + 'version' => $procure['version'], |
|
| 404 | + 'chemin' => [], |
|
| 405 | + 'necessite' => [], |
|
| 406 | + 'utilise' => [], |
|
| 407 | + 'lib' => [], |
|
| 408 | + 'menu' => [], |
|
| 409 | + 'onglet' => [], |
|
| 410 | + 'procure' => [], |
|
| 411 | + ]; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -426,20 +426,20 @@ discard block |
||
| 426 | 426 | * @return array |
| 427 | 427 | */ |
| 428 | 428 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 429 | - foreach ($liste as $prefix => $infos) { |
|
| 430 | - if ( |
|
| 431 | - !$dir_plugins |
|
| 432 | - or ( |
|
| 433 | - defined($infos['dir_type']) |
|
| 434 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | - ) { |
|
| 436 | - $liste[$prefix] = $infos['dir']; |
|
| 437 | - } else { |
|
| 438 | - unset($liste[$prefix]); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $liste; |
|
| 429 | + foreach ($liste as $prefix => $infos) { |
|
| 430 | + if ( |
|
| 431 | + !$dir_plugins |
|
| 432 | + or ( |
|
| 433 | + defined($infos['dir_type']) |
|
| 434 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | + ) { |
|
| 436 | + $liste[$prefix] = $infos['dir']; |
|
| 437 | + } else { |
|
| 438 | + unset($liste[$prefix]); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $liste; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -454,9 +454,9 @@ discard block |
||
| 454 | 454 | * @return array |
| 455 | 455 | */ |
| 456 | 456 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 457 | - include_spip('plugins/installer'); |
|
| 457 | + include_spip('plugins/installer'); |
|
| 458 | 458 | |
| 459 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 459 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -487,54 +487,54 @@ discard block |
||
| 487 | 487 | * qui n'ont pas satisfait leurs dépendances |
| 488 | 488 | **/ |
| 489 | 489 | function plugin_trier($infos, $liste_non_classee) { |
| 490 | - $toute_la_liste = $liste_non_classee; |
|
| 491 | - $liste = $ordre = []; |
|
| 492 | - $count = 0; |
|
| 493 | - |
|
| 494 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | - $count = $c; |
|
| 497 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | - $plug = $resume['dir']; |
|
| 499 | - $dir_type = $resume['dir_type']; |
|
| 500 | - $info1 = $infos[$dir_type][$plug]; |
|
| 501 | - // si des plugins sont necessaires, |
|
| 502 | - // on ne peut inserer qu'apres eux |
|
| 503 | - foreach ($info1['necessite'] as $need) { |
|
| 504 | - $nom = strtoupper($need['nom']); |
|
| 505 | - $compat = $need['compatibilite'] ?? ''; |
|
| 506 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | - $info1 = false; |
|
| 508 | - break; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - if (!$info1) { |
|
| 512 | - continue; |
|
| 513 | - } |
|
| 514 | - // idem si des plugins sont utiles, |
|
| 515 | - // sauf si ils sont de toute facon absents de la liste |
|
| 516 | - foreach ($info1['utilise'] as $need) { |
|
| 517 | - $nom = strtoupper($need['nom']); |
|
| 518 | - $compat = $need['compatibilite'] ?? ''; |
|
| 519 | - if (isset($toute_la_liste[$nom])) { |
|
| 520 | - if ( |
|
| 521 | - !isset($liste[$nom]) or |
|
| 522 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | - ) { |
|
| 524 | - $info1 = false; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - if ($info1) { |
|
| 530 | - $ordre[$p] = $info1; |
|
| 531 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | - unset($liste_non_classee[$p]); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 490 | + $toute_la_liste = $liste_non_classee; |
|
| 491 | + $liste = $ordre = []; |
|
| 492 | + $count = 0; |
|
| 493 | + |
|
| 494 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | + $count = $c; |
|
| 497 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | + $plug = $resume['dir']; |
|
| 499 | + $dir_type = $resume['dir_type']; |
|
| 500 | + $info1 = $infos[$dir_type][$plug]; |
|
| 501 | + // si des plugins sont necessaires, |
|
| 502 | + // on ne peut inserer qu'apres eux |
|
| 503 | + foreach ($info1['necessite'] as $need) { |
|
| 504 | + $nom = strtoupper($need['nom']); |
|
| 505 | + $compat = $need['compatibilite'] ?? ''; |
|
| 506 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | + $info1 = false; |
|
| 508 | + break; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + if (!$info1) { |
|
| 512 | + continue; |
|
| 513 | + } |
|
| 514 | + // idem si des plugins sont utiles, |
|
| 515 | + // sauf si ils sont de toute facon absents de la liste |
|
| 516 | + foreach ($info1['utilise'] as $need) { |
|
| 517 | + $nom = strtoupper($need['nom']); |
|
| 518 | + $compat = $need['compatibilite'] ?? ''; |
|
| 519 | + if (isset($toute_la_liste[$nom])) { |
|
| 520 | + if ( |
|
| 521 | + !isset($liste[$nom]) or |
|
| 522 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | + ) { |
|
| 524 | + $info1 = false; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + if ($info1) { |
|
| 530 | + $ordre[$p] = $info1; |
|
| 531 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | + unset($liste_non_classee[$p]); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -551,40 +551,40 @@ discard block |
||
| 551 | 551 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 552 | 552 | **/ |
| 553 | 553 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 554 | - static $erreurs = []; |
|
| 555 | - |
|
| 556 | - if (!is_array($liste)) { |
|
| 557 | - $liste = []; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | - |
|
| 563 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | - $dir_type = $resume['dir_type']; |
|
| 565 | - $plug = $resume['dir']; |
|
| 566 | - $k = $infos[$dir_type][$plug]; |
|
| 567 | - |
|
| 568 | - $plug = constant($dir_type) . $plug; |
|
| 569 | - if (!isset($msg[$p])) { |
|
| 570 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | - $msg[$p] = [$resume['erreur']]; |
|
| 572 | - } |
|
| 573 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | - } |
|
| 576 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | - } |
|
| 579 | - } else { |
|
| 580 | - foreach ($msg[$p] as $c => $l) { |
|
| 581 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - $erreurs[$plug] = $msg[$p]; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 554 | + static $erreurs = []; |
|
| 555 | + |
|
| 556 | + if (!is_array($liste)) { |
|
| 557 | + $liste = []; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | + |
|
| 563 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | + $dir_type = $resume['dir_type']; |
|
| 565 | + $plug = $resume['dir']; |
|
| 566 | + $k = $infos[$dir_type][$plug]; |
|
| 567 | + |
|
| 568 | + $plug = constant($dir_type) . $plug; |
|
| 569 | + if (!isset($msg[$p])) { |
|
| 570 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | + $msg[$p] = [$resume['erreur']]; |
|
| 572 | + } |
|
| 573 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | + } |
|
| 576 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | + } |
|
| 579 | + } else { |
|
| 580 | + foreach ($msg[$p] as $c => $l) { |
|
| 581 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + $erreurs[$plug] = $msg[$p]; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -599,25 +599,25 @@ discard block |
||
| 599 | 599 | * - Liste des erreurs ou code HTML des erreurs |
| 600 | 600 | **/ |
| 601 | 601 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 602 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | - return $raw ? [] : ''; |
|
| 604 | - } |
|
| 605 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | - // Compat ancienne version |
|
| 607 | - if (!$list) { |
|
| 608 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | - } elseif (!$raw) { |
|
| 610 | - foreach ($list as $plug => $msg) { |
|
| 611 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | - } |
|
| 614 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | - } |
|
| 616 | - if ($raz) { |
|
| 617 | - effacer_meta('plugin_erreur_activation'); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return $list; |
|
| 602 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | + return $raw ? [] : ''; |
|
| 604 | + } |
|
| 605 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | + // Compat ancienne version |
|
| 607 | + if (!$list) { |
|
| 608 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | + } elseif (!$raw) { |
|
| 610 | + foreach ($list as $plug => $msg) { |
|
| 611 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | + } |
|
| 614 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | + } |
|
| 616 | + if ($raz) { |
|
| 617 | + effacer_meta('plugin_erreur_activation'); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return $list; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
@@ -637,21 +637,21 @@ discard block |
||
| 637 | 637 | * |
| 638 | 638 | **/ |
| 639 | 639 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 640 | - $msg = []; |
|
| 641 | - foreach ($n as $need) { |
|
| 642 | - $id = strtoupper($need['nom']); |
|
| 643 | - $r = plugin_controler_necessite( |
|
| 644 | - $liste, |
|
| 645 | - $id, |
|
| 646 | - $need['compatibilite'] ?? '', |
|
| 647 | - $balise |
|
| 648 | - ); |
|
| 649 | - if ($r) { |
|
| 650 | - $msg[] = $r; |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $msg; |
|
| 640 | + $msg = []; |
|
| 641 | + foreach ($n as $need) { |
|
| 642 | + $id = strtoupper($need['nom']); |
|
| 643 | + $r = plugin_controler_necessite( |
|
| 644 | + $liste, |
|
| 645 | + $id, |
|
| 646 | + $need['compatibilite'] ?? '', |
|
| 647 | + $balise |
|
| 648 | + ); |
|
| 649 | + if ($r) { |
|
| 650 | + $msg[] = $r; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $msg; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -673,19 +673,19 @@ discard block |
||
| 673 | 673 | * Message d'erreur lorsque la dépendance est absente. |
| 674 | 674 | **/ |
| 675 | 675 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 676 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | - return ''; |
|
| 678 | - } |
|
| 679 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | - if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | - return ''; |
|
| 682 | - } |
|
| 683 | - return plugin_message_incompatibilite( |
|
| 684 | - $intervalle, |
|
| 685 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | - $nom, |
|
| 687 | - $balise |
|
| 688 | - ); |
|
| 676 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | + return ''; |
|
| 678 | + } |
|
| 679 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | + if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | + return ''; |
|
| 682 | + } |
|
| 683 | + return plugin_message_incompatibilite( |
|
| 684 | + $intervalle, |
|
| 685 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | + $nom, |
|
| 687 | + $balise |
|
| 688 | + ); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -702,70 +702,70 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 704 | 704 | |
| 705 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | - $type = 'plugin'; |
|
| 708 | - if ($nom === 'SPIP') { |
|
| 709 | - $type = 'spip'; |
|
| 710 | - } elseif ($nom === 'PHP') { |
|
| 711 | - $type = 'php'; |
|
| 712 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | - $type = 'extension_php'; |
|
| 714 | - [, $nom] = explode(':', $nom, 2); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | - $minimum = $regs[1]; |
|
| 719 | - $maximum = $regs[2]; |
|
| 720 | - |
|
| 721 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | - $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | - |
|
| 724 | - if (strlen($minimum)) { |
|
| 725 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | - 'plugin' => $nom, |
|
| 728 | - 'version' => ' ≥ ' . $minimum |
|
| 729 | - ]); |
|
| 730 | - } |
|
| 731 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | - 'plugin' => $nom, |
|
| 734 | - 'version' => ' > ' . $minimum |
|
| 735 | - ]); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if (strlen($maximum)) { |
|
| 740 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | - 'plugin' => $nom, |
|
| 743 | - 'version' => ' ≤ ' . $maximum |
|
| 744 | - ]); |
|
| 745 | - } |
|
| 746 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | - return _T("plugin_{$balise}_plugin", [ |
|
| 748 | - 'plugin' => $nom, |
|
| 749 | - 'version' => ' < ' . $maximum |
|
| 750 | - ]); |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | - // - un 'utilise' sans version. |
|
| 757 | - // - un 'php' sans version. |
|
| 758 | - return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 705 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | + $type = 'plugin'; |
|
| 708 | + if ($nom === 'SPIP') { |
|
| 709 | + $type = 'spip'; |
|
| 710 | + } elseif ($nom === 'PHP') { |
|
| 711 | + $type = 'php'; |
|
| 712 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | + $type = 'extension_php'; |
|
| 714 | + [, $nom] = explode(':', $nom, 2); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | + $minimum = $regs[1]; |
|
| 719 | + $maximum = $regs[2]; |
|
| 720 | + |
|
| 721 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | + $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | + |
|
| 724 | + if (strlen($minimum)) { |
|
| 725 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | + 'plugin' => $nom, |
|
| 728 | + 'version' => ' ≥ ' . $minimum |
|
| 729 | + ]); |
|
| 730 | + } |
|
| 731 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | + 'plugin' => $nom, |
|
| 734 | + 'version' => ' > ' . $minimum |
|
| 735 | + ]); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if (strlen($maximum)) { |
|
| 740 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | + 'plugin' => $nom, |
|
| 743 | + 'version' => ' ≤ ' . $maximum |
|
| 744 | + ]); |
|
| 745 | + } |
|
| 746 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | + return _T("plugin_{$balise}_plugin", [ |
|
| 748 | + 'plugin' => $nom, |
|
| 749 | + 'version' => ' < ' . $maximum |
|
| 750 | + ]); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | + // - un 'utilise' sans version. |
|
| 757 | + // - un 'php' sans version. |
|
| 758 | + return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
| 762 | 762 | function plugin_controler_lib($lib, $url) { |
| 763 | - /* Feature sortie du core, voir STP |
|
| 763 | + /* Feature sortie du core, voir STP |
|
| 764 | 764 | * if ($url) { |
| 765 | 765 | include_spip('inc/charger_plugin'); |
| 766 | 766 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 767 | 767 | }*/ |
| 768 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 768 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 781 | 781 | **/ |
| 782 | 782 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 783 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 783 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -807,116 +807,116 @@ discard block |
||
| 807 | 807 | **/ |
| 808 | 808 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 809 | 809 | |
| 810 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | - |
|
| 813 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | - if (!$cache and !spip_connect()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($operation != 'raz') { |
|
| 819 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | - } |
|
| 826 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | - // on les reinjecte ici |
|
| 828 | - if ( |
|
| 829 | - isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | - ) { |
|
| 832 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - if ($operation == 'ajoute') { |
|
| 836 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | - } elseif ($operation == 'enleve') { |
|
| 838 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | - } else { |
|
| 840 | - $plugin = $plugin_valides; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | - |
|
| 845 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | - $plugin = $ajouter_dependances($plugin); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // recharger le xml des plugins a activer |
|
| 851 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | - // trouver l'ordre d'activation |
|
| 857 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | - if ($invalides or $reste) { |
|
| 859 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - // Ignorer les plugins necessitant une lib absente |
|
| 863 | - // et preparer la meta d'entete Http |
|
| 864 | - $err = $msg = $header = []; |
|
| 865 | - foreach ($plugin_valides as $p => $resume) { |
|
| 866 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | - } |
|
| 870 | - if ($resume['dir']) { |
|
| 871 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | - $err[$p] = $resume; |
|
| 874 | - $msg[$p][] = $l; |
|
| 875 | - unset($plugin_valides[$p]); |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - if ($err) { |
|
| 881 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | - effacer_meta('message_crash_plugins'); |
|
| 886 | - } |
|
| 887 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | - $header = strtolower(implode(',', $header)); |
|
| 891 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | - ecrire_fichier( |
|
| 893 | - _DIR_VAR . 'config.txt', |
|
| 894 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | - ); |
|
| 896 | - } else { |
|
| 897 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | - } |
|
| 899 | - // generer charger_plugins_chemin.php |
|
| 900 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | - // generer les fichiers |
|
| 902 | - // - charger_plugins_options.php |
|
| 903 | - // - charger_plugins_fonctions.php |
|
| 904 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | - // charger les chemins des plugins et les fichiers d'options |
|
| 906 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | - plugins_amorcer_plugins_actifs(); |
|
| 908 | - // mise a jour de la matrice des pipelines |
|
| 909 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | - // generer le fichier _CACHE_PIPELINE |
|
| 911 | - pipeline_precompile($prepend_code); |
|
| 912 | - |
|
| 913 | - if (spip_connect()) { |
|
| 914 | - // lancer et initialiser les nouveaux crons ! |
|
| 915 | - include_spip('inc/genie'); |
|
| 916 | - genie_queue_watch_dist(); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 810 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | + |
|
| 813 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | + if (!$cache and !spip_connect()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($operation != 'raz') { |
|
| 819 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | + } |
|
| 826 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | + // on les reinjecte ici |
|
| 828 | + if ( |
|
| 829 | + isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | + ) { |
|
| 832 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + if ($operation == 'ajoute') { |
|
| 836 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | + } elseif ($operation == 'enleve') { |
|
| 838 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | + } else { |
|
| 840 | + $plugin = $plugin_valides; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | + |
|
| 845 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | + $plugin = $ajouter_dependances($plugin); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + // recharger le xml des plugins a activer |
|
| 851 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | + // trouver l'ordre d'activation |
|
| 857 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | + if ($invalides or $reste) { |
|
| 859 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + // Ignorer les plugins necessitant une lib absente |
|
| 863 | + // et preparer la meta d'entete Http |
|
| 864 | + $err = $msg = $header = []; |
|
| 865 | + foreach ($plugin_valides as $p => $resume) { |
|
| 866 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | + } |
|
| 870 | + if ($resume['dir']) { |
|
| 871 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | + $err[$p] = $resume; |
|
| 874 | + $msg[$p][] = $l; |
|
| 875 | + unset($plugin_valides[$p]); |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + if ($err) { |
|
| 881 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | + effacer_meta('message_crash_plugins'); |
|
| 886 | + } |
|
| 887 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | + $header = strtolower(implode(',', $header)); |
|
| 891 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | + ecrire_fichier( |
|
| 893 | + _DIR_VAR . 'config.txt', |
|
| 894 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | + ); |
|
| 896 | + } else { |
|
| 897 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | + } |
|
| 899 | + // generer charger_plugins_chemin.php |
|
| 900 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | + // generer les fichiers |
|
| 902 | + // - charger_plugins_options.php |
|
| 903 | + // - charger_plugins_fonctions.php |
|
| 904 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | + // charger les chemins des plugins et les fichiers d'options |
|
| 906 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | + plugins_amorcer_plugins_actifs(); |
|
| 908 | + // mise a jour de la matrice des pipelines |
|
| 909 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | + // generer le fichier _CACHE_PIPELINE |
|
| 911 | + pipeline_precompile($prepend_code); |
|
| 912 | + |
|
| 913 | + if (spip_connect()) { |
|
| 914 | + // lancer et initialiser les nouveaux crons ! |
|
| 915 | + include_spip('inc/genie'); |
|
| 916 | + genie_queue_watch_dist(); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -935,74 +935,74 @@ discard block |
||
| 935 | 935 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 936 | 936 | **/ |
| 937 | 937 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 938 | - $chemins = [ |
|
| 939 | - 'public' => [], |
|
| 940 | - 'prive' => [] |
|
| 941 | - ]; |
|
| 942 | - $contenu = ''; |
|
| 943 | - foreach ($ordre as $p => $info) { |
|
| 944 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | - if (isset($plugin_valides[$p])) { |
|
| 946 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | - $plug = $plugin_valides[$p]['dir']; |
|
| 948 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | - |
|
| 951 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | - |
|
| 953 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | - if ( |
|
| 955 | - $prefix !== 'SPIP' |
|
| 956 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 957 | - ) { |
|
| 958 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | - if (!$info['chemin']) { |
|
| 960 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - else { |
|
| 967 | - foreach ($info['chemin'] as $chemin) { |
|
| 968 | - if ( |
|
| 969 | - !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | - $chemin['version'], |
|
| 971 | - $GLOBALS['spip_version_branche'], |
|
| 972 | - 'spip' |
|
| 973 | - ) |
|
| 974 | - ) { |
|
| 975 | - $dir = $chemin['path']; |
|
| 976 | - if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | - $dir = substr($dir, 1); |
|
| 978 | - } |
|
| 979 | - if (strlen($dir) and $dir == './') { |
|
| 980 | - $dir = ''; |
|
| 981 | - } |
|
| 982 | - if (strlen($dir)) { |
|
| 983 | - $dir = rtrim($dir, '/') . '/'; |
|
| 984 | - } |
|
| 985 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | - } |
|
| 988 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | - ',', |
|
| 1000 | - array_reverse($chemins['public']) |
|
| 1001 | - ) . "]);\n" |
|
| 1002 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 938 | + $chemins = [ |
|
| 939 | + 'public' => [], |
|
| 940 | + 'prive' => [] |
|
| 941 | + ]; |
|
| 942 | + $contenu = ''; |
|
| 943 | + foreach ($ordre as $p => $info) { |
|
| 944 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | + if (isset($plugin_valides[$p])) { |
|
| 946 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | + $plug = $plugin_valides[$p]['dir']; |
|
| 948 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | + |
|
| 951 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | + |
|
| 953 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | + if ( |
|
| 955 | + $prefix !== 'SPIP' |
|
| 956 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 957 | + ) { |
|
| 958 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | + if (!$info['chemin']) { |
|
| 960 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + else { |
|
| 967 | + foreach ($info['chemin'] as $chemin) { |
|
| 968 | + if ( |
|
| 969 | + !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | + $chemin['version'], |
|
| 971 | + $GLOBALS['spip_version_branche'], |
|
| 972 | + 'spip' |
|
| 973 | + ) |
|
| 974 | + ) { |
|
| 975 | + $dir = $chemin['path']; |
|
| 976 | + if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | + $dir = substr($dir, 1); |
|
| 978 | + } |
|
| 979 | + if (strlen($dir) and $dir == './') { |
|
| 980 | + $dir = ''; |
|
| 981 | + } |
|
| 982 | + if (strlen($dir)) { |
|
| 983 | + $dir = rtrim($dir, '/') . '/'; |
|
| 984 | + } |
|
| 985 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | + } |
|
| 988 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | + ',', |
|
| 1000 | + array_reverse($chemins['public']) |
|
| 1001 | + ) . "]);\n" |
|
| 1002 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1020,67 +1020,67 @@ discard block |
||
| 1020 | 1020 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1021 | 1021 | **/ |
| 1022 | 1022 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1023 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | - $boutons = []; |
|
| 1025 | - $onglets = []; |
|
| 1026 | - $sign = ''; |
|
| 1027 | - |
|
| 1028 | - foreach ($ordre as $p => $info) { |
|
| 1029 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | - if (isset($plugin_valides[$p])) { |
|
| 1031 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | - $dir = constant($dir_type); |
|
| 1034 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | - if ($info['menu']) { |
|
| 1036 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | - } |
|
| 1038 | - if ($info['onglet']) { |
|
| 1039 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | - } |
|
| 1041 | - foreach ($contenu as $charge => $v) { |
|
| 1042 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | - // donc ni sa relecture, ni sa detection |
|
| 1045 | - if ( |
|
| 1046 | - !isset($info[$charge]) |
|
| 1047 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1049 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | - ) { |
|
| 1051 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | - $info[$charge] = [$file]; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - if (isset($info[$charge])) { |
|
| 1056 | - $files = $info[$charge]; |
|
| 1057 | - foreach ($files as $k => $file) { |
|
| 1058 | - // on genere un if file_exists devant chaque include |
|
| 1059 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | - $file = trim($file); |
|
| 1061 | - if ( |
|
| 1062 | - !is_readable("$dir$plug/$file") |
|
| 1063 | - // uniquement pour les paquet.xml |
|
| 1064 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | - ) { |
|
| 1066 | - unset($info[$charge][$k]); |
|
| 1067 | - } else { |
|
| 1068 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - $sign .= md5(serialize($info)); |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | - |
|
| 1082 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1023 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | + $boutons = []; |
|
| 1025 | + $onglets = []; |
|
| 1026 | + $sign = ''; |
|
| 1027 | + |
|
| 1028 | + foreach ($ordre as $p => $info) { |
|
| 1029 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | + if (isset($plugin_valides[$p])) { |
|
| 1031 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | + $dir = constant($dir_type); |
|
| 1034 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | + if ($info['menu']) { |
|
| 1036 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | + } |
|
| 1038 | + if ($info['onglet']) { |
|
| 1039 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | + } |
|
| 1041 | + foreach ($contenu as $charge => $v) { |
|
| 1042 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | + // donc ni sa relecture, ni sa detection |
|
| 1045 | + if ( |
|
| 1046 | + !isset($info[$charge]) |
|
| 1047 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1049 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | + ) { |
|
| 1051 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | + $info[$charge] = [$file]; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if (isset($info[$charge])) { |
|
| 1056 | + $files = $info[$charge]; |
|
| 1057 | + foreach ($files as $k => $file) { |
|
| 1058 | + // on genere un if file_exists devant chaque include |
|
| 1059 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | + $file = trim($file); |
|
| 1061 | + if ( |
|
| 1062 | + !is_readable("$dir$plug/$file") |
|
| 1063 | + // uniquement pour les paquet.xml |
|
| 1064 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | + ) { |
|
| 1066 | + unset($info[$charge][$k]); |
|
| 1067 | + } else { |
|
| 1068 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + $sign .= md5(serialize($info)); |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | + |
|
| 1082 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1099,24 +1099,24 @@ discard block |
||
| 1099 | 1099 | * @return string Code php |
| 1100 | 1100 | */ |
| 1101 | 1101 | function plugin_ongletbouton($nom, $val) { |
| 1102 | - if (!$val) { |
|
| 1103 | - $val = []; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - $val = serialize($val); |
|
| 1107 | - $md5 = md5($val); |
|
| 1108 | - |
|
| 1109 | - if (!defined("_UPDATED_$nom")) { |
|
| 1110 | - define("_UPDATED_$nom", $val); |
|
| 1111 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | - } |
|
| 1113 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | - |
|
| 1115 | - return |
|
| 1116 | - "if (!function_exists('$nom')) {\n" |
|
| 1117 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | - . "}\n"; |
|
| 1102 | + if (!$val) { |
|
| 1103 | + $val = []; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + $val = serialize($val); |
|
| 1107 | + $md5 = md5($val); |
|
| 1108 | + |
|
| 1109 | + if (!defined("_UPDATED_$nom")) { |
|
| 1110 | + define("_UPDATED_$nom", $val); |
|
| 1111 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | + } |
|
| 1113 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | + |
|
| 1115 | + return |
|
| 1116 | + "if (!function_exists('$nom')) {\n" |
|
| 1117 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | + . "}\n"; |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
@@ -1131,15 +1131,15 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function plugins_amorcer_plugins_actifs() { |
| 1133 | 1133 | |
| 1134 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | - } |
|
| 1134 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | - } else { |
|
| 1141 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | - } |
|
| 1138 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | + } else { |
|
| 1141 | + spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | + } |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1162,140 +1162,140 @@ discard block |
||
| 1162 | 1162 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1165 | - static $liste_pipe_manquants = []; |
|
| 1166 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - $prepend_code = []; |
|
| 1171 | - |
|
| 1172 | - foreach ($ordre as $p => $info) { |
|
| 1173 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | - if (isset($plugin_valides[$p])) { |
|
| 1175 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | - $nom = $pipe['nom']; |
|
| 1182 | - if (isset($pipe['action'])) { |
|
| 1183 | - $action = $pipe['action']; |
|
| 1184 | - } else { |
|
| 1185 | - $action = $nom; |
|
| 1186 | - } |
|
| 1187 | - $nomlower = strtolower($nom); |
|
| 1188 | - if ( |
|
| 1189 | - $nomlower != $nom |
|
| 1190 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | - ) { |
|
| 1193 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | - } |
|
| 1196 | - $nom = $nomlower; |
|
| 1197 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | - } |
|
| 1201 | - if ($action) { |
|
| 1202 | - if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | - ',(\|\||$),', |
|
| 1205 | - "|$prefix$action\\1", |
|
| 1206 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | - 1 |
|
| 1208 | - ); |
|
| 1209 | - } |
|
| 1210 | - if (isset($pipe['inclure'])) { |
|
| 1211 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | - } |
|
| 1221 | - foreach ($info['genie'] as $genie) { |
|
| 1222 | - $nom = $prefix . $genie['nom']; |
|
| 1223 | - $periode = max(60, intval($genie['periode'])); |
|
| 1224 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | - } else { |
|
| 1227 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | - $prepend_code['insert_head_css'] = ''; |
|
| 1234 | - } |
|
| 1235 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | - $prepend_code['header_prive_css'] = ''; |
|
| 1237 | - } |
|
| 1238 | - foreach ($info['style'] as $style) { |
|
| 1239 | - if (isset($style['path']) and $style['path']) { |
|
| 1240 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | - } else { |
|
| 1242 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | - } |
|
| 1244 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | - } |
|
| 1248 | - $code .= "/>';\n"; |
|
| 1249 | - if ($style['type'] != 'prive') { |
|
| 1250 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | - } |
|
| 1252 | - if ($style['type'] != 'public') { |
|
| 1253 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | - $prepend_code['insert_head'] = ''; |
|
| 1259 | - } |
|
| 1260 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | - $prepend_code['header_prive'] = ''; |
|
| 1262 | - } |
|
| 1263 | - if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | - foreach ($info['script'] as $script) { |
|
| 1265 | - if (isset($script['path']) and $script['path']) { |
|
| 1266 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | - } else { |
|
| 1268 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | - } |
|
| 1270 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | - if ($script['type'] != 'prive') { |
|
| 1272 | - $prepend_code['insert_head'] .= $code; |
|
| 1273 | - } |
|
| 1274 | - if ($script['type'] != 'public') { |
|
| 1275 | - $prepend_code['header_prive'] .= $code; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - $prepend_code['insert_head'] = |
|
| 1283 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | - . $prepend_code['insert_head']; |
|
| 1286 | - $prepend_code['header_prive'] = |
|
| 1287 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | - . $prepend_code['header_prive']; |
|
| 1290 | - |
|
| 1291 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - return $prepend_code; |
|
| 1165 | + static $liste_pipe_manquants = []; |
|
| 1166 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + $prepend_code = []; |
|
| 1171 | + |
|
| 1172 | + foreach ($ordre as $p => $info) { |
|
| 1173 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | + if (isset($plugin_valides[$p])) { |
|
| 1175 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | + $nom = $pipe['nom']; |
|
| 1182 | + if (isset($pipe['action'])) { |
|
| 1183 | + $action = $pipe['action']; |
|
| 1184 | + } else { |
|
| 1185 | + $action = $nom; |
|
| 1186 | + } |
|
| 1187 | + $nomlower = strtolower($nom); |
|
| 1188 | + if ( |
|
| 1189 | + $nomlower != $nom |
|
| 1190 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | + ) { |
|
| 1193 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | + } |
|
| 1196 | + $nom = $nomlower; |
|
| 1197 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | + } |
|
| 1201 | + if ($action) { |
|
| 1202 | + if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | + ',(\|\||$),', |
|
| 1205 | + "|$prefix$action\\1", |
|
| 1206 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | + 1 |
|
| 1208 | + ); |
|
| 1209 | + } |
|
| 1210 | + if (isset($pipe['inclure'])) { |
|
| 1211 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | + } |
|
| 1221 | + foreach ($info['genie'] as $genie) { |
|
| 1222 | + $nom = $prefix . $genie['nom']; |
|
| 1223 | + $periode = max(60, intval($genie['periode'])); |
|
| 1224 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | + } else { |
|
| 1227 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | + $prepend_code['insert_head_css'] = ''; |
|
| 1234 | + } |
|
| 1235 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | + $prepend_code['header_prive_css'] = ''; |
|
| 1237 | + } |
|
| 1238 | + foreach ($info['style'] as $style) { |
|
| 1239 | + if (isset($style['path']) and $style['path']) { |
|
| 1240 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | + } else { |
|
| 1242 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | + } |
|
| 1244 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | + } |
|
| 1248 | + $code .= "/>';\n"; |
|
| 1249 | + if ($style['type'] != 'prive') { |
|
| 1250 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | + } |
|
| 1252 | + if ($style['type'] != 'public') { |
|
| 1253 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | + $prepend_code['insert_head'] = ''; |
|
| 1259 | + } |
|
| 1260 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | + $prepend_code['header_prive'] = ''; |
|
| 1262 | + } |
|
| 1263 | + if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | + foreach ($info['script'] as $script) { |
|
| 1265 | + if (isset($script['path']) and $script['path']) { |
|
| 1266 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | + } else { |
|
| 1268 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | + } |
|
| 1270 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | + if ($script['type'] != 'prive') { |
|
| 1272 | + $prepend_code['insert_head'] .= $code; |
|
| 1273 | + } |
|
| 1274 | + if ($script['type'] != 'public') { |
|
| 1275 | + $prepend_code['header_prive'] .= $code; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + $prepend_code['insert_head'] = |
|
| 1283 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | + . $prepend_code['insert_head']; |
|
| 1286 | + $prepend_code['header_prive'] = |
|
| 1287 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | + . $prepend_code['header_prive']; |
|
| 1290 | + |
|
| 1291 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + return $prepend_code; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | /** |
@@ -1322,62 +1322,62 @@ discard block |
||
| 1322 | 1322 | **/ |
| 1323 | 1323 | function pipeline_precompile($prepend_code = []) { |
| 1324 | 1324 | |
| 1325 | - $all_pipes = $all_pipes_end = ''; |
|
| 1326 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | - $all_pipes = trim(array_shift($a)); |
|
| 1330 | - if ($all_pipes) { |
|
| 1331 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | - } |
|
| 1333 | - if (count($a)) { |
|
| 1334 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - $content = ''; |
|
| 1338 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | - $s_inc = ''; |
|
| 1340 | - $s_call = ''; |
|
| 1341 | - if ($all_pipes) { |
|
| 1342 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | - } |
|
| 1344 | - if ($all_pipes_end) { |
|
| 1345 | - $pipeline .= $all_pipes_end; |
|
| 1346 | - } |
|
| 1347 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | - foreach ($pipe as $fonc) { |
|
| 1350 | - $fonc = trim($fonc); |
|
| 1351 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | - $file = "'$file'"; |
|
| 1355 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | - $dir = $regs[1]; |
|
| 1358 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | - if (defined($root_dir)) { |
|
| 1360 | - $dir = $root_dir; |
|
| 1361 | - } |
|
| 1362 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | - $file = str_replace("''.", '', $file); |
|
| 1364 | - $file = str_replace(constant($dir), '', $file); |
|
| 1365 | - } |
|
| 1366 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - if (strlen($s_inc)) { |
|
| 1370 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | - } |
|
| 1372 | - $content .= "// Pipeline $action \n" |
|
| 1373 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | - . $s_inc |
|
| 1375 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | - . $s_call |
|
| 1377 | - . "return \$val;\n}\n"; |
|
| 1378 | - } |
|
| 1379 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | - clear_path_cache(); |
|
| 1325 | + $all_pipes = $all_pipes_end = ''; |
|
| 1326 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | + $all_pipes = trim(array_shift($a)); |
|
| 1330 | + if ($all_pipes) { |
|
| 1331 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | + } |
|
| 1333 | + if (count($a)) { |
|
| 1334 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + $content = ''; |
|
| 1338 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | + $s_inc = ''; |
|
| 1340 | + $s_call = ''; |
|
| 1341 | + if ($all_pipes) { |
|
| 1342 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | + } |
|
| 1344 | + if ($all_pipes_end) { |
|
| 1345 | + $pipeline .= $all_pipes_end; |
|
| 1346 | + } |
|
| 1347 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | + foreach ($pipe as $fonc) { |
|
| 1350 | + $fonc = trim($fonc); |
|
| 1351 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | + $file = "'$file'"; |
|
| 1355 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | + $dir = $regs[1]; |
|
| 1358 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | + if (defined($root_dir)) { |
|
| 1360 | + $dir = $root_dir; |
|
| 1361 | + } |
|
| 1362 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | + $file = str_replace("''.", '', $file); |
|
| 1364 | + $file = str_replace(constant($dir), '', $file); |
|
| 1365 | + } |
|
| 1366 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + if (strlen($s_inc)) { |
|
| 1370 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | + } |
|
| 1372 | + $content .= "// Pipeline $action \n" |
|
| 1373 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | + . $s_inc |
|
| 1375 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | + . $s_call |
|
| 1377 | + . "return \$val;\n}\n"; |
|
| 1378 | + } |
|
| 1379 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | + clear_path_cache(); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | |
@@ -1390,12 +1390,12 @@ discard block |
||
| 1390 | 1390 | * true si le plugin est actif, false sinon |
| 1391 | 1391 | **/ |
| 1392 | 1392 | function plugin_est_installe($plug_path) { |
| 1393 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | - if (!$plugin_installes) { |
|
| 1395 | - return false; |
|
| 1396 | - } |
|
| 1393 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | + if (!$plugin_installes) { |
|
| 1395 | + return false; |
|
| 1396 | + } |
|
| 1397 | 1397 | |
| 1398 | - return in_array($plug_path, $plugin_installes); |
|
| 1398 | + return in_array($plug_path, $plugin_installes); |
|
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | |
@@ -1408,46 +1408,46 @@ discard block |
||
| 1408 | 1408 | * @uses plugins_installer_dist() |
| 1409 | 1409 | **/ |
| 1410 | 1410 | function plugin_installes_meta() { |
| 1411 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | - $meta_plug_installes = []; |
|
| 1418 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | - if ($plug = $resume['dir']) { |
|
| 1420 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | - if ($infos) { |
|
| 1422 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | - $meta_plug_installes[] = $plug; |
|
| 1424 | - } |
|
| 1425 | - if (is_array($infos)) { |
|
| 1426 | - [$ok, $trace] = $infos['install_test']; |
|
| 1427 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | - if (_IS_CLI) { |
|
| 1430 | - include_spip('inc/filtres'); |
|
| 1431 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | - $trace, |
|
| 1435 | - "\n"; |
|
| 1436 | - } |
|
| 1437 | - else { |
|
| 1438 | - include_spip('inc/filtres_boites'); |
|
| 1439 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | - . $trace |
|
| 1442 | - . "<div class='result'>$result</div>" |
|
| 1443 | - . boite_fermer() |
|
| 1444 | - . '</div>'; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1411 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | + $meta_plug_installes = []; |
|
| 1418 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | + if ($plug = $resume['dir']) { |
|
| 1420 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | + if ($infos) { |
|
| 1422 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | + $meta_plug_installes[] = $plug; |
|
| 1424 | + } |
|
| 1425 | + if (is_array($infos)) { |
|
| 1426 | + [$ok, $trace] = $infos['install_test']; |
|
| 1427 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | + if (_IS_CLI) { |
|
| 1430 | + include_spip('inc/filtres'); |
|
| 1431 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | + $trace, |
|
| 1435 | + "\n"; |
|
| 1436 | + } |
|
| 1437 | + else { |
|
| 1438 | + include_spip('inc/filtres_boites'); |
|
| 1439 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | + . $trace |
|
| 1442 | + . "<div class='result'>$result</div>" |
|
| 1443 | + . boite_fermer() |
|
| 1444 | + . '</div>'; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | /** |
@@ -1461,29 +1461,29 @@ discard block |
||
| 1461 | 1461 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1464 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | - if (file_exists($nom)) { |
|
| 1472 | - if (substr($nom, -4) == '.php') { |
|
| 1473 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | - } |
|
| 1475 | - else { |
|
| 1476 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | - } |
|
| 1478 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | - @unlink($fichier_tmp); |
|
| 1482 | - return; |
|
| 1483 | - } |
|
| 1484 | - @unlink($fichier_tmp); |
|
| 1485 | - } |
|
| 1486 | - ecrire_fichier($nom, $contenu); |
|
| 1487 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1464 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | + if (file_exists($nom)) { |
|
| 1472 | + if (substr($nom, -4) == '.php') { |
|
| 1473 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | + } |
|
| 1475 | + else { |
|
| 1476 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | + } |
|
| 1478 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | + @unlink($fichier_tmp); |
|
| 1482 | + return; |
|
| 1483 | + } |
|
| 1484 | + @unlink($fichier_tmp); |
|
| 1485 | + } |
|
| 1486 | + ecrire_fichier($nom, $contenu); |
|
| 1487 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1489 | 1489 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | if ($dir) { |
| 382 | 382 | $dir .= '/'; |
| 383 | 383 | } |
| 384 | - $dir .= 'procure:' . $procure['nom']; |
|
| 384 | + $dir .= 'procure:'.$procure['nom']; |
|
| 385 | 385 | |
| 386 | 386 | $procure['etat'] = '?'; |
| 387 | 387 | $procure['dir_type'] = $resume['dir_type']; |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | $plug = $resume['dir']; |
| 566 | 566 | $k = $infos[$dir_type][$plug]; |
| 567 | 567 | |
| 568 | - $plug = constant($dir_type) . $plug; |
|
| 568 | + $plug = constant($dir_type).$plug; |
|
| 569 | 569 | if (!isset($msg[$p])) { |
| 570 | 570 | if (isset($resume['erreur']) and $resume['erreur']) { |
| 571 | 571 | $msg[$p] = [$resume['erreur']]; |
@@ -608,10 +608,10 @@ discard block |
||
| 608 | 608 | $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
| 609 | 609 | } elseif (!$raw) { |
| 610 | 610 | foreach ($list as $plug => $msg) { |
| 611 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 611 | + $list[$plug] = '<li>'._T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | + . '<ul><li>'.implode('</li><li>', $msg).'</li></ul></li>'; |
|
| 613 | 613 | } |
| 614 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 614 | + $list = '<ul>'.join("\n", $list).'</ul>'; |
|
| 615 | 615 | } |
| 616 | 616 | if ($raz) { |
| 617 | 617 | effacer_meta('plugin_erreur_activation'); |
@@ -725,13 +725,13 @@ discard block |
||
| 725 | 725 | if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
| 726 | 726 | return _T("plugin_{$balise}_{$type}", [ |
| 727 | 727 | 'plugin' => $nom, |
| 728 | - 'version' => ' ≥ ' . $minimum |
|
| 728 | + 'version' => ' ≥ '.$minimum |
|
| 729 | 729 | ]); |
| 730 | 730 | } |
| 731 | 731 | if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
| 732 | 732 | return _T("plugin_{$balise}_{$type}", [ |
| 733 | 733 | 'plugin' => $nom, |
| 734 | - 'version' => ' > ' . $minimum |
|
| 734 | + 'version' => ' > '.$minimum |
|
| 735 | 735 | ]); |
| 736 | 736 | } |
| 737 | 737 | } |
@@ -740,13 +740,13 @@ discard block |
||
| 740 | 740 | if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
| 741 | 741 | return _T("plugin_{$balise}_{$type}", [ |
| 742 | 742 | 'plugin' => $nom, |
| 743 | - 'version' => ' ≤ ' . $maximum |
|
| 743 | + 'version' => ' ≤ '.$maximum |
|
| 744 | 744 | ]); |
| 745 | 745 | } |
| 746 | 746 | if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
| 747 | 747 | return _T("plugin_{$balise}_plugin", [ |
| 748 | 748 | 'plugin' => $nom, |
| 749 | - 'version' => ' < ' . $maximum |
|
| 749 | + 'version' => ' < '.$maximum |
|
| 750 | 750 | ]); |
| 751 | 751 | } |
| 752 | 752 | } |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | include_spip('inc/charger_plugin'); |
| 766 | 766 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 767 | 767 | }*/ |
| 768 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 768 | + return _T('plugin_necessite_lib', ['lib' => $lib])." <a href='$url'>$url</a>"; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | foreach ($plugin_valides as $p => $resume) { |
| 866 | 866 | // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
| 867 | 867 | if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
| 868 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 868 | + $header[] = $p.($resume['version'] ? '('.$resume['version'].')' : ''); |
|
| 869 | 869 | } |
| 870 | 870 | if ($resume['dir']) { |
| 871 | 871 | foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
@@ -890,11 +890,11 @@ discard block |
||
| 890 | 890 | $header = strtolower(implode(',', $header)); |
| 891 | 891 | if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
| 892 | 892 | ecrire_fichier( |
| 893 | - _DIR_VAR . 'config.txt', |
|
| 894 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 893 | + _DIR_VAR.'config.txt', |
|
| 894 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP').' '.$GLOBALS['spip_version_affichee'].' @ www.spip.net + '.$header |
|
| 895 | 895 | ); |
| 896 | 896 | } else { |
| 897 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 897 | + @unlink(_DIR_VAR.'config.txt'); |
|
| 898 | 898 | } |
| 899 | 899 | // generer charger_plugins_chemin.php |
| 900 | 900 | plugins_precompile_chemin($plugin_valides, $ordre); |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | // definir le plugin, donc le path avant l'include du fichier options |
| 949 | 949 | // permet de faire des include_spip pour attraper un inc_ du plugin |
| 950 | 950 | |
| 951 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 951 | + $dir = $dir_type.".'".$plug."/'"; |
|
| 952 | 952 | |
| 953 | 953 | $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
| 954 | 954 | if ( |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | if (!$info['chemin']) { |
| 960 | 960 | $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
| 961 | 961 | $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
| 962 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 962 | + if (is_dir(constant($dir_type).$plug.'/squelettes/')) { |
|
| 963 | 963 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 964 | 964 | } |
| 965 | 965 | } |
@@ -980,13 +980,13 @@ discard block |
||
| 980 | 980 | $dir = ''; |
| 981 | 981 | } |
| 982 | 982 | if (strlen($dir)) { |
| 983 | - $dir = rtrim($dir, '/') . '/'; |
|
| 983 | + $dir = rtrim($dir, '/').'/'; |
|
| 984 | 984 | } |
| 985 | 985 | if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
| 986 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 986 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | 987 | } |
| 988 | 988 | if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
| 989 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 989 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | 990 | } |
| 991 | 991 | } |
| 992 | 992 | } |
@@ -995,11 +995,11 @@ discard block |
||
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | if (count($chemins['public']) or count($chemins['prive'])) { |
| 998 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 998 | + $contenu .= 'if (_DIR_RESTREINT) _chemin(['.implode( |
|
| 999 | 999 | ',', |
| 1000 | 1000 | array_reverse($chemins['public']) |
| 1001 | - ) . "]);\n" |
|
| 1002 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1001 | + )."]);\n" |
|
| 1002 | + . 'else _chemin(['.implode(',', array_reverse($chemins['prive']))."]);\n"; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | and strpos($dir, ':') === false // exclure le cas des procure: |
| 1049 | 1049 | and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
| 1050 | 1050 | ) { |
| 1051 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1051 | + if (is_readable("$dir$plug/".($file = $info['prefix'].'_'.$charge.'.php'))) { |
|
| 1052 | 1052 | $info[$charge] = [$file]; |
| 1053 | 1053 | } |
| 1054 | 1054 | } |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | ) { |
| 1066 | 1066 | unset($info[$charge][$k]); |
| 1067 | 1067 | } else { |
| 1068 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1068 | + $_file = $root_dir_type.".'$plug/$file'"; |
|
| 1069 | 1069 | $contenu[$charge] .= "include_once_check($_file);\n"; |
| 1070 | 1070 | } |
| 1071 | 1071 | } |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | } |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1078 | + $contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options']; |
|
| 1079 | 1079 | $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
| 1080 | 1080 | . plugin_ongletbouton('onglets_plugins', $onglets); |
| 1081 | 1081 | |
@@ -1110,12 +1110,12 @@ discard block |
||
| 1110 | 1110 | define("_UPDATED_$nom", $val); |
| 1111 | 1111 | define("_UPDATED_md5_$nom", $md5); |
| 1112 | 1112 | } |
| 1113 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1113 | + $val = "unserialize('".str_replace("'", "\'", $val)."')"; |
|
| 1114 | 1114 | |
| 1115 | 1115 | return |
| 1116 | 1116 | "if (!function_exists('$nom')) {\n" |
| 1117 | 1117 | . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
| 1118 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1118 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n" |
|
| 1119 | 1119 | . "}\n"; |
| 1120 | 1120 | } |
| 1121 | 1121 | |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | if (@is_readable(_CACHE_PLUGINS_OPT)) { |
| 1139 | 1139 | include_once(_CACHE_PLUGINS_OPT); |
| 1140 | 1140 | } else { |
| 1141 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1141 | + spip_log('pipelines desactives: impossible de produire '._CACHE_PLUGINS_OPT); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | } |
| 1144 | 1144 | |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | $dir_type = $plugin_valides[$p]['dir_type']; |
| 1176 | 1176 | $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
| 1177 | 1177 | $plug = $plugin_valides[$p]['dir']; |
| 1178 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1178 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'].'_'); |
|
| 1179 | 1179 | if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
| 1180 | 1180 | foreach ($info['pipeline'] as $pipe) { |
| 1181 | 1181 | $nom = $pipe['nom']; |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | } |
| 1210 | 1210 | if (isset($pipe['inclure'])) { |
| 1211 | 1211 | $GLOBALS['spip_matrice']["$prefix$action"] = |
| 1212 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1212 | + "$root_dir_type:$plug/".$pipe['inclure']; |
|
| 1213 | 1213 | } |
| 1214 | 1214 | } |
| 1215 | 1215 | } |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | $prepend_code['taches_generales_cron'] = ''; |
| 1220 | 1220 | } |
| 1221 | 1221 | foreach ($info['genie'] as $genie) { |
| 1222 | - $nom = $prefix . $genie['nom']; |
|
| 1222 | + $nom = $prefix.$genie['nom']; |
|
| 1223 | 1223 | $periode = max(60, intval($genie['periode'])); |
| 1224 | 1224 | if (charger_fonction($nom, 'genie', true)) { |
| 1225 | 1225 | $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
@@ -1237,13 +1237,13 @@ discard block |
||
| 1237 | 1237 | } |
| 1238 | 1238 | foreach ($info['style'] as $style) { |
| 1239 | 1239 | if (isset($style['path']) and $style['path']) { |
| 1240 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1240 | + $code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) "; |
|
| 1241 | 1241 | } else { |
| 1242 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1242 | + $code = "if (\$f='".addslashes($style['url'])."') "; |
|
| 1243 | 1243 | } |
| 1244 | 1244 | $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
| 1245 | 1245 | if (isset($style['media']) and strlen($style['media'])) { |
| 1246 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1246 | + $code .= ' media="'.addslashes($style['media']).'"'; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | $code .= "/>';\n"; |
| 1249 | 1249 | if ($style['type'] != 'prive') { |
@@ -1263,9 +1263,9 @@ discard block |
||
| 1263 | 1263 | if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
| 1264 | 1264 | foreach ($info['script'] as $script) { |
| 1265 | 1265 | if (isset($script['path']) and $script['path']) { |
| 1266 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1266 | + $code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) "; |
|
| 1267 | 1267 | } else { |
| 1268 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1268 | + $code = "if (\$f='".addslashes($script['url'])."') "; |
|
| 1269 | 1269 | } |
| 1270 | 1270 | $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
| 1271 | 1271 | if ($script['type'] != 'prive') { |
@@ -1328,10 +1328,10 @@ discard block |
||
| 1328 | 1328 | unset($GLOBALS['spip_pipeline']['all']); |
| 1329 | 1329 | $all_pipes = trim(array_shift($a)); |
| 1330 | 1330 | if ($all_pipes) { |
| 1331 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1331 | + $all_pipes = '|'.ltrim($all_pipes, '|'); |
|
| 1332 | 1332 | } |
| 1333 | 1333 | if (count($a)) { |
| 1334 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1334 | + $all_pipes_end = '||'.array_shift($a); |
|
| 1335 | 1335 | } |
| 1336 | 1336 | } |
| 1337 | 1337 | $content = ''; |
@@ -1348,7 +1348,7 @@ discard block |
||
| 1348 | 1348 | // Eclater le pipeline en filtres et appliquer chaque filtre |
| 1349 | 1349 | foreach ($pipe as $fonc) { |
| 1350 | 1350 | $fonc = trim($fonc); |
| 1351 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1351 | + $s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n"; |
|
| 1352 | 1352 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 1353 | 1353 | $file = $GLOBALS['spip_matrice'][$fonc]; |
| 1354 | 1354 | $file = "'$file'"; |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | if (defined($root_dir)) { |
| 1360 | 1360 | $dir = $root_dir; |
| 1361 | 1361 | } |
| 1362 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1362 | + $file = str_replace($regs[0], "'.".$dir.".'", $file); |
|
| 1363 | 1363 | $file = str_replace("''.", '', $file); |
| 1364 | 1364 | $file = str_replace(constant($dir), '', $file); |
| 1365 | 1365 | } |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | $content .= "// Pipeline $action \n" |
| 1373 | 1373 | . "function execute_pipeline_$action(&\$val){\n" |
| 1374 | 1374 | . $s_inc |
| 1375 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1375 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '') |
|
| 1376 | 1376 | . $s_call |
| 1377 | 1377 | . "return \$val;\n}\n"; |
| 1378 | 1378 | } |
@@ -1428,9 +1428,9 @@ discard block |
||
| 1428 | 1428 | $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
| 1429 | 1429 | if (_IS_CLI) { |
| 1430 | 1430 | include_spip('inc/filtres'); |
| 1431 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1431 | + $trace = ltrim(textebrut($trace)."\n".$result); |
|
| 1432 | + $trace = ' '.str_replace("\n", "\n ", $trace); |
|
| 1433 | + echo "\n".($ok ? 'OK ' : '/!\ ').textebrut($titre)."\n", |
|
| 1434 | 1434 | $trace, |
| 1435 | 1435 | "\n"; |
| 1436 | 1436 | } |
@@ -1465,15 +1465,15 @@ discard block |
||
| 1465 | 1465 | $GLOBALS['fichier_php_compile_recent'] = 0; |
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1468 | + $contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>'; |
|
| 1469 | 1469 | // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
| 1470 | 1470 | // si pas de modif on ne touche pas au fichier initial |
| 1471 | 1471 | if (file_exists($nom)) { |
| 1472 | 1472 | if (substr($nom, -4) == '.php') { |
| 1473 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1473 | + $fichier_tmp = substr($nom, 0, -4).'.tmp.php'; |
|
| 1474 | 1474 | } |
| 1475 | 1475 | else { |
| 1476 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1476 | + $fichier_tmp = $nom.'.tmp'; |
|
| 1477 | 1477 | } |
| 1478 | 1478 | file_put_contents($fichier_tmp, $contenu); |
| 1479 | 1479 | if (md5_file($nom) == md5_file($fichier_tmp)) { |
@@ -20,21 +20,21 @@ |
||
| 20 | 20 | * Retourne la liste des menus favoris par défaut ainsi que leur rang |
| 21 | 21 | */ |
| 22 | 22 | function inc_definir_menus_favoris_dist() { |
| 23 | - $liste = [ |
|
| 23 | + $liste = [ |
|
| 24 | 24 | |
| 25 | - // Menu Édition, |
|
| 26 | - 'auteurs' => 1, |
|
| 27 | - 'rubriques' => 2, |
|
| 28 | - 'articles' => 3, |
|
| 25 | + // Menu Édition, |
|
| 26 | + 'auteurs' => 1, |
|
| 27 | + 'rubriques' => 2, |
|
| 28 | + 'articles' => 3, |
|
| 29 | 29 | |
| 30 | - // Menu Maintenance |
|
| 31 | - 'admin_vider' => 1, |
|
| 30 | + // Menu Maintenance |
|
| 31 | + 'admin_vider' => 1, |
|
| 32 | 32 | |
| 33 | - // Menu Configurations |
|
| 34 | - 'configurer_identite' => 1, |
|
| 35 | - 'admin_plugin' => 2, |
|
| 33 | + // Menu Configurations |
|
| 34 | + 'configurer_identite' => 1, |
|
| 35 | + 'admin_plugin' => 2, |
|
| 36 | 36 | |
| 37 | - ]; |
|
| 37 | + ]; |
|
| 38 | 38 | |
| 39 | - return $liste; |
|
| 39 | + return $liste; |
|
| 40 | 40 | } |
@@ -416,7 +416,7 @@ |
||
| 416 | 416 | $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
| 417 | 417 | $t = supprimer_tags($titre); |
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 25 | - /** |
|
| 26 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | - * |
|
| 28 | - * Peut ralentir un site sur des listes très longues. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - **/ |
|
| 32 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 25 | + /** |
|
| 26 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | + * |
|
| 28 | + * Peut ralentir un site sur des listes très longues. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + **/ |
|
| 32 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -57,31 +57,31 @@ discard block |
||
| 57 | 57 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 58 | 58 | */ |
| 59 | 59 | function inc_puce_statut_dist( |
| 60 | - $id_objet, |
|
| 61 | - $statut, |
|
| 62 | - $id_parent, |
|
| 63 | - $type, |
|
| 64 | - $ajax = false, |
|
| 65 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 60 | + $id_objet, |
|
| 61 | + $statut, |
|
| 62 | + $id_parent, |
|
| 63 | + $type, |
|
| 64 | + $ajax = false, |
|
| 65 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 66 | 66 | ) { |
| 67 | - static $f_puce_statut = []; |
|
| 68 | - $type = objet_type($type); |
|
| 69 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | - if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | - } |
|
| 73 | - if ($f_puce_statut[$type]) { |
|
| 74 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | - // composer une puce, avec si possible changement rapide |
|
| 79 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | - return $puce; |
|
| 81 | - } // sinon fausse puce avec le type de l'image |
|
| 82 | - else { |
|
| 83 | - return http_img_pack("$type-16.png", ''); |
|
| 84 | - } |
|
| 67 | + static $f_puce_statut = []; |
|
| 68 | + $type = objet_type($type); |
|
| 69 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | + if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | + } |
|
| 73 | + if ($f_puce_statut[$type]) { |
|
| 74 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | + // composer une puce, avec si possible changement rapide |
|
| 79 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | + return $puce; |
|
| 81 | + } // sinon fausse puce avec le type de l'image |
|
| 82 | + else { |
|
| 83 | + return http_img_pack("$type-16.png", ''); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -110,41 +110,41 @@ discard block |
||
| 110 | 110 | * null si pas capable de déterminer l'image |
| 111 | 111 | */ |
| 112 | 112 | function statut_image($objet, $statut) { |
| 113 | - $src = null; |
|
| 114 | - $table = table_objet_sql($objet); |
|
| 115 | - $desc = lister_tables_objets_sql($table); |
|
| 116 | - if (isset($desc['statut_images'])) { |
|
| 117 | - // si une declaration statut_images |
|
| 118 | - // mais rien pour le statut demande, ne rien afficher |
|
| 119 | - $src = ''; |
|
| 120 | - if (isset($desc['statut_images'][$statut])) { |
|
| 121 | - $src = $desc['statut_images'][$statut]; |
|
| 122 | - } // sinon image par defaut ? |
|
| 123 | - elseif (isset($desc['statut_images'][0])) { |
|
| 124 | - $src = $desc['statut_images'][0]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - switch ($statut) { |
|
| 128 | - case 'prepa': |
|
| 129 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | - break; |
|
| 131 | - case 'prop': |
|
| 132 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | - break; |
|
| 134 | - case 'publie': |
|
| 135 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | - break; |
|
| 137 | - case 'refuse': |
|
| 138 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | - break; |
|
| 140 | - case 'poubelle': |
|
| 141 | - case 'poub': |
|
| 142 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $src; |
|
| 113 | + $src = null; |
|
| 114 | + $table = table_objet_sql($objet); |
|
| 115 | + $desc = lister_tables_objets_sql($table); |
|
| 116 | + if (isset($desc['statut_images'])) { |
|
| 117 | + // si une declaration statut_images |
|
| 118 | + // mais rien pour le statut demande, ne rien afficher |
|
| 119 | + $src = ''; |
|
| 120 | + if (isset($desc['statut_images'][$statut])) { |
|
| 121 | + $src = $desc['statut_images'][$statut]; |
|
| 122 | + } // sinon image par defaut ? |
|
| 123 | + elseif (isset($desc['statut_images'][0])) { |
|
| 124 | + $src = $desc['statut_images'][0]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + switch ($statut) { |
|
| 128 | + case 'prepa': |
|
| 129 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | + break; |
|
| 131 | + case 'prop': |
|
| 132 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | + break; |
|
| 134 | + case 'publie': |
|
| 135 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | + break; |
|
| 137 | + case 'refuse': |
|
| 138 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | + break; |
|
| 140 | + case 'poubelle': |
|
| 141 | + case 'poub': |
|
| 142 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $src; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -172,40 +172,40 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | function statut_titre($objet, $statut) { |
| 175 | - $titre = ''; |
|
| 176 | - $table = table_objet_sql($objet); |
|
| 177 | - $desc = lister_tables_objets_sql($table); |
|
| 178 | - if (isset($desc['statut_titres'])) { |
|
| 179 | - // si une declaration statut_titres |
|
| 180 | - // mais rien pour le statut demande, ne rien afficher |
|
| 181 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | - $titre = $desc['statut_titres'][$statut]; |
|
| 183 | - } // sinon image par defaut ? |
|
| 184 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | - $titre = $desc['statut_titres'][0]; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - switch ($statut) { |
|
| 189 | - case 'prepa': |
|
| 190 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | - break; |
|
| 192 | - case 'prop': |
|
| 193 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | - break; |
|
| 195 | - case 'publie': |
|
| 196 | - $titre = 'texte_statut_publie'; |
|
| 197 | - break; |
|
| 198 | - case 'refuse': |
|
| 199 | - $titre = 'texte_statut_refuse'; |
|
| 200 | - break; |
|
| 201 | - case 'poubelle': |
|
| 202 | - case 'poub': |
|
| 203 | - $titre = 'texte_statut_poubelle'; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $titre ? _T($titre) : ''; |
|
| 175 | + $titre = ''; |
|
| 176 | + $table = table_objet_sql($objet); |
|
| 177 | + $desc = lister_tables_objets_sql($table); |
|
| 178 | + if (isset($desc['statut_titres'])) { |
|
| 179 | + // si une declaration statut_titres |
|
| 180 | + // mais rien pour le statut demande, ne rien afficher |
|
| 181 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | + $titre = $desc['statut_titres'][$statut]; |
|
| 183 | + } // sinon image par defaut ? |
|
| 184 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | + $titre = $desc['statut_titres'][0]; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + switch ($statut) { |
|
| 189 | + case 'prepa': |
|
| 190 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | + break; |
|
| 192 | + case 'prop': |
|
| 193 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | + break; |
|
| 195 | + case 'publie': |
|
| 196 | + $titre = 'texte_statut_publie'; |
|
| 197 | + break; |
|
| 198 | + case 'refuse': |
|
| 199 | + $titre = 'texte_statut_refuse'; |
|
| 200 | + break; |
|
| 201 | + case 'poubelle': |
|
| 202 | + case 'poub': |
|
| 203 | + $titre = 'texte_statut_poubelle'; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $titre ? _T($titre) : ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -225,37 +225,37 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | function statut_texte_instituer($objet, $statut) { |
| 228 | - $texte = ''; |
|
| 229 | - $table = table_objet_sql($objet); |
|
| 230 | - $desc = lister_tables_objets_sql($table); |
|
| 231 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | - // si une declaration statut_titres |
|
| 233 | - // mais rien pour le statut demande, ne rien afficher |
|
| 234 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | - } |
|
| 237 | - } else { |
|
| 238 | - switch ($statut) { |
|
| 239 | - case 'prepa': |
|
| 240 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | - break; |
|
| 242 | - case 'prop': |
|
| 243 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | - break; |
|
| 245 | - case 'publie': |
|
| 246 | - $texte = 'texte_statut_publie'; |
|
| 247 | - break; |
|
| 248 | - case 'refuse': |
|
| 249 | - $texte = 'texte_statut_refuse'; |
|
| 250 | - break; |
|
| 251 | - case 'poubelle': |
|
| 252 | - case 'poub': |
|
| 253 | - $texte = 'texte_statut_poubelle'; |
|
| 254 | - break; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte ? _T($texte) : ''; |
|
| 228 | + $texte = ''; |
|
| 229 | + $table = table_objet_sql($objet); |
|
| 230 | + $desc = lister_tables_objets_sql($table); |
|
| 231 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | + // si une declaration statut_titres |
|
| 233 | + // mais rien pour le statut demande, ne rien afficher |
|
| 234 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | + } |
|
| 237 | + } else { |
|
| 238 | + switch ($statut) { |
|
| 239 | + case 'prepa': |
|
| 240 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | + break; |
|
| 242 | + case 'prop': |
|
| 243 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | + break; |
|
| 245 | + case 'publie': |
|
| 246 | + $texte = 'texte_statut_publie'; |
|
| 247 | + break; |
|
| 248 | + case 'refuse': |
|
| 249 | + $texte = 'texte_statut_refuse'; |
|
| 250 | + break; |
|
| 251 | + case 'poubelle': |
|
| 252 | + case 'poub': |
|
| 253 | + $texte = 'texte_statut_poubelle'; |
|
| 254 | + break; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte ? _T($texte) : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 278 | - $img = statut_image('auteur', $statut); |
|
| 279 | - if (!$img) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - $alt = statut_titre('auteur', $statut); |
|
| 278 | + $img = statut_image('auteur', $statut); |
|
| 279 | + if (!$img) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + $alt = statut_titre('auteur', $statut); |
|
| 283 | 283 | |
| 284 | - $fond = ''; |
|
| 285 | - $titre = ''; |
|
| 284 | + $fond = ''; |
|
| 285 | + $titre = ''; |
|
| 286 | 286 | |
| 287 | - /* |
|
| 287 | + /* |
|
| 288 | 288 | if ($type != 'auteur') { |
| 289 | 289 | $img2 = chemin_image('del-16.png'); |
| 290 | 290 | $titre = _T('titre_image_redacteur'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 302 | - return http_img_pack('rubrique-16.png', ''); |
|
| 302 | + return http_img_pack('rubrique-16.png', ''); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -323,110 +323,110 @@ discard block |
||
| 323 | 323 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 324 | 324 | **/ |
| 325 | 325 | function puce_statut_changement_rapide( |
| 326 | - $id, |
|
| 327 | - $statut, |
|
| 328 | - $id_rubrique, |
|
| 329 | - $type = 'article', |
|
| 330 | - $ajax = false, |
|
| 331 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 326 | + $id, |
|
| 327 | + $statut, |
|
| 328 | + $id_rubrique, |
|
| 329 | + $type = 'article', |
|
| 330 | + $ajax = false, |
|
| 331 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 332 | 332 | ) { |
| 333 | - $src = statut_image($type, $statut); |
|
| 334 | - if (!$src) { |
|
| 335 | - return $src; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( |
|
| 339 | - !$id |
|
| 340 | - or !_SPIP_AJAX |
|
| 341 | - or !$menu_rapide |
|
| 342 | - ) { |
|
| 343 | - $ajax_node = ''; |
|
| 344 | - } else { |
|
| 345 | - $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - $t = statut_titre($type, $statut); |
|
| 350 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | - |
|
| 352 | - if (!$ajax_node) { |
|
| 353 | - return $inser_puce; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $table = table_objet_sql($type); |
|
| 357 | - $desc = lister_tables_objets_sql($table); |
|
| 358 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | - return $inser_puce; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (!function_exists('autoriser')) { |
|
| 363 | - include_spip('inc/autoriser'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | - if ($id_rubrique) { |
|
| 368 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | - return $inser_puce; |
|
| 370 | - } |
|
| 371 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | - else { |
|
| 373 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | - return $inser_puce; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | - if (!isset($coord[$statut])) { |
|
| 380 | - return $inser_puce; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | - ; |
|
| 385 | - $margin = 0; /* marge a gauche + droite */ |
|
| 386 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | - ; |
|
| 388 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | - |
|
| 390 | - if ($ajax) { |
|
| 391 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 392 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | - . $inser_puce |
|
| 394 | - . '</span>' |
|
| 395 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | - $i = 0; |
|
| 397 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | - } |
|
| 400 | - $out .= '</span>'; |
|
| 401 | - |
|
| 402 | - return $out; |
|
| 403 | - } else { |
|
| 404 | - $nom = 'puce_statut_'; |
|
| 405 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | - $lang_dir = lang_dir(lang_typo()); |
|
| 407 | - |
|
| 408 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | - . $inser_puce |
|
| 410 | - . '</span>'; |
|
| 411 | - } |
|
| 333 | + $src = statut_image($type, $statut); |
|
| 334 | + if (!$src) { |
|
| 335 | + return $src; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( |
|
| 339 | + !$id |
|
| 340 | + or !_SPIP_AJAX |
|
| 341 | + or !$menu_rapide |
|
| 342 | + ) { |
|
| 343 | + $ajax_node = ''; |
|
| 344 | + } else { |
|
| 345 | + $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + $t = statut_titre($type, $statut); |
|
| 350 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | + |
|
| 352 | + if (!$ajax_node) { |
|
| 353 | + return $inser_puce; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $table = table_objet_sql($type); |
|
| 357 | + $desc = lister_tables_objets_sql($table); |
|
| 358 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | + return $inser_puce; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (!function_exists('autoriser')) { |
|
| 363 | + include_spip('inc/autoriser'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | + if ($id_rubrique) { |
|
| 368 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | + return $inser_puce; |
|
| 370 | + } |
|
| 371 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | + else { |
|
| 373 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | + return $inser_puce; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | + if (!isset($coord[$statut])) { |
|
| 380 | + return $inser_puce; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | + ; |
|
| 385 | + $margin = 0; /* marge a gauche + droite */ |
|
| 386 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | + ; |
|
| 388 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | + |
|
| 390 | + if ($ajax) { |
|
| 391 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 392 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | + . $inser_puce |
|
| 394 | + . '</span>' |
|
| 395 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | + $i = 0; |
|
| 397 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | + } |
|
| 400 | + $out .= '</span>'; |
|
| 401 | + |
|
| 402 | + return $out; |
|
| 403 | + } else { |
|
| 404 | + $nom = 'puce_statut_'; |
|
| 405 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | + $lang_dir = lang_dir(lang_typo()); |
|
| 407 | + |
|
| 408 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | + . $inser_puce |
|
| 410 | + . '</span>'; |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| 415 | 415 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 416 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | - $t = supprimer_tags($titre); |
|
| 416 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | + $t = supprimer_tags($titre); |
|
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
| 423 | 423 | // La couleur du statut |
| 424 | 424 | |
| 425 | 425 | function puce_statut($statut, $atts = '') { |
| 426 | - $src = statut_image('article', $statut); |
|
| 427 | - if (!$src) { |
|
| 428 | - return ''; |
|
| 429 | - } |
|
| 426 | + $src = statut_image('article', $statut); |
|
| 427 | + if (!$src) { |
|
| 428 | + return ''; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 431 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 432 | 432 | } |
@@ -524,8 +524,7 @@ discard block |
||
| 524 | 524 | process_image_svg_identite($ret); |
| 525 | 525 | $ret['creer'] = false; |
| 526 | 526 | } |
| 527 | - } |
|
| 528 | - else { |
|
| 527 | + } else { |
|
| 529 | 528 | if (!function_exists($ret['fonction_imagecreatefrom'])) { |
| 530 | 529 | return false; |
| 531 | 530 | } |
@@ -628,8 +627,7 @@ discard block |
||
| 628 | 627 | |
| 629 | 628 | if (isset($info['mime'])) { |
| 630 | 629 | $mime = $info['mime']; |
| 631 | - } |
|
| 632 | - else { |
|
| 630 | + } else { |
|
| 633 | 631 | $mime = image_type_to_mime_type($info[2]); |
| 634 | 632 | } |
| 635 | 633 | |
@@ -1408,9 +1406,7 @@ discard block |
||
| 1408 | 1406 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1409 | 1407 | $vignette = $destination . '.' . $format; |
| 1410 | 1408 | @copy($image, $vignette); |
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1409 | + } elseif ($valeurs['format_source'] === 'svg') { |
|
| 1414 | 1410 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1415 | 1411 | $format_sortie = 'svg'; |
| 1416 | 1412 | $vignette = $destination . '.' . $format_sortie; |
@@ -1846,8 +1842,7 @@ discard block |
||
| 1846 | 1842 | $date = test_espace_prive() ? ('?' . $date) : ''; |
| 1847 | 1843 | |
| 1848 | 1844 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1849 | - } |
|
| 1850 | - else { |
|
| 1845 | + } else { |
|
| 1851 | 1846 | # BMP, tiff ... les redacteurs osent tout! |
| 1852 | 1847 | return $img; |
| 1853 | 1848 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | $blue = dechex($blue); |
| 44 | 44 | |
| 45 | 45 | if (strlen($red) == 1) { |
| 46 | - $red = '0' . $red; |
|
| 46 | + $red = '0'.$red; |
|
| 47 | 47 | } |
| 48 | 48 | if (strlen($green) == 1) { |
| 49 | - $green = '0' . $green; |
|
| 49 | + $green = '0'.$green; |
|
| 50 | 50 | } |
| 51 | 51 | if (strlen($blue) == 1) { |
| 52 | - $blue = '0' . $blue; |
|
| 52 | + $blue = '0'.$blue; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $var_G = ($G / 255); |
| 126 | 126 | $var_B = ($B / 255); |
| 127 | 127 | |
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | 131 | |
| 132 | 132 | $L = ($var_Max + $var_Min) / 2; |
| 133 | 133 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | 191 | // helper |
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 193 | 193 | if ($vH < 0) { |
| 194 | 194 | $vH += 1; |
| 195 | 195 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | $img = "<img src='$source' />"; |
| 322 | 322 | } elseif ( |
| 323 | 323 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]) |
|
| 325 | 325 | and in_array($extension, _image_extensions_acceptees_en_entree()) |
| 326 | 326 | ) { |
| 327 | 327 | # gerer img src="data:....base64" |
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 329 | 329 | if (!file_exists($local)) { |
| 330 | 330 | ecrire_fichier($local, base64_decode($regs[2])); |
| 331 | 331 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // les protocoles web prennent au moins 3 lettres |
| 343 | 343 | if (tester_url_absolue($source)) { |
| 344 | 344 | include_spip('inc/distant'); |
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 346 | 346 | if (!$fichier) { |
| 347 | 347 | return ''; |
| 348 | 348 | } |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | // on garde la terminaison initiale car image simplement copiee |
| 441 | 441 | // et on postfixe son nom avec un md5 du path |
| 442 | 442 | $terminaison_dest = $terminaison; |
| 443 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 444 | 444 | } else { |
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | 446 | } |
| 447 | 447 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 448 | 448 | $cache = sous_repertoire($cache, $effet); |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | $fichier_dest = substr($fichier_dest, 2); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 457 | 457 | |
| 458 | 458 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 459 | 459 | |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | |
| 492 | 492 | if ($creer) { |
| 493 | 493 | spip_log( |
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 494 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 495 | + 'images'._LOG_DEBUG |
|
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 501 | 501 | $ret['fichier'] = $fichier; |
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 503 | 503 | $ret['fichier_dest'] = $fichier_dest; |
| 504 | 504 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 505 | 505 | $ret['format_dest'] = $terminaison_dest; |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 651 | 651 | if ($_terminaison and $_terminaison !== $terminaison) { |
| 652 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 652 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 653 | 653 | $terminaison = $_terminaison; |
| 654 | 654 | } |
| 655 | 655 | return $terminaison; |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | if (!function_exists('imagepng')) { |
| 807 | 807 | return false; |
| 808 | 808 | } |
| 809 | - $tmp = $fichier . '.tmp'; |
|
| 809 | + $tmp = $fichier.'.tmp'; |
|
| 810 | 810 | $ret = imagepng($img, $tmp); |
| 811 | 811 | if (file_exists($tmp)) { |
| 812 | 812 | $taille_test = getimagesize($tmp); |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | if (!function_exists('imagegif')) { |
| 842 | 842 | return false; |
| 843 | 843 | } |
| 844 | - $tmp = $fichier . '.tmp'; |
|
| 844 | + $tmp = $fichier.'.tmp'; |
|
| 845 | 845 | $ret = imagegif($img, $tmp); |
| 846 | 846 | if (file_exists($tmp)) { |
| 847 | 847 | $taille_test = getimagesize($tmp); |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | if (!function_exists('imagejpeg')) { |
| 882 | 882 | return false; |
| 883 | 883 | } |
| 884 | - $tmp = $fichier . '.tmp'; |
|
| 884 | + $tmp = $fichier.'.tmp'; |
|
| 885 | 885 | |
| 886 | 886 | // Enable interlancing |
| 887 | 887 | imageinterlace($img, true); |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | if (!function_exists('imagewebp')) { |
| 943 | 943 | return false; |
| 944 | 944 | } |
| 945 | - $tmp = $fichier . '.tmp'; |
|
| 945 | + $tmp = $fichier.'.tmp'; |
|
| 946 | 946 | $ret = imagewebp($img, $tmp, $qualite); |
| 947 | 947 | if (file_exists($tmp)) { |
| 948 | 948 | $taille_test = getimagesize($tmp); |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | function _image_imagesvg($img, $fichier) { |
| 978 | 978 | |
| 979 | - $tmp = $fichier . '.tmp'; |
|
| 979 | + $tmp = $fichier.'.tmp'; |
|
| 980 | 980 | if (strpos($img, '<') === false) { |
| 981 | 981 | $img = supprimer_timestamp($img); |
| 982 | 982 | if (!file_exists($img)) { |
@@ -1033,13 +1033,13 @@ discard block |
||
| 1033 | 1033 | */ |
| 1034 | 1034 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1035 | 1035 | if (is_null($fonction)) { |
| 1036 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1036 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | $ret = false; |
| 1039 | 1039 | #un flag pour reperer les images gravees |
| 1040 | 1040 | $lock = ( |
| 1041 | 1041 | !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
| 1042 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1042 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src')) |
|
| 1043 | 1043 | ); |
| 1044 | 1044 | if ( |
| 1045 | 1045 | function_exists($fonction) |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | // dans tous les cas mettre a jour la taille de l'image finale |
| 1052 | 1052 | [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
| 1053 | 1053 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
| 1054 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1054 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | } |
| 1057 | 1057 | |
@@ -1226,7 +1226,7 @@ discard block |
||
| 1226 | 1226 | |
| 1227 | 1227 | // attributs deprecies. Transformer en CSS |
| 1228 | 1228 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1229 | - $style = "margin:{$espace}px;" . $style; |
|
| 1229 | + $style = "margin:{$espace}px;".$style; |
|
| 1230 | 1230 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1231 | 1231 | } |
| 1232 | 1232 | |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | $image = $valeurs['fichier']; |
| 1354 | 1354 | $format = $valeurs['format_source']; |
| 1355 | 1355 | $destdir = dirname($valeurs['fichier_dest']); |
| 1356 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1356 | + $destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1357 | 1357 | |
| 1358 | 1358 | $format_sortie = $valeurs['format_dest']; |
| 1359 | 1359 | |
@@ -1385,14 +1385,14 @@ discard block |
||
| 1385 | 1385 | |
| 1386 | 1386 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1387 | 1387 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1388 | - $vignette = $destination . '.' . $format; |
|
| 1388 | + $vignette = $destination.'.'.$format; |
|
| 1389 | 1389 | @copy($image, $vignette); |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | elseif ($valeurs['format_source'] === 'svg') { |
| 1393 | 1393 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1394 | 1394 | $format_sortie = 'svg'; |
| 1395 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1395 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1396 | 1396 | $valeurs['fichier_dest'] = $vignette; |
| 1397 | 1397 | _image_gd_output($svg, $valeurs); |
| 1398 | 1398 | } |
@@ -1404,9 +1404,9 @@ discard block |
||
| 1404 | 1404 | define('_CONVERT_COMMAND', 'convert'); |
| 1405 | 1405 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 1406 | 1406 | if (!defined('_RESIZE_COMMAND')) { |
| 1407 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1407 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest'); |
|
| 1408 | 1408 | } |
| 1409 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1409 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1410 | 1410 | $commande = str_replace( |
| 1411 | 1411 | ['%x', '%y', '%src', '%dest'], |
| 1412 | 1412 | [ |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | if (!@file_exists($vignette)) { |
| 1423 | 1423 | spip_log("echec convert sur $vignette"); |
| 1424 | 1424 | |
| 1425 | - return; // echec commande |
|
| 1425 | + return; // echec commande |
|
| 1426 | 1426 | } |
| 1427 | 1427 | } |
| 1428 | 1428 | |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | if (!$output) { |
| 1440 | 1440 | return; |
| 1441 | 1441 | } |
| 1442 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1442 | + $vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie; |
|
| 1443 | 1443 | |
| 1444 | 1444 | $imagick = new Imagick(); |
| 1445 | 1445 | $imagick->readImage(realpath($image)); |
@@ -1448,7 +1448,7 @@ discard block |
||
| 1448 | 1448 | $destHeight, |
| 1449 | 1449 | Imagick::FILTER_LANCZOS, |
| 1450 | 1450 | 1 |
| 1451 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1451 | + ); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1452 | 1452 | $imagick->writeImage($vignette); |
| 1453 | 1453 | |
| 1454 | 1454 | if (!@file_exists($vignette)) { |
@@ -1457,7 +1457,7 @@ discard block |
||
| 1457 | 1457 | return; |
| 1458 | 1458 | } |
| 1459 | 1459 | // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
| 1460 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1460 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | // netpbm |
@@ -1468,11 +1468,11 @@ discard block |
||
| 1468 | 1468 | if (_PNMSCALE_COMMAND == '') { |
| 1469 | 1469 | return; |
| 1470 | 1470 | } |
| 1471 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1471 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1472 | 1472 | $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
| 1473 | 1473 | if ($format == 'jpg') { |
| 1474 | 1474 | $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
| 1475 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1475 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1476 | 1476 | if (!($s = @filesize($vignette))) { |
| 1477 | 1477 | spip_unlink($vignette); |
| 1478 | 1478 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | } else { |
| 1485 | 1485 | if ($format == 'gif') { |
| 1486 | 1486 | $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
| 1487 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1487 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1488 | 1488 | if (!($s = @filesize($vignette))) { |
| 1489 | 1489 | spip_unlink($vignette); |
| 1490 | 1490 | } |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | } else { |
| 1497 | 1497 | if ($format == 'png') { |
| 1498 | 1498 | $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
| 1499 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1499 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1500 | 1500 | if (!($s = @filesize($vignette))) { |
| 1501 | 1501 | spip_unlink($vignette); |
| 1502 | 1502 | } |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | return; |
| 1519 | 1519 | } |
| 1520 | 1520 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1521 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1521 | + spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels'); |
|
| 1522 | 1522 | |
| 1523 | 1523 | return; |
| 1524 | 1524 | } |
@@ -1828,7 +1828,7 @@ discard block |
||
| 1828 | 1828 | // de l'image, de facon a tromper le cache du navigateur |
| 1829 | 1829 | // quand on fait supprimer/reuploader un logo |
| 1830 | 1830 | // (pas de filemtime si SAFE MODE) |
| 1831 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1831 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1832 | 1832 | |
| 1833 | 1833 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1834 | 1834 | } |
@@ -1874,7 +1874,7 @@ discard block |
||
| 1874 | 1874 | public static function LittleEndian2String($number, $minbytes = 1) { |
| 1875 | 1875 | $intstring = ''; |
| 1876 | 1876 | while ($number > 0) { |
| 1877 | - $intstring = $intstring . chr($number & 255); |
|
| 1877 | + $intstring = $intstring.chr($number & 255); |
|
| 1878 | 1878 | $number >>= 8; |
| 1879 | 1879 | } |
| 1880 | 1880 | |
@@ -1906,9 +1906,9 @@ discard block |
||
| 1906 | 1906 | $b = $argb['blue']; |
| 1907 | 1907 | |
| 1908 | 1908 | if ($bpp[$key] == 32) { |
| 1909 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1909 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1910 | 1910 | } elseif ($bpp[$key] == 24) { |
| 1911 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1911 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | if ($a < 128) { |
@@ -1935,48 +1935,48 @@ discard block |
||
| 1935 | 1935 | |
| 1936 | 1936 | // BITMAPINFOHEADER - 40 bytes |
| 1937 | 1937 | $BitmapInfoHeader[$key] = ''; |
| 1938 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1938 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1940 | 1940 | // The biHeight member specifies the combined |
| 1941 | 1941 | // height of the XOR and AND masks. |
| 1942 | 1942 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
| 1943 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1944 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1945 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1946 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1947 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1948 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1949 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1950 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1943 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1944 | + $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount; |
|
| 1945 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1946 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1947 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1948 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1949 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1950 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1951 | 1951 | } |
| 1952 | 1952 | |
| 1953 | 1953 | |
| 1954 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1955 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1956 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1954 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1955 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1956 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1957 | 1957 | |
| 1958 | 1958 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1959 | 1959 | foreach ($gd_image_array as $key => $gd_image) { |
| 1960 | 1960 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1961 | 1961 | |
| 1962 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1963 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1964 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1965 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1962 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1963 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1964 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1965 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1966 | 1966 | |
| 1967 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1967 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1969 | 1969 | |
| 1970 | 1970 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1971 | 1971 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1972 | 1972 | $dwBytesInRes, |
| 1973 | 1973 | 4 |
| 1974 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1974 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1975 | 1975 | |
| 1976 | 1976 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1977 | 1977 | $dwImageOffset, |
| 1978 | 1978 | 4 |
| 1979 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1979 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1980 | 1980 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1981 | 1981 | $dwImageOffset += strlen($icXOR[$key]); |
| 1982 | 1982 | $dwImageOffset += strlen($icAND[$key]); |
@@ -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 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur ??= ''; |
|
| 68 | - $couleur = couleur_html_to_hex($couleur); |
|
| 69 | - $couleur = ltrim($couleur, '#'); |
|
| 70 | - if (strlen($couleur) === 3) { |
|
| 71 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | - } |
|
| 73 | - $retour = []; |
|
| 74 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 75 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 76 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 77 | - |
|
| 78 | - return $retour; |
|
| 67 | + $couleur ??= ''; |
|
| 68 | + $couleur = couleur_html_to_hex($couleur); |
|
| 69 | + $couleur = ltrim($couleur, '#'); |
|
| 70 | + if (strlen($couleur) === 3) { |
|
| 71 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | + } |
|
| 73 | + $retour = []; |
|
| 74 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 75 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 76 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 77 | + |
|
| 78 | + return $retour; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * Le code de la couleur en hexadécimal. |
| 93 | 93 | */ |
| 94 | 94 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 95 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 96 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 95 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 96 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 106 | 106 | */ |
| 107 | 107 | function _couleur_hex_to_hsl($couleur) { |
| 108 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 109 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 108 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 109 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -121,59 +121,59 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 124 | - $H = null; |
|
| 125 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 126 | - $var_G = ($G / 255); |
|
| 127 | - $var_B = ($B / 255); |
|
| 128 | - |
|
| 129 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 130 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 131 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 132 | - |
|
| 133 | - $L = ($var_Max + $var_Min) / 2; |
|
| 134 | - |
|
| 135 | - if ($del_Max == 0) { |
|
| 136 | - //This is a gray, no chroma... |
|
| 137 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 138 | - $S = 0; |
|
| 139 | - } else { |
|
| 140 | - // Chromatic data... |
|
| 141 | - if ($L < 0.5) { |
|
| 142 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 143 | - } else { |
|
| 144 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 150 | - |
|
| 151 | - if ($var_R == $var_Max) { |
|
| 152 | - $H = $del_B - $del_G; |
|
| 153 | - } else { |
|
| 154 | - if ($var_G == $var_Max) { |
|
| 155 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 156 | - } else { |
|
| 157 | - if ($var_B == $var_Max) { |
|
| 158 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($H < 0) { |
|
| 164 | - $H += 1; |
|
| 165 | - } |
|
| 166 | - if ($H > 1) { |
|
| 167 | - $H -= 1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $ret = []; |
|
| 172 | - $ret['h'] = $H; |
|
| 173 | - $ret['s'] = $S; |
|
| 174 | - $ret['l'] = $L; |
|
| 175 | - |
|
| 176 | - return $ret; |
|
| 124 | + $H = null; |
|
| 125 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 126 | + $var_G = ($G / 255); |
|
| 127 | + $var_B = ($B / 255); |
|
| 128 | + |
|
| 129 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 130 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 131 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 132 | + |
|
| 133 | + $L = ($var_Max + $var_Min) / 2; |
|
| 134 | + |
|
| 135 | + if ($del_Max == 0) { |
|
| 136 | + //This is a gray, no chroma... |
|
| 137 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 138 | + $S = 0; |
|
| 139 | + } else { |
|
| 140 | + // Chromatic data... |
|
| 141 | + if ($L < 0.5) { |
|
| 142 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 143 | + } else { |
|
| 144 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 150 | + |
|
| 151 | + if ($var_R == $var_Max) { |
|
| 152 | + $H = $del_B - $del_G; |
|
| 153 | + } else { |
|
| 154 | + if ($var_G == $var_Max) { |
|
| 155 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 156 | + } else { |
|
| 157 | + if ($var_B == $var_Max) { |
|
| 158 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($H < 0) { |
|
| 164 | + $H += 1; |
|
| 165 | + } |
|
| 166 | + if ($H > 1) { |
|
| 167 | + $H -= 1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $ret = []; |
|
| 172 | + $ret['h'] = $H; |
|
| 173 | + $ret['s'] = $S; |
|
| 174 | + $ret['l'] = $L; |
|
| 175 | + |
|
| 176 | + return $ret; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -189,52 +189,52 @@ discard block |
||
| 189 | 189 | * @return array |
| 190 | 190 | */ |
| 191 | 191 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 192 | - // helper |
|
| 193 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 194 | - if ($vH < 0) { |
|
| 195 | - $vH += 1; |
|
| 196 | - } |
|
| 197 | - if ($vH > 1) { |
|
| 198 | - $vH -= 1; |
|
| 199 | - } |
|
| 200 | - if ((6 * $vH) < 1) { |
|
| 201 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 202 | - } |
|
| 203 | - if ((2 * $vH) < 1) { |
|
| 204 | - return ($v2); |
|
| 205 | - } |
|
| 206 | - if ((3 * $vH) < 2) { |
|
| 207 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return ($v1); |
|
| 211 | - }; |
|
| 212 | - |
|
| 213 | - if ($S == 0) { |
|
| 214 | - // HSV values = 0 -> 1 |
|
| 215 | - $R = $L * 255; |
|
| 216 | - $G = $L * 255; |
|
| 217 | - $B = $L * 255; |
|
| 218 | - } else { |
|
| 219 | - if ($L < 0.5) { |
|
| 220 | - $var_2 = $L * (1 + $S); |
|
| 221 | - } else { |
|
| 222 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $var_1 = 2 * $L - $var_2; |
|
| 226 | - |
|
| 227 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 228 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 229 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $ret = []; |
|
| 233 | - $ret['r'] = floor($R); |
|
| 234 | - $ret['g'] = floor($G); |
|
| 235 | - $ret['b'] = floor($B); |
|
| 236 | - |
|
| 237 | - return $ret; |
|
| 192 | + // helper |
|
| 193 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 194 | + if ($vH < 0) { |
|
| 195 | + $vH += 1; |
|
| 196 | + } |
|
| 197 | + if ($vH > 1) { |
|
| 198 | + $vH -= 1; |
|
| 199 | + } |
|
| 200 | + if ((6 * $vH) < 1) { |
|
| 201 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 202 | + } |
|
| 203 | + if ((2 * $vH) < 1) { |
|
| 204 | + return ($v2); |
|
| 205 | + } |
|
| 206 | + if ((3 * $vH) < 2) { |
|
| 207 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return ($v1); |
|
| 211 | + }; |
|
| 212 | + |
|
| 213 | + if ($S == 0) { |
|
| 214 | + // HSV values = 0 -> 1 |
|
| 215 | + $R = $L * 255; |
|
| 216 | + $G = $L * 255; |
|
| 217 | + $B = $L * 255; |
|
| 218 | + } else { |
|
| 219 | + if ($L < 0.5) { |
|
| 220 | + $var_2 = $L * (1 + $S); |
|
| 221 | + } else { |
|
| 222 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $var_1 = 2 * $L - $var_2; |
|
| 226 | + |
|
| 227 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 228 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 229 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $ret = []; |
|
| 233 | + $ret['r'] = floor($R); |
|
| 234 | + $ret['g'] = floor($G); |
|
| 235 | + $ret['b'] = floor($B); |
|
| 236 | + |
|
| 237 | + return $ret; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 253 | 253 | */ |
| 254 | 254 | function statut_effacer_images_temporaires($stat) { |
| 255 | - static $statut = false; // par defaut on grave toute les images |
|
| 256 | - if ($stat === 'get') { |
|
| 257 | - return $statut; |
|
| 258 | - } |
|
| 259 | - $statut = $stat ? true : false; |
|
| 255 | + static $statut = false; // par defaut on grave toute les images |
|
| 256 | + if ($stat === 'get') { |
|
| 257 | + return $statut; |
|
| 258 | + } |
|
| 259 | + $statut = $stat ? true : false; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -309,243 +309,243 @@ discard block |
||
| 309 | 309 | * - array : tableau décrivant de l'image |
| 310 | 310 | */ |
| 311 | 311 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 312 | - $ret = []; |
|
| 313 | - $f = null; |
|
| 314 | - static $images_recalcul = []; |
|
| 315 | - if (strlen($img) == 0) { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 320 | - if (strlen($source) < 1) { |
|
| 321 | - $source = $img; |
|
| 322 | - $img = "<img src='$source' />"; |
|
| 323 | - } elseif ( |
|
| 324 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 325 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 326 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 327 | - ) { |
|
| 328 | - # gerer img src="data:....base64" |
|
| 329 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 330 | - if (!file_exists($local)) { |
|
| 331 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 332 | - } |
|
| 333 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 334 | - $sanitizer($local); |
|
| 335 | - } |
|
| 336 | - $source = $local; |
|
| 337 | - $img = inserer_attribut($img, 'src', $source); |
|
| 338 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 339 | - $img = inserer_attribut($img, 'width', ''); |
|
| 340 | - $img = inserer_attribut($img, 'height', ''); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // les protocoles web prennent au moins 3 lettres |
|
| 344 | - if (tester_url_absolue($source)) { |
|
| 345 | - include_spip('inc/distant'); |
|
| 346 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 347 | - if (!$fichier) { |
|
| 348 | - return ''; |
|
| 349 | - } |
|
| 350 | - if ( |
|
| 351 | - $extension = _image_trouver_extension($fichier) |
|
| 352 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 353 | - ) { |
|
| 354 | - $sanitizer($fichier); |
|
| 355 | - } |
|
| 356 | - } else { |
|
| 357 | - // enlever le timestamp eventuel |
|
| 358 | - if (strpos($source, '?') !== false) { |
|
| 359 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 360 | - } |
|
| 361 | - if ( |
|
| 362 | - strpos($source, '?') !== false |
|
| 363 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 364 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 365 | - ) { |
|
| 366 | - $source = $f; |
|
| 367 | - } |
|
| 368 | - $fichier = $source; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $terminaison_dest = ''; |
|
| 372 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 373 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if ( |
|
| 377 | - $forcer_format !== false |
|
| 378 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 379 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 380 | - ) { |
|
| 381 | - $terminaison_dest = $forcer_format; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if (!$terminaison_dest) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 389 | - $fichier_dest = $nom_fichier; |
|
| 390 | - if ( |
|
| 391 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 392 | - or @file_exists($f = $fichier) |
|
| 393 | - ) { |
|
| 394 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 395 | - // au lieu de faire un acces disque sur le fichier |
|
| 396 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 397 | - $date_src = @filemtime($f); |
|
| 398 | - } elseif ( |
|
| 399 | - @file_exists($f = "$fichier.src") |
|
| 400 | - and lire_fichier($f, $valeurs) |
|
| 401 | - and $valeurs = unserialize($valeurs) |
|
| 402 | - and isset($valeurs['hauteur_dest']) |
|
| 403 | - and isset($valeurs['largeur_dest']) |
|
| 404 | - ) { |
|
| 405 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 406 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 407 | - $date_src = $valeurs['date']; |
|
| 408 | - } // pas de fichier source par la |
|
| 409 | - else { |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // pas de taille mesurable |
|
| 414 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 415 | - return false; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // les images calculees dependent du chemin du fichier source |
|
| 419 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 420 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 421 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 422 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 423 | - // alors que ca concerne peu de site au final |
|
| 424 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 425 | - $identifiant = $fichier; |
|
| 426 | - |
|
| 427 | - // cas general : |
|
| 428 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 429 | - // cas particulier de reduire : |
|
| 430 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 431 | - $cache = 'cache-gd2'; |
|
| 432 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 433 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 434 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 435 | - $ret['largeur_dest'] = $destWidth; |
|
| 436 | - $ret['hauteur_dest'] = $destHeight; |
|
| 437 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 438 | - $cache = 'cache-vignettes'; |
|
| 439 | - $fichier_dest = basename($fichier_dest); |
|
| 440 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 441 | - // on garde la terminaison initiale car image simplement copiee |
|
| 442 | - // et on postfixe son nom avec un md5 du path |
|
| 443 | - $terminaison_dest = $terminaison; |
|
| 444 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 445 | - } else { |
|
| 446 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 447 | - } |
|
| 448 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 449 | - $cache = sous_repertoire($cache, $effet); |
|
| 450 | - } else { |
|
| 451 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 452 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 453 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 454 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 458 | - |
|
| 459 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 460 | - |
|
| 461 | - $creer = true; |
|
| 462 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 463 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 464 | - $images_recalcul[$fichier_dest] = true; |
|
| 465 | - } else { |
|
| 466 | - if (@file_exists($f = $fichier_dest)) { |
|
| 467 | - if (filemtime($f) >= $date_src) { |
|
| 468 | - $creer = false; |
|
| 469 | - } |
|
| 470 | - } else { |
|
| 471 | - if ( |
|
| 472 | - @file_exists($f = "$fichier_dest.src") |
|
| 473 | - and lire_fichier($f, $valeurs) |
|
| 474 | - and $valeurs = unserialize($valeurs) |
|
| 475 | - and $valeurs['date'] >= $date_src |
|
| 476 | - ) { |
|
| 477 | - $creer = false; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - if ($creer) { |
|
| 482 | - if (!@file_exists($fichier)) { |
|
| 483 | - if (!@file_exists("$fichier.src")) { |
|
| 484 | - spip_log("Image absente : $fichier"); |
|
| 485 | - |
|
| 486 | - return false; |
|
| 487 | - } |
|
| 488 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | - reconstruire_image_intermediaire($fichier); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - if ($creer) { |
|
| 494 | - spip_log( |
|
| 495 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 496 | - 'images' . _LOG_DEBUG |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 501 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 502 | - $ret['fichier'] = $fichier; |
|
| 503 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 504 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 505 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 506 | - $ret['format_dest'] = $terminaison_dest; |
|
| 507 | - $ret['date_src'] = $date_src; |
|
| 508 | - $ret['creer'] = $creer; |
|
| 509 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 510 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 511 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 512 | - $ret['tag'] = $img; |
|
| 513 | - if ($fonction_creation) { |
|
| 514 | - $ret['reconstruction'] = $fonction_creation; |
|
| 515 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 516 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 517 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 518 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 522 | - 'args' => [ |
|
| 523 | - 'img' => $img, |
|
| 524 | - 'effet' => $effet, |
|
| 525 | - 'forcer_format' => $forcer_format, |
|
| 526 | - 'fonction_creation' => $fonction_creation, |
|
| 527 | - 'find_in_path' => $find_in_path, |
|
| 528 | - ], |
|
| 529 | - 'data' => $ret |
|
| 530 | - ]); |
|
| 531 | - |
|
| 532 | - // une globale pour le debug en cas de crash memoire |
|
| 533 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 534 | - |
|
| 535 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 536 | - if ($term_fonction === 'svg') { |
|
| 537 | - if ($creer and !$support_svg) { |
|
| 538 | - process_image_svg_identite($ret); |
|
| 539 | - $ret['creer'] = false; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - else { |
|
| 543 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 544 | - return false; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - return $ret; |
|
| 312 | + $ret = []; |
|
| 313 | + $f = null; |
|
| 314 | + static $images_recalcul = []; |
|
| 315 | + if (strlen($img) == 0) { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 320 | + if (strlen($source) < 1) { |
|
| 321 | + $source = $img; |
|
| 322 | + $img = "<img src='$source' />"; |
|
| 323 | + } elseif ( |
|
| 324 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 325 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 326 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 327 | + ) { |
|
| 328 | + # gerer img src="data:....base64" |
|
| 329 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 330 | + if (!file_exists($local)) { |
|
| 331 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 332 | + } |
|
| 333 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 334 | + $sanitizer($local); |
|
| 335 | + } |
|
| 336 | + $source = $local; |
|
| 337 | + $img = inserer_attribut($img, 'src', $source); |
|
| 338 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 339 | + $img = inserer_attribut($img, 'width', ''); |
|
| 340 | + $img = inserer_attribut($img, 'height', ''); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // les protocoles web prennent au moins 3 lettres |
|
| 344 | + if (tester_url_absolue($source)) { |
|
| 345 | + include_spip('inc/distant'); |
|
| 346 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 347 | + if (!$fichier) { |
|
| 348 | + return ''; |
|
| 349 | + } |
|
| 350 | + if ( |
|
| 351 | + $extension = _image_trouver_extension($fichier) |
|
| 352 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 353 | + ) { |
|
| 354 | + $sanitizer($fichier); |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + // enlever le timestamp eventuel |
|
| 358 | + if (strpos($source, '?') !== false) { |
|
| 359 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 360 | + } |
|
| 361 | + if ( |
|
| 362 | + strpos($source, '?') !== false |
|
| 363 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 364 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 365 | + ) { |
|
| 366 | + $source = $f; |
|
| 367 | + } |
|
| 368 | + $fichier = $source; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $terminaison_dest = ''; |
|
| 372 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 373 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if ( |
|
| 377 | + $forcer_format !== false |
|
| 378 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 379 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 380 | + ) { |
|
| 381 | + $terminaison_dest = $forcer_format; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if (!$terminaison_dest) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 389 | + $fichier_dest = $nom_fichier; |
|
| 390 | + if ( |
|
| 391 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 392 | + or @file_exists($f = $fichier) |
|
| 393 | + ) { |
|
| 394 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 395 | + // au lieu de faire un acces disque sur le fichier |
|
| 396 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 397 | + $date_src = @filemtime($f); |
|
| 398 | + } elseif ( |
|
| 399 | + @file_exists($f = "$fichier.src") |
|
| 400 | + and lire_fichier($f, $valeurs) |
|
| 401 | + and $valeurs = unserialize($valeurs) |
|
| 402 | + and isset($valeurs['hauteur_dest']) |
|
| 403 | + and isset($valeurs['largeur_dest']) |
|
| 404 | + ) { |
|
| 405 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 406 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 407 | + $date_src = $valeurs['date']; |
|
| 408 | + } // pas de fichier source par la |
|
| 409 | + else { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // pas de taille mesurable |
|
| 414 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 415 | + return false; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // les images calculees dependent du chemin du fichier source |
|
| 419 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 420 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 421 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 422 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 423 | + // alors que ca concerne peu de site au final |
|
| 424 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 425 | + $identifiant = $fichier; |
|
| 426 | + |
|
| 427 | + // cas general : |
|
| 428 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 429 | + // cas particulier de reduire : |
|
| 430 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 431 | + $cache = 'cache-gd2'; |
|
| 432 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 433 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 434 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 435 | + $ret['largeur_dest'] = $destWidth; |
|
| 436 | + $ret['hauteur_dest'] = $destHeight; |
|
| 437 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 438 | + $cache = 'cache-vignettes'; |
|
| 439 | + $fichier_dest = basename($fichier_dest); |
|
| 440 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 441 | + // on garde la terminaison initiale car image simplement copiee |
|
| 442 | + // et on postfixe son nom avec un md5 du path |
|
| 443 | + $terminaison_dest = $terminaison; |
|
| 444 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 445 | + } else { |
|
| 446 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 447 | + } |
|
| 448 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 449 | + $cache = sous_repertoire($cache, $effet); |
|
| 450 | + } else { |
|
| 451 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 452 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 453 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 454 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 458 | + |
|
| 459 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 460 | + |
|
| 461 | + $creer = true; |
|
| 462 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 463 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 464 | + $images_recalcul[$fichier_dest] = true; |
|
| 465 | + } else { |
|
| 466 | + if (@file_exists($f = $fichier_dest)) { |
|
| 467 | + if (filemtime($f) >= $date_src) { |
|
| 468 | + $creer = false; |
|
| 469 | + } |
|
| 470 | + } else { |
|
| 471 | + if ( |
|
| 472 | + @file_exists($f = "$fichier_dest.src") |
|
| 473 | + and lire_fichier($f, $valeurs) |
|
| 474 | + and $valeurs = unserialize($valeurs) |
|
| 475 | + and $valeurs['date'] >= $date_src |
|
| 476 | + ) { |
|
| 477 | + $creer = false; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + if ($creer) { |
|
| 482 | + if (!@file_exists($fichier)) { |
|
| 483 | + if (!@file_exists("$fichier.src")) { |
|
| 484 | + spip_log("Image absente : $fichier"); |
|
| 485 | + |
|
| 486 | + return false; |
|
| 487 | + } |
|
| 488 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | + reconstruire_image_intermediaire($fichier); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + if ($creer) { |
|
| 494 | + spip_log( |
|
| 495 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 496 | + 'images' . _LOG_DEBUG |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 501 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 502 | + $ret['fichier'] = $fichier; |
|
| 503 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 504 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 505 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 506 | + $ret['format_dest'] = $terminaison_dest; |
|
| 507 | + $ret['date_src'] = $date_src; |
|
| 508 | + $ret['creer'] = $creer; |
|
| 509 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 510 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 511 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 512 | + $ret['tag'] = $img; |
|
| 513 | + if ($fonction_creation) { |
|
| 514 | + $ret['reconstruction'] = $fonction_creation; |
|
| 515 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 516 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 517 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 518 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 522 | + 'args' => [ |
|
| 523 | + 'img' => $img, |
|
| 524 | + 'effet' => $effet, |
|
| 525 | + 'forcer_format' => $forcer_format, |
|
| 526 | + 'fonction_creation' => $fonction_creation, |
|
| 527 | + 'find_in_path' => $find_in_path, |
|
| 528 | + ], |
|
| 529 | + 'data' => $ret |
|
| 530 | + ]); |
|
| 531 | + |
|
| 532 | + // une globale pour le debug en cas de crash memoire |
|
| 533 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 534 | + |
|
| 535 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 536 | + if ($term_fonction === 'svg') { |
|
| 537 | + if ($creer and !$support_svg) { |
|
| 538 | + process_image_svg_identite($ret); |
|
| 539 | + $ret['creer'] = false; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + else { |
|
| 543 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + return $ret; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -554,54 +554,54 @@ discard block |
||
| 554 | 554 | * @return array |
| 555 | 555 | */ |
| 556 | 556 | function _image_extensions_acceptees_en_entree() { |
| 557 | - static $extensions = null; |
|
| 558 | - if (empty($extensions)) { |
|
| 559 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 560 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 561 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 562 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 563 | - $extensions = array_map('trim', $extensions); |
|
| 564 | - $extensions = array_filter($extensions); |
|
| 565 | - if (in_array('jpg', $extensions)) { |
|
| 566 | - $extensions[] = 'jpeg'; |
|
| 567 | - } |
|
| 568 | - $extensions = array_unique($extensions); |
|
| 569 | - } |
|
| 570 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $extensions; |
|
| 557 | + static $extensions = null; |
|
| 558 | + if (empty($extensions)) { |
|
| 559 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 560 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 561 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 562 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 563 | + $extensions = array_map('trim', $extensions); |
|
| 564 | + $extensions = array_filter($extensions); |
|
| 565 | + if (in_array('jpg', $extensions)) { |
|
| 566 | + $extensions[] = 'jpeg'; |
|
| 567 | + } |
|
| 568 | + $extensions = array_unique($extensions); |
|
| 569 | + } |
|
| 570 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $extensions; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
| 577 | 577 | * @return array|string[]|null |
| 578 | 578 | */ |
| 579 | 579 | function _image_extensions_acceptees_en_sortie() { |
| 580 | - static $extensions = null; |
|
| 581 | - if (empty($extensions)) { |
|
| 582 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 583 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 584 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 585 | - $extensions = array_diff($extensions, ['gif']); |
|
| 586 | - } |
|
| 587 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 588 | - $extensions = array_diff($extensions, ['webp']); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - return $extensions; |
|
| 580 | + static $extensions = null; |
|
| 581 | + if (empty($extensions)) { |
|
| 582 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 583 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 584 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 585 | + $extensions = array_diff($extensions, ['gif']); |
|
| 586 | + } |
|
| 587 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 588 | + $extensions = array_diff($extensions, ['webp']); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + return $extensions; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | function _image_extension_normalisee($extension) { |
| 596 | - $extension = strtolower($extension); |
|
| 597 | - if ($extension === 'jpeg') { |
|
| 598 | - $extension = 'jpg'; |
|
| 599 | - } |
|
| 600 | - return $extension; |
|
| 596 | + $extension = strtolower($extension); |
|
| 597 | + if ($extension === 'jpeg') { |
|
| 598 | + $extension = 'jpg'; |
|
| 599 | + } |
|
| 600 | + return $extension; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | function _image_extensions_conservent_transparence() { |
| 604 | - return ['png', 'webp']; |
|
| 604 | + return ['png', 'webp']; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | |
@@ -611,12 +611,12 @@ discard block |
||
| 611 | 611 | * @return string |
| 612 | 612 | */ |
| 613 | 613 | function _image_trouver_extension($path) { |
| 614 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 615 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 616 | - $terminaison = strtolower($regs[1]); |
|
| 617 | - return $terminaison; |
|
| 618 | - } |
|
| 619 | - return ''; |
|
| 614 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 615 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 616 | + $terminaison = strtolower($regs[1]); |
|
| 617 | + return $terminaison; |
|
| 618 | + } |
|
| 619 | + return ''; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -627,33 +627,33 @@ discard block |
||
| 627 | 627 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 628 | 628 | */ |
| 629 | 629 | function _image_trouver_extension_pertinente($path) { |
| 630 | - $path = supprimer_timestamp($path); |
|
| 631 | - $terminaison = _image_trouver_extension($path); |
|
| 632 | - if ($terminaison == 'jpg') { |
|
| 633 | - $terminaison = 'jpeg'; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - if (!file_exists($path)) { |
|
| 637 | - return $terminaison; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - if (!$info = @spip_getimagesize($path)) { |
|
| 641 | - return $terminaison; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if (isset($info['mime'])) { |
|
| 645 | - $mime = $info['mime']; |
|
| 646 | - } |
|
| 647 | - else { |
|
| 648 | - $mime = image_type_to_mime_type($info[2]); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 652 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 653 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 654 | - $terminaison = $_terminaison; |
|
| 655 | - } |
|
| 656 | - return $terminaison; |
|
| 630 | + $path = supprimer_timestamp($path); |
|
| 631 | + $terminaison = _image_trouver_extension($path); |
|
| 632 | + if ($terminaison == 'jpg') { |
|
| 633 | + $terminaison = 'jpeg'; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + if (!file_exists($path)) { |
|
| 637 | + return $terminaison; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + if (!$info = @spip_getimagesize($path)) { |
|
| 641 | + return $terminaison; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if (isset($info['mime'])) { |
|
| 645 | + $mime = $info['mime']; |
|
| 646 | + } |
|
| 647 | + else { |
|
| 648 | + $mime = image_type_to_mime_type($info[2]); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 652 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 653 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 654 | + $terminaison = $_terminaison; |
|
| 655 | + } |
|
| 656 | + return $terminaison; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
@@ -661,36 +661,36 @@ discard block |
||
| 661 | 661 | * @return string |
| 662 | 662 | */ |
| 663 | 663 | function _image_trouver_extension_depuis_mime($mime) { |
| 664 | - switch (strtolower($mime)) { |
|
| 665 | - case 'image/png': |
|
| 666 | - case 'image/x-png': |
|
| 667 | - $terminaison = 'png'; |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'image/jpg': |
|
| 671 | - case 'image/jpeg': |
|
| 672 | - case 'image/pjpeg': |
|
| 673 | - $terminaison = 'jpeg'; |
|
| 674 | - break; |
|
| 675 | - |
|
| 676 | - case 'image/gif': |
|
| 677 | - $terminaison = 'gif'; |
|
| 678 | - break; |
|
| 679 | - |
|
| 680 | - case 'image/webp': |
|
| 681 | - case 'image/x-webp': |
|
| 682 | - $terminaison = 'webp'; |
|
| 683 | - break; |
|
| 684 | - |
|
| 685 | - case 'image/svg+xml': |
|
| 686 | - $terminaison = 'svg'; |
|
| 687 | - break; |
|
| 688 | - |
|
| 689 | - default: |
|
| 690 | - $terminaison = ''; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $terminaison; |
|
| 664 | + switch (strtolower($mime)) { |
|
| 665 | + case 'image/png': |
|
| 666 | + case 'image/x-png': |
|
| 667 | + $terminaison = 'png'; |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'image/jpg': |
|
| 671 | + case 'image/jpeg': |
|
| 672 | + case 'image/pjpeg': |
|
| 673 | + $terminaison = 'jpeg'; |
|
| 674 | + break; |
|
| 675 | + |
|
| 676 | + case 'image/gif': |
|
| 677 | + $terminaison = 'gif'; |
|
| 678 | + break; |
|
| 679 | + |
|
| 680 | + case 'image/webp': |
|
| 681 | + case 'image/x-webp': |
|
| 682 | + $terminaison = 'webp'; |
|
| 683 | + break; |
|
| 684 | + |
|
| 685 | + case 'image/svg+xml': |
|
| 686 | + $terminaison = 'svg'; |
|
| 687 | + break; |
|
| 688 | + |
|
| 689 | + default: |
|
| 690 | + $terminaison = ''; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $terminaison; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | |
@@ -710,18 +710,18 @@ discard block |
||
| 710 | 710 | * Une ressource de type Image GD. |
| 711 | 711 | */ |
| 712 | 712 | function _imagecreatefrom_func(string $func, string $filename) { |
| 713 | - if (!function_exists($func)) { |
|
| 714 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 715 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 716 | - return null; |
|
| 717 | - } |
|
| 718 | - $img = @$func($filename); |
|
| 719 | - if (!$img) { |
|
| 720 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 721 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 722 | - $img = imagecreate(10, 10); |
|
| 723 | - } |
|
| 724 | - return $img; |
|
| 713 | + if (!function_exists($func)) { |
|
| 714 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 715 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 716 | + return null; |
|
| 717 | + } |
|
| 718 | + $img = @$func($filename); |
|
| 719 | + if (!$img) { |
|
| 720 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 721 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 722 | + $img = imagecreate(10, 10); |
|
| 723 | + } |
|
| 724 | + return $img; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * Une ressource de type Image GD. |
| 738 | 738 | */ |
| 739 | 739 | function _imagecreatefromjpeg($filename) { |
| 740 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 740 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * Une ressource de type Image GD. |
| 754 | 754 | */ |
| 755 | 755 | function _imagecreatefrompng($filename) { |
| 756 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 756 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | * Une ressource de type Image GD. |
| 770 | 770 | */ |
| 771 | 771 | function _imagecreatefromgif($filename) { |
| 772 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 772 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | * Une ressource de type Image GD. |
| 787 | 787 | */ |
| 788 | 788 | function _imagecreatefromwebp($filename) { |
| 789 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 789 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -804,24 +804,24 @@ discard block |
||
| 804 | 804 | * - true si une image est bien retournée. |
| 805 | 805 | */ |
| 806 | 806 | function _image_imagepng($img, $fichier) { |
| 807 | - if (!function_exists('imagepng')) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $tmp = $fichier . '.tmp'; |
|
| 811 | - $ret = imagepng($img, $tmp); |
|
| 812 | - if (file_exists($tmp)) { |
|
| 813 | - $taille_test = getimagesize($tmp); |
|
| 814 | - if ($taille_test[0] < 1) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 819 | - @rename($tmp, $fichier); |
|
| 820 | - |
|
| 821 | - return $ret; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - return false; |
|
| 807 | + if (!function_exists('imagepng')) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $tmp = $fichier . '.tmp'; |
|
| 811 | + $ret = imagepng($img, $tmp); |
|
| 812 | + if (file_exists($tmp)) { |
|
| 813 | + $taille_test = getimagesize($tmp); |
|
| 814 | + if ($taille_test[0] < 1) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 819 | + @rename($tmp, $fichier); |
|
| 820 | + |
|
| 821 | + return $ret; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + return false; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
@@ -839,24 +839,24 @@ discard block |
||
| 839 | 839 | * - true si une image est bien retournée. |
| 840 | 840 | */ |
| 841 | 841 | function _image_imagegif($img, $fichier) { |
| 842 | - if (!function_exists('imagegif')) { |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - $tmp = $fichier . '.tmp'; |
|
| 846 | - $ret = imagegif($img, $tmp); |
|
| 847 | - if (file_exists($tmp)) { |
|
| 848 | - $taille_test = getimagesize($tmp); |
|
| 849 | - if ($taille_test[0] < 1) { |
|
| 850 | - return false; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 854 | - @rename($tmp, $fichier); |
|
| 855 | - |
|
| 856 | - return $ret; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - return false; |
|
| 842 | + if (!function_exists('imagegif')) { |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + $tmp = $fichier . '.tmp'; |
|
| 846 | + $ret = imagegif($img, $tmp); |
|
| 847 | + if (file_exists($tmp)) { |
|
| 848 | + $taille_test = getimagesize($tmp); |
|
| 849 | + if ($taille_test[0] < 1) { |
|
| 850 | + return false; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 854 | + @rename($tmp, $fichier); |
|
| 855 | + |
|
| 856 | + return $ret; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + return false; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -879,29 +879,29 @@ discard block |
||
| 879 | 879 | * - true si une image est bien retournée. |
| 880 | 880 | */ |
| 881 | 881 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 882 | - if (!function_exists('imagejpeg')) { |
|
| 883 | - return false; |
|
| 884 | - } |
|
| 885 | - $tmp = $fichier . '.tmp'; |
|
| 882 | + if (!function_exists('imagejpeg')) { |
|
| 883 | + return false; |
|
| 884 | + } |
|
| 885 | + $tmp = $fichier . '.tmp'; |
|
| 886 | 886 | |
| 887 | - // Enable interlancing |
|
| 888 | - imageinterlace($img, true); |
|
| 887 | + // Enable interlancing |
|
| 888 | + imageinterlace($img, true); |
|
| 889 | 889 | |
| 890 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 890 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 891 | 891 | |
| 892 | - if (file_exists($tmp)) { |
|
| 893 | - $taille_test = getimagesize($tmp); |
|
| 894 | - if ($taille_test[0] < 1) { |
|
| 895 | - return false; |
|
| 896 | - } |
|
| 892 | + if (file_exists($tmp)) { |
|
| 893 | + $taille_test = getimagesize($tmp); |
|
| 894 | + if ($taille_test[0] < 1) { |
|
| 895 | + return false; |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 899 | - @rename($tmp, $fichier); |
|
| 898 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 899 | + @rename($tmp, $fichier); |
|
| 900 | 900 | |
| 901 | - return $ret; |
|
| 902 | - } |
|
| 901 | + return $ret; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - return false; |
|
| 904 | + return false; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -919,9 +919,9 @@ discard block |
||
| 919 | 919 | * true si le fichier a bien été créé ; false sinon. |
| 920 | 920 | */ |
| 921 | 921 | function _image_imageico($img, $fichier) { |
| 922 | - $gd_image_array = [$img]; |
|
| 922 | + $gd_image_array = [$img]; |
|
| 923 | 923 | |
| 924 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 924 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | |
@@ -940,24 +940,24 @@ discard block |
||
| 940 | 940 | * - true si une image est bien retournée. |
| 941 | 941 | */ |
| 942 | 942 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 943 | - if (!function_exists('imagewebp')) { |
|
| 944 | - return false; |
|
| 945 | - } |
|
| 946 | - $tmp = $fichier . '.tmp'; |
|
| 947 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 948 | - if (file_exists($tmp)) { |
|
| 949 | - $taille_test = getimagesize($tmp); |
|
| 950 | - if ($taille_test[0] < 1) { |
|
| 951 | - return false; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 955 | - @rename($tmp, $fichier); |
|
| 956 | - |
|
| 957 | - return $ret; |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - return false; |
|
| 943 | + if (!function_exists('imagewebp')) { |
|
| 944 | + return false; |
|
| 945 | + } |
|
| 946 | + $tmp = $fichier . '.tmp'; |
|
| 947 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 948 | + if (file_exists($tmp)) { |
|
| 949 | + $taille_test = getimagesize($tmp); |
|
| 950 | + if ($taille_test[0] < 1) { |
|
| 951 | + return false; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 955 | + @rename($tmp, $fichier); |
|
| 956 | + |
|
| 957 | + return $ret; |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + return false; |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
@@ -977,35 +977,35 @@ discard block |
||
| 977 | 977 | */ |
| 978 | 978 | function _image_imagesvg($img, $fichier) { |
| 979 | 979 | |
| 980 | - $tmp = $fichier . '.tmp'; |
|
| 981 | - if (strpos($img, '<') === false) { |
|
| 982 | - $img = supprimer_timestamp($img); |
|
| 983 | - if (!file_exists($img)) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - @copy($img, $tmp); |
|
| 987 | - if (filesize($tmp) == filesize($img)) { |
|
| 988 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 989 | - @rename($tmp, $fichier); |
|
| 990 | - return true; |
|
| 991 | - } |
|
| 992 | - return false; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - file_put_contents($tmp, $img); |
|
| 996 | - if (file_exists($tmp)) { |
|
| 997 | - $taille_test = spip_getimagesize($tmp); |
|
| 998 | - if ($taille_test[0] < 1) { |
|
| 999 | - return false; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1003 | - @rename($tmp, $fichier); |
|
| 1004 | - |
|
| 1005 | - return true; |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - return false; |
|
| 980 | + $tmp = $fichier . '.tmp'; |
|
| 981 | + if (strpos($img, '<') === false) { |
|
| 982 | + $img = supprimer_timestamp($img); |
|
| 983 | + if (!file_exists($img)) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + @copy($img, $tmp); |
|
| 987 | + if (filesize($tmp) == filesize($img)) { |
|
| 988 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 989 | + @rename($tmp, $fichier); |
|
| 990 | + return true; |
|
| 991 | + } |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + file_put_contents($tmp, $img); |
|
| 996 | + if (file_exists($tmp)) { |
|
| 997 | + $taille_test = spip_getimagesize($tmp); |
|
| 998 | + if ($taille_test[0] < 1) { |
|
| 999 | + return false; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1003 | + @rename($tmp, $fichier); |
|
| 1004 | + |
|
| 1005 | + return true; |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + return false; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | |
@@ -1033,30 +1033,30 @@ discard block |
||
| 1033 | 1033 | * - false sinon. |
| 1034 | 1034 | */ |
| 1035 | 1035 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1036 | - if (is_null($fonction)) { |
|
| 1037 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1038 | - } |
|
| 1039 | - $ret = false; |
|
| 1040 | - #un flag pour reperer les images gravees |
|
| 1041 | - $lock = ( |
|
| 1042 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1043 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1044 | - ); |
|
| 1045 | - if ( |
|
| 1046 | - function_exists($fonction) |
|
| 1047 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1048 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1049 | - && !$lock |
|
| 1050 | - ) { |
|
| 1051 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1052 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1053 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1054 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1055 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - return $ret; |
|
| 1036 | + if (is_null($fonction)) { |
|
| 1037 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1038 | + } |
|
| 1039 | + $ret = false; |
|
| 1040 | + #un flag pour reperer les images gravees |
|
| 1041 | + $lock = ( |
|
| 1042 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1043 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1044 | + ); |
|
| 1045 | + if ( |
|
| 1046 | + function_exists($fonction) |
|
| 1047 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1048 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1049 | + && !$lock |
|
| 1050 | + ) { |
|
| 1051 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1052 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1053 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1054 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1055 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + return $ret; |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1069,27 +1069,27 @@ discard block |
||
| 1069 | 1069 | * Chemin vers le fichier manquant |
| 1070 | 1070 | **/ |
| 1071 | 1071 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1072 | - $reconstruire = []; |
|
| 1073 | - $fichier = $fichier_manquant; |
|
| 1074 | - while ( |
|
| 1075 | - strpos($fichier, '://') === false |
|
| 1076 | - and !@file_exists($fichier) |
|
| 1077 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1078 | - and $valeurs = unserialize($source) |
|
| 1079 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1080 | - ) { |
|
| 1081 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1082 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1083 | - } |
|
| 1084 | - while (count($reconstruire)) { |
|
| 1085 | - $r = array_pop($reconstruire); |
|
| 1086 | - $fonction = $r[0]; |
|
| 1087 | - $args = $r[1]; |
|
| 1088 | - $fonction(...$args); |
|
| 1089 | - } |
|
| 1090 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1091 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1092 | - ramasse_miettes($fichier_manquant); |
|
| 1072 | + $reconstruire = []; |
|
| 1073 | + $fichier = $fichier_manquant; |
|
| 1074 | + while ( |
|
| 1075 | + strpos($fichier, '://') === false |
|
| 1076 | + and !@file_exists($fichier) |
|
| 1077 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1078 | + and $valeurs = unserialize($source) |
|
| 1079 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1080 | + ) { |
|
| 1081 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1082 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1083 | + } |
|
| 1084 | + while (count($reconstruire)) { |
|
| 1085 | + $r = array_pop($reconstruire); |
|
| 1086 | + $fonction = $r[0]; |
|
| 1087 | + $args = $r[1]; |
|
| 1088 | + $fonction(...$args); |
|
| 1089 | + } |
|
| 1090 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1091 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1092 | + ramasse_miettes($fichier_manquant); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1109,28 +1109,28 @@ discard block |
||
| 1109 | 1109 | * Chemin du fichier d'image calculé |
| 1110 | 1110 | **/ |
| 1111 | 1111 | function ramasse_miettes($fichier) { |
| 1112 | - if ( |
|
| 1113 | - strpos($fichier, '://') !== false |
|
| 1114 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1115 | - or !$valeurs = unserialize($source) |
|
| 1116 | - ) { |
|
| 1117 | - return; |
|
| 1118 | - } |
|
| 1119 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1120 | - while ( |
|
| 1121 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1122 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1123 | - and (lire_fichier( |
|
| 1124 | - $src = "$fichier.src", |
|
| 1125 | - $source |
|
| 1126 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1127 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1128 | - ) { |
|
| 1129 | - # on efface le fichier |
|
| 1130 | - spip_unlink($fichier); |
|
| 1131 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1132 | - #spip_unlink($src); |
|
| 1133 | - } |
|
| 1112 | + if ( |
|
| 1113 | + strpos($fichier, '://') !== false |
|
| 1114 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1115 | + or !$valeurs = unserialize($source) |
|
| 1116 | + ) { |
|
| 1117 | + return; |
|
| 1118 | + } |
|
| 1119 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1120 | + while ( |
|
| 1121 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1122 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1123 | + and (lire_fichier( |
|
| 1124 | + $src = "$fichier.src", |
|
| 1125 | + $source |
|
| 1126 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1127 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1128 | + ) { |
|
| 1129 | + # on efface le fichier |
|
| 1130 | + spip_unlink($fichier); |
|
| 1131 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1132 | + #spip_unlink($src); |
|
| 1133 | + } |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | |
@@ -1155,31 +1155,31 @@ discard block |
||
| 1155 | 1155 | * Code HTML de l'image |
| 1156 | 1156 | **/ |
| 1157 | 1157 | function image_graver($img) { |
| 1158 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1159 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1160 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1161 | - |
|
| 1162 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1163 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1164 | - $fichier = substr($fichier, 0, $p); |
|
| 1165 | - } |
|
| 1166 | - if (strlen($fichier) < 1) { |
|
| 1167 | - $fichier = $img; |
|
| 1168 | - } |
|
| 1169 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1170 | - # et qu'il ne s'agit pas d'une URL |
|
| 1171 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1172 | - reconstruire_image_intermediaire($fichier); |
|
| 1173 | - } |
|
| 1174 | - ramasse_miettes($fichier); |
|
| 1175 | - |
|
| 1176 | - // ajouter le timestamp si besoin |
|
| 1177 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1178 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1179 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return $img; |
|
| 1158 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1159 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1160 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1161 | + |
|
| 1162 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1163 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1164 | + $fichier = substr($fichier, 0, $p); |
|
| 1165 | + } |
|
| 1166 | + if (strlen($fichier) < 1) { |
|
| 1167 | + $fichier = $img; |
|
| 1168 | + } |
|
| 1169 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1170 | + # et qu'il ne s'agit pas d'une URL |
|
| 1171 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1172 | + reconstruire_image_intermediaire($fichier); |
|
| 1173 | + } |
|
| 1174 | + ramasse_miettes($fichier); |
|
| 1175 | + |
|
| 1176 | + // ajouter le timestamp si besoin |
|
| 1177 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1178 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1179 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return $img; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1206,34 +1206,34 @@ discard block |
||
| 1206 | 1206 | * Code html modifié de la balise. |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1209 | - if ($style === false) { |
|
| 1210 | - $style = extraire_attribut($tag, 'style'); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - // enlever le width et height du style |
|
| 1214 | - if ($style) { |
|
| 1215 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1216 | - } |
|
| 1217 | - if ($style and $style[0] === ';') { |
|
| 1218 | - $style = substr($style, 1); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - // mettre des attributs de width et height sur les images, |
|
| 1222 | - // ca accelere le rendu du navigateur |
|
| 1223 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1224 | - // quand on a desactive l'affichage des images. |
|
| 1225 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1226 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1227 | - |
|
| 1228 | - // attributs deprecies. Transformer en CSS |
|
| 1229 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1230 | - $style = "margin:{$espace}px;" . $style; |
|
| 1231 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1235 | - |
|
| 1236 | - return $tag; |
|
| 1209 | + if ($style === false) { |
|
| 1210 | + $style = extraire_attribut($tag, 'style'); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + // enlever le width et height du style |
|
| 1214 | + if ($style) { |
|
| 1215 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1216 | + } |
|
| 1217 | + if ($style and $style[0] === ';') { |
|
| 1218 | + $style = substr($style, 1); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + // mettre des attributs de width et height sur les images, |
|
| 1222 | + // ca accelere le rendu du navigateur |
|
| 1223 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1224 | + // quand on a desactive l'affichage des images. |
|
| 1225 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1226 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1227 | + |
|
| 1228 | + // attributs deprecies. Transformer en CSS |
|
| 1229 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1230 | + $style = "margin:{$espace}px;" . $style; |
|
| 1231 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1235 | + |
|
| 1236 | + return $tag; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | |
@@ -1259,72 +1259,72 @@ discard block |
||
| 1259 | 1259 | * Retourne le code HTML de l'image |
| 1260 | 1260 | **/ |
| 1261 | 1261 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1262 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1263 | - |
|
| 1264 | - // fermer les tags img pas bien fermes; |
|
| 1265 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1266 | - |
|
| 1267 | - // le style |
|
| 1268 | - $style = $valeurs['style']; |
|
| 1269 | - if (isset($surcharge['style'])) { |
|
| 1270 | - $style = $surcharge['style']; |
|
| 1271 | - unset($surcharge['style']); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - // traiter specifiquement la largeur et la hauteur |
|
| 1275 | - $width = $valeurs['largeur']; |
|
| 1276 | - if (isset($surcharge['width'])) { |
|
| 1277 | - $width = $surcharge['width']; |
|
| 1278 | - unset($surcharge['width']); |
|
| 1279 | - } |
|
| 1280 | - $height = $valeurs['hauteur']; |
|
| 1281 | - if (isset($surcharge['height'])) { |
|
| 1282 | - $height = $surcharge['height']; |
|
| 1283 | - unset($surcharge['height']); |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1287 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1288 | - // on remplace toute les ref a src dans le tag |
|
| 1289 | - $src = extraire_attribut($tag, 'src'); |
|
| 1290 | - if (isset($surcharge['src'])) { |
|
| 1291 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1292 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1293 | - // pas garanti comme methode, mais mieux que rien |
|
| 1294 | - if (strpos($src, '&') !== false) { |
|
| 1295 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1296 | - } |
|
| 1297 | - $src = $surcharge['src']; |
|
| 1298 | - unset($surcharge['src']); |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - $class = $valeurs['class']; |
|
| 1302 | - if (isset($surcharge['class'])) { |
|
| 1303 | - $class = $surcharge['class']; |
|
| 1304 | - unset($surcharge['class']); |
|
| 1305 | - } |
|
| 1306 | - if (is_scalar($class) && strlen($class)) { |
|
| 1307 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - if (count($surcharge)) { |
|
| 1311 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1312 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1313 | - } |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - $tag = pipeline( |
|
| 1317 | - 'image_ecrire_tag_finir', |
|
| 1318 | - [ |
|
| 1319 | - 'args' => [ |
|
| 1320 | - 'valeurs' => $valeurs, |
|
| 1321 | - 'surcharge' => $surcharge, |
|
| 1322 | - ], |
|
| 1323 | - 'data' => $tag |
|
| 1324 | - ] |
|
| 1325 | - ); |
|
| 1326 | - |
|
| 1327 | - return $tag; |
|
| 1262 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1263 | + |
|
| 1264 | + // fermer les tags img pas bien fermes; |
|
| 1265 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1266 | + |
|
| 1267 | + // le style |
|
| 1268 | + $style = $valeurs['style']; |
|
| 1269 | + if (isset($surcharge['style'])) { |
|
| 1270 | + $style = $surcharge['style']; |
|
| 1271 | + unset($surcharge['style']); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + // traiter specifiquement la largeur et la hauteur |
|
| 1275 | + $width = $valeurs['largeur']; |
|
| 1276 | + if (isset($surcharge['width'])) { |
|
| 1277 | + $width = $surcharge['width']; |
|
| 1278 | + unset($surcharge['width']); |
|
| 1279 | + } |
|
| 1280 | + $height = $valeurs['hauteur']; |
|
| 1281 | + if (isset($surcharge['height'])) { |
|
| 1282 | + $height = $surcharge['height']; |
|
| 1283 | + unset($surcharge['height']); |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1287 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1288 | + // on remplace toute les ref a src dans le tag |
|
| 1289 | + $src = extraire_attribut($tag, 'src'); |
|
| 1290 | + if (isset($surcharge['src'])) { |
|
| 1291 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1292 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1293 | + // pas garanti comme methode, mais mieux que rien |
|
| 1294 | + if (strpos($src, '&') !== false) { |
|
| 1295 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1296 | + } |
|
| 1297 | + $src = $surcharge['src']; |
|
| 1298 | + unset($surcharge['src']); |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + $class = $valeurs['class']; |
|
| 1302 | + if (isset($surcharge['class'])) { |
|
| 1303 | + $class = $surcharge['class']; |
|
| 1304 | + unset($surcharge['class']); |
|
| 1305 | + } |
|
| 1306 | + if (is_scalar($class) && strlen($class)) { |
|
| 1307 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + if (count($surcharge)) { |
|
| 1311 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1312 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1313 | + } |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + $tag = pipeline( |
|
| 1317 | + 'image_ecrire_tag_finir', |
|
| 1318 | + [ |
|
| 1319 | + 'args' => [ |
|
| 1320 | + 'valeurs' => $valeurs, |
|
| 1321 | + 'surcharge' => $surcharge, |
|
| 1322 | + ], |
|
| 1323 | + 'data' => $tag |
|
| 1324 | + ] |
|
| 1325 | + ); |
|
| 1326 | + |
|
| 1327 | + return $tag; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
@@ -1347,267 +1347,267 @@ discard block |
||
| 1347 | 1347 | * Description de l'image, sinon null. |
| 1348 | 1348 | **/ |
| 1349 | 1349 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1350 | - $srcHeight = null; |
|
| 1351 | - $retour = []; |
|
| 1352 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1353 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1354 | - $image = $valeurs['fichier']; |
|
| 1355 | - $format = $valeurs['format_source']; |
|
| 1356 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1357 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1358 | - |
|
| 1359 | - $format_sortie = $valeurs['format_dest']; |
|
| 1360 | - |
|
| 1361 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1362 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1366 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1367 | - return; |
|
| 1368 | - } |
|
| 1369 | - $destination = "$destdir/$destfile"; |
|
| 1370 | - |
|
| 1371 | - // calculer la taille |
|
| 1372 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1373 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1374 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1375 | - } |
|
| 1376 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1377 | - $destWidth = $maxWidth; |
|
| 1378 | - $destHeight = $maxHeight; |
|
| 1379 | - } else { |
|
| 1380 | - spip_log("echec $process sur $image"); |
|
| 1381 | - |
|
| 1382 | - return; |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - $vignette = ''; |
|
| 1386 | - |
|
| 1387 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1388 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1389 | - $vignette = $destination . '.' . $format; |
|
| 1390 | - @copy($image, $vignette); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1394 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1395 | - $format_sortie = 'svg'; |
|
| 1396 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1397 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1398 | - _image_gd_output($svg, $valeurs); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - // imagemagick en ligne de commande |
|
| 1403 | - elseif ($process == 'convert') { |
|
| 1404 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1405 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1406 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1407 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1408 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1409 | - } |
|
| 1410 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1411 | - $commande = str_replace( |
|
| 1412 | - ['%x', '%y', '%src', '%dest'], |
|
| 1413 | - [ |
|
| 1414 | - $destWidth, |
|
| 1415 | - $destHeight, |
|
| 1416 | - escapeshellcmd($image), |
|
| 1417 | - escapeshellcmd($vignette) |
|
| 1418 | - ], |
|
| 1419 | - _RESIZE_COMMAND |
|
| 1420 | - ); |
|
| 1421 | - spip_log($commande); |
|
| 1422 | - exec($commande); |
|
| 1423 | - if (!@file_exists($vignette)) { |
|
| 1424 | - spip_log("echec convert sur $vignette"); |
|
| 1425 | - |
|
| 1426 | - return; // echec commande |
|
| 1427 | - } |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - // php5 imagemagick |
|
| 1431 | - elseif ($process == 'imagick') { |
|
| 1432 | - if (!class_exists(\Imagick::class)) { |
|
| 1433 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1434 | - |
|
| 1435 | - return; |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - // chemin compatible Windows |
|
| 1439 | - $output = realpath(dirname($destination)); |
|
| 1440 | - if (!$output) { |
|
| 1441 | - return; |
|
| 1442 | - } |
|
| 1443 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1444 | - |
|
| 1445 | - $imagick = new Imagick(); |
|
| 1446 | - $imagick->readImage(realpath($image)); |
|
| 1447 | - $imagick->resizeImage( |
|
| 1448 | - $destWidth, |
|
| 1449 | - $destHeight, |
|
| 1450 | - Imagick::FILTER_LANCZOS, |
|
| 1451 | - 1 |
|
| 1452 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1453 | - $imagick->writeImage($vignette); |
|
| 1454 | - |
|
| 1455 | - if (!@file_exists($vignette)) { |
|
| 1456 | - spip_log("echec imagick sur $vignette"); |
|
| 1457 | - |
|
| 1458 | - return; |
|
| 1459 | - } |
|
| 1460 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1461 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - // netpbm |
|
| 1465 | - elseif ($process == 'netpbm') { |
|
| 1466 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1467 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1468 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1469 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1470 | - return; |
|
| 1471 | - } |
|
| 1472 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1473 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1474 | - if ($format == 'jpg') { |
|
| 1475 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1476 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1477 | - if (!($s = @filesize($vignette))) { |
|
| 1478 | - spip_unlink($vignette); |
|
| 1479 | - } |
|
| 1480 | - if (!@file_exists($vignette)) { |
|
| 1481 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1482 | - |
|
| 1483 | - return; |
|
| 1484 | - } |
|
| 1485 | - } else { |
|
| 1486 | - if ($format == 'gif') { |
|
| 1487 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1488 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1489 | - if (!($s = @filesize($vignette))) { |
|
| 1490 | - spip_unlink($vignette); |
|
| 1491 | - } |
|
| 1492 | - if (!@file_exists($vignette)) { |
|
| 1493 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1494 | - |
|
| 1495 | - return; |
|
| 1496 | - } |
|
| 1497 | - } else { |
|
| 1498 | - if ($format == 'png') { |
|
| 1499 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1500 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1501 | - if (!($s = @filesize($vignette))) { |
|
| 1502 | - spip_unlink($vignette); |
|
| 1503 | - } |
|
| 1504 | - if (!@file_exists($vignette)) { |
|
| 1505 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1506 | - |
|
| 1507 | - return; |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - // gd ou gd2 |
|
| 1515 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1516 | - if (!function_exists('gd_info')) { |
|
| 1517 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1518 | - |
|
| 1519 | - return; |
|
| 1520 | - } |
|
| 1521 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1522 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1523 | - |
|
| 1524 | - return; |
|
| 1525 | - } |
|
| 1526 | - $destFormat = $format_sortie; |
|
| 1527 | - if (!$destFormat) { |
|
| 1528 | - spip_log("pas de format pour $image"); |
|
| 1529 | - |
|
| 1530 | - return; |
|
| 1531 | - } |
|
| 1532 | - |
|
| 1533 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1534 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1535 | - return; |
|
| 1536 | - } |
|
| 1537 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1538 | - if (!$srcImage) { |
|
| 1539 | - spip_log('echec gd1/gd2'); |
|
| 1540 | - |
|
| 1541 | - return; |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - // Initialisation de l'image destination |
|
| 1545 | - $destImage = null; |
|
| 1546 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1547 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1548 | - } |
|
| 1549 | - if (!$destImage) { |
|
| 1550 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1554 | - $ok = false; |
|
| 1555 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1556 | - if ($format == 'gif') { |
|
| 1557 | - // Si un GIF est transparent, |
|
| 1558 | - // fabriquer un PNG transparent |
|
| 1559 | - $transp = imagecolortransparent($srcImage); |
|
| 1560 | - if ($transp > 0) { |
|
| 1561 | - $destFormat = 'png'; |
|
| 1562 | - } |
|
| 1563 | - } |
|
| 1564 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1565 | - // Conserver la transparence |
|
| 1566 | - if (function_exists('imageAntiAlias')) { |
|
| 1567 | - imageAntiAlias($destImage, true); |
|
| 1568 | - } |
|
| 1569 | - @imagealphablending($destImage, false); |
|
| 1570 | - @imagesavealpha($destImage, true); |
|
| 1571 | - } |
|
| 1572 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1573 | - } |
|
| 1574 | - if (!$ok) { |
|
| 1575 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - // Sauvegarde de l'image destination |
|
| 1579 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1580 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1581 | - _image_gd_output($destImage, $valeurs); |
|
| 1582 | - |
|
| 1583 | - if ($srcImage) { |
|
| 1584 | - ImageDestroy($srcImage); |
|
| 1585 | - } |
|
| 1586 | - ImageDestroy($destImage); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1590 | - $size = [$destWidth, $destHeight]; |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1594 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1595 | - if ($size[0] < 1) { |
|
| 1596 | - $size[0] = $destWidth; |
|
| 1597 | - } |
|
| 1598 | - if ($size[1] < 1) { |
|
| 1599 | - $size[1] = $destHeight; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - $retour['width'] = $largeur = $size[0]; |
|
| 1603 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1604 | - |
|
| 1605 | - $retour['fichier'] = $vignette; |
|
| 1606 | - $retour['format'] = $format; |
|
| 1607 | - $retour['date'] = @filemtime($vignette); |
|
| 1608 | - |
|
| 1609 | - // renvoyer l'image |
|
| 1610 | - return $retour; |
|
| 1350 | + $srcHeight = null; |
|
| 1351 | + $retour = []; |
|
| 1352 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1353 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1354 | + $image = $valeurs['fichier']; |
|
| 1355 | + $format = $valeurs['format_source']; |
|
| 1356 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1357 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1358 | + |
|
| 1359 | + $format_sortie = $valeurs['format_dest']; |
|
| 1360 | + |
|
| 1361 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1362 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1366 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1367 | + return; |
|
| 1368 | + } |
|
| 1369 | + $destination = "$destdir/$destfile"; |
|
| 1370 | + |
|
| 1371 | + // calculer la taille |
|
| 1372 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1373 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1374 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1375 | + } |
|
| 1376 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1377 | + $destWidth = $maxWidth; |
|
| 1378 | + $destHeight = $maxHeight; |
|
| 1379 | + } else { |
|
| 1380 | + spip_log("echec $process sur $image"); |
|
| 1381 | + |
|
| 1382 | + return; |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + $vignette = ''; |
|
| 1386 | + |
|
| 1387 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1388 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1389 | + $vignette = $destination . '.' . $format; |
|
| 1390 | + @copy($image, $vignette); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1394 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1395 | + $format_sortie = 'svg'; |
|
| 1396 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1397 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1398 | + _image_gd_output($svg, $valeurs); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + // imagemagick en ligne de commande |
|
| 1403 | + elseif ($process == 'convert') { |
|
| 1404 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1405 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1406 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1407 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1408 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1409 | + } |
|
| 1410 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1411 | + $commande = str_replace( |
|
| 1412 | + ['%x', '%y', '%src', '%dest'], |
|
| 1413 | + [ |
|
| 1414 | + $destWidth, |
|
| 1415 | + $destHeight, |
|
| 1416 | + escapeshellcmd($image), |
|
| 1417 | + escapeshellcmd($vignette) |
|
| 1418 | + ], |
|
| 1419 | + _RESIZE_COMMAND |
|
| 1420 | + ); |
|
| 1421 | + spip_log($commande); |
|
| 1422 | + exec($commande); |
|
| 1423 | + if (!@file_exists($vignette)) { |
|
| 1424 | + spip_log("echec convert sur $vignette"); |
|
| 1425 | + |
|
| 1426 | + return; // echec commande |
|
| 1427 | + } |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + // php5 imagemagick |
|
| 1431 | + elseif ($process == 'imagick') { |
|
| 1432 | + if (!class_exists(\Imagick::class)) { |
|
| 1433 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1434 | + |
|
| 1435 | + return; |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + // chemin compatible Windows |
|
| 1439 | + $output = realpath(dirname($destination)); |
|
| 1440 | + if (!$output) { |
|
| 1441 | + return; |
|
| 1442 | + } |
|
| 1443 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1444 | + |
|
| 1445 | + $imagick = new Imagick(); |
|
| 1446 | + $imagick->readImage(realpath($image)); |
|
| 1447 | + $imagick->resizeImage( |
|
| 1448 | + $destWidth, |
|
| 1449 | + $destHeight, |
|
| 1450 | + Imagick::FILTER_LANCZOS, |
|
| 1451 | + 1 |
|
| 1452 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1453 | + $imagick->writeImage($vignette); |
|
| 1454 | + |
|
| 1455 | + if (!@file_exists($vignette)) { |
|
| 1456 | + spip_log("echec imagick sur $vignette"); |
|
| 1457 | + |
|
| 1458 | + return; |
|
| 1459 | + } |
|
| 1460 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1461 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + // netpbm |
|
| 1465 | + elseif ($process == 'netpbm') { |
|
| 1466 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1467 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1468 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1469 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1470 | + return; |
|
| 1471 | + } |
|
| 1472 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1473 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1474 | + if ($format == 'jpg') { |
|
| 1475 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1476 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1477 | + if (!($s = @filesize($vignette))) { |
|
| 1478 | + spip_unlink($vignette); |
|
| 1479 | + } |
|
| 1480 | + if (!@file_exists($vignette)) { |
|
| 1481 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1482 | + |
|
| 1483 | + return; |
|
| 1484 | + } |
|
| 1485 | + } else { |
|
| 1486 | + if ($format == 'gif') { |
|
| 1487 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1488 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1489 | + if (!($s = @filesize($vignette))) { |
|
| 1490 | + spip_unlink($vignette); |
|
| 1491 | + } |
|
| 1492 | + if (!@file_exists($vignette)) { |
|
| 1493 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1494 | + |
|
| 1495 | + return; |
|
| 1496 | + } |
|
| 1497 | + } else { |
|
| 1498 | + if ($format == 'png') { |
|
| 1499 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1500 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1501 | + if (!($s = @filesize($vignette))) { |
|
| 1502 | + spip_unlink($vignette); |
|
| 1503 | + } |
|
| 1504 | + if (!@file_exists($vignette)) { |
|
| 1505 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1506 | + |
|
| 1507 | + return; |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + // gd ou gd2 |
|
| 1515 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1516 | + if (!function_exists('gd_info')) { |
|
| 1517 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1518 | + |
|
| 1519 | + return; |
|
| 1520 | + } |
|
| 1521 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1522 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1523 | + |
|
| 1524 | + return; |
|
| 1525 | + } |
|
| 1526 | + $destFormat = $format_sortie; |
|
| 1527 | + if (!$destFormat) { |
|
| 1528 | + spip_log("pas de format pour $image"); |
|
| 1529 | + |
|
| 1530 | + return; |
|
| 1531 | + } |
|
| 1532 | + |
|
| 1533 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1534 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1535 | + return; |
|
| 1536 | + } |
|
| 1537 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1538 | + if (!$srcImage) { |
|
| 1539 | + spip_log('echec gd1/gd2'); |
|
| 1540 | + |
|
| 1541 | + return; |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + // Initialisation de l'image destination |
|
| 1545 | + $destImage = null; |
|
| 1546 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1547 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1548 | + } |
|
| 1549 | + if (!$destImage) { |
|
| 1550 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1554 | + $ok = false; |
|
| 1555 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1556 | + if ($format == 'gif') { |
|
| 1557 | + // Si un GIF est transparent, |
|
| 1558 | + // fabriquer un PNG transparent |
|
| 1559 | + $transp = imagecolortransparent($srcImage); |
|
| 1560 | + if ($transp > 0) { |
|
| 1561 | + $destFormat = 'png'; |
|
| 1562 | + } |
|
| 1563 | + } |
|
| 1564 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1565 | + // Conserver la transparence |
|
| 1566 | + if (function_exists('imageAntiAlias')) { |
|
| 1567 | + imageAntiAlias($destImage, true); |
|
| 1568 | + } |
|
| 1569 | + @imagealphablending($destImage, false); |
|
| 1570 | + @imagesavealpha($destImage, true); |
|
| 1571 | + } |
|
| 1572 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1573 | + } |
|
| 1574 | + if (!$ok) { |
|
| 1575 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1576 | + } |
|
| 1577 | + |
|
| 1578 | + // Sauvegarde de l'image destination |
|
| 1579 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1580 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1581 | + _image_gd_output($destImage, $valeurs); |
|
| 1582 | + |
|
| 1583 | + if ($srcImage) { |
|
| 1584 | + ImageDestroy($srcImage); |
|
| 1585 | + } |
|
| 1586 | + ImageDestroy($destImage); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1590 | + $size = [$destWidth, $destHeight]; |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1594 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1595 | + if ($size[0] < 1) { |
|
| 1596 | + $size[0] = $destWidth; |
|
| 1597 | + } |
|
| 1598 | + if ($size[1] < 1) { |
|
| 1599 | + $size[1] = $destHeight; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + $retour['width'] = $largeur = $size[0]; |
|
| 1603 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1604 | + |
|
| 1605 | + $retour['fichier'] = $vignette; |
|
| 1606 | + $retour['format'] = $format; |
|
| 1607 | + $retour['date'] = @filemtime($vignette); |
|
| 1608 | + |
|
| 1609 | + // renvoyer l'image |
|
| 1610 | + return $retour; |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | /** |
@@ -1627,25 +1627,25 @@ discard block |
||
| 1627 | 1627 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1628 | 1628 | **/ |
| 1629 | 1629 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1630 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1631 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1632 | - |
|
| 1633 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1634 | - $destWidth = $srcWidth; |
|
| 1635 | - $destHeight = $srcHeight; |
|
| 1636 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1637 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1638 | - $destHeight = $maxHeight; |
|
| 1639 | - } else { |
|
| 1640 | - $destWidth = $maxWidth; |
|
| 1641 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - return [ |
|
| 1645 | - intval(round($destWidth)), |
|
| 1646 | - intval(round($destHeight)), |
|
| 1647 | - max($ratioWidth, $ratioHeight) |
|
| 1648 | - ]; |
|
| 1630 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1631 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1632 | + |
|
| 1633 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1634 | + $destWidth = $srcWidth; |
|
| 1635 | + $destHeight = $srcHeight; |
|
| 1636 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1637 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1638 | + $destHeight = $maxHeight; |
|
| 1639 | + } else { |
|
| 1640 | + $destWidth = $maxWidth; |
|
| 1641 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + return [ |
|
| 1645 | + intval(round($destWidth)), |
|
| 1646 | + intval(round($destHeight)), |
|
| 1647 | + max($ratioWidth, $ratioHeight) |
|
| 1648 | + ]; |
|
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | /** |
@@ -1665,25 +1665,25 @@ discard block |
||
| 1665 | 1665 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1666 | 1666 | **/ |
| 1667 | 1667 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1668 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1669 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1670 | - |
|
| 1671 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1672 | - $destWidth = $srcWidth; |
|
| 1673 | - $destHeight = $srcHeight; |
|
| 1674 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1675 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1676 | - $destHeight = $maxHeight; |
|
| 1677 | - } else { |
|
| 1678 | - $destWidth = $maxWidth; |
|
| 1679 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - return [ |
|
| 1683 | - intval(round($destWidth)), |
|
| 1684 | - intval(round($destHeight)), |
|
| 1685 | - min($ratioWidth, $ratioHeight) |
|
| 1686 | - ]; |
|
| 1668 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1669 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1670 | + |
|
| 1671 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1672 | + $destWidth = $srcWidth; |
|
| 1673 | + $destHeight = $srcHeight; |
|
| 1674 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1675 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1676 | + $destHeight = $maxHeight; |
|
| 1677 | + } else { |
|
| 1678 | + $destWidth = $maxWidth; |
|
| 1679 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + return [ |
|
| 1683 | + intval(round($destWidth)), |
|
| 1684 | + intval(round($destHeight)), |
|
| 1685 | + min($ratioWidth, $ratioHeight) |
|
| 1686 | + ]; |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | |
@@ -1696,12 +1696,12 @@ discard block |
||
| 1696 | 1696 | * @return string |
| 1697 | 1697 | */ |
| 1698 | 1698 | function process_image_svg_identite($image) { |
| 1699 | - if ($image['creer']) { |
|
| 1700 | - $source = $image['fichier']; |
|
| 1701 | - _image_gd_output($source, $image); |
|
| 1702 | - } |
|
| 1699 | + if ($image['creer']) { |
|
| 1700 | + $source = $image['fichier']; |
|
| 1701 | + _image_gd_output($source, $image); |
|
| 1702 | + } |
|
| 1703 | 1703 | |
| 1704 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1704 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | |
@@ -1734,109 +1734,109 @@ discard block |
||
| 1734 | 1734 | * Code HTML de la balise img produite |
| 1735 | 1735 | **/ |
| 1736 | 1736 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1737 | - $image = false; |
|
| 1738 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1739 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1740 | - } |
|
| 1741 | - # determiner le format de sortie |
|
| 1742 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1743 | - if ($process == 'netpbm') { |
|
| 1744 | - $format_sortie = 'jpg'; |
|
| 1745 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1746 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1747 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1748 | - $gd_formats = formats_image_acceptables(true); |
|
| 1749 | - if ( |
|
| 1750 | - is_array($image) |
|
| 1751 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1752 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1753 | - ) |
|
| 1754 | - ) { |
|
| 1755 | - if ($image['format_source'] == 'jpg') { |
|
| 1756 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1757 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1758 | - { |
|
| 1759 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1760 | - } |
|
| 1761 | - // Choisir le format destination |
|
| 1762 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1763 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1764 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1765 | - # pas *ecrire* |
|
| 1766 | - $format_sortie = ''; |
|
| 1767 | - foreach ($formats_sortie as $fmt) { |
|
| 1768 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1769 | - $format_sortie = $fmt; |
|
| 1770 | - break; |
|
| 1771 | - } |
|
| 1772 | - } |
|
| 1773 | - $image = false; |
|
| 1774 | - } |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - if (!is_array($image)) { |
|
| 1778 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1779 | - } |
|
| 1780 | - |
|
| 1781 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1782 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1783 | - // on peut resizer en mode html si on dispose des elements |
|
| 1784 | - [$srcw, $srch] = taille_image($img); |
|
| 1785 | - if ($srcw and $srch) { |
|
| 1786 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1787 | - |
|
| 1788 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1789 | - } |
|
| 1790 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1791 | - // sous la forme style='max-width: NNpx;' |
|
| 1792 | - return inserer_attribut( |
|
| 1793 | - $img, |
|
| 1794 | - 'style', |
|
| 1795 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1796 | - ); |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1800 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1801 | - if ($image['creer']) { |
|
| 1802 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - if ($image['creer'] == false && !$force) { |
|
| 1809 | - return _image_ecrire_tag( |
|
| 1810 | - $image, |
|
| 1811 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1812 | - ); |
|
| 1813 | - } |
|
| 1814 | - |
|
| 1815 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1816 | - $destWidth = $image['largeur_dest']; |
|
| 1817 | - $destHeight = $image['hauteur_dest']; |
|
| 1818 | - $logo = $image['fichier']; |
|
| 1819 | - $date = $image['date_src']; |
|
| 1820 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1821 | - |
|
| 1822 | - if ($preview && $preview['fichier']) { |
|
| 1823 | - $logo = $preview['fichier']; |
|
| 1824 | - $destWidth = $preview['width']; |
|
| 1825 | - $destHeight = $preview['height']; |
|
| 1826 | - $date = $preview['date']; |
|
| 1827 | - } |
|
| 1828 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1829 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1830 | - // quand on fait supprimer/reuploader un logo |
|
| 1831 | - // (pas de filemtime si SAFE MODE) |
|
| 1832 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1833 | - |
|
| 1834 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1835 | - } |
|
| 1836 | - else { |
|
| 1837 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1838 | - return $img; |
|
| 1839 | - } |
|
| 1737 | + $image = false; |
|
| 1738 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1739 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1740 | + } |
|
| 1741 | + # determiner le format de sortie |
|
| 1742 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1743 | + if ($process == 'netpbm') { |
|
| 1744 | + $format_sortie = 'jpg'; |
|
| 1745 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1746 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1747 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1748 | + $gd_formats = formats_image_acceptables(true); |
|
| 1749 | + if ( |
|
| 1750 | + is_array($image) |
|
| 1751 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1752 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1753 | + ) |
|
| 1754 | + ) { |
|
| 1755 | + if ($image['format_source'] == 'jpg') { |
|
| 1756 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1757 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1758 | + { |
|
| 1759 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1760 | + } |
|
| 1761 | + // Choisir le format destination |
|
| 1762 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1763 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1764 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1765 | + # pas *ecrire* |
|
| 1766 | + $format_sortie = ''; |
|
| 1767 | + foreach ($formats_sortie as $fmt) { |
|
| 1768 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1769 | + $format_sortie = $fmt; |
|
| 1770 | + break; |
|
| 1771 | + } |
|
| 1772 | + } |
|
| 1773 | + $image = false; |
|
| 1774 | + } |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + if (!is_array($image)) { |
|
| 1778 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1779 | + } |
|
| 1780 | + |
|
| 1781 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1782 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1783 | + // on peut resizer en mode html si on dispose des elements |
|
| 1784 | + [$srcw, $srch] = taille_image($img); |
|
| 1785 | + if ($srcw and $srch) { |
|
| 1786 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1787 | + |
|
| 1788 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1789 | + } |
|
| 1790 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1791 | + // sous la forme style='max-width: NNpx;' |
|
| 1792 | + return inserer_attribut( |
|
| 1793 | + $img, |
|
| 1794 | + 'style', |
|
| 1795 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1796 | + ); |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1800 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1801 | + if ($image['creer']) { |
|
| 1802 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + if ($image['creer'] == false && !$force) { |
|
| 1809 | + return _image_ecrire_tag( |
|
| 1810 | + $image, |
|
| 1811 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1812 | + ); |
|
| 1813 | + } |
|
| 1814 | + |
|
| 1815 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1816 | + $destWidth = $image['largeur_dest']; |
|
| 1817 | + $destHeight = $image['hauteur_dest']; |
|
| 1818 | + $logo = $image['fichier']; |
|
| 1819 | + $date = $image['date_src']; |
|
| 1820 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1821 | + |
|
| 1822 | + if ($preview && $preview['fichier']) { |
|
| 1823 | + $logo = $preview['fichier']; |
|
| 1824 | + $destWidth = $preview['width']; |
|
| 1825 | + $destHeight = $preview['height']; |
|
| 1826 | + $date = $preview['date']; |
|
| 1827 | + } |
|
| 1828 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1829 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1830 | + // quand on fait supprimer/reuploader un logo |
|
| 1831 | + // (pas de filemtime si SAFE MODE) |
|
| 1832 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1833 | + |
|
| 1834 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1835 | + } |
|
| 1836 | + else { |
|
| 1837 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1838 | + return $img; |
|
| 1839 | + } |
|
| 1840 | 1840 | } |
| 1841 | 1841 | |
| 1842 | 1842 | /** |
@@ -1850,145 +1850,145 @@ discard block |
||
| 1850 | 1850 | * Class phpthumb_functions |
| 1851 | 1851 | */ |
| 1852 | 1852 | class phpthumb_functions { |
| 1853 | - /** |
|
| 1854 | - * Retourne la couleur d'un pixel dans une image |
|
| 1855 | - * |
|
| 1856 | - * @param resource|GdImage $img |
|
| 1857 | - * @param int $x |
|
| 1858 | - * @param int $y |
|
| 1859 | - * @return array|bool |
|
| 1860 | - */ |
|
| 1861 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1862 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1863 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1864 | - } |
|
| 1865 | - return false; |
|
| 1866 | - } |
|
| 1867 | - |
|
| 1868 | - /** |
|
| 1869 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1870 | - * |
|
| 1871 | - * @param int $number |
|
| 1872 | - * @param int $minbytes |
|
| 1873 | - * @return string |
|
| 1874 | - */ |
|
| 1875 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1876 | - $intstring = ''; |
|
| 1877 | - while ($number > 0) { |
|
| 1878 | - $intstring = $intstring . chr($number & 255); |
|
| 1879 | - $number >>= 8; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - /** |
|
| 1886 | - * Transforme une ressource GD en image au format ICO |
|
| 1887 | - * |
|
| 1888 | - * @param array $gd_image_array |
|
| 1889 | - * Tableau de ressources d'images GD |
|
| 1890 | - * @return string |
|
| 1891 | - * Image au format ICO |
|
| 1892 | - */ |
|
| 1893 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1894 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1895 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1896 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1897 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1898 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1899 | - |
|
| 1900 | - $icXOR[$key] = ''; |
|
| 1901 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1902 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1903 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1904 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1905 | - $r = $argb['red']; |
|
| 1906 | - $g = $argb['green']; |
|
| 1907 | - $b = $argb['blue']; |
|
| 1908 | - |
|
| 1909 | - if ($bpp[$key] == 32) { |
|
| 1910 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1911 | - } elseif ($bpp[$key] == 24) { |
|
| 1912 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - if ($a < 128) { |
|
| 1916 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1917 | - } else { |
|
| 1918 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1919 | - } |
|
| 1920 | - } |
|
| 1921 | - // mask bits are 32-bit aligned per scanline |
|
| 1922 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1923 | - $icANDmask[$key][$y] .= '0'; |
|
| 1924 | - } |
|
| 1925 | - } |
|
| 1926 | - $icAND[$key] = ''; |
|
| 1927 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1928 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1929 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1930 | - } |
|
| 1931 | - } |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1935 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1936 | - |
|
| 1937 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1938 | - $BitmapInfoHeader[$key] = ''; |
|
| 1939 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1940 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1941 | - // The biHeight member specifies the combined |
|
| 1942 | - // height of the XOR and AND masks. |
|
| 1943 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1944 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1945 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1946 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1947 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1948 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1949 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1950 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1951 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1956 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1957 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1958 | - |
|
| 1959 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1960 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1961 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1962 | - |
|
| 1963 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1964 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1965 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1966 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1967 | - |
|
| 1968 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1969 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1970 | - |
|
| 1971 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1972 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1973 | - $dwBytesInRes, |
|
| 1974 | - 4 |
|
| 1975 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1976 | - |
|
| 1977 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1978 | - $dwImageOffset, |
|
| 1979 | - 4 |
|
| 1980 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1981 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1982 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1983 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1987 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1988 | - $icondata .= $icXOR[$key]; |
|
| 1989 | - $icondata .= $icAND[$key]; |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - return $icondata; |
|
| 1993 | - } |
|
| 1853 | + /** |
|
| 1854 | + * Retourne la couleur d'un pixel dans une image |
|
| 1855 | + * |
|
| 1856 | + * @param resource|GdImage $img |
|
| 1857 | + * @param int $x |
|
| 1858 | + * @param int $y |
|
| 1859 | + * @return array|bool |
|
| 1860 | + */ |
|
| 1861 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1862 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1863 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1864 | + } |
|
| 1865 | + return false; |
|
| 1866 | + } |
|
| 1867 | + |
|
| 1868 | + /** |
|
| 1869 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1870 | + * |
|
| 1871 | + * @param int $number |
|
| 1872 | + * @param int $minbytes |
|
| 1873 | + * @return string |
|
| 1874 | + */ |
|
| 1875 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1876 | + $intstring = ''; |
|
| 1877 | + while ($number > 0) { |
|
| 1878 | + $intstring = $intstring . chr($number & 255); |
|
| 1879 | + $number >>= 8; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + /** |
|
| 1886 | + * Transforme une ressource GD en image au format ICO |
|
| 1887 | + * |
|
| 1888 | + * @param array $gd_image_array |
|
| 1889 | + * Tableau de ressources d'images GD |
|
| 1890 | + * @return string |
|
| 1891 | + * Image au format ICO |
|
| 1892 | + */ |
|
| 1893 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1894 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1895 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1896 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1897 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1898 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1899 | + |
|
| 1900 | + $icXOR[$key] = ''; |
|
| 1901 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1902 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1903 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1904 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1905 | + $r = $argb['red']; |
|
| 1906 | + $g = $argb['green']; |
|
| 1907 | + $b = $argb['blue']; |
|
| 1908 | + |
|
| 1909 | + if ($bpp[$key] == 32) { |
|
| 1910 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1911 | + } elseif ($bpp[$key] == 24) { |
|
| 1912 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + if ($a < 128) { |
|
| 1916 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1917 | + } else { |
|
| 1918 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1919 | + } |
|
| 1920 | + } |
|
| 1921 | + // mask bits are 32-bit aligned per scanline |
|
| 1922 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1923 | + $icANDmask[$key][$y] .= '0'; |
|
| 1924 | + } |
|
| 1925 | + } |
|
| 1926 | + $icAND[$key] = ''; |
|
| 1927 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1928 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1929 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1930 | + } |
|
| 1931 | + } |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1935 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1936 | + |
|
| 1937 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1938 | + $BitmapInfoHeader[$key] = ''; |
|
| 1939 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1940 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1941 | + // The biHeight member specifies the combined |
|
| 1942 | + // height of the XOR and AND masks. |
|
| 1943 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1944 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1945 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1946 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1947 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1948 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1949 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1950 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1951 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1956 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1957 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1958 | + |
|
| 1959 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1960 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1961 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1962 | + |
|
| 1963 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1964 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1965 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1966 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1967 | + |
|
| 1968 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1969 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1970 | + |
|
| 1971 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1972 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1973 | + $dwBytesInRes, |
|
| 1974 | + 4 |
|
| 1975 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1976 | + |
|
| 1977 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1978 | + $dwImageOffset, |
|
| 1979 | + 4 |
|
| 1980 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1981 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1982 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1983 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1984 | + } |
|
| 1985 | + |
|
| 1986 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1987 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1988 | + $icondata .= $icXOR[$key]; |
|
| 1989 | + $icondata .= $icAND[$key]; |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + return $icondata; |
|
| 1993 | + } |
|
| 1994 | 1994 | } |