@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | static $t1 = ['&', '<', '>']; |
| 120 | 120 | static $t2 = ['&', '<', '>']; |
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>'.str_replace($t1, $t2, (string) $t).'</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | foreach ($lignes as &$l) { |
| 140 | 140 | $l = implode('|', $l); |
| 141 | 141 | } |
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 142 | + $corps = implode("\n", $lignes)."\n"; |
|
| 143 | + $corps = $caption. |
|
| 144 | + "\n|{{". |
|
| 145 | + implode('}}|{{', $entete). |
|
| 146 | + '}}|'. |
|
| 147 | + "\n|". |
|
| 148 | 148 | str_replace("\n", "|\n|", $corps); |
| 149 | 149 | include_spip('inc/texte'); |
| 150 | 150 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
| 189 | 189 | $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
| 190 | 190 | |
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 191 | + return ($style ? "\n<style>".$style.'</style>' : '').$t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | include_spip('inc/filtres'); |
| 27 | 27 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string Rien. |
| 39 | 39 | **/ |
| 40 | 40 | function filtre_image_dist($t) { |
| 41 | - return ''; |
|
| 41 | + return ''; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return string Rien. |
| 52 | 52 | **/ |
| 53 | 53 | function filtre_audio_dist($t) { |
| 54 | - return ''; |
|
| 54 | + return ''; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return string Rien. |
| 65 | 65 | **/ |
| 66 | 66 | function filtre_video_dist($t) { |
| 67 | - return ''; |
|
| 67 | + return ''; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @return string Rien. |
| 78 | 78 | **/ |
| 79 | 79 | function filtre_application_dist($t) { |
| 80 | - return ''; |
|
| 80 | + return ''; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return string Rien. |
| 91 | 91 | **/ |
| 92 | 92 | function filtre_message_dist($t) { |
| 93 | - return ''; |
|
| 93 | + return ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string Rien. |
| 104 | 104 | **/ |
| 105 | 105 | function filtre_multipart_dist($t) { |
| 106 | - return ''; |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | * @return string Contenu échappé. |
| 117 | 117 | **/ |
| 118 | 118 | function filtre_text_dist($t) { |
| 119 | - static $t1 = ['&', '<', '>']; |
|
| 120 | - static $t2 = ['&', '<', '>']; |
|
| 119 | + static $t1 = ['&', '<', '>']; |
|
| 120 | + static $t2 = ['&', '<', '>']; |
|
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * Tableau (formaté en SPIP) |
| 135 | 135 | **/ |
| 136 | 136 | function filtre_text_csv_dist($t) { |
| 137 | - include_spip('inc/csv'); |
|
| 138 | - [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | - foreach ($lignes as &$l) { |
|
| 140 | - $l = implode('|', $l); |
|
| 141 | - } |
|
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 148 | - str_replace("\n", "|\n|", $corps); |
|
| 149 | - include_spip('inc/texte'); |
|
| 150 | - |
|
| 151 | - return propre($corps); |
|
| 137 | + include_spip('inc/csv'); |
|
| 138 | + [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | + foreach ($lignes as &$l) { |
|
| 140 | + $l = implode('|', $l); |
|
| 141 | + } |
|
| 142 | + $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | + $corps = $caption . |
|
| 144 | + "\n|{{" . |
|
| 145 | + implode('}}|{{', $entete) . |
|
| 146 | + '}}|' . |
|
| 147 | + "\n|" . |
|
| 148 | + str_replace("\n", "|\n|", $corps); |
|
| 149 | + include_spip('inc/texte'); |
|
| 150 | + |
|
| 151 | + return propre($corps); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -162,33 +162,33 @@ discard block |
||
| 162 | 162 | * @return string Code html sécurisé ou texte échappé |
| 163 | 163 | **/ |
| 164 | 164 | function filtre_text_html_dist($t) { |
| 165 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | - return appliquer_filtre($t, 'text/plain'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - [, $h, $t] = $r; |
|
| 170 | - |
|
| 171 | - $style = ''; |
|
| 172 | - // recuperer les styles internes |
|
| 173 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | - $style = implode("\n", $r[1]); |
|
| 175 | - } |
|
| 176 | - // ... et externes |
|
| 177 | - |
|
| 178 | - include_spip('inc/distant'); |
|
| 179 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | - foreach ($r[0] as $l) { |
|
| 181 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | - $page = recuperer_url($m[1]); |
|
| 183 | - $page = $page['page'] ?? ''; |
|
| 184 | - $style .= "\n/* $l */\n" |
|
| 185 | - . str_replace('<', '', (string) $page); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | - $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | - |
|
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 165 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | + return appliquer_filtre($t, 'text/plain'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + [, $h, $t] = $r; |
|
| 170 | + |
|
| 171 | + $style = ''; |
|
| 172 | + // recuperer les styles internes |
|
| 173 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | + $style = implode("\n", $r[1]); |
|
| 175 | + } |
|
| 176 | + // ... et externes |
|
| 177 | + |
|
| 178 | + include_spip('inc/distant'); |
|
| 179 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | + foreach ($r[0] as $l) { |
|
| 181 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | + $page = recuperer_url($m[1]); |
|
| 183 | + $page = $page['page'] ?? ''; |
|
| 184 | + $style .= "\n/* $l */\n" |
|
| 185 | + . str_replace('<', '', (string) $page); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | + $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | + |
|
| 191 | + return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return string Code HTML des balises `<param>` |
| 202 | 202 | **/ |
| 203 | 203 | function filtre_audio_x_pn_realaudio($id) { |
| 204 | - return " |
|
| 204 | + return " |
|
| 205 | 205 | <param name='controls' value='PositionSlider' /> |
| 206 | 206 | <param name='controls' value='ImageWindow' /> |
| 207 | 207 | <param name='controls' value='PlayButton' /> |
@@ -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 | include_spip('inc/filtres'); |
| 22 | 22 | include_spip('inc/lang'); |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function definir_puce() { |
| 40 | 40 | |
| 41 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 42 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 43 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 44 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 41 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 42 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 43 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 44 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 45 | 45 | |
| 46 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | - if ($dir == 'rtl') { |
|
| 48 | - $p .= '_rtl'; |
|
| 49 | - } |
|
| 46 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + if ($dir == 'rtl') { |
|
| 48 | + $p .= '_rtl'; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if (!isset($GLOBALS[$p])) { |
|
| 52 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | - } |
|
| 51 | + if (!isset($GLOBALS[$p])) { |
|
| 52 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return $GLOBALS[$p]; |
|
| 55 | + return $GLOBALS[$p]; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -66,31 +66,31 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 68 | 68 | |
| 69 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | - $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | - if ($attributs) { |
|
| 72 | - $attributs = ' ' . trim($attributs); |
|
| 73 | - } |
|
| 74 | - if ($langage) { |
|
| 75 | - $class .= " language-$langage"; |
|
| 76 | - $attributs .= ' data-language="' . $langage . '"'; |
|
| 77 | - } |
|
| 78 | - if ($bloc) { |
|
| 79 | - $html = '<div class="precode">' |
|
| 80 | - . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | - . '<code>' |
|
| 82 | - . $echap |
|
| 83 | - . '</code>' |
|
| 84 | - . '</pre>' |
|
| 85 | - . '</div>'; |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - $echap = str_replace("\t", ' ', $echap); |
|
| 89 | - $echap = str_replace(' ', ' ', $echap); |
|
| 90 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $html; |
|
| 69 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | + $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | + if ($attributs) { |
|
| 72 | + $attributs = ' ' . trim($attributs); |
|
| 73 | + } |
|
| 74 | + if ($langage) { |
|
| 75 | + $class .= " language-$langage"; |
|
| 76 | + $attributs .= ' data-language="' . $langage . '"'; |
|
| 77 | + } |
|
| 78 | + if ($bloc) { |
|
| 79 | + $html = '<div class="precode">' |
|
| 80 | + . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | + . '<code>' |
|
| 82 | + . $echap |
|
| 83 | + . '</code>' |
|
| 84 | + . '</pre>' |
|
| 85 | + . '</div>'; |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + $echap = str_replace("\t", ' ', $echap); |
|
| 89 | + $echap = str_replace(' ', ' ', $echap); |
|
| 90 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $html; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 99 | 99 | |
| 100 | 100 | if (!defined('_BALISES_BLOCS')) { |
| 101 | - define( |
|
| 102 | - '_BALISES_BLOCS', |
|
| 103 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 104 | - ); |
|
| 101 | + define( |
|
| 102 | + '_BALISES_BLOCS', |
|
| 103 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 104 | + ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 108 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 108 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // |
@@ -116,100 +116,100 @@ discard block |
||
| 116 | 116 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 117 | 117 | // echappe est un div ou un span |
| 118 | 118 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 119 | - if (!strlen($rempl)) { |
|
| 120 | - return ''; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // Tester si on echappe en span ou en div |
|
| 124 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 125 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 129 | - $taille = 30000; |
|
| 130 | - $return = ''; |
|
| 131 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 132 | - // Convertir en base64 et cacher dans un attribut |
|
| 133 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 134 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 135 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $return; |
|
| 119 | + if (!strlen($rempl)) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // Tester si on echappe en span ou en div |
|
| 124 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 125 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 129 | + $taille = 30000; |
|
| 130 | + $return = ''; |
|
| 131 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 132 | + // Convertir en base64 et cacher dans un attribut |
|
| 133 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 134 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 135 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $return; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
| 142 | 142 | // Echapper les <html>...</ html> |
| 143 | 143 | function traiter_echap_html_dist($regs, $options = []) { |
| 144 | - return $regs[3]; |
|
| 144 | + return $regs[3]; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Echapper les <pre>...</ pre> |
| 148 | 148 | function traiter_echap_pre_dist($regs, $options = []) { |
| 149 | - // echapper les <code> dans <pre> |
|
| 150 | - $pre = $regs[3]; |
|
| 151 | - |
|
| 152 | - // echapper les < dans <code> |
|
| 153 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 154 | - if ( |
|
| 155 | - strpos($pre, '<') !== false |
|
| 156 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 157 | - ) { |
|
| 158 | - foreach ($matches as $m) { |
|
| 159 | - if ($m[1] === 'code') { |
|
| 160 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 161 | - $pre = str_replace($m[0], $code, $pre); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - return "<pre>$pre</pre>"; |
|
| 149 | + // echapper les <code> dans <pre> |
|
| 150 | + $pre = $regs[3]; |
|
| 151 | + |
|
| 152 | + // echapper les < dans <code> |
|
| 153 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 154 | + if ( |
|
| 155 | + strpos($pre, '<') !== false |
|
| 156 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 157 | + ) { |
|
| 158 | + foreach ($matches as $m) { |
|
| 159 | + if ($m[1] === 'code') { |
|
| 160 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 161 | + $pre = str_replace($m[0], $code, $pre); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + return "<pre>$pre</pre>"; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Echapper les <code>...</ code> |
| 169 | 169 | function traiter_echap_code_dist($regs, $options = []) { |
| 170 | - [, , $att, $corps] = $regs; |
|
| 170 | + [, , $att, $corps] = $regs; |
|
| 171 | 171 | |
| 172 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 173 | - if (strpos($corps, "\n") !== false) { |
|
| 174 | - // supprimer les sauts de ligne debut/fin |
|
| 175 | - // (mais pas les espaces => ascii art). |
|
| 176 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 172 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 173 | + if (strpos($corps, "\n") !== false) { |
|
| 174 | + // supprimer les sauts de ligne debut/fin |
|
| 175 | + // (mais pas les espaces => ascii art). |
|
| 176 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 177 | 177 | |
| 178 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 179 | - } else { |
|
| 180 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 181 | - } |
|
| 178 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 179 | + } else { |
|
| 180 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $echap; |
|
| 183 | + return $echap; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 187 | 187 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 188 | - $echap = trim(entites_html($regs[3])); |
|
| 189 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 190 | - $lignes = explode("\n", trim($echap)); |
|
| 191 | - $n = 0; |
|
| 192 | - foreach ($lignes as $l) { |
|
| 193 | - $n += floor(strlen($l) / 60) + 1; |
|
| 194 | - } |
|
| 195 | - $n = max($n, 2); |
|
| 196 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 197 | - |
|
| 198 | - return $echap; |
|
| 188 | + $echap = trim(entites_html($regs[3])); |
|
| 189 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 190 | + $lignes = explode("\n", trim($echap)); |
|
| 191 | + $n = 0; |
|
| 192 | + foreach ($lignes as $l) { |
|
| 193 | + $n += floor(strlen($l) / 60) + 1; |
|
| 194 | + } |
|
| 195 | + $n = max($n, 2); |
|
| 196 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 197 | + |
|
| 198 | + return $echap; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | function traiter_echap_frame_dist($regs, $options = []) { |
| 202 | - return traiter_echap_cadre_dist($regs); |
|
| 202 | + return traiter_echap_cadre_dist($regs); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function traiter_echap_script_dist($regs, $options = []) { |
| 206 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 207 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 208 | - return highlight_string($regs[0], true); |
|
| 209 | - } |
|
| 206 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 207 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 208 | + return highlight_string($regs[0], true); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - // Cas normal : le script passe tel quel |
|
| 212 | - return $regs[0]; |
|
| 211 | + // Cas normal : le script passe tel quel |
|
| 212 | + return $regs[0]; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -228,74 +228,74 @@ discard block |
||
| 228 | 228 | * @return string|string[] |
| 229 | 229 | */ |
| 230 | 230 | function echappe_html( |
| 231 | - $letexte, |
|
| 232 | - $source = '', |
|
| 233 | - $no_transform = false, |
|
| 234 | - $preg = '', |
|
| 235 | - $callback_prefix = '', |
|
| 236 | - $callback_options = [] |
|
| 231 | + $letexte, |
|
| 232 | + $source = '', |
|
| 233 | + $no_transform = false, |
|
| 234 | + $preg = '', |
|
| 235 | + $callback_prefix = '', |
|
| 236 | + $callback_options = [] |
|
| 237 | 237 | ) { |
| 238 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 239 | - return $letexte; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if ( |
|
| 243 | - ($preg or str_contains($letexte, '<')) |
|
| 244 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 245 | - ) { |
|
| 246 | - foreach ($matches as $regs) { |
|
| 247 | - $echap = ''; |
|
| 248 | - // echappements tels quels ? |
|
| 249 | - if ($no_transform) { |
|
| 250 | - $echap = $regs[0]; |
|
| 251 | - } else { |
|
| 252 | - // sinon les traiter selon le cas |
|
| 253 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | - if ( |
|
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 257 | - or ($callback_secure_prefix and ( |
|
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 260 | - )) |
|
| 261 | - ) { |
|
| 262 | - $echap = $f($regs, $callback_options); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if ($no_transform) { |
|
| 272 | - return $letexte; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | - // seulement si on a echappe les <script> |
|
| 277 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | - // dans une callback autonommee |
|
| 279 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | - if ( |
|
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | - ',<[?].*($|[?]>),UisS', |
|
| 283 | - $letexte, |
|
| 284 | - $matches, |
|
| 285 | - PREG_SET_ORDER |
|
| 286 | - ) |
|
| 287 | - ) { |
|
| 288 | - foreach ($matches as $regs) { |
|
| 289 | - $letexte = str_replace( |
|
| 290 | - $regs[0], |
|
| 291 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | - $letexte |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return $letexte; |
|
| 238 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 239 | + return $letexte; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if ( |
|
| 243 | + ($preg or str_contains($letexte, '<')) |
|
| 244 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 245 | + ) { |
|
| 246 | + foreach ($matches as $regs) { |
|
| 247 | + $echap = ''; |
|
| 248 | + // echappements tels quels ? |
|
| 249 | + if ($no_transform) { |
|
| 250 | + $echap = $regs[0]; |
|
| 251 | + } else { |
|
| 252 | + // sinon les traiter selon le cas |
|
| 253 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | + if ( |
|
| 255 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f . '_dist') |
|
| 257 | + or ($callback_secure_prefix and ( |
|
| 258 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f . '_dist') |
|
| 260 | + )) |
|
| 261 | + ) { |
|
| 262 | + $echap = $f($regs, $callback_options); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if ($no_transform) { |
|
| 272 | + return $letexte; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | + // seulement si on a echappe les <script> |
|
| 277 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | + // dans une callback autonommee |
|
| 279 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | + if ( |
|
| 281 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | + ',<[?].*($|[?]>),UisS', |
|
| 283 | + $letexte, |
|
| 284 | + $matches, |
|
| 285 | + PREG_SET_ORDER |
|
| 286 | + ) |
|
| 287 | + ) { |
|
| 288 | + foreach ($matches as $regs) { |
|
| 289 | + $letexte = str_replace( |
|
| 290 | + $regs[0], |
|
| 291 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | + $letexte |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return $letexte; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // |
@@ -303,57 +303,57 @@ discard block |
||
| 303 | 303 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 304 | 304 | // par propre() : exemple dans multi et dans typo() |
| 305 | 305 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 306 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | - $max_prof = 5; |
|
| 309 | - while ( |
|
| 310 | - strpos($letexte, '<') !== false |
|
| 311 | - and |
|
| 312 | - preg_match_all( |
|
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | - $letexte, |
|
| 315 | - $regs, |
|
| 316 | - PREG_SET_ORDER |
|
| 317 | - ) |
|
| 318 | - and $max_prof-- |
|
| 319 | - ) { |
|
| 320 | - foreach ($regs as $reg) { |
|
| 321 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | - // recherche d'attributs supplementaires |
|
| 323 | - $at = []; |
|
| 324 | - foreach (['lang', 'dir'] as $attr) { |
|
| 325 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | - $at[$attr] = $a; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($at) { |
|
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | - foreach ($at as $attr => $a) { |
|
| 332 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - if ($filtre) { |
|
| 336 | - $rempl = $filtre($rempl); |
|
| 337 | - } |
|
| 338 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $letexte; |
|
| 306 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | + $max_prof = 5; |
|
| 309 | + while ( |
|
| 310 | + strpos($letexte, '<') !== false |
|
| 311 | + and |
|
| 312 | + preg_match_all( |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | + $letexte, |
|
| 315 | + $regs, |
|
| 316 | + PREG_SET_ORDER |
|
| 317 | + ) |
|
| 318 | + and $max_prof-- |
|
| 319 | + ) { |
|
| 320 | + foreach ($regs as $reg) { |
|
| 321 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | + // recherche d'attributs supplementaires |
|
| 323 | + $at = []; |
|
| 324 | + foreach (['lang', 'dir'] as $attr) { |
|
| 325 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | + $at[$attr] = $a; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($at) { |
|
| 330 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | + foreach ($at as $attr => $a) { |
|
| 332 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + if ($filtre) { |
|
| 336 | + $rempl = $filtre($rempl); |
|
| 337 | + } |
|
| 338 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $letexte; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Reinserer le javascript de confiance (venant des modeles) |
| 347 | 347 | |
| 348 | 348 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 349 | - $letexte = echappe_retour($letexte); |
|
| 349 | + $letexte = echappe_retour($letexte); |
|
| 350 | 350 | |
| 351 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | - if ($interdire_scripts) { |
|
| 353 | - $letexte = interdire_scripts($letexte); |
|
| 354 | - } |
|
| 351 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | + if ($interdire_scripts) { |
|
| 353 | + $letexte = interdire_scripts($letexte); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return trim($letexte); |
|
| 356 | + return trim($letexte); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
@@ -381,128 +381,128 @@ discard block |
||
| 381 | 381 | * texte coupé |
| 382 | 382 | **/ |
| 383 | 383 | function couper($texte, $taille = 50, $suite = null) { |
| 384 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 387 | - $offset = 400 + 2 * $taille; |
|
| 388 | - while ( |
|
| 389 | - $offset < $length |
|
| 390 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | - ) { |
|
| 392 | - $offset = 2 * $offset; |
|
| 393 | - } |
|
| 394 | - if ( |
|
| 395 | - $offset < $length |
|
| 396 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | - ) { |
|
| 398 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | - $offset = $p_tag_fermant + 1; |
|
| 401 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | - } |
|
| 403 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | - |
|
| 405 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | - include_spip('inc/lien'); |
|
| 407 | - } |
|
| 408 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | - |
|
| 410 | - // balises de sauts de ligne et paragraphe |
|
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | - |
|
| 414 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | - $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | - |
|
| 417 | - // supprimer les tags |
|
| 418 | - $texte = supprimer_tags($texte); |
|
| 419 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | - |
|
| 421 | - // tester s'il est nécessaire de couper le texte |
|
| 422 | - if (spip_strlen($texte) <= $taille) { |
|
| 423 | - $points = ''; |
|
| 424 | - } else { |
|
| 425 | - // points de suite |
|
| 426 | - if (is_null($suite)) { |
|
| 427 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | - } |
|
| 429 | - $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | - |
|
| 431 | - // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | - // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | - // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | - // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | - $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | - $points = $suite; |
|
| 439 | - |
|
| 440 | - // trop court ? ne pas faire de (...) |
|
| 441 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | - $points = ''; |
|
| 443 | - $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | - // encore trop court ? couper au caractere |
|
| 447 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | - $texte = spip_substr($long, 0, $taille); |
|
| 449 | - } |
|
| 450 | - } else { |
|
| 451 | - $texte = $court; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // remettre les paragraphes |
|
| 456 | - $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | - |
|
| 458 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | - |
|
| 461 | - return quote_amp(trim($texte)) . $points; |
|
| 384 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | + $offset = 400 + 2 * $taille; |
|
| 388 | + while ( |
|
| 389 | + $offset < $length |
|
| 390 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | + ) { |
|
| 392 | + $offset = 2 * $offset; |
|
| 393 | + } |
|
| 394 | + if ( |
|
| 395 | + $offset < $length |
|
| 396 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | + ) { |
|
| 398 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | + $offset = $p_tag_fermant + 1; |
|
| 401 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | + } |
|
| 403 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | + |
|
| 405 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | + include_spip('inc/lien'); |
|
| 407 | + } |
|
| 408 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | + |
|
| 410 | + // balises de sauts de ligne et paragraphe |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | + |
|
| 414 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | + $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | + |
|
| 417 | + // supprimer les tags |
|
| 418 | + $texte = supprimer_tags($texte); |
|
| 419 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | + |
|
| 421 | + // tester s'il est nécessaire de couper le texte |
|
| 422 | + if (spip_strlen($texte) <= $taille) { |
|
| 423 | + $points = ''; |
|
| 424 | + } else { |
|
| 425 | + // points de suite |
|
| 426 | + if (is_null($suite)) { |
|
| 427 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | + } |
|
| 429 | + $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | + |
|
| 431 | + // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | + // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | + // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | + // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | + $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | + $points = $suite; |
|
| 439 | + |
|
| 440 | + // trop court ? ne pas faire de (...) |
|
| 441 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | + $points = ''; |
|
| 443 | + $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | + // encore trop court ? couper au caractere |
|
| 447 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | + $texte = spip_substr($long, 0, $taille); |
|
| 449 | + } |
|
| 450 | + } else { |
|
| 451 | + $texte = $court; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // remettre les paragraphes |
|
| 456 | + $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | + |
|
| 458 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | + |
|
| 461 | + return quote_amp(trim($texte)) . $points; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
| 465 | 465 | function protege_js_modeles($t) { |
| 466 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | - include_spip('inc/acces'); |
|
| 470 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | - } |
|
| 472 | - foreach ($r as $regs) { |
|
| 473 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | - include_spip('inc/acces'); |
|
| 479 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | - } |
|
| 481 | - foreach ($r as $regs) { |
|
| 482 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $t; |
|
| 466 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | + include_spip('inc/acces'); |
|
| 470 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | + } |
|
| 472 | + foreach ($r as $regs) { |
|
| 473 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | + include_spip('inc/acces'); |
|
| 479 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | + } |
|
| 481 | + foreach ($r as $regs) { |
|
| 482 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $t; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
| 491 | 491 | function echapper_faux_tags($letexte) { |
| 492 | - if (strpos($letexte, '<') === false) { |
|
| 493 | - return $letexte; |
|
| 494 | - } |
|
| 495 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | - |
|
| 497 | - $letexte = ''; |
|
| 498 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | - // un texte a echapper |
|
| 500 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | - // un tag html qui a servit a faite le split |
|
| 502 | - $letexte .= array_shift($textMatches); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return $letexte; |
|
| 492 | + if (strpos($letexte, '<') === false) { |
|
| 493 | + return $letexte; |
|
| 494 | + } |
|
| 495 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | + |
|
| 497 | + $letexte = ''; |
|
| 498 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | + // un texte a echapper |
|
| 500 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | + // un tag html qui a servit a faite le split |
|
| 502 | + $letexte .= array_shift($textMatches); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return $letexte; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -522,114 +522,114 @@ discard block |
||
| 522 | 522 | * @return string |
| 523 | 523 | */ |
| 524 | 524 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 525 | - static $echapper_html_suspect; |
|
| 526 | - if (!$texte or !is_string($texte)) { |
|
| 527 | - return $texte; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!isset($echapper_html_suspect)) { |
|
| 531 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | - } |
|
| 533 | - // si fonction personalisee, on delegue |
|
| 534 | - if ($echapper_html_suspect) { |
|
| 535 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | - $args = [$texte, $options]; |
|
| 537 | - if ($connect or !empty($env)) { |
|
| 538 | - $args[] = $connect; |
|
| 539 | - } |
|
| 540 | - if (!empty($env)) { |
|
| 541 | - $args[] = $env; |
|
| 542 | - } |
|
| 543 | - return $echapper_html_suspect(...$args); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if (is_bool($options)) { |
|
| 547 | - $options = ['strict' => $options]; |
|
| 548 | - } |
|
| 549 | - $strict = $options['strict'] ?? true; |
|
| 550 | - |
|
| 551 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | - if ( |
|
| 553 | - strpos($texte, '<') === false |
|
| 554 | - or !str_contains($texte, '=') |
|
| 555 | - ) { |
|
| 556 | - return $texte; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | - if (!isset($env['espace_prive'])) { |
|
| 561 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | - $env['espace_prive'] = test_espace_prive(); |
|
| 563 | - } |
|
| 564 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 566 | - // car sinon on declenche sur les modeles ou ressources |
|
| 567 | - if ( |
|
| 568 | - !$strict and |
|
| 569 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 570 | - ) { |
|
| 571 | - return $texte; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 575 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 576 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 577 | - $texte = $collecteurModeles->echapper($texte); |
|
| 578 | - $texte = echappe_js($texte); |
|
| 579 | - |
|
| 580 | - $texte_to_check = $texte; |
|
| 581 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 582 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 583 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 584 | - if (!empty($options['expanser_liens'])) { |
|
| 585 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 586 | - } |
|
| 587 | - if (!is_html_safe($texte_to_check)) { |
|
| 588 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 589 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 590 | - $texte = str_replace('<', '<', $texte); |
|
| 591 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 592 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 593 | - if (!function_exists('attribut_html')) { |
|
| 594 | - include_spip('inc/filtres'); |
|
| 595 | - } |
|
| 596 | - if (!empty($options['wrap_suspect'])) { |
|
| 597 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 598 | - } |
|
| 599 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $texte = $collecteurModeles->retablir($texte); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // si on est là dans le public c'est le mode parano |
|
| 606 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 607 | - else { |
|
| 608 | - $collecteurLiens = $collecteurModeles = null; |
|
| 609 | - if (!empty($options['expanser_liens'])) { |
|
| 610 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 611 | - } |
|
| 612 | - else { |
|
| 613 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 614 | - include_spip('src/Texte/Collecteur/Liens'); |
|
| 615 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 616 | - |
|
| 617 | - $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 618 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 619 | - |
|
| 620 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 621 | - $texte = $collecteurModeles->echapper($texte); |
|
| 622 | - } |
|
| 623 | - $texte = safehtml($texte); |
|
| 624 | - if ($collecteurModeles) { |
|
| 625 | - $texte = $collecteurModeles->retablir($texte); |
|
| 626 | - } |
|
| 627 | - if ($collecteurLiens) { |
|
| 628 | - $texte = $collecteurLiens->retablir($texte); |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - return $texte; |
|
| 525 | + static $echapper_html_suspect; |
|
| 526 | + if (!$texte or !is_string($texte)) { |
|
| 527 | + return $texte; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + if (!isset($echapper_html_suspect)) { |
|
| 531 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | + } |
|
| 533 | + // si fonction personalisee, on delegue |
|
| 534 | + if ($echapper_html_suspect) { |
|
| 535 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | + $args = [$texte, $options]; |
|
| 537 | + if ($connect or !empty($env)) { |
|
| 538 | + $args[] = $connect; |
|
| 539 | + } |
|
| 540 | + if (!empty($env)) { |
|
| 541 | + $args[] = $env; |
|
| 542 | + } |
|
| 543 | + return $echapper_html_suspect(...$args); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if (is_bool($options)) { |
|
| 547 | + $options = ['strict' => $options]; |
|
| 548 | + } |
|
| 549 | + $strict = $options['strict'] ?? true; |
|
| 550 | + |
|
| 551 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | + if ( |
|
| 553 | + strpos($texte, '<') === false |
|
| 554 | + or !str_contains($texte, '=') |
|
| 555 | + ) { |
|
| 556 | + return $texte; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | + if (!isset($env['espace_prive'])) { |
|
| 561 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | + $env['espace_prive'] = test_espace_prive(); |
|
| 563 | + } |
|
| 564 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 566 | + // car sinon on declenche sur les modeles ou ressources |
|
| 567 | + if ( |
|
| 568 | + !$strict and |
|
| 569 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 570 | + ) { |
|
| 571 | + return $texte; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 575 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 576 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 577 | + $texte = $collecteurModeles->echapper($texte); |
|
| 578 | + $texte = echappe_js($texte); |
|
| 579 | + |
|
| 580 | + $texte_to_check = $texte; |
|
| 581 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 582 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 583 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 584 | + if (!empty($options['expanser_liens'])) { |
|
| 585 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 586 | + } |
|
| 587 | + if (!is_html_safe($texte_to_check)) { |
|
| 588 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 589 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 590 | + $texte = str_replace('<', '<', $texte); |
|
| 591 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 592 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 593 | + if (!function_exists('attribut_html')) { |
|
| 594 | + include_spip('inc/filtres'); |
|
| 595 | + } |
|
| 596 | + if (!empty($options['wrap_suspect'])) { |
|
| 597 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 598 | + } |
|
| 599 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + $texte = $collecteurModeles->retablir($texte); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // si on est là dans le public c'est le mode parano |
|
| 606 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 607 | + else { |
|
| 608 | + $collecteurLiens = $collecteurModeles = null; |
|
| 609 | + if (!empty($options['expanser_liens'])) { |
|
| 610 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 611 | + } |
|
| 612 | + else { |
|
| 613 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 614 | + include_spip('src/Texte/Collecteur/Liens'); |
|
| 615 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 616 | + |
|
| 617 | + $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 618 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 619 | + |
|
| 620 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 621 | + $texte = $collecteurModeles->echapper($texte); |
|
| 622 | + } |
|
| 623 | + $texte = safehtml($texte); |
|
| 624 | + if ($collecteurModeles) { |
|
| 625 | + $texte = $collecteurModeles->retablir($texte); |
|
| 626 | + } |
|
| 627 | + if ($collecteurLiens) { |
|
| 628 | + $texte = $collecteurLiens->retablir($texte); |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + return $texte; |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | |
@@ -650,52 +650,52 @@ discard block |
||
| 650 | 650 | * texte sécurisé |
| 651 | 651 | **/ |
| 652 | 652 | function safehtml($t) { |
| 653 | - static $safehtml; |
|
| 654 | - |
|
| 655 | - if (!$t or !is_string($t)) { |
|
| 656 | - return $t; |
|
| 657 | - } |
|
| 658 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 659 | - if (strpos($t, '<') === false) { |
|
| 660 | - return str_replace("\x00", '', $t); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $collecteurIdiomes = null; |
|
| 664 | - if (stripos($t, '<:') !== false) { |
|
| 665 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 666 | - include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 667 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 668 | - $t = $collecteurIdiomes->echapper($t); |
|
| 669 | - } |
|
| 670 | - $collecteurMultis = null; |
|
| 671 | - if (stripos($t, '<multi') !== false) { |
|
| 672 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 673 | - include_spip('src/Texte/Collecteur/Multis'); |
|
| 674 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 675 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - if (!function_exists('interdire_scripts')) { |
|
| 679 | - include_spip('inc/texte'); |
|
| 680 | - } |
|
| 681 | - $t = interdire_scripts($t); // jolifier le php |
|
| 682 | - $t = echappe_js($t); |
|
| 683 | - |
|
| 684 | - if (!isset($safehtml)) { |
|
| 685 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 686 | - } |
|
| 687 | - if ($safehtml) { |
|
| 688 | - $t = $safehtml($t); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - if ($collecteurMultis) { |
|
| 692 | - $t = $collecteurMultis->retablir($t); |
|
| 693 | - } |
|
| 694 | - if ($collecteurIdiomes) { |
|
| 695 | - $t = $collecteurIdiomes->retablir($t); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 653 | + static $safehtml; |
|
| 654 | + |
|
| 655 | + if (!$t or !is_string($t)) { |
|
| 656 | + return $t; |
|
| 657 | + } |
|
| 658 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 659 | + if (strpos($t, '<') === false) { |
|
| 660 | + return str_replace("\x00", '', $t); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $collecteurIdiomes = null; |
|
| 664 | + if (stripos($t, '<:') !== false) { |
|
| 665 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 666 | + include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 667 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 668 | + $t = $collecteurIdiomes->echapper($t); |
|
| 669 | + } |
|
| 670 | + $collecteurMultis = null; |
|
| 671 | + if (stripos($t, '<multi') !== false) { |
|
| 672 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 673 | + include_spip('src/Texte/Collecteur/Multis'); |
|
| 674 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 675 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + if (!function_exists('interdire_scripts')) { |
|
| 679 | + include_spip('inc/texte'); |
|
| 680 | + } |
|
| 681 | + $t = interdire_scripts($t); // jolifier le php |
|
| 682 | + $t = echappe_js($t); |
|
| 683 | + |
|
| 684 | + if (!isset($safehtml)) { |
|
| 685 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 686 | + } |
|
| 687 | + if ($safehtml) { |
|
| 688 | + $t = $safehtml($t); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + if ($collecteurMultis) { |
|
| 692 | + $t = $collecteurMultis->retablir($t); |
|
| 693 | + } |
|
| 694 | + if ($collecteurIdiomes) { |
|
| 695 | + $t = $collecteurIdiomes->retablir($t); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | |
@@ -703,25 +703,25 @@ discard block |
||
| 703 | 703 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 704 | 704 | */ |
| 705 | 705 | function is_html_safe(string $texte): bool { |
| 706 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 707 | - return $is_html_safe($texte); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 711 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 712 | - // safehtml reduit aussi potentiellement les |
|
| 713 | - $texte = str_replace(' ', ' ', $texte); |
|
| 714 | - // safehtml remplace les entités numériques |
|
| 715 | - if (strpos($texte, '&#') !== false) { |
|
| 716 | - $texte = unicode2charset($texte); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - $texte_safe = safehtml($texte); |
|
| 720 | - |
|
| 721 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 722 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 723 | - // donc un test d'egalite est trop strict |
|
| 724 | - return strlen($texte_safe) === strlen($texte); |
|
| 706 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 707 | + return $is_html_safe($texte); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 711 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 712 | + // safehtml reduit aussi potentiellement les |
|
| 713 | + $texte = str_replace(' ', ' ', $texte); |
|
| 714 | + // safehtml remplace les entités numériques |
|
| 715 | + if (strpos($texte, '&#') !== false) { |
|
| 716 | + $texte = unicode2charset($texte); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + $texte_safe = safehtml($texte); |
|
| 720 | + |
|
| 721 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 722 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 723 | + // donc un test d'egalite est trop strict |
|
| 724 | + return strlen($texte_safe) === strlen($texte); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -742,13 +742,13 @@ discard block |
||
| 742 | 742 | * texte sans les modèles d'image |
| 743 | 743 | **/ |
| 744 | 744 | function supprime_img($letexte, $message = null) { |
| 745 | - if ($message === null) { |
|
| 746 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - return preg_replace( |
|
| 750 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 751 | - $message, |
|
| 752 | - $letexte |
|
| 753 | - ); |
|
| 745 | + if ($message === null) { |
|
| 746 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + return preg_replace( |
|
| 750 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 751 | + $message, |
|
| 752 | + $letexte |
|
| 753 | + ); |
|
| 754 | 754 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | // celle du texte) et public (spip_lang est la langue du texte) |
| 44 | 44 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 45 | 45 | |
| 46 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 46 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 47 | 47 | if ($dir == 'rtl') { |
| 48 | 48 | $p .= '_rtl'; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if (!isset($GLOBALS[$p])) { |
| 52 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 52 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $GLOBALS[$p]; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 68 | 68 | |
| 69 | 69 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 70 | - $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 70 | + $class = 'spip_code '.($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | 71 | if ($attributs) { |
| 72 | - $attributs = ' ' . trim($attributs); |
|
| 72 | + $attributs = ' '.trim($attributs); |
|
| 73 | 73 | } |
| 74 | 74 | if ($langage) { |
| 75 | 75 | $class .= " language-$langage"; |
| 76 | - $attributs .= ' data-language="' . $langage . '"'; |
|
| 76 | + $attributs .= ' data-language="'.$langage.'"'; |
|
| 77 | 77 | } |
| 78 | 78 | if ($bloc) { |
| 79 | 79 | $html = '<div class="precode">' |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | else { |
| 88 | 88 | $echap = str_replace("\t", ' ', $echap); |
| 89 | 89 | $echap = str_replace(' ', ' ', $echap); |
| 90 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>'; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $html; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 108 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 108 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // Tester si on echappe en span ou en div |
| 124 | 124 | if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
| 125 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 125 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ) { |
| 158 | 158 | foreach ($matches as $m) { |
| 159 | 159 | if ($m[1] === 'code') { |
| 160 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 160 | + $code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>'; |
|
| 161 | 161 | $pre = str_replace($m[0], $code, $pre); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // Echapper les <code>...</ code> |
| 169 | 169 | function traiter_echap_code_dist($regs, $options = []) { |
| 170 | - [, , $att, $corps] = $regs; |
|
| 170 | + [,, $att, $corps] = $regs; |
|
| 171 | 171 | |
| 172 | 172 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
| 173 | 173 | if (strpos($corps, "\n") !== false) { |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | // sinon les traiter selon le cas |
| 253 | 253 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 254 | 254 | if ( |
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 255 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f.'_dist') |
|
| 257 | 257 | or ($callback_secure_prefix and ( |
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 258 | + function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f.'_dist') |
|
| 260 | 260 | )) |
| 261 | 261 | ) { |
| 262 | 262 | $echap = $f($regs, $callback_options); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | // dans une callback autonommee |
| 279 | 279 | if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
| 280 | 280 | if ( |
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 281 | + strpos($letexte, '<'.'?') !== false and preg_match_all( |
|
| 282 | 282 | ',<[?].*($|[?]>),UisS', |
| 283 | 283 | $letexte, |
| 284 | 284 | $matches, |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | strpos($letexte, '<') !== false |
| 311 | 311 | and |
| 312 | 312 | preg_match_all( |
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | 314 | $letexte, |
| 315 | 315 | $regs, |
| 316 | 316 | PREG_SET_ORDER |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | if ($at) { |
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 330 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 331 | 331 | foreach ($at as $attr => $a) { |
| 332 | 332 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 333 | 333 | } |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | $texte = nettoyer_raccourcis_typo($texte); |
| 409 | 409 | |
| 410 | 410 | // balises de sauts de ligne et paragraphe |
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 413 | 413 | |
| 414 | 414 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 415 | 415 | $texte = str_replace("\n\n", "\r\r", $texte); |
@@ -434,15 +434,15 @@ discard block |
||
| 434 | 434 | // excédentaire est ensuite supprimé par l'appel à preg_replace() |
| 435 | 435 | $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
| 436 | 436 | $u = $GLOBALS['meta']['pcre_u']; |
| 437 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 437 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 438 | 438 | $points = $suite; |
| 439 | 439 | |
| 440 | 440 | // trop court ? ne pas faire de (...) |
| 441 | 441 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 442 | 442 | $points = ''; |
| 443 | 443 | $long = spip_substr($texte, 0, $taille + 1); |
| 444 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 444 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, $long, $m); |
|
| 445 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 446 | 446 | // encore trop court ? couper au caractere |
| 447 | 447 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 448 | 448 | $texte = spip_substr($long, 0, $taille); |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | // supprimer l'eventuelle entite finale mal coupee |
| 459 | 459 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 460 | 460 | |
| 461 | - return quote_amp(trim($texte)) . $points; |
|
| 461 | + return quote_amp(trim($texte)).$points; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -470,16 +470,16 @@ discard block |
||
| 470 | 470 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 471 | 471 | } |
| 472 | 472 | foreach ($r as $regs) { |
| 473 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 473 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 476 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | 477 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 478 | 478 | include_spip('inc/acces'); |
| 479 | 479 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 480 | 480 | } |
| 481 | 481 | foreach ($r as $regs) { |
| 482 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 482 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | if (!empty($options['wrap_suspect'])) { |
| 597 | 597 | $texte = wrap($texte, $options['wrap_suspect']); |
| 598 | 598 | } |
| 599 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 599 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | $texte = $collecteurModeles->retablir($texte); |
@@ -743,11 +743,11 @@ discard block |
||
| 743 | 743 | **/ |
| 744 | 744 | function supprime_img($letexte, $message = null) { |
| 745 | 745 | if ($message === null) { |
| 746 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 746 | + $message = '('._T('img_indisponible').')'; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | return preg_replace( |
| 750 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 750 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 751 | 751 | $message, |
| 752 | 752 | $letexte |
| 753 | 753 | ); |
@@ -83,8 +83,7 @@ discard block |
||
| 83 | 83 | . '</code>' |
| 84 | 84 | . '</pre>' |
| 85 | 85 | . '</div>'; |
| 86 | - } |
|
| 87 | - else { |
|
| 86 | + } else { |
|
| 88 | 87 | $echap = str_replace("\t", ' ', $echap); |
| 89 | 88 | $echap = str_replace(' ', ' ', $echap); |
| 90 | 89 | $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
@@ -608,8 +607,7 @@ discard block |
||
| 608 | 607 | $collecteurLiens = $collecteurModeles = null; |
| 609 | 608 | if (!empty($options['expanser_liens'])) { |
| 610 | 609 | $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
| 611 | - } |
|
| 612 | - else { |
|
| 610 | + } else { |
|
| 613 | 611 | include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
| 614 | 612 | include_spip('src/Texte/Collecteur/Liens'); |
| 615 | 613 | include_spip('src/Texte/Collecteur/Modeles'); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/charsets'); |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | 43 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 44 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | - static $charset_source = 'iso-8859-1'; |
|
| 46 | - if ($definir_charset_source) { |
|
| 47 | - $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | - } |
|
| 49 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | - $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | - return importer_charset($texte, $charset); |
|
| 44 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | + static $charset_source = 'iso-8859-1'; |
|
| 46 | + if ($definir_charset_source) { |
|
| 47 | + $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | + } |
|
| 49 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | + $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | + return importer_charset($texte, $charset); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function importer_csv_nettoie_key($key) { |
| 62 | - return translitteration($key); |
|
| 62 | + return translitteration($key); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -78,70 +78,70 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function inc_importer_csv_dist($file, $options = []) { |
| 80 | 80 | |
| 81 | - // support ancienne syntaxe |
|
| 82 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | - if (!is_array($options)) { |
|
| 84 | - $args = func_get_args(); |
|
| 85 | - $options = []; |
|
| 86 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | - if (!empty($args[$k])) { |
|
| 88 | - $options[$option] = $args[$k]; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 81 | + // support ancienne syntaxe |
|
| 82 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | + if (!is_array($options)) { |
|
| 84 | + $args = func_get_args(); |
|
| 85 | + $options = []; |
|
| 86 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | + if (!empty($args[$k])) { |
|
| 88 | + $options[$option] = $args[$k]; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $default_options = [ |
|
| 94 | - 'head' => false, |
|
| 95 | - 'delim' => ',', |
|
| 96 | - 'enclos' => '"', |
|
| 97 | - 'len' => 10000, |
|
| 98 | - 'charset_source' => '', |
|
| 99 | - ]; |
|
| 100 | - $options = array_merge($default_options, $options); |
|
| 93 | + $default_options = [ |
|
| 94 | + 'head' => false, |
|
| 95 | + 'delim' => ',', |
|
| 96 | + 'enclos' => '"', |
|
| 97 | + 'len' => 10000, |
|
| 98 | + 'charset_source' => '', |
|
| 99 | + ]; |
|
| 100 | + $options = array_merge($default_options, $options); |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - $return = []; |
|
| 104 | - if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | - if ($options['charset_source']) { |
|
| 106 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | - } |
|
| 108 | - if ($options['head']) { |
|
| 109 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | - if ($header) { |
|
| 111 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | - $header_type = []; |
|
| 114 | - foreach ($header as $heading) { |
|
| 115 | - $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 103 | + $return = []; |
|
| 104 | + if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | + if ($options['charset_source']) { |
|
| 106 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | + } |
|
| 108 | + if ($options['head']) { |
|
| 109 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | + if ($header) { |
|
| 111 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | + $header_type = []; |
|
| 114 | + foreach ($header as $heading) { |
|
| 115 | + $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | - if ($options['head'] && isset($header)) { |
|
| 123 | - $row = []; |
|
| 124 | - foreach ($header as $key => $heading) { |
|
| 125 | - if ($header_type[$heading] == 'array') { |
|
| 126 | - if (!isset($row[$heading])) { |
|
| 127 | - $row[$heading] = []; |
|
| 128 | - } |
|
| 129 | - if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | - $row[$heading][] = $data[$key]; |
|
| 131 | - } |
|
| 132 | - } else { |
|
| 133 | - $row[$heading] = $data[$key] ?? ''; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $return[] = $row; |
|
| 137 | - } else { |
|
| 138 | - $return[] = $data; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - if ($options['charset_source']) { |
|
| 142 | - importer_csv_importcharset('', true); |
|
| 143 | - } |
|
| 144 | - } |
|
| 120 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | + if ($options['head'] && isset($header)) { |
|
| 123 | + $row = []; |
|
| 124 | + foreach ($header as $key => $heading) { |
|
| 125 | + if ($header_type[$heading] == 'array') { |
|
| 126 | + if (!isset($row[$heading])) { |
|
| 127 | + $row[$heading] = []; |
|
| 128 | + } |
|
| 129 | + if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | + $row[$heading][] = $data[$key]; |
|
| 131 | + } |
|
| 132 | + } else { |
|
| 133 | + $row[$heading] = $data[$key] ?? ''; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $return[] = $row; |
|
| 137 | + } else { |
|
| 138 | + $return[] = $data; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + if ($options['charset_source']) { |
|
| 142 | + importer_csv_importcharset('', true); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return $return ?: false; |
|
| 146 | + return $return ?: false; |
|
| 147 | 147 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Minipres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 37 | 37 | |
| 38 | - if ($onLoad) { |
|
| 39 | - include_spip('inc/filtres'); |
|
| 40 | - $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 41 | - } |
|
| 38 | + if ($onLoad) { |
|
| 39 | + include_spip('inc/filtres'); |
|
| 40 | + $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $options = [ |
|
| 44 | - 'all_inline' => $all_inline, |
|
| 45 | - 'onload' => $onLoad, |
|
| 46 | - 'titre' => $titre, |
|
| 47 | - ]; |
|
| 43 | + $options = [ |
|
| 44 | + 'all_inline' => $all_inline, |
|
| 45 | + 'onload' => $onLoad, |
|
| 46 | + 'titre' => $titre, |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 50 | - return $minipage->installDebutPage($options); |
|
| 49 | + $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 50 | + return $minipage->installDebutPage($options); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | * @return string Code HTML |
| 60 | 60 | */ |
| 61 | 61 | function install_fin_html() { |
| 62 | - $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 63 | - return $minipage->installFinPage(); |
|
| 62 | + $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 63 | + return $minipage->installFinPage(); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function minipres($titre = '', $corps = '', $options = []) { |
| 101 | 101 | |
| 102 | - // compat signature old |
|
| 103 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 104 | - $args = func_get_args(); |
|
| 105 | - if (isset($args[2]) && is_string($args[2])) { |
|
| 106 | - $options = ['onload' => $args[2]]; |
|
| 107 | - } |
|
| 108 | - if (isset($args[3])) { |
|
| 109 | - $options['all_inline'] = $args[3]; |
|
| 110 | - } |
|
| 102 | + // compat signature old |
|
| 103 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 104 | + $args = func_get_args(); |
|
| 105 | + if (isset($args[2]) && is_string($args[2])) { |
|
| 106 | + $options = ['onload' => $args[2]]; |
|
| 107 | + } |
|
| 108 | + if (isset($args[3])) { |
|
| 109 | + $options['all_inline'] = $args[3]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $options = array_merge([ |
|
| 113 | - 'onload' => '', |
|
| 114 | - 'all_inline' => false, |
|
| 115 | - ], $options); |
|
| 112 | + $options = array_merge([ |
|
| 113 | + 'onload' => '', |
|
| 114 | + 'all_inline' => false, |
|
| 115 | + ], $options); |
|
| 116 | 116 | |
| 117 | - $options['titre'] = $titre; |
|
| 117 | + $options['titre'] = $titre; |
|
| 118 | 118 | |
| 119 | - $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 120 | - return $minipage->page($corps, $options); |
|
| 119 | + $minipage = new Spip\Afficher\Minipage\Admin(); |
|
| 120 | + return $minipage->page($corps, $options); |
|
| 121 | 121 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $_id_table = reset($_id_table); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 69 | + $requete['SELECT'][] = 't.'.$_id_table; |
|
| 70 | 70 | $a = []; |
| 71 | 71 | // Recherche fulltext |
| 72 | 72 | foreach ($champs as $champ => $poids) { |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | $champ = "t.$champ"; |
| 78 | 78 | } |
| 79 | 79 | $requete['SELECT'][] = $champ; |
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 80 | + $a[] = $champ.' '.$methode.' '.$q; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | if ($a) { |
| 84 | 84 | $requete['WHERE'][] = implode(' OR ', $a); |
| 85 | 85 | } |
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table).' AS t'; |
|
| 87 | 87 | |
| 88 | 88 | $results = []; |
| 89 | 89 | |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | ); |
| 245 | 245 | } // cas table de liaison generique spip_xxx_yyy |
| 246 | 246 | elseif ( |
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 247 | + ($t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur)) |
|
| 249 | 249 | ) { |
| 250 | 250 | $s = sql_select( |
| 251 | 251 | "$cle_depart,$cle_arrivee", |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if (isset($joint['champs']) && $joint['champs']) { |
| 286 | 286 | foreach ($joint['champs'] as $c => $val) { |
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 287 | + $results[$id]['champs'][$table_liee.'.'.$c] = $val; |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | if (isset($joint['matches']) && $joint['matches']) { |
| 291 | 291 | foreach ($joint['matches'] as $c => $val) { |
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 292 | + $results[$id]['matches'][$table_liee.'.'.$c] = $val; |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -10,291 +10,291 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | // methodes sql |
| 18 | 18 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 19 | 19 | |
| 20 | - // options par defaut |
|
| 21 | - $options = array_merge( |
|
| 22 | - [ |
|
| 23 | - 'score' => true, |
|
| 24 | - 'champs' => false, |
|
| 25 | - 'toutvoir' => false, |
|
| 26 | - 'matches' => false, |
|
| 27 | - 'jointures' => false |
|
| 28 | - ], |
|
| 29 | - $options |
|
| 30 | - ); |
|
| 20 | + // options par defaut |
|
| 21 | + $options = array_merge( |
|
| 22 | + [ |
|
| 23 | + 'score' => true, |
|
| 24 | + 'champs' => false, |
|
| 25 | + 'toutvoir' => false, |
|
| 26 | + 'matches' => false, |
|
| 27 | + 'jointures' => false |
|
| 28 | + ], |
|
| 29 | + $options |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - include_spip('inc/rechercher'); |
|
| 33 | - include_spip('inc/autoriser'); |
|
| 32 | + include_spip('inc/rechercher'); |
|
| 33 | + include_spip('inc/autoriser'); |
|
| 34 | 34 | |
| 35 | - $requete = [ |
|
| 36 | - 'SELECT' => [], |
|
| 37 | - 'FROM' => [], |
|
| 38 | - 'WHERE' => [], |
|
| 39 | - 'GROUPBY' => [], |
|
| 40 | - 'ORDERBY' => [], |
|
| 41 | - 'LIMIT' => '', |
|
| 42 | - 'HAVING' => [] |
|
| 43 | - ]; |
|
| 35 | + $requete = [ |
|
| 36 | + 'SELECT' => [], |
|
| 37 | + 'FROM' => [], |
|
| 38 | + 'WHERE' => [], |
|
| 39 | + 'GROUPBY' => [], |
|
| 40 | + 'ORDERBY' => [], |
|
| 41 | + 'LIMIT' => '', |
|
| 42 | + 'HAVING' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - $table = sinon($options['table'], 'article'); |
|
| 46 | - if ($options['champs']) { |
|
| 47 | - $champs = $options['champs']; |
|
| 48 | - } else { |
|
| 49 | - $l = liste_des_champs(); |
|
| 50 | - $champs = $l['article']; |
|
| 51 | - } |
|
| 52 | - $serveur = $options['serveur']; |
|
| 45 | + $table = sinon($options['table'], 'article'); |
|
| 46 | + if ($options['champs']) { |
|
| 47 | + $champs = $options['champs']; |
|
| 48 | + } else { |
|
| 49 | + $l = liste_des_champs(); |
|
| 50 | + $champs = $l['article']; |
|
| 51 | + } |
|
| 52 | + $serveur = $options['serveur']; |
|
| 53 | 53 | |
| 54 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 54 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | 55 | |
| 56 | - $jointures = $options['jointures'] |
|
| 57 | - ? liste_des_jointures() |
|
| 58 | - : []; |
|
| 56 | + $jointures = $options['jointures'] |
|
| 57 | + ? liste_des_jointures() |
|
| 58 | + : []; |
|
| 59 | 59 | |
| 60 | - $_id_table = id_table_objet($table); |
|
| 60 | + $_id_table = id_table_objet($table); |
|
| 61 | 61 | |
| 62 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | - if (str_contains((string) $_id_table, ',')) { |
|
| 65 | - $_id_table = explode(',', (string) $_id_table); |
|
| 66 | - $_id_table = reset($_id_table); |
|
| 67 | - } |
|
| 62 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | + if (str_contains((string) $_id_table, ',')) { |
|
| 65 | + $_id_table = explode(',', (string) $_id_table); |
|
| 66 | + $_id_table = reset($_id_table); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | - $a = []; |
|
| 71 | - // Recherche fulltext |
|
| 72 | - foreach ($champs as $champ => $poids) { |
|
| 73 | - if (is_array($champ)) { |
|
| 74 | - spip_log('requetes imbriquees interdites'); |
|
| 75 | - } else { |
|
| 76 | - if (!str_contains((string) $champ, '.')) { |
|
| 77 | - $champ = "t.$champ"; |
|
| 78 | - } |
|
| 79 | - $requete['SELECT'][] = $champ; |
|
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - if ($a) { |
|
| 84 | - $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | - } |
|
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 69 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | + $a = []; |
|
| 71 | + // Recherche fulltext |
|
| 72 | + foreach ($champs as $champ => $poids) { |
|
| 73 | + if (is_array($champ)) { |
|
| 74 | + spip_log('requetes imbriquees interdites'); |
|
| 75 | + } else { |
|
| 76 | + if (!str_contains((string) $champ, '.')) { |
|
| 77 | + $champ = "t.$champ"; |
|
| 78 | + } |
|
| 79 | + $requete['SELECT'][] = $champ; |
|
| 80 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + if ($a) { |
|
| 84 | + $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | + } |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 87 | 87 | |
| 88 | - $results = []; |
|
| 88 | + $results = []; |
|
| 89 | 89 | |
| 90 | - $s = sql_select( |
|
| 91 | - $requete['SELECT'], |
|
| 92 | - $requete['FROM'], |
|
| 93 | - $requete['WHERE'], |
|
| 94 | - implode(' ', $requete['GROUPBY']), |
|
| 95 | - $requete['ORDERBY'], |
|
| 96 | - $requete['LIMIT'], |
|
| 97 | - $requete['HAVING'], |
|
| 98 | - $serveur |
|
| 99 | - ); |
|
| 90 | + $s = sql_select( |
|
| 91 | + $requete['SELECT'], |
|
| 92 | + $requete['FROM'], |
|
| 93 | + $requete['WHERE'], |
|
| 94 | + implode(' ', $requete['GROUPBY']), |
|
| 95 | + $requete['ORDERBY'], |
|
| 96 | + $requete['LIMIT'], |
|
| 97 | + $requete['HAVING'], |
|
| 98 | + $serveur |
|
| 99 | + ); |
|
| 100 | 100 | |
| 101 | - while ( |
|
| 102 | - ($t = sql_fetch($s, $serveur)) |
|
| 103 | - && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | - ) { |
|
| 105 | - $id = (int) $t[$_id_table]; |
|
| 101 | + while ( |
|
| 102 | + ($t = sql_fetch($s, $serveur)) |
|
| 103 | + && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | + ) { |
|
| 105 | + $id = (int) $t[$_id_table]; |
|
| 106 | 106 | |
| 107 | - if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | - // indiquer les champs concernes |
|
| 109 | - $champs_vus = []; |
|
| 110 | - $score = 0; |
|
| 111 | - $matches = []; |
|
| 107 | + if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | + // indiquer les champs concernes |
|
| 109 | + $champs_vus = []; |
|
| 110 | + $score = 0; |
|
| 111 | + $matches = []; |
|
| 112 | 112 | |
| 113 | - $vu = false; |
|
| 114 | - foreach ($champs as $champ => $poids) { |
|
| 115 | - $champ = explode('.', (string) $champ); |
|
| 116 | - $champ = end($champ); |
|
| 117 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | - if ( |
|
| 120 | - $n = |
|
| 121 | - ($options['score'] || $options['matches']) |
|
| 122 | - ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | - : preg_match($preg, (string) $value) |
|
| 124 | - ) { |
|
| 125 | - $vu = true; |
|
| 113 | + $vu = false; |
|
| 114 | + foreach ($champs as $champ => $poids) { |
|
| 115 | + $champ = explode('.', (string) $champ); |
|
| 116 | + $champ = end($champ); |
|
| 117 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | + if ( |
|
| 120 | + $n = |
|
| 121 | + ($options['score'] || $options['matches']) |
|
| 122 | + ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | + : preg_match($preg, (string) $value) |
|
| 124 | + ) { |
|
| 125 | + $vu = true; |
|
| 126 | 126 | |
| 127 | - if ($options['champs']) { |
|
| 128 | - $champs_vus[$champ] = $t[$champ]; |
|
| 129 | - } |
|
| 130 | - if ($options['score']) { |
|
| 131 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | - } |
|
| 127 | + if ($options['champs']) { |
|
| 128 | + $champs_vus[$champ] = $t[$champ]; |
|
| 129 | + } |
|
| 130 | + if ($options['score']) { |
|
| 131 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if ($options['matches']) { |
|
| 136 | - $matches[$champ] = $regs; |
|
| 137 | - } |
|
| 135 | + if ($options['matches']) { |
|
| 136 | + $matches[$champ] = $regs; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | - break; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 139 | + if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | + break; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ($vu) { |
|
| 146 | - if (!isset($results)) { |
|
| 147 | - $results = []; |
|
| 148 | - } |
|
| 149 | - $results[$id] = []; |
|
| 150 | - if ($champs_vus) { |
|
| 151 | - $results[$id]['champs'] = $champs_vus; |
|
| 152 | - } |
|
| 153 | - if ($score) { |
|
| 154 | - $results[$id]['score'] = $score; |
|
| 155 | - } |
|
| 156 | - if ($matches) { |
|
| 157 | - $results[$id]['matches'] = $matches; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 145 | + if ($vu) { |
|
| 146 | + if (!isset($results)) { |
|
| 147 | + $results = []; |
|
| 148 | + } |
|
| 149 | + $results[$id] = []; |
|
| 150 | + if ($champs_vus) { |
|
| 151 | + $results[$id]['champs'] = $champs_vus; |
|
| 152 | + } |
|
| 153 | + if ($score) { |
|
| 154 | + $results[$id]['score'] = $score; |
|
| 155 | + } |
|
| 156 | + if ($matches) { |
|
| 157 | + $results[$id]['matches'] = $matches; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - // Gerer les donnees associees |
|
| 165 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | - // on ne sait passer que par table de laison en 1 coup |
|
| 167 | - if ( |
|
| 168 | - isset($jointures[$table]) |
|
| 169 | - && ($joints = recherche_en_base( |
|
| 170 | - $recherche, |
|
| 171 | - $jointures[$table], |
|
| 172 | - array_merge($options, ['jointures' => false]) |
|
| 173 | - )) |
|
| 174 | - ) { |
|
| 175 | - include_spip('action/editer_liens'); |
|
| 176 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | - $cle_depart = id_table_objet($table); |
|
| 178 | - $table_depart = table_objet($table, $serveur); |
|
| 179 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | - $depart_associable = objet_associable($table); |
|
| 181 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | - if ( |
|
| 184 | - !( |
|
| 185 | - ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | - || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | - || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | - ) |
|
| 189 | - ) { |
|
| 190 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | - // cas simple : $cle_depart dans la table_liee |
|
| 194 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | - $s = sql_select( |
|
| 196 | - "$cle_depart, $cle_arrivee", |
|
| 197 | - $desc_arrivee['table_sql'], |
|
| 198 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | - '', |
|
| 200 | - '', |
|
| 201 | - '', |
|
| 202 | - '', |
|
| 203 | - $serveur |
|
| 204 | - ); |
|
| 205 | - } // cas simple : $cle_arrivee dans la table |
|
| 206 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | - $s = sql_select( |
|
| 208 | - "$cle_depart, $cle_arrivee", |
|
| 209 | - $desc_depart['table_sql'], |
|
| 210 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | - '', |
|
| 212 | - '', |
|
| 213 | - '', |
|
| 214 | - '', |
|
| 215 | - $serveur |
|
| 216 | - ); |
|
| 217 | - } |
|
| 218 | - // sinon cherchons une table de liaison |
|
| 219 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | - elseif ($l = objet_associable($table_liee)) { |
|
| 221 | - [$primary, $table_liens] = $l; |
|
| 222 | - $s = sql_select( |
|
| 223 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | - $table_liens, |
|
| 225 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | - '', |
|
| 227 | - '', |
|
| 228 | - '', |
|
| 229 | - '', |
|
| 230 | - $serveur |
|
| 231 | - ); |
|
| 232 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | - elseif ($l = $depart_associable) { |
|
| 234 | - [$primary, $table_liens] = $l; |
|
| 235 | - $s = sql_select( |
|
| 236 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | - $table_liens, |
|
| 238 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | - '', |
|
| 240 | - '', |
|
| 241 | - '', |
|
| 242 | - '', |
|
| 243 | - $serveur |
|
| 244 | - ); |
|
| 245 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | - elseif ( |
|
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | - ) { |
|
| 250 | - $s = sql_select( |
|
| 251 | - "$cle_depart,$cle_arrivee", |
|
| 252 | - $t['table_sql'], |
|
| 253 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | - '', |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - $serveur |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | - $table, |
|
| 264 | - $table_liee, |
|
| 265 | - array_keys($ids_trouves), |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 164 | + // Gerer les donnees associees |
|
| 165 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | + // on ne sait passer que par table de laison en 1 coup |
|
| 167 | + if ( |
|
| 168 | + isset($jointures[$table]) |
|
| 169 | + && ($joints = recherche_en_base( |
|
| 170 | + $recherche, |
|
| 171 | + $jointures[$table], |
|
| 172 | + array_merge($options, ['jointures' => false]) |
|
| 173 | + )) |
|
| 174 | + ) { |
|
| 175 | + include_spip('action/editer_liens'); |
|
| 176 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | + $cle_depart = id_table_objet($table); |
|
| 178 | + $table_depart = table_objet($table, $serveur); |
|
| 179 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | + $depart_associable = objet_associable($table); |
|
| 181 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | + if ( |
|
| 184 | + !( |
|
| 185 | + ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | + || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | + || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | + ) |
|
| 189 | + ) { |
|
| 190 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | + // cas simple : $cle_depart dans la table_liee |
|
| 194 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | + $s = sql_select( |
|
| 196 | + "$cle_depart, $cle_arrivee", |
|
| 197 | + $desc_arrivee['table_sql'], |
|
| 198 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | + '', |
|
| 200 | + '', |
|
| 201 | + '', |
|
| 202 | + '', |
|
| 203 | + $serveur |
|
| 204 | + ); |
|
| 205 | + } // cas simple : $cle_arrivee dans la table |
|
| 206 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | + $s = sql_select( |
|
| 208 | + "$cle_depart, $cle_arrivee", |
|
| 209 | + $desc_depart['table_sql'], |
|
| 210 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | + '', |
|
| 212 | + '', |
|
| 213 | + '', |
|
| 214 | + '', |
|
| 215 | + $serveur |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | + // sinon cherchons une table de liaison |
|
| 219 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | + elseif ($l = objet_associable($table_liee)) { |
|
| 221 | + [$primary, $table_liens] = $l; |
|
| 222 | + $s = sql_select( |
|
| 223 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | + $table_liens, |
|
| 225 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | + '', |
|
| 227 | + '', |
|
| 228 | + '', |
|
| 229 | + '', |
|
| 230 | + $serveur |
|
| 231 | + ); |
|
| 232 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | + elseif ($l = $depart_associable) { |
|
| 234 | + [$primary, $table_liens] = $l; |
|
| 235 | + $s = sql_select( |
|
| 236 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | + $table_liens, |
|
| 238 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | + '', |
|
| 240 | + '', |
|
| 241 | + '', |
|
| 242 | + '', |
|
| 243 | + $serveur |
|
| 244 | + ); |
|
| 245 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | + elseif ( |
|
| 247 | + ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | + ) { |
|
| 250 | + $s = sql_select( |
|
| 251 | + "$cle_depart,$cle_arrivee", |
|
| 252 | + $t['table_sql'], |
|
| 253 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | + '', |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + $serveur |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | + $table, |
|
| 264 | + $table_liee, |
|
| 265 | + array_keys($ids_trouves), |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | - $id = $t[$cle_depart]; |
|
| 272 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | - if (!isset($results)) { |
|
| 274 | - $results = []; |
|
| 275 | - } |
|
| 276 | - if (!isset($results[$id])) { |
|
| 277 | - $results[$id] = []; |
|
| 278 | - } |
|
| 279 | - if (isset($joint['score']) && $joint['score']) { |
|
| 280 | - if (!isset($results[$id]['score'])) { |
|
| 281 | - $results[$id]['score'] = 0; |
|
| 282 | - } |
|
| 283 | - $results[$id]['score'] += $joint['score']; |
|
| 284 | - } |
|
| 285 | - if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | - foreach ($joint['champs'] as $c => $val) { |
|
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | - foreach ($joint['matches'] as $c => $val) { |
|
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 270 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | + $id = $t[$cle_depart]; |
|
| 272 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | + if (!isset($results)) { |
|
| 274 | + $results = []; |
|
| 275 | + } |
|
| 276 | + if (!isset($results[$id])) { |
|
| 277 | + $results[$id] = []; |
|
| 278 | + } |
|
| 279 | + if (isset($joint['score']) && $joint['score']) { |
|
| 280 | + if (!isset($results[$id]['score'])) { |
|
| 281 | + $results[$id]['score'] = 0; |
|
| 282 | + } |
|
| 283 | + $results[$id]['score'] += $joint['score']; |
|
| 284 | + } |
|
| 285 | + if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | + foreach ($joint['champs'] as $c => $val) { |
|
| 287 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | + foreach ($joint['matches'] as $c => $val) { |
|
| 292 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - return $results; |
|
| 299 | + return $results; |
|
| 300 | 300 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/autoriser'); |
@@ -29,74 +29,74 @@ discard block |
||
| 29 | 29 | * Un tableau des sous rubriques |
| 30 | 30 | */ |
| 31 | 31 | function enfant_rub($collection, $debut = 0, $limite = 500) { |
| 32 | - $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | - $logo = ''; |
|
| 34 | - |
|
| 35 | - if ($voir_logo) { |
|
| 36 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | - include_spip('inc/filtres_images_mini'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $res = []; |
|
| 41 | - |
|
| 42 | - $result = sql_select( |
|
| 43 | - 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | - 'spip_rubriques', |
|
| 45 | - 'id_parent=' . (int) $collection, |
|
| 46 | - '', |
|
| 47 | - '0+titre,titre', |
|
| 48 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | - ); |
|
| 50 | - while ($row = sql_fetch($result)) { |
|
| 51 | - $id_rubrique = $row['id_rubrique']; |
|
| 52 | - $id_parent = $row['id_parent']; |
|
| 53 | - // pour etre sur de passer par tous les traitements |
|
| 54 | - $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | - if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | - $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | - $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | - |
|
| 62 | - changer_typo($row['lang']); |
|
| 63 | - $lang_dir = lang_dir($row['lang']); |
|
| 64 | - $descriptif = propre($row['descriptif']); |
|
| 65 | - |
|
| 66 | - if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | - [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | - $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | - if ($logo) { |
|
| 70 | - $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | - ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | - : '') . |
|
| 77 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | - " href='" . |
|
| 80 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | - "'><span class='titre'>" . |
|
| 82 | - $rang . $titre |
|
| 83 | - . '</span>' |
|
| 84 | - . (is_string($logo) ? $logo : '') |
|
| 85 | - . '</a>'; |
|
| 86 | - |
|
| 87 | - $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | - . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | - ; |
|
| 90 | - |
|
| 91 | - $res[] = |
|
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 94 | - fin_cadre_sous_rub(); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | - return $res; |
|
| 32 | + $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | + $logo = ''; |
|
| 34 | + |
|
| 35 | + if ($voir_logo) { |
|
| 36 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | + include_spip('inc/filtres_images_mini'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $res = []; |
|
| 41 | + |
|
| 42 | + $result = sql_select( |
|
| 43 | + 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | + 'spip_rubriques', |
|
| 45 | + 'id_parent=' . (int) $collection, |
|
| 46 | + '', |
|
| 47 | + '0+titre,titre', |
|
| 48 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | + ); |
|
| 50 | + while ($row = sql_fetch($result)) { |
|
| 51 | + $id_rubrique = $row['id_rubrique']; |
|
| 52 | + $id_parent = $row['id_parent']; |
|
| 53 | + // pour etre sur de passer par tous les traitements |
|
| 54 | + $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | + if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | + $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | + $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | + |
|
| 62 | + changer_typo($row['lang']); |
|
| 63 | + $lang_dir = lang_dir($row['lang']); |
|
| 64 | + $descriptif = propre($row['descriptif']); |
|
| 65 | + |
|
| 66 | + if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | + [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | + $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | + if ($logo) { |
|
| 70 | + $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | + ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | + : '') . |
|
| 77 | + " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | + " href='" . |
|
| 80 | + generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | + "'><span class='titre'>" . |
|
| 82 | + $rang . $titre |
|
| 83 | + . '</span>' |
|
| 84 | + . (is_string($logo) ? $logo : '') |
|
| 85 | + . '</a>'; |
|
| 86 | + |
|
| 87 | + $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | + . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | + ; |
|
| 90 | + |
|
| 91 | + $res[] = |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | + $les_sous_enfants . |
|
| 94 | + fin_cadre_sous_rub(); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,71 +109,71 @@ discard block |
||
| 109 | 109 | * Le contenu du bloc dépliable |
| 110 | 110 | */ |
| 111 | 111 | function sous_enfant_rub($collection2) { |
| 112 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | - |
|
| 114 | - $retour = ''; |
|
| 115 | - $pagination = ''; |
|
| 116 | - $debut = 0; |
|
| 117 | - $limite = 500; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * On ne va afficher que 500 résultats max |
|
| 121 | - * Si > 500 on affiche une pagination |
|
| 122 | - */ |
|
| 123 | - if ($nb > $limite) { |
|
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | - $pagination = chercher_filtre('pagination'); |
|
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | - $nb, |
|
| 128 | - '_rubrique' . $collection2, |
|
| 129 | - $debut, |
|
| 130 | - $limite, |
|
| 131 | - true, |
|
| 132 | - 'prive' |
|
| 133 | - ) . '</nav>'; |
|
| 134 | - $limite = $debut + $limite; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $result = sql_select( |
|
| 138 | - 'id_rubrique, id_parent, titre, lang', |
|
| 139 | - 'spip_rubriques', |
|
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 141 | - '', |
|
| 142 | - '0+titre,titre', |
|
| 143 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - while ($row = sql_fetch($result)) { |
|
| 147 | - $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | - $titre2 = generer_objet_info( |
|
| 149 | - $id_rubrique2, |
|
| 150 | - 'rubrique', |
|
| 151 | - 'titre' |
|
| 152 | - ); // pour etre sur de passer par tous les traitements |
|
| 153 | - if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | - $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - changer_typo($row['lang']); |
|
| 158 | - $lang_dir = lang_dir($row['lang']); |
|
| 159 | - if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | - $id_rubrique2, |
|
| 162 | - 'rubrique' |
|
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 168 | - |
|
| 169 | - if (!$retour) { |
|
| 170 | - return ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | - . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | - . $retour |
|
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | + |
|
| 114 | + $retour = ''; |
|
| 115 | + $pagination = ''; |
|
| 116 | + $debut = 0; |
|
| 117 | + $limite = 500; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * On ne va afficher que 500 résultats max |
|
| 121 | + * Si > 500 on affiche une pagination |
|
| 122 | + */ |
|
| 123 | + if ($nb > $limite) { |
|
| 124 | + $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | + $pagination = chercher_filtre('pagination'); |
|
| 126 | + $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | + $nb, |
|
| 128 | + '_rubrique' . $collection2, |
|
| 129 | + $debut, |
|
| 130 | + $limite, |
|
| 131 | + true, |
|
| 132 | + 'prive' |
|
| 133 | + ) . '</nav>'; |
|
| 134 | + $limite = $debut + $limite; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $result = sql_select( |
|
| 138 | + 'id_rubrique, id_parent, titre, lang', |
|
| 139 | + 'spip_rubriques', |
|
| 140 | + 'id_parent=' . (int) $collection2, |
|
| 141 | + '', |
|
| 142 | + '0+titre,titre', |
|
| 143 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + while ($row = sql_fetch($result)) { |
|
| 147 | + $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | + $titre2 = generer_objet_info( |
|
| 149 | + $id_rubrique2, |
|
| 150 | + 'rubrique', |
|
| 151 | + 'titre' |
|
| 152 | + ); // pour etre sur de passer par tous les traitements |
|
| 153 | + if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | + $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + changer_typo($row['lang']); |
|
| 158 | + $lang_dir = lang_dir($row['lang']); |
|
| 159 | + if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | + $id_rubrique2, |
|
| 162 | + 'rubrique' |
|
| 163 | + ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $retour = $pagination . $retour . $pagination; |
|
| 168 | + |
|
| 169 | + if (!$retour) { |
|
| 170 | + return ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | + . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | + . $retour |
|
| 176 | + . "</ul>\n" . fin_block() . "\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,41 +188,41 @@ discard block |
||
| 188 | 188 | * Le contenu textuel affiché, la liste des sous rubriques |
| 189 | 189 | */ |
| 190 | 190 | function afficher_enfant_rub($id_rubrique = 0) { |
| 191 | - $pagination = ''; |
|
| 192 | - $debut = 0; |
|
| 193 | - $limite = 500; |
|
| 194 | - |
|
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | - |
|
| 197 | - if ($nb > $limite) { |
|
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | - $pagination = chercher_filtre('pagination'); |
|
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | - '</nav>'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | - |
|
| 207 | - if (!$n = count($les_enfants)) { |
|
| 208 | - return ''; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ($n == 1) { |
|
| 212 | - $les_enfants = reset($les_enfants); |
|
| 213 | - $les_enfants2 = ''; |
|
| 214 | - } else { |
|
| 215 | - $n = ceil($n / 2); |
|
| 216 | - $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | - $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $pagination |
|
| 221 | - . "<div class='gauche'>" |
|
| 222 | - . $les_enfants |
|
| 223 | - . '</div>' |
|
| 224 | - . "<div class='droite'>" |
|
| 225 | - . $les_enfants2 |
|
| 226 | - . '</div>' |
|
| 227 | - . $pagination; |
|
| 191 | + $pagination = ''; |
|
| 192 | + $debut = 0; |
|
| 193 | + $limite = 500; |
|
| 194 | + |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | + |
|
| 197 | + if ($nb > $limite) { |
|
| 198 | + $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | + $pagination = chercher_filtre('pagination'); |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | + $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | + '</nav>'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | + |
|
| 207 | + if (!$n = count($les_enfants)) { |
|
| 208 | + return ''; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ($n == 1) { |
|
| 212 | + $les_enfants = reset($les_enfants); |
|
| 213 | + $les_enfants2 = ''; |
|
| 214 | + } else { |
|
| 215 | + $n = ceil($n / 2); |
|
| 216 | + $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | + $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $pagination |
|
| 221 | + . "<div class='gauche'>" |
|
| 222 | + . $les_enfants |
|
| 223 | + . '</div>' |
|
| 224 | + . "<div class='droite'>" |
|
| 225 | + . $les_enfants2 |
|
| 226 | + . '</div>' |
|
| 227 | + . $pagination; |
|
| 228 | 228 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $result = sql_select( |
| 43 | 43 | 'id_rubrique, id_parent, titre, descriptif, lang', |
| 44 | 44 | 'spip_rubriques', |
| 45 | - 'id_parent=' . (int) $collection, |
|
| 45 | + 'id_parent='.(int) $collection, |
|
| 46 | 46 | '', |
| 47 | 47 | '0+titre,titre', |
| 48 | 48 | $debut == -1 ? '' : "$debut,$limite" |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
| 75 | 75 | ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
| 76 | - : '') . |
|
| 77 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | - " href='" . |
|
| 80 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | - "'><span class='titre'>" . |
|
| 82 | - $rang . $titre |
|
| 76 | + : ''). |
|
| 77 | + " <a class='titremlien' dir='$lang_dir'". |
|
| 78 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='".$row['lang']."'" : ''). |
|
| 79 | + " href='". |
|
| 80 | + generer_objet_url($id_rubrique, 'rubrique'). |
|
| 81 | + "'><span class='titre'>". |
|
| 82 | + $rang.$titre |
|
| 83 | 83 | . '</span>' |
| 84 | 84 | . (is_string($logo) ? $logo : '') |
| 85 | 85 | . '</a>'; |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | ; |
| 90 | 90 | |
| 91 | 91 | $res[] = |
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre). |
|
| 93 | + $les_sous_enfants. |
|
| 94 | 94 | fin_cadre_sous_rub(); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * Le contenu du bloc dépliable |
| 110 | 110 | */ |
| 111 | 111 | function sous_enfant_rub($collection2) { |
| 112 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $collection2); |
|
| 113 | 113 | |
| 114 | 114 | $retour = ''; |
| 115 | 115 | $pagination = ''; |
@@ -121,23 +121,23 @@ discard block |
||
| 121 | 121 | * Si > 500 on affiche une pagination |
| 122 | 122 | */ |
| 123 | 123 | if ($nb > $limite) { |
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 124 | + $debut = _request('debut_rubrique'.$collection2) ?: $debut; |
|
| 125 | 125 | $pagination = chercher_filtre('pagination'); |
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 126 | + $pagination = '<nav class="pagination">'.$pagination( |
|
| 127 | 127 | $nb, |
| 128 | - '_rubrique' . $collection2, |
|
| 128 | + '_rubrique'.$collection2, |
|
| 129 | 129 | $debut, |
| 130 | 130 | $limite, |
| 131 | 131 | true, |
| 132 | 132 | 'prive' |
| 133 | - ) . '</nav>'; |
|
| 133 | + ).'</nav>'; |
|
| 134 | 134 | $limite = $debut + $limite; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $result = sql_select( |
| 138 | 138 | 'id_rubrique, id_parent, titre, lang', |
| 139 | 139 | 'spip_rubriques', |
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 140 | + 'id_parent='.(int) $collection2, |
|
| 141 | 141 | '', |
| 142 | 142 | '0+titre,titre', |
| 143 | 143 | $debut == -1 ? '' : "$debut,$limite" |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | changer_typo($row['lang']); |
| 158 | 158 | $lang_dir = lang_dir($row['lang']); |
| 159 | 159 | if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_objet_url( |
|
| 161 | 161 | $id_rubrique2, |
| 162 | 162 | 'rubrique' |
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 163 | + )."'>".$rang2.$titre2."</a></li>\n"; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 167 | + $retour = $pagination.$retour.$pagination; |
|
| 168 | 168 | |
| 169 | 169 | if (!$retour) { |
| 170 | 170 | return ''; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return debut_block_depliable($debut > 0, "enfants$collection2") |
| 174 | 174 | . "\n<ul class='liste-items sous-sous-rub'>\n" |
| 175 | 175 | . $retour |
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 176 | + . "</ul>\n".fin_block()."\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | $debut = 0; |
| 193 | 193 | $limite = 500; |
| 194 | 194 | |
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $id_rubrique); |
|
| 196 | 196 | |
| 197 | 197 | if ($nb > $limite) { |
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 198 | + $debut = _request('debut_rubrique'.$id_rubrique) ?: $debut; |
|
| 199 | 199 | $pagination = chercher_filtre('pagination'); |
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">'. |
|
| 201 | + $pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive'). |
|
| 202 | 202 | '</nav>'; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | if (!defined('_AUTO_SELECTION_RUBRIQUE')) { |
| 16 | - define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 16 | + define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -27,39 +27,39 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) { |
| 30 | - if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | - return ''; |
|
| 32 | - } |
|
| 30 | + if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if (!isset($row['id_rubrique'])) { |
|
| 35 | - return ''; |
|
| 36 | - } |
|
| 34 | + if (!isset($row['id_rubrique'])) { |
|
| 35 | + return ''; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $id_rubrique = ''; |
|
| 39 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | - // si admin restreint : sa rubrique |
|
| 41 | - $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | - } elseif ( |
|
| 43 | - is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | - ) { |
|
| 46 | - $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | - } else { |
|
| 48 | - // sinon la derniere rubrique cree |
|
| 49 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | - } |
|
| 52 | - // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | - $id_rubrique = ''; |
|
| 55 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | - while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 38 | + $id_rubrique = ''; |
|
| 39 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | + // si admin restreint : sa rubrique |
|
| 41 | + $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | + } elseif ( |
|
| 43 | + is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | + ) { |
|
| 46 | + $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | + } else { |
|
| 48 | + // sinon la derniere rubrique cree |
|
| 49 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | + } |
|
| 52 | + // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | + if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | + $id_rubrique = ''; |
|
| 55 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | + while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | + if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $id_rubrique; |
|
| 64 | + return $id_rubrique; |
|
| 65 | 65 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
| 42 | 42 | } elseif ( |
| 43 | 43 | is_int(_AUTO_SELECTION_RUBRIQUE) |
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.(int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | 45 | ) { |
| 46 | 46 | $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
| 47 | 47 | } else { |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | $id_rubrique = $row_rub['id_rubrique']; |
| 51 | 51 | } |
| 52 | 52 | // si le choix ne convient pas, on cherche dans un secteur |
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 53 | + if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | 54 | $id_rubrique = ''; |
| 55 | 55 | // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
| 56 | 56 | $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
| 57 | 57 | while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 58 | + if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | 59 | $id_rubrique = $row_rub['id_rubrique']; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | include_spip('inc/acces'); |
@@ -101,93 +101,93 @@ discard block |
||
| 101 | 101 | * @return int|bool Timestamp du verrou, false si erreur |
| 102 | 102 | */ |
| 103 | 103 | function spip_nfslock($fichier, $max_age = 0) { |
| 104 | - $tries = 0; |
|
| 104 | + $tries = 0; |
|
| 105 | 105 | |
| 106 | - if (!$max_age) { |
|
| 107 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | - } |
|
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 106 | + if (!$max_age) { |
|
| 107 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | + } |
|
| 109 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * 1. create a tmp file with a psuedo random file name. we also make |
| 114 | 114 | * tpath which is a buffer to store the full pathname of the tmp file. |
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | - $id = creer_uniqid(); |
|
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | - $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | - if (!$tmpfd) { /* open failed */ |
|
| 121 | - @fclose($tmpfd); |
|
| 122 | - spip_unlink($tpath); |
|
| 117 | + $id = creer_uniqid(); |
|
| 118 | + $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | + $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | + if (!$tmpfd) { /* open failed */ |
|
| 121 | + @fclose($tmpfd); |
|
| 122 | + spip_unlink($tpath); |
|
| 123 | 123 | |
| 124 | - return false; //NFSL_SYSF |
|
| 125 | - } |
|
| 124 | + return false; //NFSL_SYSF |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /* |
|
| 127 | + /* |
|
| 128 | 128 | * 2. make fullpath, a buffer for the full pathname of the lock file. |
| 129 | 129 | * then start looping trying to lock it |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - while ($tries < 10) { |
|
| 133 | - /* |
|
| 132 | + while ($tries < 10) { |
|
| 133 | + /* |
|
| 134 | 134 | * 3. link tmp file to lock file. if it goes, we win and we clean |
| 135 | 135 | * up and return the st_ctime of the lock file. |
| 136 | 136 | */ |
| 137 | 137 | |
| 138 | - if (link($tpath, $lock_file) == 1) { |
|
| 139 | - spip_unlink($tpath); /* got it! */ |
|
| 140 | - @fclose($tmpfd); |
|
| 141 | - if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | - spip_unlink($lock_file); |
|
| 138 | + if (link($tpath, $lock_file) == 1) { |
|
| 139 | + spip_unlink($tpath); /* got it! */ |
|
| 140 | + @fclose($tmpfd); |
|
| 141 | + if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | + spip_unlink($lock_file); |
|
| 143 | 143 | |
| 144 | - return false; // (NFSL_SYSF); |
|
| 145 | - } |
|
| 144 | + return false; // (NFSL_SYSF); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return ($our_tmp['ctime']); |
|
| 148 | - } |
|
| 147 | + return ($our_tmp['ctime']); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /* |
|
| 150 | + /* |
|
| 151 | 151 | * 4. the lock failed. check for a stale lock file, being mindful |
| 152 | 152 | * of NFS and the fact the time is set from the NFS server. we |
| 153 | 153 | * do a write on the tmp file to update its time to the server's |
| 154 | 154 | * idea of "now." |
| 155 | 155 | */ |
| 156 | 156 | |
| 157 | - $old_stat = lstat($lock_file); |
|
| 158 | - if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | - break; |
|
| 160 | - } /* something bogus is going on */ |
|
| 157 | + $old_stat = lstat($lock_file); |
|
| 158 | + if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | + break; |
|
| 160 | + } /* something bogus is going on */ |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | - spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | - $tries++; |
|
| 166 | - /* It is CRITICAL that we sleep after breaking |
|
| 163 | + if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | + spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | + $tries++; |
|
| 166 | + /* It is CRITICAL that we sleep after breaking |
|
| 167 | 167 | * the lock. Otherwise, we could race with |
| 168 | 168 | * another process and unlink it's newly- |
| 169 | 169 | * created file. |
| 170 | 170 | */ |
| 171 | - sleep(1 + random_int(0, 4)); |
|
| 172 | - continue; |
|
| 173 | - } |
|
| 171 | + sleep(1 + random_int(0, 4)); |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /* |
|
| 175 | + /* |
|
| 176 | 176 | * 5. try again |
| 177 | 177 | */ |
| 178 | 178 | |
| 179 | - $tries++; |
|
| 180 | - sleep(1 + random_int(0, 4)); |
|
| 181 | - } |
|
| 179 | + $tries++; |
|
| 180 | + sleep(1 + random_int(0, 4)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /* |
|
| 183 | + /* |
|
| 184 | 184 | * 6. give up, failure. |
| 185 | 185 | */ |
| 186 | 186 | |
| 187 | - spip_unlink($tpath); |
|
| 188 | - @fclose($tmpfd); |
|
| 187 | + spip_unlink($tpath); |
|
| 188 | + @fclose($tmpfd); |
|
| 189 | 189 | |
| 190 | - return false; //(NFSL_LOCKED); |
|
| 190 | + return false; //(NFSL_LOCKED); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -231,71 +231,71 @@ discard block |
||
| 231 | 231 | * return bool true si déverrouillé, false sinon |
| 232 | 232 | */ |
| 233 | 233 | function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) { |
| 234 | - $id = creer_uniqid(); |
|
| 235 | - if (!$max_age) { |
|
| 236 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | - } |
|
| 234 | + $id = creer_uniqid(); |
|
| 235 | + if (!$max_age) { |
|
| 236 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /* |
|
| 239 | + /* |
|
| 240 | 240 | * 1. Build a temp file and stat that to get an idea of what the server |
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | - $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | - if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | - /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | - @fclose($tmpfd); |
|
| 249 | - spip_unlink($tpath); |
|
| 244 | + $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | + $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | + if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | + /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | + @fclose($tmpfd); |
|
| 249 | + spip_unlink($tpath); |
|
| 250 | 250 | |
| 251 | - return false; //(NFSL_SYSF); |
|
| 252 | - } |
|
| 251 | + return false; //(NFSL_SYSF); |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | - spip_unlink($tpath); |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | + spip_unlink($tpath); |
|
| 256 | 256 | |
| 257 | - /* |
|
| 257 | + /* |
|
| 258 | 258 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 259 | 259 | */ |
| 260 | 260 | |
| 261 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 261 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 262 | 262 | |
| 263 | - /* |
|
| 263 | + /* |
|
| 264 | 264 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
| 265 | 265 | * lock has expired, sleep the usual random interval before returning. |
| 266 | 266 | * If we didn't sleep, there could be a race if the caller immediately |
| 267 | 267 | * tries to relock the file. |
| 268 | 268 | */ |
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | - && ($old_stat['ctime'] == $birth) |
|
| 273 | - ) { /* hasn't been modified since birth */ |
|
| 274 | - if (!$test) { |
|
| 275 | - spip_unlink($lock_file); |
|
| 276 | - } /* so the lock is ours to remove */ |
|
| 277 | - if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | - if (!$test) { |
|
| 279 | - return false; |
|
| 280 | - } //(NFSL_LOST); |
|
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /* |
|
| 270 | + if ( |
|
| 271 | + ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | + && ($old_stat['ctime'] == $birth) |
|
| 273 | + ) { /* hasn't been modified since birth */ |
|
| 274 | + if (!$test) { |
|
| 275 | + spip_unlink($lock_file); |
|
| 276 | + } /* so the lock is ours to remove */ |
|
| 277 | + if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | + if (!$test) { |
|
| 279 | + return false; |
|
| 280 | + } //(NFSL_LOST); |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return true;//(NFSL_OK); /* success */ |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /* |
|
| 288 | 288 | * 4. Either ctime has been modified, or the entire lock file is missing. |
| 289 | 289 | * If the lock should still be ours, based on the ctime of the temp |
| 290 | 290 | * file, return with NFSL_STOLEN. If not, then our lock is expired and |
| 291 | 291 | * someone else has grabbed the file, so return NFSL_LOST. |
| 292 | 292 | */ |
| 293 | 293 | |
| 294 | - if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | - return false; |
|
| 296 | - } //(NFSL_STOLEN); |
|
| 294 | + if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | + return false; |
|
| 296 | + } //(NFSL_STOLEN); |
|
| 297 | 297 | |
| 298 | - return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 298 | + return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -319,5 +319,5 @@ discard block |
||
| 319 | 319 | * return bool true si déverrouillé, false sinon |
| 320 | 320 | */ |
| 321 | 321 | function spip_nfslock_test($fichier, $birth, $max_age = 0) { |
| 322 | - return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 322 | + return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 323 | 323 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if (!$max_age) { |
| 107 | 107 | $max_age = _DEFAULT_LOCKTIME; |
| 108 | 108 | } |
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 109 | + $lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | /* |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | 117 | $id = creer_uniqid(); |
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 118 | + $tpath = _DIR_TMP."slock.$id"; |
|
| 119 | 119 | $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
| 120 | 120 | if (!$tmpfd) { /* open failed */ |
| 121 | 121 | @fclose($tmpfd); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 244 | + $tpath = _DIR_TMP."stime.$id"; |
|
| 245 | 245 | $tmpfd = @fopen($tpath, 'w'); |
| 246 | 246 | if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
| 247 | 247 | /* The open failed, or we can't write the file, or we can't stat it */ |
@@ -251,14 +251,14 @@ discard block |
||
| 251 | 251 | return false; //(NFSL_SYSF); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | 255 | spip_unlink($tpath); |
| 256 | 256 | |
| 257 | 257 | /* |
| 258 | 258 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 259 | 259 | */ |
| 260 | 260 | |
| 261 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 261 | + $lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8); |
|
| 262 | 262 | |
| 263 | 263 | /* |
| 264 | 264 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | if (!$test) { |
| 279 | 279 | return false; |
| 280 | 280 | } //(NFSL_LOST); |
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 284 | + return true; //(NFSL_OK); /* success */ |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /* |
@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 24 | - /** |
|
| 25 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | - * |
|
| 27 | - * Peut ralentir un site sur des listes très longues. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - **/ |
|
| 31 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 24 | + /** |
|
| 25 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | + * |
|
| 27 | + * Peut ralentir un site sur des listes très longues. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + **/ |
|
| 31 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -56,31 +56,31 @@ discard block |
||
| 56 | 56 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 57 | 57 | */ |
| 58 | 58 | function inc_puce_statut_dist( |
| 59 | - $id_objet, |
|
| 60 | - $statut, |
|
| 61 | - $id_parent, |
|
| 62 | - $type, |
|
| 63 | - $ajax = false, |
|
| 64 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 59 | + $id_objet, |
|
| 60 | + $statut, |
|
| 61 | + $id_parent, |
|
| 62 | + $type, |
|
| 63 | + $ajax = false, |
|
| 64 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 65 | 65 | ) { |
| 66 | - static $f_puce_statut = []; |
|
| 67 | - $type = objet_type($type); |
|
| 68 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | - if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | - } |
|
| 72 | - if ($f_puce_statut[$type]) { |
|
| 73 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | - // composer une puce, avec si possible changement rapide |
|
| 78 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | - return $puce; |
|
| 80 | - } // sinon fausse puce avec le type de l'image |
|
| 81 | - else { |
|
| 82 | - return http_img_pack("$type-16.png", ''); |
|
| 83 | - } |
|
| 66 | + static $f_puce_statut = []; |
|
| 67 | + $type = objet_type($type); |
|
| 68 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | + if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | + } |
|
| 72 | + if ($f_puce_statut[$type]) { |
|
| 73 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | + // composer une puce, avec si possible changement rapide |
|
| 78 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | + return $puce; |
|
| 80 | + } // sinon fausse puce avec le type de l'image |
|
| 81 | + else { |
|
| 82 | + return http_img_pack("$type-16.png", ''); |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -109,41 +109,41 @@ discard block |
||
| 109 | 109 | * null si pas capable de déterminer l'image |
| 110 | 110 | */ |
| 111 | 111 | function statut_image($objet, $statut) { |
| 112 | - $src = null; |
|
| 113 | - $table = table_objet_sql($objet); |
|
| 114 | - $desc = lister_tables_objets_sql($table); |
|
| 115 | - if (isset($desc['statut_images'])) { |
|
| 116 | - // si une declaration statut_images |
|
| 117 | - // mais rien pour le statut demande, ne rien afficher |
|
| 118 | - $src = ''; |
|
| 119 | - if (isset($desc['statut_images'][$statut])) { |
|
| 120 | - $src = $desc['statut_images'][$statut]; |
|
| 121 | - } // sinon image par defaut ? |
|
| 122 | - elseif (isset($desc['statut_images'][0])) { |
|
| 123 | - $src = $desc['statut_images'][0]; |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - switch ($statut) { |
|
| 127 | - case 'prepa': |
|
| 128 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | - break; |
|
| 130 | - case 'prop': |
|
| 131 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | - break; |
|
| 133 | - case 'publie': |
|
| 134 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | - break; |
|
| 136 | - case 'refuse': |
|
| 137 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | - break; |
|
| 139 | - case 'poubelle': |
|
| 140 | - case 'poub': |
|
| 141 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $src; |
|
| 112 | + $src = null; |
|
| 113 | + $table = table_objet_sql($objet); |
|
| 114 | + $desc = lister_tables_objets_sql($table); |
|
| 115 | + if (isset($desc['statut_images'])) { |
|
| 116 | + // si une declaration statut_images |
|
| 117 | + // mais rien pour le statut demande, ne rien afficher |
|
| 118 | + $src = ''; |
|
| 119 | + if (isset($desc['statut_images'][$statut])) { |
|
| 120 | + $src = $desc['statut_images'][$statut]; |
|
| 121 | + } // sinon image par defaut ? |
|
| 122 | + elseif (isset($desc['statut_images'][0])) { |
|
| 123 | + $src = $desc['statut_images'][0]; |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + switch ($statut) { |
|
| 127 | + case 'prepa': |
|
| 128 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | + break; |
|
| 130 | + case 'prop': |
|
| 131 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | + break; |
|
| 133 | + case 'publie': |
|
| 134 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | + break; |
|
| 136 | + case 'refuse': |
|
| 137 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | + break; |
|
| 139 | + case 'poubelle': |
|
| 140 | + case 'poub': |
|
| 141 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $src; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | 173 | function statut_titre($objet, $statut) { |
| 174 | - $titre = ''; |
|
| 175 | - $table = table_objet_sql($objet); |
|
| 176 | - $desc = lister_tables_objets_sql($table); |
|
| 177 | - if (isset($desc['statut_titres'])) { |
|
| 178 | - // si une declaration statut_titres |
|
| 179 | - // mais rien pour le statut demande, ne rien afficher |
|
| 180 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | - $titre = $desc['statut_titres'][$statut]; |
|
| 182 | - } // sinon image par defaut ? |
|
| 183 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | - $titre = $desc['statut_titres'][0]; |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - switch ($statut) { |
|
| 188 | - case 'prepa': |
|
| 189 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | - break; |
|
| 191 | - case 'prop': |
|
| 192 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | - break; |
|
| 194 | - case 'publie': |
|
| 195 | - $titre = 'texte_statut_publie'; |
|
| 196 | - break; |
|
| 197 | - case 'refuse': |
|
| 198 | - $titre = 'texte_statut_refuse'; |
|
| 199 | - break; |
|
| 200 | - case 'poubelle': |
|
| 201 | - case 'poub': |
|
| 202 | - $titre = 'texte_statut_poubelle'; |
|
| 203 | - break; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $titre ? _T($titre) : ''; |
|
| 174 | + $titre = ''; |
|
| 175 | + $table = table_objet_sql($objet); |
|
| 176 | + $desc = lister_tables_objets_sql($table); |
|
| 177 | + if (isset($desc['statut_titres'])) { |
|
| 178 | + // si une declaration statut_titres |
|
| 179 | + // mais rien pour le statut demande, ne rien afficher |
|
| 180 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | + $titre = $desc['statut_titres'][$statut]; |
|
| 182 | + } // sinon image par defaut ? |
|
| 183 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | + $titre = $desc['statut_titres'][0]; |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + switch ($statut) { |
|
| 188 | + case 'prepa': |
|
| 189 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | + break; |
|
| 191 | + case 'prop': |
|
| 192 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | + break; |
|
| 194 | + case 'publie': |
|
| 195 | + $titre = 'texte_statut_publie'; |
|
| 196 | + break; |
|
| 197 | + case 'refuse': |
|
| 198 | + $titre = 'texte_statut_refuse'; |
|
| 199 | + break; |
|
| 200 | + case 'poubelle': |
|
| 201 | + case 'poub': |
|
| 202 | + $titre = 'texte_statut_poubelle'; |
|
| 203 | + break; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $titre ? _T($titre) : ''; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -224,37 +224,37 @@ discard block |
||
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | 226 | function statut_texte_instituer($objet, $statut) { |
| 227 | - $texte = ''; |
|
| 228 | - $table = table_objet_sql($objet); |
|
| 229 | - $desc = lister_tables_objets_sql($table); |
|
| 230 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | - // si une declaration statut_titres |
|
| 232 | - // mais rien pour le statut demande, ne rien afficher |
|
| 233 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | - } |
|
| 236 | - } else { |
|
| 237 | - switch ($statut) { |
|
| 238 | - case 'prepa': |
|
| 239 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | - break; |
|
| 241 | - case 'prop': |
|
| 242 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | - break; |
|
| 244 | - case 'publie': |
|
| 245 | - $texte = 'texte_statut_publie'; |
|
| 246 | - break; |
|
| 247 | - case 'refuse': |
|
| 248 | - $texte = 'texte_statut_refuse'; |
|
| 249 | - break; |
|
| 250 | - case 'poubelle': |
|
| 251 | - case 'poub': |
|
| 252 | - $texte = 'texte_statut_poubelle'; |
|
| 253 | - break; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $texte ? _T($texte) : ''; |
|
| 227 | + $texte = ''; |
|
| 228 | + $table = table_objet_sql($objet); |
|
| 229 | + $desc = lister_tables_objets_sql($table); |
|
| 230 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | + // si une declaration statut_titres |
|
| 232 | + // mais rien pour le statut demande, ne rien afficher |
|
| 233 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + switch ($statut) { |
|
| 238 | + case 'prepa': |
|
| 239 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | + break; |
|
| 241 | + case 'prop': |
|
| 242 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | + break; |
|
| 244 | + case 'publie': |
|
| 245 | + $texte = 'texte_statut_publie'; |
|
| 246 | + break; |
|
| 247 | + case 'refuse': |
|
| 248 | + $texte = 'texte_statut_refuse'; |
|
| 249 | + break; |
|
| 250 | + case 'poubelle': |
|
| 251 | + case 'poub': |
|
| 252 | + $texte = 'texte_statut_poubelle'; |
|
| 253 | + break; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $texte ? _T($texte) : ''; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | 276 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 277 | - $img = statut_image('auteur', $statut); |
|
| 278 | - if (!$img) { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - $alt = statut_titre('auteur', $statut); |
|
| 277 | + $img = statut_image('auteur', $statut); |
|
| 278 | + if (!$img) { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + $alt = statut_titre('auteur', $statut); |
|
| 282 | 282 | |
| 283 | - $fond = ''; |
|
| 284 | - $titre = ''; |
|
| 283 | + $fond = ''; |
|
| 284 | + $titre = ''; |
|
| 285 | 285 | |
| 286 | - /* |
|
| 286 | + /* |
|
| 287 | 287 | if ($type != 'auteur') { |
| 288 | 288 | $img2 = chemin_image('del-16.png'); |
| 289 | 289 | $titre = _T('titre_image_redacteur'); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | */ |
| 295 | 295 | |
| 296 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 296 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 301 | - return http_img_pack('rubrique-16.png', ''); |
|
| 301 | + return http_img_pack('rubrique-16.png', ''); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -322,101 +322,101 @@ discard block |
||
| 322 | 322 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 323 | 323 | **/ |
| 324 | 324 | function puce_statut_changement_rapide( |
| 325 | - $id, |
|
| 326 | - $statut, |
|
| 327 | - $id_rubrique, |
|
| 328 | - $type = 'article', |
|
| 329 | - $ajax = false, |
|
| 330 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 325 | + $id, |
|
| 326 | + $statut, |
|
| 327 | + $id_rubrique, |
|
| 328 | + $type = 'article', |
|
| 329 | + $ajax = false, |
|
| 330 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 331 | 331 | ) { |
| 332 | - $src = statut_image($type, $statut); |
|
| 333 | - if (!$src) { |
|
| 334 | - return $src; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - $t = statut_titre($type, $statut); |
|
| 341 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | - |
|
| 343 | - if (!$ajax_node) { |
|
| 344 | - return $inser_puce; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $table = table_objet_sql($type); |
|
| 348 | - $desc = lister_tables_objets_sql($table); |
|
| 349 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | - return $inser_puce; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!function_exists('autoriser')) { |
|
| 354 | - include_spip('inc/autoriser'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | - if ($id_rubrique) { |
|
| 359 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | - return $inser_puce; |
|
| 361 | - } |
|
| 362 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | - else { |
|
| 364 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | - return $inser_puce; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | - if (!isset($coord[$statut])) { |
|
| 371 | - return $inser_puce; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | - ; |
|
| 376 | - $margin = 0; /* marge a gauche + droite */ |
|
| 377 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | - ; |
|
| 379 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | - |
|
| 381 | - if ($ajax) { |
|
| 382 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | - . $inser_puce |
|
| 385 | - . '</span>' |
|
| 386 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | - $i = 0; |
|
| 388 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $out . '</span>'; |
|
| 393 | - } else { |
|
| 394 | - $nom = 'puce_statut_'; |
|
| 395 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | - $lang_dir = lang_dir(lang_typo()); |
|
| 397 | - |
|
| 398 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | - . $inser_puce |
|
| 400 | - . '</span>'; |
|
| 401 | - } |
|
| 332 | + $src = statut_image($type, $statut); |
|
| 333 | + if (!$src) { |
|
| 334 | + return $src; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + $t = statut_titre($type, $statut); |
|
| 341 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | + |
|
| 343 | + if (!$ajax_node) { |
|
| 344 | + return $inser_puce; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $table = table_objet_sql($type); |
|
| 348 | + $desc = lister_tables_objets_sql($table); |
|
| 349 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | + return $inser_puce; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!function_exists('autoriser')) { |
|
| 354 | + include_spip('inc/autoriser'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | + if ($id_rubrique) { |
|
| 359 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | + return $inser_puce; |
|
| 361 | + } |
|
| 362 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | + else { |
|
| 364 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | + return $inser_puce; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | + if (!isset($coord[$statut])) { |
|
| 371 | + return $inser_puce; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | + ; |
|
| 376 | + $margin = 0; /* marge a gauche + droite */ |
|
| 377 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | + ; |
|
| 379 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | + |
|
| 381 | + if ($ajax) { |
|
| 382 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | + . $inser_puce |
|
| 385 | + . '</span>' |
|
| 386 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | + $i = 0; |
|
| 388 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $out . '</span>'; |
|
| 393 | + } else { |
|
| 394 | + $nom = 'puce_statut_'; |
|
| 395 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | + $lang_dir = lang_dir(lang_typo()); |
|
| 397 | + |
|
| 398 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | + . $inser_puce |
|
| 400 | + . '</span>'; |
|
| 401 | + } |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
| 405 | 405 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 406 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | - $t = supprimer_tags($titre); |
|
| 406 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | + $t = supprimer_tags($titre); |
|
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
| 413 | 413 | // La couleur du statut |
| 414 | 414 | |
| 415 | 415 | function puce_statut($statut, $atts = '') { |
| 416 | - $src = statut_image('article', $statut); |
|
| 417 | - if (!$src) { |
|
| 418 | - return ''; |
|
| 419 | - } |
|
| 416 | + $src = statut_image('article', $statut); |
|
| 417 | + if (!$src) { |
|
| 418 | + return ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 421 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 422 | 422 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - return $out . '</span>'; |
|
| 392 | + return $out.'</span>'; |
|
| 393 | 393 | } else { |
| 394 | 394 | $nom = 'puce_statut_'; |
| 395 | 395 | $action = generer_url_ecrire('puce_statut', '', true); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
| 407 | 407 | $t = supprimer_tags($titre); |
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |