@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -37,70 +37,70 @@ discard block |
||
| 37 | 37 | * @return array|string |
| 38 | 38 | */ |
| 39 | 39 | function inc_couleurs_dist($choix = null, $ajouter = false) { |
| 40 | - static $couleurs_spip = [ |
|
| 41 | - // Violet soutenu |
|
| 42 | - 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | - // Violet rosé |
|
| 44 | - 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | - // Rose interface SPIP |
|
| 46 | - 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | - // Rouge |
|
| 48 | - 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | - // Orange |
|
| 50 | - 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | - // Vert SPIP |
|
| 52 | - 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | - // Vert Troglo |
|
| 54 | - 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | - // Bleu-vert |
|
| 56 | - 12 => ['couleur_theme' => '#269681'], |
|
| 57 | - // Bleu pastel |
|
| 58 | - 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | - // Bleu Kermesse |
|
| 60 | - 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | - // Gris bleuté |
|
| 62 | - 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | - // Gris |
|
| 64 | - 10 => ['couleur_theme' => '#909090'], |
|
| 65 | - ]; |
|
| 40 | + static $couleurs_spip = [ |
|
| 41 | + // Violet soutenu |
|
| 42 | + 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | + // Violet rosé |
|
| 44 | + 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | + // Rose interface SPIP |
|
| 46 | + 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | + // Rouge |
|
| 48 | + 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | + // Orange |
|
| 50 | + 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | + // Vert SPIP |
|
| 52 | + 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | + // Vert Troglo |
|
| 54 | + 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | + // Bleu-vert |
|
| 56 | + 12 => ['couleur_theme' => '#269681'], |
|
| 57 | + // Bleu pastel |
|
| 58 | + 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | + // Bleu Kermesse |
|
| 60 | + 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | + // Gris bleuté |
|
| 62 | + 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | + // Gris |
|
| 64 | + 10 => ['couleur_theme' => '#909090'], |
|
| 65 | + ]; |
|
| 66 | 66 | |
| 67 | - if (is_numeric($choix)) { |
|
| 68 | - $c = $couleurs_spip[$choix]; |
|
| 69 | - // compat < SPIP 3.3 |
|
| 70 | - include_spip('inc/filtres_images_mini'); |
|
| 71 | - $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 67 | + if (is_numeric($choix)) { |
|
| 68 | + $c = $couleurs_spip[$choix]; |
|
| 69 | + // compat < SPIP 3.3 |
|
| 70 | + include_spip('inc/filtres_images_mini'); |
|
| 71 | + $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | + $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | 73 | |
| 74 | - return |
|
| 75 | - 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | - // compat < SPIP 3.3 |
|
| 77 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | - . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | - } else { |
|
| 80 | - if (is_array($choix)) { |
|
| 81 | - // compat < SPIP 3.3 |
|
| 82 | - $compat_spip_33 = function ($c) { |
|
| 83 | - if (!isset($c['couleur_theme'])) { |
|
| 84 | - $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | - unset($c['couleur_foncee']); |
|
| 86 | - unset($c['couleur_claire']); |
|
| 87 | - unset($c['couleur_lien']); |
|
| 88 | - unset($c['couleur_lien_off']); |
|
| 89 | - } |
|
| 90 | - return $c; |
|
| 91 | - }; |
|
| 92 | - if ($ajouter) { |
|
| 93 | - foreach ($choix as $c) { |
|
| 94 | - $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | - } |
|
| 74 | + return |
|
| 75 | + 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | + // compat < SPIP 3.3 |
|
| 77 | + . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | + . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | + } else { |
|
| 80 | + if (is_array($choix)) { |
|
| 81 | + // compat < SPIP 3.3 |
|
| 82 | + $compat_spip_33 = function ($c) { |
|
| 83 | + if (!isset($c['couleur_theme'])) { |
|
| 84 | + $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | + unset($c['couleur_foncee']); |
|
| 86 | + unset($c['couleur_claire']); |
|
| 87 | + unset($c['couleur_lien']); |
|
| 88 | + unset($c['couleur_lien_off']); |
|
| 89 | + } |
|
| 90 | + return $c; |
|
| 91 | + }; |
|
| 92 | + if ($ajouter) { |
|
| 93 | + foreach ($choix as $c) { |
|
| 94 | + $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $couleurs_spip; |
|
| 98 | - } else { |
|
| 99 | - $choix = array_map($compat_spip_33, $choix); |
|
| 100 | - return $couleurs_spip = $choix; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 97 | + return $couleurs_spip; |
|
| 98 | + } else { |
|
| 99 | + $choix = array_map($compat_spip_33, $choix); |
|
| 100 | + return $couleurs_spip = $choix; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $couleurs_spip; |
|
| 105 | + return $couleurs_spip; |
|
| 106 | 106 | } |
@@ -69,17 +69,17 @@ |
||
| 69 | 69 | // compat < SPIP 3.3 |
| 70 | 70 | include_spip('inc/filtres_images_mini'); |
| 71 | 71 | $c['couleur_foncee'] = $c['couleur_theme']; |
| 72 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 72 | + $c['couleur_claire'] = '#'.couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | 73 | |
| 74 | 74 | return |
| 75 | - 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 75 | + 'couleur_theme='.substr((string) $c['couleur_theme'], 1) |
|
| 76 | 76 | // compat < SPIP 3.3 |
| 77 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | - . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 77 | + . '&couleur_claire='.substr($c['couleur_claire'], 1) |
|
| 78 | + . '&couleur_foncee='.substr((string) $c['couleur_foncee'], 1); |
|
| 79 | 79 | } else { |
| 80 | 80 | if (is_array($choix)) { |
| 81 | 81 | // compat < SPIP 3.3 |
| 82 | - $compat_spip_33 = function ($c) { |
|
| 82 | + $compat_spip_33 = function($c) { |
|
| 83 | 83 | if (!isset($c['couleur_theme'])) { |
| 84 | 84 | $c['couleur_theme'] = $c['couleur_foncee']; |
| 85 | 85 | unset($c['couleur_foncee']); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | * @return void |
| 43 | 43 | **/ |
| 44 | 44 | function install_fichier_connexion($nom, $texte) { |
| 45 | - $texte = '<' . "?php\n" |
|
| 46 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 47 | - . $texte; |
|
| 45 | + $texte = '<' . "?php\n" |
|
| 46 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 47 | + . $texte; |
|
| 48 | 48 | |
| 49 | - ecrire_fichier($nom, $texte); |
|
| 49 | + ecrire_fichier($nom, $texte); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | **/ |
| 77 | 77 | function install_connexion($adr, $port, $login, #[\SensitiveParameter] $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 78 | - $adr = addcslashes($adr, "'\\"); |
|
| 79 | - $port = addcslashes($port, "'\\"); |
|
| 80 | - $login = addcslashes($login, "'\\"); |
|
| 81 | - $pass = addcslashes($pass, "'\\"); |
|
| 82 | - $base = addcslashes($base, "'\\"); |
|
| 83 | - $type = addcslashes($type, "'\\"); |
|
| 84 | - $pref = addcslashes($pref, "'\\"); |
|
| 85 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 86 | - $charset = addcslashes($charset, "'\\"); |
|
| 87 | - |
|
| 88 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 89 | - . 'spip_connect_db(' |
|
| 90 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 91 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 78 | + $adr = addcslashes($adr, "'\\"); |
|
| 79 | + $port = addcslashes($port, "'\\"); |
|
| 80 | + $login = addcslashes($login, "'\\"); |
|
| 81 | + $pass = addcslashes($pass, "'\\"); |
|
| 82 | + $base = addcslashes($base, "'\\"); |
|
| 83 | + $type = addcslashes($type, "'\\"); |
|
| 84 | + $pref = addcslashes($pref, "'\\"); |
|
| 85 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 86 | + $charset = addcslashes($charset, "'\\"); |
|
| 87 | + |
|
| 88 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 89 | + . 'spip_connect_db(' |
|
| 90 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 91 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -104,29 +104,29 @@ discard block |
||
| 104 | 104 | * Tableau des informations sur la connexion |
| 105 | 105 | **/ |
| 106 | 106 | function analyse_fichier_connection(string $file): array { |
| 107 | - if (!file_exists($file)) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - $s = file_get_contents($file); |
|
| 111 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 112 | - array_shift($regs); |
|
| 113 | - |
|
| 114 | - return $regs; |
|
| 115 | - } else { |
|
| 116 | - $ar = '\s*\'([^\']*)\''; |
|
| 117 | - $r = '\s*,' . $ar; |
|
| 118 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 119 | - if (preg_match($r, $s, $regs)) { |
|
| 120 | - $regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : ''); |
|
| 121 | - array_shift($regs); |
|
| 122 | - array_shift($regs); |
|
| 123 | - |
|
| 124 | - return $regs; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 128 | - |
|
| 129 | - return []; |
|
| 107 | + if (!file_exists($file)) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + $s = file_get_contents($file); |
|
| 111 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 112 | + array_shift($regs); |
|
| 113 | + |
|
| 114 | + return $regs; |
|
| 115 | + } else { |
|
| 116 | + $ar = '\s*\'([^\']*)\''; |
|
| 117 | + $r = '\s*,' . $ar; |
|
| 118 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 119 | + if (preg_match($r, $s, $regs)) { |
|
| 120 | + $regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : ''); |
|
| 121 | + array_shift($regs); |
|
| 122 | + array_shift($regs); |
|
| 123 | + |
|
| 124 | + return $regs; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 128 | + |
|
| 129 | + return []; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -143,80 +143,80 @@ discard block |
||
| 143 | 143 | * Liste des noms de connecteurs |
| 144 | 144 | **/ |
| 145 | 145 | function bases_referencees($exclu = '') { |
| 146 | - $tables = []; |
|
| 147 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 148 | - if ($f != $exclu && analyse_fichier_connection($f)) { |
|
| 149 | - $tables[] = basename((string) $f, '.php'); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $tables; |
|
| 146 | + $tables = []; |
|
| 147 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 148 | + if ($f != $exclu && analyse_fichier_connection($f)) { |
|
| 149 | + $tables[] = basename((string) $f, '.php'); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $tables; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
| 157 | 157 | function install_mode_appel($server_db, $tout = true) { |
| 158 | - return ($server_db != 'mysql') ? '' |
|
| 159 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 160 | - . test_sql_mode_mysql($server_db)); |
|
| 158 | + return ($server_db != 'mysql') ? '' |
|
| 159 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 160 | + . test_sql_mode_mysql($server_db)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // |
| 164 | 164 | // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-) |
| 165 | 165 | // (sert a l'etape 1 de l'installation) |
| 166 | 166 | function tester_compatibilite_hebergement() { |
| 167 | - $err = []; |
|
| 168 | - |
|
| 169 | - $p = phpversion(); |
|
| 170 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | - } |
|
| 173 | - if (version_compare($p, _PHP_MAX, '>')) { |
|
| 174 | - $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 178 | - if ($diff !== []) { |
|
| 179 | - $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 183 | - if ($err) { |
|
| 184 | - die("<div class='error'>" |
|
| 185 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 186 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Il faut une base de donnees tout de meme ... |
|
| 190 | - $serveurs = install_select_serveur(); |
|
| 191 | - if (!$serveurs) { |
|
| 192 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 194 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 198 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 199 | - $err[] = _T('install_extension_mbstring') |
|
| 200 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if ($err) { |
|
| 204 | - echo "<div class='error'>" |
|
| 205 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 206 | - foreach ($err as $e) { |
|
| 207 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 211 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 212 | - echo "</ul></div>\n"; |
|
| 213 | - } |
|
| 167 | + $err = []; |
|
| 168 | + |
|
| 169 | + $p = phpversion(); |
|
| 170 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | + } |
|
| 173 | + if (version_compare($p, _PHP_MAX, '>')) { |
|
| 174 | + $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 178 | + if ($diff !== []) { |
|
| 179 | + $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 183 | + if ($err) { |
|
| 184 | + die("<div class='error'>" |
|
| 185 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 186 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Il faut une base de donnees tout de meme ... |
|
| 190 | + $serveurs = install_select_serveur(); |
|
| 191 | + if (!$serveurs) { |
|
| 192 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 194 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 198 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 199 | + $err[] = _T('install_extension_mbstring') |
|
| 200 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if ($err) { |
|
| 204 | + echo "<div class='error'>" |
|
| 205 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 206 | + foreach ($err as $e) { |
|
| 207 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 211 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 212 | + echo "</ul></div>\n"; |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
| 217 | 217 | function info_etape($titre, $complement = '') { |
| 218 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 219 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 218 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 219 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -226,143 +226,143 @@ discard block |
||
| 226 | 226 | * @return string Code HTML du bouton |
| 227 | 227 | **/ |
| 228 | 228 | function bouton_suivant($code = '') { |
| 229 | - if ($code == '') { |
|
| 230 | - $code = _T('bouton_suivant'); |
|
| 231 | - } |
|
| 232 | - static $suivant = 0; |
|
| 233 | - $id = 'suivant' . (($suivant > 0) ? (string) $suivant : ''); |
|
| 234 | - $suivant += 1; |
|
| 235 | - |
|
| 236 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 237 | - $code . |
|
| 238 | - " >>\" /></p>\n"; |
|
| 229 | + if ($code == '') { |
|
| 230 | + $code = _T('bouton_suivant'); |
|
| 231 | + } |
|
| 232 | + static $suivant = 0; |
|
| 233 | + $id = 'suivant' . (($suivant > 0) ? (string) $suivant : ''); |
|
| 234 | + $suivant += 1; |
|
| 235 | + |
|
| 236 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 237 | + $code . |
|
| 238 | + " >>\" /></p>\n"; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 242 | - $intitule_etat = []; |
|
| 243 | - |
|
| 244 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 245 | - $debut = 1; |
|
| 246 | - $last = is_countable($liste) ? count($liste) : 0; |
|
| 247 | - |
|
| 248 | - include_spip('inc/texte'); |
|
| 249 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 250 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 251 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 252 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 253 | - |
|
| 254 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 255 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 256 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 257 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 258 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 259 | - |
|
| 260 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 261 | - |
|
| 262 | - foreach (array_keys($liste) as $etape) { |
|
| 263 | - if ($debut < $last) { |
|
| 264 | - if ($debut == $en_cours && $erreur) { |
|
| 265 | - $class = 'on erreur'; |
|
| 266 | - } else { |
|
| 267 | - if ($debut == $en_cours) { |
|
| 268 | - $class = 'on'; |
|
| 269 | - } else { |
|
| 270 | - $class = $debut > $en_cours ? 'prochains' : 'valides'; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 275 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 276 | - $aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>'; |
|
| 277 | - $aff_etapes .= '</div></li>'; |
|
| 278 | - } |
|
| 279 | - $debut++; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return $aff_etapes . '</ul>'; |
|
| 242 | + $intitule_etat = []; |
|
| 243 | + |
|
| 244 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 245 | + $debut = 1; |
|
| 246 | + $last = is_countable($liste) ? count($liste) : 0; |
|
| 247 | + |
|
| 248 | + include_spip('inc/texte'); |
|
| 249 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 250 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 251 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 252 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 253 | + |
|
| 254 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 255 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 256 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 257 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 258 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 259 | + |
|
| 260 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 261 | + |
|
| 262 | + foreach (array_keys($liste) as $etape) { |
|
| 263 | + if ($debut < $last) { |
|
| 264 | + if ($debut == $en_cours && $erreur) { |
|
| 265 | + $class = 'on erreur'; |
|
| 266 | + } else { |
|
| 267 | + if ($debut == $en_cours) { |
|
| 268 | + $class = 'on'; |
|
| 269 | + } else { |
|
| 270 | + $class = $debut > $en_cours ? 'prochains' : 'valides'; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 275 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 276 | + $aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>'; |
|
| 277 | + $aff_etapes .= '</div></li>'; |
|
| 278 | + } |
|
| 279 | + $debut++; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return $aff_etapes . '</ul>'; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
| 286 | 286 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 287 | - return "<fieldset>\n" . |
|
| 288 | - $avant . |
|
| 289 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 290 | - fieldset_champs($champs) . |
|
| 291 | - $apres . |
|
| 292 | - "</fieldset>\n"; |
|
| 287 | + return "<fieldset>\n" . |
|
| 288 | + $avant . |
|
| 289 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 290 | + fieldset_champs($champs) . |
|
| 291 | + $apres . |
|
| 292 | + "</fieldset>\n"; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | function fieldset_champs($champs = []) { |
| 296 | - $fieldset = ''; |
|
| 297 | - foreach ($champs as $nom => $contenu) { |
|
| 298 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text'); |
|
| 299 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 300 | - if (isset($contenu['alternatives'])) { |
|
| 301 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 302 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 303 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 304 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 305 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 306 | - . "/>\n"; |
|
| 307 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 308 | - } |
|
| 309 | - $fieldset .= "<br />\n"; |
|
| 310 | - } else { |
|
| 311 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 312 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 313 | - . (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '') |
|
| 314 | - . ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '') |
|
| 315 | - . " />\n"; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $fieldset; |
|
| 296 | + $fieldset = ''; |
|
| 297 | + foreach ($champs as $nom => $contenu) { |
|
| 298 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text'); |
|
| 299 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 300 | + if (isset($contenu['alternatives'])) { |
|
| 301 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 302 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 303 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 304 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 305 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 306 | + . "/>\n"; |
|
| 307 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 308 | + } |
|
| 309 | + $fieldset .= "<br />\n"; |
|
| 310 | + } else { |
|
| 311 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 312 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 313 | + . (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '') |
|
| 314 | + . ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '') |
|
| 315 | + . " />\n"; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $fieldset; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | function install_select_serveur() { |
| 323 | - $options = []; |
|
| 324 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 325 | - $d = opendir($dir); |
|
| 326 | - if (!$d) { |
|
| 327 | - return []; |
|
| 328 | - } |
|
| 329 | - while (($f = readdir($d)) !== false) { |
|
| 330 | - if ( |
|
| 331 | - preg_match('/^(.*)[.]php$/', $f, $s) |
|
| 332 | - && is_readable($f = $dir . $f) |
|
| 333 | - ) { |
|
| 334 | - require_once($f); |
|
| 335 | - $s = $s[1]; |
|
| 336 | - $v = 'spip_versions_' . $s; |
|
| 337 | - if (function_exists($v) && $v()) { |
|
| 338 | - $titre = _T("install_select_type_$s"); |
|
| 339 | - // proposer mysql par defaut si dispo |
|
| 340 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 341 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 342 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 343 | - } else { |
|
| 344 | - spip_log("$s: portage indisponible"); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - sort($options); |
|
| 349 | - |
|
| 350 | - return $options; |
|
| 323 | + $options = []; |
|
| 324 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 325 | + $d = opendir($dir); |
|
| 326 | + if (!$d) { |
|
| 327 | + return []; |
|
| 328 | + } |
|
| 329 | + while (($f = readdir($d)) !== false) { |
|
| 330 | + if ( |
|
| 331 | + preg_match('/^(.*)[.]php$/', $f, $s) |
|
| 332 | + && is_readable($f = $dir . $f) |
|
| 333 | + ) { |
|
| 334 | + require_once($f); |
|
| 335 | + $s = $s[1]; |
|
| 336 | + $v = 'spip_versions_' . $s; |
|
| 337 | + if (function_exists($v) && $v()) { |
|
| 338 | + $titre = _T("install_select_type_$s"); |
|
| 339 | + // proposer mysql par defaut si dispo |
|
| 340 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 341 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 342 | + . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 343 | + } else { |
|
| 344 | + spip_log("$s: portage indisponible"); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + sort($options); |
|
| 349 | + |
|
| 350 | + return $options; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | function install_connexion_form($db, $login, #[\SensitiveParameter] $pass, $predef, $hidden, $etape, $jquery = true) { |
| 354 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 355 | - |
|
| 356 | - return generer_form_ecrire('install', ( |
|
| 357 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 358 | - . $hidden |
|
| 359 | - . (_request('echec') ? |
|
| 360 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 361 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 362 | - : '') |
|
| 363 | - |
|
| 364 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 365 | - . http_script(' |
|
| 354 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 355 | + |
|
| 356 | + return generer_form_ecrire('install', ( |
|
| 357 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 358 | + . $hidden |
|
| 359 | + . (_request('echec') ? |
|
| 360 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 361 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 362 | + : '') |
|
| 363 | + |
|
| 364 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 365 | + . http_script(' |
|
| 366 | 366 | jQuery(function($) { |
| 367 | 367 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 368 | 368 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -395,145 +395,145 @@ discard block |
||
| 395 | 395 | }); |
| 396 | 396 | });') |
| 397 | 397 | |
| 398 | - . ($server_db |
|
| 399 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 400 | - . (($predef[0]) |
|
| 401 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 402 | - : '') |
|
| 403 | - : ('<fieldset><legend>' |
|
| 404 | - . _T('install_select_type_db') |
|
| 405 | - . '</legend>' |
|
| 406 | - . '<p class="explication">' |
|
| 407 | - . _T('install_types_db_connus') |
|
| 408 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 409 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 410 | - . '</p>' |
|
| 411 | - . "\n<div class='p'>\n<ul>\n" |
|
| 412 | - . implode("\n", install_select_serveur()) |
|
| 413 | - . "\n</ul>\n</div></fieldset>") |
|
| 414 | - ) |
|
| 415 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 416 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 417 | - . ($predef[1] |
|
| 418 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 419 | - : fieldset( |
|
| 420 | - _T('entree_base_donnee_1'), |
|
| 421 | - [ |
|
| 422 | - 'adresse_db' => [ |
|
| 423 | - 'label' => $db[1], |
|
| 424 | - 'valeur' => $db[0] |
|
| 425 | - ], |
|
| 426 | - ] |
|
| 427 | - ) |
|
| 428 | - ) |
|
| 429 | - . '</div>' |
|
| 430 | - |
|
| 431 | - . '<div id="install_login_base_hebergeur">' |
|
| 432 | - . ($predef[2] |
|
| 433 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 434 | - : fieldset( |
|
| 435 | - _T('entree_login_connexion_1'), |
|
| 436 | - [ |
|
| 437 | - 'login_db' => [ |
|
| 438 | - 'label' => $login[1], |
|
| 439 | - 'valeur' => $login[0] |
|
| 440 | - ], |
|
| 441 | - ] |
|
| 442 | - ) |
|
| 443 | - ) |
|
| 444 | - . '</div>' |
|
| 445 | - |
|
| 446 | - . '<div id="install_pass_base_hebergeur">' |
|
| 447 | - . ($predef[3] |
|
| 448 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 449 | - : fieldset( |
|
| 450 | - _T('entree_mot_passe_1'), |
|
| 451 | - [ |
|
| 452 | - 'pass_db' => [ |
|
| 453 | - 'label' => $pass[1], |
|
| 454 | - 'valeur' => $pass[0] |
|
| 455 | - ], |
|
| 456 | - ] |
|
| 457 | - ) |
|
| 458 | - ) |
|
| 459 | - . '</div>' |
|
| 460 | - |
|
| 461 | - . bouton_suivant())); |
|
| 398 | + . ($server_db |
|
| 399 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 400 | + . (($predef[0]) |
|
| 401 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 402 | + : '') |
|
| 403 | + : ('<fieldset><legend>' |
|
| 404 | + . _T('install_select_type_db') |
|
| 405 | + . '</legend>' |
|
| 406 | + . '<p class="explication">' |
|
| 407 | + . _T('install_types_db_connus') |
|
| 408 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 409 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 410 | + . '</p>' |
|
| 411 | + . "\n<div class='p'>\n<ul>\n" |
|
| 412 | + . implode("\n", install_select_serveur()) |
|
| 413 | + . "\n</ul>\n</div></fieldset>") |
|
| 414 | + ) |
|
| 415 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 416 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 417 | + . ($predef[1] |
|
| 418 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 419 | + : fieldset( |
|
| 420 | + _T('entree_base_donnee_1'), |
|
| 421 | + [ |
|
| 422 | + 'adresse_db' => [ |
|
| 423 | + 'label' => $db[1], |
|
| 424 | + 'valeur' => $db[0] |
|
| 425 | + ], |
|
| 426 | + ] |
|
| 427 | + ) |
|
| 428 | + ) |
|
| 429 | + . '</div>' |
|
| 430 | + |
|
| 431 | + . '<div id="install_login_base_hebergeur">' |
|
| 432 | + . ($predef[2] |
|
| 433 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 434 | + : fieldset( |
|
| 435 | + _T('entree_login_connexion_1'), |
|
| 436 | + [ |
|
| 437 | + 'login_db' => [ |
|
| 438 | + 'label' => $login[1], |
|
| 439 | + 'valeur' => $login[0] |
|
| 440 | + ], |
|
| 441 | + ] |
|
| 442 | + ) |
|
| 443 | + ) |
|
| 444 | + . '</div>' |
|
| 445 | + |
|
| 446 | + . '<div id="install_pass_base_hebergeur">' |
|
| 447 | + . ($predef[3] |
|
| 448 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 449 | + : fieldset( |
|
| 450 | + _T('entree_mot_passe_1'), |
|
| 451 | + [ |
|
| 452 | + 'pass_db' => [ |
|
| 453 | + 'label' => $pass[1], |
|
| 454 | + 'valeur' => $pass[0] |
|
| 455 | + ], |
|
| 456 | + ] |
|
| 457 | + ) |
|
| 458 | + ) |
|
| 459 | + . '</div>' |
|
| 460 | + |
|
| 461 | + . bouton_suivant())); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // 4 valeurs qu'on reconduit d'un script a l'autre |
| 465 | 465 | // sauf s'ils sont predefinis. |
| 466 | 466 | |
| 467 | 467 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 468 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 469 | - ? '' |
|
| 470 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 471 | - ) |
|
| 472 | - . ((defined('_INSTALL_USER_DB')) |
|
| 473 | - ? '' |
|
| 474 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 475 | - ) |
|
| 476 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 477 | - ? '' |
|
| 478 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 479 | - ) |
|
| 480 | - |
|
| 481 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 482 | - ? '' |
|
| 483 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 484 | - ); |
|
| 468 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 469 | + ? '' |
|
| 470 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 471 | + ) |
|
| 472 | + . ((defined('_INSTALL_USER_DB')) |
|
| 473 | + ? '' |
|
| 474 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 475 | + ) |
|
| 476 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 477 | + ? '' |
|
| 478 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 479 | + ) |
|
| 480 | + |
|
| 481 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 482 | + ? '' |
|
| 483 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 484 | + ); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // presentation des bases existantes |
| 488 | 488 | |
| 489 | 489 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 490 | - $bases = $checked = []; |
|
| 491 | - $noms = sql_listdbs($server_db); |
|
| 492 | - if (!$noms) { |
|
| 493 | - return ''; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - foreach ($noms as $nom) { |
|
| 497 | - $id = spip_htmlspecialchars($nom); |
|
| 498 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 499 | - $base = ' name="choix_db" value="' |
|
| 500 | - . $nom |
|
| 501 | - . '"' |
|
| 502 | - . $dis |
|
| 503 | - . " type='radio' id='$id'"; |
|
| 504 | - $label = "<label for='$id'>" |
|
| 505 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 506 | - . '</label>'; |
|
| 507 | - |
|
| 508 | - if ( |
|
| 509 | - !$checked |
|
| 510 | - && !$dis |
|
| 511 | - && ($nom == $login_db || $GLOBALS['table_prefix'] == $nom) |
|
| 512 | - ) { |
|
| 513 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 514 | - } else { |
|
| 515 | - $bases[] = "<input$base />\n$label"; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - if (!$bases && !$checked) { |
|
| 520 | - return false; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if ($checked) { |
|
| 524 | - array_unshift($bases, $checked); |
|
| 525 | - $checked = true; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - return [$checked, $bases]; |
|
| 490 | + $bases = $checked = []; |
|
| 491 | + $noms = sql_listdbs($server_db); |
|
| 492 | + if (!$noms) { |
|
| 493 | + return ''; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + foreach ($noms as $nom) { |
|
| 497 | + $id = spip_htmlspecialchars($nom); |
|
| 498 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 499 | + $base = ' name="choix_db" value="' |
|
| 500 | + . $nom |
|
| 501 | + . '"' |
|
| 502 | + . $dis |
|
| 503 | + . " type='radio' id='$id'"; |
|
| 504 | + $label = "<label for='$id'>" |
|
| 505 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 506 | + . '</label>'; |
|
| 507 | + |
|
| 508 | + if ( |
|
| 509 | + !$checked |
|
| 510 | + && !$dis |
|
| 511 | + && ($nom == $login_db || $GLOBALS['table_prefix'] == $nom) |
|
| 512 | + ) { |
|
| 513 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 514 | + } else { |
|
| 515 | + $bases[] = "<input$base />\n$label"; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + if (!$bases && !$checked) { |
|
| 520 | + return false; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if ($checked) { |
|
| 524 | + array_unshift($bases, $checked); |
|
| 525 | + $checked = true; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + return [$checked, $bases]; |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | function install_propager($hidden) { |
| 532 | - $res = ''; |
|
| 533 | - foreach ($hidden as $k) { |
|
| 534 | - $v = spip_htmlentities(_request($k)); |
|
| 535 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 536 | - } |
|
| 532 | + $res = ''; |
|
| 533 | + foreach ($hidden as $k) { |
|
| 534 | + $v = spip_htmlentities(_request($k)); |
|
| 535 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - return $res; |
|
| 538 | + return $res; |
|
| 539 | 539 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @return void |
| 43 | 43 | **/ |
| 44 | 44 | function install_fichier_connexion($nom, $texte) { |
| 45 | - $texte = '<' . "?php\n" |
|
| 45 | + $texte = '<'."?php\n" |
|
| 46 | 46 | . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
| 47 | 47 | . $texte; |
| 48 | 48 | |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | return $regs; |
| 115 | 115 | } else { |
| 116 | 116 | $ar = '\s*\'([^\']*)\''; |
| 117 | - $r = '\s*,' . $ar; |
|
| 117 | + $r = '\s*,'.$ar; |
|
| 118 | 118 | $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
| 119 | 119 | if (preg_match($r, $s, $regs)) { |
| 120 | - $regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : ''); |
|
| 120 | + $regs[2] = $regs[1].($regs[2] ? ':'.$regs[2].';' : ''); |
|
| 121 | 121 | array_shift($regs); |
| 122 | 122 | array_shift($regs); |
| 123 | 123 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // Si on n'a pas la bonne version de PHP, c'est la fin |
| 183 | 183 | if ($err) { |
| 184 | 184 | die("<div class='error'>" |
| 185 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 185 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>" |
|
| 186 | 186 | . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | if ($err) { |
| 204 | 204 | echo "<div class='error'>" |
| 205 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"; |
|
| 206 | 206 | foreach ($err as $e) { |
| 207 | 207 | echo "<li><strong>$e</strong></li>\n"; |
| 208 | 208 | } |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | |
| 217 | 217 | function info_etape($titre, $complement = '') { |
| 218 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 219 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 218 | + return '<h2>'.$titre."</h2>\n". |
|
| 219 | + ($complement ? ''.$complement."\n" : ''); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -230,18 +230,18 @@ discard block |
||
| 230 | 230 | $code = _T('bouton_suivant'); |
| 231 | 231 | } |
| 232 | 232 | static $suivant = 0; |
| 233 | - $id = 'suivant' . (($suivant > 0) ? (string) $suivant : ''); |
|
| 233 | + $id = 'suivant'.(($suivant > 0) ? (string) $suivant : ''); |
|
| 234 | 234 | $suivant += 1; |
| 235 | 235 | |
| 236 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 237 | - $code . |
|
| 236 | + return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"". |
|
| 237 | + $code. |
|
| 238 | 238 | " >>\" /></p>\n"; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 242 | 242 | $intitule_etat = []; |
| 243 | 243 | |
| 244 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 244 | + $liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$'); |
|
| 245 | 245 | $debut = 1; |
| 246 | 246 | $last = is_countable($liste) ? count($liste) : 0; |
| 247 | 247 | |
@@ -272,23 +272,23 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | $aff_etapes .= "<li class='$class'><div class='fond'>"; |
| 275 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 276 | - $aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>'; |
|
| 275 | + $aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 276 | + $aff_etapes .= '<'.(($debut == $en_cours) ? 'strong' : 'span').' class="label_etape">'.$intitule_etat["$phase"][$debut].'</'.(($debut == $en_cours) ? 'strong' : 'span').'>'; |
|
| 277 | 277 | $aff_etapes .= '</div></li>'; |
| 278 | 278 | } |
| 279 | 279 | $debut++; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - return $aff_etapes . '</ul>'; |
|
| 282 | + return $aff_etapes.'</ul>'; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
| 286 | 286 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 287 | - return "<fieldset>\n" . |
|
| 288 | - $avant . |
|
| 289 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 290 | - fieldset_champs($champs) . |
|
| 291 | - $apres . |
|
| 287 | + return "<fieldset>\n". |
|
| 288 | + $avant. |
|
| 289 | + ($legend ? '<legend>'.$legend."</legend>\n" : ''). |
|
| 290 | + fieldset_champs($champs). |
|
| 291 | + $apres. |
|
| 292 | 292 | "</fieldset>\n"; |
| 293 | 293 | } |
| 294 | 294 | |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text'); |
| 299 | 299 | $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
| 300 | 300 | if (isset($contenu['alternatives'])) { |
| 301 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 301 | + $fieldset .= $contenu['label']."\n"; |
|
| 302 | 302 | foreach ($contenu['alternatives'] as $valeur => $label) { |
| 303 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 303 | + $fieldset .= "<input type='radio' name='".$nom. |
|
| 304 | 304 | "' id='$nom-$valeur' value='$valeur'" |
| 305 | 305 | . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
| 306 | 306 | . "/>\n"; |
| 307 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 307 | + $fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n"; |
|
| 308 | 308 | } |
| 309 | 309 | $fieldset .= "<br />\n"; |
| 310 | 310 | } else { |
| 311 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 312 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 311 | + $fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n"; |
|
| 312 | + $fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'" |
|
| 313 | 313 | . (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '') |
| 314 | 314 | . ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '') |
| 315 | 315 | . " />\n"; |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | |
| 322 | 322 | function install_select_serveur() { |
| 323 | 323 | $options = []; |
| 324 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 324 | + $dir = _DIR_RESTREINT.'req/'; |
|
| 325 | 325 | $d = opendir($dir); |
| 326 | 326 | if (!$d) { |
| 327 | 327 | return []; |
@@ -329,17 +329,17 @@ discard block |
||
| 329 | 329 | while (($f = readdir($d)) !== false) { |
| 330 | 330 | if ( |
| 331 | 331 | preg_match('/^(.*)[.]php$/', $f, $s) |
| 332 | - && is_readable($f = $dir . $f) |
|
| 332 | + && is_readable($f = $dir.$f) |
|
| 333 | 333 | ) { |
| 334 | 334 | require_once($f); |
| 335 | 335 | $s = $s[1]; |
| 336 | - $v = 'spip_versions_' . $s; |
|
| 336 | + $v = 'spip_versions_'.$s; |
|
| 337 | 337 | if (function_exists($v) && $v()) { |
| 338 | 338 | $titre = _T("install_select_type_$s"); |
| 339 | 339 | // proposer mysql par defaut si dispo |
| 340 | 340 | $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
| 341 | 341 | $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
| 342 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 342 | + . "<label for='$s'>".($titre ?: $s).'</label></li>'; |
|
| 343 | 343 | } else { |
| 344 | 344 | spip_log("$s: portage indisponible"); |
| 345 | 345 | } |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | "\n<input type='hidden' name='etape' value='$etape' />" |
| 358 | 358 | . $hidden |
| 359 | 359 | . (_request('echec') ? |
| 360 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 361 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 360 | + ('<p><b>'._T('avis_connexion_echec_1'). |
|
| 361 | + '</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>') |
|
| 362 | 362 | : '') |
| 363 | 363 | |
| 364 | 364 | . ($jquery ? http_script('', 'jquery.js') : '') |
@@ -396,9 +396,9 @@ discard block |
||
| 396 | 396 | });') |
| 397 | 397 | |
| 398 | 398 | . ($server_db |
| 399 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 399 | + ? '<input type="hidden" name="server_db" value="'.$server_db.'" />' |
|
| 400 | 400 | . (($predef[0]) |
| 401 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 401 | + ? ('<h3>'._T('install_serveur_hebergeur').'</h3>') |
|
| 402 | 402 | : '') |
| 403 | 403 | : ('<fieldset><legend>' |
| 404 | 404 | . _T('install_select_type_db') |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | . "\n</ul>\n</div></fieldset>") |
| 414 | 414 | ) |
| 415 | 415 | . '<div id="install_adresse_base_hebergeur">' |
| 416 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 416 | + . '<p>'._T('texte_connexion_mysql').'</p>' |
|
| 417 | 417 | . ($predef[1] |
| 418 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 418 | + ? '<h3>'._T('install_adresse_base_hebergeur').'</h3>' |
|
| 419 | 419 | : fieldset( |
| 420 | 420 | _T('entree_base_donnee_1'), |
| 421 | 421 | [ |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | . '<div id="install_login_base_hebergeur">' |
| 432 | 432 | . ($predef[2] |
| 433 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 433 | + ? '<h3>'._T('install_login_base_hebergeur').'</h3>' |
|
| 434 | 434 | : fieldset( |
| 435 | 435 | _T('entree_login_connexion_1'), |
| 436 | 436 | [ |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | |
| 446 | 446 | . '<div id="install_pass_base_hebergeur">' |
| 447 | 447 | . ($predef[3] |
| 448 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 448 | + ? '<h3>'._T('install_pass_base_hebergeur').'</h3>' |
|
| 449 | 449 | : fieldset( |
| 450 | 450 | _T('entree_mot_passe_1'), |
| 451 | 451 | [ |
@@ -467,20 +467,20 @@ discard block |
||
| 467 | 467 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 468 | 468 | return ((defined('_INSTALL_HOST_DB')) |
| 469 | 469 | ? '' |
| 470 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 470 | + : "\n<input type='hidden' name='adresse_db' value=\"".spip_htmlspecialchars($adresse_db).'" />' |
|
| 471 | 471 | ) |
| 472 | 472 | . ((defined('_INSTALL_USER_DB')) |
| 473 | 473 | ? '' |
| 474 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 474 | + : "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />' |
|
| 475 | 475 | ) |
| 476 | 476 | . ((defined('_INSTALL_PASS_DB')) |
| 477 | 477 | ? '' |
| 478 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 478 | + : "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />' |
|
| 479 | 479 | ) |
| 480 | 480 | |
| 481 | 481 | . ((defined('_INSTALL_SERVER_DB')) |
| 482 | 482 | ? '' |
| 483 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 483 | + : "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />' |
|
| 484 | 484 | ); |
| 485 | 485 | } |
| 486 | 486 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @return void |
| 28 | 28 | */ |
| 29 | 29 | function inc_config_dist() { |
| 30 | - actualise_metas(liste_metas()); |
|
| 30 | + actualise_metas(liste_metas()); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -44,32 +44,32 @@ discard block |
||
| 44 | 44 | * Liste (table, casier, sous_casier) |
| 45 | 45 | */ |
| 46 | 46 | function expliquer_config($cfg) { |
| 47 | - // par defaut, sur la table des meta |
|
| 48 | - $table = 'meta'; |
|
| 49 | - $casier = null; |
|
| 50 | - $sous_casier = []; |
|
| 51 | - $cfg = explode('/', $cfg); |
|
| 52 | - |
|
| 53 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 54 | - if (!reset($cfg) && count($cfg) > 1) { |
|
| 55 | - array_shift($cfg); |
|
| 56 | - $table = array_shift($cfg); |
|
| 57 | - if (!isset($GLOBALS[$table])) { |
|
| 58 | - lire_metas($table); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 63 | - // pas sur un appel vide '' |
|
| 64 | - if (count($cfg) && '' !== ($c = array_shift($cfg))) { |
|
| 65 | - $casier = $c; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($cfg !== []) { |
|
| 69 | - $sous_casier = $cfg; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return [$table, $casier, $sous_casier]; |
|
| 47 | + // par defaut, sur la table des meta |
|
| 48 | + $table = 'meta'; |
|
| 49 | + $casier = null; |
|
| 50 | + $sous_casier = []; |
|
| 51 | + $cfg = explode('/', $cfg); |
|
| 52 | + |
|
| 53 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 54 | + if (!reset($cfg) && count($cfg) > 1) { |
|
| 55 | + array_shift($cfg); |
|
| 56 | + $table = array_shift($cfg); |
|
| 57 | + if (!isset($GLOBALS[$table])) { |
|
| 58 | + lire_metas($table); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 63 | + // pas sur un appel vide '' |
|
| 64 | + if (count($cfg) && '' !== ($c = array_shift($cfg))) { |
|
| 65 | + $casier = $c; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($cfg !== []) { |
|
| 69 | + $sous_casier = $cfg; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return [$table, $casier, $sous_casier]; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -97,63 +97,63 @@ discard block |
||
| 97 | 97 | * Contenu de la configuration obtenue |
| 98 | 98 | */ |
| 99 | 99 | function lire_config($cfg = '', mixed $def = null, $unserialize = true) { |
| 100 | - // lire le stockage sous la forme /table/valeur |
|
| 101 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 102 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 103 | - |
|
| 104 | - // traiter en priorite le cas simple et frequent |
|
| 105 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 106 | - if ($cfg && strpbrk($cfg, '/:') === false) { |
|
| 107 | - return isset($GLOBALS['meta'][$cfg]) |
|
| 108 | - ? (!$unserialize |
|
| 109 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 110 | - || !is_string($GLOBALS['meta'][$cfg]) |
|
| 111 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 112 | - || !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 113 | - || ($t = @unserialize($GLOBALS['meta'][$cfg])) === false ? $GLOBALS['meta'][$cfg] : $t) |
|
| 114 | - : $def; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Brancher sur methodes externes si besoin |
|
| 118 | - if ($cfg && ($p = strpos($cfg, '::'))) { |
|
| 119 | - $methode = substr($cfg, 0, $p); |
|
| 120 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 121 | - |
|
| 122 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 126 | - |
|
| 127 | - if (!isset($GLOBALS[$table])) { |
|
| 128 | - return $def; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $r = $GLOBALS[$table]; |
|
| 132 | - |
|
| 133 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 134 | - if (!$casier) { |
|
| 135 | - return $unserialize ? $r : serialize($r); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // casier principal : |
|
| 139 | - // le deserializer si demande |
|
| 140 | - // ou si on a besoin |
|
| 141 | - // d'un sous casier |
|
| 142 | - $r = $r[$casier] ?? null; |
|
| 143 | - if (($unserialize || (is_countable($sous_casier) ? count($sous_casier) : 0)) && $r && is_string($r)) { |
|
| 144 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // aller chercher le sous_casier |
|
| 148 | - while (!is_null($r) && ($casier = array_shift($sous_casier))) { |
|
| 149 | - $r = $r[$casier] ?? null; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if (is_null($r)) { |
|
| 153 | - return $def; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $r; |
|
| 100 | + // lire le stockage sous la forme /table/valeur |
|
| 101 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 102 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 103 | + |
|
| 104 | + // traiter en priorite le cas simple et frequent |
|
| 105 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 106 | + if ($cfg && strpbrk($cfg, '/:') === false) { |
|
| 107 | + return isset($GLOBALS['meta'][$cfg]) |
|
| 108 | + ? (!$unserialize |
|
| 109 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 110 | + || !is_string($GLOBALS['meta'][$cfg]) |
|
| 111 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 112 | + || !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 113 | + || ($t = @unserialize($GLOBALS['meta'][$cfg])) === false ? $GLOBALS['meta'][$cfg] : $t) |
|
| 114 | + : $def; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Brancher sur methodes externes si besoin |
|
| 118 | + if ($cfg && ($p = strpos($cfg, '::'))) { |
|
| 119 | + $methode = substr($cfg, 0, $p); |
|
| 120 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 121 | + |
|
| 122 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 126 | + |
|
| 127 | + if (!isset($GLOBALS[$table])) { |
|
| 128 | + return $def; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $r = $GLOBALS[$table]; |
|
| 132 | + |
|
| 133 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 134 | + if (!$casier) { |
|
| 135 | + return $unserialize ? $r : serialize($r); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // casier principal : |
|
| 139 | + // le deserializer si demande |
|
| 140 | + // ou si on a besoin |
|
| 141 | + // d'un sous casier |
|
| 142 | + $r = $r[$casier] ?? null; |
|
| 143 | + if (($unserialize || (is_countable($sous_casier) ? count($sous_casier) : 0)) && $r && is_string($r)) { |
|
| 144 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // aller chercher le sous_casier |
|
| 148 | + while (!is_null($r) && ($casier = array_shift($sous_casier))) { |
|
| 149 | + $r = $r[$casier] ?? null; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if (is_null($r)) { |
|
| 153 | + return $def; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $r; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @return mixed |
| 167 | 167 | */ |
| 168 | 168 | function lire_config_metapack_dist($cfg = '', mixed $def = null, $unserialize = true) { |
| 169 | - return lire_config($cfg, $def, $unserialize); |
|
| 169 | + return lire_config($cfg, $def, $unserialize); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -177,144 +177,144 @@ discard block |
||
| 177 | 177 | * @return bool |
| 178 | 178 | */ |
| 179 | 179 | function ecrire_config($cfg, mixed $store) { |
| 180 | - // Brancher sur methodes externes si besoin |
|
| 181 | - if ($cfg && ($p = strpos($cfg, '::'))) { |
|
| 182 | - $methode = substr($cfg, 0, $p); |
|
| 183 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 184 | - |
|
| 185 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 189 | - // il faut au moins un casier pour ecrire |
|
| 190 | - if (!$casier) { |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // trouvons ou creons le pointeur sur le casier |
|
| 195 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 196 | - if (!is_array($st) && ($sous_casier || is_array($store))) { |
|
| 197 | - if ($st === null) { |
|
| 198 | - // ne rien creer si c'est une demande d'effacement |
|
| 199 | - if ($store === null) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - $st = []; |
|
| 203 | - } else { |
|
| 204 | - $st = unserialize($st); |
|
| 205 | - if ($st === false) { |
|
| 206 | - // ne rien creer si c'est une demande d'effacement |
|
| 207 | - if ($store === null) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - $st = []; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $has_planes = false; |
|
| 216 | - // si on a affaire a un sous caiser |
|
| 217 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 218 | - if ($c = $sous_casier) { |
|
| 219 | - $sc = &$st; |
|
| 220 | - $pointeurs = []; |
|
| 221 | - while ((is_countable($c) ? count($c) : 0) && ($cc = array_shift($c))) { |
|
| 222 | - // creer l'entree si elle n'existe pas |
|
| 223 | - if (!isset($sc[$cc])) { |
|
| 224 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 225 | - // ne rien creer mais sortir |
|
| 226 | - if (is_null($store)) { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - $sc[$cc] = []; |
|
| 230 | - } |
|
| 231 | - $pointeurs[$cc] = &$sc; |
|
| 232 | - $sc = &$sc[$cc]; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - // si c'est une demande d'effacement |
|
| 236 | - if (is_null($store)) { |
|
| 237 | - $c = $sous_casier; |
|
| 238 | - $sous = array_pop($c); |
|
| 239 | - // effacer, et remonter pour effacer les parents vides |
|
| 240 | - do { |
|
| 241 | - unset($pointeurs[$sous][$sous]); |
|
| 242 | - } while (($sous = array_pop($c)) && !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 243 | - |
|
| 244 | - // si on a vide tous les sous casiers, |
|
| 245 | - // et que le casier est vide |
|
| 246 | - // vider aussi la meta |
|
| 247 | - if (!$sous && !(is_countable($st) ? count($st) : 0)) { |
|
| 248 | - $st = null; |
|
| 249 | - } |
|
| 250 | - } // dans tous les autres cas, on ecrase |
|
| 251 | - else { |
|
| 252 | - if ( |
|
| 253 | - defined('_MYSQL_NOPLANES') |
|
| 254 | - && _MYSQL_NOPLANES |
|
| 255 | - && !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 256 | - && $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 257 | - ) { |
|
| 258 | - // detecter si la valeur qu'on veut ecrire a des planes |
|
| 259 | - // @see utf8_noplanes |
|
| 260 | - $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 261 | - // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 262 | - if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 263 | - if (!function_exists('utf8_noplanes')) { |
|
| 264 | - include_spip('inc/charsets'); |
|
| 265 | - } |
|
| 266 | - if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 267 | - $has_planes = true; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $sc = $store; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Maintenant que $st est modifiee |
|
| 276 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 277 | - $store = $st; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - if (is_null($store)) { |
|
| 281 | - if (is_null($st) && !$sous_casier) { |
|
| 282 | - return false; |
|
| 283 | - } // la config n'existait deja pas ! |
|
| 284 | - effacer_meta($casier, $table); |
|
| 285 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 286 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 287 | - else { |
|
| 288 | - if (!isset($GLOBALS[$table])) { |
|
| 289 | - installer_table_meta($table); |
|
| 290 | - } |
|
| 291 | - // si ce n'est pas une chaine |
|
| 292 | - // il faut serializer |
|
| 293 | - if (!is_string($store)) { |
|
| 294 | - $serialized_store = serialize($store); |
|
| 295 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 296 | - // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 297 | - // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 298 | - if ($has_planes) { |
|
| 299 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 300 | - if ($check_store !== $serialized_store) { |
|
| 301 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 302 | - if (is_string($value)) { |
|
| 303 | - $value = utf8_noplanes($value); |
|
| 304 | - } |
|
| 305 | - }); |
|
| 306 | - $serialized_store = serialize($store); |
|
| 307 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - else { |
|
| 312 | - ecrire_meta($casier, $store, null, $table); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - // verifier que lire_config($cfg)==$store ? |
|
| 317 | - return true; |
|
| 180 | + // Brancher sur methodes externes si besoin |
|
| 181 | + if ($cfg && ($p = strpos($cfg, '::'))) { |
|
| 182 | + $methode = substr($cfg, 0, $p); |
|
| 183 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 184 | + |
|
| 185 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 189 | + // il faut au moins un casier pour ecrire |
|
| 190 | + if (!$casier) { |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // trouvons ou creons le pointeur sur le casier |
|
| 195 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 196 | + if (!is_array($st) && ($sous_casier || is_array($store))) { |
|
| 197 | + if ($st === null) { |
|
| 198 | + // ne rien creer si c'est une demande d'effacement |
|
| 199 | + if ($store === null) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + $st = []; |
|
| 203 | + } else { |
|
| 204 | + $st = unserialize($st); |
|
| 205 | + if ($st === false) { |
|
| 206 | + // ne rien creer si c'est une demande d'effacement |
|
| 207 | + if ($store === null) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + $st = []; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $has_planes = false; |
|
| 216 | + // si on a affaire a un sous caiser |
|
| 217 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 218 | + if ($c = $sous_casier) { |
|
| 219 | + $sc = &$st; |
|
| 220 | + $pointeurs = []; |
|
| 221 | + while ((is_countable($c) ? count($c) : 0) && ($cc = array_shift($c))) { |
|
| 222 | + // creer l'entree si elle n'existe pas |
|
| 223 | + if (!isset($sc[$cc])) { |
|
| 224 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 225 | + // ne rien creer mais sortir |
|
| 226 | + if (is_null($store)) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + $sc[$cc] = []; |
|
| 230 | + } |
|
| 231 | + $pointeurs[$cc] = &$sc; |
|
| 232 | + $sc = &$sc[$cc]; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + // si c'est une demande d'effacement |
|
| 236 | + if (is_null($store)) { |
|
| 237 | + $c = $sous_casier; |
|
| 238 | + $sous = array_pop($c); |
|
| 239 | + // effacer, et remonter pour effacer les parents vides |
|
| 240 | + do { |
|
| 241 | + unset($pointeurs[$sous][$sous]); |
|
| 242 | + } while (($sous = array_pop($c)) && !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 243 | + |
|
| 244 | + // si on a vide tous les sous casiers, |
|
| 245 | + // et que le casier est vide |
|
| 246 | + // vider aussi la meta |
|
| 247 | + if (!$sous && !(is_countable($st) ? count($st) : 0)) { |
|
| 248 | + $st = null; |
|
| 249 | + } |
|
| 250 | + } // dans tous les autres cas, on ecrase |
|
| 251 | + else { |
|
| 252 | + if ( |
|
| 253 | + defined('_MYSQL_NOPLANES') |
|
| 254 | + && _MYSQL_NOPLANES |
|
| 255 | + && !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 256 | + && $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 257 | + ) { |
|
| 258 | + // detecter si la valeur qu'on veut ecrire a des planes |
|
| 259 | + // @see utf8_noplanes |
|
| 260 | + $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 261 | + // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 262 | + if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 263 | + if (!function_exists('utf8_noplanes')) { |
|
| 264 | + include_spip('inc/charsets'); |
|
| 265 | + } |
|
| 266 | + if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 267 | + $has_planes = true; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $sc = $store; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Maintenant que $st est modifiee |
|
| 276 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 277 | + $store = $st; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + if (is_null($store)) { |
|
| 281 | + if (is_null($st) && !$sous_casier) { |
|
| 282 | + return false; |
|
| 283 | + } // la config n'existait deja pas ! |
|
| 284 | + effacer_meta($casier, $table); |
|
| 285 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 286 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 287 | + else { |
|
| 288 | + if (!isset($GLOBALS[$table])) { |
|
| 289 | + installer_table_meta($table); |
|
| 290 | + } |
|
| 291 | + // si ce n'est pas une chaine |
|
| 292 | + // il faut serializer |
|
| 293 | + if (!is_string($store)) { |
|
| 294 | + $serialized_store = serialize($store); |
|
| 295 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 296 | + // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 297 | + // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 298 | + if ($has_planes) { |
|
| 299 | + $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 300 | + if ($check_store !== $serialized_store) { |
|
| 301 | + array_walk_recursive($store, function (&$value, $key) { |
|
| 302 | + if (is_string($value)) { |
|
| 303 | + $value = utf8_noplanes($value); |
|
| 304 | + } |
|
| 305 | + }); |
|
| 306 | + $serialized_store = serialize($store); |
|
| 307 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + else { |
|
| 312 | + ecrire_meta($casier, $store, null, $table); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + // verifier que lire_config($cfg)==$store ? |
|
| 317 | + return true; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -327,14 +327,14 @@ discard block |
||
| 327 | 327 | * @return bool |
| 328 | 328 | */ |
| 329 | 329 | function ecrire_config_metapack_dist($cfg, mixed $store) { |
| 330 | - // cas particulier en metapack:: |
|
| 331 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 332 | - // intacte en sortie ... |
|
| 333 | - if (is_string($store) && strpos($store, ':') && unserialize($store)) { |
|
| 334 | - $store = serialize($store); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return ecrire_config($cfg, $store); |
|
| 330 | + // cas particulier en metapack:: |
|
| 331 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 332 | + // intacte en sortie ... |
|
| 333 | + if (is_string($store) && strpos($store, ':') && unserialize($store)) { |
|
| 334 | + $store = serialize($store); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return ecrire_config($cfg, $store); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | * @return bool |
| 345 | 345 | */ |
| 346 | 346 | function effacer_config($cfg) { |
| 347 | - ecrire_config($cfg, null); |
|
| 347 | + ecrire_config($cfg, null); |
|
| 348 | 348 | |
| 349 | - return true; |
|
| 349 | + return true; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -363,58 +363,58 @@ discard block |
||
| 363 | 363 | * Couples nom de la `meta` => valeur par défaut |
| 364 | 364 | */ |
| 365 | 365 | function liste_metas() { |
| 366 | - return pipeline('configurer_liste_metas', [ |
|
| 367 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 368 | - 'slogan_site' => '', |
|
| 369 | - 'adresse_site' => preg_replace(',/$,', '', (string) url_de_base()), |
|
| 370 | - 'descriptif_site' => '', |
|
| 371 | - 'activer_logos' => 'oui', |
|
| 372 | - 'activer_logos_survol' => 'non', |
|
| 373 | - 'articles_surtitre' => 'non', |
|
| 374 | - 'articles_soustitre' => 'non', |
|
| 375 | - 'articles_descriptif' => 'non', |
|
| 376 | - 'articles_chapeau' => 'non', |
|
| 377 | - 'articles_texte' => 'oui', |
|
| 378 | - 'articles_ps' => 'non', |
|
| 379 | - 'articles_redac' => 'non', |
|
| 380 | - 'post_dates' => 'non', |
|
| 381 | - 'articles_urlref' => 'non', |
|
| 382 | - 'articles_redirection' => 'non', |
|
| 383 | - 'creer_preview' => 'non', |
|
| 384 | - 'taille_preview' => 150, |
|
| 385 | - 'articles_modif' => 'non', |
|
| 386 | - |
|
| 387 | - 'rubriques_descriptif' => 'non', |
|
| 388 | - 'rubriques_texte' => 'oui', |
|
| 389 | - |
|
| 390 | - 'accepter_inscriptions' => 'non', |
|
| 391 | - 'accepter_visiteurs' => 'non', |
|
| 392 | - 'prevenir_auteurs' => 'non', |
|
| 393 | - 'suivi_edito' => 'non', |
|
| 394 | - 'adresse_suivi' => '', |
|
| 395 | - 'adresse_suivi_inscription' => '', |
|
| 396 | - 'adresse_neuf' => '', |
|
| 397 | - 'jours_neuf' => '', |
|
| 398 | - 'quoi_de_neuf' => 'non', |
|
| 399 | - 'preview' => ',0minirezo,1comite,', |
|
| 400 | - |
|
| 401 | - 'syndication_integrale' => 'oui', |
|
| 402 | - 'charset' => _DEFAULT_CHARSET, |
|
| 403 | - 'dir_img' => substr((string) _DIR_IMG, strlen(_DIR_RACINE)), |
|
| 404 | - |
|
| 405 | - 'multi_rubriques' => 'non', |
|
| 406 | - 'multi_secteurs' => 'non', |
|
| 407 | - 'gerer_trad' => 'non', |
|
| 408 | - 'langues_multilingue' => '', |
|
| 409 | - |
|
| 410 | - 'version_html_max' => 'html4', |
|
| 411 | - |
|
| 412 | - 'type_urls' => 'page', |
|
| 413 | - |
|
| 414 | - 'email_envoi' => '', |
|
| 415 | - 'email_webmaster' => '', |
|
| 416 | - 'auto_compress_http' => 'non', |
|
| 417 | - ]); |
|
| 366 | + return pipeline('configurer_liste_metas', [ |
|
| 367 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 368 | + 'slogan_site' => '', |
|
| 369 | + 'adresse_site' => preg_replace(',/$,', '', (string) url_de_base()), |
|
| 370 | + 'descriptif_site' => '', |
|
| 371 | + 'activer_logos' => 'oui', |
|
| 372 | + 'activer_logos_survol' => 'non', |
|
| 373 | + 'articles_surtitre' => 'non', |
|
| 374 | + 'articles_soustitre' => 'non', |
|
| 375 | + 'articles_descriptif' => 'non', |
|
| 376 | + 'articles_chapeau' => 'non', |
|
| 377 | + 'articles_texte' => 'oui', |
|
| 378 | + 'articles_ps' => 'non', |
|
| 379 | + 'articles_redac' => 'non', |
|
| 380 | + 'post_dates' => 'non', |
|
| 381 | + 'articles_urlref' => 'non', |
|
| 382 | + 'articles_redirection' => 'non', |
|
| 383 | + 'creer_preview' => 'non', |
|
| 384 | + 'taille_preview' => 150, |
|
| 385 | + 'articles_modif' => 'non', |
|
| 386 | + |
|
| 387 | + 'rubriques_descriptif' => 'non', |
|
| 388 | + 'rubriques_texte' => 'oui', |
|
| 389 | + |
|
| 390 | + 'accepter_inscriptions' => 'non', |
|
| 391 | + 'accepter_visiteurs' => 'non', |
|
| 392 | + 'prevenir_auteurs' => 'non', |
|
| 393 | + 'suivi_edito' => 'non', |
|
| 394 | + 'adresse_suivi' => '', |
|
| 395 | + 'adresse_suivi_inscription' => '', |
|
| 396 | + 'adresse_neuf' => '', |
|
| 397 | + 'jours_neuf' => '', |
|
| 398 | + 'quoi_de_neuf' => 'non', |
|
| 399 | + 'preview' => ',0minirezo,1comite,', |
|
| 400 | + |
|
| 401 | + 'syndication_integrale' => 'oui', |
|
| 402 | + 'charset' => _DEFAULT_CHARSET, |
|
| 403 | + 'dir_img' => substr((string) _DIR_IMG, strlen(_DIR_RACINE)), |
|
| 404 | + |
|
| 405 | + 'multi_rubriques' => 'non', |
|
| 406 | + 'multi_secteurs' => 'non', |
|
| 407 | + 'gerer_trad' => 'non', |
|
| 408 | + 'langues_multilingue' => '', |
|
| 409 | + |
|
| 410 | + 'version_html_max' => 'html4', |
|
| 411 | + |
|
| 412 | + 'type_urls' => 'page', |
|
| 413 | + |
|
| 414 | + 'email_envoi' => '', |
|
| 415 | + 'email_webmaster' => '', |
|
| 416 | + 'auto_compress_http' => 'non', |
|
| 417 | + ]); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -425,43 +425,43 @@ discard block |
||
| 425 | 425 | * @return void |
| 426 | 426 | */ |
| 427 | 427 | function actualise_metas($liste_meta) { |
| 428 | - $meta_serveur = |
|
| 429 | - [ |
|
| 430 | - 'version_installee', |
|
| 431 | - 'adresse_site', |
|
| 432 | - 'alea_ephemere_ancien', |
|
| 433 | - 'alea_ephemere', |
|
| 434 | - 'alea_ephemere_date', |
|
| 435 | - 'langue_site', |
|
| 436 | - 'langues_proposees', |
|
| 437 | - 'date_calcul_rubriques', |
|
| 438 | - 'derniere_modif', |
|
| 439 | - 'optimiser_table', |
|
| 440 | - 'drapeau_edition', |
|
| 441 | - 'creer_preview', |
|
| 442 | - 'taille_preview', |
|
| 443 | - 'creer_htpasswd', |
|
| 444 | - 'creer_htaccess', |
|
| 445 | - 'gd_formats_read', |
|
| 446 | - 'gd_formats', |
|
| 447 | - 'netpbm_formats', |
|
| 448 | - 'formats_graphiques', |
|
| 449 | - 'image_process', |
|
| 450 | - 'plugin_header', |
|
| 451 | - 'plugin' |
|
| 452 | - ]; |
|
| 453 | - // verifier le impt=non |
|
| 454 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 455 | - |
|
| 456 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 457 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 458 | - ecrire_meta($nom, $valeur); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - include_spip('inc/rubriques'); |
|
| 463 | - $langues = calculer_langues_utilisees(); |
|
| 464 | - ecrire_meta('langues_utilisees', $langues); |
|
| 428 | + $meta_serveur = |
|
| 429 | + [ |
|
| 430 | + 'version_installee', |
|
| 431 | + 'adresse_site', |
|
| 432 | + 'alea_ephemere_ancien', |
|
| 433 | + 'alea_ephemere', |
|
| 434 | + 'alea_ephemere_date', |
|
| 435 | + 'langue_site', |
|
| 436 | + 'langues_proposees', |
|
| 437 | + 'date_calcul_rubriques', |
|
| 438 | + 'derniere_modif', |
|
| 439 | + 'optimiser_table', |
|
| 440 | + 'drapeau_edition', |
|
| 441 | + 'creer_preview', |
|
| 442 | + 'taille_preview', |
|
| 443 | + 'creer_htpasswd', |
|
| 444 | + 'creer_htaccess', |
|
| 445 | + 'gd_formats_read', |
|
| 446 | + 'gd_formats', |
|
| 447 | + 'netpbm_formats', |
|
| 448 | + 'formats_graphiques', |
|
| 449 | + 'image_process', |
|
| 450 | + 'plugin_header', |
|
| 451 | + 'plugin' |
|
| 452 | + ]; |
|
| 453 | + // verifier le impt=non |
|
| 454 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 455 | + |
|
| 456 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 457 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 458 | + ecrire_meta($nom, $valeur); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + include_spip('inc/rubriques'); |
|
| 463 | + $langues = calculer_langues_utilisees(); |
|
| 464 | + ecrire_meta('langues_utilisees', $langues); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | |
@@ -483,18 +483,18 @@ discard block |
||
| 483 | 483 | */ |
| 484 | 484 | function appliquer_modifs_config($purger_skel = false) { |
| 485 | 485 | |
| 486 | - foreach (liste_metas() as $i => $v) { |
|
| 487 | - if (($x = _request($i)) !== null) { |
|
| 488 | - ecrire_meta($i, $x); |
|
| 489 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 490 | - ecrire_meta($i, $v); |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - if ($purger_skel) { |
|
| 495 | - include_spip('inc/invalideur'); |
|
| 496 | - purger_repertoire(_DIR_SKELS); |
|
| 497 | - } |
|
| 486 | + foreach (liste_metas() as $i => $v) { |
|
| 487 | + if (($x = _request($i)) !== null) { |
|
| 488 | + ecrire_meta($i, $x); |
|
| 489 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 490 | + ecrire_meta($i, $v); |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + if ($purger_skel) { |
|
| 495 | + include_spip('inc/invalideur'); |
|
| 496 | + purger_repertoire(_DIR_SKELS); |
|
| 497 | + } |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,21 +505,21 @@ discard block |
||
| 505 | 505 | * @return string |
| 506 | 506 | */ |
| 507 | 507 | function appliquer_adresse_site($adresse_site) { |
| 508 | - if ($adresse_site !== null) { |
|
| 509 | - if (!strlen($adresse_site)) { |
|
| 510 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 511 | - $adresse_site = url_de_base(); |
|
| 512 | - } |
|
| 513 | - $adresse_site = preg_replace(',/?\s*$,', '', (string) $adresse_site); |
|
| 508 | + if ($adresse_site !== null) { |
|
| 509 | + if (!strlen($adresse_site)) { |
|
| 510 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 511 | + $adresse_site = url_de_base(); |
|
| 512 | + } |
|
| 513 | + $adresse_site = preg_replace(',/?\s*$,', '', (string) $adresse_site); |
|
| 514 | 514 | |
| 515 | - if (!tester_url_absolue($adresse_site)) { |
|
| 516 | - $adresse_site = "http://$adresse_site"; |
|
| 517 | - } |
|
| 515 | + if (!tester_url_absolue($adresse_site)) { |
|
| 516 | + $adresse_site = "http://$adresse_site"; |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - $adresse_site = entites_html($adresse_site); |
|
| 519 | + $adresse_site = entites_html($adresse_site); |
|
| 520 | 520 | |
| 521 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 522 | - } |
|
| 521 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - return $adresse_site; |
|
| 524 | + return $adresse_site; |
|
| 525 | 525 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | */ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres_boites'); |
@@ -40,25 +40,25 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function parametres_css_prive() { |
| 42 | 42 | |
| 43 | - $args = []; |
|
| 44 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | - $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 43 | + $args = []; |
|
| 44 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | + $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 50 | 50 | |
| 51 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 51 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | 52 | |
| 53 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | - parse_str((string) $couleurs($c), $c); |
|
| 55 | - $args = array_merge($args, $c); |
|
| 53 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | + parse_str((string) $couleurs($c), $c); |
|
| 55 | + $args = array_merge($args, $c); |
|
| 56 | 56 | |
| 57 | - if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | - $args['var_mode'] = 'recalcul'; |
|
| 59 | - } |
|
| 57 | + if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | + $args['var_mode'] = 'recalcul'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return http_build_query($args); |
|
| 61 | + return http_build_query($args); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -81,95 +81,95 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | function chercher_rubrique( |
| 84 | - $titre, |
|
| 85 | - $id_objet, |
|
| 86 | - $id_parent, |
|
| 87 | - $objet, |
|
| 88 | - $id_secteur, |
|
| 89 | - $restreint, |
|
| 90 | - $actionable = false, |
|
| 91 | - $retour_sans_cadre = false |
|
| 84 | + $titre, |
|
| 85 | + $id_objet, |
|
| 86 | + $id_parent, |
|
| 87 | + $objet, |
|
| 88 | + $id_secteur, |
|
| 89 | + $restreint, |
|
| 90 | + $actionable = false, |
|
| 91 | + $retour_sans_cadre = false |
|
| 92 | 92 | ) { |
| 93 | 93 | |
| 94 | - include_spip('inc/autoriser'); |
|
| 95 | - if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | - return ''; |
|
| 97 | - } |
|
| 98 | - if (!sql_countsel('spip_rubriques')) { |
|
| 99 | - return ''; |
|
| 100 | - } |
|
| 101 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | - |
|
| 104 | - if ($id_parent == 0) { |
|
| 105 | - $logo = 'racine-24.png'; |
|
| 106 | - } elseif ($id_secteur == $id_parent) { |
|
| 107 | - $logo = 'secteur-24.png'; |
|
| 108 | - } else { |
|
| 109 | - $logo = 'rubrique-24.png'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $confirm = ''; |
|
| 113 | - if ($objet == 'rubrique') { |
|
| 114 | - // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - if ( |
|
| 118 | - sql_table_exists('spip_breves') |
|
| 119 | - && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | - && $contient_breves > 0 |
|
| 121 | - ) { |
|
| 122 | - // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | - $scb = _T( |
|
| 125 | - 'avis_deplacement_rubrique', |
|
| 126 | - [ |
|
| 127 | - 'contient_breves' => $contient_breves, |
|
| 128 | - 'scb' => $scb |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | - . $scb . |
|
| 134 | - "</label></div></div>\n"; |
|
| 135 | - } else { |
|
| 136 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - $form .= $confirm; |
|
| 140 | - if ($actionable) { |
|
| 141 | - if (str_contains($form, '<select')) { |
|
| 142 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | - . '</div>'; |
|
| 145 | - } |
|
| 146 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | - $form = generer_action_auteur( |
|
| 149 | - "editer_$objet", |
|
| 150 | - $id_objet, |
|
| 151 | - self(), |
|
| 152 | - $form, |
|
| 153 | - " method='post' class='submit_plongeur'" |
|
| 154 | - ); |
|
| 155 | - } else { |
|
| 156 | - $form = generer_action_auteur( |
|
| 157 | - 'editer_objet', |
|
| 158 | - "$objet/$id_objet", |
|
| 159 | - self(), |
|
| 160 | - $form, |
|
| 161 | - " method='post' class='submit_plongeur'" |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($retour_sans_cadre) { |
|
| 167 | - return $form; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - include_spip('inc/presentation'); |
|
| 171 | - |
|
| 172 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 94 | + include_spip('inc/autoriser'); |
|
| 95 | + if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | + return ''; |
|
| 97 | + } |
|
| 98 | + if (!sql_countsel('spip_rubriques')) { |
|
| 99 | + return ''; |
|
| 100 | + } |
|
| 101 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | + |
|
| 104 | + if ($id_parent == 0) { |
|
| 105 | + $logo = 'racine-24.png'; |
|
| 106 | + } elseif ($id_secteur == $id_parent) { |
|
| 107 | + $logo = 'secteur-24.png'; |
|
| 108 | + } else { |
|
| 109 | + $logo = 'rubrique-24.png'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $confirm = ''; |
|
| 113 | + if ($objet == 'rubrique') { |
|
| 114 | + // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + if ( |
|
| 118 | + sql_table_exists('spip_breves') |
|
| 119 | + && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | + && $contient_breves > 0 |
|
| 121 | + ) { |
|
| 122 | + // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | + $scb = _T( |
|
| 125 | + 'avis_deplacement_rubrique', |
|
| 126 | + [ |
|
| 127 | + 'contient_breves' => $contient_breves, |
|
| 128 | + 'scb' => $scb |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | + . $scb . |
|
| 134 | + "</label></div></div>\n"; |
|
| 135 | + } else { |
|
| 136 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + $form .= $confirm; |
|
| 140 | + if ($actionable) { |
|
| 141 | + if (str_contains($form, '<select')) { |
|
| 142 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | + . '</div>'; |
|
| 145 | + } |
|
| 146 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | + $form = generer_action_auteur( |
|
| 149 | + "editer_$objet", |
|
| 150 | + $id_objet, |
|
| 151 | + self(), |
|
| 152 | + $form, |
|
| 153 | + " method='post' class='submit_plongeur'" |
|
| 154 | + ); |
|
| 155 | + } else { |
|
| 156 | + $form = generer_action_auteur( |
|
| 157 | + 'editer_objet', |
|
| 158 | + "$objet/$id_objet", |
|
| 159 | + self(), |
|
| 160 | + $form, |
|
| 161 | + " method='post' class='submit_plongeur'" |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($retour_sans_cadre) { |
|
| 167 | + return $form; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + include_spip('inc/presentation'); |
|
| 171 | + |
|
| 172 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -183,24 +183,24 @@ discard block |
||
| 183 | 183 | * @return bool |
| 184 | 184 | */ |
| 185 | 185 | function avoir_visiteurs($past = false, $accepter = true) { |
| 186 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!$past) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return sql_countsel( |
|
| 200 | - 'spip_auteurs', |
|
| 201 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 186 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!$past) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return sql_countsel( |
|
| 200 | + 'spip_auteurs', |
|
| 201 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 202 | 202 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 203 | - ); |
|
| 203 | + ); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | 218 | function statuts_articles_visibles($statut_auteur) { |
| 219 | - static $auth = []; |
|
| 220 | - if (!isset($auth[$statut_auteur])) { |
|
| 221 | - $auth[$statut_auteur] = []; |
|
| 222 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | - foreach ($statuts as $s) { |
|
| 224 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | - $auth[$statut_auteur][] = $s; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $auth[$statut_auteur]; |
|
| 219 | + static $auth = []; |
|
| 220 | + if (!isset($auth[$statut_auteur])) { |
|
| 221 | + $auth[$statut_auteur] = []; |
|
| 222 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | + foreach ($statuts as $s) { |
|
| 224 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | + $auth[$statut_auteur][] = $s; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $auth[$statut_auteur]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -241,38 +241,38 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function traduire_statut_auteur($statut, $attente = '') { |
| 244 | - $plus = ''; |
|
| 245 | - if ($statut == 'nouveau') { |
|
| 246 | - if ($attente) { |
|
| 247 | - $statut = $attente; |
|
| 248 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | - } else { |
|
| 250 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $recom = [ |
|
| 255 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | - ]; |
|
| 260 | - if (isset($recom[$statut])) { |
|
| 261 | - return $recom[$statut] . $plus; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // retrouver directement par le statut sinon |
|
| 265 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | - if (isset($recom[$t])) { |
|
| 267 | - return $recom[$t] . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return _T($t) . $plus; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | - // c'est toujours plus informatif que rien du tout |
|
| 275 | - return $statut; |
|
| 244 | + $plus = ''; |
|
| 245 | + if ($statut == 'nouveau') { |
|
| 246 | + if ($attente) { |
|
| 247 | + $statut = $attente; |
|
| 248 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | + } else { |
|
| 250 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $recom = [ |
|
| 255 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | + ]; |
|
| 260 | + if (isset($recom[$statut])) { |
|
| 261 | + return $recom[$statut] . $plus; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // retrouver directement par le statut sinon |
|
| 265 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | + if (isset($recom[$t])) { |
|
| 267 | + return $recom[$t] . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return _T($t) . $plus; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | + // c'est toujours plus informatif que rien du tout |
|
| 275 | + return $statut; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -283,29 +283,29 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | function afficher_qui_edite($id_objet, $objet): string { |
| 286 | - static $qui = []; |
|
| 287 | - if (isset($qui[$objet][$id_objet])) { |
|
| 288 | - return $qui[$objet][$id_objet]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - include_spip('inc/config'); |
|
| 292 | - if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | - return $qui[$objet][$id_objet] = ''; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - include_spip('inc/drapeau_edition'); |
|
| 297 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | - if (!$modif) { |
|
| 299 | - return $qui[$objet][$id_objet] = ''; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - include_spip('base/objets'); |
|
| 303 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | - if (isset($infos['texte_signale_edition'])) { |
|
| 305 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 286 | + static $qui = []; |
|
| 287 | + if (isset($qui[$objet][$id_objet])) { |
|
| 288 | + return $qui[$objet][$id_objet]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + include_spip('inc/config'); |
|
| 292 | + if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | + return $qui[$objet][$id_objet] = ''; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + include_spip('inc/drapeau_edition'); |
|
| 297 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | + if (!$modif) { |
|
| 299 | + return $qui[$objet][$id_objet] = ''; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + include_spip('base/objets'); |
|
| 303 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | + if (isset($infos['texte_signale_edition'])) { |
|
| 305 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -323,53 +323,53 @@ discard block |
||
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | 325 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array { |
| 326 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - switch ($quoi) { |
|
| 331 | - case 'redacteurs': |
|
| 332 | - $statut = AUTEURS_MIN_REDAC; |
|
| 333 | - $statut = explode(',', (string) $statut); |
|
| 334 | - if ($en_base) { |
|
| 335 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | - $retire = array_diff($statut, $check); |
|
| 337 | - $statut = array_diff($statut, $retire); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return array_unique($statut); |
|
| 341 | - |
|
| 342 | - case 'visiteurs': |
|
| 343 | - $statut = []; |
|
| 344 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | - $exclus = explode(',', (string) $exclus); |
|
| 346 | - if (!$en_base) { |
|
| 347 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | - } |
|
| 350 | - $s_complement = array_column( |
|
| 351 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | - 'statut' |
|
| 353 | - ); |
|
| 354 | - |
|
| 355 | - return array_unique([...$statut, ...$s_complement]); |
|
| 356 | - |
|
| 357 | - default: |
|
| 358 | - case 'tous': |
|
| 359 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | - $s_complement = array_column( |
|
| 361 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | - 'statut' |
|
| 363 | - ); |
|
| 364 | - $statut = [...$statut, ...$s_complement]; |
|
| 365 | - if ($en_base) { |
|
| 366 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | - $retire = array_diff($statut, $check); |
|
| 368 | - $statut = array_diff($statut, $retire); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return array_unique($statut); |
|
| 372 | - } |
|
| 326 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + switch ($quoi) { |
|
| 331 | + case 'redacteurs': |
|
| 332 | + $statut = AUTEURS_MIN_REDAC; |
|
| 333 | + $statut = explode(',', (string) $statut); |
|
| 334 | + if ($en_base) { |
|
| 335 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | + $retire = array_diff($statut, $check); |
|
| 337 | + $statut = array_diff($statut, $retire); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return array_unique($statut); |
|
| 341 | + |
|
| 342 | + case 'visiteurs': |
|
| 343 | + $statut = []; |
|
| 344 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | + $exclus = explode(',', (string) $exclus); |
|
| 346 | + if (!$en_base) { |
|
| 347 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | + } |
|
| 350 | + $s_complement = array_column( |
|
| 351 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | + 'statut' |
|
| 353 | + ); |
|
| 354 | + |
|
| 355 | + return array_unique([...$statut, ...$s_complement]); |
|
| 356 | + |
|
| 357 | + default: |
|
| 358 | + case 'tous': |
|
| 359 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | + $s_complement = array_column( |
|
| 361 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | + 'statut' |
|
| 363 | + ); |
|
| 364 | + $statut = [...$statut, ...$s_complement]; |
|
| 365 | + if ($en_base) { |
|
| 366 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | + $retire = array_diff($statut, $check); |
|
| 368 | + $statut = array_diff($statut, $retire); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return array_unique($statut); |
|
| 372 | + } |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | - : ''; |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | + : ''; |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - return propre('[->' . $virtuel . ']'); |
|
| 425 | + return propre('[->' . $virtuel . ']'); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | * @filtre |
| 446 | 446 | */ |
| 447 | 447 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 448 | - include_spip('inc/acces'); |
|
| 449 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 448 | + include_spip('inc/acces'); |
|
| 449 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 450 | 450 | |
| 451 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 451 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | |
@@ -461,72 +461,72 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | function alertes_auteur($id_auteur): string { |
| 463 | 463 | |
| 464 | - $alertes = []; |
|
| 465 | - |
|
| 466 | - if ( |
|
| 467 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | - && autoriser('detruire', null, null, $id_auteur) |
|
| 469 | - ) { |
|
| 470 | - include_spip('genie/maintenance'); |
|
| 471 | - if ($msg = message_crash_tables()) { |
|
| 472 | - $alertes[] = $msg; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if ( |
|
| 477 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | - && $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | - && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | - ) { |
|
| 482 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | - if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 488 | - $update = false; |
|
| 489 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 490 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 491 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 492 | - $update = true; |
|
| 493 | - } |
|
| 494 | - if (isset($a[''])) { |
|
| 495 | - $alertes = array_merge($alertes, $a['']); |
|
| 496 | - unset($a['']); |
|
| 497 | - $update = true; |
|
| 498 | - } |
|
| 499 | - if ($update) { |
|
| 500 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - if ( |
|
| 505 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 506 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 507 | - ) { |
|
| 508 | - include_spip('inc/plugin'); |
|
| 509 | - $alertes[] = plugin_donne_erreurs(); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $alertes = pipeline( |
|
| 513 | - 'alertes_auteur', |
|
| 514 | - [ |
|
| 515 | - 'args' => [ |
|
| 516 | - 'id_auteur' => $id_auteur, |
|
| 517 | - 'exec' => _request('exec'), |
|
| 518 | - ], |
|
| 519 | - 'data' => $alertes |
|
| 520 | - ] |
|
| 521 | - ); |
|
| 522 | - |
|
| 523 | - if ($alertes = array_filter($alertes)) { |
|
| 524 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 525 | - implode(' | ', $alertes) |
|
| 526 | - . '</div></div>'; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return ''; |
|
| 464 | + $alertes = []; |
|
| 465 | + |
|
| 466 | + if ( |
|
| 467 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | + && autoriser('detruire', null, null, $id_auteur) |
|
| 469 | + ) { |
|
| 470 | + include_spip('genie/maintenance'); |
|
| 471 | + if ($msg = message_crash_tables()) { |
|
| 472 | + $alertes[] = $msg; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if ( |
|
| 477 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | + && $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | + && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | + ) { |
|
| 482 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | + if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 488 | + $update = false; |
|
| 489 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 490 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 491 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 492 | + $update = true; |
|
| 493 | + } |
|
| 494 | + if (isset($a[''])) { |
|
| 495 | + $alertes = array_merge($alertes, $a['']); |
|
| 496 | + unset($a['']); |
|
| 497 | + $update = true; |
|
| 498 | + } |
|
| 499 | + if ($update) { |
|
| 500 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if ( |
|
| 505 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 506 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 507 | + ) { |
|
| 508 | + include_spip('inc/plugin'); |
|
| 509 | + $alertes[] = plugin_donne_erreurs(); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $alertes = pipeline( |
|
| 513 | + 'alertes_auteur', |
|
| 514 | + [ |
|
| 515 | + 'args' => [ |
|
| 516 | + 'id_auteur' => $id_auteur, |
|
| 517 | + 'exec' => _request('exec'), |
|
| 518 | + ], |
|
| 519 | + 'data' => $alertes |
|
| 520 | + ] |
|
| 521 | + ); |
|
| 522 | + |
|
| 523 | + if ($alertes = array_filter($alertes)) { |
|
| 524 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 525 | + implode(' | ', $alertes) |
|
| 526 | + . '</div></div>'; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return ''; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -536,9 +536,9 @@ discard block |
||
| 536 | 536 | * @return string |
| 537 | 537 | */ |
| 538 | 538 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 539 | - include_spip('inc/presenter_enfants'); |
|
| 539 | + include_spip('inc/presenter_enfants'); |
|
| 540 | 540 | |
| 541 | - return afficher_enfant_rub((int) $id_rubrique); |
|
| 541 | + return afficher_enfant_rub((int) $id_rubrique); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -556,15 +556,15 @@ discard block |
||
| 556 | 556 | * @return string |
| 557 | 557 | */ |
| 558 | 558 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 559 | - $titre = attribut_html($titre); |
|
| 560 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 561 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 562 | - |
|
| 563 | - if (!$titre_lien) { |
|
| 564 | - return $icone; |
|
| 565 | - } else { |
|
| 566 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 567 | - } |
|
| 559 | + $titre = attribut_html($titre); |
|
| 560 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 561 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 562 | + |
|
| 563 | + if (!$titre_lien) { |
|
| 564 | + return $icone; |
|
| 565 | + } else { |
|
| 566 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 567 | + } |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -583,20 +583,20 @@ discard block |
||
| 583 | 583 | * @return array |
| 584 | 584 | */ |
| 585 | 585 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 586 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 587 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 588 | - return []; |
|
| 589 | - } |
|
| 590 | - $r = reset($res); |
|
| 591 | - $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 592 | - if (isset($r['rang_lien'])) { |
|
| 593 | - $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 594 | - asort($l); |
|
| 595 | - $l = array_keys($l); |
|
| 596 | - } else { |
|
| 597 | - // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 598 | - // Sinon c'est dans "id_objet" |
|
| 599 | - $l = array_column($res, $colonne_id); |
|
| 600 | - } |
|
| 601 | - return $l; |
|
| 586 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 587 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 588 | + return []; |
|
| 589 | + } |
|
| 590 | + $r = reset($res); |
|
| 591 | + $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 592 | + if (isset($r['rang_lien'])) { |
|
| 593 | + $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 594 | + asort($l); |
|
| 595 | + $l = array_keys($l); |
|
| 596 | + } else { |
|
| 597 | + // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 598 | + // Sinon c'est dans "id_objet" |
|
| 599 | + $l = array_column($res, $colonne_id); |
|
| 600 | + } |
|
| 601 | + return $l; |
|
| 602 | 602 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 43 | 43 | */ |
| 44 | 44 | function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 45 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 45 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | 46 | |
| 47 | - return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 47 | + return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * Code HTML du formulaire |
| 78 | 78 | */ |
| 79 | 79 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 80 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 80 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 81 | 81 | |
| 82 | - return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 82 | + return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 105 | 105 | */ |
| 106 | 106 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
| 107 | - $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 107 | + $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 108 | 108 | |
| 109 | - return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 109 | + return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -123,26 +123,26 @@ discard block |
||
| 123 | 123 | * passer "text/html" comme $content_type |
| 124 | 124 | */ |
| 125 | 125 | function ajax_retour($corps, $content_type = null): void { |
| 126 | - $xml = false; |
|
| 127 | - if (is_null($content_type) || $content_type === true) { |
|
| 128 | - $xml = true; |
|
| 129 | - $content_type = 'text/html'; |
|
| 130 | - } elseif (!$content_type || !is_string($content_type) || !str_contains($content_type, '/')) { |
|
| 131 | - $content_type = 'text/html'; |
|
| 132 | - } |
|
| 126 | + $xml = false; |
|
| 127 | + if (is_null($content_type) || $content_type === true) { |
|
| 128 | + $xml = true; |
|
| 129 | + $content_type = 'text/html'; |
|
| 130 | + } elseif (!$content_type || !is_string($content_type) || !str_contains($content_type, '/')) { |
|
| 131 | + $content_type = 'text/html'; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - $e = ''; |
|
| 135 | - if ( |
|
| 136 | - isset($_COOKIE['spip_admin']) |
|
| 137 | - && (_request('var_mode') == 'debug' || !empty($GLOBALS['tableau_des_temps'])) |
|
| 138 | - ) { |
|
| 139 | - $e = erreur_squelette(); |
|
| 140 | - } |
|
| 134 | + $e = ''; |
|
| 135 | + if ( |
|
| 136 | + isset($_COOKIE['spip_admin']) |
|
| 137 | + && (_request('var_mode') == 'debug' || !empty($GLOBALS['tableau_des_temps'])) |
|
| 138 | + ) { |
|
| 139 | + $e = erreur_squelette(); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - $c = $GLOBALS['meta']['charset']; |
|
| 143 | - header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 144 | - $debut = (($xml && strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 145 | - $fin = ''; |
|
| 142 | + $c = $GLOBALS['meta']['charset']; |
|
| 143 | + header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 144 | + $debut = (($xml && strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 145 | + $fin = ''; |
|
| 146 | 146 | |
| 147 | - echo $debut, $corps, $fin, $e; |
|
| 147 | + echo $debut, $corps, $fin, $e; |
|
| 148 | 148 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * Code HTML du formulaire |
| 78 | 78 | */ |
| 79 | 79 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 80 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 80 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT).generer_url_ecrire($ret, $gra, true, true); |
|
| 81 | 81 | |
| 82 | 82 | return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
| 83 | 83 | } |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 105 | 105 | */ |
| 106 | 106 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
| 107 | - $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 107 | + $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true); |
|
| 108 | 108 | |
| 109 | - return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 109 | + return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'"); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $c = $GLOBALS['meta']['charset']; |
| 143 | - header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 144 | - $debut = (($xml && strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 143 | + header('Content-Type: '.$content_type.'; charset='.$c); |
|
| 144 | + $debut = (($xml && strlen(trim($corps))) ? '<'."?xml version='1.0' encoding='".$c."'?".">\n" : ''); |
|
| 145 | 145 | $fin = ''; |
| 146 | 146 | |
| 147 | 147 | echo $debut, $corps, $fin, $e; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 37 | 37 | **/ |
| 38 | 38 | function extraire_date($texte): string { |
| 39 | - // format = 2001-08 |
|
| 40 | - if (preg_match(',([1-2]\d{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | - } |
|
| 43 | - return ''; |
|
| 39 | + // format = 2001-08 |
|
| 40 | + if (preg_match(',([1-2]\d{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + } |
|
| 43 | + return ''; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -62,29 +62,29 @@ discard block |
||
| 62 | 62 | * - une chaîne vide si la date est considérée nulle |
| 63 | 63 | **/ |
| 64 | 64 | function normaliser_date($date, $forcer_jour = false): string { |
| 65 | - $date = vider_date($date); |
|
| 66 | - if ($date) { |
|
| 67 | - if (preg_match('/^\d{8,10}$/', $date)) { |
|
| 68 | - $date = date('Y-m-d H:i:s', $date); |
|
| 69 | - } |
|
| 70 | - if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | - } else { |
|
| 74 | - if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | - $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3]; |
|
| 77 | - } else { |
|
| 78 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ($forcer_jour) { |
|
| 83 | - $date = str_replace('-00', '-01', $date); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $date; |
|
| 65 | + $date = vider_date($date); |
|
| 66 | + if ($date) { |
|
| 67 | + if (preg_match('/^\d{8,10}$/', $date)) { |
|
| 68 | + $date = date('Y-m-d H:i:s', $date); |
|
| 69 | + } |
|
| 70 | + if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + } else { |
|
| 74 | + if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | + $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + } else { |
|
| 78 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ($forcer_jour) { |
|
| 83 | + $date = str_replace('-00', '-01', $date); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $date; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,22 +97,22 @@ discard block |
||
| 97 | 97 | * - Une chaine vide |
| 98 | 98 | **/ |
| 99 | 99 | function vider_date($letexte, $verif_format_date = false): string { |
| 100 | - $letexte ??= ''; |
|
| 101 | - if ( |
|
| 102 | - !$verif_format_date |
|
| 103 | - || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte) |
|
| 104 | - ) { |
|
| 105 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 106 | - return ''; |
|
| 107 | - } |
|
| 108 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 109 | - return ''; |
|
| 110 | - } |
|
| 111 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 112 | - return ''; |
|
| 113 | - } // eviter le bug GMT-1 |
|
| 114 | - } |
|
| 115 | - return $letexte; |
|
| 100 | + $letexte ??= ''; |
|
| 101 | + if ( |
|
| 102 | + !$verif_format_date |
|
| 103 | + || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte) |
|
| 104 | + ) { |
|
| 105 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 106 | + return ''; |
|
| 107 | + } |
|
| 108 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 109 | + return ''; |
|
| 110 | + } |
|
| 111 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 112 | + return ''; |
|
| 113 | + } // eviter le bug GMT-1 |
|
| 114 | + } |
|
| 115 | + return $letexte; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | **/ |
| 129 | 129 | function recup_heure($date): array { |
| 130 | 130 | |
| 131 | - if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) { |
|
| 132 | - array_shift($elements); |
|
| 133 | - if (!isset($elements[2])) { |
|
| 134 | - $elements[2] = 0; |
|
| 135 | - } |
|
| 136 | - $heure = $elements; |
|
| 137 | - } else { |
|
| 138 | - $heure = [0, 0, 0]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $heure; |
|
| 131 | + if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) { |
|
| 132 | + array_shift($elements); |
|
| 133 | + if (!isset($elements[2])) { |
|
| 134 | + $elements[2] = 0; |
|
| 135 | + } |
|
| 136 | + $heure = $elements; |
|
| 137 | + } else { |
|
| 138 | + $heure = [0, 0, 0]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $heure; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | * @return string heures, sinon 0 |
| 153 | 153 | **/ |
| 154 | 154 | function heures($numdate): string { |
| 155 | - $heures = null; |
|
| 156 | - $date_array = recup_heure($numdate); |
|
| 157 | - if ($date_array) { |
|
| 158 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 159 | - } |
|
| 155 | + $heures = null; |
|
| 156 | + $date_array = recup_heure($numdate); |
|
| 157 | + if ($date_array) { |
|
| 158 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $heures; |
|
| 161 | + return $heures; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | * @return string minutes, sinon 0 |
| 173 | 173 | **/ |
| 174 | 174 | function minutes($numdate): string { |
| 175 | - $minutes = null; |
|
| 176 | - $date_array = recup_heure($numdate); |
|
| 177 | - if ($date_array) { |
|
| 178 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 179 | - } |
|
| 175 | + $minutes = null; |
|
| 176 | + $date_array = recup_heure($numdate); |
|
| 177 | + if ($date_array) { |
|
| 178 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - return $minutes; |
|
| 181 | + return $minutes; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | * @return string secondes, sinon 0 |
| 193 | 193 | **/ |
| 194 | 194 | function secondes($numdate): string { |
| 195 | - $secondes = null; |
|
| 196 | - $date_array = recup_heure($numdate); |
|
| 197 | - if ($date_array) { |
|
| 198 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 199 | - } |
|
| 195 | + $secondes = null; |
|
| 196 | + $date_array = recup_heure($numdate); |
|
| 197 | + if ($date_array) { |
|
| 198 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return $secondes; |
|
| 201 | + return $secondes; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | * @return string L'heure formatée dans la langue en cours. |
| 218 | 218 | **/ |
| 219 | 219 | function heures_minutes($numdate, $forme = ''): string { |
| 220 | - if ($forme !== 'abbr') { |
|
| 221 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 222 | - } else { |
|
| 223 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | - } |
|
| 220 | + if ($forme !== 'abbr') { |
|
| 221 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 222 | + } else { |
|
| 223 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -246,57 +246,57 @@ discard block |
||
| 246 | 246 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 247 | 247 | **/ |
| 248 | 248 | function recup_date($numdate, $forcer_jour = true): array { |
| 249 | - if (!$numdate) { |
|
| 250 | - return []; |
|
| 251 | - } |
|
| 252 | - $heures = $minutes = $secondes = 0; |
|
| 253 | - if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) { |
|
| 254 | - $jour = $regs[1]; |
|
| 255 | - $mois = $regs[2]; |
|
| 256 | - $annee = $regs[3]; |
|
| 257 | - if ($annee < 90) { |
|
| 258 | - $annee = 2000 + $annee; |
|
| 259 | - } elseif ($annee < 100) { |
|
| 260 | - $annee = 1900 + $annee; |
|
| 261 | - } |
|
| 262 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 263 | - } elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) { |
|
| 264 | - $annee = $regs[1]; |
|
| 265 | - $mois = $regs[2]; |
|
| 266 | - $jour = $regs[3]; |
|
| 267 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 268 | - } elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) { |
|
| 269 | - $annee = $regs[1]; |
|
| 270 | - $mois = $regs[2]; |
|
| 271 | - $jour = ''; |
|
| 272 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 273 | - } elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) { |
|
| 274 | - $annee = $regs[1]; |
|
| 275 | - $mois = $regs[2]; |
|
| 276 | - $jour = $regs[3]; |
|
| 277 | - $heures = $regs[4]; |
|
| 278 | - $minutes = $regs[5]; |
|
| 279 | - $secondes = $regs[6]; |
|
| 280 | - } else { |
|
| 281 | - $annee = $mois = $jour = ''; |
|
| 282 | - } |
|
| 283 | - if ($annee > 4000) { |
|
| 284 | - $annee -= 9000; |
|
| 285 | - } |
|
| 286 | - if (strlen($jour) && str_starts_with($jour, '0')) { |
|
| 287 | - $jour = substr($jour, 1); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - if ($forcer_jour && $jour == '0') { |
|
| 291 | - $jour = '1'; |
|
| 292 | - } |
|
| 293 | - if ($forcer_jour && $mois == '0') { |
|
| 294 | - $mois = '1'; |
|
| 295 | - } |
|
| 296 | - if ($annee || $mois || $jour || $heures || $minutes || $secondes) { |
|
| 297 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 298 | - } |
|
| 299 | - return []; |
|
| 249 | + if (!$numdate) { |
|
| 250 | + return []; |
|
| 251 | + } |
|
| 252 | + $heures = $minutes = $secondes = 0; |
|
| 253 | + if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) { |
|
| 254 | + $jour = $regs[1]; |
|
| 255 | + $mois = $regs[2]; |
|
| 256 | + $annee = $regs[3]; |
|
| 257 | + if ($annee < 90) { |
|
| 258 | + $annee = 2000 + $annee; |
|
| 259 | + } elseif ($annee < 100) { |
|
| 260 | + $annee = 1900 + $annee; |
|
| 261 | + } |
|
| 262 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 263 | + } elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) { |
|
| 264 | + $annee = $regs[1]; |
|
| 265 | + $mois = $regs[2]; |
|
| 266 | + $jour = $regs[3]; |
|
| 267 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 268 | + } elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) { |
|
| 269 | + $annee = $regs[1]; |
|
| 270 | + $mois = $regs[2]; |
|
| 271 | + $jour = ''; |
|
| 272 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 273 | + } elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) { |
|
| 274 | + $annee = $regs[1]; |
|
| 275 | + $mois = $regs[2]; |
|
| 276 | + $jour = $regs[3]; |
|
| 277 | + $heures = $regs[4]; |
|
| 278 | + $minutes = $regs[5]; |
|
| 279 | + $secondes = $regs[6]; |
|
| 280 | + } else { |
|
| 281 | + $annee = $mois = $jour = ''; |
|
| 282 | + } |
|
| 283 | + if ($annee > 4000) { |
|
| 284 | + $annee -= 9000; |
|
| 285 | + } |
|
| 286 | + if (strlen($jour) && str_starts_with($jour, '0')) { |
|
| 287 | + $jour = substr($jour, 1); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + if ($forcer_jour && $jour == '0') { |
|
| 291 | + $jour = '1'; |
|
| 292 | + } |
|
| 293 | + if ($forcer_jour && $mois == '0') { |
|
| 294 | + $mois = '1'; |
|
| 295 | + } |
|
| 296 | + if ($annee || $mois || $jour || $heures || $minutes || $secondes) { |
|
| 297 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 298 | + } |
|
| 299 | + return []; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -323,10 +323,10 @@ discard block |
||
| 323 | 323 | * La date relative ou complète |
| 324 | 324 | **/ |
| 325 | 325 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 326 | - return sinon( |
|
| 327 | - date_relative($date, $decalage_maxi), |
|
| 328 | - affdate_heure($date) |
|
| 329 | - ); |
|
| 326 | + return sinon( |
|
| 327 | + date_relative($date, $decalage_maxi), |
|
| 328 | + affdate_heure($date) |
|
| 329 | + ); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -359,72 +359,72 @@ discard block |
||
| 359 | 359 | **/ |
| 360 | 360 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 361 | 361 | |
| 362 | - if (!$date) { |
|
| 363 | - return ''; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $ref_time = is_null($ref_date) ? time() : strtotime($ref_date); |
|
| 367 | - |
|
| 368 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 369 | - |
|
| 370 | - if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) { |
|
| 371 | - return ''; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ($decal < 0) { |
|
| 375 | - $il_y_a = 'date_dans'; |
|
| 376 | - $decal = -1 * $decal; |
|
| 377 | - } else { |
|
| 378 | - $il_y_a = 'date_il_y_a'; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 382 | - return affdate_court($date); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - if ($decal > 3600 * 24 * 30) { |
|
| 386 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 387 | - $delai = $mois < 2 |
|
| 388 | - ? "$mois " . _T('date_un_mois') |
|
| 389 | - : "$mois " . _T('date_mois'); |
|
| 390 | - } else { |
|
| 391 | - if ($decal > 3600 * 24 * 7) { |
|
| 392 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 393 | - $delai = $semaines < 2 |
|
| 394 | - ? "$semaines " . _T('date_une_semaine') |
|
| 395 | - : "$semaines " . _T('date_semaines'); |
|
| 396 | - } else { |
|
| 397 | - if ($decal > 3600 * 24) { |
|
| 398 | - $jours = floor($decal / (3600 * 24)); |
|
| 399 | - if ($jours < 2) { |
|
| 400 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 401 | - } else { |
|
| 402 | - $delai = "$jours " . _T('date_jours'); |
|
| 403 | - } |
|
| 404 | - } else { |
|
| 405 | - if ($decal >= 3600) { |
|
| 406 | - $heures = floor($decal / 3600); |
|
| 407 | - $delai = $heures < 2 |
|
| 408 | - ? "$heures " . _T('date_une_heure') |
|
| 409 | - : "$heures " . _T('date_heures'); |
|
| 410 | - } else { |
|
| 411 | - if ($decal >= 60) { |
|
| 412 | - $minutes = floor($decal / 60); |
|
| 413 | - $delai = $minutes < 2 |
|
| 414 | - ? "$minutes " . _T('date_une_minute') |
|
| 415 | - : "$minutes " . _T('date_minutes'); |
|
| 416 | - } else { |
|
| 417 | - $secondes = ceil($decal); |
|
| 418 | - $delai = $secondes < 2 |
|
| 419 | - ? "$secondes " . _T('date_une_seconde') |
|
| 420 | - : "$secondes " . _T('date_secondes'); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 362 | + if (!$date) { |
|
| 363 | + return ''; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $ref_time = is_null($ref_date) ? time() : strtotime($ref_date); |
|
| 367 | + |
|
| 368 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 369 | + |
|
| 370 | + if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) { |
|
| 371 | + return ''; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ($decal < 0) { |
|
| 375 | + $il_y_a = 'date_dans'; |
|
| 376 | + $decal = -1 * $decal; |
|
| 377 | + } else { |
|
| 378 | + $il_y_a = 'date_il_y_a'; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 382 | + return affdate_court($date); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + if ($decal > 3600 * 24 * 30) { |
|
| 386 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 387 | + $delai = $mois < 2 |
|
| 388 | + ? "$mois " . _T('date_un_mois') |
|
| 389 | + : "$mois " . _T('date_mois'); |
|
| 390 | + } else { |
|
| 391 | + if ($decal > 3600 * 24 * 7) { |
|
| 392 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 393 | + $delai = $semaines < 2 |
|
| 394 | + ? "$semaines " . _T('date_une_semaine') |
|
| 395 | + : "$semaines " . _T('date_semaines'); |
|
| 396 | + } else { |
|
| 397 | + if ($decal > 3600 * 24) { |
|
| 398 | + $jours = floor($decal / (3600 * 24)); |
|
| 399 | + if ($jours < 2) { |
|
| 400 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 401 | + } else { |
|
| 402 | + $delai = "$jours " . _T('date_jours'); |
|
| 403 | + } |
|
| 404 | + } else { |
|
| 405 | + if ($decal >= 3600) { |
|
| 406 | + $heures = floor($decal / 3600); |
|
| 407 | + $delai = $heures < 2 |
|
| 408 | + ? "$heures " . _T('date_une_heure') |
|
| 409 | + : "$heures " . _T('date_heures'); |
|
| 410 | + } else { |
|
| 411 | + if ($decal >= 60) { |
|
| 412 | + $minutes = floor($decal / 60); |
|
| 413 | + $delai = $minutes < 2 |
|
| 414 | + ? "$minutes " . _T('date_une_minute') |
|
| 415 | + : "$minutes " . _T('date_minutes'); |
|
| 416 | + } else { |
|
| 417 | + $secondes = ceil($decal); |
|
| 418 | + $delai = $secondes < 2 |
|
| 419 | + ? "$secondes " . _T('date_une_seconde') |
|
| 420 | + : "$secondes " . _T('date_secondes'); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | |
@@ -450,30 +450,30 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 452 | 452 | |
| 453 | - if (!$date) { |
|
| 454 | - return ''; |
|
| 455 | - } |
|
| 456 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 457 | - |
|
| 458 | - if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) { |
|
| 459 | - return ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - if ($decal < -24 * 3600) { |
|
| 463 | - $retour = date_relative($date, $decalage_maxi); |
|
| 464 | - } elseif ($decal < 0) { |
|
| 465 | - $retour = _T('date_demain'); |
|
| 466 | - } else { |
|
| 467 | - if ($decal < (3600 * 24)) { |
|
| 468 | - $retour = _T('date_aujourdhui'); |
|
| 469 | - } else { |
|
| 470 | - $retour = $decal < (3600 * 24 * 2) |
|
| 471 | - ? _T('date_hier') |
|
| 472 | - : date_relative($date, $decalage_maxi); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - return $retour; |
|
| 453 | + if (!$date) { |
|
| 454 | + return ''; |
|
| 455 | + } |
|
| 456 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 457 | + |
|
| 458 | + if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) { |
|
| 459 | + return ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if ($decal < -24 * 3600) { |
|
| 463 | + $retour = date_relative($date, $decalage_maxi); |
|
| 464 | + } elseif ($decal < 0) { |
|
| 465 | + $retour = _T('date_demain'); |
|
| 466 | + } else { |
|
| 467 | + if ($decal < (3600 * 24)) { |
|
| 468 | + $retour = _T('date_aujourdhui'); |
|
| 469 | + } else { |
|
| 470 | + $retour = $decal < (3600 * 24 * 2) |
|
| 471 | + ? _T('date_hier') |
|
| 472 | + : date_relative($date, $decalage_maxi); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + return $retour; |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -490,173 +490,173 @@ discard block |
||
| 490 | 490 | * @return string |
| 491 | 491 | */ |
| 492 | 492 | function affdate_base($numdate, $vue, $options = []): string { |
| 493 | - if (is_string($options)) { |
|
| 494 | - $options = ['param' => $options]; |
|
| 495 | - } |
|
| 496 | - $date_array = recup_date($numdate, false); |
|
| 497 | - if (!$date_array) { |
|
| 498 | - return ''; |
|
| 499 | - } |
|
| 500 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 501 | - |
|
| 502 | - // 1er, 21st, etc. |
|
| 503 | - $journum = $jour; |
|
| 504 | - |
|
| 505 | - if ($jour == 0) { |
|
| 506 | - $jour = ''; |
|
| 507 | - $njour = 0; |
|
| 508 | - } else { |
|
| 509 | - $njour = (int) $jour; |
|
| 510 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 511 | - $jour = $jourth; |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - $mois = (int) $mois; |
|
| 516 | - if ($mois > 0 && $mois < 13) { |
|
| 517 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 518 | - $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 519 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 520 | - $jourmois = $jour |
|
| 521 | - ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]) |
|
| 522 | - : $nommois; |
|
| 523 | - } else { |
|
| 524 | - $nommois = ''; |
|
| 525 | - $jourmois = ''; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - if ($annee < 0) { |
|
| 529 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 530 | - $avjc = true; |
|
| 531 | - } else { |
|
| 532 | - $avjc = false; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - switch ($vue) { |
|
| 536 | - case 'saison': |
|
| 537 | - case 'saison_annee': |
|
| 538 | - $saison = ''; |
|
| 539 | - if ($mois > 0) { |
|
| 540 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 541 | - if ($mois == 3 && $jour >= 21 || $mois > 3) { |
|
| 542 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 543 | - } |
|
| 544 | - if ($mois == 6 && $jour >= 21 || $mois > 6) { |
|
| 545 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 546 | - } |
|
| 547 | - if ($mois == 9 && $jour >= 21 || $mois > 9) { |
|
| 548 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 549 | - } |
|
| 550 | - if ($mois == 12 && $jour >= 21 || $mois > 12) { |
|
| 551 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - if ($vue == 'saison') { |
|
| 555 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 556 | - } else { |
|
| 557 | - return $saison ? trim((string) _T( |
|
| 558 | - 'date_fmt_saison_annee', |
|
| 559 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 560 | - )) : ''; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - case 'court': |
|
| 564 | - if ($avjc) { |
|
| 565 | - return $annee; |
|
| 566 | - } |
|
| 567 | - $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 568 | - if ($annee < ($a - 100) || $annee > ($a + 100)) { |
|
| 569 | - return $annee; |
|
| 570 | - } |
|
| 571 | - if ($annee != $a) { |
|
| 572 | - return _T( |
|
| 573 | - 'date_fmt_mois_annee', |
|
| 574 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 575 | - ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - return _T( |
|
| 579 | - 'date_fmt_jour_mois', |
|
| 580 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 581 | - ); |
|
| 582 | - |
|
| 583 | - case 'jourcourt': |
|
| 584 | - if ($avjc) { |
|
| 585 | - return $annee; |
|
| 586 | - } |
|
| 587 | - $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | - if ($annee < ($a - 100) || $annee > ($a + 100)) { |
|
| 589 | - return $annee; |
|
| 590 | - } |
|
| 591 | - if ($annee != $a) { |
|
| 592 | - return _T( |
|
| 593 | - 'date_fmt_jour_mois_annee', |
|
| 594 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return _T( |
|
| 599 | - 'date_fmt_jour_mois', |
|
| 600 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | - ); |
|
| 602 | - |
|
| 603 | - case 'entier': |
|
| 604 | - if ($avjc) { |
|
| 605 | - return $annee; |
|
| 606 | - } |
|
| 607 | - if ($jour) { |
|
| 608 | - return _T( |
|
| 609 | - 'date_fmt_jour_mois_annee', |
|
| 610 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 611 | - ); |
|
| 612 | - } elseif ($mois) { |
|
| 613 | - return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 614 | - } else { |
|
| 615 | - return $annee; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - case 'nom_mois': |
|
| 619 | - return $nommois; |
|
| 620 | - |
|
| 621 | - case 'mois': |
|
| 622 | - return sprintf('%02s', $mois); |
|
| 623 | - |
|
| 624 | - case 'jour': |
|
| 625 | - return $jour; |
|
| 626 | - |
|
| 627 | - case 'journum': |
|
| 628 | - return $journum; |
|
| 629 | - |
|
| 630 | - case 'nom_jour': |
|
| 631 | - if (!$mois || !$njour) { |
|
| 632 | - return ''; |
|
| 633 | - } |
|
| 634 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 635 | - $nom = 1 + (int) date('w', $nom); |
|
| 636 | - $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : ''); |
|
| 637 | - |
|
| 638 | - return _T('date_jour_' . $nom . $param); |
|
| 639 | - |
|
| 640 | - case 'mois_annee': |
|
| 641 | - if ($avjc) { |
|
| 642 | - return $annee; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 646 | - |
|
| 647 | - case 'annee': |
|
| 648 | - return $annee; |
|
| 649 | - |
|
| 650 | - // Cas d'une vue non definie : retomber sur le format |
|
| 651 | - // de date propose par http://www.php.net/date |
|
| 652 | - default: |
|
| 653 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 654 | - // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant '' |
|
| 655 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) { |
|
| 656 | - $time = strtotime($numdate); |
|
| 657 | - } |
|
| 658 | - return date($vue, $time); |
|
| 659 | - } |
|
| 493 | + if (is_string($options)) { |
|
| 494 | + $options = ['param' => $options]; |
|
| 495 | + } |
|
| 496 | + $date_array = recup_date($numdate, false); |
|
| 497 | + if (!$date_array) { |
|
| 498 | + return ''; |
|
| 499 | + } |
|
| 500 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 501 | + |
|
| 502 | + // 1er, 21st, etc. |
|
| 503 | + $journum = $jour; |
|
| 504 | + |
|
| 505 | + if ($jour == 0) { |
|
| 506 | + $jour = ''; |
|
| 507 | + $njour = 0; |
|
| 508 | + } else { |
|
| 509 | + $njour = (int) $jour; |
|
| 510 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 511 | + $jour = $jourth; |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + $mois = (int) $mois; |
|
| 516 | + if ($mois > 0 && $mois < 13) { |
|
| 517 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 518 | + $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 519 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 520 | + $jourmois = $jour |
|
| 521 | + ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]) |
|
| 522 | + : $nommois; |
|
| 523 | + } else { |
|
| 524 | + $nommois = ''; |
|
| 525 | + $jourmois = ''; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + if ($annee < 0) { |
|
| 529 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 530 | + $avjc = true; |
|
| 531 | + } else { |
|
| 532 | + $avjc = false; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + switch ($vue) { |
|
| 536 | + case 'saison': |
|
| 537 | + case 'saison_annee': |
|
| 538 | + $saison = ''; |
|
| 539 | + if ($mois > 0) { |
|
| 540 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 541 | + if ($mois == 3 && $jour >= 21 || $mois > 3) { |
|
| 542 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 543 | + } |
|
| 544 | + if ($mois == 6 && $jour >= 21 || $mois > 6) { |
|
| 545 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 546 | + } |
|
| 547 | + if ($mois == 9 && $jour >= 21 || $mois > 9) { |
|
| 548 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 549 | + } |
|
| 550 | + if ($mois == 12 && $jour >= 21 || $mois > 12) { |
|
| 551 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + if ($vue == 'saison') { |
|
| 555 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 556 | + } else { |
|
| 557 | + return $saison ? trim((string) _T( |
|
| 558 | + 'date_fmt_saison_annee', |
|
| 559 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 560 | + )) : ''; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + case 'court': |
|
| 564 | + if ($avjc) { |
|
| 565 | + return $annee; |
|
| 566 | + } |
|
| 567 | + $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 568 | + if ($annee < ($a - 100) || $annee > ($a + 100)) { |
|
| 569 | + return $annee; |
|
| 570 | + } |
|
| 571 | + if ($annee != $a) { |
|
| 572 | + return _T( |
|
| 573 | + 'date_fmt_mois_annee', |
|
| 574 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 575 | + ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + return _T( |
|
| 579 | + 'date_fmt_jour_mois', |
|
| 580 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 581 | + ); |
|
| 582 | + |
|
| 583 | + case 'jourcourt': |
|
| 584 | + if ($avjc) { |
|
| 585 | + return $annee; |
|
| 586 | + } |
|
| 587 | + $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | + if ($annee < ($a - 100) || $annee > ($a + 100)) { |
|
| 589 | + return $annee; |
|
| 590 | + } |
|
| 591 | + if ($annee != $a) { |
|
| 592 | + return _T( |
|
| 593 | + 'date_fmt_jour_mois_annee', |
|
| 594 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return _T( |
|
| 599 | + 'date_fmt_jour_mois', |
|
| 600 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + case 'entier': |
|
| 604 | + if ($avjc) { |
|
| 605 | + return $annee; |
|
| 606 | + } |
|
| 607 | + if ($jour) { |
|
| 608 | + return _T( |
|
| 609 | + 'date_fmt_jour_mois_annee', |
|
| 610 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 611 | + ); |
|
| 612 | + } elseif ($mois) { |
|
| 613 | + return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 614 | + } else { |
|
| 615 | + return $annee; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + case 'nom_mois': |
|
| 619 | + return $nommois; |
|
| 620 | + |
|
| 621 | + case 'mois': |
|
| 622 | + return sprintf('%02s', $mois); |
|
| 623 | + |
|
| 624 | + case 'jour': |
|
| 625 | + return $jour; |
|
| 626 | + |
|
| 627 | + case 'journum': |
|
| 628 | + return $journum; |
|
| 629 | + |
|
| 630 | + case 'nom_jour': |
|
| 631 | + if (!$mois || !$njour) { |
|
| 632 | + return ''; |
|
| 633 | + } |
|
| 634 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 635 | + $nom = 1 + (int) date('w', $nom); |
|
| 636 | + $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : ''); |
|
| 637 | + |
|
| 638 | + return _T('date_jour_' . $nom . $param); |
|
| 639 | + |
|
| 640 | + case 'mois_annee': |
|
| 641 | + if ($avjc) { |
|
| 642 | + return $annee; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 646 | + |
|
| 647 | + case 'annee': |
|
| 648 | + return $annee; |
|
| 649 | + |
|
| 650 | + // Cas d'une vue non definie : retomber sur le format |
|
| 651 | + // de date propose par http://www.php.net/date |
|
| 652 | + default: |
|
| 653 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 654 | + // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant '' |
|
| 655 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) { |
|
| 656 | + $time = strtotime($numdate); |
|
| 657 | + } |
|
| 658 | + return date($vue, $time); |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | |
@@ -683,11 +683,11 @@ discard block |
||
| 683 | 683 | * Nom du jour |
| 684 | 684 | **/ |
| 685 | 685 | function nom_jour($numdate, $forme = ''): string { |
| 686 | - if ($forme !== 'abbr' && $forme !== 'initiale') { |
|
| 687 | - $forme = ''; |
|
| 688 | - } |
|
| 686 | + if ($forme !== 'abbr' && $forme !== 'initiale') { |
|
| 687 | + $forme = ''; |
|
| 688 | + } |
|
| 689 | 689 | |
| 690 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 690 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /** |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | * Numéro du jour |
| 710 | 710 | **/ |
| 711 | 711 | function jour($numdate): string { |
| 712 | - return affdate_base($numdate, 'jour'); |
|
| 712 | + return affdate_base($numdate, 'jour'); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * Numéro du jour |
| 728 | 728 | **/ |
| 729 | 729 | function journum($numdate): string { |
| 730 | - return affdate_base($numdate, 'journum'); |
|
| 730 | + return affdate_base($numdate, 'journum'); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | * Numéro du mois (sur 2 chiffres) |
| 746 | 746 | **/ |
| 747 | 747 | function mois($numdate): string { |
| 748 | - return affdate_base($numdate, 'mois'); |
|
| 748 | + return affdate_base($numdate, 'mois'); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * Nom du mois |
| 770 | 770 | **/ |
| 771 | 771 | function nom_mois($numdate, $forme = ''): string { |
| 772 | - if ($forme !== 'abbr') { |
|
| 773 | - $forme = ''; |
|
| 774 | - } |
|
| 772 | + if ($forme !== 'abbr') { |
|
| 773 | + $forme = ''; |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 776 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | * Année (sur 4 chiffres) |
| 792 | 792 | **/ |
| 793 | 793 | function annee($numdate): string { |
| 794 | - return affdate_base($numdate, 'annee'); |
|
| 794 | + return affdate_base($numdate, 'annee'); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | |
@@ -821,11 +821,11 @@ discard block |
||
| 821 | 821 | * La date formatée |
| 822 | 822 | **/ |
| 823 | 823 | function saison($numdate, $hemisphere = 'nord'): string { |
| 824 | - if ($hemisphere !== 'sud') { |
|
| 825 | - $hemisphere = 'nord'; |
|
| 826 | - } |
|
| 824 | + if ($hemisphere !== 'sud') { |
|
| 825 | + $hemisphere = 'nord'; |
|
| 826 | + } |
|
| 827 | 827 | |
| 828 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 828 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | |
@@ -854,11 +854,11 @@ discard block |
||
| 854 | 854 | * La date formatée |
| 855 | 855 | **/ |
| 856 | 856 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 857 | - if ($hemisphere !== 'sud') { |
|
| 858 | - $hemisphere = 'nord'; |
|
| 859 | - } |
|
| 857 | + if ($hemisphere !== 'sud') { |
|
| 858 | + $hemisphere = 'nord'; |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 861 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | /** |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | * La date formatée |
| 887 | 887 | **/ |
| 888 | 888 | function affdate($numdate, $format = 'entier'): string { |
| 889 | - return affdate_base($numdate, $format); |
|
| 889 | + return affdate_base($numdate, $format); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | * La date formatée |
| 914 | 914 | **/ |
| 915 | 915 | function affdate_court($numdate, $annee_courante = null): string { |
| 916 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 916 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | * La date formatée |
| 941 | 941 | **/ |
| 942 | 942 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 943 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 943 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | * La date formatée |
| 959 | 959 | **/ |
| 960 | 960 | function affdate_mois_annee($numdate): string { |
| 961 | - return affdate_base($numdate, 'mois_annee'); |
|
| 961 | + return affdate_base($numdate, 'mois_annee'); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -976,16 +976,16 @@ discard block |
||
| 976 | 976 | * La date formatée, sinon '' |
| 977 | 977 | **/ |
| 978 | 978 | function affdate_heure($numdate): string { |
| 979 | - $date_array = recup_date($numdate); |
|
| 980 | - if (!$date_array) { |
|
| 981 | - return ''; |
|
| 982 | - } |
|
| 983 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 984 | - |
|
| 985 | - return _T('date_fmt_jour_heure', [ |
|
| 986 | - 'jour' => affdate($numdate), |
|
| 987 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 988 | - ]); |
|
| 979 | + $date_array = recup_date($numdate); |
|
| 980 | + if (!$date_array) { |
|
| 981 | + return ''; |
|
| 982 | + } |
|
| 983 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 984 | + |
|
| 985 | + return _T('date_fmt_jour_heure', [ |
|
| 986 | + 'jour' => affdate($numdate), |
|
| 987 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 988 | + ]); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -1017,113 +1017,113 @@ discard block |
||
| 1017 | 1017 | * texte de la date |
| 1018 | 1018 | */ |
| 1019 | 1019 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1020 | - $abbr = $jour = ''; |
|
| 1021 | - $affdate = 'affdate_jourcourt'; |
|
| 1022 | - if (str_contains($forme, 'abbr')) { |
|
| 1023 | - $abbr = 'abbr'; |
|
| 1024 | - } |
|
| 1025 | - if (str_contains($forme, 'annee')) { |
|
| 1026 | - $affdate = 'affdate'; |
|
| 1027 | - } |
|
| 1028 | - if (str_contains($forme, 'jour')) { |
|
| 1029 | - $jour = 'jour'; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1033 | - if (str_contains($forme, 'hcal')) { |
|
| 1034 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1035 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1036 | - $dtabbr = '</abbr>'; |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - $date_debut = strtotime($date_debut); |
|
| 1040 | - $date_fin = strtotime($date_fin); |
|
| 1041 | - $d = date('Y-m-d', $date_debut); |
|
| 1042 | - $f = date('Y-m-d', $date_fin); |
|
| 1043 | - $h = ($horaire === 'oui' || $horaire === true); |
|
| 1044 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1045 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1046 | - |
|
| 1047 | - if ($d === $f) { // meme jour |
|
| 1048 | - $nomjour = nom_jour($d, $abbr); |
|
| 1049 | - $s = $affdate($d); |
|
| 1050 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1051 | - if ($h) { |
|
| 1052 | - if ($hd === $hf) { |
|
| 1053 | - // Lundi 20 fevrier a 18h25 |
|
| 1054 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1055 | - $s = "$dtstart$s$dtabbr"; |
|
| 1056 | - } else { |
|
| 1057 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1058 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1059 | - $s = _T( |
|
| 1060 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1061 | - [ |
|
| 1062 | - 'jour' => spip_ucfirst($s), |
|
| 1063 | - 'heure_debut' => $hd, |
|
| 1064 | - 'heure_fin' => $hf, |
|
| 1065 | - 'dtstart' => $dtstart, |
|
| 1066 | - 'dtend' => $dtend, |
|
| 1067 | - 'dtabbr' => $dtabbr |
|
| 1068 | - ], |
|
| 1069 | - [ |
|
| 1070 | - 'sanitize' => false |
|
| 1071 | - ] |
|
| 1072 | - ); |
|
| 1073 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1074 | - else { |
|
| 1075 | - $s = spip_ucfirst(_T( |
|
| 1076 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1077 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1078 | - )); |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - } else { |
|
| 1082 | - $s = $dtabbr && $dtstart |
|
| 1083 | - ? $dtstart . spip_ucfirst($s) . $dtabbr |
|
| 1084 | - : spip_ucfirst($s); |
|
| 1085 | - } |
|
| 1086 | - } else { |
|
| 1087 | - if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1088 | - $date_debut = $h |
|
| 1089 | - ? affdate_jourcourt($d, date('Y', $date_fin)) |
|
| 1090 | - : jour($d); |
|
| 1091 | - $date_fin = $affdate($f); |
|
| 1092 | - if ($jour) { |
|
| 1093 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1094 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1095 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1096 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1097 | - } |
|
| 1098 | - if ($h) { |
|
| 1099 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1100 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1101 | - } |
|
| 1102 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1103 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1104 | - |
|
| 1105 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1106 | - } else { |
|
| 1107 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | - $date_fin = $affdate($f); |
|
| 1109 | - if ($jour) { |
|
| 1110 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1111 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1112 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1113 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1114 | - } |
|
| 1115 | - if ($h) { |
|
| 1116 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1117 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - return $s; |
|
| 1020 | + $abbr = $jour = ''; |
|
| 1021 | + $affdate = 'affdate_jourcourt'; |
|
| 1022 | + if (str_contains($forme, 'abbr')) { |
|
| 1023 | + $abbr = 'abbr'; |
|
| 1024 | + } |
|
| 1025 | + if (str_contains($forme, 'annee')) { |
|
| 1026 | + $affdate = 'affdate'; |
|
| 1027 | + } |
|
| 1028 | + if (str_contains($forme, 'jour')) { |
|
| 1029 | + $jour = 'jour'; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1033 | + if (str_contains($forme, 'hcal')) { |
|
| 1034 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1035 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1036 | + $dtabbr = '</abbr>'; |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + $date_debut = strtotime($date_debut); |
|
| 1040 | + $date_fin = strtotime($date_fin); |
|
| 1041 | + $d = date('Y-m-d', $date_debut); |
|
| 1042 | + $f = date('Y-m-d', $date_fin); |
|
| 1043 | + $h = ($horaire === 'oui' || $horaire === true); |
|
| 1044 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1045 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1046 | + |
|
| 1047 | + if ($d === $f) { // meme jour |
|
| 1048 | + $nomjour = nom_jour($d, $abbr); |
|
| 1049 | + $s = $affdate($d); |
|
| 1050 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1051 | + if ($h) { |
|
| 1052 | + if ($hd === $hf) { |
|
| 1053 | + // Lundi 20 fevrier a 18h25 |
|
| 1054 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1055 | + $s = "$dtstart$s$dtabbr"; |
|
| 1056 | + } else { |
|
| 1057 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1058 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1059 | + $s = _T( |
|
| 1060 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1061 | + [ |
|
| 1062 | + 'jour' => spip_ucfirst($s), |
|
| 1063 | + 'heure_debut' => $hd, |
|
| 1064 | + 'heure_fin' => $hf, |
|
| 1065 | + 'dtstart' => $dtstart, |
|
| 1066 | + 'dtend' => $dtend, |
|
| 1067 | + 'dtabbr' => $dtabbr |
|
| 1068 | + ], |
|
| 1069 | + [ |
|
| 1070 | + 'sanitize' => false |
|
| 1071 | + ] |
|
| 1072 | + ); |
|
| 1073 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1074 | + else { |
|
| 1075 | + $s = spip_ucfirst(_T( |
|
| 1076 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1077 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1078 | + )); |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + } else { |
|
| 1082 | + $s = $dtabbr && $dtstart |
|
| 1083 | + ? $dtstart . spip_ucfirst($s) . $dtabbr |
|
| 1084 | + : spip_ucfirst($s); |
|
| 1085 | + } |
|
| 1086 | + } else { |
|
| 1087 | + if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1088 | + $date_debut = $h |
|
| 1089 | + ? affdate_jourcourt($d, date('Y', $date_fin)) |
|
| 1090 | + : jour($d); |
|
| 1091 | + $date_fin = $affdate($f); |
|
| 1092 | + if ($jour) { |
|
| 1093 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1094 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1095 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1096 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1097 | + } |
|
| 1098 | + if ($h) { |
|
| 1099 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1100 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1101 | + } |
|
| 1102 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1103 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1104 | + |
|
| 1105 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1106 | + } else { |
|
| 1107 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | + $date_fin = $affdate($f); |
|
| 1109 | + if ($jour) { |
|
| 1110 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1111 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1112 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1113 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1114 | + } |
|
| 1115 | + if ($h) { |
|
| 1116 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1117 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + return $s; |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | /** |
@@ -1144,10 +1144,10 @@ discard block |
||
| 1144 | 1144 | * Date au format ical |
| 1145 | 1145 | **/ |
| 1146 | 1146 | function date_ical($date, $addminutes = 0): string { |
| 1147 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1148 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1147 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1148 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1149 | 1149 | |
| 1150 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1150 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | |
@@ -1171,14 +1171,14 @@ discard block |
||
| 1171 | 1171 | * La date formatée |
| 1172 | 1172 | **/ |
| 1173 | 1173 | function date_iso($date_heure): string { |
| 1174 | - $date = recup_date($date_heure); |
|
| 1175 | - $annee = $date[0] ?? null; |
|
| 1176 | - $mois = $date[1] ?? null; |
|
| 1177 | - $jour = $date[2] ?? null; |
|
| 1178 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1179 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1180 | - |
|
| 1181 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1174 | + $date = recup_date($date_heure); |
|
| 1175 | + $annee = $date[0] ?? null; |
|
| 1176 | + $mois = $date[1] ?? null; |
|
| 1177 | + $jour = $date[2] ?? null; |
|
| 1178 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1179 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1180 | + |
|
| 1181 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1201,11 +1201,11 @@ discard block |
||
| 1201 | 1201 | * La date formatée |
| 1202 | 1202 | **/ |
| 1203 | 1203 | function date_822($date_heure): string { |
| 1204 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1205 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1206 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1204 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1205 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1206 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1207 | 1207 | |
| 1208 | - return date('r', $time); |
|
| 1208 | + return date('r', $time); |
|
| 1209 | 1209 | } |
| 1210 | 1210 | |
| 1211 | 1211 | /** |
@@ -1221,11 +1221,11 @@ discard block |
||
| 1221 | 1221 | * Date au format `Ymd` |
| 1222 | 1222 | **/ |
| 1223 | 1223 | function date_anneemoisjour($d): string { |
| 1224 | - if (!$d) { |
|
| 1225 | - $d = date('Y-m-d'); |
|
| 1226 | - } |
|
| 1224 | + if (!$d) { |
|
| 1225 | + $d = date('Y-m-d'); |
|
| 1226 | + } |
|
| 1227 | 1227 | |
| 1228 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1228 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * Date au format `Ym` |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function date_anneemois($d): string { |
| 1244 | - if (!$d) { |
|
| 1245 | - $d = date('Y-m-d'); |
|
| 1246 | - } |
|
| 1244 | + if (!$d) { |
|
| 1245 | + $d = date('Y-m-d'); |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1248 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -1261,13 +1261,13 @@ discard block |
||
| 1261 | 1261 | * Date au lundi de la même semaine au format `Ymd` |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1264 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1265 | - if ($w_day == 0) { |
|
| 1266 | - $w_day = 7; |
|
| 1267 | - } // Gaffe: le dimanche est zero |
|
| 1268 | - $debut = $jour - $w_day + 1; |
|
| 1264 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1265 | + if ($w_day == 0) { |
|
| 1266 | + $w_day = 7; |
|
| 1267 | + } // Gaffe: le dimanche est zero |
|
| 1268 | + $debut = $jour - $w_day + 1; |
|
| 1269 | 1269 | |
| 1270 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1270 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | /** |
@@ -1283,11 +1283,11 @@ discard block |
||
| 1283 | 1283 | * Date au dimanche de la même semaine au format `Ymd` |
| 1284 | 1284 | **/ |
| 1285 | 1285 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1286 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | - if ($w_day == 0) { |
|
| 1288 | - $w_day = 7; |
|
| 1289 | - } // Gaffe: le dimanche est zero |
|
| 1290 | - $debut = $jour - $w_day + 1; |
|
| 1286 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | + if ($w_day == 0) { |
|
| 1288 | + $w_day = 7; |
|
| 1289 | + } // Gaffe: le dimanche est zero |
|
| 1290 | + $debut = $jour - $w_day + 1; |
|
| 1291 | 1291 | |
| 1292 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1292 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1293 | 1293 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | function extraire_date($texte): string { |
| 39 | 39 | // format = 2001-08 |
| 40 | 40 | if (preg_match(',([1-2]\d{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 41 | + return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01'; |
|
| 42 | 42 | } |
| 43 | 43 | return ''; |
| 44 | 44 | } |
@@ -69,11 +69,11 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 71 | 71 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 72 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 72 | + $date = $regs[1].'-00-00'.$regs[3]; |
|
| 73 | 73 | } else { |
| 74 | 74 | if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 75 | 75 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 76 | - $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3]; |
|
| 76 | + $date = preg_replace('@/@', '-', (string) $regs[1]).'-00'.$regs[3]; |
|
| 77 | 77 | } else { |
| 78 | 78 | $date = date('Y-m-d H:i:s', strtotime($date)); |
| 79 | 79 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $letexte ??= ''; |
| 101 | 101 | if ( |
| 102 | 102 | !$verif_format_date |
| 103 | - || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte) |
|
| 103 | + || in_array(strlen($letexte), [10, 19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte) |
|
| 104 | 104 | ) { |
| 105 | 105 | if (strncmp('0000-00-00', $letexte, 10) == 0) { |
| 106 | 106 | return ''; |
@@ -385,39 +385,39 @@ discard block |
||
| 385 | 385 | if ($decal > 3600 * 24 * 30) { |
| 386 | 386 | $mois = floor($decal / (3600 * 24 * 30)); |
| 387 | 387 | $delai = $mois < 2 |
| 388 | - ? "$mois " . _T('date_un_mois') |
|
| 389 | - : "$mois " . _T('date_mois'); |
|
| 388 | + ? "$mois "._T('date_un_mois') |
|
| 389 | + : "$mois "._T('date_mois'); |
|
| 390 | 390 | } else { |
| 391 | 391 | if ($decal > 3600 * 24 * 7) { |
| 392 | 392 | $semaines = floor($decal / (3600 * 24 * 7)); |
| 393 | 393 | $delai = $semaines < 2 |
| 394 | - ? "$semaines " . _T('date_une_semaine') |
|
| 395 | - : "$semaines " . _T('date_semaines'); |
|
| 394 | + ? "$semaines "._T('date_une_semaine') |
|
| 395 | + : "$semaines "._T('date_semaines'); |
|
| 396 | 396 | } else { |
| 397 | 397 | if ($decal > 3600 * 24) { |
| 398 | 398 | $jours = floor($decal / (3600 * 24)); |
| 399 | 399 | if ($jours < 2) { |
| 400 | 400 | return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
| 401 | 401 | } else { |
| 402 | - $delai = "$jours " . _T('date_jours'); |
|
| 402 | + $delai = "$jours "._T('date_jours'); |
|
| 403 | 403 | } |
| 404 | 404 | } else { |
| 405 | 405 | if ($decal >= 3600) { |
| 406 | 406 | $heures = floor($decal / 3600); |
| 407 | 407 | $delai = $heures < 2 |
| 408 | - ? "$heures " . _T('date_une_heure') |
|
| 409 | - : "$heures " . _T('date_heures'); |
|
| 408 | + ? "$heures "._T('date_une_heure') |
|
| 409 | + : "$heures "._T('date_heures'); |
|
| 410 | 410 | } else { |
| 411 | 411 | if ($decal >= 60) { |
| 412 | 412 | $minutes = floor($decal / 60); |
| 413 | 413 | $delai = $minutes < 2 |
| 414 | - ? "$minutes " . _T('date_une_minute') |
|
| 415 | - : "$minutes " . _T('date_minutes'); |
|
| 414 | + ? "$minutes "._T('date_une_minute') |
|
| 415 | + : "$minutes "._T('date_minutes'); |
|
| 416 | 416 | } else { |
| 417 | 417 | $secondes = ceil($decal); |
| 418 | 418 | $delai = $secondes < 2 |
| 419 | - ? "$secondes " . _T('date_une_seconde') |
|
| 420 | - : "$secondes " . _T('date_secondes'); |
|
| 419 | + ? "$secondes "._T('date_une_seconde') |
|
| 420 | + : "$secondes "._T('date_secondes'); |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | } |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | $njour = 0; |
| 508 | 508 | } else { |
| 509 | 509 | $njour = (int) $jour; |
| 510 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 510 | + if ($jourth = _T('date_jnum'.$jour)) { |
|
| 511 | 511 | $jour = $jourth; |
| 512 | 512 | } |
| 513 | 513 | } |
@@ -515,10 +515,10 @@ discard block |
||
| 515 | 515 | $mois = (int) $mois; |
| 516 | 516 | if ($mois > 0 && $mois < 13) { |
| 517 | 517 | /* Traiter le cas "abbr" pour les noms de mois */ |
| 518 | - $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 519 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 518 | + $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_'.$options['param'] : ''); |
|
| 519 | + $nommois = _T('date_mois_'.$mois.$param); |
|
| 520 | 520 | $jourmois = $jour |
| 521 | - ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]) |
|
| 521 | + ? _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]) |
|
| 522 | 522 | : $nommois; |
| 523 | 523 | } else { |
| 524 | 524 | $nommois = ''; |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | if ($annee < 0) { |
| 529 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 529 | + $annee = -$annee.' '._T('date_avant_jc'); |
|
| 530 | 530 | $avjc = true; |
| 531 | 531 | } else { |
| 532 | 532 | $avjc = false; |
@@ -552,11 +552,11 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | if ($vue == 'saison') { |
| 555 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 555 | + return $saison ? _T('date_saison_'.$saison) : ''; |
|
| 556 | 556 | } else { |
| 557 | 557 | return $saison ? trim((string) _T( |
| 558 | 558 | 'date_fmt_saison_annee', |
| 559 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 559 | + ['saison' => _T('date_saison_'.$saison), 'annee' => $annee] |
|
| 560 | 560 | )) : ''; |
| 561 | 561 | } |
| 562 | 562 | |
@@ -633,9 +633,9 @@ discard block |
||
| 633 | 633 | } |
| 634 | 634 | $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
| 635 | 635 | $nom = 1 + (int) date('w', $nom); |
| 636 | - $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : ''); |
|
| 636 | + $param = ((isset($options['param']) && $options['param']) ? '_'.$options['param'] : ''); |
|
| 637 | 637 | |
| 638 | - return _T('date_jour_' . $nom . $param); |
|
| 638 | + return _T('date_jour_'.$nom.$param); |
|
| 639 | 639 | |
| 640 | 640 | case 'mois_annee': |
| 641 | 641 | if ($avjc) { |
@@ -1031,8 +1031,8 @@ discard block |
||
| 1031 | 1031 | |
| 1032 | 1032 | $dtstart = $dtend = $dtabbr = ''; |
| 1033 | 1033 | if (str_contains($forme, 'hcal')) { |
| 1034 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1035 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1034 | + $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1035 | + $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1036 | 1036 | $dtabbr = '</abbr>'; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | } |
| 1081 | 1081 | } else { |
| 1082 | 1082 | $s = $dtabbr && $dtstart |
| 1083 | - ? $dtstart . spip_ucfirst($s) . $dtabbr |
|
| 1083 | + ? $dtstart.spip_ucfirst($s).$dtabbr |
|
| 1084 | 1084 | : spip_ucfirst($s); |
| 1085 | 1085 | } |
| 1086 | 1086 | } else { |
@@ -1099,8 +1099,8 @@ discard block |
||
| 1099 | 1099 | $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
| 1100 | 1100 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1101 | 1101 | } |
| 1102 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1103 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1102 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1103 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1104 | 1104 | |
| 1105 | 1105 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1106 | 1106 | } else { |
@@ -1117,8 +1117,8 @@ discard block |
||
| 1117 | 1117 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1120 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1121 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1122 | 1122 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1123 | 1123 | } |
| 1124 | 1124 | } |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | $d = date('Y-m-d'); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1228 | + return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | $d = date('Y-m-d'); |
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1248 | + return substr($d, 0, 4).substr($d, 5, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | 28 | function autosave_clean_value($val) { |
| 29 | - return stripslashes(urldecode((string) $val)); |
|
| 29 | + return stripslashes(urldecode((string) $val)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -37,58 +37,58 @@ discard block |
||
| 37 | 37 | * @return array |
| 38 | 38 | */ |
| 39 | 39 | function cvtautosave_formulaire_charger($flux) { |
| 40 | - if ( |
|
| 41 | - is_array($flux['data']) |
|
| 42 | - && isset($flux['data']['_autosave_id']) |
|
| 43 | - && ($cle_autosave = $flux['data']['_autosave_id']) |
|
| 44 | - ) { |
|
| 45 | - $form = $flux['args']['form']; |
|
| 46 | - $je_suis_poste = $flux['args']['je_suis_poste']; |
|
| 40 | + if ( |
|
| 41 | + is_array($flux['data']) |
|
| 42 | + && isset($flux['data']['_autosave_id']) |
|
| 43 | + && ($cle_autosave = $flux['data']['_autosave_id']) |
|
| 44 | + ) { |
|
| 45 | + $form = $flux['args']['form']; |
|
| 46 | + $je_suis_poste = $flux['args']['je_suis_poste']; |
|
| 47 | 47 | |
| 48 | - $cle_autosave = serialize($cle_autosave); |
|
| 49 | - $cle_autosave = $form . '_' . md5($cle_autosave); |
|
| 48 | + $cle_autosave = serialize($cle_autosave); |
|
| 49 | + $cle_autosave = $form . '_' . md5($cle_autosave); |
|
| 50 | 50 | |
| 51 | - // si on a un backup en session et qu'on est au premier chargement, non poste |
|
| 52 | - // on restitue les donnees |
|
| 53 | - if ( |
|
| 54 | - isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave]) |
|
| 55 | - && !$je_suis_poste |
|
| 56 | - ) { |
|
| 57 | - parse_str((string) $GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars); |
|
| 58 | - foreach ($vars as $key => $val) { |
|
| 59 | - if (isset($flux['data'][$key])) { |
|
| 60 | - $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map( |
|
| 61 | - 'autosave_clean_value', |
|
| 62 | - $val |
|
| 63 | - )); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 51 | + // si on a un backup en session et qu'on est au premier chargement, non poste |
|
| 52 | + // on restitue les donnees |
|
| 53 | + if ( |
|
| 54 | + isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave]) |
|
| 55 | + && !$je_suis_poste |
|
| 56 | + ) { |
|
| 57 | + parse_str((string) $GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars); |
|
| 58 | + foreach ($vars as $key => $val) { |
|
| 59 | + if (isset($flux['data'][$key])) { |
|
| 60 | + $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map( |
|
| 61 | + 'autosave_clean_value', |
|
| 62 | + $val |
|
| 63 | + )); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // si on est dans le charger() qui suit le traiter(), l'autosave a normalement ete vide |
|
| 69 | - // mais si il y a plusieurs sessions il peut y avoir concurrence et un retour de l'autosave |
|
| 70 | - if ($je_suis_poste && _request('autosave') === $cle_autosave && function_exists('terminer_actualiser_sessions')) { |
|
| 71 | - terminer_actualiser_sessions(); |
|
| 72 | - // et verifions si jamais l'autosave a fait un come back, dans ce cas on le revide |
|
| 73 | - if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])) { |
|
| 74 | - session_set('session_autosave_' . $cle_autosave, null); |
|
| 75 | - // en court sleep pour etre certain que la concurrence est finie |
|
| 76 | - sleep(1); |
|
| 77 | - terminer_actualiser_sessions(); |
|
| 78 | - } |
|
| 79 | - } |
|
| 68 | + // si on est dans le charger() qui suit le traiter(), l'autosave a normalement ete vide |
|
| 69 | + // mais si il y a plusieurs sessions il peut y avoir concurrence et un retour de l'autosave |
|
| 70 | + if ($je_suis_poste && _request('autosave') === $cle_autosave && function_exists('terminer_actualiser_sessions')) { |
|
| 71 | + terminer_actualiser_sessions(); |
|
| 72 | + // et verifions si jamais l'autosave a fait un come back, dans ce cas on le revide |
|
| 73 | + if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])) { |
|
| 74 | + session_set('session_autosave_' . $cle_autosave, null); |
|
| 75 | + // en court sleep pour etre certain que la concurrence est finie |
|
| 76 | + sleep(1); |
|
| 77 | + terminer_actualiser_sessions(); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Envoyer le input hidden et le bout de js qui l'utilisera |
|
| 84 | - */ |
|
| 85 | - $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />" |
|
| 86 | - . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){ |
|
| 82 | + /** |
|
| 83 | + * Envoyer le input hidden et le bout de js qui l'utilisera |
|
| 84 | + */ |
|
| 85 | + $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />" |
|
| 86 | + . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){ |
|
| 87 | 87 | $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon"); |
| 88 | 88 | });/*]]>*/</script>'; |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $flux; |
|
| 91 | + return $flux; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -102,33 +102,33 @@ discard block |
||
| 102 | 102 | * @return array |
| 103 | 103 | */ |
| 104 | 104 | function cvtautosave_formulaire_traiter($flux) { |
| 105 | - // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder : |
|
| 106 | - // on elimine les donnees de la session |
|
| 107 | - if ($cle_autosave = _request('autosave')) { |
|
| 108 | - include_spip('inc/session'); |
|
| 109 | - session_set('session_autosave_' . $cle_autosave, null); |
|
| 110 | - } |
|
| 105 | + // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder : |
|
| 106 | + // on elimine les donnees de la session |
|
| 107 | + if ($cle_autosave = _request('autosave')) { |
|
| 108 | + include_spip('inc/session'); |
|
| 109 | + session_set('session_autosave_' . $cle_autosave, null); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if (isset($GLOBALS['visiteur_session']) && $GLOBALS['visiteur_session']) { |
|
| 113 | - // delai par defaut avant purge d'un backup de form : 72H |
|
| 114 | - if (!defined('_AUTOSAVE_GB_DELAY')) { |
|
| 115 | - define('_AUTOSAVE_GB_DELAY', 72 * 3600); |
|
| 116 | - } |
|
| 117 | - $time_too_old = time() - _AUTOSAVE_GB_DELAY; |
|
| 118 | - // purger aussi toutes les vieilles autosave |
|
| 119 | - $session = $GLOBALS['visiteur_session']; |
|
| 120 | - foreach ($session as $k => $v) { |
|
| 121 | - if (str_starts_with((string) $k, 'session_autosave_')) { |
|
| 122 | - $timestamp = 0; |
|
| 123 | - if (preg_match(',&__timestamp=(\d+)$,', (string) $v, $m)) { |
|
| 124 | - $timestamp = (int) $m[1]; |
|
| 125 | - } |
|
| 126 | - if ($timestamp < $time_too_old) { |
|
| 127 | - session_set($k, null); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 112 | + if (isset($GLOBALS['visiteur_session']) && $GLOBALS['visiteur_session']) { |
|
| 113 | + // delai par defaut avant purge d'un backup de form : 72H |
|
| 114 | + if (!defined('_AUTOSAVE_GB_DELAY')) { |
|
| 115 | + define('_AUTOSAVE_GB_DELAY', 72 * 3600); |
|
| 116 | + } |
|
| 117 | + $time_too_old = time() - _AUTOSAVE_GB_DELAY; |
|
| 118 | + // purger aussi toutes les vieilles autosave |
|
| 119 | + $session = $GLOBALS['visiteur_session']; |
|
| 120 | + foreach ($session as $k => $v) { |
|
| 121 | + if (str_starts_with((string) $k, 'session_autosave_')) { |
|
| 122 | + $timestamp = 0; |
|
| 123 | + if (preg_match(',&__timestamp=(\d+)$,', (string) $v, $m)) { |
|
| 124 | + $timestamp = (int) $m[1]; |
|
| 125 | + } |
|
| 126 | + if ($timestamp < $time_too_old) { |
|
| 127 | + session_set($k, null); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return $flux; |
|
| 133 | + return $flux; |
|
| 134 | 134 | } |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | $je_suis_poste = $flux['args']['je_suis_poste']; |
| 47 | 47 | |
| 48 | 48 | $cle_autosave = serialize($cle_autosave); |
| 49 | - $cle_autosave = $form . '_' . md5($cle_autosave); |
|
| 49 | + $cle_autosave = $form.'_'.md5($cle_autosave); |
|
| 50 | 50 | |
| 51 | 51 | // si on a un backup en session et qu'on est au premier chargement, non poste |
| 52 | 52 | // on restitue les donnees |
| 53 | 53 | if ( |
| 54 | - isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave]) |
|
| 54 | + isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave]) |
|
| 55 | 55 | && !$je_suis_poste |
| 56 | 56 | ) { |
| 57 | - parse_str((string) $GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars); |
|
| 57 | + parse_str((string) $GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars); |
|
| 58 | 58 | foreach ($vars as $key => $val) { |
| 59 | 59 | if (isset($flux['data'][$key])) { |
| 60 | 60 | $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map( |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | if ($je_suis_poste && _request('autosave') === $cle_autosave && function_exists('terminer_actualiser_sessions')) { |
| 71 | 71 | terminer_actualiser_sessions(); |
| 72 | 72 | // et verifions si jamais l'autosave a fait un come back, dans ce cas on le revide |
| 73 | - if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])) { |
|
| 74 | - session_set('session_autosave_' . $cle_autosave, null); |
|
| 73 | + if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])) { |
|
| 74 | + session_set('session_autosave_'.$cle_autosave, null); |
|
| 75 | 75 | // en court sleep pour etre certain que la concurrence est finie |
| 76 | 76 | sleep(1); |
| 77 | 77 | terminer_actualiser_sessions(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />" |
| 86 | 86 | . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){ |
| 87 | - $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon"); |
|
| 87 | + $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon"); |
|
| 88 | 88 | });/*]]>*/</script>'; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | // on elimine les donnees de la session |
| 107 | 107 | if ($cle_autosave = _request('autosave')) { |
| 108 | 108 | include_spip('inc/session'); |
| 109 | - session_set('session_autosave_' . $cle_autosave, null); |
|
| 109 | + session_set('session_autosave_'.$cle_autosave, null); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | if (isset($GLOBALS['visiteur_session']) && $GLOBALS['visiteur_session']) { |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/boutons'); |
@@ -38,33 +38,33 @@ discard block |
||
| 38 | 38 | * contexte |
| 39 | 39 | **/ |
| 40 | 40 | function definir_barre_contexte($contexte = null) { |
| 41 | - if (is_null($contexte)) { |
|
| 42 | - $contexte = $_GET; |
|
| 43 | - } elseif (is_string($contexte)) { |
|
| 44 | - $contexte = unserialize($contexte); |
|
| 45 | - } |
|
| 46 | - if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) { |
|
| 47 | - if (!function_exists('trouver_objet_exec')) { |
|
| 48 | - include_spip('inc/pipelines_ecrire'); |
|
| 49 | - } |
|
| 50 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 51 | - $_id = $e['id_table_objet']; |
|
| 52 | - if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) { |
|
| 53 | - $table = $e['table_objet_sql']; |
|
| 54 | - $row = sql_fetsel('*', $table, "$_id=" . (int) $id); |
|
| 55 | - if (isset($row['id_rubrique'])) { |
|
| 56 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 57 | - if (isset($row['id_secteur'])) { |
|
| 58 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 59 | - } |
|
| 60 | - } elseif (isset($row['id_groupe'])) { |
|
| 61 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 62 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $contexte; |
|
| 41 | + if (is_null($contexte)) { |
|
| 42 | + $contexte = $_GET; |
|
| 43 | + } elseif (is_string($contexte)) { |
|
| 44 | + $contexte = unserialize($contexte); |
|
| 45 | + } |
|
| 46 | + if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) { |
|
| 47 | + if (!function_exists('trouver_objet_exec')) { |
|
| 48 | + include_spip('inc/pipelines_ecrire'); |
|
| 49 | + } |
|
| 50 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 51 | + $_id = $e['id_table_objet']; |
|
| 52 | + if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) { |
|
| 53 | + $table = $e['table_objet_sql']; |
|
| 54 | + $row = sql_fetsel('*', $table, "$_id=" . (int) $id); |
|
| 55 | + if (isset($row['id_rubrique'])) { |
|
| 56 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 57 | + if (isset($row['id_secteur'])) { |
|
| 58 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 59 | + } |
|
| 60 | + } elseif (isset($row['id_groupe'])) { |
|
| 61 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 62 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $contexte; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -80,89 +80,89 @@ discard block |
||
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | 82 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 83 | - include_spip('inc/autoriser'); |
|
| 84 | - $boutons_admin = []; |
|
| 83 | + include_spip('inc/autoriser'); |
|
| 84 | + $boutons_admin = []; |
|
| 85 | 85 | |
| 86 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 87 | - $liste_boutons = []; |
|
| 86 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 87 | + $liste_boutons = []; |
|
| 88 | 88 | |
| 89 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 90 | - if ( |
|
| 91 | - function_exists('boutons_plugins') |
|
| 92 | - && is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 93 | - ) { |
|
| 94 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 95 | - } |
|
| 89 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 90 | + if ( |
|
| 91 | + function_exists('boutons_plugins') |
|
| 92 | + && is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 93 | + ) { |
|
| 94 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - foreach ($liste_boutons as $id => $infos) { |
|
| 98 | - $parent = ''; |
|
| 99 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 100 | - if ( |
|
| 101 | - !isset($infos['parent']) |
|
| 102 | - || !($parent = $infos['parent']) |
|
| 103 | - || !$autorise |
|
| 104 | - || autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 105 | - ) { |
|
| 106 | - if ( |
|
| 107 | - $parent |
|
| 108 | - && ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent)) |
|
| 109 | - && isset($boutons_admin[$parent]) |
|
| 110 | - ) { |
|
| 111 | - $position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu); |
|
| 112 | - if ($position < 0) { |
|
| 113 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 114 | - } |
|
| 115 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 116 | - + [ |
|
| 117 | - $id => new Bouton( |
|
| 118 | - ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | - $infos['titre'], // titre |
|
| 120 | - (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 121 | - (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 122 | - ) |
|
| 123 | - ] |
|
| 124 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 125 | - } |
|
| 126 | - if ( |
|
| 127 | - !$parent |
|
| 128 | - // provisoire, eviter les vieux boutons |
|
| 129 | - && !in_array($id, ['forum', 'statistiques_visites']) |
|
| 130 | - && (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 131 | - ) { |
|
| 132 | - $position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 133 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 134 | - + [ |
|
| 135 | - $id => new Bouton( |
|
| 136 | - ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | - $infos['titre'], // titre |
|
| 138 | - (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 139 | - (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 140 | - ) |
|
| 141 | - ] |
|
| 142 | - + array_slice($boutons_admin, $position, 100); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 97 | + foreach ($liste_boutons as $id => $infos) { |
|
| 98 | + $parent = ''; |
|
| 99 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 100 | + if ( |
|
| 101 | + !isset($infos['parent']) |
|
| 102 | + || !($parent = $infos['parent']) |
|
| 103 | + || !$autorise |
|
| 104 | + || autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 105 | + ) { |
|
| 106 | + if ( |
|
| 107 | + $parent |
|
| 108 | + && ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent)) |
|
| 109 | + && isset($boutons_admin[$parent]) |
|
| 110 | + ) { |
|
| 111 | + $position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu); |
|
| 112 | + if ($position < 0) { |
|
| 113 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 114 | + } |
|
| 115 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 116 | + + [ |
|
| 117 | + $id => new Bouton( |
|
| 118 | + ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | + $infos['titre'], // titre |
|
| 120 | + (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 121 | + (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 122 | + ) |
|
| 123 | + ] |
|
| 124 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 125 | + } |
|
| 126 | + if ( |
|
| 127 | + !$parent |
|
| 128 | + // provisoire, eviter les vieux boutons |
|
| 129 | + && !in_array($id, ['forum', 'statistiques_visites']) |
|
| 130 | + && (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 131 | + ) { |
|
| 132 | + $position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 133 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 134 | + + [ |
|
| 135 | + $id => new Bouton( |
|
| 136 | + ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | + $infos['titre'], // titre |
|
| 138 | + (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 139 | + (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 140 | + ) |
|
| 141 | + ] |
|
| 142 | + + array_slice($boutons_admin, $position, 100); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 147 | 147 | |
| 148 | - // définir les favoris et positions d’origine |
|
| 149 | - if ($boutons_admin) { |
|
| 150 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 151 | - $i = 1; |
|
| 152 | - foreach ($boutons_admin as $key => $menu) { |
|
| 153 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 154 | - $menu->position = $i++; |
|
| 155 | - if ($menu->sousmenu) { |
|
| 156 | - $j = 1; |
|
| 157 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 158 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 159 | - $bouton->position = $j++; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 148 | + // définir les favoris et positions d’origine |
|
| 149 | + if ($boutons_admin) { |
|
| 150 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 151 | + $i = 1; |
|
| 152 | + foreach ($boutons_admin as $key => $menu) { |
|
| 153 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 154 | + $menu->position = $i++; |
|
| 155 | + if ($menu->sousmenu) { |
|
| 156 | + $j = 1; |
|
| 157 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 158 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 159 | + $bouton->position = $j++; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return $boutons_admin; |
|
| 165 | + return $boutons_admin; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -174,22 +174,22 @@ discard block |
||
| 174 | 174 | * @return Bouton[] |
| 175 | 175 | */ |
| 176 | 176 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 177 | - foreach ($menus as $menu) { |
|
| 178 | - if ($menu->sousmenu) { |
|
| 179 | - $libelles = $isfavoris = $favoris = []; |
|
| 180 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 181 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 182 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 183 | - $favoris[$key] = $item->favori; |
|
| 184 | - } |
|
| 185 | - if ($avec_favoris) { |
|
| 186 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | - } else { |
|
| 188 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - return $menus; |
|
| 177 | + foreach ($menus as $menu) { |
|
| 178 | + if ($menu->sousmenu) { |
|
| 179 | + $libelles = $isfavoris = $favoris = []; |
|
| 180 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 181 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 182 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 183 | + $favoris[$key] = $item->favori; |
|
| 184 | + } |
|
| 185 | + if ($avec_favoris) { |
|
| 186 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | + } else { |
|
| 188 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + return $menus; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return Bouton[] |
| 201 | 201 | */ |
| 202 | 202 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 203 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 203 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | |
@@ -213,23 +213,23 @@ discard block |
||
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | 215 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 216 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 217 | - $url = generer_url_ecrire($url, $args, true); |
|
| 218 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 219 | - // &truc=@machin@ |
|
| 220 | - // @machin@ etant remplace par _request('machin') |
|
| 221 | - $url = str_replace('&', '&', $url); |
|
| 222 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 223 | - if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) { |
|
| 224 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']); |
|
| 225 | - } |
|
| 226 | - $val = _request($matches[2], $contexte); |
|
| 227 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 228 | - } |
|
| 229 | - $url = str_replace('&', '&', $url); |
|
| 230 | - } |
|
| 216 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 217 | + $url = generer_url_ecrire($url, $args, true); |
|
| 218 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 219 | + // &truc=@machin@ |
|
| 220 | + // @machin@ etant remplace par _request('machin') |
|
| 221 | + $url = str_replace('&', '&', $url); |
|
| 222 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 223 | + if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) { |
|
| 224 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']); |
|
| 225 | + } |
|
| 226 | + $val = _request($matches[2], $contexte); |
|
| 227 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 228 | + } |
|
| 229 | + $url = str_replace('&', '&', $url); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return $url; |
|
| 232 | + return $url; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * Code HTML du bandeau |
| 240 | 240 | */ |
| 241 | 241 | function inc_bandeau_dist() { |
| 242 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 242 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -248,13 +248,13 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function obtenir_menus_favoris() { |
| 251 | - if ( |
|
| 252 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | - && is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | - && $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 255 | - ) { |
|
| 256 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 257 | - } |
|
| 258 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 259 | - return $definir_menus_favoris(); |
|
| 251 | + if ( |
|
| 252 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | + && is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | + && $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 255 | + ) { |
|
| 256 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 257 | + } |
|
| 258 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 259 | + return $definir_menus_favoris(); |
|
| 260 | 260 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/charsets'); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * @return string Fonction PHP correspondante du filtre |
| 42 | 42 | */ |
| 43 | 43 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 44 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | - return chercher_filtre($fonc, $default); |
|
| 44 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | + return chercher_filtre($fonc, $default); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string texte |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_identite_dist($texte) { |
| 55 | - return $texte; |
|
| 55 | + return $texte; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -76,33 +76,33 @@ discard block |
||
| 76 | 76 | * Fonction PHP correspondante du filtre demandé |
| 77 | 77 | */ |
| 78 | 78 | function chercher_filtre($fonc, $default = null) { |
| 79 | - if (!$fonc) { |
|
| 80 | - return $default; |
|
| 81 | - } |
|
| 82 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | - // Foo::Bar |
|
| 84 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | - $f = chercher_filtre($nom); |
|
| 88 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | - if (!$f && $nom !== $fonc) { |
|
| 91 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $f; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - include_fichiers_fonctions(); |
|
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | - if (is_callable($f)) { |
|
| 101 | - return $f; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $default; |
|
| 79 | + if (!$fonc) { |
|
| 80 | + return $default; |
|
| 81 | + } |
|
| 82 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | + // Foo::Bar |
|
| 84 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | + $f = chercher_filtre($nom); |
|
| 88 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | + if (!$f && $nom !== $fonc) { |
|
| 91 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $f; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + include_fichiers_fonctions(); |
|
| 98 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | + if (is_callable($f)) { |
|
| 101 | + return $f; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $default; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * Chaîne vide sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function appliquer_filtre(mixed $arg, $filtre) { |
| 149 | - $args = func_get_args(); |
|
| 150 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 149 | + $args = func_get_args(); |
|
| 150 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * texte d'origine sinon |
| 173 | 173 | **/ |
| 174 | 174 | function appliquer_si_filtre(mixed $arg, $filtre) { |
| 175 | - $args = func_get_args(); |
|
| 176 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 175 | + $args = func_get_args(); |
|
| 176 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | * Version de SPIP |
| 190 | 190 | **/ |
| 191 | 191 | function spip_version() { |
| 192 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | - $version .= " $vcs_version"; |
|
| 195 | - } |
|
| 192 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | + $version .= " $vcs_version"; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $version; |
|
| 197 | + return $version; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | 208 | function header_silencieux($version): string { |
| 209 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | - $version = ''; |
|
| 211 | - } |
|
| 209 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | + $version = ''; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return (string) $version; |
|
| 213 | + return (string) $version; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | * - string|null si $raw = false |
| 224 | 224 | */ |
| 225 | 225 | function version_vcs_courante($dir, $raw = false) { |
| 226 | - $desc = decrire_version_git($dir); |
|
| 227 | - if ($desc === null || $raw) { |
|
| 228 | - return $desc; |
|
| 229 | - } |
|
| 230 | - // affichage "GIT [master: abcdef]" |
|
| 231 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | - if ($desc['branch']) { |
|
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | - } |
|
| 235 | - return "{$desc['vcs']} [$commit]"; |
|
| 226 | + $desc = decrire_version_git($dir); |
|
| 227 | + if ($desc === null || $raw) { |
|
| 228 | + return $desc; |
|
| 229 | + } |
|
| 230 | + // affichage "GIT [master: abcdef]" |
|
| 231 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | + if ($desc['branch']) { |
|
| 233 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | + } |
|
| 235 | + return "{$desc['vcs']} [$commit]"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,26 +244,26 @@ discard block |
||
| 244 | 244 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 245 | 245 | **/ |
| 246 | 246 | function decrire_version_git($dir) { |
| 247 | - $c = null; |
|
| 248 | - $hash = null; |
|
| 249 | - if (!$dir) { |
|
| 250 | - $dir = '.'; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // version installee par GIT |
|
| 254 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 255 | - $currentHead = trim(substr((string) $c, 4)); |
|
| 256 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 257 | - return [ |
|
| 258 | - 'vcs' => 'GIT', |
|
| 259 | - 'branch' => basename($currentHead), |
|
| 260 | - 'commit' => trim((string) $hash), |
|
| 261 | - 'commit_short' => substr(trim((string) $hash), 0, 8), |
|
| 262 | - ]; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return null; |
|
| 247 | + $c = null; |
|
| 248 | + $hash = null; |
|
| 249 | + if (!$dir) { |
|
| 250 | + $dir = '.'; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // version installee par GIT |
|
| 254 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 255 | + $currentHead = trim(substr((string) $c, 4)); |
|
| 256 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 257 | + return [ |
|
| 258 | + 'vcs' => 'GIT', |
|
| 259 | + 'branch' => basename($currentHead), |
|
| 260 | + 'commit' => trim((string) $hash), |
|
| 261 | + 'commit_short' => substr(trim((string) $hash), 0, 8), |
|
| 262 | + ]; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return null; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -310,18 +310,18 @@ discard block |
||
| 310 | 310 | * Code HTML retourné par le filtre |
| 311 | 311 | **/ |
| 312 | 312 | function filtrer($filtre) { |
| 313 | - $tous = func_get_args(); |
|
| 314 | - if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 315 | - return image_filtrer($tous); |
|
| 316 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 317 | - array_shift($tous); |
|
| 318 | - return $f(...$tous); |
|
| 319 | - } else { |
|
| 320 | - // le filtre n'existe pas, on provoque une erreur |
|
| 321 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 322 | - erreur_squelette($msg); |
|
| 323 | - return ''; |
|
| 324 | - } |
|
| 313 | + $tous = func_get_args(); |
|
| 314 | + if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 315 | + return image_filtrer($tous); |
|
| 316 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 317 | + array_shift($tous); |
|
| 318 | + return $f(...$tous); |
|
| 319 | + } else { |
|
| 320 | + // le filtre n'existe pas, on provoque une erreur |
|
| 321 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 322 | + erreur_squelette($msg); |
|
| 323 | + return ''; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -338,11 +338,11 @@ discard block |
||
| 338 | 338 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 339 | 339 | */ |
| 340 | 340 | function trouver_filtre_matrice($filtre) { |
| 341 | - if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 342 | - find_in_path($f, '', true); |
|
| 343 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 344 | - } |
|
| 345 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 341 | + if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 342 | + find_in_path($f, '', true); |
|
| 343 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 344 | + } |
|
| 345 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | * @return mixed |
| 371 | 371 | */ |
| 372 | 372 | function filtre_set(&$Pile, mixed $val, $key, $continue = null) { |
| 373 | - $Pile['vars'][$key] = $val; |
|
| 374 | - return $continue ? $val : ''; |
|
| 373 | + $Pile['vars'][$key] = $val; |
|
| 374 | + return $continue ? $val : ''; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -397,8 +397,8 @@ discard block |
||
| 397 | 397 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 398 | 398 | */ |
| 399 | 399 | function filtre_setenv(&$Pile, mixed $val, mixed $key, $continue = null) { |
| 400 | - $Pile[0][$key] = $val; |
|
| 401 | - return $continue ? $val : ''; |
|
| 400 | + $Pile[0][$key] = $val; |
|
| 401 | + return $continue ? $val : ''; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * @return string |
| 408 | 408 | */ |
| 409 | 409 | function filtre_sanitize_env(&$Pile, $keys) { |
| 410 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 411 | - return ''; |
|
| 410 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 411 | + return ''; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -431,18 +431,18 @@ discard block |
||
| 431 | 431 | * @return mixed Retourne la valeur (sans la modifier). |
| 432 | 432 | */ |
| 433 | 433 | function filtre_debug(mixed $val, $key = null) { |
| 434 | - $debug = ( |
|
| 435 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | - ) . var_export($val, true); |
|
| 434 | + $debug = ( |
|
| 435 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | + ) . var_export($val, true); |
|
| 437 | 437 | |
| 438 | - include_spip('inc/autoriser'); |
|
| 439 | - if (autoriser('webmestre')) { |
|
| 440 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 441 | - } |
|
| 438 | + include_spip('inc/autoriser'); |
|
| 439 | + if (autoriser('webmestre')) { |
|
| 440 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - spip_log($debug, 'debug'); |
|
| 443 | + spip_log($debug, 'debug'); |
|
| 444 | 444 | |
| 445 | - return $val; |
|
| 445 | + return $val; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -472,81 +472,81 @@ discard block |
||
| 472 | 472 | * texte qui a reçu les filtres |
| 473 | 473 | **/ |
| 474 | 474 | function image_filtrer($args) { |
| 475 | - $filtre = array_shift($args); # enlever $filtre |
|
| 476 | - $texte = array_shift($args); |
|
| 477 | - if ($texte === null || !strlen((string) $texte)) { |
|
| 478 | - return ''; |
|
| 479 | - } |
|
| 480 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 481 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 482 | - // Cas du nom de fichier local |
|
| 483 | - $is_file = trim((string) $texte); |
|
| 484 | - if ( |
|
| 485 | - str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 486 | - || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 487 | - || str_starts_with($is_file, '/') |
|
| 488 | - ) { |
|
| 489 | - $is_file = false; |
|
| 490 | - } |
|
| 491 | - if ($is_file) { |
|
| 492 | - $is_local_file = function ($path) { |
|
| 493 | - if (str_contains($path, '?')) { |
|
| 494 | - $path = supprimer_timestamp($path); |
|
| 495 | - // remove ?24px added by find_in_theme on .svg files |
|
| 496 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 497 | - } |
|
| 498 | - return file_exists($path); |
|
| 499 | - }; |
|
| 500 | - if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 501 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 502 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 503 | - return $res; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 508 | - if ( |
|
| 509 | - preg_match_all( |
|
| 510 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 511 | - (string) $texte, |
|
| 512 | - $tags, |
|
| 513 | - PREG_SET_ORDER |
|
| 514 | - ) |
|
| 515 | - ) { |
|
| 516 | - foreach ($tags as $tag) { |
|
| 517 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 518 | - if ( |
|
| 519 | - (!$class || !str_contains($class, 'filtre_inactif') |
|
| 520 | - && !str_contains($class, 'no_image_filtrer')) && ($reduit = $filtre($tag[3], ...$args)) |
|
| 521 | - ) { |
|
| 522 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 523 | - if ($tag[1]) { |
|
| 524 | - $w = extraire_attribut($reduit, 'width'); |
|
| 525 | - if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 526 | - $w = $regs[1]; |
|
| 527 | - } |
|
| 528 | - if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 529 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 530 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 531 | - $texte = str_replace($tag[1], $replace, (string) $texte); |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - // traiter aussi un eventuel mouseover |
|
| 535 | - if ( |
|
| 536 | - ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 537 | - && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 538 | - ) { |
|
| 539 | - $srcover = $match[1]; |
|
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | - $reduit = str_replace($srcover, $srcover_filter, (string) $reduit); |
|
| 543 | - } |
|
| 544 | - $texte = str_replace($tag[3], $reduit, (string) $texte); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 549 | - return $texte; |
|
| 475 | + $filtre = array_shift($args); # enlever $filtre |
|
| 476 | + $texte = array_shift($args); |
|
| 477 | + if ($texte === null || !strlen((string) $texte)) { |
|
| 478 | + return ''; |
|
| 479 | + } |
|
| 480 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 481 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 482 | + // Cas du nom de fichier local |
|
| 483 | + $is_file = trim((string) $texte); |
|
| 484 | + if ( |
|
| 485 | + str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 486 | + || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 487 | + || str_starts_with($is_file, '/') |
|
| 488 | + ) { |
|
| 489 | + $is_file = false; |
|
| 490 | + } |
|
| 491 | + if ($is_file) { |
|
| 492 | + $is_local_file = function ($path) { |
|
| 493 | + if (str_contains($path, '?')) { |
|
| 494 | + $path = supprimer_timestamp($path); |
|
| 495 | + // remove ?24px added by find_in_theme on .svg files |
|
| 496 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 497 | + } |
|
| 498 | + return file_exists($path); |
|
| 499 | + }; |
|
| 500 | + if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 501 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 502 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 503 | + return $res; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 508 | + if ( |
|
| 509 | + preg_match_all( |
|
| 510 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 511 | + (string) $texte, |
|
| 512 | + $tags, |
|
| 513 | + PREG_SET_ORDER |
|
| 514 | + ) |
|
| 515 | + ) { |
|
| 516 | + foreach ($tags as $tag) { |
|
| 517 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 518 | + if ( |
|
| 519 | + (!$class || !str_contains($class, 'filtre_inactif') |
|
| 520 | + && !str_contains($class, 'no_image_filtrer')) && ($reduit = $filtre($tag[3], ...$args)) |
|
| 521 | + ) { |
|
| 522 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 523 | + if ($tag[1]) { |
|
| 524 | + $w = extraire_attribut($reduit, 'width'); |
|
| 525 | + if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 526 | + $w = $regs[1]; |
|
| 527 | + } |
|
| 528 | + if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 529 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 530 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 531 | + $texte = str_replace($tag[1], $replace, (string) $texte); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + // traiter aussi un eventuel mouseover |
|
| 535 | + if ( |
|
| 536 | + ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 537 | + && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 538 | + ) { |
|
| 539 | + $srcover = $match[1]; |
|
| 540 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | + $reduit = str_replace($srcover, $srcover_filter, (string) $reduit); |
|
| 543 | + } |
|
| 544 | + $texte = str_replace($tag[3], $reduit, (string) $texte); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 549 | + return $texte; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -563,94 +563,94 @@ discard block |
||
| 563 | 563 | **/ |
| 564 | 564 | function infos_image($img, $force_refresh = false) { |
| 565 | 565 | |
| 566 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 567 | - $srcWidth = 0; |
|
| 568 | - $srcHeight = 0; |
|
| 569 | - $srcSize = null; |
|
| 570 | - $valeurs = null; |
|
| 571 | - |
|
| 572 | - $src = extraire_attribut($img, 'src'); |
|
| 573 | - |
|
| 574 | - if (!$src) { |
|
| 575 | - $src = $img; |
|
| 576 | - } else { |
|
| 577 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | - if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 580 | - $srcWidth = $srcHeight = 0; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | - if (tester_url_absolue($src)) { |
|
| 587 | - include_spip('inc/distant'); |
|
| 588 | - $fichier = copie_locale($src); |
|
| 589 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | - } |
|
| 591 | - if (($p = strpos($src, '?')) !== false) { |
|
| 592 | - $src = substr($src, 0, $p); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $imagesize = false; |
|
| 596 | - if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 597 | - $srcWidth = $largeur_img[$src]; |
|
| 598 | - } |
|
| 599 | - if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 600 | - $srcHeight = $hauteur_img[$src]; |
|
| 601 | - } |
|
| 602 | - if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 603 | - $srcSize = $poids_img[$src]; |
|
| 604 | - } |
|
| 605 | - if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 606 | - if ( |
|
| 607 | - file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 608 | - ) { |
|
| 609 | - if (!$srcWidth) { |
|
| 610 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 611 | - } |
|
| 612 | - if (!$srcHeight) { |
|
| 613 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 614 | - } |
|
| 615 | - if (!$srcSize) { |
|
| 616 | - $poids_img[$src] = filesize($src); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - elseif (str_contains($src, '<svg')) { |
|
| 620 | - include_spip('inc/svg'); |
|
| 621 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 622 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 623 | - if (!$srcWidth) { |
|
| 624 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 625 | - } |
|
| 626 | - if (!$srcHeight) { |
|
| 627 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 628 | - } |
|
| 629 | - if (!$srcSize) { |
|
| 630 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 635 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 636 | - elseif ( |
|
| 637 | - @file_exists($f = "$src.src") |
|
| 638 | - && lire_fichier($f, $valeurs) |
|
| 639 | - && ($valeurs = unserialize($valeurs)) |
|
| 640 | - ) { |
|
| 641 | - if (!$srcWidth) { |
|
| 642 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 643 | - } |
|
| 644 | - if (!$srcHeight) { |
|
| 645 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 646 | - } |
|
| 647 | - if (!$srcSize) { |
|
| 648 | - $poids_img[$src] = $srcSize = 0; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 566 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 567 | + $srcWidth = 0; |
|
| 568 | + $srcHeight = 0; |
|
| 569 | + $srcSize = null; |
|
| 570 | + $valeurs = null; |
|
| 571 | + |
|
| 572 | + $src = extraire_attribut($img, 'src'); |
|
| 573 | + |
|
| 574 | + if (!$src) { |
|
| 575 | + $src = $img; |
|
| 576 | + } else { |
|
| 577 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | + if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 580 | + $srcWidth = $srcHeight = 0; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | + if (tester_url_absolue($src)) { |
|
| 587 | + include_spip('inc/distant'); |
|
| 588 | + $fichier = copie_locale($src); |
|
| 589 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | + } |
|
| 591 | + if (($p = strpos($src, '?')) !== false) { |
|
| 592 | + $src = substr($src, 0, $p); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $imagesize = false; |
|
| 596 | + if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 597 | + $srcWidth = $largeur_img[$src]; |
|
| 598 | + } |
|
| 599 | + if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 600 | + $srcHeight = $hauteur_img[$src]; |
|
| 601 | + } |
|
| 602 | + if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 603 | + $srcSize = $poids_img[$src]; |
|
| 604 | + } |
|
| 605 | + if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 606 | + if ( |
|
| 607 | + file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 608 | + ) { |
|
| 609 | + if (!$srcWidth) { |
|
| 610 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 611 | + } |
|
| 612 | + if (!$srcHeight) { |
|
| 613 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 614 | + } |
|
| 615 | + if (!$srcSize) { |
|
| 616 | + $poids_img[$src] = filesize($src); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + elseif (str_contains($src, '<svg')) { |
|
| 620 | + include_spip('inc/svg'); |
|
| 621 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 622 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 623 | + if (!$srcWidth) { |
|
| 624 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 625 | + } |
|
| 626 | + if (!$srcHeight) { |
|
| 627 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 628 | + } |
|
| 629 | + if (!$srcSize) { |
|
| 630 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 635 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 636 | + elseif ( |
|
| 637 | + @file_exists($f = "$src.src") |
|
| 638 | + && lire_fichier($f, $valeurs) |
|
| 639 | + && ($valeurs = unserialize($valeurs)) |
|
| 640 | + ) { |
|
| 641 | + if (!$srcWidth) { |
|
| 642 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 643 | + } |
|
| 644 | + if (!$srcHeight) { |
|
| 645 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 646 | + } |
|
| 647 | + if (!$srcSize) { |
|
| 648 | + $poids_img[$src] = $srcSize = 0; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -666,13 +666,13 @@ discard block |
||
| 666 | 666 | * poids |
| 667 | 667 | **/ |
| 668 | 668 | function poids_image($img, $force_refresh = false) { |
| 669 | - $infos = infos_image($img, $force_refresh); |
|
| 670 | - return $infos['poids']; |
|
| 669 | + $infos = infos_image($img, $force_refresh); |
|
| 670 | + return $infos['poids']; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | function taille_image($img, $force_refresh = false) { |
| 674 | - $infos = infos_image($img, $force_refresh); |
|
| 675 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 674 | + $infos = infos_image($img, $force_refresh); |
|
| 675 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -689,12 +689,12 @@ discard block |
||
| 689 | 689 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 690 | 690 | **/ |
| 691 | 691 | function largeur($img) { |
| 692 | - if (!$img) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - [$h, $l] = taille_image($img); |
|
| 692 | + if (!$img) { |
|
| 693 | + return; |
|
| 694 | + } |
|
| 695 | + [$h, $l] = taille_image($img); |
|
| 696 | 696 | |
| 697 | - return $l; |
|
| 697 | + return $l; |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 712 | 712 | **/ |
| 713 | 713 | function hauteur($img) { |
| 714 | - if (!$img) { |
|
| 715 | - return; |
|
| 716 | - } |
|
| 717 | - [$h, $l] = taille_image($img); |
|
| 714 | + if (!$img) { |
|
| 715 | + return; |
|
| 716 | + } |
|
| 717 | + [$h, $l] = taille_image($img); |
|
| 718 | 718 | |
| 719 | - return $h; |
|
| 719 | + return $h; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -736,11 +736,11 @@ discard block |
||
| 736 | 736 | * @return string |
| 737 | 737 | **/ |
| 738 | 738 | function corriger_entites_html($texte) { |
| 739 | - if (!str_contains($texte, '&')) { |
|
| 740 | - return $texte; |
|
| 741 | - } |
|
| 739 | + if (!str_contains($texte, '&')) { |
|
| 740 | + return $texte; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | - return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 743 | + return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -755,11 +755,11 @@ discard block |
||
| 755 | 755 | * @return string |
| 756 | 756 | **/ |
| 757 | 757 | function corriger_toutes_entites_html($texte) { |
| 758 | - if (!str_contains($texte, '&')) { |
|
| 759 | - return $texte; |
|
| 760 | - } |
|
| 758 | + if (!str_contains($texte, '&')) { |
|
| 759 | + return $texte; |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 762 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | **/ |
| 771 | 771 | function proteger_amp($texte) { |
| 772 | - return str_replace('&', '&', $texte); |
|
| 772 | + return str_replace('&', '&', $texte); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -800,18 +800,18 @@ discard block |
||
| 800 | 800 | * @return mixed|string |
| 801 | 801 | */ |
| 802 | 802 | function entites_html($texte, $tout = false, $quote = true) { |
| 803 | - if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 804 | - return $texte; |
|
| 805 | - } |
|
| 806 | - include_spip('inc/texte'); |
|
| 807 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 808 | - $flags |= ENT_HTML401; |
|
| 809 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 810 | - if ($tout) { |
|
| 811 | - return corriger_toutes_entites_html($texte); |
|
| 812 | - } else { |
|
| 813 | - return corriger_entites_html($texte); |
|
| 814 | - } |
|
| 803 | + if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 804 | + return $texte; |
|
| 805 | + } |
|
| 806 | + include_spip('inc/texte'); |
|
| 807 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 808 | + $flags |= ENT_HTML401; |
|
| 809 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 810 | + if ($tout) { |
|
| 811 | + return corriger_toutes_entites_html($texte); |
|
| 812 | + } else { |
|
| 813 | + return corriger_entites_html($texte); |
|
| 814 | + } |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | /** |
@@ -830,38 +830,38 @@ discard block |
||
| 830 | 830 | * texte converti |
| 831 | 831 | **/ |
| 832 | 832 | function filtrer_entites(?string $texte): string { |
| 833 | - $texte ??= ''; |
|
| 834 | - if (!str_contains($texte, '&')) { |
|
| 835 | - return $texte; |
|
| 836 | - } |
|
| 837 | - // filtrer |
|
| 838 | - $texte = html2unicode($texte); |
|
| 839 | - // remettre le tout dans le charset cible |
|
| 840 | - $texte = unicode2charset($texte); |
|
| 841 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 842 | - // (on le faisait deja avec un ") |
|
| 843 | - if (str_contains($texte, '&#')) { |
|
| 844 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 845 | - } |
|
| 833 | + $texte ??= ''; |
|
| 834 | + if (!str_contains($texte, '&')) { |
|
| 835 | + return $texte; |
|
| 836 | + } |
|
| 837 | + // filtrer |
|
| 838 | + $texte = html2unicode($texte); |
|
| 839 | + // remettre le tout dans le charset cible |
|
| 840 | + $texte = unicode2charset($texte); |
|
| 841 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 842 | + // (on le faisait deja avec un ") |
|
| 843 | + if (str_contains($texte, '&#')) { |
|
| 844 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return $texte; |
|
| 847 | + return $texte; |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
| 851 | 851 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 852 | - /** |
|
| 853 | - * Version sécurisée de filtrer_entites |
|
| 854 | - * |
|
| 855 | - * @uses interdire_scripts() |
|
| 856 | - * @uses filtrer_entites() |
|
| 857 | - * |
|
| 858 | - * @param string $t |
|
| 859 | - * @return string |
|
| 860 | - */ |
|
| 861 | - function filtre_filtrer_entites_dist($t) { |
|
| 862 | - include_spip('inc/texte'); |
|
| 863 | - return interdire_scripts(filtrer_entites($t)); |
|
| 864 | - } |
|
| 852 | + /** |
|
| 853 | + * Version sécurisée de filtrer_entites |
|
| 854 | + * |
|
| 855 | + * @uses interdire_scripts() |
|
| 856 | + * @uses filtrer_entites() |
|
| 857 | + * |
|
| 858 | + * @param string $t |
|
| 859 | + * @return string |
|
| 860 | + */ |
|
| 861 | + function filtre_filtrer_entites_dist($t) { |
|
| 862 | + include_spip('inc/texte'); |
|
| 863 | + return interdire_scripts(filtrer_entites($t)); |
|
| 864 | + } |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | |
@@ -876,18 +876,18 @@ discard block |
||
| 876 | 876 | * @return string|array |
| 877 | 877 | **/ |
| 878 | 878 | function supprimer_caracteres_illegaux($texte) { |
| 879 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 880 | - static $to = null; |
|
| 879 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 880 | + static $to = null; |
|
| 881 | 881 | |
| 882 | - if (is_array($texte)) { |
|
| 883 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 884 | - } |
|
| 882 | + if (is_array($texte)) { |
|
| 883 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - if (!$to) { |
|
| 887 | - $to = str_repeat('-', strlen((string) $from)); |
|
| 888 | - } |
|
| 886 | + if (!$to) { |
|
| 887 | + $to = str_repeat('-', strlen((string) $from)); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - return strtr($texte, $from, $to); |
|
| 890 | + return strtr($texte, $from, $to); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | /** |
@@ -899,9 +899,9 @@ discard block |
||
| 899 | 899 | * @return string|array |
| 900 | 900 | **/ |
| 901 | 901 | function corriger_caracteres($texte) { |
| 902 | - $texte = corriger_caracteres_windows($texte); |
|
| 902 | + $texte = corriger_caracteres_windows($texte); |
|
| 903 | 903 | |
| 904 | - return supprimer_caracteres_illegaux($texte); |
|
| 904 | + return supprimer_caracteres_illegaux($texte); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -918,44 +918,44 @@ discard block |
||
| 918 | 918 | * texte encodé pour XML |
| 919 | 919 | */ |
| 920 | 920 | function texte_backend(string $texte): string { |
| 921 | - if ($texte === '') { |
|
| 922 | - return ''; |
|
| 923 | - } |
|
| 921 | + if ($texte === '') { |
|
| 922 | + return ''; |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 925 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 926 | 926 | |
| 927 | - // si on a des liens ou des images, les passer en absolu |
|
| 928 | - $texte = liens_absolus($texte); |
|
| 927 | + // si on a des liens ou des images, les passer en absolu |
|
| 928 | + $texte = liens_absolus($texte); |
|
| 929 | 929 | |
| 930 | - // echapper les tags > < |
|
| 931 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 930 | + // echapper les tags > < |
|
| 931 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 932 | 932 | |
| 933 | - // importer les é |
|
| 934 | - $texte = filtrer_entites($texte); |
|
| 933 | + // importer les é |
|
| 934 | + $texte = filtrer_entites($texte); |
|
| 935 | 935 | |
| 936 | - // " -> " et tout ce genre de choses |
|
| 937 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 938 | - $texte = str_replace(' ', ' ', $texte); |
|
| 939 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 940 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 941 | - $texte = entites_html($texte, false, false); |
|
| 942 | - // mais bien echapper les double quotes ! |
|
| 943 | - $texte = str_replace('"', '"', (string) $texte); |
|
| 936 | + // " -> " et tout ce genre de choses |
|
| 937 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 938 | + $texte = str_replace(' ', ' ', $texte); |
|
| 939 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 940 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 941 | + $texte = entites_html($texte, false, false); |
|
| 942 | + // mais bien echapper les double quotes ! |
|
| 943 | + $texte = str_replace('"', '"', (string) $texte); |
|
| 944 | 944 | |
| 945 | - // verifier le charset |
|
| 946 | - $texte = charset2unicode($texte); |
|
| 945 | + // verifier le charset |
|
| 946 | + $texte = charset2unicode($texte); |
|
| 947 | 947 | |
| 948 | - // Caracteres problematiques en iso-latin 1 |
|
| 949 | - if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 950 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 951 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 952 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 953 | - } |
|
| 948 | + // Caracteres problematiques en iso-latin 1 |
|
| 949 | + if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 950 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 951 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 952 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 953 | + } |
|
| 954 | 954 | |
| 955 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 956 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 957 | - // ==> on les remplace par l'entite HTML |
|
| 958 | - return str_replace($apostrophe, "'", $texte); |
|
| 955 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 956 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 957 | + // ==> on les remplace par l'entite HTML |
|
| 958 | + return str_replace($apostrophe, "'", $texte); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | * texte encodé et quote pour XML |
| 973 | 973 | */ |
| 974 | 974 | function texte_backendq(string $texte): string { |
| 975 | - return addslashes(texte_backend($texte)); |
|
| 975 | + return addslashes(texte_backend($texte)); |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | |
@@ -994,14 +994,14 @@ discard block |
||
| 994 | 994 | * Texte sans son numéro éventuel |
| 995 | 995 | **/ |
| 996 | 996 | function supprimer_numero(?string $texte): string { |
| 997 | - if ($texte === null) { |
|
| 998 | - return ''; |
|
| 999 | - } |
|
| 1000 | - return preg_replace( |
|
| 1001 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1002 | - '', |
|
| 1003 | - $texte |
|
| 1004 | - ); |
|
| 997 | + if ($texte === null) { |
|
| 998 | + return ''; |
|
| 999 | + } |
|
| 1000 | + return preg_replace( |
|
| 1001 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1002 | + '', |
|
| 1003 | + $texte |
|
| 1004 | + ); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | /** |
@@ -1024,18 +1024,18 @@ discard block |
||
| 1024 | 1024 | * Numéro de titre, sinon chaîne vide |
| 1025 | 1025 | **/ |
| 1026 | 1026 | function recuperer_numero(?string $texte): string { |
| 1027 | - if ( |
|
| 1028 | - $texte |
|
| 1029 | - && preg_match( |
|
| 1030 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1031 | - $texte, |
|
| 1032 | - $regs |
|
| 1033 | - ) |
|
| 1034 | - ) { |
|
| 1035 | - return (string) $regs[1]; |
|
| 1036 | - } else { |
|
| 1037 | - return ''; |
|
| 1038 | - } |
|
| 1027 | + if ( |
|
| 1028 | + $texte |
|
| 1029 | + && preg_match( |
|
| 1030 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1031 | + $texte, |
|
| 1032 | + $regs |
|
| 1033 | + ) |
|
| 1034 | + ) { |
|
| 1035 | + return (string) $regs[1]; |
|
| 1036 | + } else { |
|
| 1037 | + return ''; |
|
| 1038 | + } |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1062,16 +1062,16 @@ discard block |
||
| 1062 | 1062 | * texte ou tableau de textes converti |
| 1063 | 1063 | **/ |
| 1064 | 1064 | function supprimer_tags($texte, $rempl = '') { |
| 1065 | - if ($texte === null) { |
|
| 1066 | - return ''; |
|
| 1067 | - } |
|
| 1068 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1069 | - // ne pas oublier un < final non ferme car coupe |
|
| 1070 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1071 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1072 | - $texte = str_replace('<', '<', $texte); |
|
| 1065 | + if ($texte === null) { |
|
| 1066 | + return ''; |
|
| 1067 | + } |
|
| 1068 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1069 | + // ne pas oublier un < final non ferme car coupe |
|
| 1070 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1071 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1072 | + $texte = str_replace('<', '<', $texte); |
|
| 1073 | 1073 | |
| 1074 | - return $texte; |
|
| 1074 | + return $texte; |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | * texte converti |
| 1095 | 1095 | **/ |
| 1096 | 1096 | function echapper_tags($texte, $rempl = '') { |
| 1097 | - return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1097 | + return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
@@ -1115,18 +1115,18 @@ discard block |
||
| 1115 | 1115 | * texte converti |
| 1116 | 1116 | **/ |
| 1117 | 1117 | function textebrut($texte) { |
| 1118 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1119 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1120 | - $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1121 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1122 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1123 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1124 | - $texte = supprimer_tags($texte); |
|
| 1125 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1126 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1127 | - $texte = str_replace('’', "'", $texte); |
|
| 1118 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1119 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1120 | + $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1121 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1122 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1123 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1124 | + $texte = supprimer_tags($texte); |
|
| 1125 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1126 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1127 | + $texte = str_replace('’', "'", $texte); |
|
| 1128 | 1128 | |
| 1129 | - return $texte; |
|
| 1129 | + return $texte; |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
@@ -1142,23 +1142,23 @@ discard block |
||
| 1142 | 1142 | * texte avec liens ouvrants |
| 1143 | 1143 | **/ |
| 1144 | 1144 | function liens_ouvrants($texte) { |
| 1145 | - if ( |
|
| 1146 | - preg_match_all( |
|
| 1147 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1148 | - $texte, |
|
| 1149 | - $liens, |
|
| 1150 | - PREG_PATTERN_ORDER |
|
| 1151 | - ) |
|
| 1152 | - ) { |
|
| 1153 | - foreach ($liens[0] as $a) { |
|
| 1154 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1155 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1156 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1157 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - return $texte; |
|
| 1145 | + if ( |
|
| 1146 | + preg_match_all( |
|
| 1147 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1148 | + $texte, |
|
| 1149 | + $liens, |
|
| 1150 | + PREG_PATTERN_ORDER |
|
| 1151 | + ) |
|
| 1152 | + ) { |
|
| 1153 | + foreach ($liens[0] as $a) { |
|
| 1154 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1155 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1156 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1157 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + return $texte; |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | /** |
@@ -1168,22 +1168,22 @@ discard block |
||
| 1168 | 1168 | * @return string |
| 1169 | 1169 | */ |
| 1170 | 1170 | function liens_nofollow($texte) { |
| 1171 | - if (stripos($texte, '<a') === false) { |
|
| 1172 | - return $texte; |
|
| 1173 | - } |
|
| 1171 | + if (stripos($texte, '<a') === false) { |
|
| 1172 | + return $texte; |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1176 | - foreach ($regs[0] as $a) { |
|
| 1177 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1178 | - if (!str_contains($rel, 'nofollow')) { |
|
| 1179 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1180 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1181 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1175 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1176 | + foreach ($regs[0] as $a) { |
|
| 1177 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1178 | + if (!str_contains($rel, 'nofollow')) { |
|
| 1179 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1180 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1181 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - return $texte; |
|
| 1186 | + return $texte; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1202,11 +1202,11 @@ discard block |
||
| 1202 | 1202 | * texte sans paraghaphes |
| 1203 | 1203 | **/ |
| 1204 | 1204 | function PtoBR($texte) { |
| 1205 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1206 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1207 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1205 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1206 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1207 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1208 | 1208 | |
| 1209 | - return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1209 | + return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | |
@@ -1231,19 +1231,19 @@ discard block |
||
| 1231 | 1231 | * @return string texte encadré du style CSS |
| 1232 | 1232 | */ |
| 1233 | 1233 | function lignes_longues($texte) { |
| 1234 | - trigger_error( |
|
| 1235 | - sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1236 | - \E_USER_DEPRECATED |
|
| 1237 | - ); |
|
| 1234 | + trigger_error( |
|
| 1235 | + sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1236 | + \E_USER_DEPRECATED |
|
| 1237 | + ); |
|
| 1238 | 1238 | |
| 1239 | - if (!strlen(trim($texte))) { |
|
| 1240 | - return $texte; |
|
| 1241 | - } |
|
| 1242 | - include_spip('inc/texte'); |
|
| 1243 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1244 | - 'div' : 'span'; |
|
| 1239 | + if (!strlen(trim($texte))) { |
|
| 1240 | + return $texte; |
|
| 1241 | + } |
|
| 1242 | + include_spip('inc/texte'); |
|
| 1243 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1244 | + 'div' : 'span'; |
|
| 1245 | 1245 | |
| 1246 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1246 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1262,30 +1262,30 @@ discard block |
||
| 1262 | 1262 | * @return string texte en majuscule |
| 1263 | 1263 | */ |
| 1264 | 1264 | function majuscules($texte) { |
| 1265 | - if (!strlen($texte)) { |
|
| 1266 | - return ''; |
|
| 1267 | - } |
|
| 1265 | + if (!strlen($texte)) { |
|
| 1266 | + return ''; |
|
| 1267 | + } |
|
| 1268 | 1268 | |
| 1269 | - // Cas du turc |
|
| 1270 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1271 | - # remplacer hors des tags et des entites |
|
| 1272 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1273 | - foreach ($regs as $n => $match) { |
|
| 1274 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1269 | + // Cas du turc |
|
| 1270 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1271 | + # remplacer hors des tags et des entites |
|
| 1272 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1273 | + foreach ($regs as $n => $match) { |
|
| 1274 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | 1277 | |
| 1278 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1278 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1279 | 1279 | |
| 1280 | - if ($regs) { |
|
| 1281 | - foreach ($regs as $n => $match) { |
|
| 1282 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1285 | - } |
|
| 1280 | + if ($regs) { |
|
| 1281 | + foreach ($regs as $n => $match) { |
|
| 1282 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | + } |
|
| 1286 | 1286 | |
| 1287 | - // Cas general |
|
| 1288 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1287 | + // Cas general |
|
| 1288 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1307,38 +1307,38 @@ discard block |
||
| 1307 | 1307 | */ |
| 1308 | 1308 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1309 | 1309 | |
| 1310 | - // Texte à afficher pour la taille |
|
| 1311 | - $affichage = ''; |
|
| 1310 | + // Texte à afficher pour la taille |
|
| 1311 | + $affichage = ''; |
|
| 1312 | 1312 | |
| 1313 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1314 | - static $precisions = [0, 1, 1, 2]; |
|
| 1313 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1314 | + static $precisions = [0, 1, 1, 2]; |
|
| 1315 | 1315 | |
| 1316 | - if ($octets >= 1) { |
|
| 1317 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1318 | - $systeme = strtolower($systeme); |
|
| 1319 | - if ($systeme === 'bi') { |
|
| 1320 | - $kilo = 1024; |
|
| 1321 | - $suffixe_item = "_$systeme"; |
|
| 1322 | - } elseif ($systeme === 'si') { |
|
| 1323 | - $kilo = 1000; |
|
| 1324 | - $suffixe_item = ''; |
|
| 1325 | - } else { |
|
| 1326 | - return $affichage; |
|
| 1327 | - } |
|
| 1316 | + if ($octets >= 1) { |
|
| 1317 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1318 | + $systeme = strtolower($systeme); |
|
| 1319 | + if ($systeme === 'bi') { |
|
| 1320 | + $kilo = 1024; |
|
| 1321 | + $suffixe_item = "_$systeme"; |
|
| 1322 | + } elseif ($systeme === 'si') { |
|
| 1323 | + $kilo = 1000; |
|
| 1324 | + $suffixe_item = ''; |
|
| 1325 | + } else { |
|
| 1326 | + return $affichage; |
|
| 1327 | + } |
|
| 1328 | 1328 | |
| 1329 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1330 | - $puissance = floor(log($octets, $kilo)); |
|
| 1329 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1330 | + $puissance = floor(log($octets, $kilo)); |
|
| 1331 | 1331 | |
| 1332 | - // Calcul de la taille et choix de l'unité |
|
| 1333 | - $affichage = _T( |
|
| 1334 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1335 | - [ |
|
| 1336 | - 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1337 | - ] |
|
| 1338 | - ); |
|
| 1339 | - } |
|
| 1332 | + // Calcul de la taille et choix de l'unité |
|
| 1333 | + $affichage = _T( |
|
| 1334 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1335 | + [ |
|
| 1336 | + 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1337 | + ] |
|
| 1338 | + ); |
|
| 1339 | + } |
|
| 1340 | 1340 | |
| 1341 | - return $affichage; |
|
| 1341 | + return $affichage; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | |
@@ -1360,21 +1360,21 @@ discard block |
||
| 1360 | 1360 | * texte prêt pour être utilisé en attribut HTML |
| 1361 | 1361 | **/ |
| 1362 | 1362 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1363 | - if ($texte === null) { |
|
| 1364 | - return ''; |
|
| 1365 | - } |
|
| 1366 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1367 | - if ($textebrut) { |
|
| 1368 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1369 | - } |
|
| 1370 | - $texte = texte_backend($texte); |
|
| 1371 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1363 | + if ($texte === null) { |
|
| 1364 | + return ''; |
|
| 1365 | + } |
|
| 1366 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1367 | + if ($textebrut) { |
|
| 1368 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1369 | + } |
|
| 1370 | + $texte = texte_backend($texte); |
|
| 1371 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1372 | 1372 | |
| 1373 | - return preg_replace( |
|
| 1374 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1375 | - ['&', '&'], |
|
| 1376 | - $texte |
|
| 1377 | - ); |
|
| 1373 | + return preg_replace( |
|
| 1374 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1375 | + ['&', '&'], |
|
| 1376 | + $texte |
|
| 1377 | + ); |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | |
@@ -1394,15 +1394,15 @@ discard block |
||
| 1394 | 1394 | * URL ou chaîne vide |
| 1395 | 1395 | **/ |
| 1396 | 1396 | function vider_url(?string $url, $entites = true): string { |
| 1397 | - if ($url === null) { |
|
| 1398 | - return ''; |
|
| 1399 | - } |
|
| 1400 | - # un message pour abs_url |
|
| 1401 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1402 | - $url = trim($url); |
|
| 1403 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1397 | + if ($url === null) { |
|
| 1398 | + return ''; |
|
| 1399 | + } |
|
| 1400 | + # un message pour abs_url |
|
| 1401 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1402 | + $url = trim($url); |
|
| 1403 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1404 | 1404 | |
| 1405 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1405 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | |
@@ -1417,10 +1417,10 @@ discard block |
||
| 1417 | 1417 | * @return string Adresse email maquillée |
| 1418 | 1418 | **/ |
| 1419 | 1419 | function antispam($texte) { |
| 1420 | - include_spip('inc/acces'); |
|
| 1421 | - $masque = creer_pass_aleatoire(3); |
|
| 1420 | + include_spip('inc/acces'); |
|
| 1421 | + $masque = creer_pass_aleatoire(3); |
|
| 1422 | 1422 | |
| 1423 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1423 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | /** |
@@ -1452,8 +1452,8 @@ discard block |
||
| 1452 | 1452 | * True si on a le droit d'accès, false sinon. |
| 1453 | 1453 | **/ |
| 1454 | 1454 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1455 | - include_spip('inc/acces'); |
|
| 1456 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1455 | + include_spip('inc/acces'); |
|
| 1456 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | /** |
@@ -1477,13 +1477,13 @@ discard block |
||
| 1477 | 1477 | * Retourne $texte, sinon $sinon. |
| 1478 | 1478 | **/ |
| 1479 | 1479 | function sinon(mixed $texte, mixed $sinon = '') { |
| 1480 | - if ($texte) { |
|
| 1481 | - return $texte; |
|
| 1482 | - } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1483 | - return $texte; |
|
| 1484 | - } else { |
|
| 1485 | - return $sinon; |
|
| 1486 | - } |
|
| 1480 | + if ($texte) { |
|
| 1481 | + return $texte; |
|
| 1482 | + } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1483 | + return $texte; |
|
| 1484 | + } else { |
|
| 1485 | + return $sinon; |
|
| 1486 | + } |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | /** |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | * @return mixed |
| 1508 | 1508 | **/ |
| 1509 | 1509 | function choixsivide(mixed $a, mixed $vide, mixed $pasvide) { |
| 1510 | - return $a ? $pasvide : $vide; |
|
| 1510 | + return $a ? $pasvide : $vide; |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | * @return mixed |
| 1532 | 1532 | **/ |
| 1533 | 1533 | function choixsiegal(mixed $a1, mixed $a2, mixed $v, mixed $f) { |
| 1534 | - return ($a1 == $a2) ? $v : $f; |
|
| 1534 | + return ($a1 == $a2) ? $v : $f; |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | // |
@@ -1550,12 +1550,12 @@ discard block |
||
| 1550 | 1550 | * @return string |
| 1551 | 1551 | **/ |
| 1552 | 1552 | function filtrer_ical($texte) { |
| 1553 | - #include_spip('inc/charsets'); |
|
| 1554 | - $texte = html2unicode($texte); |
|
| 1555 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1556 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1553 | + #include_spip('inc/charsets'); |
|
| 1554 | + $texte = html2unicode($texte); |
|
| 1555 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1556 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1557 | 1557 | |
| 1558 | - return preg_replace('/,/', '\,', $texte); |
|
| 1558 | + return preg_replace('/,/', '\,', $texte); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | |
@@ -1580,58 +1580,58 @@ discard block |
||
| 1580 | 1580 | * @return string |
| 1581 | 1581 | **/ |
| 1582 | 1582 | function post_autobr($texte, $delim = "\n_ ") { |
| 1583 | - if (!function_exists('echappe_html')) { |
|
| 1584 | - include_spip('inc/texte_mini'); |
|
| 1585 | - } |
|
| 1586 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1587 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1588 | - |
|
| 1589 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1590 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1591 | - } else { |
|
| 1592 | - $fin = ''; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - $texte = echappe_html($texte, '', true); |
|
| 1596 | - |
|
| 1597 | - // echapper les modeles |
|
| 1598 | - $collecteurModeles = null; |
|
| 1599 | - if (str_contains($texte, '<')) { |
|
| 1600 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1601 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 1602 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1603 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - $debut = ''; |
|
| 1607 | - $suite = $texte; |
|
| 1608 | - while ($t = strpos((string) ('-' . $suite), "\n", 1)) { |
|
| 1609 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1610 | - $suite = substr($suite, $t); |
|
| 1611 | - $car = substr($suite, 0, 1); |
|
| 1612 | - if ( |
|
| 1613 | - $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1614 | - && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1615 | - && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1616 | - ) { |
|
| 1617 | - $debut .= $delim; |
|
| 1618 | - } else { |
|
| 1619 | - $debut .= "\n"; |
|
| 1620 | - } |
|
| 1621 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1622 | - $debut .= $regs[0]; |
|
| 1623 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1624 | - } |
|
| 1625 | - } |
|
| 1626 | - $texte = $debut . $suite; |
|
| 1627 | - |
|
| 1628 | - if ($collecteurModeles) { |
|
| 1629 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - $texte = echappe_retour($texte); |
|
| 1633 | - |
|
| 1634 | - return $texte . $fin; |
|
| 1583 | + if (!function_exists('echappe_html')) { |
|
| 1584 | + include_spip('inc/texte_mini'); |
|
| 1585 | + } |
|
| 1586 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1587 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1588 | + |
|
| 1589 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1590 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1591 | + } else { |
|
| 1592 | + $fin = ''; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + $texte = echappe_html($texte, '', true); |
|
| 1596 | + |
|
| 1597 | + // echapper les modeles |
|
| 1598 | + $collecteurModeles = null; |
|
| 1599 | + if (str_contains($texte, '<')) { |
|
| 1600 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1601 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 1602 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1603 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + $debut = ''; |
|
| 1607 | + $suite = $texte; |
|
| 1608 | + while ($t = strpos((string) ('-' . $suite), "\n", 1)) { |
|
| 1609 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1610 | + $suite = substr($suite, $t); |
|
| 1611 | + $car = substr($suite, 0, 1); |
|
| 1612 | + if ( |
|
| 1613 | + $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1614 | + && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1615 | + && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1616 | + ) { |
|
| 1617 | + $debut .= $delim; |
|
| 1618 | + } else { |
|
| 1619 | + $debut .= "\n"; |
|
| 1620 | + } |
|
| 1621 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1622 | + $debut .= $regs[0]; |
|
| 1623 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1624 | + } |
|
| 1625 | + } |
|
| 1626 | + $texte = $debut . $suite; |
|
| 1627 | + |
|
| 1628 | + if ($collecteurModeles) { |
|
| 1629 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + $texte = echappe_retour($texte); |
|
| 1633 | + |
|
| 1634 | + return $texte . $fin; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | |
@@ -1666,26 +1666,26 @@ discard block |
||
| 1666 | 1666 | **/ |
| 1667 | 1667 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1668 | 1668 | |
| 1669 | - if ($letexte && str_contains($letexte, '<:')) { |
|
| 1670 | - if (!$lang) { |
|
| 1671 | - $lang = $GLOBALS['spip_lang']; |
|
| 1672 | - } |
|
| 1673 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1674 | - if (is_bool($options)) { |
|
| 1675 | - $options = ['echappe_span' => $options]; |
|
| 1676 | - } |
|
| 1677 | - if (!isset($options['echappe_span'])) { |
|
| 1678 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1679 | - } |
|
| 1680 | - $options['lang'] = $lang; |
|
| 1669 | + if ($letexte && str_contains($letexte, '<:')) { |
|
| 1670 | + if (!$lang) { |
|
| 1671 | + $lang = $GLOBALS['spip_lang']; |
|
| 1672 | + } |
|
| 1673 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1674 | + if (is_bool($options)) { |
|
| 1675 | + $options = ['echappe_span' => $options]; |
|
| 1676 | + } |
|
| 1677 | + if (!isset($options['echappe_span'])) { |
|
| 1678 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1679 | + } |
|
| 1680 | + $options['lang'] = $lang; |
|
| 1681 | 1681 | |
| 1682 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1683 | - include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 1684 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1682 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1683 | + include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 1684 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1685 | 1685 | |
| 1686 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1687 | - } |
|
| 1688 | - return $letexte; |
|
| 1686 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1687 | + } |
|
| 1688 | + return $letexte; |
|
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | /** |
@@ -1723,31 +1723,31 @@ discard block |
||
| 1723 | 1723 | **/ |
| 1724 | 1724 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1725 | 1725 | |
| 1726 | - if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1727 | - if (!$lang) { |
|
| 1728 | - $lang = $GLOBALS['spip_lang']; |
|
| 1729 | - } |
|
| 1726 | + if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1727 | + if (!$lang) { |
|
| 1728 | + $lang = $GLOBALS['spip_lang']; |
|
| 1729 | + } |
|
| 1730 | 1730 | |
| 1731 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1732 | - if (is_bool($options)) { |
|
| 1733 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1734 | - } |
|
| 1735 | - if (!isset($options['echappe_span'])) { |
|
| 1736 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1737 | - } |
|
| 1738 | - if (!isset($options['lang_defaut'])) { |
|
| 1739 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1740 | - } |
|
| 1741 | - $options['lang'] = $lang; |
|
| 1731 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1732 | + if (is_bool($options)) { |
|
| 1733 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1734 | + } |
|
| 1735 | + if (!isset($options['echappe_span'])) { |
|
| 1736 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1737 | + } |
|
| 1738 | + if (!isset($options['lang_defaut'])) { |
|
| 1739 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1740 | + } |
|
| 1741 | + $options['lang'] = $lang; |
|
| 1742 | 1742 | |
| 1743 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1744 | - include_spip('src/Texte/Collecteur/Multis'); |
|
| 1745 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1743 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1744 | + include_spip('src/Texte/Collecteur/Multis'); |
|
| 1745 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1746 | 1746 | |
| 1747 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1748 | - } |
|
| 1747 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1748 | + } |
|
| 1749 | 1749 | |
| 1750 | - return $letexte; |
|
| 1750 | + return $letexte; |
|
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | 1753 | /** |
@@ -1757,7 +1757,7 @@ discard block |
||
| 1757 | 1757 | * @return string L'initiale en majuscule |
| 1758 | 1758 | */ |
| 1759 | 1759 | function filtre_initiale($nom) { |
| 1760 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1760 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1761 | 1761 | } |
| 1762 | 1762 | |
| 1763 | 1763 | |
@@ -1802,33 +1802,33 @@ discard block |
||
| 1802 | 1802 | * - null (interne) : si on empile |
| 1803 | 1803 | **/ |
| 1804 | 1804 | function unique($donnee, $famille = '', $cpt = false) { |
| 1805 | - static $mem = []; |
|
| 1806 | - // permettre de vider la pile et de la restaurer |
|
| 1807 | - // pour le calcul de introduction... |
|
| 1808 | - if ($famille == '_spip_raz_') { |
|
| 1809 | - $tmp = $mem; |
|
| 1810 | - $mem = []; |
|
| 1811 | - |
|
| 1812 | - return $tmp; |
|
| 1813 | - } elseif ($famille == '_spip_set_') { |
|
| 1814 | - $mem = $donnee; |
|
| 1815 | - |
|
| 1816 | - return; |
|
| 1817 | - } |
|
| 1818 | - // eviter une notice |
|
| 1819 | - if (!isset($mem[$famille])) { |
|
| 1820 | - $mem[$famille] = []; |
|
| 1821 | - } |
|
| 1822 | - if ($cpt) { |
|
| 1823 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1824 | - } |
|
| 1825 | - // eviter une notice |
|
| 1826 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1827 | - $mem[$famille][$donnee] = 0; |
|
| 1828 | - } |
|
| 1829 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1830 | - return $donnee; |
|
| 1831 | - } |
|
| 1805 | + static $mem = []; |
|
| 1806 | + // permettre de vider la pile et de la restaurer |
|
| 1807 | + // pour le calcul de introduction... |
|
| 1808 | + if ($famille == '_spip_raz_') { |
|
| 1809 | + $tmp = $mem; |
|
| 1810 | + $mem = []; |
|
| 1811 | + |
|
| 1812 | + return $tmp; |
|
| 1813 | + } elseif ($famille == '_spip_set_') { |
|
| 1814 | + $mem = $donnee; |
|
| 1815 | + |
|
| 1816 | + return; |
|
| 1817 | + } |
|
| 1818 | + // eviter une notice |
|
| 1819 | + if (!isset($mem[$famille])) { |
|
| 1820 | + $mem[$famille] = []; |
|
| 1821 | + } |
|
| 1822 | + if ($cpt) { |
|
| 1823 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1824 | + } |
|
| 1825 | + // eviter une notice |
|
| 1826 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1827 | + $mem[$famille][$donnee] = 0; |
|
| 1828 | + } |
|
| 1829 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1830 | + return $donnee; |
|
| 1831 | + } |
|
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | |
@@ -1858,20 +1858,20 @@ discard block |
||
| 1858 | 1858 | * Une des valeurs en fonction du compteur. |
| 1859 | 1859 | **/ |
| 1860 | 1860 | function alterner($i, ...$args) { |
| 1861 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1862 | - $num = count($args); |
|
| 1861 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1862 | + $num = count($args); |
|
| 1863 | 1863 | |
| 1864 | - if ($num === 1 && is_array($args[0])) { |
|
| 1865 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1866 | - $args = array_values($args[0]); |
|
| 1867 | - $num = count($args); |
|
| 1868 | - } |
|
| 1864 | + if ($num === 1 && is_array($args[0])) { |
|
| 1865 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1866 | + $args = array_values($args[0]); |
|
| 1867 | + $num = count($args); |
|
| 1868 | + } |
|
| 1869 | 1869 | |
| 1870 | - // un index compris entre 0 et num exclus |
|
| 1871 | - $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1872 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1873 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | - return $args[$i]; |
|
| 1870 | + // un index compris entre 0 et num exclus |
|
| 1871 | + $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1872 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1873 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | + return $args[$i]; |
|
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | 1877 | |
@@ -1897,52 +1897,52 @@ discard block |
||
| 1897 | 1897 | * - null lorsque l’attribut n’existe pas. |
| 1898 | 1898 | **/ |
| 1899 | 1899 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1900 | - if (is_array($balise)) { |
|
| 1901 | - array_walk( |
|
| 1902 | - $balise, |
|
| 1903 | - function (&$a, $key, $t) { |
|
| 1904 | - $a = extraire_attribut($a, $t); |
|
| 1905 | - }, |
|
| 1906 | - $attribut |
|
| 1907 | - ); |
|
| 1908 | - |
|
| 1909 | - return $balise; |
|
| 1910 | - } |
|
| 1911 | - if ( |
|
| 1912 | - $balise |
|
| 1913 | - && stripos($balise, $attribut) !== false |
|
| 1914 | - && preg_match( |
|
| 1915 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1916 | - . $attribut |
|
| 1917 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1918 | - $balise, |
|
| 1919 | - $r |
|
| 1920 | - ) |
|
| 1921 | - ) { |
|
| 1922 | - if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1923 | - $r[4] = substr($r[3], 1, -1); |
|
| 1924 | - $r[3] = $r[3][0]; |
|
| 1925 | - } elseif ($r[3] !== '') { |
|
| 1926 | - $r[4] = $r[3]; |
|
| 1927 | - $r[3] = ''; |
|
| 1928 | - } else { |
|
| 1929 | - $r[4] = trim($r[2]); |
|
| 1930 | - } |
|
| 1931 | - $att = $r[4]; |
|
| 1932 | - if (str_contains($att, '&#')) { |
|
| 1933 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1934 | - } |
|
| 1935 | - $att = filtrer_entites($att); |
|
| 1936 | - } else { |
|
| 1937 | - $att = null; |
|
| 1938 | - $r = []; |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - if ($complet) { |
|
| 1942 | - return [$att, $r]; |
|
| 1943 | - } else { |
|
| 1944 | - return $att; |
|
| 1945 | - } |
|
| 1900 | + if (is_array($balise)) { |
|
| 1901 | + array_walk( |
|
| 1902 | + $balise, |
|
| 1903 | + function (&$a, $key, $t) { |
|
| 1904 | + $a = extraire_attribut($a, $t); |
|
| 1905 | + }, |
|
| 1906 | + $attribut |
|
| 1907 | + ); |
|
| 1908 | + |
|
| 1909 | + return $balise; |
|
| 1910 | + } |
|
| 1911 | + if ( |
|
| 1912 | + $balise |
|
| 1913 | + && stripos($balise, $attribut) !== false |
|
| 1914 | + && preg_match( |
|
| 1915 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1916 | + . $attribut |
|
| 1917 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1918 | + $balise, |
|
| 1919 | + $r |
|
| 1920 | + ) |
|
| 1921 | + ) { |
|
| 1922 | + if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1923 | + $r[4] = substr($r[3], 1, -1); |
|
| 1924 | + $r[3] = $r[3][0]; |
|
| 1925 | + } elseif ($r[3] !== '') { |
|
| 1926 | + $r[4] = $r[3]; |
|
| 1927 | + $r[3] = ''; |
|
| 1928 | + } else { |
|
| 1929 | + $r[4] = trim($r[2]); |
|
| 1930 | + } |
|
| 1931 | + $att = $r[4]; |
|
| 1932 | + if (str_contains($att, '&#')) { |
|
| 1933 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1934 | + } |
|
| 1935 | + $att = filtrer_entites($att); |
|
| 1936 | + } else { |
|
| 1937 | + $att = null; |
|
| 1938 | + $r = []; |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + if ($complet) { |
|
| 1942 | + return [$att, $r]; |
|
| 1943 | + } else { |
|
| 1944 | + return $att; |
|
| 1945 | + } |
|
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | /** |
@@ -1975,37 +1975,37 @@ discard block |
||
| 1975 | 1975 | **/ |
| 1976 | 1976 | function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string { |
| 1977 | 1977 | |
| 1978 | - if ($balise === null || $balise === '') { |
|
| 1979 | - return ''; |
|
| 1980 | - } |
|
| 1978 | + if ($balise === null || $balise === '') { |
|
| 1979 | + return ''; |
|
| 1980 | + } |
|
| 1981 | 1981 | |
| 1982 | - // preparer l'attribut |
|
| 1983 | - // supprimer les etc mais pas les balises html |
|
| 1984 | - // qui ont un sens dans un attribut value d'un input |
|
| 1985 | - if ($proteger) { |
|
| 1986 | - $val = attribut_html($val, false); |
|
| 1987 | - } |
|
| 1982 | + // preparer l'attribut |
|
| 1983 | + // supprimer les etc mais pas les balises html |
|
| 1984 | + // qui ont un sens dans un attribut value d'un input |
|
| 1985 | + if ($proteger) { |
|
| 1986 | + $val = attribut_html($val, false); |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - // echapper les ' pour eviter tout bug |
|
| 1990 | - $val = str_replace("'", ''', $val ?? ''); |
|
| 1991 | - $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1989 | + // echapper les ' pour eviter tout bug |
|
| 1990 | + $val = str_replace("'", ''', $val ?? ''); |
|
| 1991 | + $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1992 | 1992 | |
| 1993 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1993 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1994 | 1994 | |
| 1995 | - if ($old !== null) { |
|
| 1996 | - // Remplacer l'ancien attribut du meme nom |
|
| 1997 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1998 | - } else { |
|
| 1999 | - // preferer une balise " />" (comme <img />) |
|
| 2000 | - if (preg_match(',/>,', $balise)) { |
|
| 2001 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2002 | - } // sinon une balise <a ...> ... </a> |
|
| 2003 | - else { |
|
| 2004 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2005 | - } |
|
| 2006 | - } |
|
| 1995 | + if ($old !== null) { |
|
| 1996 | + // Remplacer l'ancien attribut du meme nom |
|
| 1997 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1998 | + } else { |
|
| 1999 | + // preferer une balise " />" (comme <img />) |
|
| 2000 | + if (preg_match(',/>,', $balise)) { |
|
| 2001 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2002 | + } // sinon une balise <a ...> ... </a> |
|
| 2003 | + else { |
|
| 2004 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2005 | + } |
|
| 2006 | + } |
|
| 2007 | 2007 | |
| 2008 | - return $balise; |
|
| 2008 | + return $balise; |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | /** |
@@ -2023,7 +2023,7 @@ discard block |
||
| 2023 | 2023 | * @return string Code HTML sans l'attribut |
| 2024 | 2024 | **/ |
| 2025 | 2025 | function vider_attribut(?string $balise, string $attribut): string { |
| 2026 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2026 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2027 | 2027 | } |
| 2028 | 2028 | |
| 2029 | 2029 | /** |
@@ -2035,50 +2035,50 @@ discard block |
||
| 2035 | 2035 | * @return string |
| 2036 | 2036 | */ |
| 2037 | 2037 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2038 | - if (is_string($class)) { |
|
| 2039 | - $class = explode(' ', trim($class)); |
|
| 2040 | - } |
|
| 2041 | - $class = array_filter($class); |
|
| 2042 | - $class = array_unique($class); |
|
| 2043 | - if (!$class) { |
|
| 2044 | - return $balise; |
|
| 2045 | - } |
|
| 2046 | - |
|
| 2047 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2048 | - $class_new = $class_courante; |
|
| 2049 | - foreach ($class as $c) { |
|
| 2050 | - $is_class_presente = false; |
|
| 2051 | - if ( |
|
| 2052 | - $class_courante |
|
| 2053 | - && str_contains($class_courante, (string) $c) |
|
| 2054 | - && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2055 | - ) { |
|
| 2056 | - $is_class_presente = true; |
|
| 2057 | - } |
|
| 2058 | - if ( |
|
| 2059 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2060 | - && !$is_class_presente |
|
| 2061 | - ) { |
|
| 2062 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2063 | - } elseif ( |
|
| 2064 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2065 | - && $is_class_presente |
|
| 2066 | - ) { |
|
| 2067 | - $class_new = preg_split(',\s+,', $class_new); |
|
| 2068 | - $class_new = array_diff($class_new, [$c]); |
|
| 2069 | - $class_new = implode(' ', $class_new); |
|
| 2070 | - } |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - if ($class_new !== $class_courante) { |
|
| 2074 | - if (strlen($class_new)) { |
|
| 2075 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2076 | - } elseif ($class_courante) { |
|
| 2077 | - $balise = vider_attribut($balise, 'class'); |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - return $balise; |
|
| 2038 | + if (is_string($class)) { |
|
| 2039 | + $class = explode(' ', trim($class)); |
|
| 2040 | + } |
|
| 2041 | + $class = array_filter($class); |
|
| 2042 | + $class = array_unique($class); |
|
| 2043 | + if (!$class) { |
|
| 2044 | + return $balise; |
|
| 2045 | + } |
|
| 2046 | + |
|
| 2047 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2048 | + $class_new = $class_courante; |
|
| 2049 | + foreach ($class as $c) { |
|
| 2050 | + $is_class_presente = false; |
|
| 2051 | + if ( |
|
| 2052 | + $class_courante |
|
| 2053 | + && str_contains($class_courante, (string) $c) |
|
| 2054 | + && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2055 | + ) { |
|
| 2056 | + $is_class_presente = true; |
|
| 2057 | + } |
|
| 2058 | + if ( |
|
| 2059 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2060 | + && !$is_class_presente |
|
| 2061 | + ) { |
|
| 2062 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2063 | + } elseif ( |
|
| 2064 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2065 | + && $is_class_presente |
|
| 2066 | + ) { |
|
| 2067 | + $class_new = preg_split(',\s+,', $class_new); |
|
| 2068 | + $class_new = array_diff($class_new, [$c]); |
|
| 2069 | + $class_new = implode(' ', $class_new); |
|
| 2070 | + } |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + if ($class_new !== $class_courante) { |
|
| 2074 | + if (strlen($class_new)) { |
|
| 2075 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2076 | + } elseif ($class_courante) { |
|
| 2077 | + $balise = vider_attribut($balise, 'class'); |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + return $balise; |
|
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | 2084 | /** |
@@ -2088,7 +2088,7 @@ discard block |
||
| 2088 | 2088 | * @return string |
| 2089 | 2089 | */ |
| 2090 | 2090 | function ajouter_class($balise, $class) { |
| 2091 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2091 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2092 | 2092 | } |
| 2093 | 2093 | |
| 2094 | 2094 | /** |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | * @return string |
| 2099 | 2099 | */ |
| 2100 | 2100 | function supprimer_class($balise, $class) { |
| 2101 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2101 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | /** |
@@ -2109,7 +2109,7 @@ discard block |
||
| 2109 | 2109 | * @return string |
| 2110 | 2110 | */ |
| 2111 | 2111 | function commuter_class($balise, $class) { |
| 2112 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2112 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
@@ -2120,19 +2120,19 @@ discard block |
||
| 2120 | 2120 | * @return string |
| 2121 | 2121 | */ |
| 2122 | 2122 | function tester_config($id, $mode = '') { |
| 2123 | - include_spip('action/inscrire_auteur'); |
|
| 2123 | + include_spip('action/inscrire_auteur'); |
|
| 2124 | 2124 | |
| 2125 | - return tester_statut_inscription($mode, $id); |
|
| 2125 | + return tester_statut_inscription($mode, $id); |
|
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 2128 | 2128 | // |
| 2129 | 2129 | // Quelques fonctions de calcul arithmetique |
| 2130 | 2130 | // |
| 2131 | 2131 | function floatstr($a) { |
| 2132 | - return str_replace(',', '.', (string)(float) $a); |
|
| 2132 | + return str_replace(',', '.', (string)(float) $a); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | function strize($f, $a, $b) { |
| 2135 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2135 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | /** |
@@ -2151,11 +2151,11 @@ discard block |
||
| 2151 | 2151 | * @return int $a+$b |
| 2152 | 2152 | **/ |
| 2153 | 2153 | function plus($a, $b) { |
| 2154 | - return $a + $b; |
|
| 2154 | + return $a + $b; |
|
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | 2157 | function strplus($a, $b) { |
| 2158 | - return strize('plus', $a, $b); |
|
| 2158 | + return strize('plus', $a, $b); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2174,11 +2174,11 @@ discard block |
||
| 2174 | 2174 | * @return int $a-$b |
| 2175 | 2175 | **/ |
| 2176 | 2176 | function moins($a, $b) { |
| 2177 | - return $a - $b; |
|
| 2177 | + return $a - $b; |
|
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | function strmoins($a, $b) { |
| 2181 | - return strize('moins', $a, $b); |
|
| 2181 | + return strize('moins', $a, $b); |
|
| 2182 | 2182 | } |
| 2183 | 2183 | |
| 2184 | 2184 | /** |
@@ -2198,11 +2198,11 @@ discard block |
||
| 2198 | 2198 | * @return int $a*$b |
| 2199 | 2199 | **/ |
| 2200 | 2200 | function mult($a, $b) { |
| 2201 | - return $a * $b; |
|
| 2201 | + return $a * $b; |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | function strmult($a, $b) { |
| 2205 | - return strize('mult', $a, $b); |
|
| 2205 | + return strize('mult', $a, $b); |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | /** |
@@ -2222,11 +2222,11 @@ discard block |
||
| 2222 | 2222 | * @return int $a/$b (ou 0 si $b est nul) |
| 2223 | 2223 | **/ |
| 2224 | 2224 | function div($a, $b) { |
| 2225 | - return $b ? $a / $b : 0; |
|
| 2225 | + return $b ? $a / $b : 0; |
|
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | function strdiv($a, $b) { |
| 2229 | - return strize('div', $a, $b); |
|
| 2229 | + return strize('div', $a, $b); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2247,7 +2247,7 @@ discard block |
||
| 2247 | 2247 | * @return int ($nb % $mod) + $add |
| 2248 | 2248 | **/ |
| 2249 | 2249 | function modulo($nb, $mod, $add = 0) { |
| 2250 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2250 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | |
@@ -2262,26 +2262,26 @@ discard block |
||
| 2262 | 2262 | * - true sinon |
| 2263 | 2263 | **/ |
| 2264 | 2264 | function nom_acceptable($nom) { |
| 2265 | - $remp2 = []; |
|
| 2266 | - $remp1 = []; |
|
| 2267 | - if (!is_string($nom)) { |
|
| 2268 | - return false; |
|
| 2269 | - } |
|
| 2270 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2271 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2272 | - } |
|
| 2273 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2274 | - foreach ($tags_acceptes as $tag) { |
|
| 2275 | - if (strlen($tag)) { |
|
| 2276 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2280 | - } |
|
| 2281 | - } |
|
| 2282 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2283 | - |
|
| 2284 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2265 | + $remp2 = []; |
|
| 2266 | + $remp1 = []; |
|
| 2267 | + if (!is_string($nom)) { |
|
| 2268 | + return false; |
|
| 2269 | + } |
|
| 2270 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2271 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2272 | + } |
|
| 2273 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2274 | + foreach ($tags_acceptes as $tag) { |
|
| 2275 | + if (strlen($tag)) { |
|
| 2276 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2280 | + } |
|
| 2281 | + } |
|
| 2282 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2283 | + |
|
| 2284 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | |
@@ -2297,13 +2297,13 @@ discard block |
||
| 2297 | 2297 | * - renvoie un tableau si l'entree est un tableau |
| 2298 | 2298 | **/ |
| 2299 | 2299 | function email_valide($adresses) { |
| 2300 | - if (is_array($adresses)) { |
|
| 2301 | - $adresses = array_map('email_valide', $adresses); |
|
| 2302 | - return array_filter($adresses); |
|
| 2303 | - } |
|
| 2300 | + if (is_array($adresses)) { |
|
| 2301 | + $adresses = array_map('email_valide', $adresses); |
|
| 2302 | + return array_filter($adresses); |
|
| 2303 | + } |
|
| 2304 | 2304 | |
| 2305 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2306 | - return $email_valide($adresses); |
|
| 2305 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2306 | + return $email_valide($adresses); |
|
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | /** |
@@ -2317,29 +2317,29 @@ discard block |
||
| 2317 | 2317 | * @return string texte |
| 2318 | 2318 | **/ |
| 2319 | 2319 | function afficher_enclosures($tags) { |
| 2320 | - $s = []; |
|
| 2321 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2322 | - if ( |
|
| 2323 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2324 | - && ($t = extraire_attribut($tag, 'href')) |
|
| 2325 | - ) { |
|
| 2326 | - $s[] = preg_replace( |
|
| 2327 | - ',>[^<]+</a>,S', |
|
| 2328 | - '>' |
|
| 2329 | - . http_img_pack( |
|
| 2330 | - 'attachment-16.png', |
|
| 2331 | - $t, |
|
| 2332 | - '', |
|
| 2333 | - $t, |
|
| 2334 | - ['utiliser_suffixe_size' => true] |
|
| 2335 | - ) |
|
| 2336 | - . '</a>', |
|
| 2337 | - (string) $tag |
|
| 2338 | - ); |
|
| 2339 | - } |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - return implode(' ', $s); |
|
| 2320 | + $s = []; |
|
| 2321 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2322 | + if ( |
|
| 2323 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2324 | + && ($t = extraire_attribut($tag, 'href')) |
|
| 2325 | + ) { |
|
| 2326 | + $s[] = preg_replace( |
|
| 2327 | + ',>[^<]+</a>,S', |
|
| 2328 | + '>' |
|
| 2329 | + . http_img_pack( |
|
| 2330 | + 'attachment-16.png', |
|
| 2331 | + $t, |
|
| 2332 | + '', |
|
| 2333 | + $t, |
|
| 2334 | + ['utiliser_suffixe_size' => true] |
|
| 2335 | + ) |
|
| 2336 | + . '</a>', |
|
| 2337 | + (string) $tag |
|
| 2338 | + ); |
|
| 2339 | + } |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + return implode(' ', $s); |
|
| 2343 | 2343 | } |
| 2344 | 2344 | |
| 2345 | 2345 | /** |
@@ -2354,15 +2354,15 @@ discard block |
||
| 2354 | 2354 | * @return string Liens trouvés |
| 2355 | 2355 | **/ |
| 2356 | 2356 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2357 | - $s = []; |
|
| 2358 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2359 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2360 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2361 | - $s[] = $tag; |
|
| 2362 | - } |
|
| 2363 | - } |
|
| 2357 | + $s = []; |
|
| 2358 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2359 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2360 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2361 | + $s[] = $tag; |
|
| 2362 | + } |
|
| 2363 | + } |
|
| 2364 | 2364 | |
| 2365 | - return implode(', ', $s); |
|
| 2365 | + return implode(', ', $s); |
|
| 2366 | 2366 | } |
| 2367 | 2367 | |
| 2368 | 2368 | |
@@ -2384,21 +2384,21 @@ discard block |
||
| 2384 | 2384 | * @return string Tag HTML `<a>` avec microformat. |
| 2385 | 2385 | **/ |
| 2386 | 2386 | function enclosure2microformat($e) { |
| 2387 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2388 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2389 | - } |
|
| 2390 | - $type = extraire_attribut($e, 'type'); |
|
| 2391 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2392 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2393 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2394 | - } |
|
| 2395 | - $fichier = basename($url); |
|
| 2387 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2388 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2389 | + } |
|
| 2390 | + $type = extraire_attribut($e, 'type'); |
|
| 2391 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2392 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2393 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2394 | + } |
|
| 2395 | + $fichier = basename($url); |
|
| 2396 | 2396 | |
| 2397 | - return '<a rel="enclosure"' |
|
| 2398 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | - . '>' . $fichier . '</a>'; |
|
| 2397 | + return '<a rel="enclosure"' |
|
| 2398 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | + . '>' . $fichier . '</a>'; |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2416,24 +2416,24 @@ discard block |
||
| 2416 | 2416 | * @return string Tags RSS `<enclosure>`. |
| 2417 | 2417 | **/ |
| 2418 | 2418 | function microformat2enclosure($tags) { |
| 2419 | - $enclosures = []; |
|
| 2420 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2421 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2422 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2423 | - $type = extraire_attribut($e, 'type'); |
|
| 2424 | - if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2425 | - $length = (int) extraire_attribut($e, 'length'); |
|
| 2426 | - } # vieux data |
|
| 2427 | - $fichier = basename($url); |
|
| 2428 | - $enclosures[] = '<enclosure' |
|
| 2429 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2432 | - . ' />'; |
|
| 2433 | - } |
|
| 2434 | - } |
|
| 2419 | + $enclosures = []; |
|
| 2420 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2421 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2422 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2423 | + $type = extraire_attribut($e, 'type'); |
|
| 2424 | + if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2425 | + $length = (int) extraire_attribut($e, 'length'); |
|
| 2426 | + } # vieux data |
|
| 2427 | + $fichier = basename($url); |
|
| 2428 | + $enclosures[] = '<enclosure' |
|
| 2429 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2432 | + . ' />'; |
|
| 2433 | + } |
|
| 2434 | + } |
|
| 2435 | 2435 | |
| 2436 | - return implode("\n", $enclosures); |
|
| 2436 | + return implode("\n", $enclosures); |
|
| 2437 | 2437 | } |
| 2438 | 2438 | |
| 2439 | 2439 | |
@@ -2449,16 +2449,16 @@ discard block |
||
| 2449 | 2449 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2450 | 2450 | **/ |
| 2451 | 2451 | function tags2dcsubject($tags) { |
| 2452 | - $subjects = ''; |
|
| 2453 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2454 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2455 | - $subjects .= '<dc:subject>' |
|
| 2456 | - . texte_backend(textebrut($e)) |
|
| 2457 | - . '</dc:subject>' . "\n"; |
|
| 2458 | - } |
|
| 2459 | - } |
|
| 2452 | + $subjects = ''; |
|
| 2453 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2454 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2455 | + $subjects .= '<dc:subject>' |
|
| 2456 | + . texte_backend(textebrut($e)) |
|
| 2457 | + . '</dc:subject>' . "\n"; |
|
| 2458 | + } |
|
| 2459 | + } |
|
| 2460 | 2460 | |
| 2461 | - return $subjects; |
|
| 2461 | + return $subjects; |
|
| 2462 | 2462 | } |
| 2463 | 2463 | |
| 2464 | 2464 | /** |
@@ -2487,27 +2487,27 @@ discard block |
||
| 2487 | 2487 | * - Tableau de résultats, si tableau en entrée. |
| 2488 | 2488 | **/ |
| 2489 | 2489 | function extraire_balise($texte, $tag = 'a') { |
| 2490 | - if (is_array($texte)) { |
|
| 2491 | - array_walk( |
|
| 2492 | - $texte, |
|
| 2493 | - function (&$a, $key, $t) { |
|
| 2494 | - $a = extraire_balise($a, $t); |
|
| 2495 | - }, |
|
| 2496 | - $tag |
|
| 2497 | - ); |
|
| 2498 | - |
|
| 2499 | - return $texte; |
|
| 2500 | - } |
|
| 2501 | - |
|
| 2502 | - if ( |
|
| 2503 | - preg_match( |
|
| 2504 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2505 | - $texte, |
|
| 2506 | - $regs |
|
| 2507 | - ) |
|
| 2508 | - ) { |
|
| 2509 | - return $regs[0]; |
|
| 2510 | - } |
|
| 2490 | + if (is_array($texte)) { |
|
| 2491 | + array_walk( |
|
| 2492 | + $texte, |
|
| 2493 | + function (&$a, $key, $t) { |
|
| 2494 | + $a = extraire_balise($a, $t); |
|
| 2495 | + }, |
|
| 2496 | + $tag |
|
| 2497 | + ); |
|
| 2498 | + |
|
| 2499 | + return $texte; |
|
| 2500 | + } |
|
| 2501 | + |
|
| 2502 | + if ( |
|
| 2503 | + preg_match( |
|
| 2504 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2505 | + $texte, |
|
| 2506 | + $regs |
|
| 2507 | + ) |
|
| 2508 | + ) { |
|
| 2509 | + return $regs[0]; |
|
| 2510 | + } |
|
| 2511 | 2511 | } |
| 2512 | 2512 | |
| 2513 | 2513 | /** |
@@ -2535,30 +2535,30 @@ discard block |
||
| 2535 | 2535 | * - Tableau de résultats, si tableau en entrée. |
| 2536 | 2536 | **/ |
| 2537 | 2537 | function extraire_balises($texte, $tag = 'a') { |
| 2538 | - if (is_array($texte)) { |
|
| 2539 | - array_walk( |
|
| 2540 | - $texte, |
|
| 2541 | - function (&$a, $key, $t) { |
|
| 2542 | - $a = extraire_balises($a, $t); |
|
| 2543 | - }, |
|
| 2544 | - $tag |
|
| 2545 | - ); |
|
| 2546 | - |
|
| 2547 | - return $texte; |
|
| 2548 | - } |
|
| 2549 | - |
|
| 2550 | - if ( |
|
| 2551 | - preg_match_all( |
|
| 2552 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2553 | - $texte, |
|
| 2554 | - $regs, |
|
| 2555 | - PREG_PATTERN_ORDER |
|
| 2556 | - ) |
|
| 2557 | - ) { |
|
| 2558 | - return $regs[0]; |
|
| 2559 | - } else { |
|
| 2560 | - return []; |
|
| 2561 | - } |
|
| 2538 | + if (is_array($texte)) { |
|
| 2539 | + array_walk( |
|
| 2540 | + $texte, |
|
| 2541 | + function (&$a, $key, $t) { |
|
| 2542 | + $a = extraire_balises($a, $t); |
|
| 2543 | + }, |
|
| 2544 | + $tag |
|
| 2545 | + ); |
|
| 2546 | + |
|
| 2547 | + return $texte; |
|
| 2548 | + } |
|
| 2549 | + |
|
| 2550 | + if ( |
|
| 2551 | + preg_match_all( |
|
| 2552 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2553 | + $texte, |
|
| 2554 | + $regs, |
|
| 2555 | + PREG_PATTERN_ORDER |
|
| 2556 | + ) |
|
| 2557 | + ) { |
|
| 2558 | + return $regs[0]; |
|
| 2559 | + } else { |
|
| 2560 | + return []; |
|
| 2561 | + } |
|
| 2562 | 2562 | } |
| 2563 | 2563 | |
| 2564 | 2564 | /** |
@@ -2587,11 +2587,11 @@ discard block |
||
| 2587 | 2587 | * - `$def` si on n'a pas transmis de tableau |
| 2588 | 2588 | **/ |
| 2589 | 2589 | function in_any($val, $vals, $def = '') { |
| 2590 | - if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2591 | - $vals = $v; |
|
| 2592 | - } |
|
| 2590 | + if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2591 | + $vals = $v; |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | - return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2594 | + return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | |
@@ -2612,12 +2612,12 @@ discard block |
||
| 2612 | 2612 | * Résultat du calcul |
| 2613 | 2613 | **/ |
| 2614 | 2614 | function valeur_numerique($expr) { |
| 2615 | - $a = 0; |
|
| 2616 | - if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2617 | - eval("\$a = $expr;"); |
|
| 2618 | - } |
|
| 2615 | + $a = 0; |
|
| 2616 | + if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2617 | + eval("\$a = $expr;"); |
|
| 2618 | + } |
|
| 2619 | 2619 | |
| 2620 | - return (int) $a; |
|
| 2620 | + return (int) $a; |
|
| 2621 | 2621 | } |
| 2622 | 2622 | |
| 2623 | 2623 | /** |
@@ -2636,7 +2636,7 @@ discard block |
||
| 2636 | 2636 | * Retourne `$a*$b/$c` |
| 2637 | 2637 | **/ |
| 2638 | 2638 | function regledetrois($a, $b, $c) { |
| 2639 | - return round($a * $b / $c); |
|
| 2639 | + return round($a * $b / $c); |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | |
@@ -2659,79 +2659,79 @@ discard block |
||
| 2659 | 2659 | * @return string Suite de champs input hidden |
| 2660 | 2660 | **/ |
| 2661 | 2661 | function form_hidden(?string $action = ''): string { |
| 2662 | - $action ??= ''; |
|
| 2663 | - |
|
| 2664 | - $contexte = []; |
|
| 2665 | - include_spip('inc/urls'); |
|
| 2666 | - if ( |
|
| 2667 | - ($p = urls_decoder_url($action, '')) |
|
| 2668 | - && reset($p) |
|
| 2669 | - ) { |
|
| 2670 | - $fond = array_shift($p); |
|
| 2671 | - if ($fond != '404') { |
|
| 2672 | - $contexte = array_shift($p); |
|
| 2673 | - $contexte['page'] = $fond; |
|
| 2674 | - $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | - } |
|
| 2676 | - } |
|
| 2677 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2678 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2679 | - unset($contexte['type']); |
|
| 2680 | - } |
|
| 2681 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2682 | - unset($contexte['type-page']); |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2686 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2687 | - $values = []; |
|
| 2688 | - |
|
| 2689 | - // d'abord avec celles de l'url |
|
| 2690 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2691 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2692 | - $c = explode('=', (string) $c, 2); |
|
| 2693 | - $var = array_shift($c); |
|
| 2694 | - $val = array_shift($c) ?? ''; |
|
| 2695 | - if ($var) { |
|
| 2696 | - $val = rawurldecode($val); |
|
| 2697 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2698 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2699 | - $values[] = [$var, $val]; |
|
| 2700 | - } else { |
|
| 2701 | - if (!isset($values[$var])) { |
|
| 2702 | - $values[$var] = [$var, $val]; |
|
| 2703 | - } |
|
| 2704 | - } |
|
| 2705 | - } |
|
| 2706 | - } |
|
| 2707 | - } |
|
| 2708 | - |
|
| 2709 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2710 | - foreach ($contexte as $var => $val) { |
|
| 2711 | - if (preg_match(',\[\]$,S', (string) $var)) { |
|
| 2712 | - $values[] = [$var, $val]; |
|
| 2713 | - } else { |
|
| 2714 | - if (!isset($values[$var])) { |
|
| 2715 | - $values[$var] = [$var, $val]; |
|
| 2716 | - } |
|
| 2717 | - } |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - // puis on rassemble le tout |
|
| 2721 | - $hidden = []; |
|
| 2722 | - foreach ($values as $value) { |
|
| 2723 | - [$var, $val] = $value; |
|
| 2724 | - $hidden[] = '<input name="' |
|
| 2725 | - . entites_html($var) |
|
| 2726 | - . '"' |
|
| 2727 | - . (is_null($val) |
|
| 2728 | - ? '' |
|
| 2729 | - : ' value="' . entites_html($val) . '"' |
|
| 2730 | - ) |
|
| 2731 | - . ' type="hidden"' . "\n/>"; |
|
| 2732 | - } |
|
| 2733 | - |
|
| 2734 | - return implode('', $hidden); |
|
| 2662 | + $action ??= ''; |
|
| 2663 | + |
|
| 2664 | + $contexte = []; |
|
| 2665 | + include_spip('inc/urls'); |
|
| 2666 | + if ( |
|
| 2667 | + ($p = urls_decoder_url($action, '')) |
|
| 2668 | + && reset($p) |
|
| 2669 | + ) { |
|
| 2670 | + $fond = array_shift($p); |
|
| 2671 | + if ($fond != '404') { |
|
| 2672 | + $contexte = array_shift($p); |
|
| 2673 | + $contexte['page'] = $fond; |
|
| 2674 | + $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | + } |
|
| 2676 | + } |
|
| 2677 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2678 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2679 | + unset($contexte['type']); |
|
| 2680 | + } |
|
| 2681 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2682 | + unset($contexte['type-page']); |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2686 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2687 | + $values = []; |
|
| 2688 | + |
|
| 2689 | + // d'abord avec celles de l'url |
|
| 2690 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2691 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2692 | + $c = explode('=', (string) $c, 2); |
|
| 2693 | + $var = array_shift($c); |
|
| 2694 | + $val = array_shift($c) ?? ''; |
|
| 2695 | + if ($var) { |
|
| 2696 | + $val = rawurldecode($val); |
|
| 2697 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2698 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2699 | + $values[] = [$var, $val]; |
|
| 2700 | + } else { |
|
| 2701 | + if (!isset($values[$var])) { |
|
| 2702 | + $values[$var] = [$var, $val]; |
|
| 2703 | + } |
|
| 2704 | + } |
|
| 2705 | + } |
|
| 2706 | + } |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2710 | + foreach ($contexte as $var => $val) { |
|
| 2711 | + if (preg_match(',\[\]$,S', (string) $var)) { |
|
| 2712 | + $values[] = [$var, $val]; |
|
| 2713 | + } else { |
|
| 2714 | + if (!isset($values[$var])) { |
|
| 2715 | + $values[$var] = [$var, $val]; |
|
| 2716 | + } |
|
| 2717 | + } |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + // puis on rassemble le tout |
|
| 2721 | + $hidden = []; |
|
| 2722 | + foreach ($values as $value) { |
|
| 2723 | + [$var, $val] = $value; |
|
| 2724 | + $hidden[] = '<input name="' |
|
| 2725 | + . entites_html($var) |
|
| 2726 | + . '"' |
|
| 2727 | + . (is_null($val) |
|
| 2728 | + ? '' |
|
| 2729 | + : ' value="' . entites_html($val) . '"' |
|
| 2730 | + ) |
|
| 2731 | + . ' type="hidden"' . "\n/>"; |
|
| 2732 | + } |
|
| 2733 | + |
|
| 2734 | + return implode('', $hidden); |
|
| 2735 | 2735 | } |
| 2736 | 2736 | |
| 2737 | 2737 | |
@@ -2753,7 +2753,7 @@ discard block |
||
| 2753 | 2753 | * - la première valeur du tableau sinon. |
| 2754 | 2754 | **/ |
| 2755 | 2755 | function filtre_reset($array) { |
| 2756 | - return is_array($array) ? reset($array) : null; |
|
| 2756 | + return is_array($array) ? reset($array) : null; |
|
| 2757 | 2757 | } |
| 2758 | 2758 | |
| 2759 | 2759 | /** |
@@ -2774,7 +2774,7 @@ discard block |
||
| 2774 | 2774 | * - la dernière valeur du tableau sinon. |
| 2775 | 2775 | **/ |
| 2776 | 2776 | function filtre_end($array) { |
| 2777 | - return is_array($array) ? end($array) : null; |
|
| 2777 | + return is_array($array) ? end($array) : null; |
|
| 2778 | 2778 | } |
| 2779 | 2779 | |
| 2780 | 2780 | /** |
@@ -2794,11 +2794,11 @@ discard block |
||
| 2794 | 2794 | * |
| 2795 | 2795 | **/ |
| 2796 | 2796 | function filtre_push($array, mixed $val) { |
| 2797 | - if (!is_array($array) || !array_push($array, $val)) { |
|
| 2798 | - return ''; |
|
| 2799 | - } |
|
| 2797 | + if (!is_array($array) || !array_push($array, $val)) { |
|
| 2798 | + return ''; |
|
| 2799 | + } |
|
| 2800 | 2800 | |
| 2801 | - return $array; |
|
| 2801 | + return $array; |
|
| 2802 | 2802 | } |
| 2803 | 2803 | |
| 2804 | 2804 | /** |
@@ -2817,7 +2817,7 @@ discard block |
||
| 2817 | 2817 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2818 | 2818 | **/ |
| 2819 | 2819 | function filtre_find($array, mixed $val) { |
| 2820 | - return (is_array($array) && in_array($val, $array)); |
|
| 2820 | + return (is_array($array) && in_array($val, $array)); |
|
| 2821 | 2821 | } |
| 2822 | 2822 | |
| 2823 | 2823 | |
@@ -2834,13 +2834,13 @@ discard block |
||
| 2834 | 2834 | * Contenu avec urls en absolus |
| 2835 | 2835 | **/ |
| 2836 | 2836 | function urls_absolues_css($contenu, $source) { |
| 2837 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2837 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2838 | 2838 | |
| 2839 | - return preg_replace_callback( |
|
| 2840 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2841 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2842 | - $contenu |
|
| 2843 | - ); |
|
| 2839 | + return preg_replace_callback( |
|
| 2840 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2841 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2842 | + $contenu |
|
| 2843 | + ); |
|
| 2844 | 2844 | } |
| 2845 | 2845 | |
| 2846 | 2846 | |
@@ -2869,120 +2869,120 @@ discard block |
||
| 2869 | 2869 | * Chemin du fichier CSS inversé |
| 2870 | 2870 | **/ |
| 2871 | 2871 | function direction_css($css, $voulue = '') { |
| 2872 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2873 | - return $css; |
|
| 2874 | - } |
|
| 2875 | - include_spip('inc/lang'); |
|
| 2876 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2877 | - if ($voulue = strtolower($voulue)) { |
|
| 2878 | - if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2879 | - $voulue = lang_dir($voulue); |
|
| 2880 | - } |
|
| 2881 | - } else { |
|
| 2882 | - $voulue = lang_dir(); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - $r = count($r) > 1; |
|
| 2886 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2887 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2888 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2889 | - |
|
| 2890 | - if ($voulue == $dir) { |
|
| 2891 | - return $css; |
|
| 2892 | - } |
|
| 2893 | - |
|
| 2894 | - if ( |
|
| 2895 | - // url absolue |
|
| 2896 | - preg_match(',^https?:,i', $css) |
|
| 2897 | - // ou qui contient un ? |
|
| 2898 | - || ($p = strpos($css, '?')) !== false |
|
| 2899 | - ) { |
|
| 2900 | - $distant = true; |
|
| 2901 | - $cssf = parse_url($css); |
|
| 2902 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2903 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2904 | - } else { |
|
| 2905 | - $distant = false; |
|
| 2906 | - $cssf = $css; |
|
| 2907 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2908 | - //propose (rien a faire dans ce cas) |
|
| 2909 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2910 | - if (@file_exists($f)) { |
|
| 2911 | - return $f; |
|
| 2912 | - } |
|
| 2913 | - } |
|
| 2914 | - |
|
| 2915 | - // 2. |
|
| 2916 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2917 | - $f = $dir_var |
|
| 2918 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2919 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2920 | - |
|
| 2921 | - // la css peut etre distante (url absolue !) |
|
| 2922 | - $contenu = null; |
|
| 2923 | - if ($distant) { |
|
| 2924 | - include_spip('inc/distant'); |
|
| 2925 | - $res = recuperer_url($css); |
|
| 2926 | - if (!$res || !($contenu = $res['page'])) { |
|
| 2927 | - return $css; |
|
| 2928 | - } |
|
| 2929 | - } else { |
|
| 2930 | - if ( |
|
| 2931 | - @filemtime($f) > @filemtime($css) |
|
| 2932 | - && _VAR_MODE != 'recalcul' |
|
| 2933 | - ) { |
|
| 2934 | - return $f; |
|
| 2935 | - } |
|
| 2936 | - if (!lire_fichier($css, $contenu)) { |
|
| 2937 | - return $css; |
|
| 2938 | - } |
|
| 2939 | - } |
|
| 2940 | - |
|
| 2941 | - |
|
| 2942 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2943 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2944 | - $parser = new csstidy(); |
|
| 2945 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2946 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2947 | - $parser->parse($contenu); |
|
| 2948 | - |
|
| 2949 | - $contenu = $parser->print->plain(); |
|
| 2950 | - |
|
| 2951 | - |
|
| 2952 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2953 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs); |
|
| 2954 | - $src = []; |
|
| 2955 | - $src_direction_css = []; |
|
| 2956 | - $src_faux_abs = []; |
|
| 2957 | - $d = dirname($css); |
|
| 2958 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2959 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2960 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2961 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2962 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2963 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2964 | - elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2965 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2966 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2968 | - } |
|
| 2969 | - $src[] = $regs[0][$k]; |
|
| 2970 | - $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]); |
|
| 2971 | - } |
|
| 2972 | - $contenu = str_replace($src, $src_direction_css, (string) $contenu); |
|
| 2973 | - |
|
| 2974 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2975 | - |
|
| 2976 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2977 | - if ($src_faux_abs !== []) { |
|
| 2978 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2979 | - } |
|
| 2980 | - |
|
| 2981 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2982 | - return $css; |
|
| 2983 | - } |
|
| 2984 | - |
|
| 2985 | - return $f; |
|
| 2872 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2873 | + return $css; |
|
| 2874 | + } |
|
| 2875 | + include_spip('inc/lang'); |
|
| 2876 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2877 | + if ($voulue = strtolower($voulue)) { |
|
| 2878 | + if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2879 | + $voulue = lang_dir($voulue); |
|
| 2880 | + } |
|
| 2881 | + } else { |
|
| 2882 | + $voulue = lang_dir(); |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + $r = count($r) > 1; |
|
| 2886 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2887 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2888 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2889 | + |
|
| 2890 | + if ($voulue == $dir) { |
|
| 2891 | + return $css; |
|
| 2892 | + } |
|
| 2893 | + |
|
| 2894 | + if ( |
|
| 2895 | + // url absolue |
|
| 2896 | + preg_match(',^https?:,i', $css) |
|
| 2897 | + // ou qui contient un ? |
|
| 2898 | + || ($p = strpos($css, '?')) !== false |
|
| 2899 | + ) { |
|
| 2900 | + $distant = true; |
|
| 2901 | + $cssf = parse_url($css); |
|
| 2902 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2903 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2904 | + } else { |
|
| 2905 | + $distant = false; |
|
| 2906 | + $cssf = $css; |
|
| 2907 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2908 | + //propose (rien a faire dans ce cas) |
|
| 2909 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2910 | + if (@file_exists($f)) { |
|
| 2911 | + return $f; |
|
| 2912 | + } |
|
| 2913 | + } |
|
| 2914 | + |
|
| 2915 | + // 2. |
|
| 2916 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2917 | + $f = $dir_var |
|
| 2918 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2919 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2920 | + |
|
| 2921 | + // la css peut etre distante (url absolue !) |
|
| 2922 | + $contenu = null; |
|
| 2923 | + if ($distant) { |
|
| 2924 | + include_spip('inc/distant'); |
|
| 2925 | + $res = recuperer_url($css); |
|
| 2926 | + if (!$res || !($contenu = $res['page'])) { |
|
| 2927 | + return $css; |
|
| 2928 | + } |
|
| 2929 | + } else { |
|
| 2930 | + if ( |
|
| 2931 | + @filemtime($f) > @filemtime($css) |
|
| 2932 | + && _VAR_MODE != 'recalcul' |
|
| 2933 | + ) { |
|
| 2934 | + return $f; |
|
| 2935 | + } |
|
| 2936 | + if (!lire_fichier($css, $contenu)) { |
|
| 2937 | + return $css; |
|
| 2938 | + } |
|
| 2939 | + } |
|
| 2940 | + |
|
| 2941 | + |
|
| 2942 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2943 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2944 | + $parser = new csstidy(); |
|
| 2945 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2946 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2947 | + $parser->parse($contenu); |
|
| 2948 | + |
|
| 2949 | + $contenu = $parser->print->plain(); |
|
| 2950 | + |
|
| 2951 | + |
|
| 2952 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2953 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs); |
|
| 2954 | + $src = []; |
|
| 2955 | + $src_direction_css = []; |
|
| 2956 | + $src_faux_abs = []; |
|
| 2957 | + $d = dirname($css); |
|
| 2958 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2959 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2960 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2961 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2962 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2963 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2964 | + elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2965 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2966 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2968 | + } |
|
| 2969 | + $src[] = $regs[0][$k]; |
|
| 2970 | + $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]); |
|
| 2971 | + } |
|
| 2972 | + $contenu = str_replace($src, $src_direction_css, (string) $contenu); |
|
| 2973 | + |
|
| 2974 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2975 | + |
|
| 2976 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2977 | + if ($src_faux_abs !== []) { |
|
| 2978 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2979 | + } |
|
| 2980 | + |
|
| 2981 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2982 | + return $css; |
|
| 2983 | + } |
|
| 2984 | + |
|
| 2985 | + return $f; |
|
| 2986 | 2986 | } |
| 2987 | 2987 | |
| 2988 | 2988 | |
@@ -3005,47 +3005,47 @@ discard block |
||
| 3005 | 3005 | * - Chemin ou URL du fichier CSS source sinon. |
| 3006 | 3006 | **/ |
| 3007 | 3007 | function url_absolue_css($css) { |
| 3008 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3009 | - return $css; |
|
| 3010 | - } |
|
| 3008 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3009 | + return $css; |
|
| 3010 | + } |
|
| 3011 | 3011 | |
| 3012 | - $url_absolue_css = url_absolue($css); |
|
| 3012 | + $url_absolue_css = url_absolue($css); |
|
| 3013 | 3013 | |
| 3014 | - $f = basename($css, '.css'); |
|
| 3015 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3016 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3017 | - . '.css'; |
|
| 3014 | + $f = basename($css, '.css'); |
|
| 3015 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3016 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3017 | + . '.css'; |
|
| 3018 | 3018 | |
| 3019 | - if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 3020 | - return $f; |
|
| 3021 | - } |
|
| 3019 | + if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 3020 | + return $f; |
|
| 3021 | + } |
|
| 3022 | 3022 | |
| 3023 | - $contenu = null; |
|
| 3024 | - if ($url_absolue_css == $css) { |
|
| 3025 | - if ( |
|
| 3026 | - strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3027 | - || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3028 | - ) { |
|
| 3029 | - include_spip('inc/distant'); |
|
| 3030 | - $contenu = recuperer_url($css); |
|
| 3031 | - $contenu = $contenu['page'] ?? ''; |
|
| 3032 | - if (!$contenu) { |
|
| 3033 | - return $css; |
|
| 3034 | - } |
|
| 3035 | - } |
|
| 3036 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3037 | - return $css; |
|
| 3038 | - } |
|
| 3023 | + $contenu = null; |
|
| 3024 | + if ($url_absolue_css == $css) { |
|
| 3025 | + if ( |
|
| 3026 | + strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3027 | + || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3028 | + ) { |
|
| 3029 | + include_spip('inc/distant'); |
|
| 3030 | + $contenu = recuperer_url($css); |
|
| 3031 | + $contenu = $contenu['page'] ?? ''; |
|
| 3032 | + if (!$contenu) { |
|
| 3033 | + return $css; |
|
| 3034 | + } |
|
| 3035 | + } |
|
| 3036 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3037 | + return $css; |
|
| 3038 | + } |
|
| 3039 | 3039 | |
| 3040 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3041 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3040 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3041 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3042 | 3042 | |
| 3043 | - // ecrire la css |
|
| 3044 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3045 | - return $css; |
|
| 3046 | - } |
|
| 3043 | + // ecrire la css |
|
| 3044 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3045 | + return $css; |
|
| 3046 | + } |
|
| 3047 | 3047 | |
| 3048 | - return $f; |
|
| 3048 | + return $f; |
|
| 3049 | 3049 | } |
| 3050 | 3050 | |
| 3051 | 3051 | |
@@ -3079,24 +3079,24 @@ discard block |
||
| 3079 | 3079 | * Valeur trouvée ou valeur par défaut. |
| 3080 | 3080 | **/ |
| 3081 | 3081 | function table_valeur(mixed $table, $cle, mixed $defaut = '', $conserver_null = false) { |
| 3082 | - foreach (explode('/', $cle) as $k) { |
|
| 3083 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3082 | + foreach (explode('/', $cle) as $k) { |
|
| 3083 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3084 | 3084 | |
| 3085 | - if (is_object($table)) { |
|
| 3086 | - $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3087 | - } elseif (is_array($table)) { |
|
| 3088 | - if ($conserver_null) { |
|
| 3089 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3090 | - } else { |
|
| 3091 | - $table = ($table[$k] ?? $defaut); |
|
| 3092 | - } |
|
| 3093 | - } else { |
|
| 3094 | - $table = $defaut; |
|
| 3095 | - break; |
|
| 3096 | - } |
|
| 3097 | - } |
|
| 3085 | + if (is_object($table)) { |
|
| 3086 | + $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3087 | + } elseif (is_array($table)) { |
|
| 3088 | + if ($conserver_null) { |
|
| 3089 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3090 | + } else { |
|
| 3091 | + $table = ($table[$k] ?? $defaut); |
|
| 3092 | + } |
|
| 3093 | + } else { |
|
| 3094 | + $table = $defaut; |
|
| 3095 | + break; |
|
| 3096 | + } |
|
| 3097 | + } |
|
| 3098 | 3098 | |
| 3099 | - return $table; |
|
| 3099 | + return $table; |
|
| 3100 | 3100 | } |
| 3101 | 3101 | |
| 3102 | 3102 | /** |
@@ -3129,22 +3129,22 @@ discard block |
||
| 3129 | 3129 | * - string : expression trouvée. |
| 3130 | 3130 | **/ |
| 3131 | 3131 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3132 | - if ((int) $modif && $capte == 0) { |
|
| 3133 | - $capte = $modif; |
|
| 3134 | - $modif = 'UuimsS'; |
|
| 3135 | - } |
|
| 3136 | - $expression = str_replace('\/', '/', $expression); |
|
| 3137 | - $expression = str_replace('/', '\/', $expression); |
|
| 3132 | + if ((int) $modif && $capte == 0) { |
|
| 3133 | + $capte = $modif; |
|
| 3134 | + $modif = 'UuimsS'; |
|
| 3135 | + } |
|
| 3136 | + $expression = str_replace('\/', '/', $expression); |
|
| 3137 | + $expression = str_replace('/', '\/', $expression); |
|
| 3138 | 3138 | |
| 3139 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3140 | - if (isset($r[$capte])) { |
|
| 3141 | - return $r[$capte]; |
|
| 3142 | - } else { |
|
| 3143 | - return true; |
|
| 3144 | - } |
|
| 3145 | - } |
|
| 3139 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3140 | + if (isset($r[$capte])) { |
|
| 3141 | + return $r[$capte]; |
|
| 3142 | + } else { |
|
| 3143 | + return true; |
|
| 3144 | + } |
|
| 3145 | + } |
|
| 3146 | 3146 | |
| 3147 | - return false; |
|
| 3147 | + return false; |
|
| 3148 | 3148 | } |
| 3149 | 3149 | |
| 3150 | 3150 | |
@@ -3171,14 +3171,14 @@ discard block |
||
| 3171 | 3171 | * Texte |
| 3172 | 3172 | **/ |
| 3173 | 3173 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3174 | - if (null === $texte) { |
|
| 3175 | - return ''; |
|
| 3176 | - } |
|
| 3174 | + if (null === $texte) { |
|
| 3175 | + return ''; |
|
| 3176 | + } |
|
| 3177 | 3177 | |
| 3178 | - $expression = str_replace('\/', '/', $expression); |
|
| 3179 | - $expression = str_replace('/', '\/', $expression); |
|
| 3178 | + $expression = str_replace('\/', '/', $expression); |
|
| 3179 | + $expression = str_replace('/', '\/', $expression); |
|
| 3180 | 3180 | |
| 3181 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3181 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3182 | 3182 | } |
| 3183 | 3183 | |
| 3184 | 3184 | |
@@ -3196,25 +3196,25 @@ discard block |
||
| 3196 | 3196 | **/ |
| 3197 | 3197 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3198 | 3198 | |
| 3199 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3200 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3199 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3200 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3201 | 3201 | |
| 3202 | - if ( |
|
| 3203 | - strstr($t, 'spip_document_') |
|
| 3204 | - && preg_match_all( |
|
| 3205 | - ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3206 | - $t, |
|
| 3207 | - $matches, |
|
| 3208 | - PREG_PATTERN_ORDER |
|
| 3209 | - ) |
|
| 3210 | - ) { |
|
| 3211 | - if (!isset($doublons['documents'])) { |
|
| 3212 | - $doublons['documents'] = ''; |
|
| 3213 | - } |
|
| 3214 | - $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3215 | - } |
|
| 3202 | + if ( |
|
| 3203 | + strstr($t, 'spip_document_') |
|
| 3204 | + && preg_match_all( |
|
| 3205 | + ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3206 | + $t, |
|
| 3207 | + $matches, |
|
| 3208 | + PREG_PATTERN_ORDER |
|
| 3209 | + ) |
|
| 3210 | + ) { |
|
| 3211 | + if (!isset($doublons['documents'])) { |
|
| 3212 | + $doublons['documents'] = ''; |
|
| 3213 | + } |
|
| 3214 | + $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3215 | + } |
|
| 3216 | 3216 | |
| 3217 | - return $letexte; |
|
| 3217 | + return $letexte; |
|
| 3218 | 3218 | } |
| 3219 | 3219 | |
| 3220 | 3220 | /** |
@@ -3228,7 +3228,7 @@ discard block |
||
| 3228 | 3228 | * @return string Chaîne vide |
| 3229 | 3229 | **/ |
| 3230 | 3230 | function vide(mixed $texte) { |
| 3231 | - return ''; |
|
| 3231 | + return ''; |
|
| 3232 | 3232 | } |
| 3233 | 3233 | |
| 3234 | 3234 | // |
@@ -3257,23 +3257,23 @@ discard block |
||
| 3257 | 3257 | * Code HTML résultant |
| 3258 | 3258 | **/ |
| 3259 | 3259 | function env_to_params($env, $ignore_params = []) { |
| 3260 | - $ignore_params = array_merge( |
|
| 3261 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3262 | - $ignore_params |
|
| 3263 | - ); |
|
| 3264 | - if (!is_array($env)) { |
|
| 3265 | - $env = unserialize($env); |
|
| 3266 | - } |
|
| 3267 | - $texte = ''; |
|
| 3268 | - if ($env) { |
|
| 3269 | - foreach ($env as $i => $j) { |
|
| 3270 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3271 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3272 | - } |
|
| 3273 | - } |
|
| 3274 | - } |
|
| 3275 | - |
|
| 3276 | - return $texte; |
|
| 3260 | + $ignore_params = array_merge( |
|
| 3261 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3262 | + $ignore_params |
|
| 3263 | + ); |
|
| 3264 | + if (!is_array($env)) { |
|
| 3265 | + $env = unserialize($env); |
|
| 3266 | + } |
|
| 3267 | + $texte = ''; |
|
| 3268 | + if ($env) { |
|
| 3269 | + foreach ($env as $i => $j) { |
|
| 3270 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3271 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3272 | + } |
|
| 3273 | + } |
|
| 3274 | + } |
|
| 3275 | + |
|
| 3276 | + return $texte; |
|
| 3277 | 3277 | } |
| 3278 | 3278 | |
| 3279 | 3279 | /** |
@@ -3296,23 +3296,23 @@ discard block |
||
| 3296 | 3296 | * Code HTML résultant |
| 3297 | 3297 | **/ |
| 3298 | 3298 | function env_to_attributs($env, $ignore_params = []) { |
| 3299 | - $ignore_params = array_merge( |
|
| 3300 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3301 | - $ignore_params |
|
| 3302 | - ); |
|
| 3303 | - if (!is_array($env)) { |
|
| 3304 | - $env = unserialize($env); |
|
| 3305 | - } |
|
| 3306 | - $texte = ''; |
|
| 3307 | - if ($env) { |
|
| 3308 | - foreach ($env as $i => $j) { |
|
| 3309 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3310 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3311 | - } |
|
| 3312 | - } |
|
| 3313 | - } |
|
| 3299 | + $ignore_params = array_merge( |
|
| 3300 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3301 | + $ignore_params |
|
| 3302 | + ); |
|
| 3303 | + if (!is_array($env)) { |
|
| 3304 | + $env = unserialize($env); |
|
| 3305 | + } |
|
| 3306 | + $texte = ''; |
|
| 3307 | + if ($env) { |
|
| 3308 | + foreach ($env as $i => $j) { |
|
| 3309 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3310 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3311 | + } |
|
| 3312 | + } |
|
| 3313 | + } |
|
| 3314 | 3314 | |
| 3315 | - return $texte; |
|
| 3315 | + return $texte; |
|
| 3316 | 3316 | } |
| 3317 | 3317 | |
| 3318 | 3318 | |
@@ -3330,7 +3330,7 @@ discard block |
||
| 3330 | 3330 | * @return string Chaînes concaténés |
| 3331 | 3331 | **/ |
| 3332 | 3332 | function concat(...$args): string { |
| 3333 | - return implode('', $args); |
|
| 3333 | + return implode('', $args); |
|
| 3334 | 3334 | } |
| 3335 | 3335 | |
| 3336 | 3336 | |
@@ -3350,23 +3350,23 @@ discard block |
||
| 3350 | 3350 | * Contenu du ou des fichiers, concaténé |
| 3351 | 3351 | **/ |
| 3352 | 3352 | function charge_scripts($files, $script = true) { |
| 3353 | - $flux = ''; |
|
| 3354 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3355 | - if (!is_string($file)) { |
|
| 3356 | - continue; |
|
| 3357 | - } |
|
| 3358 | - if ($script) { |
|
| 3359 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3360 | - } |
|
| 3361 | - if ($file) { |
|
| 3362 | - $path = find_in_path($file); |
|
| 3363 | - if ($path) { |
|
| 3364 | - $flux .= spip_file_get_contents($path); |
|
| 3365 | - } |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3368 | - |
|
| 3369 | - return $flux; |
|
| 3353 | + $flux = ''; |
|
| 3354 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3355 | + if (!is_string($file)) { |
|
| 3356 | + continue; |
|
| 3357 | + } |
|
| 3358 | + if ($script) { |
|
| 3359 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3360 | + } |
|
| 3361 | + if ($file) { |
|
| 3362 | + $path = find_in_path($file); |
|
| 3363 | + if ($path) { |
|
| 3364 | + $flux .= spip_file_get_contents($path); |
|
| 3365 | + } |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | + |
|
| 3369 | + return $flux; |
|
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | /** |
@@ -3377,24 +3377,24 @@ discard block |
||
| 3377 | 3377 | * @return string |
| 3378 | 3378 | */ |
| 3379 | 3379 | function http_img_variante_svg_si_possible($img_file) { |
| 3380 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3381 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3382 | - if ( |
|
| 3383 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3384 | - && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3385 | - && file_exists($variante_svg_generique) |
|
| 3386 | - ) { |
|
| 3387 | - if ( |
|
| 3388 | - ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3389 | - && file_exists($variante_svg_size) |
|
| 3390 | - ) { |
|
| 3391 | - $img_file = $variante_svg_size; |
|
| 3392 | - } else { |
|
| 3393 | - $img_file = $variante_svg_generique; |
|
| 3394 | - } |
|
| 3395 | - } |
|
| 3396 | - |
|
| 3397 | - return $img_file; |
|
| 3380 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3381 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3382 | + if ( |
|
| 3383 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3384 | + && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3385 | + && file_exists($variante_svg_generique) |
|
| 3386 | + ) { |
|
| 3387 | + if ( |
|
| 3388 | + ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3389 | + && file_exists($variante_svg_size) |
|
| 3390 | + ) { |
|
| 3391 | + $img_file = $variante_svg_size; |
|
| 3392 | + } else { |
|
| 3393 | + $img_file = $variante_svg_generique; |
|
| 3394 | + } |
|
| 3395 | + } |
|
| 3396 | + |
|
| 3397 | + return $img_file; |
|
| 3398 | 3398 | } |
| 3399 | 3399 | |
| 3400 | 3400 | /** |
@@ -3415,51 +3415,51 @@ discard block |
||
| 3415 | 3415 | */ |
| 3416 | 3416 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3417 | 3417 | |
| 3418 | - $img_file = $img; |
|
| 3419 | - if ($p = strpos($img_file, '?')) { |
|
| 3420 | - $img_file = substr($img_file, 0, $p); |
|
| 3421 | - } |
|
| 3422 | - if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3423 | - $img_file = chemin_image($img); |
|
| 3424 | - } |
|
| 3425 | - else { |
|
| 3426 | - if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3427 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3428 | - } |
|
| 3429 | - } |
|
| 3430 | - if (stripos($atts, 'width') === false) { |
|
| 3431 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3432 | - if ( |
|
| 3433 | - (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3434 | - && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3435 | - ) { |
|
| 3436 | - $largeur = $hauteur = (int) $regs[1]; |
|
| 3437 | - } else { |
|
| 3438 | - $taille = taille_image($img_file); |
|
| 3439 | - [$hauteur, $largeur] = $taille; |
|
| 3440 | - if (!$hauteur || !$largeur) { |
|
| 3441 | - return ''; |
|
| 3442 | - } |
|
| 3443 | - } |
|
| 3444 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3445 | - } |
|
| 3446 | - |
|
| 3447 | - if (file_exists($img_file)) { |
|
| 3448 | - $img_file = timestamp($img_file); |
|
| 3449 | - } |
|
| 3450 | - if ($alt === false) { |
|
| 3451 | - $alt = ''; |
|
| 3452 | - } |
|
| 3453 | - elseif ($alt || $alt === '') { |
|
| 3454 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3455 | - } |
|
| 3456 | - else { |
|
| 3457 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3458 | - } |
|
| 3459 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3460 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3461 | - . ' ' . ltrim($atts) |
|
| 3462 | - . ' />'; |
|
| 3418 | + $img_file = $img; |
|
| 3419 | + if ($p = strpos($img_file, '?')) { |
|
| 3420 | + $img_file = substr($img_file, 0, $p); |
|
| 3421 | + } |
|
| 3422 | + if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3423 | + $img_file = chemin_image($img); |
|
| 3424 | + } |
|
| 3425 | + else { |
|
| 3426 | + if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3427 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3428 | + } |
|
| 3429 | + } |
|
| 3430 | + if (stripos($atts, 'width') === false) { |
|
| 3431 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3432 | + if ( |
|
| 3433 | + (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3434 | + && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3435 | + ) { |
|
| 3436 | + $largeur = $hauteur = (int) $regs[1]; |
|
| 3437 | + } else { |
|
| 3438 | + $taille = taille_image($img_file); |
|
| 3439 | + [$hauteur, $largeur] = $taille; |
|
| 3440 | + if (!$hauteur || !$largeur) { |
|
| 3441 | + return ''; |
|
| 3442 | + } |
|
| 3443 | + } |
|
| 3444 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3445 | + } |
|
| 3446 | + |
|
| 3447 | + if (file_exists($img_file)) { |
|
| 3448 | + $img_file = timestamp($img_file); |
|
| 3449 | + } |
|
| 3450 | + if ($alt === false) { |
|
| 3451 | + $alt = ''; |
|
| 3452 | + } |
|
| 3453 | + elseif ($alt || $alt === '') { |
|
| 3454 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3455 | + } |
|
| 3456 | + else { |
|
| 3457 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3458 | + } |
|
| 3459 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3460 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3461 | + . ' ' . ltrim($atts) |
|
| 3462 | + . ' />'; |
|
| 3463 | 3463 | } |
| 3464 | 3464 | |
| 3465 | 3465 | /** |
@@ -3471,70 +3471,70 @@ discard block |
||
| 3471 | 3471 | * @return string |
| 3472 | 3472 | */ |
| 3473 | 3473 | function http_style_background($img, $att = '', $size = null) { |
| 3474 | - if ($size && is_numeric($size)) { |
|
| 3475 | - $size = trim($size) . 'px'; |
|
| 3476 | - } |
|
| 3477 | - return " style='background" . |
|
| 3478 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3479 | - . ($size ? "background-size:{$size};" : '') |
|
| 3480 | - . "'"; |
|
| 3474 | + if ($size && is_numeric($size)) { |
|
| 3475 | + $size = trim($size) . 'px'; |
|
| 3476 | + } |
|
| 3477 | + return " style='background" . |
|
| 3478 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3479 | + . ($size ? "background-size:{$size};" : '') |
|
| 3480 | + . "'"; |
|
| 3481 | 3481 | } |
| 3482 | 3482 | |
| 3483 | 3483 | |
| 3484 | 3484 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3485 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3486 | - while (is_null(end($args)) && count($args)) { |
|
| 3487 | - array_pop($args); |
|
| 3488 | - } |
|
| 3489 | - if ($args === []) { |
|
| 3490 | - return [null, null, null]; |
|
| 3491 | - } |
|
| 3492 | - if (count($args) < 3) { |
|
| 3493 | - $maybe_size = array_pop($args); |
|
| 3494 | - // @2x |
|
| 3495 | - // @1.5x |
|
| 3496 | - // 512 |
|
| 3497 | - // 512x* |
|
| 3498 | - // 512x300 |
|
| 3499 | - if ( |
|
| 3500 | - !strlen((string) $maybe_size) |
|
| 3501 | - || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size)) |
|
| 3502 | - ) { |
|
| 3503 | - $args[] = $maybe_size; |
|
| 3504 | - $maybe_size = null; |
|
| 3505 | - } |
|
| 3506 | - while (count($args) < 2) { |
|
| 3507 | - $args[] = null; // default alt or class |
|
| 3508 | - } |
|
| 3509 | - $args[] = $maybe_size; |
|
| 3510 | - } |
|
| 3511 | - return $args; |
|
| 3485 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3486 | + while (is_null(end($args)) && count($args)) { |
|
| 3487 | + array_pop($args); |
|
| 3488 | + } |
|
| 3489 | + if ($args === []) { |
|
| 3490 | + return [null, null, null]; |
|
| 3491 | + } |
|
| 3492 | + if (count($args) < 3) { |
|
| 3493 | + $maybe_size = array_pop($args); |
|
| 3494 | + // @2x |
|
| 3495 | + // @1.5x |
|
| 3496 | + // 512 |
|
| 3497 | + // 512x* |
|
| 3498 | + // 512x300 |
|
| 3499 | + if ( |
|
| 3500 | + !strlen((string) $maybe_size) |
|
| 3501 | + || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size)) |
|
| 3502 | + ) { |
|
| 3503 | + $args[] = $maybe_size; |
|
| 3504 | + $maybe_size = null; |
|
| 3505 | + } |
|
| 3506 | + while (count($args) < 2) { |
|
| 3507 | + $args[] = null; // default alt or class |
|
| 3508 | + } |
|
| 3509 | + $args[] = $maybe_size; |
|
| 3510 | + } |
|
| 3511 | + return $args; |
|
| 3512 | 3512 | } |
| 3513 | 3513 | |
| 3514 | 3514 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3515 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3516 | - if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) { |
|
| 3517 | - $coef = (float) substr((string) $size, 1, -1); |
|
| 3518 | - [$h, $w] = taille_image($img); |
|
| 3519 | - $height = (int) round($h / $coef); |
|
| 3520 | - $width = (int) round($w / $coef); |
|
| 3521 | - } |
|
| 3522 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3523 | - else { |
|
| 3524 | - $size = explode('x', (string) $size, 2); |
|
| 3525 | - $size = array_map('trim', $size); |
|
| 3526 | - $height = $width = (int) array_shift($size); |
|
| 3527 | - |
|
| 3528 | - if (count($size) && reset($size)) { |
|
| 3529 | - $height = array_shift($size); |
|
| 3530 | - if ($height === '*') { |
|
| 3531 | - [$h, $w] = taille_image($img); |
|
| 3532 | - $height = (int) round($h * $width / $w); |
|
| 3533 | - } |
|
| 3534 | - } |
|
| 3535 | - } |
|
| 3536 | - |
|
| 3537 | - return [$width, $height]; |
|
| 3515 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3516 | + if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) { |
|
| 3517 | + $coef = (float) substr((string) $size, 1, -1); |
|
| 3518 | + [$h, $w] = taille_image($img); |
|
| 3519 | + $height = (int) round($h / $coef); |
|
| 3520 | + $width = (int) round($w / $coef); |
|
| 3521 | + } |
|
| 3522 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3523 | + else { |
|
| 3524 | + $size = explode('x', (string) $size, 2); |
|
| 3525 | + $size = array_map('trim', $size); |
|
| 3526 | + $height = $width = (int) array_shift($size); |
|
| 3527 | + |
|
| 3528 | + if (count($size) && reset($size)) { |
|
| 3529 | + $height = array_shift($size); |
|
| 3530 | + if ($height === '*') { |
|
| 3531 | + [$h, $w] = taille_image($img); |
|
| 3532 | + $height = (int) round($h * $width / $w); |
|
| 3533 | + } |
|
| 3534 | + } |
|
| 3535 | + } |
|
| 3536 | + |
|
| 3537 | + return [$width, $height]; |
|
| 3538 | 3538 | } |
| 3539 | 3539 | |
| 3540 | 3540 | /** |
@@ -3570,38 +3570,38 @@ discard block |
||
| 3570 | 3570 | */ |
| 3571 | 3571 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3572 | 3572 | |
| 3573 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3573 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3574 | 3574 | |
| 3575 | - $img = trim((string) $img); |
|
| 3576 | - if (str_starts_with($img, '<img')) { |
|
| 3577 | - if (!is_null($alt)) { |
|
| 3578 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3579 | - } |
|
| 3580 | - if (!is_null($class)) { |
|
| 3581 | - $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3582 | - } |
|
| 3583 | - } |
|
| 3584 | - else { |
|
| 3585 | - $img = http_img_pack( |
|
| 3586 | - $img, |
|
| 3587 | - $alt, |
|
| 3588 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3589 | - '', |
|
| 3590 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3591 | - ); |
|
| 3592 | - if (is_null($alt)) { |
|
| 3593 | - $img = vider_attribut($img, 'alt'); |
|
| 3594 | - } |
|
| 3595 | - } |
|
| 3575 | + $img = trim((string) $img); |
|
| 3576 | + if (str_starts_with($img, '<img')) { |
|
| 3577 | + if (!is_null($alt)) { |
|
| 3578 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3579 | + } |
|
| 3580 | + if (!is_null($class)) { |
|
| 3581 | + $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3582 | + } |
|
| 3583 | + } |
|
| 3584 | + else { |
|
| 3585 | + $img = http_img_pack( |
|
| 3586 | + $img, |
|
| 3587 | + $alt, |
|
| 3588 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3589 | + '', |
|
| 3590 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3591 | + ); |
|
| 3592 | + if (is_null($alt)) { |
|
| 3593 | + $img = vider_attribut($img, 'alt'); |
|
| 3594 | + } |
|
| 3595 | + } |
|
| 3596 | 3596 | |
| 3597 | - if ($img && !is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3598 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3597 | + if ($img && !is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3598 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3599 | 3599 | |
| 3600 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3601 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3602 | - } |
|
| 3600 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3601 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3602 | + } |
|
| 3603 | 3603 | |
| 3604 | - return $img; |
|
| 3604 | + return $img; |
|
| 3605 | 3605 | } |
| 3606 | 3606 | |
| 3607 | 3607 | |
@@ -3635,77 +3635,77 @@ discard block |
||
| 3635 | 3635 | */ |
| 3636 | 3636 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3637 | 3637 | |
| 3638 | - $svg = null; |
|
| 3639 | - $img = trim($img); |
|
| 3640 | - $img_file = $img; |
|
| 3641 | - if (!str_contains($img, '<svg')) { |
|
| 3642 | - if ($p = strpos($img_file, '?')) { |
|
| 3643 | - $img_file = substr($img_file, 0, $p); |
|
| 3644 | - } |
|
| 3638 | + $svg = null; |
|
| 3639 | + $img = trim($img); |
|
| 3640 | + $img_file = $img; |
|
| 3641 | + if (!str_contains($img, '<svg')) { |
|
| 3642 | + if ($p = strpos($img_file, '?')) { |
|
| 3643 | + $img_file = substr($img_file, 0, $p); |
|
| 3644 | + } |
|
| 3645 | 3645 | |
| 3646 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3647 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3648 | - if (tester_url_absolue($img_file)) { |
|
| 3649 | - include_spip('inc/distant'); |
|
| 3650 | - $fichier = copie_locale($img_file); |
|
| 3651 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3652 | - } |
|
| 3646 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3647 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3648 | + if (tester_url_absolue($img_file)) { |
|
| 3649 | + include_spip('inc/distant'); |
|
| 3650 | + $fichier = copie_locale($img_file); |
|
| 3651 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3652 | + } |
|
| 3653 | 3653 | |
| 3654 | - if ( |
|
| 3655 | - !$img_file |
|
| 3656 | - || !file_exists($img_file) |
|
| 3657 | - || !$svg = file_get_contents($img_file) |
|
| 3658 | - ) { |
|
| 3659 | - return ''; |
|
| 3660 | - } |
|
| 3661 | - } |
|
| 3654 | + if ( |
|
| 3655 | + !$img_file |
|
| 3656 | + || !file_exists($img_file) |
|
| 3657 | + || !$svg = file_get_contents($img_file) |
|
| 3658 | + ) { |
|
| 3659 | + return ''; |
|
| 3660 | + } |
|
| 3661 | + } |
|
| 3662 | 3662 | |
| 3663 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3664 | - return ''; |
|
| 3665 | - } |
|
| 3663 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3664 | + return ''; |
|
| 3665 | + } |
|
| 3666 | 3666 | |
| 3667 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3667 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3668 | 3668 | |
| 3669 | - $balise_svg = $match[0]; |
|
| 3670 | - $balise_svg_source = $balise_svg; |
|
| 3669 | + $balise_svg = $match[0]; |
|
| 3670 | + $balise_svg_source = $balise_svg; |
|
| 3671 | 3671 | |
| 3672 | - // entete XML à supprimer |
|
| 3673 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3672 | + // entete XML à supprimer |
|
| 3673 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3674 | 3674 | |
| 3675 | - // IE est toujours mon ami |
|
| 3676 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3675 | + // IE est toujours mon ami |
|
| 3676 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3677 | 3677 | |
| 3678 | - // regler la classe |
|
| 3679 | - if (!is_null($class)) { |
|
| 3680 | - $balise_svg = strlen((string) $class) |
|
| 3681 | - ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3682 | - : vider_attribut($balise_svg, 'class'); |
|
| 3683 | - } |
|
| 3678 | + // regler la classe |
|
| 3679 | + if (!is_null($class)) { |
|
| 3680 | + $balise_svg = strlen((string) $class) |
|
| 3681 | + ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3682 | + : vider_attribut($balise_svg, 'class'); |
|
| 3683 | + } |
|
| 3684 | 3684 | |
| 3685 | - // regler le alt |
|
| 3686 | - if ($alt) { |
|
| 3687 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3688 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3689 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3690 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3691 | - $balise_svg .= $title; |
|
| 3692 | - } |
|
| 3693 | - else { |
|
| 3694 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3695 | - } |
|
| 3685 | + // regler le alt |
|
| 3686 | + if ($alt) { |
|
| 3687 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3688 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3689 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3690 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3691 | + $balise_svg .= $title; |
|
| 3692 | + } |
|
| 3693 | + else { |
|
| 3694 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3695 | + } |
|
| 3696 | 3696 | |
| 3697 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3697 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3698 | 3698 | |
| 3699 | - if (!is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3700 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3699 | + if (!is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3700 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3701 | 3701 | |
| 3702 | - if (!function_exists('svg_redimensionner')) { |
|
| 3703 | - include_spip('inc/svg'); |
|
| 3704 | - } |
|
| 3705 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3706 | - } |
|
| 3702 | + if (!function_exists('svg_redimensionner')) { |
|
| 3703 | + include_spip('inc/svg'); |
|
| 3704 | + } |
|
| 3705 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3706 | + } |
|
| 3707 | 3707 | |
| 3708 | - return $svg; |
|
| 3708 | + return $svg; |
|
| 3709 | 3709 | } |
| 3710 | 3710 | |
| 3711 | 3711 | |
@@ -3731,18 +3731,18 @@ discard block |
||
| 3731 | 3731 | * Code HTML résultant |
| 3732 | 3732 | **/ |
| 3733 | 3733 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3734 | - $texte = ''; |
|
| 3735 | - if (is_array($tableau)) { |
|
| 3736 | - foreach ($tableau as $k => $v) { |
|
| 3737 | - $res = recuperer_fond( |
|
| 3738 | - 'modeles/' . $modele, |
|
| 3739 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3740 | - ); |
|
| 3741 | - $texte .= $res; |
|
| 3742 | - } |
|
| 3743 | - } |
|
| 3734 | + $texte = ''; |
|
| 3735 | + if (is_array($tableau)) { |
|
| 3736 | + foreach ($tableau as $k => $v) { |
|
| 3737 | + $res = recuperer_fond( |
|
| 3738 | + 'modeles/' . $modele, |
|
| 3739 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3740 | + ); |
|
| 3741 | + $texte .= $res; |
|
| 3742 | + } |
|
| 3743 | + } |
|
| 3744 | 3744 | |
| 3745 | - return $texte; |
|
| 3745 | + return $texte; |
|
| 3746 | 3746 | } |
| 3747 | 3747 | |
| 3748 | 3748 | |
@@ -3767,37 +3767,37 @@ discard block |
||
| 3767 | 3767 | * - tout : retourne toutes les informations du plugin actif |
| 3768 | 3768 | **/ |
| 3769 | 3769 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3770 | - include_spip('inc/plugin'); |
|
| 3771 | - $plugin = strtoupper($plugin); |
|
| 3772 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3773 | - |
|
| 3774 | - if (!$plugin) { |
|
| 3775 | - return serialize(array_keys($plugins_actifs)); |
|
| 3776 | - } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3777 | - return ''; |
|
| 3778 | - } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3779 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3780 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3781 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3782 | - } else { |
|
| 3783 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3784 | - // On prend en compte les extensions |
|
| 3785 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3786 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3787 | - } else { |
|
| 3788 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3789 | - } |
|
| 3790 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3791 | - return ''; |
|
| 3792 | - } |
|
| 3793 | - if ($type_info == 'tout') { |
|
| 3794 | - return $infos; |
|
| 3795 | - } elseif ($type_info == 'est_actif') { |
|
| 3796 | - return $infos ? 1 : 0; |
|
| 3797 | - } else { |
|
| 3798 | - return (string) $infos[$type_info]; |
|
| 3799 | - } |
|
| 3800 | - } |
|
| 3770 | + include_spip('inc/plugin'); |
|
| 3771 | + $plugin = strtoupper($plugin); |
|
| 3772 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3773 | + |
|
| 3774 | + if (!$plugin) { |
|
| 3775 | + return serialize(array_keys($plugins_actifs)); |
|
| 3776 | + } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3777 | + return ''; |
|
| 3778 | + } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3779 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3780 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3781 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3782 | + } else { |
|
| 3783 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3784 | + // On prend en compte les extensions |
|
| 3785 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3786 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3787 | + } else { |
|
| 3788 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3789 | + } |
|
| 3790 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3791 | + return ''; |
|
| 3792 | + } |
|
| 3793 | + if ($type_info == 'tout') { |
|
| 3794 | + return $infos; |
|
| 3795 | + } elseif ($type_info == 'est_actif') { |
|
| 3796 | + return $infos ? 1 : 0; |
|
| 3797 | + } else { |
|
| 3798 | + return (string) $infos[$type_info]; |
|
| 3799 | + } |
|
| 3800 | + } |
|
| 3801 | 3801 | } |
| 3802 | 3802 | |
| 3803 | 3803 | |
@@ -3824,9 +3824,9 @@ discard block |
||
| 3824 | 3824 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3825 | 3825 | */ |
| 3826 | 3826 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3827 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3827 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3828 | 3828 | |
| 3829 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3829 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3830 | 3830 | } |
| 3831 | 3831 | |
| 3832 | 3832 | |
@@ -3856,19 +3856,19 @@ discard block |
||
| 3856 | 3856 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3857 | 3857 | */ |
| 3858 | 3858 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3859 | - static $puce_statut = null; |
|
| 3860 | - if (!$puce_statut) { |
|
| 3861 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3862 | - } |
|
| 3859 | + static $puce_statut = null; |
|
| 3860 | + if (!$puce_statut) { |
|
| 3861 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3862 | + } |
|
| 3863 | 3863 | |
| 3864 | - return $puce_statut( |
|
| 3865 | - $id_objet, |
|
| 3866 | - $statut, |
|
| 3867 | - $id_parent, |
|
| 3868 | - $objet, |
|
| 3869 | - false, |
|
| 3870 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3871 | - ); |
|
| 3864 | + return $puce_statut( |
|
| 3865 | + $id_objet, |
|
| 3866 | + $statut, |
|
| 3867 | + $id_parent, |
|
| 3868 | + $objet, |
|
| 3869 | + false, |
|
| 3870 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3871 | + ); |
|
| 3872 | 3872 | } |
| 3873 | 3873 | |
| 3874 | 3874 | |
@@ -3895,95 +3895,95 @@ discard block |
||
| 3895 | 3895 | * hash du contexte |
| 3896 | 3896 | */ |
| 3897 | 3897 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3898 | - $env = null; |
|
| 3899 | - if (is_string($c) && @unserialize($c) !== false) { |
|
| 3900 | - $c = unserialize($c); |
|
| 3901 | - } |
|
| 3902 | - |
|
| 3903 | - // supprimer les parametres debut_x |
|
| 3904 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3905 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3906 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3907 | - if (is_array($c)) { |
|
| 3908 | - foreach (array_keys($c) as $k) { |
|
| 3909 | - if (str_starts_with($k, 'debut_')) { |
|
| 3910 | - unset($c[$k]); |
|
| 3911 | - } |
|
| 3912 | - } |
|
| 3913 | - } |
|
| 3914 | - |
|
| 3915 | - if (!function_exists('calculer_cle_action')) { |
|
| 3916 | - include_spip('inc/securiser_action'); |
|
| 3917 | - } |
|
| 3918 | - |
|
| 3919 | - $c = serialize($c); |
|
| 3920 | - $cle = calculer_cle_action($form . $c); |
|
| 3921 | - $c = "$cle:$c"; |
|
| 3922 | - |
|
| 3923 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3924 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3925 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3926 | - // que ce qui est toléré. |
|
| 3927 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3928 | - if (!$cache_contextes_ajax) { |
|
| 3929 | - $env = $c; |
|
| 3930 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3931 | - $env = gzdeflate($env); |
|
| 3932 | - } |
|
| 3933 | - $env = _xor($env); |
|
| 3934 | - $env = base64_encode($env); |
|
| 3935 | - $len = strlen($env); |
|
| 3936 | - // Si l’url est trop longue pour le navigateur |
|
| 3937 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3938 | - if ($len > $max_len) { |
|
| 3939 | - $cache_contextes_ajax = true; |
|
| 3940 | - spip_log( |
|
| 3941 | - 'Contextes AJAX forces en fichiers !' |
|
| 3942 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3943 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3944 | - _LOG_AVERTISSEMENT |
|
| 3945 | - ); |
|
| 3946 | - } |
|
| 3947 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3948 | - elseif ( |
|
| 3949 | - ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3950 | - && $max_len < $len |
|
| 3951 | - ) { |
|
| 3952 | - $cache_contextes_ajax = true; |
|
| 3953 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3954 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3955 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3956 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3957 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3958 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3959 | - } |
|
| 3960 | - } |
|
| 3961 | - |
|
| 3962 | - if ($cache_contextes_ajax) { |
|
| 3963 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3964 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3965 | - $md5 = md5($c); |
|
| 3966 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3967 | - $env = $md5; |
|
| 3968 | - } |
|
| 3969 | - |
|
| 3970 | - if ($emboite === null) { |
|
| 3971 | - return $env; |
|
| 3972 | - } |
|
| 3973 | - if (!trim($emboite)) { |
|
| 3974 | - return ''; |
|
| 3975 | - } |
|
| 3976 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3977 | - $r = self(); |
|
| 3978 | - $r = ' data-origin="' . $r . '"'; |
|
| 3979 | - $class = 'ajaxbloc'; |
|
| 3980 | - if ($ajaxid && is_string($ajaxid)) { |
|
| 3981 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3982 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3983 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3984 | - } |
|
| 3985 | - |
|
| 3986 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3898 | + $env = null; |
|
| 3899 | + if (is_string($c) && @unserialize($c) !== false) { |
|
| 3900 | + $c = unserialize($c); |
|
| 3901 | + } |
|
| 3902 | + |
|
| 3903 | + // supprimer les parametres debut_x |
|
| 3904 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3905 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3906 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3907 | + if (is_array($c)) { |
|
| 3908 | + foreach (array_keys($c) as $k) { |
|
| 3909 | + if (str_starts_with($k, 'debut_')) { |
|
| 3910 | + unset($c[$k]); |
|
| 3911 | + } |
|
| 3912 | + } |
|
| 3913 | + } |
|
| 3914 | + |
|
| 3915 | + if (!function_exists('calculer_cle_action')) { |
|
| 3916 | + include_spip('inc/securiser_action'); |
|
| 3917 | + } |
|
| 3918 | + |
|
| 3919 | + $c = serialize($c); |
|
| 3920 | + $cle = calculer_cle_action($form . $c); |
|
| 3921 | + $c = "$cle:$c"; |
|
| 3922 | + |
|
| 3923 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3924 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3925 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3926 | + // que ce qui est toléré. |
|
| 3927 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3928 | + if (!$cache_contextes_ajax) { |
|
| 3929 | + $env = $c; |
|
| 3930 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3931 | + $env = gzdeflate($env); |
|
| 3932 | + } |
|
| 3933 | + $env = _xor($env); |
|
| 3934 | + $env = base64_encode($env); |
|
| 3935 | + $len = strlen($env); |
|
| 3936 | + // Si l’url est trop longue pour le navigateur |
|
| 3937 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3938 | + if ($len > $max_len) { |
|
| 3939 | + $cache_contextes_ajax = true; |
|
| 3940 | + spip_log( |
|
| 3941 | + 'Contextes AJAX forces en fichiers !' |
|
| 3942 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3943 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3944 | + _LOG_AVERTISSEMENT |
|
| 3945 | + ); |
|
| 3946 | + } |
|
| 3947 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3948 | + elseif ( |
|
| 3949 | + ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3950 | + && $max_len < $len |
|
| 3951 | + ) { |
|
| 3952 | + $cache_contextes_ajax = true; |
|
| 3953 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3954 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3955 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3956 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3957 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3958 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3959 | + } |
|
| 3960 | + } |
|
| 3961 | + |
|
| 3962 | + if ($cache_contextes_ajax) { |
|
| 3963 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3964 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3965 | + $md5 = md5($c); |
|
| 3966 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3967 | + $env = $md5; |
|
| 3968 | + } |
|
| 3969 | + |
|
| 3970 | + if ($emboite === null) { |
|
| 3971 | + return $env; |
|
| 3972 | + } |
|
| 3973 | + if (!trim($emboite)) { |
|
| 3974 | + return ''; |
|
| 3975 | + } |
|
| 3976 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3977 | + $r = self(); |
|
| 3978 | + $r = ' data-origin="' . $r . '"'; |
|
| 3979 | + $class = 'ajaxbloc'; |
|
| 3980 | + if ($ajaxid && is_string($ajaxid)) { |
|
| 3981 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3982 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3983 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3984 | + } |
|
| 3985 | + |
|
| 3986 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3987 | 3987 | } |
| 3988 | 3988 | |
| 3989 | 3989 | /** |
@@ -4003,37 +4003,37 @@ discard block |
||
| 4003 | 4003 | * - false : erreur de décodage |
| 4004 | 4004 | */ |
| 4005 | 4005 | function decoder_contexte_ajax($c, $form = '') { |
| 4006 | - $contexte = null; |
|
| 4007 | - if (!function_exists('calculer_cle_action')) { |
|
| 4008 | - include_spip('inc/securiser_action'); |
|
| 4009 | - } |
|
| 4010 | - if ( |
|
| 4011 | - (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 4012 | - && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 4013 | - && lire_fichier("$dir/c$c", $contexte) |
|
| 4014 | - ) { |
|
| 4015 | - $c = $contexte; |
|
| 4016 | - } else { |
|
| 4017 | - $c = @base64_decode($c); |
|
| 4018 | - $c = _xor($c); |
|
| 4019 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4020 | - $c = @gzinflate($c); |
|
| 4021 | - } |
|
| 4022 | - } |
|
| 4023 | - |
|
| 4024 | - // extraire la signature en debut de contexte |
|
| 4025 | - // et la verifier avant de deserializer |
|
| 4026 | - // format : signature:donneesserializees |
|
| 4027 | - if ($p = strpos((string) $c, ':')) { |
|
| 4028 | - $cle = substr((string) $c, 0, $p); |
|
| 4029 | - $c = substr((string) $c, $p + 1); |
|
| 4030 | - |
|
| 4031 | - if ($cle === calculer_cle_action($form . $c)) { |
|
| 4032 | - return @unserialize($c); |
|
| 4033 | - } |
|
| 4034 | - } |
|
| 4035 | - |
|
| 4036 | - return false; |
|
| 4006 | + $contexte = null; |
|
| 4007 | + if (!function_exists('calculer_cle_action')) { |
|
| 4008 | + include_spip('inc/securiser_action'); |
|
| 4009 | + } |
|
| 4010 | + if ( |
|
| 4011 | + (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 4012 | + && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 4013 | + && lire_fichier("$dir/c$c", $contexte) |
|
| 4014 | + ) { |
|
| 4015 | + $c = $contexte; |
|
| 4016 | + } else { |
|
| 4017 | + $c = @base64_decode($c); |
|
| 4018 | + $c = _xor($c); |
|
| 4019 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4020 | + $c = @gzinflate($c); |
|
| 4021 | + } |
|
| 4022 | + } |
|
| 4023 | + |
|
| 4024 | + // extraire la signature en debut de contexte |
|
| 4025 | + // et la verifier avant de deserializer |
|
| 4026 | + // format : signature:donneesserializees |
|
| 4027 | + if ($p = strpos((string) $c, ':')) { |
|
| 4028 | + $cle = substr((string) $c, 0, $p); |
|
| 4029 | + $c = substr((string) $c, $p + 1); |
|
| 4030 | + |
|
| 4031 | + if ($cle === calculer_cle_action($form . $c)) { |
|
| 4032 | + return @unserialize($c); |
|
| 4033 | + } |
|
| 4034 | + } |
|
| 4035 | + |
|
| 4036 | + return false; |
|
| 4037 | 4037 | } |
| 4038 | 4038 | |
| 4039 | 4039 | |
@@ -4051,20 +4051,20 @@ discard block |
||
| 4051 | 4051 | * Message décrypté ou encrypté |
| 4052 | 4052 | **/ |
| 4053 | 4053 | function _xor($message, $key = null) { |
| 4054 | - if (is_null($key)) { |
|
| 4055 | - if (!function_exists('calculer_cle_action')) { |
|
| 4056 | - include_spip('inc/securiser_action'); |
|
| 4057 | - } |
|
| 4058 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4059 | - } |
|
| 4054 | + if (is_null($key)) { |
|
| 4055 | + if (!function_exists('calculer_cle_action')) { |
|
| 4056 | + include_spip('inc/securiser_action'); |
|
| 4057 | + } |
|
| 4058 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4059 | + } |
|
| 4060 | 4060 | |
| 4061 | - $keylen = strlen($key); |
|
| 4062 | - $messagelen = strlen($message); |
|
| 4063 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4064 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4065 | - } |
|
| 4061 | + $keylen = strlen($key); |
|
| 4062 | + $messagelen = strlen($message); |
|
| 4063 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4064 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4065 | + } |
|
| 4066 | 4066 | |
| 4067 | - return $message; |
|
| 4067 | + return $message; |
|
| 4068 | 4068 | } |
| 4069 | 4069 | |
| 4070 | 4070 | /** |
@@ -4078,7 +4078,7 @@ discard block |
||
| 4078 | 4078 | * @return string |
| 4079 | 4079 | */ |
| 4080 | 4080 | function url_reponse_forum($texte) { |
| 4081 | - return $texte; |
|
| 4081 | + return $texte; |
|
| 4082 | 4082 | } |
| 4083 | 4083 | |
| 4084 | 4084 | /** |
@@ -4092,7 +4092,7 @@ discard block |
||
| 4092 | 4092 | * @return string |
| 4093 | 4093 | */ |
| 4094 | 4094 | function url_rss_forum($texte) { |
| 4095 | - return $texte; |
|
| 4095 | + return $texte; |
|
| 4096 | 4096 | } |
| 4097 | 4097 | |
| 4098 | 4098 | |
@@ -4131,37 +4131,37 @@ discard block |
||
| 4131 | 4131 | * Code HTML |
| 4132 | 4132 | */ |
| 4133 | 4133 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4134 | - if ($on) { |
|
| 4135 | - $bal = 'strong'; |
|
| 4136 | - $class = ''; |
|
| 4137 | - $att = ''; |
|
| 4138 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4139 | - // a.active span.selected.active etc.... |
|
| 4140 | - if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4141 | - $on = explode('.', $on); |
|
| 4142 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4143 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4144 | - $bal = array_shift($on); |
|
| 4145 | - $class = implode(' ', $on); |
|
| 4146 | - if ($bal == 'a') { |
|
| 4147 | - $att = 'href="#" '; |
|
| 4148 | - } |
|
| 4149 | - } |
|
| 4150 | - } |
|
| 4151 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4152 | - } else { |
|
| 4153 | - $bal = 'a'; |
|
| 4154 | - $att = "href='$url'" |
|
| 4155 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4156 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4157 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4158 | - . $evt; |
|
| 4159 | - } |
|
| 4160 | - if ($libelle === null) { |
|
| 4161 | - $libelle = $url; |
|
| 4162 | - } |
|
| 4163 | - |
|
| 4164 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4134 | + if ($on) { |
|
| 4135 | + $bal = 'strong'; |
|
| 4136 | + $class = ''; |
|
| 4137 | + $att = ''; |
|
| 4138 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4139 | + // a.active span.selected.active etc.... |
|
| 4140 | + if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4141 | + $on = explode('.', $on); |
|
| 4142 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4143 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4144 | + $bal = array_shift($on); |
|
| 4145 | + $class = implode(' ', $on); |
|
| 4146 | + if ($bal == 'a') { |
|
| 4147 | + $att = 'href="#" '; |
|
| 4148 | + } |
|
| 4149 | + } |
|
| 4150 | + } |
|
| 4151 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4152 | + } else { |
|
| 4153 | + $bal = 'a'; |
|
| 4154 | + $att = "href='$url'" |
|
| 4155 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4156 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4157 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4158 | + . $evt; |
|
| 4159 | + } |
|
| 4160 | + if ($libelle === null) { |
|
| 4161 | + $libelle = $url; |
|
| 4162 | + } |
|
| 4163 | + |
|
| 4164 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4165 | 4165 | } |
| 4166 | 4166 | |
| 4167 | 4167 | |
@@ -4178,39 +4178,39 @@ discard block |
||
| 4178 | 4178 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4179 | 4179 | */ |
| 4180 | 4180 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4181 | - static $local_singulier_ou_pluriel = []; |
|
| 4182 | - |
|
| 4183 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4184 | - if (!is_numeric($nb) || $nb == 0) { |
|
| 4185 | - return ''; |
|
| 4186 | - } |
|
| 4187 | - if (!is_array($vars)) { |
|
| 4188 | - return ''; |
|
| 4189 | - } |
|
| 4190 | - |
|
| 4191 | - $langue = $GLOBALS['spip_lang']; |
|
| 4192 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4193 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4194 | - if ( |
|
| 4195 | - ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4196 | - || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4197 | - ) { |
|
| 4198 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4199 | - } |
|
| 4200 | - } |
|
| 4201 | - |
|
| 4202 | - // si on a une surcharge on l'utilise |
|
| 4203 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4204 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4205 | - } |
|
| 4206 | - |
|
| 4207 | - // sinon traitement par defaut |
|
| 4208 | - $vars[$var] = $nb; |
|
| 4209 | - if ($nb >= 2) { |
|
| 4210 | - return _T($chaine_plusieurs, $vars); |
|
| 4211 | - } else { |
|
| 4212 | - return _T($chaine_un, $vars); |
|
| 4213 | - } |
|
| 4181 | + static $local_singulier_ou_pluriel = []; |
|
| 4182 | + |
|
| 4183 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4184 | + if (!is_numeric($nb) || $nb == 0) { |
|
| 4185 | + return ''; |
|
| 4186 | + } |
|
| 4187 | + if (!is_array($vars)) { |
|
| 4188 | + return ''; |
|
| 4189 | + } |
|
| 4190 | + |
|
| 4191 | + $langue = $GLOBALS['spip_lang']; |
|
| 4192 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4193 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4194 | + if ( |
|
| 4195 | + ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4196 | + || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4197 | + ) { |
|
| 4198 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4199 | + } |
|
| 4200 | + } |
|
| 4201 | + |
|
| 4202 | + // si on a une surcharge on l'utilise |
|
| 4203 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4204 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4205 | + } |
|
| 4206 | + |
|
| 4207 | + // sinon traitement par defaut |
|
| 4208 | + $vars[$var] = $nb; |
|
| 4209 | + if ($nb >= 2) { |
|
| 4210 | + return _T($chaine_plusieurs, $vars); |
|
| 4211 | + } else { |
|
| 4212 | + return _T($chaine_un, $vars); |
|
| 4213 | + } |
|
| 4214 | 4214 | } |
| 4215 | 4215 | |
| 4216 | 4216 | |
@@ -4238,71 +4238,71 @@ discard block |
||
| 4238 | 4238 | */ |
| 4239 | 4239 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4240 | 4240 | |
| 4241 | - $class_lien = $class_bouton = $class; |
|
| 4242 | - |
|
| 4243 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4244 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4245 | - $class_lien .= ' danger'; |
|
| 4246 | - $class_bouton .= ' btn_danger'; |
|
| 4247 | - } elseif ($fonction == 'rien.gif') { |
|
| 4248 | - $fonction = ''; |
|
| 4249 | - } elseif ($fonction == 'delsafe') { |
|
| 4250 | - $fonction = 'del'; |
|
| 4251 | - } |
|
| 4252 | - |
|
| 4253 | - $fond_origine = $fond; |
|
| 4254 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4255 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4256 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4257 | - } |
|
| 4258 | - |
|
| 4259 | - // Ajouter le type d'objet dans la classe |
|
| 4260 | - $objet_type = substr(basename((string) $fond), 0, -4); |
|
| 4261 | - $class_lien .= " $objet_type"; |
|
| 4262 | - $class_bouton .= " $objet_type"; |
|
| 4263 | - |
|
| 4264 | - // texte |
|
| 4265 | - $alt = attribut_html($texte); |
|
| 4266 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4267 | - |
|
| 4268 | - // Liens : préparer les classes ajax |
|
| 4269 | - $ajax = ''; |
|
| 4270 | - if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4271 | - $ajax = 'ajax'; |
|
| 4272 | - if (str_contains($class_lien, 'preload')) { |
|
| 4273 | - $ajax .= ' preload'; |
|
| 4274 | - } |
|
| 4275 | - if (str_contains($class_lien, 'nocache')) { |
|
| 4276 | - $ajax .= ' nocache'; |
|
| 4277 | - } |
|
| 4278 | - $ajax = " class='$ajax'"; |
|
| 4279 | - } |
|
| 4280 | - |
|
| 4281 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4282 | - $size = 24; |
|
| 4283 | - if ( |
|
| 4284 | - preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match) |
|
| 4285 | - || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4286 | - ) { |
|
| 4287 | - $size = $match[1]; |
|
| 4288 | - } |
|
| 4289 | - $class_lien .= " s$size"; |
|
| 4290 | - $class_bouton .= " s$size"; |
|
| 4291 | - |
|
| 4292 | - // Icône |
|
| 4293 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4294 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4295 | - |
|
| 4296 | - // Markup final |
|
| 4297 | - if ($type == 'lien') { |
|
| 4298 | - return "<span class='icone $class_lien'>" |
|
| 4299 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4300 | - . $icone |
|
| 4301 | - . "<b>$texte</b>" |
|
| 4302 | - . "</a></span>\n"; |
|
| 4303 | - } else { |
|
| 4304 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4305 | - } |
|
| 4241 | + $class_lien = $class_bouton = $class; |
|
| 4242 | + |
|
| 4243 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4244 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4245 | + $class_lien .= ' danger'; |
|
| 4246 | + $class_bouton .= ' btn_danger'; |
|
| 4247 | + } elseif ($fonction == 'rien.gif') { |
|
| 4248 | + $fonction = ''; |
|
| 4249 | + } elseif ($fonction == 'delsafe') { |
|
| 4250 | + $fonction = 'del'; |
|
| 4251 | + } |
|
| 4252 | + |
|
| 4253 | + $fond_origine = $fond; |
|
| 4254 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4255 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4256 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4257 | + } |
|
| 4258 | + |
|
| 4259 | + // Ajouter le type d'objet dans la classe |
|
| 4260 | + $objet_type = substr(basename((string) $fond), 0, -4); |
|
| 4261 | + $class_lien .= " $objet_type"; |
|
| 4262 | + $class_bouton .= " $objet_type"; |
|
| 4263 | + |
|
| 4264 | + // texte |
|
| 4265 | + $alt = attribut_html($texte); |
|
| 4266 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4267 | + |
|
| 4268 | + // Liens : préparer les classes ajax |
|
| 4269 | + $ajax = ''; |
|
| 4270 | + if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4271 | + $ajax = 'ajax'; |
|
| 4272 | + if (str_contains($class_lien, 'preload')) { |
|
| 4273 | + $ajax .= ' preload'; |
|
| 4274 | + } |
|
| 4275 | + if (str_contains($class_lien, 'nocache')) { |
|
| 4276 | + $ajax .= ' nocache'; |
|
| 4277 | + } |
|
| 4278 | + $ajax = " class='$ajax'"; |
|
| 4279 | + } |
|
| 4280 | + |
|
| 4281 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4282 | + $size = 24; |
|
| 4283 | + if ( |
|
| 4284 | + preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match) |
|
| 4285 | + || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4286 | + ) { |
|
| 4287 | + $size = $match[1]; |
|
| 4288 | + } |
|
| 4289 | + $class_lien .= " s$size"; |
|
| 4290 | + $class_bouton .= " s$size"; |
|
| 4291 | + |
|
| 4292 | + // Icône |
|
| 4293 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4294 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4295 | + |
|
| 4296 | + // Markup final |
|
| 4297 | + if ($type == 'lien') { |
|
| 4298 | + return "<span class='icone $class_lien'>" |
|
| 4299 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4300 | + . $icone |
|
| 4301 | + . "<b>$texte</b>" |
|
| 4302 | + . "</a></span>\n"; |
|
| 4303 | + } else { |
|
| 4304 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4305 | + } |
|
| 4306 | 4306 | } |
| 4307 | 4307 | |
| 4308 | 4308 | /** |
@@ -4326,7 +4326,7 @@ discard block |
||
| 4326 | 4326 | * Code HTML du lien |
| 4327 | 4327 | **/ |
| 4328 | 4328 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4329 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4329 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4330 | 4330 | } |
| 4331 | 4331 | |
| 4332 | 4332 | /** |
@@ -4361,7 +4361,7 @@ discard block |
||
| 4361 | 4361 | * Code HTML du lien |
| 4362 | 4362 | **/ |
| 4363 | 4363 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4364 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4364 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4365 | 4365 | } |
| 4366 | 4366 | |
| 4367 | 4367 | /** |
@@ -4406,7 +4406,7 @@ discard block |
||
| 4406 | 4406 | * Code HTML du lien |
| 4407 | 4407 | **/ |
| 4408 | 4408 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4409 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4409 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4410 | 4410 | } |
| 4411 | 4411 | |
| 4412 | 4412 | /** |
@@ -4437,7 +4437,7 @@ discard block |
||
| 4437 | 4437 | * Code HTML du lien |
| 4438 | 4438 | **/ |
| 4439 | 4439 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4440 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4440 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4441 | 4441 | } |
| 4442 | 4442 | |
| 4443 | 4443 | /** |
@@ -4468,7 +4468,7 @@ discard block |
||
| 4468 | 4468 | * Code HTML du lien |
| 4469 | 4469 | */ |
| 4470 | 4470 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4471 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4471 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4472 | 4472 | } |
| 4473 | 4473 | |
| 4474 | 4474 | |
@@ -4490,7 +4490,7 @@ discard block |
||
| 4490 | 4490 | * @return array Liste des éléments |
| 4491 | 4491 | */ |
| 4492 | 4492 | function filtre_explode_dist($a, $b) { |
| 4493 | - return explode($b, (string) $a); |
|
| 4493 | + return explode($b, (string) $a); |
|
| 4494 | 4494 | } |
| 4495 | 4495 | |
| 4496 | 4496 | /** |
@@ -4511,7 +4511,7 @@ discard block |
||
| 4511 | 4511 | * @return string texte |
| 4512 | 4512 | */ |
| 4513 | 4513 | function filtre_implode_dist($a, $b) { |
| 4514 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4514 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4515 | 4515 | } |
| 4516 | 4516 | |
| 4517 | 4517 | /** |
@@ -4520,22 +4520,22 @@ discard block |
||
| 4520 | 4520 | * @return string Code CSS |
| 4521 | 4521 | */ |
| 4522 | 4522 | function bando_images_background() { |
| 4523 | - include_spip('inc/bandeau'); |
|
| 4524 | - // recuperer tous les boutons et leurs images |
|
| 4525 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4523 | + include_spip('inc/bandeau'); |
|
| 4524 | + // recuperer tous les boutons et leurs images |
|
| 4525 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4526 | 4526 | |
| 4527 | - $res = ''; |
|
| 4528 | - foreach ($boutons as $page => $detail) { |
|
| 4529 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4530 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4531 | - if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) { |
|
| 4532 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4533 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4534 | - } |
|
| 4535 | - } |
|
| 4536 | - } |
|
| 4527 | + $res = ''; |
|
| 4528 | + foreach ($boutons as $page => $detail) { |
|
| 4529 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4530 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4531 | + if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) { |
|
| 4532 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4533 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4534 | + } |
|
| 4535 | + } |
|
| 4536 | + } |
|
| 4537 | 4537 | |
| 4538 | - return $res; |
|
| 4538 | + return $res; |
|
| 4539 | 4539 | } |
| 4540 | 4540 | |
| 4541 | 4541 | /** |
@@ -4560,23 +4560,23 @@ discard block |
||
| 4560 | 4560 | */ |
| 4561 | 4561 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4562 | 4562 | |
| 4563 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4564 | - $class_form = ''; |
|
| 4565 | - if (str_contains($class, 'ajax')) { |
|
| 4566 | - $class_form = 'ajax'; |
|
| 4567 | - $class = str_replace('ajax', '', $class); |
|
| 4568 | - } |
|
| 4569 | - $class_btn = 'submit ' . trim($class); |
|
| 4563 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4564 | + $class_form = ''; |
|
| 4565 | + if (str_contains($class, 'ajax')) { |
|
| 4566 | + $class_form = 'ajax'; |
|
| 4567 | + $class = str_replace('ajax', '', $class); |
|
| 4568 | + } |
|
| 4569 | + $class_btn = 'submit ' . trim($class); |
|
| 4570 | 4570 | |
| 4571 | - if ($confirm) { |
|
| 4572 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4573 | - $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4574 | - } |
|
| 4575 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4576 | - $title = $title ? " title='$title'" : ''; |
|
| 4571 | + if ($confirm) { |
|
| 4572 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4573 | + $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4574 | + } |
|
| 4575 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4576 | + $title = $title ? " title='$title'" : ''; |
|
| 4577 | 4577 | |
| 4578 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4579 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4578 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4579 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4580 | 4580 | } |
| 4581 | 4581 | |
| 4582 | 4582 | /** |
@@ -4599,98 +4599,98 @@ discard block |
||
| 4599 | 4599 | * @return string |
| 4600 | 4600 | */ |
| 4601 | 4601 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4602 | - static $trouver_table = null; |
|
| 4603 | - static $objets; |
|
| 4604 | - |
|
| 4605 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4606 | - $id_objet = (int) $id_objet; |
|
| 4607 | - if (!($id_objet && $type_objet && $info)) { |
|
| 4608 | - return ''; |
|
| 4609 | - } |
|
| 4610 | - |
|
| 4611 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4612 | - if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4613 | - return ''; |
|
| 4614 | - } |
|
| 4615 | - |
|
| 4616 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4617 | - if ($info == 'url') { |
|
| 4618 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4619 | - } |
|
| 4620 | - |
|
| 4621 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4622 | - $demande_titre = ($info === 'titre'); |
|
| 4623 | - $demande_introduction = ($info === 'introduction'); |
|
| 4624 | - |
|
| 4625 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4626 | - if ( |
|
| 4627 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4628 | - || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4629 | - ) { |
|
| 4630 | - if (!$trouver_table) { |
|
| 4631 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4632 | - } |
|
| 4633 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4634 | - if (!$desc) { |
|
| 4635 | - return $objets[$type_objet] = false; |
|
| 4636 | - } |
|
| 4637 | - |
|
| 4638 | - // Si on demande le titre, on le gere en interne |
|
| 4639 | - $champ_titre = ''; |
|
| 4640 | - if ($demande_titre) { |
|
| 4641 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4642 | - $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4643 | - } |
|
| 4644 | - include_spip('base/abstract_sql'); |
|
| 4645 | - include_spip('base/connect_sql'); |
|
| 4646 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4647 | - '*' . $champ_titre, |
|
| 4648 | - $desc['table_sql'], |
|
| 4649 | - id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4650 | - ); |
|
| 4651 | - |
|
| 4652 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4653 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4654 | - } |
|
| 4655 | - |
|
| 4656 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4657 | - // ajouter la longueur au début des params supplémentaires |
|
| 4658 | - if ($demande_introduction) { |
|
| 4659 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4660 | - array_unshift($params, $introduction_longueur); |
|
| 4661 | - } |
|
| 4662 | - |
|
| 4663 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4664 | - if ( |
|
| 4665 | - ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) |
|
| 4666 | - || ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) |
|
| 4667 | - ) { |
|
| 4668 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4669 | - } |
|
| 4670 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4671 | - elseif ( |
|
| 4672 | - ($generer = charger_fonction("generer_objet_{$info}", '', true)) |
|
| 4673 | - || ($generer = charger_fonction("generer_{$info}_entite", '', true)) |
|
| 4674 | - ) { |
|
| 4675 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4676 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4677 | - else { |
|
| 4678 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4679 | - } |
|
| 4680 | - |
|
| 4681 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4682 | - if (!$etoile) { |
|
| 4683 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4684 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4685 | - $info_generee = appliquer_traitement_champ( |
|
| 4686 | - $info_generee, |
|
| 4687 | - $info, |
|
| 4688 | - table_objet($type_objet), |
|
| 4689 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4690 | - ); |
|
| 4691 | - } |
|
| 4692 | - |
|
| 4693 | - return $info_generee; |
|
| 4602 | + static $trouver_table = null; |
|
| 4603 | + static $objets; |
|
| 4604 | + |
|
| 4605 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4606 | + $id_objet = (int) $id_objet; |
|
| 4607 | + if (!($id_objet && $type_objet && $info)) { |
|
| 4608 | + return ''; |
|
| 4609 | + } |
|
| 4610 | + |
|
| 4611 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4612 | + if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4613 | + return ''; |
|
| 4614 | + } |
|
| 4615 | + |
|
| 4616 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4617 | + if ($info == 'url') { |
|
| 4618 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4619 | + } |
|
| 4620 | + |
|
| 4621 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4622 | + $demande_titre = ($info === 'titre'); |
|
| 4623 | + $demande_introduction = ($info === 'introduction'); |
|
| 4624 | + |
|
| 4625 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4626 | + if ( |
|
| 4627 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4628 | + || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4629 | + ) { |
|
| 4630 | + if (!$trouver_table) { |
|
| 4631 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4632 | + } |
|
| 4633 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4634 | + if (!$desc) { |
|
| 4635 | + return $objets[$type_objet] = false; |
|
| 4636 | + } |
|
| 4637 | + |
|
| 4638 | + // Si on demande le titre, on le gere en interne |
|
| 4639 | + $champ_titre = ''; |
|
| 4640 | + if ($demande_titre) { |
|
| 4641 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4642 | + $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4643 | + } |
|
| 4644 | + include_spip('base/abstract_sql'); |
|
| 4645 | + include_spip('base/connect_sql'); |
|
| 4646 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4647 | + '*' . $champ_titre, |
|
| 4648 | + $desc['table_sql'], |
|
| 4649 | + id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4650 | + ); |
|
| 4651 | + |
|
| 4652 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4653 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4654 | + } |
|
| 4655 | + |
|
| 4656 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4657 | + // ajouter la longueur au début des params supplémentaires |
|
| 4658 | + if ($demande_introduction) { |
|
| 4659 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4660 | + array_unshift($params, $introduction_longueur); |
|
| 4661 | + } |
|
| 4662 | + |
|
| 4663 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4664 | + if ( |
|
| 4665 | + ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) |
|
| 4666 | + || ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) |
|
| 4667 | + ) { |
|
| 4668 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4669 | + } |
|
| 4670 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4671 | + elseif ( |
|
| 4672 | + ($generer = charger_fonction("generer_objet_{$info}", '', true)) |
|
| 4673 | + || ($generer = charger_fonction("generer_{$info}_entite", '', true)) |
|
| 4674 | + ) { |
|
| 4675 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4676 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4677 | + else { |
|
| 4678 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4679 | + } |
|
| 4680 | + |
|
| 4681 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4682 | + if (!$etoile) { |
|
| 4683 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4684 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4685 | + $info_generee = appliquer_traitement_champ( |
|
| 4686 | + $info_generee, |
|
| 4687 | + $info, |
|
| 4688 | + table_objet($type_objet), |
|
| 4689 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4690 | + ); |
|
| 4691 | + } |
|
| 4692 | + |
|
| 4693 | + return $info_generee; |
|
| 4694 | 4694 | } |
| 4695 | 4695 | |
| 4696 | 4696 | /** |
@@ -4698,7 +4698,7 @@ discard block |
||
| 4698 | 4698 | * @see generer_objet_info |
| 4699 | 4699 | */ |
| 4700 | 4700 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4701 | - return generer_objet_info((int) $id_objet, $type_objet, $info, $etoile, $params); |
|
| 4701 | + return generer_objet_info((int) $id_objet, $type_objet, $info, $etoile, $params); |
|
| 4702 | 4702 | } |
| 4703 | 4703 | |
| 4704 | 4704 | /** |
@@ -4731,34 +4731,34 @@ discard block |
||
| 4731 | 4731 | */ |
| 4732 | 4732 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4733 | 4733 | |
| 4734 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4735 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4736 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4737 | - if (isset($ligne_sql['chapo'])) { |
|
| 4738 | - $chapo = $ligne_sql['chapo']; |
|
| 4739 | - $texte = strlen((string) $descriptif) ? |
|
| 4740 | - '' : |
|
| 4741 | - "$chapo \n\n $texte"; |
|
| 4742 | - } |
|
| 4734 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4735 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4736 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4737 | + if (isset($ligne_sql['chapo'])) { |
|
| 4738 | + $chapo = $ligne_sql['chapo']; |
|
| 4739 | + $texte = strlen((string) $descriptif) ? |
|
| 4740 | + '' : |
|
| 4741 | + "$chapo \n\n $texte"; |
|
| 4742 | + } |
|
| 4743 | 4743 | |
| 4744 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4745 | - if (!(int) $longueur_ou_suite) { |
|
| 4746 | - $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4747 | - } else { |
|
| 4748 | - $longueur = (int) $longueur_ou_suite; |
|
| 4749 | - } |
|
| 4744 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4745 | + if (!(int) $longueur_ou_suite) { |
|
| 4746 | + $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4747 | + } else { |
|
| 4748 | + $longueur = (int) $longueur_ou_suite; |
|
| 4749 | + } |
|
| 4750 | 4750 | |
| 4751 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4752 | - // Ex : #INTRODUCTION{...} |
|
| 4753 | - if ( |
|
| 4754 | - is_null($suite) && !(int) $longueur_ou_suite |
|
| 4755 | - ) { |
|
| 4756 | - $suite = $longueur_ou_suite; |
|
| 4757 | - } |
|
| 4751 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4752 | + // Ex : #INTRODUCTION{...} |
|
| 4753 | + if ( |
|
| 4754 | + is_null($suite) && !(int) $longueur_ou_suite |
|
| 4755 | + ) { |
|
| 4756 | + $suite = $longueur_ou_suite; |
|
| 4757 | + } |
|
| 4758 | 4758 | |
| 4759 | - $f = chercher_filtre('introduction'); |
|
| 4759 | + $f = chercher_filtre('introduction'); |
|
| 4760 | 4760 | |
| 4761 | - return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4761 | + return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4762 | 4762 | } |
| 4763 | 4763 | |
| 4764 | 4764 | /** |
@@ -4766,7 +4766,7 @@ discard block |
||
| 4766 | 4766 | * @see generer_objet_introduction |
| 4767 | 4767 | */ |
| 4768 | 4768 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4769 | - return generer_objet_introduction((int) $id_objet, $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4769 | + return generer_objet_introduction((int) $id_objet, $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4770 | 4770 | } |
| 4771 | 4771 | |
| 4772 | 4772 | /** |
@@ -4779,49 +4779,49 @@ discard block |
||
| 4779 | 4779 | * @return string |
| 4780 | 4780 | */ |
| 4781 | 4781 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4782 | - if (!$champ) { |
|
| 4783 | - return $texte; |
|
| 4784 | - } |
|
| 4782 | + if (!$champ) { |
|
| 4783 | + return $texte; |
|
| 4784 | + } |
|
| 4785 | 4785 | |
| 4786 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4787 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4788 | - include_fichiers_fonctions(); |
|
| 4786 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4787 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4788 | + include_fichiers_fonctions(); |
|
| 4789 | 4789 | |
| 4790 | - $champ = strtoupper($champ); |
|
| 4791 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4792 | - if (!$traitements || !is_array($traitements)) { |
|
| 4793 | - return $texte; |
|
| 4794 | - } |
|
| 4790 | + $champ = strtoupper($champ); |
|
| 4791 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4792 | + if (!$traitements || !is_array($traitements)) { |
|
| 4793 | + return $texte; |
|
| 4794 | + } |
|
| 4795 | 4795 | |
| 4796 | - $traitement = ''; |
|
| 4797 | - if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4798 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4799 | - $table_objet = table_objet($table_objet); |
|
| 4800 | - if (isset($traitements[$table_objet])) { |
|
| 4801 | - $traitement = $traitements[$table_objet]; |
|
| 4802 | - } |
|
| 4803 | - } |
|
| 4804 | - if (!$traitement && isset($traitements[0])) { |
|
| 4805 | - $traitement = $traitements[0]; |
|
| 4806 | - } |
|
| 4807 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4796 | + $traitement = ''; |
|
| 4797 | + if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4798 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4799 | + $table_objet = table_objet($table_objet); |
|
| 4800 | + if (isset($traitements[$table_objet])) { |
|
| 4801 | + $traitement = $traitements[$table_objet]; |
|
| 4802 | + } |
|
| 4803 | + } |
|
| 4804 | + if (!$traitement && isset($traitements[0])) { |
|
| 4805 | + $traitement = $traitements[0]; |
|
| 4806 | + } |
|
| 4807 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4808 | 4808 | |
| 4809 | - if (!$traitement) { |
|
| 4810 | - return $texte; |
|
| 4811 | - } |
|
| 4809 | + if (!$traitement) { |
|
| 4810 | + return $texte; |
|
| 4811 | + } |
|
| 4812 | 4812 | |
| 4813 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement); |
|
| 4813 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement); |
|
| 4814 | 4814 | |
| 4815 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4816 | - if (test_espace_prive()) { |
|
| 4817 | - $env['espace_prive'] = 1; |
|
| 4818 | - } |
|
| 4815 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4816 | + if (test_espace_prive()) { |
|
| 4817 | + $env['espace_prive'] = 1; |
|
| 4818 | + } |
|
| 4819 | 4819 | |
| 4820 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4821 | - $Pile = [0 => $env]; |
|
| 4822 | - eval("\$texte = $traitement;"); |
|
| 4820 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4821 | + $Pile = [0 => $env]; |
|
| 4822 | + eval("\$texte = $traitement;"); |
|
| 4823 | 4823 | |
| 4824 | - return $texte; |
|
| 4824 | + return $texte; |
|
| 4825 | 4825 | } |
| 4826 | 4826 | |
| 4827 | 4827 | |
@@ -4832,21 +4832,21 @@ discard block |
||
| 4832 | 4832 | * @return string |
| 4833 | 4833 | */ |
| 4834 | 4834 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4835 | - include_spip('inc/liens'); |
|
| 4836 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4837 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4838 | - // le raccourcis n'est plus valide |
|
| 4839 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4840 | - // on essaye avec generer_info_entite ? |
|
| 4841 | - if (!strlen($titre) && !$connect) { |
|
| 4842 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4843 | - } |
|
| 4844 | - if (!strlen($titre)) { |
|
| 4845 | - $titre = _T('info_sans_titre'); |
|
| 4846 | - } |
|
| 4847 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4835 | + include_spip('inc/liens'); |
|
| 4836 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4837 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4838 | + // le raccourcis n'est plus valide |
|
| 4839 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4840 | + // on essaye avec generer_info_entite ? |
|
| 4841 | + if (!strlen($titre) && !$connect) { |
|
| 4842 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4843 | + } |
|
| 4844 | + if (!strlen($titre)) { |
|
| 4845 | + $titre = _T('info_sans_titre'); |
|
| 4846 | + } |
|
| 4847 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4848 | 4848 | |
| 4849 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4849 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4850 | 4850 | } |
| 4851 | 4851 | |
| 4852 | 4852 | /** |
@@ -4854,7 +4854,7 @@ discard block |
||
| 4854 | 4854 | * @see generer_objet_lien |
| 4855 | 4855 | */ |
| 4856 | 4856 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4857 | - return generer_objet_lien((int) $id_objet, $objet, $longueur, $connect ?? ''); |
|
| 4857 | + return generer_objet_lien((int) $id_objet, $objet, $longueur, $connect ?? ''); |
|
| 4858 | 4858 | } |
| 4859 | 4859 | |
| 4860 | 4860 | /** |
@@ -4870,15 +4870,15 @@ discard block |
||
| 4870 | 4870 | * @return string |
| 4871 | 4871 | */ |
| 4872 | 4872 | function wrap($texte, $wrap) { |
| 4873 | - $balises = extraire_balises($wrap); |
|
| 4874 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4875 | - $texte = $wrap . $texte; |
|
| 4876 | - $regs = array_reverse($regs[1]); |
|
| 4877 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4878 | - $texte .= $wrap; |
|
| 4879 | - } |
|
| 4873 | + $balises = extraire_balises($wrap); |
|
| 4874 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4875 | + $texte = $wrap . $texte; |
|
| 4876 | + $regs = array_reverse($regs[1]); |
|
| 4877 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4878 | + $texte .= $wrap; |
|
| 4879 | + } |
|
| 4880 | 4880 | |
| 4881 | - return $texte; |
|
| 4881 | + return $texte; |
|
| 4882 | 4882 | } |
| 4883 | 4883 | |
| 4884 | 4884 | |
@@ -4898,42 +4898,42 @@ discard block |
||
| 4898 | 4898 | * @return array|mixed|string |
| 4899 | 4899 | */ |
| 4900 | 4900 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4901 | - if (is_string($u)) { |
|
| 4902 | - return typo($u); |
|
| 4903 | - } |
|
| 4904 | - |
|
| 4905 | - // caster $u en array si besoin |
|
| 4906 | - if (is_object($u)) { |
|
| 4907 | - $u = (array)$u; |
|
| 4908 | - } |
|
| 4909 | - |
|
| 4910 | - if (is_array($u)) { |
|
| 4911 | - $out = ''; |
|
| 4912 | - // toutes les cles sont numeriques ? |
|
| 4913 | - // et aucun enfant n'est un tableau |
|
| 4914 | - // liste simple separee par des virgules |
|
| 4915 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4916 | - $array_values = array_map('is_array', $u); |
|
| 4917 | - $object_values = array_map('is_object', $u); |
|
| 4918 | - if ( |
|
| 4919 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4920 | - && !array_sum($array_values) |
|
| 4921 | - && !array_sum($object_values) |
|
| 4922 | - ) { |
|
| 4923 | - return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4924 | - } |
|
| 4925 | - |
|
| 4926 | - // sinon on passe a la ligne et on indente |
|
| 4927 | - $i_str = str_pad('', $indent, ' '); |
|
| 4928 | - foreach ($u as $k => $v) { |
|
| 4929 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4930 | - } |
|
| 4931 | - |
|
| 4932 | - return $out; |
|
| 4933 | - } |
|
| 4934 | - |
|
| 4935 | - // on sait pas quoi faire... |
|
| 4936 | - return $u; |
|
| 4901 | + if (is_string($u)) { |
|
| 4902 | + return typo($u); |
|
| 4903 | + } |
|
| 4904 | + |
|
| 4905 | + // caster $u en array si besoin |
|
| 4906 | + if (is_object($u)) { |
|
| 4907 | + $u = (array)$u; |
|
| 4908 | + } |
|
| 4909 | + |
|
| 4910 | + if (is_array($u)) { |
|
| 4911 | + $out = ''; |
|
| 4912 | + // toutes les cles sont numeriques ? |
|
| 4913 | + // et aucun enfant n'est un tableau |
|
| 4914 | + // liste simple separee par des virgules |
|
| 4915 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4916 | + $array_values = array_map('is_array', $u); |
|
| 4917 | + $object_values = array_map('is_object', $u); |
|
| 4918 | + if ( |
|
| 4919 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4920 | + && !array_sum($array_values) |
|
| 4921 | + && !array_sum($object_values) |
|
| 4922 | + ) { |
|
| 4923 | + return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4924 | + } |
|
| 4925 | + |
|
| 4926 | + // sinon on passe a la ligne et on indente |
|
| 4927 | + $i_str = str_pad('', $indent, ' '); |
|
| 4928 | + foreach ($u as $k => $v) { |
|
| 4929 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4930 | + } |
|
| 4931 | + |
|
| 4932 | + return $out; |
|
| 4933 | + } |
|
| 4934 | + |
|
| 4935 | + // on sait pas quoi faire... |
|
| 4936 | + return $u; |
|
| 4937 | 4937 | } |
| 4938 | 4938 | |
| 4939 | 4939 | |
@@ -4946,10 +4946,10 @@ discard block |
||
| 4946 | 4946 | * @return string|array |
| 4947 | 4947 | */ |
| 4948 | 4948 | function objet_info($objet, $info) { |
| 4949 | - $table = table_objet_sql($objet); |
|
| 4950 | - $infos = lister_tables_objets_sql($table); |
|
| 4949 | + $table = table_objet_sql($objet); |
|
| 4950 | + $infos = lister_tables_objets_sql($table); |
|
| 4951 | 4951 | |
| 4952 | - return ($infos[$info] ?? ''); |
|
| 4952 | + return ($infos[$info] ?? ''); |
|
| 4953 | 4953 | } |
| 4954 | 4954 | |
| 4955 | 4955 | /** |
@@ -4964,11 +4964,11 @@ discard block |
||
| 4964 | 4964 | * texte traduit du comptage, tel que '3 articles' |
| 4965 | 4965 | */ |
| 4966 | 4966 | function objet_afficher_nb($nb, $objet) { |
| 4967 | - if (!$nb) { |
|
| 4968 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4969 | - } else { |
|
| 4970 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4971 | - } |
|
| 4967 | + if (!$nb) { |
|
| 4968 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4969 | + } else { |
|
| 4970 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4971 | + } |
|
| 4972 | 4972 | } |
| 4973 | 4973 | |
| 4974 | 4974 | /** |
@@ -4980,11 +4980,11 @@ discard block |
||
| 4980 | 4980 | * @return string |
| 4981 | 4981 | */ |
| 4982 | 4982 | function objet_icone($objet, $taille = 24, $class = '') { |
| 4983 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4984 | - $icone = chemin_image($icone); |
|
| 4985 | - $balise_img = charger_filtre('balise_img'); |
|
| 4983 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4984 | + $icone = chemin_image($icone); |
|
| 4985 | + $balise_img = charger_filtre('balise_img'); |
|
| 4986 | 4986 | |
| 4987 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4987 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4988 | 4988 | } |
| 4989 | 4989 | |
| 4990 | 4990 | /** |
@@ -5005,12 +5005,12 @@ discard block |
||
| 5005 | 5005 | * @return string |
| 5006 | 5006 | */ |
| 5007 | 5007 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5008 | - $chaine = explode(':', $chaine); |
|
| 5009 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5010 | - return $t; |
|
| 5011 | - } |
|
| 5012 | - $chaine = implode(':', $chaine); |
|
| 5013 | - return _T($chaine, $args, $options); |
|
| 5008 | + $chaine = explode(':', $chaine); |
|
| 5009 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5010 | + return $t; |
|
| 5011 | + } |
|
| 5012 | + $chaine = implode(':', $chaine); |
|
| 5013 | + return _T($chaine, $args, $options); |
|
| 5014 | 5014 | } |
| 5015 | 5015 | |
| 5016 | 5016 | /** |
@@ -5024,18 +5024,18 @@ discard block |
||
| 5024 | 5024 | * @return string Code HTML |
| 5025 | 5025 | */ |
| 5026 | 5026 | function insert_head_css_conditionnel($flux) { |
| 5027 | - if ( |
|
| 5028 | - !str_contains($flux, '<!-- insert_head_css -->') |
|
| 5029 | - && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 5030 | - ) { |
|
| 5031 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5032 | - if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 5033 | - $p = $p1; |
|
| 5034 | - } |
|
| 5035 | - $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5036 | - } |
|
| 5027 | + if ( |
|
| 5028 | + !str_contains($flux, '<!-- insert_head_css -->') |
|
| 5029 | + && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 5030 | + ) { |
|
| 5031 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5032 | + if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 5033 | + $p = $p1; |
|
| 5034 | + } |
|
| 5035 | + $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5036 | + } |
|
| 5037 | 5037 | |
| 5038 | - return $flux; |
|
| 5038 | + return $flux; |
|
| 5039 | 5039 | } |
| 5040 | 5040 | |
| 5041 | 5041 | /** |
@@ -5058,75 +5058,75 @@ discard block |
||
| 5058 | 5058 | * @return string |
| 5059 | 5059 | */ |
| 5060 | 5060 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5061 | - if (isset($contexte['format'])) { |
|
| 5062 | - $extension = $contexte['format']; |
|
| 5063 | - unset($contexte['format']); |
|
| 5064 | - } else { |
|
| 5065 | - $extension = 'html'; |
|
| 5066 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5067 | - $extension = $m[1]; |
|
| 5068 | - } |
|
| 5069 | - } |
|
| 5070 | - // recuperer le contenu produit par le squelette |
|
| 5071 | - $options['raw'] = true; |
|
| 5072 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5073 | - |
|
| 5074 | - // calculer le nom de la css |
|
| 5075 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5076 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5077 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5078 | - |
|
| 5079 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5080 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5081 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5082 | - if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 5083 | - $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
|
| 5084 | - } |
|
| 5085 | - else { |
|
| 5086 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5087 | - ksort($contexte); |
|
| 5088 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5089 | - } |
|
| 5090 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5091 | - |
|
| 5092 | - // mettre a jour le fichier si il n'existe pas |
|
| 5093 | - // ou trop ancien |
|
| 5094 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5095 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5096 | - if ( |
|
| 5097 | - !file_exists($filename) |
|
| 5098 | - || !file_exists($filename . '.last') |
|
| 5099 | - || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5100 | - || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5101 | - ) { |
|
| 5102 | - $contenu = $cache['texte']; |
|
| 5103 | - // passer les urls en absolu si c'est une css |
|
| 5104 | - if ($extension == 'css') { |
|
| 5105 | - $contenu = urls_absolues_css( |
|
| 5106 | - $contenu, |
|
| 5107 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5108 | - ); |
|
| 5109 | - } |
|
| 5110 | - |
|
| 5111 | - $comment = ''; |
|
| 5112 | - // ne pas insérer de commentaire sur certains formats |
|
| 5113 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5114 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5115 | - foreach ($contexte as $k => $v) { |
|
| 5116 | - if (is_array($v)) { |
|
| 5117 | - $v = var_export($v, true); |
|
| 5118 | - } |
|
| 5119 | - $comment .= ",$k=$v"; |
|
| 5120 | - } |
|
| 5121 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5122 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5123 | - $comment .= "}\n md5:" . md5((string) $contenu) . " */\n"; |
|
| 5124 | - } |
|
| 5125 | - // et ecrire le fichier si il change |
|
| 5126 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5127 | - } |
|
| 5128 | - |
|
| 5129 | - return timestamp($filename); |
|
| 5061 | + if (isset($contexte['format'])) { |
|
| 5062 | + $extension = $contexte['format']; |
|
| 5063 | + unset($contexte['format']); |
|
| 5064 | + } else { |
|
| 5065 | + $extension = 'html'; |
|
| 5066 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5067 | + $extension = $m[1]; |
|
| 5068 | + } |
|
| 5069 | + } |
|
| 5070 | + // recuperer le contenu produit par le squelette |
|
| 5071 | + $options['raw'] = true; |
|
| 5072 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5073 | + |
|
| 5074 | + // calculer le nom de la css |
|
| 5075 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5076 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5077 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5078 | + |
|
| 5079 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5080 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5081 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5082 | + if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 5083 | + $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
|
| 5084 | + } |
|
| 5085 | + else { |
|
| 5086 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5087 | + ksort($contexte); |
|
| 5088 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5089 | + } |
|
| 5090 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5091 | + |
|
| 5092 | + // mettre a jour le fichier si il n'existe pas |
|
| 5093 | + // ou trop ancien |
|
| 5094 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5095 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5096 | + if ( |
|
| 5097 | + !file_exists($filename) |
|
| 5098 | + || !file_exists($filename . '.last') |
|
| 5099 | + || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5100 | + || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5101 | + ) { |
|
| 5102 | + $contenu = $cache['texte']; |
|
| 5103 | + // passer les urls en absolu si c'est une css |
|
| 5104 | + if ($extension == 'css') { |
|
| 5105 | + $contenu = urls_absolues_css( |
|
| 5106 | + $contenu, |
|
| 5107 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5108 | + ); |
|
| 5109 | + } |
|
| 5110 | + |
|
| 5111 | + $comment = ''; |
|
| 5112 | + // ne pas insérer de commentaire sur certains formats |
|
| 5113 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5114 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5115 | + foreach ($contexte as $k => $v) { |
|
| 5116 | + if (is_array($v)) { |
|
| 5117 | + $v = var_export($v, true); |
|
| 5118 | + } |
|
| 5119 | + $comment .= ",$k=$v"; |
|
| 5120 | + } |
|
| 5121 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5122 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5123 | + $comment .= "}\n md5:" . md5((string) $contenu) . " */\n"; |
|
| 5124 | + } |
|
| 5125 | + // et ecrire le fichier si il change |
|
| 5126 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5127 | + } |
|
| 5128 | + |
|
| 5129 | + return timestamp($filename); |
|
| 5130 | 5130 | } |
| 5131 | 5131 | |
| 5132 | 5132 | /** |
@@ -5139,11 +5139,11 @@ discard block |
||
| 5139 | 5139 | * $fichier auquel on a ajouté le timestamp |
| 5140 | 5140 | */ |
| 5141 | 5141 | function timestamp($fichier) { |
| 5142 | - if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5143 | - return $fichier; |
|
| 5144 | - } |
|
| 5142 | + if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5143 | + return $fichier; |
|
| 5144 | + } |
|
| 5145 | 5145 | |
| 5146 | - return "$fichier?$m"; |
|
| 5146 | + return "$fichier?$m"; |
|
| 5147 | 5147 | } |
| 5148 | 5148 | |
| 5149 | 5149 | /** |
@@ -5153,11 +5153,11 @@ discard block |
||
| 5153 | 5153 | * @return string |
| 5154 | 5154 | */ |
| 5155 | 5155 | function supprimer_timestamp($url) { |
| 5156 | - if (!str_contains($url, '?')) { |
|
| 5157 | - return $url; |
|
| 5158 | - } |
|
| 5156 | + if (!str_contains($url, '?')) { |
|
| 5157 | + return $url; |
|
| 5158 | + } |
|
| 5159 | 5159 | |
| 5160 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5160 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5161 | 5161 | } |
| 5162 | 5162 | |
| 5163 | 5163 | /** |
@@ -5172,15 +5172,15 @@ discard block |
||
| 5172 | 5172 | * @return string |
| 5173 | 5173 | */ |
| 5174 | 5174 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5175 | - include_spip('inc/envoyer_mail'); |
|
| 5175 | + include_spip('inc/envoyer_mail'); |
|
| 5176 | 5176 | |
| 5177 | - $titre = nettoyer_titre_email($titre); |
|
| 5178 | - // on est dans un squelette : securiser le retour |
|
| 5179 | - if (str_contains($titre, '<')) { |
|
| 5180 | - $titre = interdire_scripts($titre); |
|
| 5181 | - } |
|
| 5177 | + $titre = nettoyer_titre_email($titre); |
|
| 5178 | + // on est dans un squelette : securiser le retour |
|
| 5179 | + if (str_contains($titre, '<')) { |
|
| 5180 | + $titre = interdire_scripts($titre); |
|
| 5181 | + } |
|
| 5182 | 5182 | |
| 5183 | - return $titre; |
|
| 5183 | + return $titre; |
|
| 5184 | 5184 | } |
| 5185 | 5185 | |
| 5186 | 5186 | /** |
@@ -5202,27 +5202,27 @@ discard block |
||
| 5202 | 5202 | * @return string |
| 5203 | 5203 | */ |
| 5204 | 5204 | function filtre_chercher_rubrique_dist( |
| 5205 | - $titre, |
|
| 5206 | - $id_objet, |
|
| 5207 | - $id_parent, |
|
| 5208 | - $objet, |
|
| 5209 | - $id_secteur, |
|
| 5210 | - $restreint, |
|
| 5211 | - $actionable = false, |
|
| 5212 | - $retour_sans_cadre = false |
|
| 5205 | + $titre, |
|
| 5206 | + $id_objet, |
|
| 5207 | + $id_parent, |
|
| 5208 | + $objet, |
|
| 5209 | + $id_secteur, |
|
| 5210 | + $restreint, |
|
| 5211 | + $actionable = false, |
|
| 5212 | + $retour_sans_cadre = false |
|
| 5213 | 5213 | ) { |
| 5214 | - include_spip('inc/filtres_ecrire'); |
|
| 5214 | + include_spip('inc/filtres_ecrire'); |
|
| 5215 | 5215 | |
| 5216 | - return chercher_rubrique( |
|
| 5217 | - $titre, |
|
| 5218 | - $id_objet, |
|
| 5219 | - $id_parent, |
|
| 5220 | - $objet, |
|
| 5221 | - $id_secteur, |
|
| 5222 | - $restreint, |
|
| 5223 | - $actionable, |
|
| 5224 | - $retour_sans_cadre |
|
| 5225 | - ); |
|
| 5216 | + return chercher_rubrique( |
|
| 5217 | + $titre, |
|
| 5218 | + $id_objet, |
|
| 5219 | + $id_parent, |
|
| 5220 | + $objet, |
|
| 5221 | + $id_secteur, |
|
| 5222 | + $restreint, |
|
| 5223 | + $actionable, |
|
| 5224 | + $retour_sans_cadre |
|
| 5225 | + ); |
|
| 5226 | 5226 | } |
| 5227 | 5227 | |
| 5228 | 5228 | /** |
@@ -5251,56 +5251,56 @@ discard block |
||
| 5251 | 5251 | * Chaîne vide si l'accès est autorisé |
| 5252 | 5252 | */ |
| 5253 | 5253 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5254 | - if ($ok) { |
|
| 5255 | - return ''; |
|
| 5256 | - } |
|
| 5257 | - |
|
| 5258 | - // Vider tous les tampons |
|
| 5259 | - $level = @ob_get_level(); |
|
| 5260 | - while ($level--) { |
|
| 5261 | - @ob_end_clean(); |
|
| 5262 | - } |
|
| 5263 | - |
|
| 5264 | - include_spip('inc/headers'); |
|
| 5265 | - |
|
| 5266 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5267 | - if ($url) { |
|
| 5268 | - redirige_par_entete($url, '', $statut); |
|
| 5269 | - } |
|
| 5270 | - |
|
| 5271 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5272 | - if (!is_numeric($statut) && is_null($message)) { |
|
| 5273 | - $message = $statut; |
|
| 5274 | - $statut = 0; |
|
| 5275 | - } |
|
| 5276 | - if (!$message) { |
|
| 5277 | - $message = ''; |
|
| 5278 | - } |
|
| 5279 | - $statut = (int) $statut; |
|
| 5280 | - |
|
| 5281 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5282 | - if (test_espace_prive()) { |
|
| 5283 | - if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5284 | - $statut = 403; |
|
| 5285 | - } |
|
| 5286 | - http_response_code(403); |
|
| 5287 | - $echec = charger_fonction('403', 'exec'); |
|
| 5288 | - $echec($message); |
|
| 5289 | - } else { |
|
| 5290 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5291 | - if (!$statut) { |
|
| 5292 | - $statut = 404; |
|
| 5293 | - } |
|
| 5294 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5295 | - http_response_code($statut); |
|
| 5296 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5297 | - if ($statut >= 400) { |
|
| 5298 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5299 | - } |
|
| 5300 | - } |
|
| 5301 | - |
|
| 5302 | - |
|
| 5303 | - exit; |
|
| 5254 | + if ($ok) { |
|
| 5255 | + return ''; |
|
| 5256 | + } |
|
| 5257 | + |
|
| 5258 | + // Vider tous les tampons |
|
| 5259 | + $level = @ob_get_level(); |
|
| 5260 | + while ($level--) { |
|
| 5261 | + @ob_end_clean(); |
|
| 5262 | + } |
|
| 5263 | + |
|
| 5264 | + include_spip('inc/headers'); |
|
| 5265 | + |
|
| 5266 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5267 | + if ($url) { |
|
| 5268 | + redirige_par_entete($url, '', $statut); |
|
| 5269 | + } |
|
| 5270 | + |
|
| 5271 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5272 | + if (!is_numeric($statut) && is_null($message)) { |
|
| 5273 | + $message = $statut; |
|
| 5274 | + $statut = 0; |
|
| 5275 | + } |
|
| 5276 | + if (!$message) { |
|
| 5277 | + $message = ''; |
|
| 5278 | + } |
|
| 5279 | + $statut = (int) $statut; |
|
| 5280 | + |
|
| 5281 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5282 | + if (test_espace_prive()) { |
|
| 5283 | + if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5284 | + $statut = 403; |
|
| 5285 | + } |
|
| 5286 | + http_response_code(403); |
|
| 5287 | + $echec = charger_fonction('403', 'exec'); |
|
| 5288 | + $echec($message); |
|
| 5289 | + } else { |
|
| 5290 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5291 | + if (!$statut) { |
|
| 5292 | + $statut = 404; |
|
| 5293 | + } |
|
| 5294 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5295 | + http_response_code($statut); |
|
| 5296 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5297 | + if ($statut >= 400) { |
|
| 5298 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5299 | + } |
|
| 5300 | + } |
|
| 5301 | + |
|
| 5302 | + |
|
| 5303 | + exit; |
|
| 5304 | 5304 | } |
| 5305 | 5305 | |
| 5306 | 5306 | /** |
@@ -5311,11 +5311,11 @@ discard block |
||
| 5311 | 5311 | * @return string |
| 5312 | 5312 | */ |
| 5313 | 5313 | function filtre_compacte_dist($source, $format = null) { |
| 5314 | - if (function_exists('minifier')) { |
|
| 5315 | - return minifier($source, $format); |
|
| 5316 | - } |
|
| 5314 | + if (function_exists('minifier')) { |
|
| 5315 | + return minifier($source, $format); |
|
| 5316 | + } |
|
| 5317 | 5317 | |
| 5318 | - return $source; |
|
| 5318 | + return $source; |
|
| 5319 | 5319 | } |
| 5320 | 5320 | |
| 5321 | 5321 | |
@@ -5325,32 +5325,32 @@ discard block |
||
| 5325 | 5325 | * @return string |
| 5326 | 5326 | */ |
| 5327 | 5327 | function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5328 | - $passe ??= ''; |
|
| 5329 | - $l = strlen($passe); |
|
| 5330 | - |
|
| 5331 | - if ($l <= 8 || !$afficher_partiellement) { |
|
| 5332 | - if (!$l) { |
|
| 5333 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5334 | - } |
|
| 5335 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5336 | - } |
|
| 5337 | - |
|
| 5338 | - if (is_null($portion_pourcent)) { |
|
| 5339 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5340 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5341 | - } |
|
| 5342 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5343 | - } |
|
| 5344 | - if ($portion_pourcent >= 100) { |
|
| 5345 | - return $passe; |
|
| 5346 | - } |
|
| 5347 | - $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5348 | - $e = max($e, 0); |
|
| 5349 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5350 | - if ($e > 0 && strlen($mid) > 8) { |
|
| 5351 | - $mid = '***...***'; |
|
| 5352 | - } |
|
| 5353 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5328 | + $passe ??= ''; |
|
| 5329 | + $l = strlen($passe); |
|
| 5330 | + |
|
| 5331 | + if ($l <= 8 || !$afficher_partiellement) { |
|
| 5332 | + if (!$l) { |
|
| 5333 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5334 | + } |
|
| 5335 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5336 | + } |
|
| 5337 | + |
|
| 5338 | + if (is_null($portion_pourcent)) { |
|
| 5339 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5340 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5341 | + } |
|
| 5342 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5343 | + } |
|
| 5344 | + if ($portion_pourcent >= 100) { |
|
| 5345 | + return $passe; |
|
| 5346 | + } |
|
| 5347 | + $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5348 | + $e = max($e, 0); |
|
| 5349 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5350 | + if ($e > 0 && strlen($mid) > 8) { |
|
| 5351 | + $mid = '***...***'; |
|
| 5352 | + } |
|
| 5353 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5354 | 5354 | } |
| 5355 | 5355 | |
| 5356 | 5356 | |
@@ -5371,64 +5371,64 @@ discard block |
||
| 5371 | 5371 | */ |
| 5372 | 5372 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5373 | 5373 | |
| 5374 | - $original = $texte; |
|
| 5375 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5376 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5377 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5374 | + $original = $texte; |
|
| 5375 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5376 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5377 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5378 | 5378 | |
| 5379 | - if (!function_exists('translitteration')) { |
|
| 5380 | - include_spip('inc/charsets'); |
|
| 5381 | - } |
|
| 5379 | + if (!function_exists('translitteration')) { |
|
| 5380 | + include_spip('inc/charsets'); |
|
| 5381 | + } |
|
| 5382 | 5382 | |
| 5383 | - // pas de balise html |
|
| 5384 | - if (str_contains($texte, '<')) { |
|
| 5385 | - $texte = strip_tags($texte); |
|
| 5386 | - } |
|
| 5387 | - if (str_contains($texte, '&')) { |
|
| 5388 | - $texte = unicode2charset($texte); |
|
| 5389 | - } |
|
| 5390 | - // On enlève les espaces indésirables |
|
| 5391 | - $texte = trim($texte); |
|
| 5383 | + // pas de balise html |
|
| 5384 | + if (str_contains($texte, '<')) { |
|
| 5385 | + $texte = strip_tags($texte); |
|
| 5386 | + } |
|
| 5387 | + if (str_contains($texte, '&')) { |
|
| 5388 | + $texte = unicode2charset($texte); |
|
| 5389 | + } |
|
| 5390 | + // On enlève les espaces indésirables |
|
| 5391 | + $texte = trim($texte); |
|
| 5392 | 5392 | |
| 5393 | - // On enlève les accents et cie |
|
| 5394 | - $texte = translitteration($texte); |
|
| 5393 | + // On enlève les accents et cie |
|
| 5394 | + $texte = translitteration($texte); |
|
| 5395 | 5395 | |
| 5396 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5397 | - $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte); |
|
| 5396 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5397 | + $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte); |
|
| 5398 | 5398 | |
| 5399 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5400 | - while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5401 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5402 | - } |
|
| 5399 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5400 | + while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5401 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5402 | + } |
|
| 5403 | 5403 | |
| 5404 | - // pas de separateur au debut ni a la fin |
|
| 5405 | - $texte = trim($texte, $separateur); |
|
| 5404 | + // pas de separateur au debut ni a la fin |
|
| 5405 | + $texte = trim($texte, $separateur); |
|
| 5406 | 5406 | |
| 5407 | - // en minuscules |
|
| 5408 | - $texte = strtolower($texte); |
|
| 5407 | + // en minuscules |
|
| 5408 | + $texte = strtolower($texte); |
|
| 5409 | 5409 | |
| 5410 | - switch ($type) { |
|
| 5411 | - case 'class': |
|
| 5412 | - case 'id': |
|
| 5413 | - case 'anchor': |
|
| 5414 | - if (preg_match(',^\d,', $texte)) { |
|
| 5415 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5416 | - } |
|
| 5417 | - } |
|
| 5410 | + switch ($type) { |
|
| 5411 | + case 'class': |
|
| 5412 | + case 'id': |
|
| 5413 | + case 'anchor': |
|
| 5414 | + if (preg_match(',^\d,', $texte)) { |
|
| 5415 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5416 | + } |
|
| 5417 | + } |
|
| 5418 | 5418 | |
| 5419 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5420 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5421 | - } |
|
| 5419 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5420 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5421 | + } |
|
| 5422 | 5422 | |
| 5423 | - if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5424 | - if (preg_match(',^\d,', $texte)) { |
|
| 5425 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5426 | - } |
|
| 5427 | - $texte .= $separateur . md5($original); |
|
| 5428 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5429 | - } |
|
| 5423 | + if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5424 | + if (preg_match(',^\d,', $texte)) { |
|
| 5425 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5426 | + } |
|
| 5427 | + $texte .= $separateur . md5($original); |
|
| 5428 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5429 | + } |
|
| 5430 | 5430 | |
| 5431 | - return $texte; |
|
| 5431 | + return $texte; |
|
| 5432 | 5432 | } |
| 5433 | 5433 | |
| 5434 | 5434 | |
@@ -5449,11 +5449,11 @@ discard block |
||
| 5449 | 5449 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5450 | 5450 | */ |
| 5451 | 5451 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5452 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5453 | - if ($ucfirst) { |
|
| 5454 | - $label = spip_ucfirst($label); |
|
| 5455 | - } |
|
| 5456 | - return $label; |
|
| 5452 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5453 | + if ($ucfirst) { |
|
| 5454 | + $label = spip_ucfirst($label); |
|
| 5455 | + } |
|
| 5456 | + return $label; |
|
| 5457 | 5457 | } |
| 5458 | 5458 | |
| 5459 | 5459 | /** |
@@ -5466,8 +5466,8 @@ discard block |
||
| 5466 | 5466 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5467 | 5467 | */ |
| 5468 | 5468 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5469 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5470 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5469 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5470 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5471 | 5471 | } |
| 5472 | 5472 | |
| 5473 | 5473 | |
@@ -5480,19 +5480,19 @@ discard block |
||
| 5480 | 5480 | * @return array |
| 5481 | 5481 | */ |
| 5482 | 5482 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5483 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5484 | - return []; |
|
| 5485 | - } |
|
| 5483 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5484 | + return []; |
|
| 5485 | + } |
|
| 5486 | 5486 | |
| 5487 | - // compatibilite signature inversee |
|
| 5488 | - if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5489 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5490 | - } |
|
| 5487 | + // compatibilite signature inversee |
|
| 5488 | + if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5489 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5490 | + } |
|
| 5491 | 5491 | |
| 5492 | - if (!function_exists($fonction)) { |
|
| 5493 | - include_spip('base/objets'); |
|
| 5494 | - } |
|
| 5495 | - return $fonction($objet, $id_objet); |
|
| 5492 | + if (!function_exists($fonction)) { |
|
| 5493 | + include_spip('base/objets'); |
|
| 5494 | + } |
|
| 5495 | + return $fonction($objet, $id_objet); |
|
| 5496 | 5496 | } |
| 5497 | 5497 | |
| 5498 | 5498 | |
@@ -5507,7 +5507,7 @@ discard block |
||
| 5507 | 5507 | * @return array |
| 5508 | 5508 | */ |
| 5509 | 5509 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5510 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5510 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5511 | 5511 | } |
| 5512 | 5512 | |
| 5513 | 5513 | /** |
@@ -5521,7 +5521,7 @@ discard block |
||
| 5521 | 5521 | * @return array |
| 5522 | 5522 | */ |
| 5523 | 5523 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5524 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5524 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5525 | 5525 | } |
| 5526 | 5526 | |
| 5527 | 5527 | /** |
@@ -5535,7 +5535,7 @@ discard block |
||
| 5535 | 5535 | * @return array |
| 5536 | 5536 | */ |
| 5537 | 5537 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5538 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5538 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5539 | 5539 | } |
| 5540 | 5540 | |
| 5541 | 5541 | /** |
@@ -5549,5 +5549,5 @@ discard block |
||
| 5549 | 5549 | * @return array |
| 5550 | 5550 | */ |
| 5551 | 5551 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5552 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5552 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5553 | 5553 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | include_fichiers_fonctions(); |
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 98 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 99 | 99 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 100 | 100 | if (is_callable($f)) { |
| 101 | 101 | return $f; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | // affichage "GIT [master: abcdef]" |
| 231 | 231 | $commit = $desc['commit_short'] ?? $desc['commit']; |
| 232 | 232 | if ($desc['branch']) { |
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 233 | + $commit = $desc['branch'].': '.$commit; |
|
| 234 | 234 | } |
| 235 | 235 | return "{$desc['vcs']} [$commit]"; |
| 236 | 236 | } |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // version installee par GIT |
| 254 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 254 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 255 | 255 | $currentHead = trim(substr((string) $c, 4)); |
| 256 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 256 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 257 | 257 | return [ |
| 258 | 258 | 'vcs' => 'GIT', |
| 259 | 259 | 'branch' => basename($currentHead), |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 270 | 270 | // et laisser passer les fonctions personnelles baptisees image_... |
| 271 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 272 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 273 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 274 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 275 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 276 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 271 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 272 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 273 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 274 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 275 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 276 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 277 | 277 | |
| 278 | 278 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 279 | 279 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | function filtre_debug(mixed $val, $key = null) { |
| 434 | 434 | $debug = ( |
| 435 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | - ) . var_export($val, true); |
|
| 435 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 436 | + ).var_export($val, true); |
|
| 437 | 437 | |
| 438 | 438 | include_spip('inc/autoriser'); |
| 439 | 439 | if (autoriser('webmestre')) { |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $is_file = false; |
| 490 | 490 | } |
| 491 | 491 | if ($is_file) { |
| 492 | - $is_local_file = function ($path) { |
|
| 492 | + $is_local_file = function($path) { |
|
| 493 | 493 | if (str_contains($path, '?')) { |
| 494 | 494 | $path = supprimer_timestamp($path); |
| 495 | 495 | // remove ?24px added by find_in_theme on .svg files |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
| 538 | 538 | ) { |
| 539 | 539 | $srcover = $match[1]; |
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | + $srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args); |
|
| 541 | 541 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 542 | 542 | $reduit = str_replace($srcover, $srcover_filter, (string) $reduit); |
| 543 | 543 | } |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | // " -> " et tout ce genre de choses |
| 937 | 937 | $u = $GLOBALS['meta']['pcre_u']; |
| 938 | 938 | $texte = str_replace(' ', ' ', $texte); |
| 939 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 939 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 940 | 940 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 941 | 941 | $texte = entites_html($texte, false, false); |
| 942 | 942 | // mais bien echapper les double quotes ! |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | return ''; |
| 999 | 999 | } |
| 1000 | 1000 | return preg_replace( |
| 1001 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1001 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1002 | 1002 | '', |
| 1003 | 1003 | $texte |
| 1004 | 1004 | ); |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | if ( |
| 1028 | 1028 | $texte |
| 1029 | 1029 | && preg_match( |
| 1030 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1030 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1031 | 1031 | $texte, |
| 1032 | 1032 | $regs |
| 1033 | 1033 | ) |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | **/ |
| 1117 | 1117 | function textebrut($texte) { |
| 1118 | 1118 | $u = $GLOBALS['meta']['pcre_u']; |
| 1119 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1119 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1120 | 1120 | $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
| 1121 | 1121 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1122 | 1122 | $texte = preg_replace("/\n+$/", '', $texte); |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | ) |
| 1152 | 1152 | ) { |
| 1153 | 1153 | foreach ($liens[0] as $a) { |
| 1154 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1154 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1155 | 1155 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1156 | 1156 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1157 | 1157 | $texte = str_replace($a, $ablank, $texte); |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | foreach ($regs[0] as $a) { |
| 1177 | 1177 | $rel = extraire_attribut($a, 'rel') ?? ''; |
| 1178 | 1178 | if (!str_contains($rel, 'nofollow')) { |
| 1179 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1179 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1180 | 1180 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1181 | 1181 | $texte = str_replace($a, $anofollow, $texte); |
| 1182 | 1182 | } |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1207 | 1207 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1208 | 1208 | |
| 1209 | - return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1209 | + return preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | |
@@ -1240,7 +1240,7 @@ discard block |
||
| 1240 | 1240 | return $texte; |
| 1241 | 1241 | } |
| 1242 | 1242 | include_spip('inc/texte'); |
| 1243 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1243 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1244 | 1244 | 'div' : 'span'; |
| 1245 | 1245 | |
| 1246 | 1246 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | |
| 1332 | 1332 | // Calcul de la taille et choix de l'unité |
| 1333 | 1333 | $affichage = _T( |
| 1334 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1334 | + 'spip:taille_'.$unites[$puissance].$suffixe_item, |
|
| 1335 | 1335 | [ |
| 1336 | 1336 | 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
| 1337 | 1337 | ] |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | } |
| 1366 | 1366 | $u = $GLOBALS['meta']['pcre_u']; |
| 1367 | 1367 | if ($textebrut) { |
| 1368 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1368 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1369 | 1369 | } |
| 1370 | 1370 | $texte = texte_backend($texte); |
| 1371 | 1371 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | # un message pour abs_url |
| 1401 | 1401 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1402 | 1402 | $url = trim($url); |
| 1403 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1403 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1404 | 1404 | |
| 1405 | 1405 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1406 | 1406 | } |
@@ -1605,7 +1605,7 @@ discard block |
||
| 1605 | 1605 | |
| 1606 | 1606 | $debut = ''; |
| 1607 | 1607 | $suite = $texte; |
| 1608 | - while ($t = strpos((string) ('-' . $suite), "\n", 1)) { |
|
| 1608 | + while ($t = strpos((string) ('-'.$suite), "\n", 1)) { |
|
| 1609 | 1609 | $debut .= substr($suite, 0, $t - 1); |
| 1610 | 1610 | $suite = substr($suite, $t); |
| 1611 | 1611 | $car = substr($suite, 0, 1); |
@@ -1623,7 +1623,7 @@ discard block |
||
| 1623 | 1623 | $suite = substr($suite, strlen($regs[0])); |
| 1624 | 1624 | } |
| 1625 | 1625 | } |
| 1626 | - $texte = $debut . $suite; |
|
| 1626 | + $texte = $debut.$suite; |
|
| 1627 | 1627 | |
| 1628 | 1628 | if ($collecteurModeles) { |
| 1629 | 1629 | $texte = $collecteurModeles->retablir($texte); |
@@ -1631,7 +1631,7 @@ discard block |
||
| 1631 | 1631 | |
| 1632 | 1632 | $texte = echappe_retour($texte); |
| 1633 | 1633 | |
| 1634 | - return $texte . $fin; |
|
| 1634 | + return $texte.$fin; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | |
@@ -1900,7 +1900,7 @@ discard block |
||
| 1900 | 1900 | if (is_array($balise)) { |
| 1901 | 1901 | array_walk( |
| 1902 | 1902 | $balise, |
| 1903 | - function (&$a, $key, $t) { |
|
| 1903 | + function(&$a, $key, $t) { |
|
| 1904 | 1904 | $a = extraire_attribut($a, $t); |
| 1905 | 1905 | }, |
| 1906 | 1906 | $attribut |
@@ -1994,14 +1994,14 @@ discard block |
||
| 1994 | 1994 | |
| 1995 | 1995 | if ($old !== null) { |
| 1996 | 1996 | // Remplacer l'ancien attribut du meme nom |
| 1997 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1997 | + $balise = $r[1].$insert.$r[5]; |
|
| 1998 | 1998 | } else { |
| 1999 | 1999 | // preferer une balise " />" (comme <img />) |
| 2000 | 2000 | if (preg_match(',/>,', $balise)) { |
| 2001 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2001 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2002 | 2002 | } // sinon une balise <a ...> ... </a> |
| 2003 | 2003 | else { |
| 2004 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2004 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | } |
| 2007 | 2007 | |
@@ -2059,7 +2059,7 @@ discard block |
||
| 2059 | 2059 | in_array($operation, ['ajouter', 'commuter']) |
| 2060 | 2060 | && !$is_class_presente |
| 2061 | 2061 | ) { |
| 2062 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2062 | + $class_new = ltrim(rtrim($class_new ?? '').' '.$c); |
|
| 2063 | 2063 | } elseif ( |
| 2064 | 2064 | in_array($operation, ['supprimer', 'commuter']) |
| 2065 | 2065 | && $is_class_presente |
@@ -2129,7 +2129,7 @@ discard block |
||
| 2129 | 2129 | // Quelques fonctions de calcul arithmetique |
| 2130 | 2130 | // |
| 2131 | 2131 | function floatstr($a) { |
| 2132 | - return str_replace(',', '.', (string)(float) $a); |
|
| 2132 | + return str_replace(',', '.', (string) (float) $a); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | function strize($f, $a, $b) { |
| 2135 | 2135 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2270,13 +2270,13 @@ discard block |
||
| 2270 | 2270 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2271 | 2271 | define('_TAGS_NOM_AUTEUR', ''); |
| 2272 | 2272 | } |
| 2273 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2273 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2274 | 2274 | foreach ($tags_acceptes as $tag) { |
| 2275 | 2275 | if (strlen($tag)) { |
| 2276 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2276 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2277 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2278 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2279 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2280 | 2280 | } |
| 2281 | 2281 | } |
| 2282 | 2282 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2395,10 +2395,10 @@ discard block |
||
| 2395 | 2395 | $fichier = basename($url); |
| 2396 | 2396 | |
| 2397 | 2397 | return '<a rel="enclosure"' |
| 2398 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | - . '>' . $fichier . '</a>'; |
|
| 2398 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2399 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2400 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2401 | + . '>'.$fichier.'</a>'; |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2426,9 +2426,9 @@ discard block |
||
| 2426 | 2426 | } # vieux data |
| 2427 | 2427 | $fichier = basename($url); |
| 2428 | 2428 | $enclosures[] = '<enclosure' |
| 2429 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2429 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2430 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2431 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2432 | 2432 | . ' />'; |
| 2433 | 2433 | } |
| 2434 | 2434 | } |
@@ -2454,7 +2454,7 @@ discard block |
||
| 2454 | 2454 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2455 | 2455 | $subjects .= '<dc:subject>' |
| 2456 | 2456 | . texte_backend(textebrut($e)) |
| 2457 | - . '</dc:subject>' . "\n"; |
|
| 2457 | + . '</dc:subject>'."\n"; |
|
| 2458 | 2458 | } |
| 2459 | 2459 | } |
| 2460 | 2460 | |
@@ -2490,7 +2490,7 @@ discard block |
||
| 2490 | 2490 | if (is_array($texte)) { |
| 2491 | 2491 | array_walk( |
| 2492 | 2492 | $texte, |
| 2493 | - function (&$a, $key, $t) { |
|
| 2493 | + function(&$a, $key, $t) { |
|
| 2494 | 2494 | $a = extraire_balise($a, $t); |
| 2495 | 2495 | }, |
| 2496 | 2496 | $tag |
@@ -2538,7 +2538,7 @@ discard block |
||
| 2538 | 2538 | if (is_array($texte)) { |
| 2539 | 2539 | array_walk( |
| 2540 | 2540 | $texte, |
| 2541 | - function (&$a, $key, $t) { |
|
| 2541 | + function(&$a, $key, $t) { |
|
| 2542 | 2542 | $a = extraire_balises($a, $t); |
| 2543 | 2543 | }, |
| 2544 | 2544 | $tag |
@@ -2671,7 +2671,7 @@ discard block |
||
| 2671 | 2671 | if ($fond != '404') { |
| 2672 | 2672 | $contexte = array_shift($p); |
| 2673 | 2673 | $contexte['page'] = $fond; |
| 2674 | - $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2674 | + $action = preg_replace('/([?]'.preg_quote((string) $fond, '/').'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | 2675 | } |
| 2676 | 2676 | } |
| 2677 | 2677 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2726,9 +2726,9 @@ discard block |
||
| 2726 | 2726 | . '"' |
| 2727 | 2727 | . (is_null($val) |
| 2728 | 2728 | ? '' |
| 2729 | - : ' value="' . entites_html($val) . '"' |
|
| 2729 | + : ' value="'.entites_html($val).'"' |
|
| 2730 | 2730 | ) |
| 2731 | - . ' type="hidden"' . "\n/>"; |
|
| 2731 | + . ' type="hidden"'."\n/>"; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | return implode('', $hidden); |
@@ -2838,7 +2838,7 @@ discard block |
||
| 2838 | 2838 | |
| 2839 | 2839 | return preg_replace_callback( |
| 2840 | 2840 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2841 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2841 | + fn($x) => "url('".suivre_lien($path, $x[1])."')", |
|
| 2842 | 2842 | $contenu |
| 2843 | 2843 | ); |
| 2844 | 2844 | } |
@@ -2899,14 +2899,14 @@ discard block |
||
| 2899 | 2899 | ) { |
| 2900 | 2900 | $distant = true; |
| 2901 | 2901 | $cssf = parse_url($css); |
| 2902 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2902 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 2903 | 2903 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 2904 | 2904 | } else { |
| 2905 | 2905 | $distant = false; |
| 2906 | 2906 | $cssf = $css; |
| 2907 | 2907 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2908 | 2908 | //propose (rien a faire dans ce cas) |
| 2909 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2909 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2910 | 2910 | if (@file_exists($f)) { |
| 2911 | 2911 | return $f; |
| 2912 | 2912 | } |
@@ -2916,7 +2916,7 @@ discard block |
||
| 2916 | 2916 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2917 | 2917 | $f = $dir_var |
| 2918 | 2918 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2919 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2919 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2920 | 2920 | |
| 2921 | 2921 | // la css peut etre distante (url absolue !) |
| 2922 | 2922 | $contenu = null; |
@@ -2963,8 +2963,8 @@ discard block |
||
| 2963 | 2963 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 2964 | 2964 | elseif (str_starts_with($css_direction, $dir_var)) { |
| 2965 | 2965 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 2966 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2966 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 2967 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 2968 | 2968 | } |
| 2969 | 2969 | $src[] = $regs[0][$k]; |
| 2970 | 2970 | $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]); |
@@ -3013,7 +3013,7 @@ discard block |
||
| 3013 | 3013 | |
| 3014 | 3014 | $f = basename($css, '.css'); |
| 3015 | 3015 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3016 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3016 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3017 | 3017 | . '.css'; |
| 3018 | 3018 | |
| 3019 | 3019 | if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
@@ -3024,7 +3024,7 @@ discard block |
||
| 3024 | 3024 | if ($url_absolue_css == $css) { |
| 3025 | 3025 | if ( |
| 3026 | 3026 | strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0 |
| 3027 | - || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3027 | + || !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3028 | 3028 | ) { |
| 3029 | 3029 | include_spip('inc/distant'); |
| 3030 | 3030 | $contenu = recuperer_url($css); |
@@ -3136,7 +3136,7 @@ discard block |
||
| 3136 | 3136 | $expression = str_replace('\/', '/', $expression); |
| 3137 | 3137 | $expression = str_replace('/', '\/', $expression); |
| 3138 | 3138 | |
| 3139 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3139 | + if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) { |
|
| 3140 | 3140 | if (isset($r[$capte])) { |
| 3141 | 3141 | return $r[$capte]; |
| 3142 | 3142 | } else { |
@@ -3178,7 +3178,7 @@ discard block |
||
| 3178 | 3178 | $expression = str_replace('\/', '/', $expression); |
| 3179 | 3179 | $expression = str_replace('/', '\/', $expression); |
| 3180 | 3180 | |
| 3181 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3181 | + return (string) preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3182 | 3182 | } |
| 3183 | 3183 | |
| 3184 | 3184 | |
@@ -3197,7 +3197,7 @@ discard block |
||
| 3197 | 3197 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3198 | 3198 | |
| 3199 | 3199 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3200 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3200 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3201 | 3201 | |
| 3202 | 3202 | if ( |
| 3203 | 3203 | strstr($t, 'spip_document_') |
@@ -3211,7 +3211,7 @@ discard block |
||
| 3211 | 3211 | if (!isset($doublons['documents'])) { |
| 3212 | 3212 | $doublons['documents'] = ''; |
| 3213 | 3213 | } |
| 3214 | - $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3214 | + $doublons['documents'] .= ','.implode(',', $matches[1]); |
|
| 3215 | 3215 | } |
| 3216 | 3216 | |
| 3217 | 3217 | return $letexte; |
@@ -3268,7 +3268,7 @@ discard block |
||
| 3268 | 3268 | if ($env) { |
| 3269 | 3269 | foreach ($env as $i => $j) { |
| 3270 | 3270 | if (is_string($j) && !in_array($i, $ignore_params)) { |
| 3271 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3271 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3272 | 3272 | } |
| 3273 | 3273 | } |
| 3274 | 3274 | } |
@@ -3307,7 +3307,7 @@ discard block |
||
| 3307 | 3307 | if ($env) { |
| 3308 | 3308 | foreach ($env as $i => $j) { |
| 3309 | 3309 | if (is_string($j) && !in_array($i, $ignore_params)) { |
| 3310 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3310 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3311 | 3311 | } |
| 3312 | 3312 | } |
| 3313 | 3313 | } |
@@ -3381,11 +3381,11 @@ discard block |
||
| 3381 | 3381 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3382 | 3382 | if ( |
| 3383 | 3383 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3384 | - && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3384 | + && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg') |
|
| 3385 | 3385 | && file_exists($variante_svg_generique) |
| 3386 | 3386 | ) { |
| 3387 | 3387 | if ( |
| 3388 | - ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3388 | + ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg') |
|
| 3389 | 3389 | && file_exists($variante_svg_size) |
| 3390 | 3390 | ) { |
| 3391 | 3391 | $img_file = $variante_svg_size; |
@@ -3441,7 +3441,7 @@ discard block |
||
| 3441 | 3441 | return ''; |
| 3442 | 3442 | } |
| 3443 | 3443 | } |
| 3444 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3444 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3445 | 3445 | } |
| 3446 | 3446 | |
| 3447 | 3447 | if (file_exists($img_file)) { |
@@ -3451,14 +3451,14 @@ discard block |
||
| 3451 | 3451 | $alt = ''; |
| 3452 | 3452 | } |
| 3453 | 3453 | elseif ($alt || $alt === '') { |
| 3454 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3454 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3455 | 3455 | } |
| 3456 | 3456 | else { |
| 3457 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3457 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3458 | 3458 | } |
| 3459 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3460 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3461 | - . ' ' . ltrim($atts) |
|
| 3459 | + return "<img src='".attribut_html($img_file)."'$alt" |
|
| 3460 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3461 | + . ' '.ltrim($atts) |
|
| 3462 | 3462 | . ' />'; |
| 3463 | 3463 | } |
| 3464 | 3464 | |
@@ -3472,10 +3472,10 @@ discard block |
||
| 3472 | 3472 | */ |
| 3473 | 3473 | function http_style_background($img, $att = '', $size = null) { |
| 3474 | 3474 | if ($size && is_numeric($size)) { |
| 3475 | - $size = trim($size) . 'px'; |
|
| 3475 | + $size = trim($size).'px'; |
|
| 3476 | 3476 | } |
| 3477 | - return " style='background" . |
|
| 3478 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3477 | + return " style='background". |
|
| 3478 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3479 | 3479 | . ($size ? "background-size:{$size};" : '') |
| 3480 | 3480 | . "'"; |
| 3481 | 3481 | } |
@@ -3585,7 +3585,7 @@ discard block |
||
| 3585 | 3585 | $img = http_img_pack( |
| 3586 | 3586 | $img, |
| 3587 | 3587 | $alt, |
| 3588 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3588 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3589 | 3589 | '', |
| 3590 | 3590 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3591 | 3591 | ); |
@@ -3685,9 +3685,9 @@ discard block |
||
| 3685 | 3685 | // regler le alt |
| 3686 | 3686 | if ($alt) { |
| 3687 | 3687 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3688 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3688 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3689 | 3689 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3690 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3690 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3691 | 3691 | $balise_svg .= $title; |
| 3692 | 3692 | } |
| 3693 | 3693 | else { |
@@ -3735,7 +3735,7 @@ discard block |
||
| 3735 | 3735 | if (is_array($tableau)) { |
| 3736 | 3736 | foreach ($tableau as $k => $v) { |
| 3737 | 3737 | $res = recuperer_fond( |
| 3738 | - 'modeles/' . $modele, |
|
| 3738 | + 'modeles/'.$modele, |
|
| 3739 | 3739 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3740 | 3740 | ); |
| 3741 | 3741 | $texte .= $res; |
@@ -3917,7 +3917,7 @@ discard block |
||
| 3917 | 3917 | } |
| 3918 | 3918 | |
| 3919 | 3919 | $c = serialize($c); |
| 3920 | - $cle = calculer_cle_action($form . $c); |
|
| 3920 | + $cle = calculer_cle_action($form.$c); |
|
| 3921 | 3921 | $c = "$cle:$c"; |
| 3922 | 3922 | |
| 3923 | 3923 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -3975,15 +3975,15 @@ discard block |
||
| 3975 | 3975 | } |
| 3976 | 3976 | // toujours encoder l'url source dans le bloc ajax |
| 3977 | 3977 | $r = self(); |
| 3978 | - $r = ' data-origin="' . $r . '"'; |
|
| 3978 | + $r = ' data-origin="'.$r.'"'; |
|
| 3979 | 3979 | $class = 'ajaxbloc'; |
| 3980 | 3980 | if ($ajaxid && is_string($ajaxid)) { |
| 3981 | 3981 | // ajaxid est normalement conforme a un nom de classe css |
| 3982 | 3982 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 3983 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3983 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 3984 | 3984 | } |
| 3985 | 3985 | |
| 3986 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3986 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3987 | 3987 | } |
| 3988 | 3988 | |
| 3989 | 3989 | /** |
@@ -4028,7 +4028,7 @@ discard block |
||
| 4028 | 4028 | $cle = substr((string) $c, 0, $p); |
| 4029 | 4029 | $c = substr((string) $c, $p + 1); |
| 4030 | 4030 | |
| 4031 | - if ($cle === calculer_cle_action($form . $c)) { |
|
| 4031 | + if ($cle === calculer_cle_action($form.$c)) { |
|
| 4032 | 4032 | return @unserialize($c); |
| 4033 | 4033 | } |
| 4034 | 4034 | } |
@@ -4148,13 +4148,13 @@ discard block |
||
| 4148 | 4148 | } |
| 4149 | 4149 | } |
| 4150 | 4150 | } |
| 4151 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4151 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4152 | 4152 | } else { |
| 4153 | 4153 | $bal = 'a'; |
| 4154 | 4154 | $att = "href='$url'" |
| 4155 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4156 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4157 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4155 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4156 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4157 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4158 | 4158 | . $evt; |
| 4159 | 4159 | } |
| 4160 | 4160 | if ($libelle === null) { |
@@ -4291,7 +4291,7 @@ discard block |
||
| 4291 | 4291 | |
| 4292 | 4292 | // Icône |
| 4293 | 4293 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4294 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4294 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4295 | 4295 | |
| 4296 | 4296 | // Markup final |
| 4297 | 4297 | if ($type == 'lien') { |
@@ -4566,16 +4566,16 @@ discard block |
||
| 4566 | 4566 | $class_form = 'ajax'; |
| 4567 | 4567 | $class = str_replace('ajax', '', $class); |
| 4568 | 4568 | } |
| 4569 | - $class_btn = 'submit ' . trim($class); |
|
| 4569 | + $class_btn = 'submit '.trim($class); |
|
| 4570 | 4570 | |
| 4571 | 4571 | if ($confirm) { |
| 4572 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4572 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4573 | 4573 | $callback = $callback ? "$confirm?($callback):false" : $confirm; |
| 4574 | 4574 | } |
| 4575 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4575 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4576 | 4576 | $title = $title ? " title='$title'" : ''; |
| 4577 | 4577 | |
| 4578 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4578 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4579 | 4579 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4580 | 4580 | } |
| 4581 | 4581 | |
@@ -4639,14 +4639,14 @@ discard block |
||
| 4639 | 4639 | $champ_titre = ''; |
| 4640 | 4640 | if ($demande_titre) { |
| 4641 | 4641 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4642 | - $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4642 | + $champ_titre = (empty($desc['titre'])) ? '' : ', '.$desc['titre']; |
|
| 4643 | 4643 | } |
| 4644 | 4644 | include_spip('base/abstract_sql'); |
| 4645 | 4645 | include_spip('base/connect_sql'); |
| 4646 | 4646 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4647 | - '*' . $champ_titre, |
|
| 4647 | + '*'.$champ_titre, |
|
| 4648 | 4648 | $desc['table_sql'], |
| 4649 | - id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4649 | + id_table_objet($type_objet).' = '.(int) $id_objet |
|
| 4650 | 4650 | ); |
| 4651 | 4651 | |
| 4652 | 4652 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4737,8 +4737,7 @@ discard block |
||
| 4737 | 4737 | if (isset($ligne_sql['chapo'])) { |
| 4738 | 4738 | $chapo = $ligne_sql['chapo']; |
| 4739 | 4739 | $texte = strlen((string) $descriptif) ? |
| 4740 | - '' : |
|
| 4741 | - "$chapo \n\n $texte"; |
|
| 4740 | + '' : "$chapo \n\n $texte"; |
|
| 4742 | 4741 | } |
| 4743 | 4742 | |
| 4744 | 4743 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4810,7 +4809,7 @@ discard block |
||
| 4810 | 4809 | return $texte; |
| 4811 | 4810 | } |
| 4812 | 4811 | |
| 4813 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement); |
|
| 4812 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", (string) $traitement); |
|
| 4814 | 4813 | |
| 4815 | 4814 | // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
| 4816 | 4815 | if (test_espace_prive()) { |
@@ -4846,7 +4845,7 @@ discard block |
||
| 4846 | 4845 | } |
| 4847 | 4846 | $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
| 4848 | 4847 | |
| 4849 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4848 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 4850 | 4849 | } |
| 4851 | 4850 | |
| 4852 | 4851 | /** |
@@ -4872,9 +4871,9 @@ discard block |
||
| 4872 | 4871 | function wrap($texte, $wrap) { |
| 4873 | 4872 | $balises = extraire_balises($wrap); |
| 4874 | 4873 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4875 | - $texte = $wrap . $texte; |
|
| 4874 | + $texte = $wrap.$texte; |
|
| 4876 | 4875 | $regs = array_reverse($regs[1]); |
| 4877 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4876 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 4878 | 4877 | $texte .= $wrap; |
| 4879 | 4878 | } |
| 4880 | 4879 | |
@@ -4904,7 +4903,7 @@ discard block |
||
| 4904 | 4903 | |
| 4905 | 4904 | // caster $u en array si besoin |
| 4906 | 4905 | if (is_object($u)) { |
| 4907 | - $u = (array)$u; |
|
| 4906 | + $u = (array) $u; |
|
| 4908 | 4907 | } |
| 4909 | 4908 | |
| 4910 | 4909 | if (is_array($u)) { |
@@ -4926,7 +4925,7 @@ discard block |
||
| 4926 | 4925 | // sinon on passe a la ligne et on indente |
| 4927 | 4926 | $i_str = str_pad('', $indent, ' '); |
| 4928 | 4927 | foreach ($u as $k => $v) { |
| 4929 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4928 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4930 | 4929 | } |
| 4931 | 4930 | |
| 4932 | 4931 | return $out; |
@@ -4980,7 +4979,7 @@ discard block |
||
| 4980 | 4979 | * @return string |
| 4981 | 4980 | */ |
| 4982 | 4981 | function objet_icone($objet, $taille = 24, $class = '') { |
| 4983 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4982 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 4984 | 4983 | $icone = chemin_image($icone); |
| 4985 | 4984 | $balise_img = charger_filtre('balise_img'); |
| 4986 | 4985 | |
@@ -5006,7 +5005,7 @@ discard block |
||
| 5006 | 5005 | */ |
| 5007 | 5006 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5008 | 5007 | $chaine = explode(':', $chaine); |
| 5009 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5008 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5010 | 5009 | return $t; |
| 5011 | 5010 | } |
| 5012 | 5011 | $chaine = implode(':', $chaine); |
@@ -5072,7 +5071,7 @@ discard block |
||
| 5072 | 5071 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5073 | 5072 | |
| 5074 | 5073 | // calculer le nom de la css |
| 5075 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5074 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5076 | 5075 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5077 | 5076 | $contexte_implicite = calculer_contexte_implicite(); |
| 5078 | 5077 | |
@@ -5080,14 +5079,14 @@ discard block |
||
| 5080 | 5079 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5081 | 5080 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5082 | 5081 | if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
| 5083 | - $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
|
| 5082 | + $hash = md5((string) ($contexte_implicite['host'].'::'.$cache)); |
|
| 5084 | 5083 | } |
| 5085 | 5084 | else { |
| 5086 | 5085 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5087 | 5086 | ksort($contexte); |
| 5088 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5087 | + $hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect); |
|
| 5089 | 5088 | } |
| 5090 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5089 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5091 | 5090 | |
| 5092 | 5091 | // mettre a jour le fichier si il n'existe pas |
| 5093 | 5092 | // ou trop ancien |
@@ -5095,8 +5094,8 @@ discard block |
||
| 5095 | 5094 | // et recopie sur le fichier cible uniquement si il change |
| 5096 | 5095 | if ( |
| 5097 | 5096 | !file_exists($filename) |
| 5098 | - || !file_exists($filename . '.last') |
|
| 5099 | - || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5097 | + || !file_exists($filename.'.last') |
|
| 5098 | + || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename.'.last') < $cache['lastmodified'] |
|
| 5100 | 5099 | || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
| 5101 | 5100 | ) { |
| 5102 | 5101 | $contenu = $cache['texte']; |
@@ -5120,10 +5119,10 @@ discard block |
||
| 5120 | 5119 | } |
| 5121 | 5120 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5122 | 5121 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5123 | - $comment .= "}\n md5:" . md5((string) $contenu) . " */\n"; |
|
| 5122 | + $comment .= "}\n md5:".md5((string) $contenu)." */\n"; |
|
| 5124 | 5123 | } |
| 5125 | 5124 | // et ecrire le fichier si il change |
| 5126 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5125 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5127 | 5126 | } |
| 5128 | 5127 | |
| 5129 | 5128 | return timestamp($filename); |
@@ -5350,7 +5349,7 @@ discard block |
||
| 5350 | 5349 | if ($e > 0 && strlen($mid) > 8) { |
| 5351 | 5350 | $mid = '***...***'; |
| 5352 | 5351 | } |
| 5353 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5352 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5354 | 5353 | } |
| 5355 | 5354 | |
| 5356 | 5355 | |
@@ -5412,7 +5411,7 @@ discard block |
||
| 5412 | 5411 | case 'id': |
| 5413 | 5412 | case 'anchor': |
| 5414 | 5413 | if (preg_match(',^\d,', $texte)) { |
| 5415 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5414 | + $texte = substr($type, 0, 1).$texte; |
|
| 5416 | 5415 | } |
| 5417 | 5416 | } |
| 5418 | 5417 | |
@@ -5422,9 +5421,9 @@ discard block |
||
| 5422 | 5421 | |
| 5423 | 5422 | if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
| 5424 | 5423 | if (preg_match(',^\d,', $texte)) { |
| 5425 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5424 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5426 | 5425 | } |
| 5427 | - $texte .= $separateur . md5($original); |
|
| 5426 | + $texte .= $separateur.md5($original); |
|
| 5428 | 5427 | $texte = substr($texte, 0, $longueur_mini); |
| 5429 | 5428 | } |
| 5430 | 5429 | |
@@ -615,8 +615,7 @@ discard block |
||
| 615 | 615 | if (!$srcSize) { |
| 616 | 616 | $poids_img[$src] = filesize($src); |
| 617 | 617 | } |
| 618 | - } |
|
| 619 | - elseif (str_contains($src, '<svg')) { |
|
| 618 | + } elseif (str_contains($src, '<svg')) { |
|
| 620 | 619 | include_spip('inc/svg'); |
| 621 | 620 | if ($attrs = svg_lire_attributs($src)) { |
| 622 | 621 | [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
@@ -3421,8 +3420,7 @@ discard block |
||
| 3421 | 3420 | } |
| 3422 | 3421 | if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
| 3423 | 3422 | $img_file = chemin_image($img); |
| 3424 | - } |
|
| 3425 | - else { |
|
| 3423 | + } else { |
|
| 3426 | 3424 | if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
| 3427 | 3425 | $img_file = http_img_variante_svg_si_possible($img_file); |
| 3428 | 3426 | } |
@@ -3449,11 +3447,9 @@ discard block |
||
| 3449 | 3447 | } |
| 3450 | 3448 | if ($alt === false) { |
| 3451 | 3449 | $alt = ''; |
| 3452 | - } |
|
| 3453 | - elseif ($alt || $alt === '') { |
|
| 3450 | + } elseif ($alt || $alt === '') { |
|
| 3454 | 3451 | $alt = " alt='" . attribut_html($alt) . "'"; |
| 3455 | - } |
|
| 3456 | - else { |
|
| 3452 | + } else { |
|
| 3457 | 3453 | $alt = " alt='" . attribut_html($title) . "'"; |
| 3458 | 3454 | } |
| 3459 | 3455 | return "<img src='" . attribut_html($img_file) . "'$alt" |
@@ -3580,8 +3576,7 @@ discard block |
||
| 3580 | 3576 | if (!is_null($class)) { |
| 3581 | 3577 | $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
| 3582 | 3578 | } |
| 3583 | - } |
|
| 3584 | - else { |
|
| 3579 | + } else { |
|
| 3585 | 3580 | $img = http_img_pack( |
| 3586 | 3581 | $img, |
| 3587 | 3582 | $alt, |
@@ -3689,8 +3684,7 @@ discard block |
||
| 3689 | 3684 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3690 | 3685 | $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
| 3691 | 3686 | $balise_svg .= $title; |
| 3692 | - } |
|
| 3693 | - else { |
|
| 3687 | + } else { |
|
| 3694 | 3688 | $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
| 3695 | 3689 | } |
| 3696 | 3690 | |
@@ -5081,8 +5075,7 @@ discard block |
||
| 5081 | 5075 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5082 | 5076 | if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
| 5083 | 5077 | $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
| 5084 | - } |
|
| 5085 | - else { |
|
| 5078 | + } else { |
|
| 5086 | 5079 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5087 | 5080 | ksort($contexte); |
| 5088 | 5081 | $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |