@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Pipelines |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | if (test_espace_prive()) { |
| 21 | - include_spip('inc/pipelines_ecrire'); |
|
| 21 | + include_spip('inc/pipelines_ecrire'); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @return string Contenu qui sera inséré dans le head HTML |
| 45 | 45 | **/ |
| 46 | 46 | function f_jQuery($texte) { |
| 47 | - $x = ''; |
|
| 48 | - $jquery_plugins = pipeline( |
|
| 49 | - 'jquery_plugins', |
|
| 50 | - [ |
|
| 51 | - 'javascript/jquery.js', |
|
| 52 | - 'javascript/jquery.form.js', |
|
| 53 | - 'javascript/jquery.autosave.js', |
|
| 54 | - 'javascript/jquery.placeholder-label.js', |
|
| 55 | - 'javascript/ajaxCallback.js', |
|
| 56 | - 'javascript/js.cookie.js', |
|
| 57 | - ] |
|
| 58 | - ); |
|
| 59 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | - $script = timestamp($script); |
|
| 62 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $x . $texte; |
|
| 47 | + $x = ''; |
|
| 48 | + $jquery_plugins = pipeline( |
|
| 49 | + 'jquery_plugins', |
|
| 50 | + [ |
|
| 51 | + 'javascript/jquery.js', |
|
| 52 | + 'javascript/jquery.form.js', |
|
| 53 | + 'javascript/jquery.autosave.js', |
|
| 54 | + 'javascript/jquery.placeholder-label.js', |
|
| 55 | + 'javascript/ajaxCallback.js', |
|
| 56 | + 'javascript/js.cookie.js', |
|
| 57 | + ] |
|
| 58 | + ); |
|
| 59 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | + $script = timestamp($script); |
|
| 62 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $x . $texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -80,33 +80,33 @@ discard block |
||
| 80 | 80 | * @return string Contenu de la page envoyée au navigateur |
| 81 | 81 | **/ |
| 82 | 82 | function f_tidy($texte) { |
| 83 | - /** |
|
| 84 | - * Indentation à faire ? |
|
| 85 | - * |
|
| 86 | - * - true : actif. |
|
| 87 | - * - false par défaut. |
|
| 88 | - */ |
|
| 89 | - |
|
| 90 | - if ( |
|
| 91 | - $GLOBALS['xhtml'] |
|
| 92 | - && $GLOBALS['html'] |
|
| 93 | - && strlen($texte) |
|
| 94 | - && !headers_sent() |
|
| 95 | - ) { |
|
| 96 | - # Compatibilite ascendante |
|
| 97 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | - $f = charger_fonction('sax', 'xml'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $f($texte); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $texte; |
|
| 83 | + /** |
|
| 84 | + * Indentation à faire ? |
|
| 85 | + * |
|
| 86 | + * - true : actif. |
|
| 87 | + * - false par défaut. |
|
| 88 | + */ |
|
| 89 | + |
|
| 90 | + if ( |
|
| 91 | + $GLOBALS['xhtml'] |
|
| 92 | + && $GLOBALS['html'] |
|
| 93 | + && strlen($texte) |
|
| 94 | + && !headers_sent() |
|
| 95 | + ) { |
|
| 96 | + # Compatibilite ascendante |
|
| 97 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | + $f = charger_fonction('sax', 'xml'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $f($texte); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $texte; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -125,24 +125,24 @@ discard block |
||
| 125 | 125 | * @return string Contenu de la page envoyée au navigateur |
| 126 | 126 | **/ |
| 127 | 127 | function f_insert_head($texte) { |
| 128 | - if (!$GLOBALS['html']) { |
|
| 129 | - return $texte; |
|
| 130 | - } |
|
| 131 | - include_spip('public/admin'); // pour strripos |
|
| 132 | - |
|
| 133 | - if ( |
|
| 134 | - !($pos = stripos($texte, '</head>')) |
|
| 135 | - && !($pos = stripos($texte, '<body>')) |
|
| 136 | - ) { |
|
| 137 | - $pos = 0; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $texte; |
|
| 128 | + if (!$GLOBALS['html']) { |
|
| 129 | + return $texte; |
|
| 130 | + } |
|
| 131 | + include_spip('public/admin'); // pour strripos |
|
| 132 | + |
|
| 133 | + if ( |
|
| 134 | + !($pos = stripos($texte, '</head>')) |
|
| 135 | + && !($pos = stripos($texte, '<body>')) |
|
| 136 | + ) { |
|
| 137 | + $pos = 0; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $texte; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -158,34 +158,34 @@ discard block |
||
| 158 | 158 | * @return string Contenu de la page envoyée au navigateur |
| 159 | 159 | **/ |
| 160 | 160 | function f_admin($texte) { |
| 161 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | - $x = "<div class='spip-previsu' " |
|
| 164 | - . http_style_background('preview-32.png', '', 32) |
|
| 165 | - . '>' |
|
| 166 | - . _T('previsualisation') |
|
| 167 | - . '</div>'; |
|
| 168 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | - $pos = strlen($texte); |
|
| 170 | - } |
|
| 171 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | - // pas de preview en fenetre enfant |
|
| 173 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | - if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | - $pos = -1; |
|
| 176 | - } |
|
| 177 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | - include_spip('public/admin'); |
|
| 182 | - $texte = affiche_boutons_admin($texte); |
|
| 183 | - } |
|
| 184 | - if (_request('var_mode') == 'noajax') { |
|
| 185 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $texte; |
|
| 161 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | + $x = "<div class='spip-previsu' " |
|
| 164 | + . http_style_background('preview-32.png', '', 32) |
|
| 165 | + . '>' |
|
| 166 | + . _T('previsualisation') |
|
| 167 | + . '</div>'; |
|
| 168 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | + $pos = strlen($texte); |
|
| 170 | + } |
|
| 171 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | + // pas de preview en fenetre enfant |
|
| 173 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | + if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | + $pos = -1; |
|
| 176 | + } |
|
| 177 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | + include_spip('public/admin'); |
|
| 182 | + $texte = affiche_boutons_admin($texte); |
|
| 183 | + } |
|
| 184 | + if (_request('var_mode') == 'noajax') { |
|
| 185 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $texte; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @return array $flux Description et contenu de l'inclusion |
| 204 | 204 | **/ |
| 205 | 205 | function f_recuperer_fond($flux) { |
| 206 | - if (!test_espace_prive()) { |
|
| 207 | - return $flux; |
|
| 208 | - } |
|
| 206 | + if (!test_espace_prive()) { |
|
| 207 | + return $flux; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return f_afficher_blocs_ecrire($flux); |
|
| 210 | + return f_afficher_blocs_ecrire($flux); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -221,30 +221,30 @@ discard block |
||
| 221 | 221 | * @return string Contenu de la page envoyée au navigateur |
| 222 | 222 | */ |
| 223 | 223 | function f_queue($texte) { |
| 224 | - // eviter une inclusion si rien a faire |
|
| 225 | - if ( |
|
| 226 | - _request('action') == 'cron' |
|
| 227 | - || queue_sleep_time_to_next_job() > 0 |
|
| 228 | - || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | - ) { |
|
| 230 | - return $texte; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - include_spip('inc/queue'); |
|
| 234 | - $code = queue_affichage_cron(); |
|
| 235 | - |
|
| 236 | - // si rien a afficher |
|
| 237 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | - if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | - return $texte; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | - } else { |
|
| 246 | - $texte .= $code; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $texte; |
|
| 224 | + // eviter une inclusion si rien a faire |
|
| 225 | + if ( |
|
| 226 | + _request('action') == 'cron' |
|
| 227 | + || queue_sleep_time_to_next_job() > 0 |
|
| 228 | + || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | + ) { |
|
| 230 | + return $texte; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + include_spip('inc/queue'); |
|
| 234 | + $code = queue_affichage_cron(); |
|
| 235 | + |
|
| 236 | + // si rien a afficher |
|
| 237 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | + if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | + return $texte; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | + } else { |
|
| 246 | + $texte .= $code; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $texte; |
|
| 250 | 250 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x.$texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
| 141 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 141 | + $insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n"; |
|
| 142 | 142 | $texte = substr_replace($texte, $insert, $pos, 0); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | $texte = substr_replace($texte, $x, $pos, 0); |
| 172 | 172 | // pas de preview en fenetre enfant |
| 173 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 173 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes((string) $GLOBALS['meta']['adresse_site'])."';}</script>"; |
|
| 174 | 174 | if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
| 175 | 175 | $pos = -1; |
| 176 | 176 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
| 243 | 243 | if (($p = strpos($texte, '</body>')) !== false) { |
| 244 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 244 | + $texte = substr($texte, 0, $p).$code.substr($texte, $p); |
|
| 245 | 245 | } else { |
| 246 | 246 | $texte .= $code; |
| 247 | 247 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte_mini'); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return array Tablea ('','') |
| 36 | 36 | */ |
| 37 | 37 | function definir_raccourcis_alineas() { |
| 38 | - return ['', '']; |
|
| 38 | + return ['', '']; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | 50 | function traiter_tableau($bloc) { |
| 51 | - return $bloc; |
|
| 51 | + return $bloc; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | 64 | function traiter_listes($texte) { |
| 65 | - return $texte; |
|
| 65 | + return $texte; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -78,16 +78,16 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function traiter_raccourcis($letexte) { |
| 80 | 80 | |
| 81 | - // Appeler les fonctions de pre_traitement |
|
| 82 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 81 | + // Appeler les fonctions de pre_traitement |
|
| 82 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 83 | 83 | |
| 84 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 85 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 84 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 85 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 86 | 86 | |
| 87 | - // Appeler les fonctions de post-traitement |
|
| 88 | - $letexte = pipeline('post_propre', $letexte); |
|
| 87 | + // Appeler les fonctions de post-traitement |
|
| 88 | + $letexte = pipeline('post_propre', $letexte); |
|
| 89 | 89 | |
| 90 | - return $letexte; |
|
| 90 | + return $letexte; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /************************************************************************************************************************* |
@@ -103,22 +103,22 @@ discard block |
||
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | 105 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 106 | - foreach (['script', 'iframe'] as $tag) { |
|
| 107 | - if ( |
|
| 108 | - stripos($t, (string) "<$tag") !== false |
|
| 109 | - && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | - ) { |
|
| 111 | - foreach ($r as $regs) { |
|
| 112 | - $t = str_replace( |
|
| 113 | - $regs[0], |
|
| 114 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 115 | - $t |
|
| 116 | - ); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $t; |
|
| 106 | + foreach (['script', 'iframe'] as $tag) { |
|
| 107 | + if ( |
|
| 108 | + stripos($t, (string) "<$tag") !== false |
|
| 109 | + && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | + ) { |
|
| 111 | + foreach ($r as $regs) { |
|
| 112 | + $t = str_replace( |
|
| 113 | + $regs[0], |
|
| 114 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 115 | + $t |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $t; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -147,55 +147,55 @@ discard block |
||
| 147 | 147 | * Code protégé |
| 148 | 148 | **/ |
| 149 | 149 | function interdire_scripts($arg, $mode_filtre = null) { |
| 150 | - // on memorise le resultat sur les arguments non triviaux |
|
| 151 | - static $dejavu = []; |
|
| 152 | - |
|
| 153 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 154 | - if (!$arg || !is_string($arg) || !strstr($arg, '<')) { |
|
| 155 | - return $arg; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (is_null($mode_filtre) || !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 159 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 163 | - return $dejavu[$mode_filtre][$arg]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // echapper les tags asp/php |
|
| 167 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 168 | - |
|
| 169 | - // echapper le php |
|
| 170 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 171 | - |
|
| 172 | - // echapper le < script language=php > |
|
| 173 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 174 | - |
|
| 175 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 176 | - switch ($mode_filtre) { |
|
| 177 | - case 0: |
|
| 178 | - if (!_DIR_RESTREINT) { |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - case -1: |
|
| 183 | - $t = echappe_js($t); |
|
| 184 | - break; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // pas de <base href /> svp ! |
|
| 188 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 189 | - |
|
| 190 | - // Reinserer les echappements des modeles |
|
| 191 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 192 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 193 | - } |
|
| 194 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 195 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 150 | + // on memorise le resultat sur les arguments non triviaux |
|
| 151 | + static $dejavu = []; |
|
| 152 | + |
|
| 153 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 154 | + if (!$arg || !is_string($arg) || !strstr($arg, '<')) { |
|
| 155 | + return $arg; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (is_null($mode_filtre) || !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 159 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 163 | + return $dejavu[$mode_filtre][$arg]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // echapper les tags asp/php |
|
| 167 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 168 | + |
|
| 169 | + // echapper le php |
|
| 170 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 171 | + |
|
| 172 | + // echapper le < script language=php > |
|
| 173 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 174 | + |
|
| 175 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 176 | + switch ($mode_filtre) { |
|
| 177 | + case 0: |
|
| 178 | + if (!_DIR_RESTREINT) { |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + case -1: |
|
| 183 | + $t = echappe_js($t); |
|
| 184 | + break; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // pas de <base href /> svp ! |
|
| 188 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 189 | + |
|
| 190 | + // Reinserer les echappements des modeles |
|
| 191 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 192 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 193 | + } |
|
| 194 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 195 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -224,66 +224,66 @@ discard block |
||
| 224 | 224 | * texte transformé |
| 225 | 225 | **/ |
| 226 | 226 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 227 | - // Plus vite ! |
|
| 228 | - if (!$letexte) { |
|
| 229 | - return $letexte; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 233 | - // prive etant historiquement ecrit sans argment $connect |
|
| 234 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 235 | - // ou il faut passer interdire_script explicitement |
|
| 236 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 237 | - // ne seront pas perturbes |
|
| 238 | - $interdire_script = false; |
|
| 239 | - if (is_null($connect)) { |
|
| 240 | - $connect = ''; |
|
| 241 | - $interdire_script = true; |
|
| 242 | - $env['espace_prive'] = test_espace_prive(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Echapper les codes <html> etc |
|
| 246 | - if ($echapper) { |
|
| 247 | - $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, 'TYPO'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // |
|
| 251 | - // Installer les modeles, notamment images et documents ; |
|
| 252 | - // |
|
| 253 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 254 | - // cf. inc/lien |
|
| 255 | - |
|
| 256 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 257 | - if ($letexte != $mem) { |
|
| 258 | - $echapper = true; |
|
| 259 | - } |
|
| 260 | - unset($mem); |
|
| 261 | - |
|
| 262 | - $letexte = corriger_typo($letexte); |
|
| 263 | - $letexte = echapper_faux_tags($letexte); |
|
| 264 | - |
|
| 265 | - // reintegrer les echappements |
|
| 266 | - if ($echapper) { |
|
| 267 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64($letexte, 'TYPO'); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 271 | - if ($interdire_script) { |
|
| 272 | - $letexte = interdire_scripts($letexte); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 276 | - // https://core.spip.net/issues/3371 |
|
| 277 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 278 | - // https://core.spip.net/issues/4166 |
|
| 279 | - if ( |
|
| 280 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 281 | - || isset($env['espace_prive']) && $env['espace_prive'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 282 | - ) { |
|
| 283 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $letexte; |
|
| 227 | + // Plus vite ! |
|
| 228 | + if (!$letexte) { |
|
| 229 | + return $letexte; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 233 | + // prive etant historiquement ecrit sans argment $connect |
|
| 234 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 235 | + // ou il faut passer interdire_script explicitement |
|
| 236 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 237 | + // ne seront pas perturbes |
|
| 238 | + $interdire_script = false; |
|
| 239 | + if (is_null($connect)) { |
|
| 240 | + $connect = ''; |
|
| 241 | + $interdire_script = true; |
|
| 242 | + $env['espace_prive'] = test_espace_prive(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Echapper les codes <html> etc |
|
| 246 | + if ($echapper) { |
|
| 247 | + $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, 'TYPO'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // |
|
| 251 | + // Installer les modeles, notamment images et documents ; |
|
| 252 | + // |
|
| 253 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 254 | + // cf. inc/lien |
|
| 255 | + |
|
| 256 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 257 | + if ($letexte != $mem) { |
|
| 258 | + $echapper = true; |
|
| 259 | + } |
|
| 260 | + unset($mem); |
|
| 261 | + |
|
| 262 | + $letexte = corriger_typo($letexte); |
|
| 263 | + $letexte = echapper_faux_tags($letexte); |
|
| 264 | + |
|
| 265 | + // reintegrer les echappements |
|
| 266 | + if ($echapper) { |
|
| 267 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64($letexte, 'TYPO'); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 271 | + if ($interdire_script) { |
|
| 272 | + $letexte = interdire_scripts($letexte); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 276 | + // https://core.spip.net/issues/3371 |
|
| 277 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 278 | + // https://core.spip.net/issues/4166 |
|
| 279 | + if ( |
|
| 280 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 281 | + || isset($env['espace_prive']) && $env['espace_prive'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 282 | + ) { |
|
| 283 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $letexte; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Correcteur typographique |
@@ -308,57 +308,57 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function corriger_typo($letexte, $lang = '') { |
| 310 | 310 | |
| 311 | - // Plus vite ! |
|
| 312 | - if (!$letexte) { |
|
| 313 | - return $letexte; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 317 | - |
|
| 318 | - // Caracteres de controle "illegaux" |
|
| 319 | - $letexte = corriger_caracteres($letexte); |
|
| 320 | - |
|
| 321 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 322 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 323 | - foreach ($regs as $reg) { |
|
| 324 | - $insert = $reg[0]; |
|
| 325 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 326 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 327 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 328 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // trouver les blocs idiomes et les traiter à part |
|
| 333 | - $letexte = extraire_idiome($ei = $letexte, $lang, ['echappe_span' => true]); |
|
| 334 | - $ei = ($ei !== $letexte); |
|
| 335 | - |
|
| 336 | - // trouver les blocs multi et les traiter a part |
|
| 337 | - $letexte = extraire_multi($em = $letexte, $lang, ['echappe_span' => true]); |
|
| 338 | - $em = ($em !== $letexte); |
|
| 339 | - |
|
| 340 | - // Charger & appliquer les fonctions de typographie |
|
| 341 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 342 | - $letexte = $typographie($letexte); |
|
| 343 | - |
|
| 344 | - // Les citations en une autre langue, s'il y a lieu |
|
| 345 | - if ($em) { |
|
| 346 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 347 | - } |
|
| 348 | - if ($ei) { |
|
| 349 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // Retablir les caracteres proteges |
|
| 353 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 354 | - |
|
| 355 | - // pipeline |
|
| 356 | - $letexte = pipeline('post_typo', $letexte); |
|
| 357 | - |
|
| 358 | - # un message pour abs_url - on est passe en mode texte |
|
| 359 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 360 | - |
|
| 361 | - return $letexte; |
|
| 311 | + // Plus vite ! |
|
| 312 | + if (!$letexte) { |
|
| 313 | + return $letexte; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 317 | + |
|
| 318 | + // Caracteres de controle "illegaux" |
|
| 319 | + $letexte = corriger_caracteres($letexte); |
|
| 320 | + |
|
| 321 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 322 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 323 | + foreach ($regs as $reg) { |
|
| 324 | + $insert = $reg[0]; |
|
| 325 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 326 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 327 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 328 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // trouver les blocs idiomes et les traiter à part |
|
| 333 | + $letexte = extraire_idiome($ei = $letexte, $lang, ['echappe_span' => true]); |
|
| 334 | + $ei = ($ei !== $letexte); |
|
| 335 | + |
|
| 336 | + // trouver les blocs multi et les traiter a part |
|
| 337 | + $letexte = extraire_multi($em = $letexte, $lang, ['echappe_span' => true]); |
|
| 338 | + $em = ($em !== $letexte); |
|
| 339 | + |
|
| 340 | + // Charger & appliquer les fonctions de typographie |
|
| 341 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 342 | + $letexte = $typographie($letexte); |
|
| 343 | + |
|
| 344 | + // Les citations en une autre langue, s'il y a lieu |
|
| 345 | + if ($em) { |
|
| 346 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 347 | + } |
|
| 348 | + if ($ei) { |
|
| 349 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // Retablir les caracteres proteges |
|
| 353 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 354 | + |
|
| 355 | + // pipeline |
|
| 356 | + $letexte = pipeline('post_typo', $letexte); |
|
| 357 | + |
|
| 358 | + # un message pour abs_url - on est passe en mode texte |
|
| 359 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 360 | + |
|
| 361 | + return $letexte; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function paragrapher($letexte, $forcer = true) { |
| 377 | - return $letexte; |
|
| 377 | + return $letexte; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -386,11 +386,11 @@ discard block |
||
| 386 | 386 | * @return string texte |
| 387 | 387 | **/ |
| 388 | 388 | function traiter_retours_chariots($letexte) { |
| 389 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 390 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 391 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 389 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 390 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 391 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 392 | 392 | |
| 393 | - return $letexte; |
|
| 393 | + return $letexte; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -416,41 +416,41 @@ discard block |
||
| 416 | 416 | * texte transformé |
| 417 | 417 | **/ |
| 418 | 418 | function propre($t, $connect = null, $env = []) { |
| 419 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 420 | - // prive etant historiquement ecrits sans argment $connect |
|
| 421 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 422 | - // ou il faut passer interdire_script explicitement |
|
| 423 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 424 | - // ne seront pas perturbes |
|
| 425 | - // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 426 | - $interdire_script = false; |
|
| 427 | - if (is_null($connect)) { |
|
| 428 | - $connect = ''; |
|
| 429 | - $interdire_script = true; |
|
| 430 | - $env['espace_prive'] = true; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if (!$t) { |
|
| 434 | - return strval($t); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 438 | - // avant echappement des balises <html> |
|
| 439 | - // https://core.spip.net/issues/3371 |
|
| 440 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 441 | - // https://core.spip.net/issues/4166 |
|
| 442 | - if ( |
|
| 443 | - $interdire_script |
|
| 444 | - || $GLOBALS['filtrer_javascript'] == -1 |
|
| 445 | - || !empty($env['espace_prive']) && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 446 | - || !empty($env['wysiwyg']) && $env['wysiwyg'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 447 | - ) { |
|
| 448 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 449 | - } |
|
| 450 | - $t = echappe_html($t); |
|
| 451 | - $t = expanser_liens($t, $connect ?? '', $env); |
|
| 452 | - $t = traiter_raccourcis($t); |
|
| 453 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 454 | - |
|
| 455 | - return $t; |
|
| 419 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 420 | + // prive etant historiquement ecrits sans argment $connect |
|
| 421 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 422 | + // ou il faut passer interdire_script explicitement |
|
| 423 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 424 | + // ne seront pas perturbes |
|
| 425 | + // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 426 | + $interdire_script = false; |
|
| 427 | + if (is_null($connect)) { |
|
| 428 | + $connect = ''; |
|
| 429 | + $interdire_script = true; |
|
| 430 | + $env['espace_prive'] = true; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if (!$t) { |
|
| 434 | + return strval($t); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 438 | + // avant echappement des balises <html> |
|
| 439 | + // https://core.spip.net/issues/3371 |
|
| 440 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 441 | + // https://core.spip.net/issues/4166 |
|
| 442 | + if ( |
|
| 443 | + $interdire_script |
|
| 444 | + || $GLOBALS['filtrer_javascript'] == -1 |
|
| 445 | + || !empty($env['espace_prive']) && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 446 | + || !empty($env['wysiwyg']) && $env['wysiwyg'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 447 | + ) { |
|
| 448 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 449 | + } |
|
| 450 | + $t = echappe_html($t); |
|
| 451 | + $t = expanser_liens($t, $connect ?? '', $env); |
|
| 452 | + $t = traiter_raccourcis($t); |
|
| 453 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 454 | + |
|
| 455 | + return $t; |
|
| 456 | 456 | } |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | foreach (['script', 'iframe'] as $tag) { |
| 107 | 107 | if ( |
| 108 | 108 | stripos($t, (string) "<$tag") !== false |
| 109 | - && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + && preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | 110 | ) { |
| 111 | 111 | foreach ($r as $regs) { |
| 112 | 112 | $t = str_replace( |
| 113 | 113 | $regs[0], |
| 114 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 115 | 115 | $t |
| 116 | 116 | ); |
| 117 | 117 | } |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // echapper les tags asp/php |
| 167 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 168 | 168 | |
| 169 | 169 | // echapper le php |
| 170 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 171 | 171 | |
| 172 | 172 | // echapper le < script language=php > |
| 173 | 173 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | // Reinserer les echappements des modeles |
| 191 | 191 | if (defined('_PROTEGE_JS_MODELES')) { |
| 192 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + $t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES); |
|
| 193 | 193 | } |
| 194 | 194 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 195 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + $t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 291 | 291 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 292 | 292 | |
| 293 | -define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS'); |
|
| 293 | +define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS'); |
|
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | 296 | * Corrige la typographie |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -50,66 +50,66 @@ discard block |
||
| 50 | 50 | * true si le cookie a été posé, false sinon. |
| 51 | 51 | **/ |
| 52 | 52 | function spip_setcookie( |
| 53 | - string $name = '', |
|
| 54 | - string $value = '', |
|
| 55 | - int|array $expires_or_options = 0, |
|
| 56 | - string $path = '', |
|
| 57 | - string $domain = '', |
|
| 58 | - bool $secure = false, |
|
| 59 | - bool $httponly = false |
|
| 53 | + string $name = '', |
|
| 54 | + string $value = '', |
|
| 55 | + int|array $expires_or_options = 0, |
|
| 56 | + string $path = '', |
|
| 57 | + string $domain = '', |
|
| 58 | + bool $secure = false, |
|
| 59 | + bool $httponly = false |
|
| 60 | 60 | ) { |
| 61 | - if (!is_array($expires_or_options)) { |
|
| 62 | - # anciens paramètres : spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $options = [ |
|
| 64 | - 'expires' => (int) $expires_or_options, |
|
| 65 | - 'path' => $path, |
|
| 66 | - 'domain' => $domain, |
|
| 67 | - 'secure' => $secure, |
|
| 68 | - 'httponly' => $httponly, |
|
| 69 | - ]; |
|
| 70 | - } else { |
|
| 71 | - $options = $expires_or_options; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // expires |
|
| 75 | - $options['expires'] ??= 0; |
|
| 76 | - if (!isset($options['path']) || $options['path'] === 'AUTO') { |
|
| 77 | - $options['path'] = defined('_COOKIE_PATH') ? constant('_COOKIE_PATH') : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 78 | - } |
|
| 79 | - if (empty($options['domain']) && defined('_COOKIE_DOMAIN') && constant('_COOKIE_DOMAIN')) { |
|
| 80 | - $options['domain'] = constant('_COOKIE_DOMAIN'); |
|
| 81 | - } |
|
| 82 | - $options['secure'] ??= false; |
|
| 83 | - $options['secure'] = ($options['secure'] ?: ($_SERVER['HTTPS'] ?? false)); |
|
| 84 | - if (defined('_COOKIE_SECURE') && constant('_COOKIE_SECURE')) { |
|
| 85 | - trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead (automatic in HTTPS).', '_COOKIE_SECURE', 'secure: true', __FUNCTION__); |
|
| 86 | - $options['secure'] = true; |
|
| 87 | - } |
|
| 88 | - $options['httponly'] ??= false; |
|
| 89 | - $options['samesite'] = ($options['samesite'] ?? 'Lax') ?: 'Lax'; |
|
| 90 | - |
|
| 91 | - /** @deprecated 5.0 Use option `'httponly' => true` */ |
|
| 92 | - if (defined('_COOKIE_SECURE_LIST')) { |
|
| 93 | - trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead.', '_COOKIE_SECURE_LIST', 'httponly: true', __FUNCTION__); |
|
| 94 | - if ( |
|
| 95 | - is_array(constant('_COOKIE_SECURE_LIST')) |
|
| 96 | - && in_array($name, constant('_COOKIE_SECURE_LIST')) |
|
| 97 | - ) { |
|
| 98 | - $options['httponly'] = true; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // in fine renommer le prefixe si besoin |
|
| 103 | - if (str_starts_with($name, 'spip_')) { |
|
| 104 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 108 | - $a = @setcookie($name, $value, $options); |
|
| 109 | - |
|
| 110 | - spip_cookie_envoye(true); |
|
| 111 | - |
|
| 112 | - return $a; |
|
| 61 | + if (!is_array($expires_or_options)) { |
|
| 62 | + # anciens paramètres : spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $options = [ |
|
| 64 | + 'expires' => (int) $expires_or_options, |
|
| 65 | + 'path' => $path, |
|
| 66 | + 'domain' => $domain, |
|
| 67 | + 'secure' => $secure, |
|
| 68 | + 'httponly' => $httponly, |
|
| 69 | + ]; |
|
| 70 | + } else { |
|
| 71 | + $options = $expires_or_options; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // expires |
|
| 75 | + $options['expires'] ??= 0; |
|
| 76 | + if (!isset($options['path']) || $options['path'] === 'AUTO') { |
|
| 77 | + $options['path'] = defined('_COOKIE_PATH') ? constant('_COOKIE_PATH') : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 78 | + } |
|
| 79 | + if (empty($options['domain']) && defined('_COOKIE_DOMAIN') && constant('_COOKIE_DOMAIN')) { |
|
| 80 | + $options['domain'] = constant('_COOKIE_DOMAIN'); |
|
| 81 | + } |
|
| 82 | + $options['secure'] ??= false; |
|
| 83 | + $options['secure'] = ($options['secure'] ?: ($_SERVER['HTTPS'] ?? false)); |
|
| 84 | + if (defined('_COOKIE_SECURE') && constant('_COOKIE_SECURE')) { |
|
| 85 | + trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead (automatic in HTTPS).', '_COOKIE_SECURE', 'secure: true', __FUNCTION__); |
|
| 86 | + $options['secure'] = true; |
|
| 87 | + } |
|
| 88 | + $options['httponly'] ??= false; |
|
| 89 | + $options['samesite'] = ($options['samesite'] ?? 'Lax') ?: 'Lax'; |
|
| 90 | + |
|
| 91 | + /** @deprecated 5.0 Use option `'httponly' => true` */ |
|
| 92 | + if (defined('_COOKIE_SECURE_LIST')) { |
|
| 93 | + trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead.', '_COOKIE_SECURE_LIST', 'httponly: true', __FUNCTION__); |
|
| 94 | + if ( |
|
| 95 | + is_array(constant('_COOKIE_SECURE_LIST')) |
|
| 96 | + && in_array($name, constant('_COOKIE_SECURE_LIST')) |
|
| 97 | + ) { |
|
| 98 | + $options['httponly'] = true; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // in fine renommer le prefixe si besoin |
|
| 103 | + if (str_starts_with($name, 'spip_')) { |
|
| 104 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 108 | + $a = @setcookie($name, $value, $options); |
|
| 109 | + |
|
| 110 | + spip_cookie_envoye(true); |
|
| 111 | + |
|
| 112 | + return $a; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | * @return bool |
| 126 | 126 | **/ |
| 127 | 127 | function spip_cookie_envoye($set = '') { |
| 128 | - static $envoye = false; |
|
| 129 | - if ($set) { |
|
| 130 | - $envoye = true; |
|
| 131 | - } |
|
| 128 | + static $envoye = false; |
|
| 129 | + if ($set) { |
|
| 130 | + $envoye = true; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return $envoye; |
|
| 133 | + return $envoye; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * Préfixe des cookies de SPIP |
| 150 | 150 | **/ |
| 151 | 151 | function recuperer_cookies_spip($cookie_prefix) { |
| 152 | - $prefix_long = strlen($cookie_prefix); |
|
| 153 | - |
|
| 154 | - foreach (array_keys($_COOKIE) as $name) { |
|
| 155 | - if (str_starts_with($name, 'spip_') && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 156 | - unset($_COOKIE[$name]); |
|
| 157 | - unset($GLOBALS[$name]); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - foreach ($_COOKIE as $name => $value) { |
|
| 161 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 162 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 163 | - $_COOKIE[$spipname] = $value; |
|
| 164 | - $GLOBALS[$spipname] = $value; |
|
| 165 | - } |
|
| 166 | - } |
|
| 152 | + $prefix_long = strlen($cookie_prefix); |
|
| 153 | + |
|
| 154 | + foreach (array_keys($_COOKIE) as $name) { |
|
| 155 | + if (str_starts_with($name, 'spip_') && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 156 | + unset($_COOKIE[$name]); |
|
| 157 | + unset($GLOBALS[$name]); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + foreach ($_COOKIE as $name => $value) { |
|
| 161 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 162 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 163 | + $_COOKIE[$spipname] = $value; |
|
| 164 | + $GLOBALS[$spipname] = $value; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -182,18 +182,18 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | **/ |
| 184 | 184 | function exec_test_ajax_dist() { |
| 185 | - switch (_request('js')) { |
|
| 186 | - // on est appele par <noscript> |
|
| 187 | - case -1: |
|
| 188 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 189 | - include_spip('inc/headers'); |
|
| 190 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 191 | - break; |
|
| 192 | - |
|
| 193 | - // ou par ajax |
|
| 194 | - case 1: |
|
| 195 | - default: |
|
| 196 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 197 | - break; |
|
| 198 | - } |
|
| 185 | + switch (_request('js')) { |
|
| 186 | + // on est appele par <noscript> |
|
| 187 | + case -1: |
|
| 188 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 189 | + include_spip('inc/headers'); |
|
| 190 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 191 | + break; |
|
| 192 | + |
|
| 193 | + // ou par ajax |
|
| 194 | + case 1: |
|
| 195 | + default: |
|
| 196 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 197 | + break; |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | function spip_setcookie( |
| 53 | 53 | string $name = '', |
| 54 | 54 | string $value = '', |
| 55 | - int|array $expires_or_options = 0, |
|
| 55 | + int | array $expires_or_options = 0, |
|
| 56 | 56 | string $path = '', |
| 57 | 57 | string $domain = '', |
| 58 | 58 | bool $secure = false, |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // in fine renommer le prefixe si besoin |
| 103 | 103 | if (str_starts_with($name, 'spip_')) { |
| 104 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 104 | + $name = $GLOBALS['cookie_prefix'].'_'.substr($name, 5); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | foreach ($_COOKIE as $name => $value) { |
| 161 | 161 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 162 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 162 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 163 | 163 | $_COOKIE[$spipname] = $value; |
| 164 | 164 | $GLOBALS[$spipname] = $value; |
| 165 | 165 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | */ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres_boites'); |
@@ -40,25 +40,25 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function parametres_css_prive() { |
| 42 | 42 | |
| 43 | - $args = []; |
|
| 44 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | - $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 43 | + $args = []; |
|
| 44 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | + $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 50 | 50 | |
| 51 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 51 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | 52 | |
| 53 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | - parse_str((string) $couleurs($c), $c); |
|
| 55 | - $args = array_merge($args, $c); |
|
| 53 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | + parse_str((string) $couleurs($c), $c); |
|
| 55 | + $args = array_merge($args, $c); |
|
| 56 | 56 | |
| 57 | - if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | - $args['var_mode'] = 'recalcul'; |
|
| 59 | - } |
|
| 57 | + if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | + $args['var_mode'] = 'recalcul'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return http_build_query($args); |
|
| 61 | + return http_build_query($args); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -81,95 +81,95 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | function chercher_rubrique( |
| 84 | - $titre, |
|
| 85 | - $id_objet, |
|
| 86 | - $id_parent, |
|
| 87 | - $objet, |
|
| 88 | - $id_secteur, |
|
| 89 | - $restreint, |
|
| 90 | - $actionable = false, |
|
| 91 | - $retour_sans_cadre = false |
|
| 84 | + $titre, |
|
| 85 | + $id_objet, |
|
| 86 | + $id_parent, |
|
| 87 | + $objet, |
|
| 88 | + $id_secteur, |
|
| 89 | + $restreint, |
|
| 90 | + $actionable = false, |
|
| 91 | + $retour_sans_cadre = false |
|
| 92 | 92 | ) { |
| 93 | 93 | |
| 94 | - include_spip('inc/autoriser'); |
|
| 95 | - if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | - return ''; |
|
| 97 | - } |
|
| 98 | - if (!sql_countsel('spip_rubriques')) { |
|
| 99 | - return ''; |
|
| 100 | - } |
|
| 101 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | - |
|
| 104 | - if ($id_parent == 0) { |
|
| 105 | - $logo = 'racine-24.png'; |
|
| 106 | - } elseif ($id_secteur == $id_parent) { |
|
| 107 | - $logo = 'secteur-24.png'; |
|
| 108 | - } else { |
|
| 109 | - $logo = 'rubrique-24.png'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $confirm = ''; |
|
| 113 | - if ($objet == 'rubrique') { |
|
| 114 | - // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - if ( |
|
| 118 | - sql_table_exists('spip_breves') |
|
| 119 | - && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | - && $contient_breves > 0 |
|
| 121 | - ) { |
|
| 122 | - // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | - $scb = _T( |
|
| 125 | - 'avis_deplacement_rubrique', |
|
| 126 | - [ |
|
| 127 | - 'contient_breves' => $contient_breves, |
|
| 128 | - 'scb' => $scb |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | - . $scb . |
|
| 134 | - "</label></div></div>\n"; |
|
| 135 | - } else { |
|
| 136 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - $form .= $confirm; |
|
| 140 | - if ($actionable) { |
|
| 141 | - if (str_contains($form, '<select')) { |
|
| 142 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | - . '</div>'; |
|
| 145 | - } |
|
| 146 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | - $form = generer_action_auteur( |
|
| 149 | - "editer_$objet", |
|
| 150 | - $id_objet, |
|
| 151 | - self(), |
|
| 152 | - $form, |
|
| 153 | - " method='post' class='submit_plongeur'" |
|
| 154 | - ); |
|
| 155 | - } else { |
|
| 156 | - $form = generer_action_auteur( |
|
| 157 | - 'editer_objet', |
|
| 158 | - "$objet/$id_objet", |
|
| 159 | - self(), |
|
| 160 | - $form, |
|
| 161 | - " method='post' class='submit_plongeur'" |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($retour_sans_cadre) { |
|
| 167 | - return $form; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - include_spip('inc/presentation'); |
|
| 171 | - |
|
| 172 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 94 | + include_spip('inc/autoriser'); |
|
| 95 | + if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | + return ''; |
|
| 97 | + } |
|
| 98 | + if (!sql_countsel('spip_rubriques')) { |
|
| 99 | + return ''; |
|
| 100 | + } |
|
| 101 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | + |
|
| 104 | + if ($id_parent == 0) { |
|
| 105 | + $logo = 'racine-24.png'; |
|
| 106 | + } elseif ($id_secteur == $id_parent) { |
|
| 107 | + $logo = 'secteur-24.png'; |
|
| 108 | + } else { |
|
| 109 | + $logo = 'rubrique-24.png'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $confirm = ''; |
|
| 113 | + if ($objet == 'rubrique') { |
|
| 114 | + // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + if ( |
|
| 118 | + sql_table_exists('spip_breves') |
|
| 119 | + && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | + && $contient_breves > 0 |
|
| 121 | + ) { |
|
| 122 | + // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | + $scb = _T( |
|
| 125 | + 'avis_deplacement_rubrique', |
|
| 126 | + [ |
|
| 127 | + 'contient_breves' => $contient_breves, |
|
| 128 | + 'scb' => $scb |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | + . $scb . |
|
| 134 | + "</label></div></div>\n"; |
|
| 135 | + } else { |
|
| 136 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + $form .= $confirm; |
|
| 140 | + if ($actionable) { |
|
| 141 | + if (str_contains($form, '<select')) { |
|
| 142 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | + . '</div>'; |
|
| 145 | + } |
|
| 146 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | + $form = generer_action_auteur( |
|
| 149 | + "editer_$objet", |
|
| 150 | + $id_objet, |
|
| 151 | + self(), |
|
| 152 | + $form, |
|
| 153 | + " method='post' class='submit_plongeur'" |
|
| 154 | + ); |
|
| 155 | + } else { |
|
| 156 | + $form = generer_action_auteur( |
|
| 157 | + 'editer_objet', |
|
| 158 | + "$objet/$id_objet", |
|
| 159 | + self(), |
|
| 160 | + $form, |
|
| 161 | + " method='post' class='submit_plongeur'" |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($retour_sans_cadre) { |
|
| 167 | + return $form; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + include_spip('inc/presentation'); |
|
| 171 | + |
|
| 172 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -183,24 +183,24 @@ discard block |
||
| 183 | 183 | * @return bool |
| 184 | 184 | */ |
| 185 | 185 | function avoir_visiteurs($past = false, $accepter = true) { |
| 186 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!$past) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return sql_countsel( |
|
| 200 | - 'spip_auteurs', |
|
| 201 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 186 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!$past) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return sql_countsel( |
|
| 200 | + 'spip_auteurs', |
|
| 201 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 202 | 202 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 203 | - ); |
|
| 203 | + ); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | 218 | function statuts_articles_visibles($statut_auteur) { |
| 219 | - static $auth = []; |
|
| 220 | - if (!isset($auth[$statut_auteur])) { |
|
| 221 | - $auth[$statut_auteur] = []; |
|
| 222 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | - foreach ($statuts as $s) { |
|
| 224 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | - $auth[$statut_auteur][] = $s; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $auth[$statut_auteur]; |
|
| 219 | + static $auth = []; |
|
| 220 | + if (!isset($auth[$statut_auteur])) { |
|
| 221 | + $auth[$statut_auteur] = []; |
|
| 222 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | + foreach ($statuts as $s) { |
|
| 224 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | + $auth[$statut_auteur][] = $s; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $auth[$statut_auteur]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -241,38 +241,38 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function traduire_statut_auteur($statut, $attente = '') { |
| 244 | - $plus = ''; |
|
| 245 | - if ($statut == 'nouveau') { |
|
| 246 | - if ($attente) { |
|
| 247 | - $statut = $attente; |
|
| 248 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | - } else { |
|
| 250 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $recom = [ |
|
| 255 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | - ]; |
|
| 260 | - if (isset($recom[$statut])) { |
|
| 261 | - return $recom[$statut] . $plus; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // retrouver directement par le statut sinon |
|
| 265 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | - if (isset($recom[$t])) { |
|
| 267 | - return $recom[$t] . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return _T($t) . $plus; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | - // c'est toujours plus informatif que rien du tout |
|
| 275 | - return $statut; |
|
| 244 | + $plus = ''; |
|
| 245 | + if ($statut == 'nouveau') { |
|
| 246 | + if ($attente) { |
|
| 247 | + $statut = $attente; |
|
| 248 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | + } else { |
|
| 250 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $recom = [ |
|
| 255 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | + ]; |
|
| 260 | + if (isset($recom[$statut])) { |
|
| 261 | + return $recom[$statut] . $plus; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // retrouver directement par le statut sinon |
|
| 265 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | + if (isset($recom[$t])) { |
|
| 267 | + return $recom[$t] . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return _T($t) . $plus; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | + // c'est toujours plus informatif que rien du tout |
|
| 275 | + return $statut; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -283,29 +283,29 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | function afficher_qui_edite($id_objet, $objet): string { |
| 286 | - static $qui = []; |
|
| 287 | - if (isset($qui[$objet][$id_objet])) { |
|
| 288 | - return $qui[$objet][$id_objet]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - include_spip('inc/config'); |
|
| 292 | - if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | - return $qui[$objet][$id_objet] = ''; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - include_spip('inc/drapeau_edition'); |
|
| 297 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | - if (!$modif) { |
|
| 299 | - return $qui[$objet][$id_objet] = ''; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - include_spip('base/objets'); |
|
| 303 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | - if (isset($infos['texte_signale_edition'])) { |
|
| 305 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 286 | + static $qui = []; |
|
| 287 | + if (isset($qui[$objet][$id_objet])) { |
|
| 288 | + return $qui[$objet][$id_objet]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + include_spip('inc/config'); |
|
| 292 | + if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | + return $qui[$objet][$id_objet] = ''; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + include_spip('inc/drapeau_edition'); |
|
| 297 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | + if (!$modif) { |
|
| 299 | + return $qui[$objet][$id_objet] = ''; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + include_spip('base/objets'); |
|
| 303 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | + if (isset($infos['texte_signale_edition'])) { |
|
| 305 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -323,53 +323,53 @@ discard block |
||
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | 325 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array { |
| 326 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - switch ($quoi) { |
|
| 331 | - case 'redacteurs': |
|
| 332 | - $statut = AUTEURS_MIN_REDAC; |
|
| 333 | - $statut = explode(',', (string) $statut); |
|
| 334 | - if ($en_base) { |
|
| 335 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | - $retire = array_diff($statut, $check); |
|
| 337 | - $statut = array_diff($statut, $retire); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return array_unique($statut); |
|
| 341 | - |
|
| 342 | - case 'visiteurs': |
|
| 343 | - $statut = []; |
|
| 344 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | - $exclus = explode(',', (string) $exclus); |
|
| 346 | - if (!$en_base) { |
|
| 347 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | - } |
|
| 350 | - $s_complement = array_column( |
|
| 351 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | - 'statut' |
|
| 353 | - ); |
|
| 354 | - |
|
| 355 | - return array_unique([...$statut, ...$s_complement]); |
|
| 356 | - |
|
| 357 | - default: |
|
| 358 | - case 'tous': |
|
| 359 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | - $s_complement = array_column( |
|
| 361 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | - 'statut' |
|
| 363 | - ); |
|
| 364 | - $statut = [...$statut, ...$s_complement]; |
|
| 365 | - if ($en_base) { |
|
| 366 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | - $retire = array_diff($statut, $check); |
|
| 368 | - $statut = array_diff($statut, $retire); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return array_unique($statut); |
|
| 372 | - } |
|
| 326 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + switch ($quoi) { |
|
| 331 | + case 'redacteurs': |
|
| 332 | + $statut = AUTEURS_MIN_REDAC; |
|
| 333 | + $statut = explode(',', (string) $statut); |
|
| 334 | + if ($en_base) { |
|
| 335 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | + $retire = array_diff($statut, $check); |
|
| 337 | + $statut = array_diff($statut, $retire); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return array_unique($statut); |
|
| 341 | + |
|
| 342 | + case 'visiteurs': |
|
| 343 | + $statut = []; |
|
| 344 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | + $exclus = explode(',', (string) $exclus); |
|
| 346 | + if (!$en_base) { |
|
| 347 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | + } |
|
| 350 | + $s_complement = array_column( |
|
| 351 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | + 'statut' |
|
| 353 | + ); |
|
| 354 | + |
|
| 355 | + return array_unique([...$statut, ...$s_complement]); |
|
| 356 | + |
|
| 357 | + default: |
|
| 358 | + case 'tous': |
|
| 359 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | + $s_complement = array_column( |
|
| 361 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | + 'statut' |
|
| 363 | + ); |
|
| 364 | + $statut = [...$statut, ...$s_complement]; |
|
| 365 | + if ($en_base) { |
|
| 366 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | + $retire = array_diff($statut, $check); |
|
| 368 | + $statut = array_diff($statut, $retire); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return array_unique($statut); |
|
| 372 | + } |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | - : ''; |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | + : ''; |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,25 +417,25 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - $joli = $virtuel; |
|
| 426 | - $parts = parse_url($virtuel); |
|
| 427 | - if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
|
| 428 | - $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
|
| 429 | - $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 430 | - } |
|
| 431 | - if ($virtuel !== $joli) { |
|
| 432 | - $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 433 | - } |
|
| 434 | - else { |
|
| 435 | - $joli = propre('[->' . $virtuel . ']'); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $joli; |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + $joli = $virtuel; |
|
| 426 | + $parts = parse_url($virtuel); |
|
| 427 | + if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
|
| 428 | + $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
|
| 429 | + $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 430 | + } |
|
| 431 | + if ($virtuel !== $joli) { |
|
| 432 | + $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 433 | + } |
|
| 434 | + else { |
|
| 435 | + $joli = propre('[->' . $virtuel . ']'); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $joli; |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
@@ -458,11 +458,11 @@ discard block |
||
| 458 | 458 | * @filtre |
| 459 | 459 | */ |
| 460 | 460 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 461 | - include_spip('inc/acces'); |
|
| 462 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 461 | + include_spip('inc/acces'); |
|
| 462 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 463 | 463 | |
| 464 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 465 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 464 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 465 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -474,72 +474,72 @@ discard block |
||
| 474 | 474 | */ |
| 475 | 475 | function alertes_auteur($id_auteur): string { |
| 476 | 476 | |
| 477 | - $alertes = []; |
|
| 478 | - |
|
| 479 | - if ( |
|
| 480 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 481 | - && autoriser('detruire', null, null, $id_auteur) |
|
| 482 | - ) { |
|
| 483 | - include_spip('genie/maintenance'); |
|
| 484 | - if ($msg = message_crash_tables()) { |
|
| 485 | - $alertes[] = $msg; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - if ( |
|
| 490 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 491 | - && $GLOBALS['meta']['message_crash_plugins'] |
|
| 492 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 493 | - && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 494 | - ) { |
|
| 495 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 496 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 500 | - if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 501 | - $update = false; |
|
| 502 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 503 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 504 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 505 | - $update = true; |
|
| 506 | - } |
|
| 507 | - if (isset($a[''])) { |
|
| 508 | - $alertes = array_merge($alertes, $a['']); |
|
| 509 | - unset($a['']); |
|
| 510 | - $update = true; |
|
| 511 | - } |
|
| 512 | - if ($update) { |
|
| 513 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if ( |
|
| 518 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 519 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 520 | - ) { |
|
| 521 | - include_spip('inc/plugin'); |
|
| 522 | - $alertes[] = plugin_donne_erreurs(); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $alertes = pipeline( |
|
| 526 | - 'alertes_auteur', |
|
| 527 | - [ |
|
| 528 | - 'args' => [ |
|
| 529 | - 'id_auteur' => $id_auteur, |
|
| 530 | - 'exec' => _request('exec'), |
|
| 531 | - ], |
|
| 532 | - 'data' => $alertes |
|
| 533 | - ] |
|
| 534 | - ); |
|
| 535 | - |
|
| 536 | - if ($alertes = array_filter($alertes)) { |
|
| 537 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 538 | - implode(' | ', $alertes) |
|
| 539 | - . '</div></div>'; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - return ''; |
|
| 477 | + $alertes = []; |
|
| 478 | + |
|
| 479 | + if ( |
|
| 480 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 481 | + && autoriser('detruire', null, null, $id_auteur) |
|
| 482 | + ) { |
|
| 483 | + include_spip('genie/maintenance'); |
|
| 484 | + if ($msg = message_crash_tables()) { |
|
| 485 | + $alertes[] = $msg; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + if ( |
|
| 490 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 491 | + && $GLOBALS['meta']['message_crash_plugins'] |
|
| 492 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 493 | + && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 494 | + ) { |
|
| 495 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 496 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 500 | + if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 501 | + $update = false; |
|
| 502 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 503 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 504 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 505 | + $update = true; |
|
| 506 | + } |
|
| 507 | + if (isset($a[''])) { |
|
| 508 | + $alertes = array_merge($alertes, $a['']); |
|
| 509 | + unset($a['']); |
|
| 510 | + $update = true; |
|
| 511 | + } |
|
| 512 | + if ($update) { |
|
| 513 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ( |
|
| 518 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 519 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 520 | + ) { |
|
| 521 | + include_spip('inc/plugin'); |
|
| 522 | + $alertes[] = plugin_donne_erreurs(); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $alertes = pipeline( |
|
| 526 | + 'alertes_auteur', |
|
| 527 | + [ |
|
| 528 | + 'args' => [ |
|
| 529 | + 'id_auteur' => $id_auteur, |
|
| 530 | + 'exec' => _request('exec'), |
|
| 531 | + ], |
|
| 532 | + 'data' => $alertes |
|
| 533 | + ] |
|
| 534 | + ); |
|
| 535 | + |
|
| 536 | + if ($alertes = array_filter($alertes)) { |
|
| 537 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 538 | + implode(' | ', $alertes) |
|
| 539 | + . '</div></div>'; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + return ''; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | * @return string |
| 550 | 550 | */ |
| 551 | 551 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 552 | - include_spip('inc/presenter_enfants'); |
|
| 552 | + include_spip('inc/presenter_enfants'); |
|
| 553 | 553 | |
| 554 | - return afficher_enfant_rub((int) $id_rubrique); |
|
| 554 | + return afficher_enfant_rub((int) $id_rubrique); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -569,15 +569,15 @@ discard block |
||
| 569 | 569 | * @return string |
| 570 | 570 | */ |
| 571 | 571 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 572 | - $titre = attribut_html($titre); |
|
| 573 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 575 | - |
|
| 576 | - if (!$titre_lien) { |
|
| 577 | - return $icone; |
|
| 578 | - } else { |
|
| 579 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | - } |
|
| 572 | + $titre = attribut_html($titre); |
|
| 573 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 575 | + |
|
| 576 | + if (!$titre_lien) { |
|
| 577 | + return $icone; |
|
| 578 | + } else { |
|
| 579 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | + } |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
@@ -596,20 +596,20 @@ discard block |
||
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | 598 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 599 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 600 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 601 | - return []; |
|
| 602 | - } |
|
| 603 | - $r = reset($res); |
|
| 604 | - $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 605 | - if (isset($r['rang_lien'])) { |
|
| 606 | - $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 607 | - asort($l); |
|
| 608 | - $l = array_keys($l); |
|
| 609 | - } else { |
|
| 610 | - // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 611 | - // Sinon c'est dans "id_objet" |
|
| 612 | - $l = array_column($res, $colonne_id); |
|
| 613 | - } |
|
| 614 | - return $l; |
|
| 599 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 600 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 601 | + return []; |
|
| 602 | + } |
|
| 603 | + $r = reset($res); |
|
| 604 | + $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 605 | + if (isset($r['rang_lien'])) { |
|
| 606 | + $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 607 | + asort($l); |
|
| 608 | + $l = array_keys($l); |
|
| 609 | + } else { |
|
| 610 | + // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 611 | + // Sinon c'est dans "id_objet" |
|
| 612 | + $l = array_column($res, $colonne_id); |
|
| 613 | + } |
|
| 614 | + return $l; |
|
| 615 | 615 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | // confirmation du deplacement |
| 117 | 117 | if ( |
| 118 | 118 | sql_table_exists('spip_breves') |
| 119 | - && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 119 | + && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique='.(int) $id_objet)) |
|
| 120 | 120 | && $contient_breves > 0 |
| 121 | 121 | ) { |
| 122 | 122 | // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
| 132 | 132 | . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
| 133 | - . $scb . |
|
| 133 | + . $scb. |
|
| 134 | 134 | "</label></div></div>\n"; |
| 135 | 135 | } else { |
| 136 | 136 | $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $form .= $confirm; |
| 140 | 140 | if ($actionable) { |
| 141 | 141 | if (str_contains($form, '<select')) { |
| 142 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 142 | + $form .= "<div style='text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 143 | + . '<input class="fondo submit btn" type="submit" value="'._T('bouton_choisir').'"/>' |
|
| 144 | 144 | . '</div>'; |
| 145 | 145 | } |
| 146 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 146 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n".$form; |
|
| 147 | 147 | if ($action = charger_fonction("editer_$objet", 'action', true)) { |
| 148 | 148 | $form = generer_action_auteur( |
| 149 | 149 | "editer_$objet", |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | include_spip('inc/presentation'); |
| 171 | 171 | |
| 172 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 172 | + return debut_cadre_couleur($logo, true, '', $titre).$form.fin_cadre_couleur(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if ($statut == 'nouveau') { |
| 246 | 246 | if ($attente) { |
| 247 | 247 | $statut = $attente; |
| 248 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 248 | + $plus = ' ('._T('info_statut_auteur_a_confirmer').')'; |
|
| 249 | 249 | } else { |
| 250 | 250 | return _T('info_statut_auteur_a_confirmer'); |
| 251 | 251 | } |
@@ -258,16 +258,16 @@ discard block |
||
| 258 | 258 | '5poubelle' => _T('texte_statut_poubelle'), // bouh |
| 259 | 259 | ]; |
| 260 | 260 | if (isset($recom[$statut])) { |
| 261 | - return $recom[$statut] . $plus; |
|
| 261 | + return $recom[$statut].$plus; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // retrouver directement par le statut sinon |
| 265 | 265 | if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
| 266 | 266 | if (isset($recom[$t])) { |
| 267 | - return $recom[$t] . $plus; |
|
| 267 | + return $recom[$t].$plus; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return _T($t) . $plus; |
|
| 270 | + return _T($t).$plus; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // si on a pas reussi a le traduire, retournons la chaine telle quelle |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
| 389 | 389 | $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
| 390 | - ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 390 | + ? ' AND '.sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | 391 | : ''; |
| 392 | 392 | |
| 393 | 393 | // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
@@ -426,13 +426,13 @@ discard block |
||
| 426 | 426 | $parts = parse_url($virtuel); |
| 427 | 427 | if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
| 428 | 428 | $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
| 429 | - $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 429 | + $virtuel = str_replace('?'.$parts['query'], "?$query", $virtuel); |
|
| 430 | 430 | } |
| 431 | 431 | if ($virtuel !== $joli) { |
| 432 | - $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 432 | + $joli = propre('['.$joli.' -> '.$virtuel.']'); |
|
| 433 | 433 | } |
| 434 | 434 | else { |
| 435 | - $joli = propre('[->' . $virtuel . ']'); |
|
| 435 | + $joli = propre('[->'.$virtuel.']'); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | return $joli; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
| 463 | 463 | |
| 464 | 464 | $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
| 465 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 465 | + return "<a style='float: ".$GLOBALS['spip_lang_right'].";' href='$url'>$clic</a>"; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | 536 | if ($alertes = array_filter($alertes)) { |
| 537 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 537 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>". |
|
| 538 | 538 | implode(' | ', $alertes) |
| 539 | 539 | . '</div></div>'; |
| 540 | 540 | } |
@@ -570,13 +570,13 @@ discard block |
||
| 570 | 570 | */ |
| 571 | 571 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 572 | 572 | $titre = attribut_html($titre); |
| 573 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 573 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>". |
|
| 574 | + http_img_pack('information-16.png', $titre).'</a>'; |
|
| 575 | 575 | |
| 576 | 576 | if (!$titre_lien) { |
| 577 | 577 | return $icone; |
| 578 | 578 | } else { |
| 579 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 579 | + return $icone."\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | |
@@ -430,8 +430,7 @@ |
||
| 430 | 430 | } |
| 431 | 431 | if ($virtuel !== $joli) { |
| 432 | 432 | $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
| 433 | - } |
|
| 434 | - else { |
|
| 433 | + } else { |
|
| 435 | 434 | $joli = propre('[->' . $virtuel . ']'); |
| 436 | 435 | } |
| 437 | 436 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // |
@@ -22,52 +22,52 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | function produire_image_math($tex) { |
| 24 | 24 | |
| 25 | - switch ($GLOBALS['traiter_math']) { |
|
| 26 | - // Attention: mathml desactiv'e pour l'instant |
|
| 27 | - case 'mathml': |
|
| 28 | - $ext = '.xhtml'; |
|
| 29 | - $server = $GLOBALS['mathml_server']; |
|
| 30 | - break; |
|
| 31 | - case 'tex': |
|
| 32 | - $ext = '.png'; |
|
| 33 | - $server = $GLOBALS['tex_server']; |
|
| 34 | - break; |
|
| 35 | - default: |
|
| 36 | - return $tex; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | - } |
|
| 43 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // Aller chercher l'image sur le serveur |
|
| 47 | - if (!@file_exists($fichier) && $server) { |
|
| 48 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 49 | - include_spip('inc/distant'); |
|
| 50 | - recuperer_url($url, ['file' => $fichier]); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - // Composer la reponse selon presence ou non de l'image |
|
| 55 | - $tex = entites_html($tex); |
|
| 56 | - if (@file_exists($fichier)) { |
|
| 57 | - // MathML |
|
| 58 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 59 | - return implode('', file($fichier)); |
|
| 60 | - } // TeX |
|
| 61 | - else { |
|
| 62 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 63 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 64 | - |
|
| 65 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 66 | - } |
|
| 67 | - } else // pas de fichier |
|
| 68 | - { |
|
| 69 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 70 | - } |
|
| 25 | + switch ($GLOBALS['traiter_math']) { |
|
| 26 | + // Attention: mathml desactiv'e pour l'instant |
|
| 27 | + case 'mathml': |
|
| 28 | + $ext = '.xhtml'; |
|
| 29 | + $server = $GLOBALS['mathml_server']; |
|
| 30 | + break; |
|
| 31 | + case 'tex': |
|
| 32 | + $ext = '.png'; |
|
| 33 | + $server = $GLOBALS['tex_server']; |
|
| 34 | + break; |
|
| 35 | + default: |
|
| 36 | + return $tex; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | + } |
|
| 43 | + $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // Aller chercher l'image sur le serveur |
|
| 47 | + if (!@file_exists($fichier) && $server) { |
|
| 48 | + spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 49 | + include_spip('inc/distant'); |
|
| 50 | + recuperer_url($url, ['file' => $fichier]); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + // Composer la reponse selon presence ou non de l'image |
|
| 55 | + $tex = entites_html($tex); |
|
| 56 | + if (@file_exists($fichier)) { |
|
| 57 | + // MathML |
|
| 58 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 59 | + return implode('', file($fichier)); |
|
| 60 | + } // TeX |
|
| 61 | + else { |
|
| 62 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 63 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 64 | + |
|
| 65 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 66 | + } |
|
| 67 | + } else // pas de fichier |
|
| 68 | + { |
|
| 69 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
@@ -102,39 +102,39 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 104 | 104 | |
| 105 | - $collecteurMath = new CollecteurHtmlTag('math', '@<math>(.*)(</math>|$)@iUsS', ''); |
|
| 106 | - $collection = $collecteurMath->collecter($letexte); |
|
| 107 | - $collection = array_reverse($collection); |
|
| 108 | - |
|
| 109 | - foreach ($collection as $c) { |
|
| 110 | - $texte_milieu = $c['match'][1]; |
|
| 111 | - |
|
| 112 | - $traitements = [ |
|
| 113 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 114 | - ['str' => '$$', 'preg' => ',[$][$]([^$]+)[$][$],', 'pre' => "\n<p class=\"spip\" style=\"text-align: center;\">", 'post' => "</p>\n"], |
|
| 115 | - // Les simples $x^2$ en mode 'span' |
|
| 116 | - ['str' => '$', 'preg' => ',[$]([^$]+)[$],'], |
|
| 117 | - ]; |
|
| 118 | - foreach ($traitements as $t) { |
|
| 119 | - while ( |
|
| 120 | - str_contains($texte_milieu, $t['str']) |
|
| 121 | - && preg_match($t['preg'], $texte_milieu, $regs) |
|
| 122 | - ) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = produire_image_math($expression); |
|
| 128 | - $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 129 | - $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
|
| 130 | - |
|
| 131 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | - $texte_milieu = substr_replace($texte_milieu, $echap, $pos, strlen($regs[0])); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $letexte = substr_replace($letexte, $texte_milieu, $c['pos'], $c['length']); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $letexte; |
|
| 105 | + $collecteurMath = new CollecteurHtmlTag('math', '@<math>(.*)(</math>|$)@iUsS', ''); |
|
| 106 | + $collection = $collecteurMath->collecter($letexte); |
|
| 107 | + $collection = array_reverse($collection); |
|
| 108 | + |
|
| 109 | + foreach ($collection as $c) { |
|
| 110 | + $texte_milieu = $c['match'][1]; |
|
| 111 | + |
|
| 112 | + $traitements = [ |
|
| 113 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 114 | + ['str' => '$$', 'preg' => ',[$][$]([^$]+)[$][$],', 'pre' => "\n<p class=\"spip\" style=\"text-align: center;\">", 'post' => "</p>\n"], |
|
| 115 | + // Les simples $x^2$ en mode 'span' |
|
| 116 | + ['str' => '$', 'preg' => ',[$]([^$]+)[$],'], |
|
| 117 | + ]; |
|
| 118 | + foreach ($traitements as $t) { |
|
| 119 | + while ( |
|
| 120 | + str_contains($texte_milieu, $t['str']) |
|
| 121 | + && preg_match($t['preg'], $texte_milieu, $regs) |
|
| 122 | + ) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = produire_image_math($expression); |
|
| 128 | + $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 129 | + $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
|
| 130 | + |
|
| 131 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | + $texte_milieu = substr_replace($texte_milieu, $echap, $pos, strlen($regs[0])); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $letexte = substr_replace($letexte, $texte_milieu, $c['pos'], $c['length']); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $letexte; |
|
| 140 | 140 | } |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 41 | 41 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 42 | 42 | } |
| 43 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 43 | + $fichier = $dir_tex.md5(trim((string) $tex)).$ext; |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | // Aller chercher l'image sur le serveur |
| 47 | 47 | if (!@file_exists($fichier) && $server) { |
| 48 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 48 | + spip_log($url = $server.'?'.rawurlencode((string) $tex)); |
|
| 49 | 49 | include_spip('inc/distant'); |
| 50 | 50 | recuperer_url($url, ['file' => $fichier]); |
| 51 | 51 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | return implode('', file($fichier)); |
| 60 | 60 | } // TeX |
| 61 | 61 | else { |
| 62 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 62 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 63 | 63 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 64 | 64 | |
| 65 | 65 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | 127 | $echap = produire_image_math($expression); |
| 128 | - $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 128 | + $echap = ($t['pre'] ?? '').$echap.($t['post'] ?? ''); |
|
| 129 | 129 | $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
| 130 | 130 | |
| 131 | 131 | $pos = strpos($texte_milieu, (string) $regs[0]); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -30,41 +30,41 @@ discard block |
||
| 30 | 30 | * Mot de passe |
| 31 | 31 | **/ |
| 32 | 32 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 33 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | - |
|
| 35 | - mt_srand($seed); |
|
| 36 | - $s = ''; |
|
| 37 | - $pass = ''; |
|
| 38 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | - if (!$s) { |
|
| 40 | - $s = random_int(0, mt_getrandmax()); |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = random_int(0, mt_getrandmax()); |
|
| 43 | - } |
|
| 44 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | - } |
|
| 46 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | - $x = $r['r'] & 63; |
|
| 48 | - if ($x < 10) { |
|
| 49 | - $x = chr($x + 48); |
|
| 50 | - } else { |
|
| 51 | - if ($x < 36) { |
|
| 52 | - $x = chr($x + 55); |
|
| 53 | - } else { |
|
| 54 | - if ($x < 62) { |
|
| 55 | - $x = chr($x + 61); |
|
| 56 | - } else { |
|
| 57 | - $x = $x == 63 ? '/' : '.'; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - $pass .= $x; |
|
| 62 | - $s = substr($s, 2); |
|
| 63 | - } |
|
| 64 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 65 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 66 | - |
|
| 67 | - return preg_replace('@[0O]@', 'o', $pass); |
|
| 33 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + |
|
| 35 | + mt_srand($seed); |
|
| 36 | + $s = ''; |
|
| 37 | + $pass = ''; |
|
| 38 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | + if (!$s) { |
|
| 40 | + $s = random_int(0, mt_getrandmax()); |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = random_int(0, mt_getrandmax()); |
|
| 43 | + } |
|
| 44 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + } |
|
| 46 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $x = $r['r'] & 63; |
|
| 48 | + if ($x < 10) { |
|
| 49 | + $x = chr($x + 48); |
|
| 50 | + } else { |
|
| 51 | + if ($x < 36) { |
|
| 52 | + $x = chr($x + 55); |
|
| 53 | + } else { |
|
| 54 | + if ($x < 62) { |
|
| 55 | + $x = chr($x + 61); |
|
| 56 | + } else { |
|
| 57 | + $x = $x == 63 ? '/' : '.'; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + $pass .= $x; |
|
| 62 | + $s = substr($s, 2); |
|
| 63 | + } |
|
| 64 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 65 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 66 | + |
|
| 67 | + return preg_replace('@[0O]@', 'o', $pass); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -73,20 +73,20 @@ discard block |
||
| 73 | 73 | * @return string Identifiant |
| 74 | 74 | */ |
| 75 | 75 | function creer_uniqid() { |
| 76 | - static $seeded; |
|
| 76 | + static $seeded; |
|
| 77 | 77 | |
| 78 | - if (!$seeded) { |
|
| 79 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 80 | - mt_srand($seed); |
|
| 81 | - $seeded = true; |
|
| 82 | - } |
|
| 78 | + if (!$seeded) { |
|
| 79 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 80 | + mt_srand($seed); |
|
| 81 | + $seeded = true; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $s = random_int(0, mt_getrandmax()); |
|
| 85 | - if (!$s) { |
|
| 86 | - $s = random_int(0, mt_getrandmax()); |
|
| 87 | - } |
|
| 84 | + $s = random_int(0, mt_getrandmax()); |
|
| 85 | + if (!$s) { |
|
| 86 | + $s = random_int(0, mt_getrandmax()); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return uniqid((string) $s, true); |
|
| 89 | + return uniqid((string) $s, true); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -100,42 +100,42 @@ discard block |
||
| 100 | 100 | * @return string Retourne l'alea éphemère actuel au passage |
| 101 | 101 | */ |
| 102 | 102 | function charger_aleas() { |
| 103 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 104 | - include_spip('base/abstract_sql'); |
|
| 105 | - $aleas = sql_allfetsel( |
|
| 106 | - ['nom', 'valeur'], |
|
| 107 | - 'spip_meta', |
|
| 108 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 109 | - '', |
|
| 110 | - '', |
|
| 111 | - '', |
|
| 112 | - '', |
|
| 113 | - '', |
|
| 114 | - 'continue' |
|
| 115 | - ); |
|
| 116 | - if ($aleas) { |
|
| 117 | - foreach ($aleas as $a) { |
|
| 118 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 119 | - } |
|
| 120 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 121 | - } else { |
|
| 122 | - spip_log('aleas indisponibles', 'session'); |
|
| 123 | - return ''; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 103 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 104 | + include_spip('base/abstract_sql'); |
|
| 105 | + $aleas = sql_allfetsel( |
|
| 106 | + ['nom', 'valeur'], |
|
| 107 | + 'spip_meta', |
|
| 108 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 109 | + '', |
|
| 110 | + '', |
|
| 111 | + '', |
|
| 112 | + '', |
|
| 113 | + '', |
|
| 114 | + 'continue' |
|
| 115 | + ); |
|
| 116 | + if ($aleas) { |
|
| 117 | + foreach ($aleas as $a) { |
|
| 118 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 119 | + } |
|
| 120 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 121 | + } else { |
|
| 122 | + spip_log('aleas indisponibles', 'session'); |
|
| 123 | + return ''; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 131 | 131 | **/ |
| 132 | 132 | function renouvelle_alea() { |
| 133 | - charger_aleas(); |
|
| 134 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 135 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 136 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 137 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 138 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 133 | + charger_aleas(); |
|
| 134 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 135 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 136 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 137 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 138 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
@@ -155,21 +155,21 @@ discard block |
||
| 155 | 155 | * Clé de sécurité. |
| 156 | 156 | **/ |
| 157 | 157 | function low_sec($id_auteur) { |
| 158 | - // Pas d'id_auteur : low_sec |
|
| 159 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 160 | - include_spip('inc/config'); |
|
| 161 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 162 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 163 | - } |
|
| 164 | - } else { |
|
| 165 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur); |
|
| 166 | - if (!$low_sec) { |
|
| 167 | - $low_sec = creer_pass_aleatoire(); |
|
| 168 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $low_sec; |
|
| 158 | + // Pas d'id_auteur : low_sec |
|
| 159 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 160 | + include_spip('inc/config'); |
|
| 161 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 162 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 163 | + } |
|
| 164 | + } else { |
|
| 165 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur); |
|
| 166 | + if (!$low_sec) { |
|
| 167 | + $low_sec = creer_pass_aleatoire(); |
|
| 168 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $low_sec; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | * @filtre |
| 203 | 203 | */ |
| 204 | 204 | function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') { |
| 205 | - if ($op) { |
|
| 206 | - $dir .= " $op $args"; |
|
| 207 | - } |
|
| 205 | + if ($op) { |
|
| 206 | + $dir .= " $op $args"; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 209 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | 216 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 217 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 218 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 219 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 217 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 218 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 219 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 220 | 220 | |
| 221 | - return generer_url_api($script, $path, $args, $no_entities, $public); |
|
| 221 | + return generer_url_api($script, $path, $args, $no_entities, $public); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * Clé |
| 235 | 235 | **/ |
| 236 | 236 | function afficher_low_sec($id_auteur, $action = '') { |
| 237 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 237 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * true si les clés corresponde, false sinon |
| 253 | 253 | **/ |
| 254 | 254 | function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') { |
| 255 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 255 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -262,10 +262,10 @@ discard block |
||
| 262 | 262 | * Identifiant de l'auteur |
| 263 | 263 | **/ |
| 264 | 264 | function effacer_low_sec($id_auteur) { |
| 265 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 266 | - return; |
|
| 267 | - } // jamais trop prudent ;) |
|
| 268 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur); |
|
| 265 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 266 | + return; |
|
| 267 | + } // jamais trop prudent ;) |
|
| 268 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -283,29 +283,29 @@ discard block |
||
| 283 | 283 | * - void sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function ecrire_acces() { |
| 286 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 287 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 288 | - |
|
| 289 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 290 | - // par exemple acces_restreint ; |
|
| 291 | - // si .htaccess existe, outrepasser spip_meta |
|
| 292 | - if ( |
|
| 293 | - (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 294 | - ) { |
|
| 295 | - spip_unlink($htpasswd); |
|
| 296 | - spip_unlink($htpasswd . '-admin'); |
|
| 297 | - return; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 301 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 302 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 303 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 304 | - if (include_spip('auth/ldap') && auth_ldap_connect()) { |
|
| 305 | - return; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 286 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 287 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 288 | + |
|
| 289 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 290 | + // par exemple acces_restreint ; |
|
| 291 | + // si .htaccess existe, outrepasser spip_meta |
|
| 292 | + if ( |
|
| 293 | + (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 294 | + ) { |
|
| 295 | + spip_unlink($htpasswd); |
|
| 296 | + spip_unlink($htpasswd . '-admin'); |
|
| 297 | + return; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 301 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 302 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 303 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 304 | + if (include_spip('auth/ldap') && auth_ldap_connect()) { |
|
| 305 | + return; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -314,29 +314,29 @@ discard block |
||
| 314 | 314 | * @param string $htpasswd_admin |
| 315 | 315 | */ |
| 316 | 316 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 317 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 318 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $pwd_all = ''; // login:htpass pour tous |
|
| 322 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 323 | - |
|
| 324 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 325 | - while ($row = sql_fetch($res)) { |
|
| 326 | - if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) { |
|
| 327 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 328 | - $pwd_all .= $ligne; |
|
| 329 | - if ($row['statut'] == '0minirezo') { |
|
| 330 | - $pwd_admin .= $ligne; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ($pwd_all) { |
|
| 336 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 337 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 338 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 339 | - } |
|
| 317 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 318 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $pwd_all = ''; // login:htpass pour tous |
|
| 322 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 323 | + |
|
| 324 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 325 | + while ($row = sql_fetch($res)) { |
|
| 326 | + if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) { |
|
| 327 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 328 | + $pwd_all .= $ligne; |
|
| 329 | + if ($row['statut'] == '0minirezo') { |
|
| 330 | + $pwd_admin .= $ligne; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ($pwd_all) { |
|
| 336 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 337 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 338 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 339 | + } |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 351 | 351 | */ |
| 352 | 352 | function generer_htpass(#[\SensitiveParameter] $pass) { |
| 353 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 354 | - return $generer_htpass($pass); |
|
| 355 | - } |
|
| 353 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 354 | + return $generer_htpass($pass); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - return ''; |
|
| 357 | + return ''; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -367,14 +367,14 @@ discard block |
||
| 367 | 367 | * @return boolean |
| 368 | 368 | */ |
| 369 | 369 | function verifier_htaccess($rep, $force = false) { |
| 370 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 371 | - if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) { |
|
| 372 | - return true; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // directive deny compatible Apache 2.0+ |
|
| 376 | - $deny = |
|
| 377 | - '# Deny all requests from Apache 2.4+. |
|
| 370 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 371 | + if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) { |
|
| 372 | + return true; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // directive deny compatible Apache 2.0+ |
|
| 376 | + $deny = |
|
| 377 | + '# Deny all requests from Apache 2.4+. |
|
| 378 | 378 | <IfModule mod_authz_core.c> |
| 379 | 379 | Require all denied |
| 380 | 380 | </IfModule> |
@@ -383,30 +383,30 @@ discard block |
||
| 383 | 383 | Deny from all |
| 384 | 384 | </IfModule> |
| 385 | 385 | '; |
| 386 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 387 | - if ( |
|
| 388 | - function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.') |
|
| 389 | - ) { |
|
| 390 | - $deny = "deny from all\n"; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 394 | - fwrite($ht, $deny); |
|
| 395 | - fclose($ht); |
|
| 396 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 397 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 398 | - if ($ht = @fopen($t, 'w')) { |
|
| 399 | - @fclose($ht); |
|
| 400 | - include_spip('inc/distant'); |
|
| 401 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 402 | - $t = url_de_base() . $t; |
|
| 403 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 404 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 408 | - |
|
| 409 | - return $ht; |
|
| 386 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 387 | + if ( |
|
| 388 | + function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.') |
|
| 389 | + ) { |
|
| 390 | + $deny = "deny from all\n"; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 394 | + fwrite($ht, $deny); |
|
| 395 | + fclose($ht); |
|
| 396 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 397 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 398 | + if ($ht = @fopen($t, 'w')) { |
|
| 399 | + @fclose($ht); |
|
| 400 | + include_spip('inc/distant'); |
|
| 401 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 402 | + $t = url_de_base() . $t; |
|
| 403 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 404 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 408 | + |
|
| 409 | + return $ht; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -424,20 +424,20 @@ discard block |
||
| 424 | 424 | * Valeur de la configuration `creer_htaccess` |
| 425 | 425 | */ |
| 426 | 426 | function gerer_htaccess() { |
| 427 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 428 | - // par exemple acces_restreint |
|
| 429 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui'); |
|
| 430 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 431 | - $dirs[] = ['extension' => 'distant']; |
|
| 432 | - foreach ($dirs as $e) { |
|
| 433 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 434 | - if ($f) { |
|
| 435 | - verifier_htaccess($dir); |
|
| 436 | - } else { |
|
| 437 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 427 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 428 | + // par exemple acces_restreint |
|
| 429 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui'); |
|
| 430 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 431 | + $dirs[] = ['extension' => 'distant']; |
|
| 432 | + foreach ($dirs as $e) { |
|
| 433 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 434 | + if ($f) { |
|
| 435 | + verifier_htaccess($dir); |
|
| 436 | + } else { |
|
| 437 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 443 | 443 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * Mot de passe |
| 31 | 31 | **/ |
| 32 | 32 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 33 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 33 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 34 | 34 | |
| 35 | 35 | mt_srand($seed); |
| 36 | 36 | $s = ''; |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | if (!$s) { |
| 42 | 42 | $s = random_int(0, mt_getrandmax()); |
| 43 | 43 | } |
| 44 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 44 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 45 | 45 | } |
| 46 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 46 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 47 | 47 | $x = $r['r'] & 63; |
| 48 | 48 | if ($x < 10) { |
| 49 | 49 | $x = chr($x + 48); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | static $seeded; |
| 77 | 77 | |
| 78 | 78 | if (!$seeded) { |
| 79 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 79 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 80 | 80 | mt_srand($seed); |
| 81 | 81 | $seeded = true; |
| 82 | 82 | } |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 163 | 163 | } |
| 164 | 164 | } else { |
| 165 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur); |
|
| 165 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.(int) $id_auteur); |
|
| 166 | 166 | if (!$low_sec) { |
| 167 | 167 | $low_sec = creer_pass_aleatoire(); |
| 168 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur); |
|
| 168 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.(int) $id_auteur); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 217 | 217 | $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
| 218 | 218 | $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
| 219 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 219 | + $path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : ''); |
|
| 220 | 220 | |
| 221 | 221 | return generer_url_api($script, $path, $args, $no_entities, $public); |
| 222 | 222 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * Clé |
| 235 | 235 | **/ |
| 236 | 236 | function afficher_low_sec($id_auteur, $action = '') { |
| 237 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 237 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | if (!$id_auteur = (int) $id_auteur) { |
| 266 | 266 | return; |
| 267 | 267 | } // jamais trop prudent ;) |
| 268 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur); |
|
| 268 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.(int) $id_auteur); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * - void sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function ecrire_acces() { |
| 286 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 287 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 286 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 287 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 288 | 288 | |
| 289 | 289 | // Cette variable de configuration peut etre posee par un plugin |
| 290 | 290 | // par exemple acces_restreint ; |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
| 294 | 294 | ) { |
| 295 | 295 | spip_unlink($htpasswd); |
| 296 | - spip_unlink($htpasswd . '-admin'); |
|
| 296 | + spip_unlink($htpasswd.'-admin'); |
|
| 297 | 297 | return; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | $pwd_all = ''; // login:htpass pour tous |
| 322 | 322 | $pwd_admin = ''; // login:htpass pour les admins |
| 323 | 323 | |
| 324 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 324 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 325 | 325 | while ($row = sql_fetch($res)) { |
| 326 | 326 | if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) { |
| 327 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 327 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 328 | 328 | $pwd_all .= $ligne; |
| 329 | 329 | if ($row['statut'] == '0minirezo') { |
| 330 | 330 | $pwd_admin .= $ligne; |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | * @return boolean |
| 368 | 368 | */ |
| 369 | 369 | function verifier_htaccess($rep, $force = false) { |
| 370 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 370 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 371 | 371 | if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) { |
| 372 | 372 | return true; |
| 373 | 373 | } |
@@ -394,17 +394,17 @@ discard block |
||
| 394 | 394 | fwrite($ht, $deny); |
| 395 | 395 | fclose($ht); |
| 396 | 396 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 397 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 397 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 398 | 398 | if ($ht = @fopen($t, 'w')) { |
| 399 | 399 | @fclose($ht); |
| 400 | 400 | include_spip('inc/distant'); |
| 401 | 401 | $t = substr($t, strlen(_DIR_RACINE)); |
| 402 | - $t = url_de_base() . $t; |
|
| 402 | + $t = url_de_base().$t; |
|
| 403 | 403 | $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
| 404 | 404 | $ht = ($ht['status'] ?? null) === 403; |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 407 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 408 | 408 | |
| 409 | 409 | return $ht; |
| 410 | 410 | } |
@@ -430,11 +430,11 @@ discard block |
||
| 430 | 430 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 431 | 431 | $dirs[] = ['extension' => 'distant']; |
| 432 | 432 | foreach ($dirs as $e) { |
| 433 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 433 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 434 | 434 | if ($f) { |
| 435 | 435 | verifier_htaccess($dir); |
| 436 | 436 | } else { |
| 437 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 437 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | } |
@@ -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('base/objets'); |
| 22 | 22 | |
@@ -56,106 +56,106 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | */ |
| 58 | 58 | function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) { |
| 59 | - static $current_base = null; |
|
| 59 | + static $current_base = null; |
|
| 60 | 60 | |
| 61 | - // les anciennes fonctions modifient directement les globales |
|
| 62 | - // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | - $save = [ |
|
| 64 | - $GLOBALS['fond'] ?? null, |
|
| 65 | - $GLOBALS['contexte'] ?? null, |
|
| 66 | - $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | - $_ENV['url_propre'] ?? null, |
|
| 68 | - $GLOBALS['profondeur_url'] |
|
| 69 | - ]; |
|
| 61 | + // les anciennes fonctions modifient directement les globales |
|
| 62 | + // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | + $save = [ |
|
| 64 | + $GLOBALS['fond'] ?? null, |
|
| 65 | + $GLOBALS['contexte'] ?? null, |
|
| 66 | + $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | + $_ENV['url_propre'] ?? null, |
|
| 68 | + $GLOBALS['profondeur_url'] |
|
| 69 | + ]; |
|
| 70 | 70 | |
| 71 | - if (is_null($current_base)) { |
|
| 72 | - include_spip('inc/filtres_mini'); |
|
| 73 | - // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | - $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | - } |
|
| 76 | - if (str_starts_with($url, $current_base)) { |
|
| 77 | - $url = substr($url, strlen($current_base)); |
|
| 78 | - } |
|
| 71 | + if (is_null($current_base)) { |
|
| 72 | + include_spip('inc/filtres_mini'); |
|
| 73 | + // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | + $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | + } |
|
| 76 | + if (str_starts_with($url, $current_base)) { |
|
| 77 | + $url = substr($url, strlen($current_base)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // si on est en train d'assembler la page principale, |
|
| 81 | - // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | - // sinon extraire la bonne portion d'url |
|
| 83 | - if ($assembler) { |
|
| 84 | - if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | - $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | - } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | - $url = $_ENV['url_propre']; |
|
| 88 | - } else { |
|
| 89 | - $qs = explode('?', $url); |
|
| 90 | - // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | - $url = ltrim($qs[0], '/'); |
|
| 92 | - $url = explode('/', $url); |
|
| 93 | - while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | - array_shift($url); |
|
| 95 | - } |
|
| 96 | - $qs[0] = implode('/', $url); |
|
| 97 | - $url = implode('?', $qs); |
|
| 98 | - } |
|
| 99 | - } |
|
| 80 | + // si on est en train d'assembler la page principale, |
|
| 81 | + // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | + // sinon extraire la bonne portion d'url |
|
| 83 | + if ($assembler) { |
|
| 84 | + if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | + $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | + } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | + $url = $_ENV['url_propre']; |
|
| 88 | + } else { |
|
| 89 | + $qs = explode('?', $url); |
|
| 90 | + // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | + $url = ltrim($qs[0], '/'); |
|
| 92 | + $url = explode('/', $url); |
|
| 93 | + while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | + array_shift($url); |
|
| 95 | + } |
|
| 96 | + $qs[0] = implode('/', $url); |
|
| 97 | + $url = implode('?', $qs); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | - unset($_ENV['url_propre']); |
|
| 103 | - include_spip('inc/filtres_mini'); |
|
| 104 | - if (!str_contains($url, '://')) { |
|
| 105 | - $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | - } else { |
|
| 107 | - $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | - } |
|
| 101 | + unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | + unset($_ENV['url_propre']); |
|
| 103 | + include_spip('inc/filtres_mini'); |
|
| 104 | + if (!str_contains($url, '://')) { |
|
| 105 | + $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | + } else { |
|
| 107 | + $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - $url_redirect = ''; |
|
| 111 | - $decoder = charger_fonction_url('decoder'); |
|
| 112 | - if ($decoder) { |
|
| 113 | - $a = $decoder($url, $fond, $contexte); |
|
| 114 | - if (is_array($a)) { |
|
| 115 | - [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | - $url_redirect ??= ''; |
|
| 117 | - if ($url_redirect === $url) { |
|
| 118 | - $url_redirect = ''; |
|
| 119 | - } // securite pour eviter une redirection infinie |
|
| 120 | - if ($assembler && strlen($url_redirect)) { |
|
| 121 | - spip_log("Redirige $url vers $url_redirect"); |
|
| 122 | - include_spip('inc/headers'); |
|
| 123 | - redirige_par_entete($url_redirect, '', 301); |
|
| 124 | - } |
|
| 125 | - if (isset($nfond)) { |
|
| 126 | - $fond = $nfond; |
|
| 127 | - } else { |
|
| 128 | - if ( |
|
| 129 | - $fond == '' |
|
| 130 | - || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | - ) { |
|
| 132 | - $fond = $type; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (isset($ncontexte)) { |
|
| 136 | - $contexte = $ncontexte; |
|
| 137 | - } |
|
| 138 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | - $contexte['type'] = $type; |
|
| 140 | - } |
|
| 141 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | - $contexte['type-page'] = $type; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 110 | + $url_redirect = ''; |
|
| 111 | + $decoder = charger_fonction_url('decoder'); |
|
| 112 | + if ($decoder) { |
|
| 113 | + $a = $decoder($url, $fond, $contexte); |
|
| 114 | + if (is_array($a)) { |
|
| 115 | + [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | + $url_redirect ??= ''; |
|
| 117 | + if ($url_redirect === $url) { |
|
| 118 | + $url_redirect = ''; |
|
| 119 | + } // securite pour eviter une redirection infinie |
|
| 120 | + if ($assembler && strlen($url_redirect)) { |
|
| 121 | + spip_log("Redirige $url vers $url_redirect"); |
|
| 122 | + include_spip('inc/headers'); |
|
| 123 | + redirige_par_entete($url_redirect, '', 301); |
|
| 124 | + } |
|
| 125 | + if (isset($nfond)) { |
|
| 126 | + $fond = $nfond; |
|
| 127 | + } else { |
|
| 128 | + if ( |
|
| 129 | + $fond == '' |
|
| 130 | + || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | + ) { |
|
| 132 | + $fond = $type; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (isset($ncontexte)) { |
|
| 136 | + $contexte = $ncontexte; |
|
| 137 | + } |
|
| 138 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | + $contexte['type'] = $type; |
|
| 140 | + } |
|
| 141 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | + $contexte['type-page'] = $type; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - // retablir les globales |
|
| 148 | - [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 147 | + // retablir les globales |
|
| 148 | + [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 149 | 149 | |
| 150 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | - // d'inversion url => objet |
|
| 152 | - // maintenir pour compat ? |
|
| 153 | - #if ($assembler) { |
|
| 154 | - # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | - # unset($_ENV['url_propre']); |
|
| 156 | - #} |
|
| 150 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | + // d'inversion url => objet |
|
| 152 | + // maintenir pour compat ? |
|
| 153 | + #if ($assembler) { |
|
| 154 | + # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | + # unset($_ENV['url_propre']); |
|
| 156 | + #} |
|
| 157 | 157 | |
| 158 | - return [$fond, $contexte, $url_redirect]; |
|
| 158 | + return [$fond, $contexte, $url_redirect]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 164 | 164 | */ |
| 165 | 165 | function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array { |
| 166 | - if ($url_propre) { |
|
| 167 | - if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | - $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | - } else { |
|
| 170 | - $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | - } |
|
| 166 | + if ($url_propre) { |
|
| 167 | + if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | + $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | + } else { |
|
| 170 | + $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($urls_anciennes) { |
|
| 174 | - $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | - } |
|
| 176 | - return $urls_anciennes ?: []; |
|
| 177 | - } |
|
| 173 | + if ($urls_anciennes) { |
|
| 174 | + $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | + } |
|
| 176 | + return $urls_anciennes ?: []; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - return []; |
|
| 179 | + return []; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -184,41 +184,41 @@ discard block |
||
| 184 | 184 | * le mode 'urls-html/standard' vers les modes 'urls propres|arbos' |
| 185 | 185 | */ |
| 186 | 186 | function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array { |
| 187 | - // Migration depuis anciennes URLs ? |
|
| 188 | - // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | - if ( |
|
| 190 | - $url |
|
| 191 | - && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | - ) { |
|
| 193 | - $r = nettoyer_url_page($url, $contexte); |
|
| 194 | - if ($r) { |
|
| 195 | - [$contexte, $type, , , $suite] = $r; |
|
| 196 | - $_id = id_table_objet($type); |
|
| 197 | - $id_objet = $contexte[$_id]; |
|
| 198 | - $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | - if ( |
|
| 200 | - strlen($url_propre) |
|
| 201 | - && !strstr($url, (string) $url_propre) |
|
| 202 | - && ( |
|
| 203 | - objet_test_si_publie($type, $id_objet) |
|
| 204 | - || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | - $args = []; |
|
| 209 | - foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | - if ($fragment != "$_id=$id_objet") { |
|
| 211 | - $args[] = $fragment; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 187 | + // Migration depuis anciennes URLs ? |
|
| 188 | + // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | + if ( |
|
| 190 | + $url |
|
| 191 | + && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | + ) { |
|
| 193 | + $r = nettoyer_url_page($url, $contexte); |
|
| 194 | + if ($r) { |
|
| 195 | + [$contexte, $type, , , $suite] = $r; |
|
| 196 | + $_id = id_table_objet($type); |
|
| 197 | + $id_objet = $contexte[$_id]; |
|
| 198 | + $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | + if ( |
|
| 200 | + strlen($url_propre) |
|
| 201 | + && !strstr($url, (string) $url_propre) |
|
| 202 | + && ( |
|
| 203 | + objet_test_si_publie($type, $id_objet) |
|
| 204 | + || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | + $args = []; |
|
| 209 | + foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | + if ($fragment != "$_id=$id_objet") { |
|
| 211 | + $args[] = $fragment; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 215 | 215 | |
| 216 | - return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - /* Fin compatibilite anciennes urls */ |
|
| 221 | - return []; |
|
| 216 | + return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + /* Fin compatibilite anciennes urls */ |
|
| 221 | + return []; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -231,24 +231,24 @@ discard block |
||
| 231 | 231 | * @return string|array |
| 232 | 232 | */ |
| 233 | 233 | function urls_liste_objets($preg = true) { |
| 234 | - static $url_objets = null; |
|
| 235 | - if (is_null($url_objets)) { |
|
| 236 | - $url_objets = []; |
|
| 237 | - // recuperer les tables_objets_sql declarees |
|
| 238 | - $tables_objets = lister_tables_objets_sql(); |
|
| 239 | - foreach ($tables_objets as $t => $infos) { |
|
| 240 | - if ($infos['page']) { |
|
| 241 | - $url_objets[] = $infos['type']; |
|
| 242 | - $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | - } |
|
| 247 | - if (!$preg) { |
|
| 248 | - return $url_objets; |
|
| 249 | - } |
|
| 234 | + static $url_objets = null; |
|
| 235 | + if (is_null($url_objets)) { |
|
| 236 | + $url_objets = []; |
|
| 237 | + // recuperer les tables_objets_sql declarees |
|
| 238 | + $tables_objets = lister_tables_objets_sql(); |
|
| 239 | + foreach ($tables_objets as $t => $infos) { |
|
| 240 | + if ($infos['page']) { |
|
| 241 | + $url_objets[] = $infos['type']; |
|
| 242 | + $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | + } |
|
| 247 | + if (!$preg) { |
|
| 248 | + return $url_objets; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return implode('|', array_map('preg_quote', $url_objets)); |
|
| 251 | + return implode('|', array_map('preg_quote', $url_objets)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -262,26 +262,26 @@ discard block |
||
| 262 | 262 | * @return array |
| 263 | 263 | */ |
| 264 | 264 | function nettoyer_url_page($url, $contexte = []) { |
| 265 | - $url_objets = urls_liste_objets(); |
|
| 266 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 265 | + $url_objets = urls_liste_objets(); |
|
| 266 | + $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | + $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | - || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | - || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | - ) { |
|
| 275 | - $regs = array_pad($regs, 4, null); |
|
| 276 | - $type = objet_type($regs[1]); |
|
| 277 | - $_id = id_table_objet($type); |
|
| 278 | - $contexte[$_id] = $regs[2]; |
|
| 279 | - $suite = $regs[3]; |
|
| 270 | + if ( |
|
| 271 | + preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | + || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | + || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | + ) { |
|
| 275 | + $regs = array_pad($regs, 4, null); |
|
| 276 | + $type = objet_type($regs[1]); |
|
| 277 | + $_id = id_table_objet($type); |
|
| 278 | + $contexte[$_id] = $regs[2]; |
|
| 279 | + $suite = $regs[3]; |
|
| 280 | 280 | |
| 281 | - return [$contexte, $type, null, $type, $suite]; |
|
| 282 | - } |
|
| 281 | + return [$contexte, $type, null, $type, $suite]; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - return []; |
|
| 284 | + return []; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -299,35 +299,35 @@ discard block |
||
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | 301 | function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string { |
| 302 | - static $furls = []; |
|
| 303 | - $id = intval($id); |
|
| 304 | - if (!isset($furls[$objet])) { |
|
| 305 | - if ( |
|
| 306 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | - || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | - || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | - || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | - ) { |
|
| 311 | - $furls[$objet] = $f; |
|
| 312 | - } else { |
|
| 313 | - $furls[$objet] = ''; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - if ($furls[$objet]) { |
|
| 317 | - return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | - } |
|
| 319 | - // si pas de flag public fourni |
|
| 320 | - // le calculer en fonction de la declaration de statut |
|
| 321 | - if (is_null($public) && !$connect) { |
|
| 322 | - $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | - } |
|
| 324 | - if ($public || $connect) { |
|
| 325 | - return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | - } |
|
| 327 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | - if (!function_exists('objet_info')) { |
|
| 329 | - include_spip('inc/filtres'); |
|
| 330 | - } |
|
| 302 | + static $furls = []; |
|
| 303 | + $id = intval($id); |
|
| 304 | + if (!isset($furls[$objet])) { |
|
| 305 | + if ( |
|
| 306 | + function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | + || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | + || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | + || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | + ) { |
|
| 311 | + $furls[$objet] = $f; |
|
| 312 | + } else { |
|
| 313 | + $furls[$objet] = ''; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + if ($furls[$objet]) { |
|
| 317 | + return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | + } |
|
| 319 | + // si pas de flag public fourni |
|
| 320 | + // le calculer en fonction de la declaration de statut |
|
| 321 | + if (is_null($public) && !$connect) { |
|
| 322 | + $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | + } |
|
| 324 | + if ($public || $connect) { |
|
| 325 | + return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | + } |
|
| 327 | + $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | + if (!function_exists('objet_info')) { |
|
| 329 | + include_spip('inc/filtres'); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 332 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 333 | 333 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | ) { |
| 193 | 193 | $r = nettoyer_url_page($url, $contexte); |
| 194 | 194 | if ($r) { |
| 195 | - [$contexte, $type, , , $suite] = $r; |
|
| 195 | + [$contexte, $type,,, $suite] = $r; |
|
| 196 | 196 | $_id = id_table_objet($type); |
| 197 | 197 | $id_objet = $contexte[$_id]; |
| 198 | 198 | $url_propre = generer_objet_url($id_objet, $type); |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function nettoyer_url_page($url, $contexte = []) { |
| 265 | 265 | $url_objets = urls_liste_objets(); |
| 266 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 266 | + $raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | + $raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,'; |
|
| 269 | 269 | |
| 270 | 270 | if ( |
| 271 | 271 | preg_match($raccourci_url_page_html, $url, $regs) |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | $id = intval($id); |
| 304 | 304 | if (!isset($furls[$objet])) { |
| 305 | 305 | if ( |
| 306 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 306 | + function_exists($f = 'generer_'.$objet.'_url_ecrire') |
|
| 307 | 307 | || ($f = charger_fonction($f, 'urls', true)) |
| 308 | - || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 308 | + || function_exists($f = 'generer_url_ecrire_'.$objet) // deprecated |
|
| 309 | 309 | || ($f = charger_fonction($f, 'urls', true)) // deprecated |
| 310 | 310 | ) { |
| 311 | 311 | $furls[$objet] = $f; |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | if ($public || $connect) { |
| 325 | 325 | return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
| 326 | 326 | } |
| 327 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 327 | + $a = id_table_objet($objet).'='.intval($id); |
|
| 328 | 328 | if (!function_exists('objet_info')) { |
| 329 | 329 | include_spip('inc/filtres'); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 332 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : ''); |
|
| 333 | 333 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -54,65 +54,65 @@ discard block |
||
| 54 | 54 | * @return void |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 57 | - $statuts_publies = null; |
|
| 58 | - $neuf = false; |
|
| 59 | - |
|
| 60 | - // Compat avec l'ancienne signature |
|
| 61 | - if (is_string($infos)) { |
|
| 62 | - $infos = ['statut_ancien' => $infos]; |
|
| 63 | - } |
|
| 64 | - if (!isset($infos['statut_ancien'])) { |
|
| 65 | - $infos['statut_ancien'] = ''; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // On recherche quels statuts tester |
|
| 69 | - if ( |
|
| 70 | - isset($infos['objet']) |
|
| 71 | - && include_spip('inc/filtres') |
|
| 72 | - && ($declaration_statut = objet_info($infos['objet'], 'statut')) |
|
| 73 | - && is_array($declaration_statut) |
|
| 74 | - ) { |
|
| 75 | - foreach ($declaration_statut as $champ_statut) { |
|
| 76 | - if ($champ_statut['champ'] == 'statut') { |
|
| 77 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | - break; // stop on a trouvé le bon champ |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } else { |
|
| 82 | - $statuts_publies = ['publie']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if ( |
|
| 87 | - isset($modifs['statut']) |
|
| 88 | - || isset($modifs['id_rubrique']) |
|
| 89 | - || $postdate && strtotime($postdate) > time() |
|
| 90 | - ) { |
|
| 91 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | - } |
|
| 93 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | - if ($postdate) { |
|
| 95 | - calculer_prochain_postdate(true); |
|
| 96 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | - } |
|
| 100 | - } elseif (isset($modifs['statut']) && in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | - if ($postdate) { |
|
| 102 | - calculer_prochain_postdate(true); |
|
| 103 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | - } else { |
|
| 105 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($neuf) { |
|
| 110 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $langues = calculer_langues_utilisees(); |
|
| 115 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $statuts_publies = null; |
|
| 58 | + $neuf = false; |
|
| 59 | + |
|
| 60 | + // Compat avec l'ancienne signature |
|
| 61 | + if (is_string($infos)) { |
|
| 62 | + $infos = ['statut_ancien' => $infos]; |
|
| 63 | + } |
|
| 64 | + if (!isset($infos['statut_ancien'])) { |
|
| 65 | + $infos['statut_ancien'] = ''; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // On recherche quels statuts tester |
|
| 69 | + if ( |
|
| 70 | + isset($infos['objet']) |
|
| 71 | + && include_spip('inc/filtres') |
|
| 72 | + && ($declaration_statut = objet_info($infos['objet'], 'statut')) |
|
| 73 | + && is_array($declaration_statut) |
|
| 74 | + ) { |
|
| 75 | + foreach ($declaration_statut as $champ_statut) { |
|
| 76 | + if ($champ_statut['champ'] == 'statut') { |
|
| 77 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | + break; // stop on a trouvé le bon champ |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + $statuts_publies = ['publie']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if ( |
|
| 87 | + isset($modifs['statut']) |
|
| 88 | + || isset($modifs['id_rubrique']) |
|
| 89 | + || $postdate && strtotime($postdate) > time() |
|
| 90 | + ) { |
|
| 91 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | + } |
|
| 93 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | + if ($postdate) { |
|
| 95 | + calculer_prochain_postdate(true); |
|
| 96 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | + } |
|
| 100 | + } elseif (isset($modifs['statut']) && in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | + if ($postdate) { |
|
| 102 | + calculer_prochain_postdate(true); |
|
| 103 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | + } else { |
|
| 105 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($neuf) { |
|
| 110 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $langues = calculer_langues_utilisees(); |
|
| 115 | + ecrire_meta('langues_utilisees', $langues); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | * true si le statut change effectivement |
| 131 | 131 | */ |
| 132 | 132 | function publier_branche_rubrique($id_rubrique) { |
| 133 | - $id_pred = $id_rubrique; |
|
| 134 | - while (true) { |
|
| 135 | - sql_updateq( |
|
| 136 | - 'spip_rubriques', |
|
| 137 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | - ); |
|
| 140 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | - if (!$id_parent) { |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - $id_rubrique = $id_parent; |
|
| 145 | - } |
|
| 133 | + $id_pred = $id_rubrique; |
|
| 134 | + while (true) { |
|
| 135 | + sql_updateq( |
|
| 136 | + 'spip_rubriques', |
|
| 137 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | + ); |
|
| 140 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | + if (!$id_parent) { |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + $id_rubrique = $id_parent; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 148 | - return $id_pred != $id_rubrique; |
|
| 148 | + return $id_pred != $id_rubrique; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * true si le statut change effectivement |
| 164 | 164 | */ |
| 165 | 165 | function depublier_branche_rubrique_if($id_rubrique) { |
| 166 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | - |
|
| 168 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | - $id_pred = $id_rubrique; |
|
| 170 | - while ($id_pred) { |
|
| 171 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | - return $id_pred != $id_rubrique; |
|
| 173 | - } |
|
| 174 | - // passer au parent si on a depublie |
|
| 175 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | - $id_pred = $r['id_parent']; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $id_pred != $id_rubrique; |
|
| 166 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | + |
|
| 168 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | + $id_pred = $id_rubrique; |
|
| 170 | + while ($id_pred) { |
|
| 171 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | + return $id_pred != $id_rubrique; |
|
| 173 | + } |
|
| 174 | + // passer au parent si on a depublie |
|
| 175 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | + $id_pred = $r['id_parent']; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $id_pred != $id_rubrique; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -193,61 +193,61 @@ discard block |
||
| 193 | 193 | * true si la rubrique a été dépubliée |
| 194 | 194 | */ |
| 195 | 195 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 196 | - if (is_null($date)) { |
|
| 197 | - $date = date('Y-m-d H:i:s'); |
|
| 198 | - } |
|
| 199 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | - |
|
| 202 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // verifier qu'elle existe et est bien publiee |
|
| 207 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | - if (!$r || $r['statut'] !== 'publie') { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | - // Le type de l'objet est au pluriel |
|
| 214 | - $compte = [ |
|
| 215 | - 'articles' => sql_countsel( |
|
| 216 | - 'spip_articles', |
|
| 217 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | - ), |
|
| 219 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | - 'documents' => sql_countsel( |
|
| 221 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | - ) |
|
| 224 | - ]; |
|
| 225 | - |
|
| 226 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | - $compte = pipeline( |
|
| 228 | - 'objet_compte_enfants', |
|
| 229 | - [ |
|
| 230 | - 'args' => [ |
|
| 231 | - 'objet' => 'rubrique', |
|
| 232 | - 'id_objet' => $id_rubrique, |
|
| 233 | - 'statut' => 'publie', |
|
| 234 | - 'date' => $date |
|
| 235 | - ], |
|
| 236 | - 'data' => $compte |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | - foreach ($compte as $objet => $n) { |
|
| 242 | - if ($n) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 196 | + if (is_null($date)) { |
|
| 197 | + $date = date('Y-m-d H:i:s'); |
|
| 198 | + } |
|
| 199 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | + |
|
| 202 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // verifier qu'elle existe et est bien publiee |
|
| 207 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | + if (!$r || $r['statut'] !== 'publie') { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | + // Le type de l'objet est au pluriel |
|
| 214 | + $compte = [ |
|
| 215 | + 'articles' => sql_countsel( |
|
| 216 | + 'spip_articles', |
|
| 217 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | + ), |
|
| 219 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | + 'documents' => sql_countsel( |
|
| 221 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | + ) |
|
| 224 | + ]; |
|
| 225 | + |
|
| 226 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | + $compte = pipeline( |
|
| 228 | + 'objet_compte_enfants', |
|
| 229 | + [ |
|
| 230 | + 'args' => [ |
|
| 231 | + 'objet' => 'rubrique', |
|
| 232 | + 'id_objet' => $id_rubrique, |
|
| 233 | + 'statut' => 'publie', |
|
| 234 | + 'date' => $date |
|
| 235 | + ], |
|
| 236 | + 'data' => $compte |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | + foreach ($compte as $objet => $n) { |
|
| 242 | + if ($n) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 248 | 248 | |
| 249 | 249 | # spip_log("depublier_rubrique $id_pred"); |
| 250 | - return true; |
|
| 250 | + return true; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | **/ |
| 271 | 271 | function calculer_rubriques() { |
| 272 | 272 | |
| 273 | - calculer_rubriques_publiees(); |
|
| 273 | + calculer_rubriques_publiees(); |
|
| 274 | 274 | |
| 275 | - // Apres chaque (de)publication |
|
| 276 | - // recalculer les langues utilisees sur le site |
|
| 277 | - $langues = calculer_langues_utilisees(); |
|
| 278 | - ecrire_meta('langues_utilisees', $langues); |
|
| 275 | + // Apres chaque (de)publication |
|
| 276 | + // recalculer les langues utilisees sur le site |
|
| 277 | + $langues = calculer_langues_utilisees(); |
|
| 278 | + ecrire_meta('langues_utilisees', $langues); |
|
| 279 | 279 | |
| 280 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 280 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 282 | 282 | |
| 283 | - // on calcule la date du prochain article post-date |
|
| 284 | - calculer_prochain_postdate(); |
|
| 283 | + // on calcule la date du prochain article post-date |
|
| 284 | + calculer_prochain_postdate(); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -298,61 +298,61 @@ discard block |
||
| 298 | 298 | **/ |
| 299 | 299 | function calculer_rubriques_publiees() { |
| 300 | 300 | |
| 301 | - // Mettre les compteurs a zero |
|
| 302 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | - |
|
| 304 | - // |
|
| 305 | - // Publier et dater les rubriques qui ont un article publie |
|
| 306 | - // |
|
| 307 | - |
|
| 308 | - // Afficher les articles post-dates ? |
|
| 309 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | - |
|
| 312 | - $r = sql_select( |
|
| 313 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | - 'R.id_rubrique' |
|
| 317 | - ); |
|
| 318 | - while ($row = sql_fetch($r)) { |
|
| 319 | - sql_updateq( |
|
| 320 | - 'spip_rubriques', |
|
| 321 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | - 'id_rubrique=' . intval($row['id']) |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | - pipeline('calculer_rubriques', null); |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | - do { |
|
| 337 | - $continuer = false; |
|
| 338 | - $r = sql_select( |
|
| 339 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | - 'R.id_rubrique' |
|
| 343 | - ); |
|
| 344 | - while ($row = sql_fetch($r)) { |
|
| 345 | - sql_updateq( |
|
| 346 | - 'spip_rubriques', |
|
| 347 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | - 'id_rubrique=' . intval($row['id']) |
|
| 349 | - ); |
|
| 350 | - $continuer = true; |
|
| 351 | - } |
|
| 352 | - } while ($continuer); |
|
| 353 | - |
|
| 354 | - // Enregistrement des modifs |
|
| 355 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 301 | + // Mettre les compteurs a zero |
|
| 302 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | + |
|
| 304 | + // |
|
| 305 | + // Publier et dater les rubriques qui ont un article publie |
|
| 306 | + // |
|
| 307 | + |
|
| 308 | + // Afficher les articles post-dates ? |
|
| 309 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | + |
|
| 312 | + $r = sql_select( |
|
| 313 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | + 'R.id_rubrique' |
|
| 317 | + ); |
|
| 318 | + while ($row = sql_fetch($r)) { |
|
| 319 | + sql_updateq( |
|
| 320 | + 'spip_rubriques', |
|
| 321 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | + 'id_rubrique=' . intval($row['id']) |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | + pipeline('calculer_rubriques', null); |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | + do { |
|
| 337 | + $continuer = false; |
|
| 338 | + $r = sql_select( |
|
| 339 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | + 'R.id_rubrique' |
|
| 343 | + ); |
|
| 344 | + while ($row = sql_fetch($r)) { |
|
| 345 | + sql_updateq( |
|
| 346 | + 'spip_rubriques', |
|
| 347 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | + 'id_rubrique=' . intval($row['id']) |
|
| 349 | + ); |
|
| 350 | + $continuer = true; |
|
| 351 | + } |
|
| 352 | + } while ($continuer); |
|
| 353 | + |
|
| 354 | + // Enregistrement des modifs |
|
| 355 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -367,123 +367,123 @@ discard block |
||
| 367 | 367 | * @return void |
| 368 | 368 | **/ |
| 369 | 369 | function propager_les_secteurs() { |
| 370 | - // Profondeur 0 |
|
| 371 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | - // et fixer les id_secteur des rubriques racines |
|
| 373 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | - // Toute rubrique non racine est de profondeur >0 |
|
| 375 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | - |
|
| 377 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | - |
|
| 380 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | - // on fait profondeur par profondeur |
|
| 382 | - |
|
| 383 | - $prof = 0; |
|
| 384 | - do { |
|
| 385 | - $continuer = false; |
|
| 386 | - |
|
| 387 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | - // on fixe le profondeur $prof+1 |
|
| 389 | - |
|
| 390 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | - // on teste A.profondeur > $prof+1 car : |
|
| 392 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | - $maxiter2 = $maxiter; |
|
| 396 | - while ( |
|
| 397 | - $maxiter2-- |
|
| 398 | - && ($rows = sql_allfetsel( |
|
| 399 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | - '', |
|
| 403 | - 'R.id_secteur', |
|
| 404 | - '0,100' |
|
| 405 | - )) |
|
| 406 | - ) { |
|
| 407 | - $id_secteur = null; |
|
| 408 | - $ids = []; |
|
| 409 | - while ($row = array_shift($rows)) { |
|
| 410 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | - if (count($ids)) { |
|
| 412 | - sql_updateq( |
|
| 413 | - 'spip_rubriques', |
|
| 414 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | - sql_in('id_rubrique', $ids) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - $id_secteur = $row['id_secteur']; |
|
| 419 | - $ids = []; |
|
| 420 | - } |
|
| 421 | - $ids[] = $row['id']; |
|
| 422 | - } |
|
| 423 | - if (count($ids)) { |
|
| 424 | - sql_updateq( |
|
| 425 | - 'spip_rubriques', |
|
| 426 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | - sql_in('id_rubrique', $ids) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | - $maxiter2 = $maxiter; |
|
| 435 | - while ( |
|
| 436 | - $maxiter2-- |
|
| 437 | - && ($rows = sql_allfetsel( |
|
| 438 | - 'id_rubrique as id', |
|
| 439 | - 'spip_rubriques', |
|
| 440 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | - 'zzz.id_rubrique', |
|
| 442 | - 'spip_rubriques AS zzz', |
|
| 443 | - 'zzz.profondeur=' . intval($prof) |
|
| 444 | - ) . ')', |
|
| 445 | - '', |
|
| 446 | - '', |
|
| 447 | - '0,100' |
|
| 448 | - )) |
|
| 449 | - ) { |
|
| 450 | - $rows = array_column($rows, 'id'); |
|
| 451 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | - // on arrete les frais |
|
| 458 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | - $prof++; |
|
| 460 | - $continuer = true; |
|
| 461 | - } |
|
| 462 | - } while ($continuer && $maxiter--); |
|
| 463 | - |
|
| 464 | - // loger si la table des rubriques semble foireuse |
|
| 465 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | - spip_log( |
|
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | - _LOG_CRITIQUE |
|
| 470 | - ); |
|
| 471 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // reparer les articles |
|
| 475 | - $r = sql_select( |
|
| 476 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | - ); |
|
| 480 | - |
|
| 481 | - while ($row = sql_fetch($r)) { |
|
| 482 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 370 | + // Profondeur 0 |
|
| 371 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | + // et fixer les id_secteur des rubriques racines |
|
| 373 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | + // Toute rubrique non racine est de profondeur >0 |
|
| 375 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | + |
|
| 377 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | + |
|
| 380 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | + // on fait profondeur par profondeur |
|
| 382 | + |
|
| 383 | + $prof = 0; |
|
| 384 | + do { |
|
| 385 | + $continuer = false; |
|
| 386 | + |
|
| 387 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | + // on fixe le profondeur $prof+1 |
|
| 389 | + |
|
| 390 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | + // on teste A.profondeur > $prof+1 car : |
|
| 392 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | + $maxiter2 = $maxiter; |
|
| 396 | + while ( |
|
| 397 | + $maxiter2-- |
|
| 398 | + && ($rows = sql_allfetsel( |
|
| 399 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | + '', |
|
| 403 | + 'R.id_secteur', |
|
| 404 | + '0,100' |
|
| 405 | + )) |
|
| 406 | + ) { |
|
| 407 | + $id_secteur = null; |
|
| 408 | + $ids = []; |
|
| 409 | + while ($row = array_shift($rows)) { |
|
| 410 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | + if (count($ids)) { |
|
| 412 | + sql_updateq( |
|
| 413 | + 'spip_rubriques', |
|
| 414 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | + sql_in('id_rubrique', $ids) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + $id_secteur = $row['id_secteur']; |
|
| 419 | + $ids = []; |
|
| 420 | + } |
|
| 421 | + $ids[] = $row['id']; |
|
| 422 | + } |
|
| 423 | + if (count($ids)) { |
|
| 424 | + sql_updateq( |
|
| 425 | + 'spip_rubriques', |
|
| 426 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | + sql_in('id_rubrique', $ids) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | + $maxiter2 = $maxiter; |
|
| 435 | + while ( |
|
| 436 | + $maxiter2-- |
|
| 437 | + && ($rows = sql_allfetsel( |
|
| 438 | + 'id_rubrique as id', |
|
| 439 | + 'spip_rubriques', |
|
| 440 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | + 'zzz.id_rubrique', |
|
| 442 | + 'spip_rubriques AS zzz', |
|
| 443 | + 'zzz.profondeur=' . intval($prof) |
|
| 444 | + ) . ')', |
|
| 445 | + '', |
|
| 446 | + '', |
|
| 447 | + '0,100' |
|
| 448 | + )) |
|
| 449 | + ) { |
|
| 450 | + $rows = array_column($rows, 'id'); |
|
| 451 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | + // on arrete les frais |
|
| 458 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | + $prof++; |
|
| 460 | + $continuer = true; |
|
| 461 | + } |
|
| 462 | + } while ($continuer && $maxiter--); |
|
| 463 | + |
|
| 464 | + // loger si la table des rubriques semble foireuse |
|
| 465 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | + spip_log( |
|
| 468 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | + _LOG_CRITIQUE |
|
| 470 | + ); |
|
| 471 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // reparer les articles |
|
| 475 | + $r = sql_select( |
|
| 476 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | + ); |
|
| 480 | + |
|
| 481 | + while ($row = sql_fetch($r)) { |
|
| 482 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -498,23 +498,23 @@ discard block |
||
| 498 | 498 | * true si un changement a eu lieu |
| 499 | 499 | **/ |
| 500 | 500 | function calculer_langues_rubriques_etape() { |
| 501 | - $s = sql_select( |
|
| 502 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | - ); |
|
| 506 | - |
|
| 507 | - $t = false; |
|
| 508 | - while ($row = sql_fetch($s)) { |
|
| 509 | - $id_rubrique = $row['id_rubrique']; |
|
| 510 | - $t = sql_updateq( |
|
| 511 | - 'spip_rubriques', |
|
| 512 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return $t; |
|
| 501 | + $s = sql_select( |
|
| 502 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | + ); |
|
| 506 | + |
|
| 507 | + $t = false; |
|
| 508 | + while ($row = sql_fetch($s)) { |
|
| 509 | + $id_rubrique = $row['id_rubrique']; |
|
| 510 | + $t = sql_updateq( |
|
| 511 | + 'spip_rubriques', |
|
| 512 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return $t; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -534,38 +534,38 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_langues_rubriques() { |
| 536 | 536 | |
| 537 | - // rubriques (recursivite) |
|
| 538 | - sql_updateq( |
|
| 539 | - 'spip_rubriques', |
|
| 540 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | - ); |
|
| 543 | - while (calculer_langues_rubriques_etape()) { |
|
| 544 | - ; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // articles |
|
| 548 | - $s = sql_select( |
|
| 549 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 552 | - ); |
|
| 553 | - while ($row = sql_fetch($s)) { |
|
| 554 | - $id_article = $row['id_article']; |
|
| 555 | - sql_updateq( |
|
| 556 | - 'spip_articles', |
|
| 557 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | - 'id_article=' . intval($id_article) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | - $langues = calculer_langues_utilisees(); |
|
| 564 | - ecrire_meta('langues_utilisees', $langues); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 537 | + // rubriques (recursivite) |
|
| 538 | + sql_updateq( |
|
| 539 | + 'spip_rubriques', |
|
| 540 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | + ); |
|
| 543 | + while (calculer_langues_rubriques_etape()) { |
|
| 544 | + ; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // articles |
|
| 548 | + $s = sql_select( |
|
| 549 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 552 | + ); |
|
| 553 | + while ($row = sql_fetch($s)) { |
|
| 554 | + $id_article = $row['id_article']; |
|
| 555 | + sql_updateq( |
|
| 556 | + 'spip_articles', |
|
| 557 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | + 'id_article=' . intval($id_article) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | + $langues = calculer_langues_utilisees(); |
|
| 564 | + ecrire_meta('langues_utilisees', $langues); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -582,80 +582,80 @@ discard block |
||
| 582 | 582 | * Liste des langues utilisées séparées par des virgules |
| 583 | 583 | **/ |
| 584 | 584 | function calculer_langues_utilisees($serveur = '') { |
| 585 | - include_spip('public/interfaces'); |
|
| 586 | - include_spip('public/compiler'); |
|
| 587 | - include_spip('public/composer'); |
|
| 588 | - include_spip('public/phraser_html'); |
|
| 589 | - $langues = []; |
|
| 590 | - |
|
| 591 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | - |
|
| 593 | - include_spip('base/objets'); |
|
| 594 | - $tables = lister_tables_objets_sql(); |
|
| 595 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | - |
|
| 597 | - foreach (array_keys($tables) as $t) { |
|
| 598 | - $desc = $trouver_table($t, $serveur); |
|
| 599 | - // c'est une table avec des langues |
|
| 600 | - if ( |
|
| 601 | - $desc['exist'] |
|
| 602 | - && isset($desc['field']['lang']) |
|
| 603 | - && isset($desc['field']['langue_choisie']) |
|
| 604 | - ) { |
|
| 605 | - $boucle = new Boucle(); |
|
| 606 | - $boucle->show = $desc; |
|
| 607 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | - $boucle->id_table = $desc['table_objet']; |
|
| 610 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | - $boucle->sql_serveur = $serveur; |
|
| 612 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | - $boucle->separateur[] = ','; |
|
| 615 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | - $boucle->iterateur = 'sql'; |
|
| 617 | - |
|
| 618 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | - $boucle->descr['gram'] = 'html'; |
|
| 621 | - |
|
| 622 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - isset($desc['statut']) |
|
| 626 | - && $desc['statut'] |
|
| 627 | - ) { |
|
| 628 | - $boucles = [ |
|
| 629 | - 'calculer_langues_utilisees' => $boucle, |
|
| 630 | - ]; |
|
| 631 | - // generer un nom de fonction "anonyme" unique |
|
| 632 | - do { |
|
| 633 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | - } while (function_exists($functionname)); |
|
| 635 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | - $res = ''; |
|
| 639 | - eval($code); |
|
| 640 | - $res = explode(',', $res); |
|
| 641 | - foreach ($res as $lang) { |
|
| 642 | - $langues[$lang] = 1; |
|
| 643 | - } |
|
| 644 | - } else { |
|
| 645 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | - while ($row = sql_fetch($res)) { |
|
| 647 | - $langues[$row['lang']] = 1; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - $langues = array_filter(array_keys($langues)); |
|
| 654 | - sort($langues); |
|
| 655 | - $langues = join(',', $langues); |
|
| 656 | - spip_log("langues utilisees: $langues"); |
|
| 657 | - |
|
| 658 | - return $langues; |
|
| 585 | + include_spip('public/interfaces'); |
|
| 586 | + include_spip('public/compiler'); |
|
| 587 | + include_spip('public/composer'); |
|
| 588 | + include_spip('public/phraser_html'); |
|
| 589 | + $langues = []; |
|
| 590 | + |
|
| 591 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | + |
|
| 593 | + include_spip('base/objets'); |
|
| 594 | + $tables = lister_tables_objets_sql(); |
|
| 595 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | + |
|
| 597 | + foreach (array_keys($tables) as $t) { |
|
| 598 | + $desc = $trouver_table($t, $serveur); |
|
| 599 | + // c'est une table avec des langues |
|
| 600 | + if ( |
|
| 601 | + $desc['exist'] |
|
| 602 | + && isset($desc['field']['lang']) |
|
| 603 | + && isset($desc['field']['langue_choisie']) |
|
| 604 | + ) { |
|
| 605 | + $boucle = new Boucle(); |
|
| 606 | + $boucle->show = $desc; |
|
| 607 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | + $boucle->id_table = $desc['table_objet']; |
|
| 610 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | + $boucle->sql_serveur = $serveur; |
|
| 612 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | + $boucle->separateur[] = ','; |
|
| 615 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | + $boucle->iterateur = 'sql'; |
|
| 617 | + |
|
| 618 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | + $boucle->descr['gram'] = 'html'; |
|
| 621 | + |
|
| 622 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + isset($desc['statut']) |
|
| 626 | + && $desc['statut'] |
|
| 627 | + ) { |
|
| 628 | + $boucles = [ |
|
| 629 | + 'calculer_langues_utilisees' => $boucle, |
|
| 630 | + ]; |
|
| 631 | + // generer un nom de fonction "anonyme" unique |
|
| 632 | + do { |
|
| 633 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | + } while (function_exists($functionname)); |
|
| 635 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | + $res = ''; |
|
| 639 | + eval($code); |
|
| 640 | + $res = explode(',', $res); |
|
| 641 | + foreach ($res as $lang) { |
|
| 642 | + $langues[$lang] = 1; |
|
| 643 | + } |
|
| 644 | + } else { |
|
| 645 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | + while ($row = sql_fetch($res)) { |
|
| 647 | + $langues[$row['lang']] = 1; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + $langues = array_filter(array_keys($langues)); |
|
| 654 | + sort($langues); |
|
| 655 | + $langues = join(',', $langues); |
|
| 656 | + spip_log("langues utilisees: $langues"); |
|
| 657 | + |
|
| 658 | + return $langues; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -672,9 +672,9 @@ discard block |
||
| 672 | 672 | * incluant les rubriques noeuds et toutes leurs descendances |
| 673 | 673 | */ |
| 674 | 674 | function calcul_branche_in($id) { |
| 675 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 676 | 676 | |
| 677 | - return $calcul_branche_in($id); |
|
| 677 | + return $calcul_branche_in($id); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * incluant les rubriques transmises et toutes leurs parentées |
| 693 | 693 | */ |
| 694 | 694 | function calcul_hierarchie_in($id, $tout = true) { |
| 695 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 696 | 696 | |
| 697 | - return $calcul_hierarchie_in($id, $tout); |
|
| 697 | + return $calcul_hierarchie_in($id, $tout); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -715,40 +715,40 @@ discard block |
||
| 715 | 715 | * incluant les rubriques noeuds et toutes leurs descendances |
| 716 | 716 | */ |
| 717 | 717 | function inc_calcul_branche_in_dist($id) { |
| 718 | - static $b = []; |
|
| 719 | - |
|
| 720 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | - if (!is_array($id)) { |
|
| 722 | - $id = explode(',', $id); |
|
| 723 | - } |
|
| 724 | - $id = join(',', array_map('intval', $id)); |
|
| 725 | - if (isset($b[$id])) { |
|
| 726 | - return $b[$id]; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // Notre branche commence par la rubrique de depart |
|
| 730 | - $branche = $r = $id; |
|
| 731 | - |
|
| 732 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | - $maxiter = 10000; |
|
| 735 | - while ( |
|
| 736 | - $maxiter-- && ($filles = sql_allfetsel( |
|
| 737 | - 'id_rubrique', |
|
| 738 | - 'spip_rubriques', |
|
| 739 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | - )) |
|
| 741 | - ) { |
|
| 742 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | - $branche .= ',' . $r; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | - if (strlen($branche) < 10000) { |
|
| 748 | - $b[$id] = $branche; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $branche; |
|
| 718 | + static $b = []; |
|
| 719 | + |
|
| 720 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | + if (!is_array($id)) { |
|
| 722 | + $id = explode(',', $id); |
|
| 723 | + } |
|
| 724 | + $id = join(',', array_map('intval', $id)); |
|
| 725 | + if (isset($b[$id])) { |
|
| 726 | + return $b[$id]; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // Notre branche commence par la rubrique de depart |
|
| 730 | + $branche = $r = $id; |
|
| 731 | + |
|
| 732 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | + $maxiter = 10000; |
|
| 735 | + while ( |
|
| 736 | + $maxiter-- && ($filles = sql_allfetsel( |
|
| 737 | + 'id_rubrique', |
|
| 738 | + 'spip_rubriques', |
|
| 739 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | + )) |
|
| 741 | + ) { |
|
| 742 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | + $branche .= ',' . $r; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | + if (strlen($branche) < 10000) { |
|
| 748 | + $b[$id] = $branche; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $branche; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -770,45 +770,45 @@ discard block |
||
| 770 | 770 | * incluant les rubriques transmises et toutes leurs parentées |
| 771 | 771 | */ |
| 772 | 772 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 773 | - static $b = []; |
|
| 774 | - |
|
| 775 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | - if (!is_array($id)) { |
|
| 777 | - $id = explode(',', $id); |
|
| 778 | - } |
|
| 779 | - $id = join(',', array_map('intval', $id)); |
|
| 780 | - |
|
| 781 | - if (isset($b[$id])) { |
|
| 782 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - $hier = ''; |
|
| 787 | - |
|
| 788 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | - $ids_nouveaux_parents = $id; |
|
| 791 | - $maxiter = 10000; |
|
| 792 | - while ( |
|
| 793 | - $maxiter-- && ($parents = sql_allfetsel( |
|
| 794 | - 'id_parent', |
|
| 795 | - 'spip_rubriques', |
|
| 796 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | - )) |
|
| 798 | - ) { |
|
| 799 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | - if (strlen($hier) < 10000) { |
|
| 805 | - $b[$id] = $hier; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | - |
|
| 811 | - return $hier; |
|
| 773 | + static $b = []; |
|
| 774 | + |
|
| 775 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | + if (!is_array($id)) { |
|
| 777 | + $id = explode(',', $id); |
|
| 778 | + } |
|
| 779 | + $id = join(',', array_map('intval', $id)); |
|
| 780 | + |
|
| 781 | + if (isset($b[$id])) { |
|
| 782 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + $hier = ''; |
|
| 787 | + |
|
| 788 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | + $ids_nouveaux_parents = $id; |
|
| 791 | + $maxiter = 10000; |
|
| 792 | + while ( |
|
| 793 | + $maxiter-- && ($parents = sql_allfetsel( |
|
| 794 | + 'id_parent', |
|
| 795 | + 'spip_rubriques', |
|
| 796 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | + )) |
|
| 798 | + ) { |
|
| 799 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | + if (strlen($hier) < 10000) { |
|
| 805 | + $b[$id] = $hier; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | + |
|
| 811 | + return $hier; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | |
@@ -826,47 +826,47 @@ discard block |
||
| 826 | 826 | * @return void |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_prochain_postdate($check = false) { |
| 829 | - include_spip('base/abstract_sql'); |
|
| 830 | - if ($check) { |
|
| 831 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | - |
|
| 834 | - $r = sql_select( |
|
| 835 | - 'DISTINCT A.id_rubrique AS id', |
|
| 836 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | - ); |
|
| 839 | - while ($row = sql_fetch($r)) { |
|
| 840 | - publier_branche_rubrique($row['id']); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $t = sql_fetsel( |
|
| 847 | - 'date', |
|
| 848 | - 'spip_articles', |
|
| 849 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | - '', |
|
| 851 | - 'date', |
|
| 852 | - '1' |
|
| 853 | - ); |
|
| 854 | - |
|
| 855 | - if ($t) { |
|
| 856 | - $t = $t['date']; |
|
| 857 | - if ( |
|
| 858 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | - || $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | - ) { |
|
| 861 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | - ecrire_meta('derniere_modif', time()); |
|
| 863 | - } |
|
| 864 | - } else { |
|
| 865 | - effacer_meta('date_prochain_postdate'); |
|
| 866 | - ecrire_meta('derniere_modif', time()); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - spip_log("prochain postdate: $t"); |
|
| 829 | + include_spip('base/abstract_sql'); |
|
| 830 | + if ($check) { |
|
| 831 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | + |
|
| 834 | + $r = sql_select( |
|
| 835 | + 'DISTINCT A.id_rubrique AS id', |
|
| 836 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | + ); |
|
| 839 | + while ($row = sql_fetch($r)) { |
|
| 840 | + publier_branche_rubrique($row['id']); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $t = sql_fetsel( |
|
| 847 | + 'date', |
|
| 848 | + 'spip_articles', |
|
| 849 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | + '', |
|
| 851 | + 'date', |
|
| 852 | + '1' |
|
| 853 | + ); |
|
| 854 | + |
|
| 855 | + if ($t) { |
|
| 856 | + $t = $t['date']; |
|
| 857 | + if ( |
|
| 858 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | + || $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | + ) { |
|
| 861 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | + ecrire_meta('derniere_modif', time()); |
|
| 863 | + } |
|
| 864 | + } else { |
|
| 865 | + effacer_meta('date_prochain_postdate'); |
|
| 866 | + ecrire_meta('derniere_modif', time()); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + spip_log("prochain postdate: $t"); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -891,62 +891,62 @@ discard block |
||
| 891 | 891 | */ |
| 892 | 892 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 893 | 893 | |
| 894 | - // eclater l'arborescence demandee |
|
| 895 | - // echapper les </multi> et autres balises fermantes html |
|
| 896 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | - include_spip('base/abstract_sql'); |
|
| 899 | - foreach ($arbo as $titre) { |
|
| 900 | - // retablir les </multi> et autres balises fermantes html |
|
| 901 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | - $r = sql_getfetsel( |
|
| 903 | - 'id_rubrique', |
|
| 904 | - 'spip_rubriques', |
|
| 905 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | - $groupby = [], |
|
| 907 | - $orderby = [], |
|
| 908 | - $limit = '', |
|
| 909 | - $having = [], |
|
| 910 | - $serveur |
|
| 911 | - ); |
|
| 912 | - if ($r !== null) { |
|
| 913 | - $id_parent = $r; |
|
| 914 | - } else { |
|
| 915 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | - 'titre' => $titre, |
|
| 917 | - 'id_parent' => $id_parent, |
|
| 918 | - 'statut' => 'prepa' |
|
| 919 | - ], $desc = [], $serveur); |
|
| 920 | - if ($id_parent > 0) { |
|
| 921 | - $data = sql_fetsel( |
|
| 922 | - 'id_secteur,lang', |
|
| 923 | - 'spip_rubriques', |
|
| 924 | - "id_rubrique=$id_parent", |
|
| 925 | - $groupby = [], |
|
| 926 | - $orderby = [], |
|
| 927 | - $limit = '', |
|
| 928 | - $having = [], |
|
| 929 | - $serveur |
|
| 930 | - ); |
|
| 931 | - $id_secteur = $data['id_secteur']; |
|
| 932 | - $lang = $data['lang']; |
|
| 933 | - } else { |
|
| 934 | - $id_secteur = $id_rubrique; |
|
| 935 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - sql_updateq( |
|
| 939 | - 'spip_rubriques', |
|
| 940 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | - [], |
|
| 943 | - $serveur |
|
| 944 | - ); |
|
| 945 | - |
|
| 946 | - // pour la recursion |
|
| 947 | - $id_parent = $id_rubrique; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return intval($id_parent); |
|
| 894 | + // eclater l'arborescence demandee |
|
| 895 | + // echapper les </multi> et autres balises fermantes html |
|
| 896 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | + include_spip('base/abstract_sql'); |
|
| 899 | + foreach ($arbo as $titre) { |
|
| 900 | + // retablir les </multi> et autres balises fermantes html |
|
| 901 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | + $r = sql_getfetsel( |
|
| 903 | + 'id_rubrique', |
|
| 904 | + 'spip_rubriques', |
|
| 905 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | + $groupby = [], |
|
| 907 | + $orderby = [], |
|
| 908 | + $limit = '', |
|
| 909 | + $having = [], |
|
| 910 | + $serveur |
|
| 911 | + ); |
|
| 912 | + if ($r !== null) { |
|
| 913 | + $id_parent = $r; |
|
| 914 | + } else { |
|
| 915 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | + 'titre' => $titre, |
|
| 917 | + 'id_parent' => $id_parent, |
|
| 918 | + 'statut' => 'prepa' |
|
| 919 | + ], $desc = [], $serveur); |
|
| 920 | + if ($id_parent > 0) { |
|
| 921 | + $data = sql_fetsel( |
|
| 922 | + 'id_secteur,lang', |
|
| 923 | + 'spip_rubriques', |
|
| 924 | + "id_rubrique=$id_parent", |
|
| 925 | + $groupby = [], |
|
| 926 | + $orderby = [], |
|
| 927 | + $limit = '', |
|
| 928 | + $having = [], |
|
| 929 | + $serveur |
|
| 930 | + ); |
|
| 931 | + $id_secteur = $data['id_secteur']; |
|
| 932 | + $lang = $data['lang']; |
|
| 933 | + } else { |
|
| 934 | + $id_secteur = $id_rubrique; |
|
| 935 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + sql_updateq( |
|
| 939 | + 'spip_rubriques', |
|
| 940 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | + [], |
|
| 943 | + $serveur |
|
| 944 | + ); |
|
| 945 | + |
|
| 946 | + // pour la recursion |
|
| 947 | + $id_parent = $id_rubrique; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return intval($id_parent); |
|
| 952 | 952 | } |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | sql_updateq( |
| 136 | 136 | 'spip_rubriques', |
| 137 | 137 | ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
| 138 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 138 | + 'id_rubrique='.intval($id_rubrique) |
|
| 139 | 139 | ); |
| 140 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 140 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique='.intval($id_rubrique)); |
|
| 141 | 141 | if (!$id_parent) { |
| 142 | 142 | break; |
| 143 | 143 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | return $id_pred != $id_rubrique; |
| 173 | 173 | } |
| 174 | 174 | // passer au parent si on a depublie |
| 175 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 175 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id_pred)); |
|
| 176 | 176 | $id_pred = $r['id_parent']; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | $date = date('Y-m-d H:i:s'); |
| 198 | 198 | } |
| 199 | 199 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 200 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 200 | + ' AND date <= '.sql_quote($date) : ''; |
|
| 201 | 201 | |
| 202 | 202 | if (!$id_rubrique = intval($id_rubrique)) { |
| 203 | 203 | return false; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // verifier qu'elle existe et est bien publiee |
| 207 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 207 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 208 | 208 | if (!$r || $r['statut'] !== 'publie') { |
| 209 | 209 | return false; |
| 210 | 210 | } |
@@ -214,12 +214,12 @@ discard block |
||
| 214 | 214 | $compte = [ |
| 215 | 215 | 'articles' => sql_countsel( |
| 216 | 216 | 'spip_articles', |
| 217 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 217 | + 'id_rubrique='.intval($id_rubrique)." AND statut='publie'$postdates" |
|
| 218 | 218 | ), |
| 219 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 219 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent='.intval($id_rubrique)." AND statut='publie'"), |
|
| 220 | 220 | 'documents' => sql_countsel( |
| 221 | 221 | 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
| 222 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | + 'L.id_objet='.intval($id_rubrique)." AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | 223 | ) |
| 224 | 224 | ]; |
| 225 | 225 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 247 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique='.intval($id_rubrique)); |
|
| 248 | 248 | |
| 249 | 249 | # spip_log("depublier_rubrique $id_pred"); |
| 250 | 250 | return true; |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | // Afficher les articles post-dates ? |
| 309 | 309 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 310 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | + 'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | 311 | |
| 312 | 312 | $r = sql_select( |
| 313 | 313 | 'R.id_rubrique AS id, max(A.date) AS date_h', |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | sql_updateq( |
| 320 | 320 | 'spip_rubriques', |
| 321 | 321 | ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
| 322 | - 'id_rubrique=' . intval($row['id']) |
|
| 322 | + 'id_rubrique='.intval($row['id']) |
|
| 323 | 323 | ); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | sql_updateq( |
| 346 | 346 | 'spip_rubriques', |
| 347 | 347 | ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
| 348 | - 'id_rubrique=' . intval($row['id']) |
|
| 348 | + 'id_rubrique='.intval($row['id']) |
|
| 349 | 349 | ); |
| 350 | 350 | $continuer = true; |
| 351 | 351 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | && ($rows = sql_allfetsel( |
| 399 | 399 | 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
| 400 | 400 | 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
| 401 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | + 'R.profondeur='.intval($prof).' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | 402 | '', |
| 403 | 403 | 'R.id_secteur', |
| 404 | 404 | '0,100' |
@@ -437,11 +437,11 @@ discard block |
||
| 437 | 437 | && ($rows = sql_allfetsel( |
| 438 | 438 | 'id_rubrique as id', |
| 439 | 439 | 'spip_rubriques', |
| 440 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 440 | + 'profondeur='.intval($prof + 1).' AND id_parent NOT IN ('.sql_get_select( |
|
| 441 | 441 | 'zzz.id_rubrique', |
| 442 | 442 | 'spip_rubriques AS zzz', |
| 443 | - 'zzz.profondeur=' . intval($prof) |
|
| 444 | - ) . ')', |
|
| 443 | + 'zzz.profondeur='.intval($prof) |
|
| 444 | + ).')', |
|
| 445 | 445 | '', |
| 446 | 446 | '', |
| 447 | 447 | '0,100' |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
| 456 | 456 | // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
| 457 | 457 | // on arrete les frais |
| 458 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 458 | + if (sql_countsel('spip_rubriques', 'profondeur='.intval($prof + 1))) { |
|
| 459 | 459 | $prof++; |
| 460 | 460 | $continuer = true; |
| 461 | 461 | } |
@@ -463,12 +463,12 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | // loger si la table des rubriques semble foireuse |
| 465 | 465 | // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
| 466 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 466 | + if (sql_countsel('spip_rubriques', 'profondeur>'.intval($prof + 1))) { |
|
| 467 | 467 | spip_log( |
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | + 'Les rubriques de profondeur>'.($prof + 1).' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | 469 | _LOG_CRITIQUE |
| 470 | 470 | ); |
| 471 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>'.intval($prof + 1)); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // reparer les articles |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | ); |
| 480 | 480 | |
| 481 | 481 | while ($row = sql_fetch($r)) { |
| 482 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article='.intval($row['id'])); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | // avertir les plugins qui peuvent faire leur mises a jour egalement |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | $t = sql_updateq( |
| 511 | 511 | 'spip_rubriques', |
| 512 | 512 | ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
| 513 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | + 'id_rubrique='.intval($id_rubrique) |
|
| 514 | 514 | ); |
| 515 | 515 | } |
| 516 | 516 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | sql_updateq( |
| 556 | 556 | 'spip_articles', |
| 557 | 557 | ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
| 558 | - 'id_article=' . intval($id_article) |
|
| 558 | + 'id_article='.intval($id_article) |
|
| 559 | 559 | ); |
| 560 | 560 | } |
| 561 | 561 | |
@@ -630,11 +630,11 @@ discard block |
||
| 630 | 630 | ]; |
| 631 | 631 | // generer un nom de fonction "anonyme" unique |
| 632 | 632 | do { |
| 633 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 633 | + $functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.random_int(0, mt_getrandmax()); |
|
| 634 | 634 | } while (function_exists($functionname)); |
| 635 | 635 | $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
| 636 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 636 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code; |
|
| 637 | + $code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();'; |
|
| 638 | 638 | $res = ''; |
| 639 | 639 | eval($code); |
| 640 | 640 | $res = explode(',', $res); |
@@ -736,11 +736,11 @@ discard block |
||
| 736 | 736 | $maxiter-- && ($filles = sql_allfetsel( |
| 737 | 737 | 'id_rubrique', |
| 738 | 738 | 'spip_rubriques', |
| 739 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | + sql_in('id_parent', $r).' AND '.sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | 740 | )) |
| 741 | 741 | ) { |
| 742 | 742 | $r = join(',', array_column($filles, 'id_rubrique')); |
| 743 | - $branche .= ',' . $r; |
|
| 743 | + $branche .= ','.$r; |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | |
| 781 | 781 | if (isset($b[$id])) { |
| 782 | 782 | // Notre branche commence par la rubrique de depart si $tout=true |
| 783 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | + return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id]; |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | $hier = ''; |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | $maxiter-- && ($parents = sql_allfetsel( |
| 794 | 794 | 'id_parent', |
| 795 | 795 | 'spip_rubriques', |
| 796 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | + sql_in('id_rubrique', $ids_nouveaux_parents).' AND '.sql_in('id_parent', $hier, 'NOT') |
|
| 797 | 797 | )) |
| 798 | 798 | ) { |
| 799 | 799 | $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
| 800 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | + $hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : ''); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | include_spip('base/abstract_sql'); |
| 830 | 830 | if ($check) { |
| 831 | 831 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 832 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | + 'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | 833 | |
| 834 | 834 | $r = sql_select( |
| 835 | 835 | 'DISTINCT A.id_rubrique AS id', |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | $t = sql_fetsel( |
| 847 | 847 | 'date', |
| 848 | 848 | 'spip_articles', |
| 849 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | + "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | 850 | '', |
| 851 | 851 | 'date', |
| 852 | 852 | '1' |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | $r = sql_getfetsel( |
| 903 | 903 | 'id_rubrique', |
| 904 | 904 | 'spip_rubriques', |
| 905 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | + 'titre = '.sql_quote($titre).' AND id_parent='.intval($id_parent), |
|
| 906 | 906 | $groupby = [], |
| 907 | 907 | $orderby = [], |
| 908 | 908 | $limit = '', |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | sql_updateq( |
| 939 | 939 | 'spip_rubriques', |
| 940 | 940 | ['id_secteur' => $id_secteur, 'lang' => $lang], |
| 941 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | + 'id_rubrique='.intval($id_rubrique), |
|
| 942 | 942 | [], |
| 943 | 943 | $serveur |
| 944 | 944 | ); |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | // celle du texte) et public (spip_lang est la langue du texte) |
| 50 | 50 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 51 | 51 | |
| 52 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 52 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 53 | 53 | if ($dir == 'rtl') { |
| 54 | 54 | $p .= '_rtl'; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | if (!isset($GLOBALS[$p])) { |
| 58 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 58 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return $GLOBALS[$p]; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = ''): string { |
| 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">' |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } else { |
| 87 | 87 | $echap = str_replace("\t", ' ', $echap); |
| 88 | 88 | $echap = str_replace(' ', ' ', $echap); |
| 89 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 89 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>'; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $html; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // XHTML - Preserver les balises-bloc : on liste ici tous les elements |
| 97 | 97 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 98 | 98 | defined('_BALISES_BLOCS') || define('_BALISES_BLOCS', implode('|', CollecteurHtmlTag::$listeBalisesBloc)); |
| 99 | -defined('_BALISES_BLOCS_REGEXP') || define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 99 | +defined('_BALISES_BLOCS_REGEXP') || define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Echapper les elements perilleux en les passant en base64 |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | return ''; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 119 | + return CollecteurHtmlTag::echappementHtmlBase64((string) $rempl, (string) $source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $collections = $collecteurCode->collecter($pre); |
| 137 | 137 | $collections = array_reverse($collections); |
| 138 | 138 | foreach ($collections as $c) { |
| 139 | - $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 139 | + $code = $c['opening'].spip_htmlspecialchars($c['innerHtml']).$c['closing']; |
|
| 140 | 140 | $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | return $regs['raw']; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<(' . implode('|', CollecteurHtmlTag::$listeBalisesAProteger) . ')(\b[^>]*)?>(.*)</\1>,UimsS'); |
|
| 194 | +defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<('.implode('|', CollecteurHtmlTag::$listeBalisesAProteger).')(\b[^>]*)?>(.*)</\1>,UimsS'); |
|
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * pour $source voir commentaire infra (echappe_retour) |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 243 | 243 | foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
| 244 | 244 | if ( |
| 245 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | - || function_exists($f = $f . '_dist') |
|
| 245 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.$tag) |
|
| 246 | + || function_exists($f = $f.'_dist') |
|
| 247 | 247 | || $callback_secure_prefix && ( |
| 248 | - function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | - || function_exists($f = $f . '_dist') |
|
| 248 | + function_exists($f = $callback_prefix.'traiter_echap_'.$tag) |
|
| 249 | + || function_exists($f = $f.'_dist') |
|
| 250 | 250 | ) |
| 251 | 251 | ) { |
| 252 | 252 | $callbacks[$tag] = $f; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | if (!is_string($letexte) || !strlen($letexte)) { |
| 287 | 287 | return $letexte; |
| 288 | 288 | } |
| 289 | - return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 289 | + return CollecteurHtmlTag::retablir_depuisHtmlBase64((string) $letexte, (string) $source, (string) $filtre); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Reinserer le javascript de confiance (venant des modeles) |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (!is_string($letexte) || !strlen($letexte)) { |
| 296 | 296 | return $letexte; |
| 297 | 297 | } |
| 298 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 298 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string) $letexte); |
|
| 299 | 299 | |
| 300 | 300 | // Dans les appels directs hors squelette, securiser aussi ici |
| 301 | 301 | // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | $texte = nettoyer_raccourcis_typo($texte); |
| 365 | 365 | |
| 366 | 366 | // balises de sauts de ligne et paragraphe |
| 367 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 367 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r\r", $texte); |
|
| 368 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 369 | 369 | |
| 370 | 370 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 371 | 371 | $texte = str_replace("\n\n", "\r\r", $texte); |
@@ -390,15 +390,15 @@ discard block |
||
| 390 | 390 | // excédentaire est ensuite supprimé par l'appel à preg_replace() |
| 391 | 391 | $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
| 392 | 392 | $u = $GLOBALS['meta']['pcre_u']; |
| 393 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 393 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 394 | 394 | $points = $suite; |
| 395 | 395 | |
| 396 | 396 | // trop court ? ne pas faire de (...) |
| 397 | 397 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 398 | 398 | $points = ''; |
| 399 | 399 | $long = spip_substr($texte, 0, $taille + 1); |
| 400 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 400 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, $long, $m); |
|
| 401 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 402 | 402 | // encore trop court ? couper au caractere |
| 403 | 403 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 404 | 404 | $texte = spip_substr($long, 0, $taille); |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | // supprimer l'eventuelle entite finale mal coupee |
| 415 | 415 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 416 | 416 | |
| 417 | - return quote_amp(trim($texte)) . $points; |
|
| 417 | + return quote_amp(trim($texte)).$points; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | |
@@ -422,16 +422,16 @@ discard block |
||
| 422 | 422 | if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
| 423 | 423 | $tags = [ |
| 424 | 424 | 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
| 425 | - 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 425 | + 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?'.'>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | 426 | ]; |
| 427 | 427 | foreach ($tags as $k => $t) { |
| 428 | - if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 428 | + if (stripos($texte, '<'.$t['tag']) !== false) { |
|
| 429 | 429 | if (!defined($t['c'])) { |
| 430 | 430 | include_spip('inc/acces'); |
| 431 | 431 | define($t['c'], creer_uniqid()); |
| 432 | 432 | } |
| 433 | 433 | $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
| 434 | - $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 434 | + $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k.constant($t['c'])); |
|
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | if (!empty($options['wrap_suspect'])) { |
| 545 | 545 | $texte = wrap($texte, $options['wrap_suspect']); |
| 546 | 546 | } |
| 547 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 547 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | $texte = $collecteurModeles->retablir($texte); |
@@ -687,11 +687,11 @@ discard block |
||
| 687 | 687 | **/ |
| 688 | 688 | function supprime_img($letexte, $message = null) { |
| 689 | 689 | if ($message === null) { |
| 690 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 690 | + $message = '('._T('img_indisponible').')'; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | return preg_replace( |
| 694 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 694 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 695 | 695 | $message, |
| 696 | 696 | $letexte |
| 697 | 697 | ); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | include_spip('inc/lang'); |
@@ -44,21 +44,21 @@ discard block |
||
| 44 | 44 | **/ |
| 45 | 45 | function definir_puce() { |
| 46 | 46 | |
| 47 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 48 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 49 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 50 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 47 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 48 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 49 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 50 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 51 | 51 | |
| 52 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 53 | - if ($dir == 'rtl') { |
|
| 54 | - $p .= '_rtl'; |
|
| 55 | - } |
|
| 52 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 53 | + if ($dir == 'rtl') { |
|
| 54 | + $p .= '_rtl'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if (!isset($GLOBALS[$p])) { |
|
| 58 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 59 | - } |
|
| 57 | + if (!isset($GLOBALS[$p])) { |
|
| 58 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return $GLOBALS[$p]; |
|
| 61 | + return $GLOBALS[$p]; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,30 +66,30 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = ''): string { |
| 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 | - } else { |
|
| 87 | - $echap = str_replace("\t", ' ', $echap); |
|
| 88 | - $echap = str_replace(' ', ' ', $echap); |
|
| 89 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - 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 | + } else { |
|
| 87 | + $echap = str_replace("\t", ' ', $echap); |
|
| 88 | + $echap = str_replace(' ', ' ', $echap); |
|
| 89 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $html; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -112,83 +112,83 @@ discard block |
||
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | 114 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 115 | - if (!is_string($rempl) || !strlen($rempl)) { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 115 | + if (!is_string($rempl) || !strlen($rempl)) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 119 | + return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | // Echapper les <html>...</ html> |
| 124 | 124 | function traiter_echap_html_dist($regs, $options = []) { |
| 125 | - return $regs['innerHtml']; |
|
| 125 | + return $regs['innerHtml']; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Echapper les <pre>...</ pre> |
| 129 | 129 | function traiter_echap_pre_dist($regs, $options = []) { |
| 130 | - // echapper les <code> dans <pre> |
|
| 131 | - $pre = $regs['innerHtml']; |
|
| 132 | - |
|
| 133 | - // echapper les < dans <code> |
|
| 134 | - if (str_contains($pre, '<')) { |
|
| 135 | - $collecteurCode = new CollecteurHtmlTag('code'); |
|
| 136 | - $collections = $collecteurCode->collecter($pre); |
|
| 137 | - $collections = array_reverse($collections); |
|
| 138 | - foreach ($collections as $c) { |
|
| 139 | - $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 140 | - $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return "<pre>$pre</pre>"; |
|
| 130 | + // echapper les <code> dans <pre> |
|
| 131 | + $pre = $regs['innerHtml']; |
|
| 132 | + |
|
| 133 | + // echapper les < dans <code> |
|
| 134 | + if (str_contains($pre, '<')) { |
|
| 135 | + $collecteurCode = new CollecteurHtmlTag('code'); |
|
| 136 | + $collections = $collecteurCode->collecter($pre); |
|
| 137 | + $collections = array_reverse($collections); |
|
| 138 | + foreach ($collections as $c) { |
|
| 139 | + $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 140 | + $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return "<pre>$pre</pre>"; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Echapper les <code>...</ code> |
| 147 | 147 | function traiter_echap_code_dist($regs, $options = []) { |
| 148 | - $corps = $regs['innerHtml']; |
|
| 149 | - $att = $regs['attributs']; |
|
| 148 | + $corps = $regs['innerHtml']; |
|
| 149 | + $att = $regs['attributs']; |
|
| 150 | 150 | |
| 151 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 152 | - if (str_contains($corps, "\n")) { |
|
| 153 | - // supprimer les sauts de ligne debut/fin |
|
| 154 | - // (mais pas les espaces => ascii art). |
|
| 155 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 151 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 152 | + if (str_contains($corps, "\n")) { |
|
| 153 | + // supprimer les sauts de ligne debut/fin |
|
| 154 | + // (mais pas les espaces => ascii art). |
|
| 155 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 156 | 156 | |
| 157 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 158 | - } else { |
|
| 159 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 160 | - } |
|
| 157 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 158 | + } else { |
|
| 159 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $echap; |
|
| 162 | + return $echap; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 166 | 166 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 167 | - $echap = trim(entites_html($regs['innerHtml'])); |
|
| 168 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 169 | - $lignes = explode("\n", trim($echap)); |
|
| 170 | - $n = 0; |
|
| 171 | - foreach ($lignes as $l) { |
|
| 172 | - $n += floor(strlen($l) / 60) + 1; |
|
| 173 | - } |
|
| 174 | - $n = max($n, 2); |
|
| 175 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 176 | - |
|
| 177 | - return $echap; |
|
| 167 | + $echap = trim(entites_html($regs['innerHtml'])); |
|
| 168 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 169 | + $lignes = explode("\n", trim($echap)); |
|
| 170 | + $n = 0; |
|
| 171 | + foreach ($lignes as $l) { |
|
| 172 | + $n += floor(strlen($l) / 60) + 1; |
|
| 173 | + } |
|
| 174 | + $n = max($n, 2); |
|
| 175 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 176 | + |
|
| 177 | + return $echap; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | function traiter_echap_frame_dist($regs, $options = []) { |
| 181 | - return traiter_echap_cadre_dist($regs); |
|
| 181 | + return traiter_echap_cadre_dist($regs); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function traiter_echap_script_dist($regs, $options = []) { |
| 185 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 186 | - if (strpos($regs['opening'], 'php')) { |
|
| 187 | - return highlight_string($regs['raw'], true); |
|
| 188 | - } |
|
| 185 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 186 | + if (strpos($regs['opening'], 'php')) { |
|
| 187 | + return highlight_string($regs['raw'], true); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - // Cas normal : le script passe tel quel |
|
| 191 | - return $regs['raw']; |
|
| 190 | + // Cas normal : le script passe tel quel |
|
| 191 | + return $regs['raw']; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<(' . implode('|', CollecteurHtmlTag::$listeBalisesAProteger) . ')(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -207,69 +207,69 @@ discard block |
||
| 207 | 207 | * @return string|string[] |
| 208 | 208 | */ |
| 209 | 209 | function echappe_html( |
| 210 | - $letexte, |
|
| 211 | - $source = '', |
|
| 212 | - $no_transform = false, |
|
| 213 | - $html_tags = null, |
|
| 214 | - $callback_prefix = '', |
|
| 215 | - $callback_options = [] |
|
| 210 | + $letexte, |
|
| 211 | + $source = '', |
|
| 212 | + $no_transform = false, |
|
| 213 | + $html_tags = null, |
|
| 214 | + $callback_prefix = '', |
|
| 215 | + $callback_options = [] |
|
| 216 | 216 | ) { |
| 217 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 218 | - return $letexte; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ($no_transform !== false) { |
|
| 222 | - trigger_deprecation('spip', '5.0', 'Using "%s" arg is deprecated, use directly "%s" instead.', '$no_transform', 'Spip\Texte\Collecteur\HtmlTag::proteger_balisesHtml', __FUNCTION__); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // appels legacy avec un '' |
|
| 226 | - if (empty($html_tags)) { |
|
| 227 | - $html_tags = null; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // legacy : les appels fournissaient une preg pour repérer les balises HTML |
|
| 231 | - if ($html_tags && !is_array($html_tags)) { |
|
| 232 | - trigger_deprecation('spip', '5.0', 'Using a preg for "%s" arg is deprecated, use a tag array instead.', '$html_tags', __FUNCTION__); |
|
| 233 | - $t = explode(')', $html_tags, 2); |
|
| 234 | - $t = reset($t); |
|
| 235 | - $t = explode('(', $t, 2); |
|
| 236 | - $t = end($t); |
|
| 237 | - $html_tags = explode('|', $t); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $callbacks = []; |
|
| 241 | - if (!$no_transform) { |
|
| 242 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 243 | - foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
|
| 244 | - if ( |
|
| 245 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | - || function_exists($f = $f . '_dist') |
|
| 247 | - || $callback_secure_prefix && ( |
|
| 248 | - function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | - || function_exists($f = $f . '_dist') |
|
| 250 | - ) |
|
| 251 | - ) { |
|
| 252 | - $callbacks[$tag] = $f; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, $source, $html_tags, $callbacks, $callback_options); |
|
| 258 | - |
|
| 259 | - if ($no_transform) { |
|
| 260 | - return $letexte; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 264 | - // seulement si on a echappe les <script> |
|
| 265 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 266 | - // dans une callback autonommee + la preg pour collecter est un peu spécifique |
|
| 267 | - if (in_array('script', $html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger)) { |
|
| 268 | - $htmlTagCollecteur = new CollecteurHtmlTag('?', '@<[?].*($|[?]>)@UsS', ''); |
|
| 269 | - $letexte = $htmlTagCollecteur->echapper_enHtmlBase64($letexte, $source, fn ($c, $o) => highlight_string($c['raw'], true)); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $letexte; |
|
| 217 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 218 | + return $letexte; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ($no_transform !== false) { |
|
| 222 | + trigger_deprecation('spip', '5.0', 'Using "%s" arg is deprecated, use directly "%s" instead.', '$no_transform', 'Spip\Texte\Collecteur\HtmlTag::proteger_balisesHtml', __FUNCTION__); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // appels legacy avec un '' |
|
| 226 | + if (empty($html_tags)) { |
|
| 227 | + $html_tags = null; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // legacy : les appels fournissaient une preg pour repérer les balises HTML |
|
| 231 | + if ($html_tags && !is_array($html_tags)) { |
|
| 232 | + trigger_deprecation('spip', '5.0', 'Using a preg for "%s" arg is deprecated, use a tag array instead.', '$html_tags', __FUNCTION__); |
|
| 233 | + $t = explode(')', $html_tags, 2); |
|
| 234 | + $t = reset($t); |
|
| 235 | + $t = explode('(', $t, 2); |
|
| 236 | + $t = end($t); |
|
| 237 | + $html_tags = explode('|', $t); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $callbacks = []; |
|
| 241 | + if (!$no_transform) { |
|
| 242 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 243 | + foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
|
| 244 | + if ( |
|
| 245 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | + || function_exists($f = $f . '_dist') |
|
| 247 | + || $callback_secure_prefix && ( |
|
| 248 | + function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | + || function_exists($f = $f . '_dist') |
|
| 250 | + ) |
|
| 251 | + ) { |
|
| 252 | + $callbacks[$tag] = $f; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, $source, $html_tags, $callbacks, $callback_options); |
|
| 258 | + |
|
| 259 | + if ($no_transform) { |
|
| 260 | + return $letexte; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 264 | + // seulement si on a echappe les <script> |
|
| 265 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 266 | + // dans une callback autonommee + la preg pour collecter est un peu spécifique |
|
| 267 | + if (in_array('script', $html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger)) { |
|
| 268 | + $htmlTagCollecteur = new CollecteurHtmlTag('?', '@<[?].*($|[?]>)@UsS', ''); |
|
| 269 | + $letexte = $htmlTagCollecteur->echapper_enHtmlBase64($letexte, $source, fn ($c, $o) => highlight_string($c['raw'], true)); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $letexte; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -283,27 +283,27 @@ discard block |
||
| 283 | 283 | * @return array|mixed|string|string[] |
| 284 | 284 | */ |
| 285 | 285 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 286 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 287 | - return $letexte; |
|
| 288 | - } |
|
| 289 | - return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 286 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 287 | + return $letexte; |
|
| 288 | + } |
|
| 289 | + return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Reinserer le javascript de confiance (venant des modeles) |
| 293 | 293 | |
| 294 | 294 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 295 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 296 | - return $letexte; |
|
| 297 | - } |
|
| 298 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 299 | - |
|
| 300 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 301 | - // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
|
| 302 | - if ($interdire_scripts) { |
|
| 303 | - $letexte = interdire_scripts($letexte); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - return trim($letexte); |
|
| 295 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 296 | + return $letexte; |
|
| 297 | + } |
|
| 298 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 299 | + |
|
| 300 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 301 | + // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
|
| 302 | + if ($interdire_scripts) { |
|
| 303 | + $letexte = interdire_scripts($letexte); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + return trim($letexte); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | |
@@ -331,129 +331,129 @@ discard block |
||
| 331 | 331 | * texte coupé |
| 332 | 332 | **/ |
| 333 | 333 | function couper($texte, $taille = 50, $suite = null) { |
| 334 | - if ($taille <= 0) { |
|
| 335 | - return ''; |
|
| 336 | - } |
|
| 337 | - $length = spip_strlen($texte); |
|
| 338 | - if (!$length) { |
|
| 339 | - return ''; |
|
| 340 | - } |
|
| 341 | - $offset = 400 + 2 * $taille; |
|
| 342 | - while ( |
|
| 343 | - $offset < $length |
|
| 344 | - && spip_strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', spip_substr($texte, 0, $offset))) < $taille |
|
| 345 | - ) { |
|
| 346 | - $offset *= 2; |
|
| 347 | - } |
|
| 348 | - if ( |
|
| 349 | - $offset < $length |
|
| 350 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | - ) { |
|
| 352 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | - // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 354 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 355 | - $offset = $p_tag_fermant + 1; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - // éviter de travailler sur 10ko pour extraire 150 caractères |
|
| 359 | - $texte = spip_substr($texte, 0, $offset); |
|
| 360 | - |
|
| 361 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 362 | - include_spip('inc/lien'); |
|
| 363 | - } |
|
| 364 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 365 | - |
|
| 366 | - // balises de sauts de ligne et paragraphe |
|
| 367 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 369 | - |
|
| 370 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 371 | - $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 372 | - |
|
| 373 | - // supprimer les tags |
|
| 374 | - $texte = supprimer_tags($texte); |
|
| 375 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 376 | - |
|
| 377 | - // tester s'il est nécessaire de couper le texte |
|
| 378 | - if (spip_strlen($texte) <= $taille) { |
|
| 379 | - $points = ''; |
|
| 380 | - } else { |
|
| 381 | - // points de suite |
|
| 382 | - if (is_null($suite)) { |
|
| 383 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 384 | - } |
|
| 385 | - $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 386 | - |
|
| 387 | - // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 388 | - // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 389 | - // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 390 | - // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 391 | - $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 392 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 393 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 394 | - $points = $suite; |
|
| 395 | - |
|
| 396 | - // trop court ? ne pas faire de (...) |
|
| 397 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 398 | - $points = ''; |
|
| 399 | - $long = spip_substr($texte, 0, $taille + 1); |
|
| 400 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 402 | - // encore trop court ? couper au caractere |
|
| 403 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 404 | - $texte = spip_substr($long, 0, $taille); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - $texte = $court; |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // remettre les paragraphes |
|
| 412 | - $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 413 | - |
|
| 414 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 415 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 416 | - |
|
| 417 | - return quote_amp(trim($texte)) . $points; |
|
| 334 | + if ($taille <= 0) { |
|
| 335 | + return ''; |
|
| 336 | + } |
|
| 337 | + $length = spip_strlen($texte); |
|
| 338 | + if (!$length) { |
|
| 339 | + return ''; |
|
| 340 | + } |
|
| 341 | + $offset = 400 + 2 * $taille; |
|
| 342 | + while ( |
|
| 343 | + $offset < $length |
|
| 344 | + && spip_strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', spip_substr($texte, 0, $offset))) < $taille |
|
| 345 | + ) { |
|
| 346 | + $offset *= 2; |
|
| 347 | + } |
|
| 348 | + if ( |
|
| 349 | + $offset < $length |
|
| 350 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | + ) { |
|
| 352 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | + // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 354 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 355 | + $offset = $p_tag_fermant + 1; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + // éviter de travailler sur 10ko pour extraire 150 caractères |
|
| 359 | + $texte = spip_substr($texte, 0, $offset); |
|
| 360 | + |
|
| 361 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 362 | + include_spip('inc/lien'); |
|
| 363 | + } |
|
| 364 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 365 | + |
|
| 366 | + // balises de sauts de ligne et paragraphe |
|
| 367 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 369 | + |
|
| 370 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 371 | + $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 372 | + |
|
| 373 | + // supprimer les tags |
|
| 374 | + $texte = supprimer_tags($texte); |
|
| 375 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 376 | + |
|
| 377 | + // tester s'il est nécessaire de couper le texte |
|
| 378 | + if (spip_strlen($texte) <= $taille) { |
|
| 379 | + $points = ''; |
|
| 380 | + } else { |
|
| 381 | + // points de suite |
|
| 382 | + if (is_null($suite)) { |
|
| 383 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 384 | + } |
|
| 385 | + $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 386 | + |
|
| 387 | + // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 388 | + // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 389 | + // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 390 | + // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 391 | + $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 392 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 393 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 394 | + $points = $suite; |
|
| 395 | + |
|
| 396 | + // trop court ? ne pas faire de (...) |
|
| 397 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 398 | + $points = ''; |
|
| 399 | + $long = spip_substr($texte, 0, $taille + 1); |
|
| 400 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 402 | + // encore trop court ? couper au caractere |
|
| 403 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 404 | + $texte = spip_substr($long, 0, $taille); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + $texte = $court; |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // remettre les paragraphes |
|
| 412 | + $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 413 | + |
|
| 414 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 415 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 416 | + |
|
| 417 | + return quote_amp(trim($texte)) . $points; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | |
| 421 | 421 | function protege_js_modeles($texte) { |
| 422 | - if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
|
| 423 | - $tags = [ |
|
| 424 | - 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
|
| 425 | - 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | - ]; |
|
| 427 | - foreach ($tags as $k => $t) { |
|
| 428 | - if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 429 | - if (!defined($t['c'])) { |
|
| 430 | - include_spip('inc/acces'); |
|
| 431 | - define($t['c'], creer_uniqid()); |
|
| 432 | - } |
|
| 433 | - $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
|
| 434 | - $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - return $texte; |
|
| 422 | + if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
|
| 423 | + $tags = [ |
|
| 424 | + 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
|
| 425 | + 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | + ]; |
|
| 427 | + foreach ($tags as $k => $t) { |
|
| 428 | + if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 429 | + if (!defined($t['c'])) { |
|
| 430 | + include_spip('inc/acces'); |
|
| 431 | + define($t['c'], creer_uniqid()); |
|
| 432 | + } |
|
| 433 | + $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
|
| 434 | + $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + return $texte; |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
| 442 | 442 | function echapper_faux_tags($letexte) { |
| 443 | - if (!str_contains($letexte, '<')) { |
|
| 444 | - return $letexte; |
|
| 445 | - } |
|
| 446 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 447 | - |
|
| 448 | - $letexte = ''; |
|
| 449 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 450 | - // un texte a echapper |
|
| 451 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 452 | - // un tag html qui a servit a faite le split |
|
| 453 | - $letexte .= array_shift($textMatches); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return $letexte; |
|
| 443 | + if (!str_contains($letexte, '<')) { |
|
| 444 | + return $letexte; |
|
| 445 | + } |
|
| 446 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 447 | + |
|
| 448 | + $letexte = ''; |
|
| 449 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 450 | + // un texte a echapper |
|
| 451 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 452 | + // un tag html qui a servit a faite le split |
|
| 453 | + $letexte .= array_shift($textMatches); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return $letexte; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -473,107 +473,107 @@ discard block |
||
| 473 | 473 | * @return string |
| 474 | 474 | */ |
| 475 | 475 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 476 | - static $echapper_html_suspect; |
|
| 477 | - if (!$texte || !is_string($texte)) { |
|
| 478 | - return $texte; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (!isset($echapper_html_suspect)) { |
|
| 482 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 483 | - } |
|
| 484 | - // si fonction personalisee, on delegue |
|
| 485 | - if ($echapper_html_suspect) { |
|
| 486 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 487 | - $args = [$texte, $options]; |
|
| 488 | - if ($connect || !empty($env)) { |
|
| 489 | - $args[] = $connect; |
|
| 490 | - } |
|
| 491 | - if (!empty($env)) { |
|
| 492 | - $args[] = $env; |
|
| 493 | - } |
|
| 494 | - return $echapper_html_suspect(...$args); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if (is_bool($options)) { |
|
| 498 | - $options = ['strict' => $options]; |
|
| 499 | - } |
|
| 500 | - $strict = $options['strict'] ?? true; |
|
| 501 | - |
|
| 502 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 503 | - if ( |
|
| 504 | - !str_contains($texte, '<') |
|
| 505 | - || !str_contains($texte, '=') |
|
| 506 | - ) { |
|
| 507 | - return $texte; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 511 | - if (!isset($env['espace_prive'])) { |
|
| 512 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 513 | - $env['espace_prive'] = test_espace_prive(); |
|
| 514 | - } |
|
| 515 | - if (!empty($env['espace_prive']) || !empty($env['wysiwyg'])) { |
|
| 516 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 517 | - // car sinon on declenche sur les modeles ou ressources |
|
| 518 | - if ( |
|
| 519 | - !$strict && (!str_contains($texte, 'on') || !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 520 | - ) { |
|
| 521 | - return $texte; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $collecteurModeles = new CollecteurModeles(); |
|
| 525 | - $texte = $collecteurModeles->echapper($texte); |
|
| 526 | - $texte = echappe_js($texte); |
|
| 527 | - |
|
| 528 | - $texte_to_check = $texte; |
|
| 529 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 530 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 531 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 532 | - if (!empty($options['expanser_liens'])) { |
|
| 533 | - $texte_to_check = expanser_liens($texte_to_check, $connect, $env); |
|
| 534 | - } |
|
| 535 | - if (!is_html_safe($texte_to_check)) { |
|
| 536 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 537 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 538 | - $texte = str_replace('<', '<', $texte); |
|
| 539 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 540 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 541 | - if (!function_exists('attribut_html')) { |
|
| 542 | - include_spip('inc/filtres'); |
|
| 543 | - } |
|
| 544 | - if (!empty($options['wrap_suspect'])) { |
|
| 545 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 546 | - } |
|
| 547 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $texte = $collecteurModeles->retablir($texte); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // si on est là dans le public c'est le mode parano |
|
| 554 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 555 | - else { |
|
| 556 | - $collecteurLiens = $collecteurModeles = null; |
|
| 557 | - if (!empty($options['expanser_liens'])) { |
|
| 558 | - $texte = expanser_liens($texte, $connect, $env); |
|
| 559 | - } |
|
| 560 | - else { |
|
| 561 | - $collecteurLiens = new CollecteurLiens(); |
|
| 562 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 563 | - |
|
| 564 | - $collecteurModeles = new CollecteurModeles(); |
|
| 565 | - $texte = $collecteurModeles->echapper($texte); |
|
| 566 | - } |
|
| 567 | - $texte = safehtml($texte); |
|
| 568 | - if ($collecteurModeles) { |
|
| 569 | - $texte = $collecteurModeles->retablir($texte); |
|
| 570 | - } |
|
| 571 | - if ($collecteurLiens) { |
|
| 572 | - $texte = $collecteurLiens->retablir($texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - return $texte; |
|
| 476 | + static $echapper_html_suspect; |
|
| 477 | + if (!$texte || !is_string($texte)) { |
|
| 478 | + return $texte; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (!isset($echapper_html_suspect)) { |
|
| 482 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 483 | + } |
|
| 484 | + // si fonction personalisee, on delegue |
|
| 485 | + if ($echapper_html_suspect) { |
|
| 486 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 487 | + $args = [$texte, $options]; |
|
| 488 | + if ($connect || !empty($env)) { |
|
| 489 | + $args[] = $connect; |
|
| 490 | + } |
|
| 491 | + if (!empty($env)) { |
|
| 492 | + $args[] = $env; |
|
| 493 | + } |
|
| 494 | + return $echapper_html_suspect(...$args); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if (is_bool($options)) { |
|
| 498 | + $options = ['strict' => $options]; |
|
| 499 | + } |
|
| 500 | + $strict = $options['strict'] ?? true; |
|
| 501 | + |
|
| 502 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 503 | + if ( |
|
| 504 | + !str_contains($texte, '<') |
|
| 505 | + || !str_contains($texte, '=') |
|
| 506 | + ) { |
|
| 507 | + return $texte; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 511 | + if (!isset($env['espace_prive'])) { |
|
| 512 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 513 | + $env['espace_prive'] = test_espace_prive(); |
|
| 514 | + } |
|
| 515 | + if (!empty($env['espace_prive']) || !empty($env['wysiwyg'])) { |
|
| 516 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 517 | + // car sinon on declenche sur les modeles ou ressources |
|
| 518 | + if ( |
|
| 519 | + !$strict && (!str_contains($texte, 'on') || !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 520 | + ) { |
|
| 521 | + return $texte; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $collecteurModeles = new CollecteurModeles(); |
|
| 525 | + $texte = $collecteurModeles->echapper($texte); |
|
| 526 | + $texte = echappe_js($texte); |
|
| 527 | + |
|
| 528 | + $texte_to_check = $texte; |
|
| 529 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 530 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 531 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 532 | + if (!empty($options['expanser_liens'])) { |
|
| 533 | + $texte_to_check = expanser_liens($texte_to_check, $connect, $env); |
|
| 534 | + } |
|
| 535 | + if (!is_html_safe($texte_to_check)) { |
|
| 536 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 537 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 538 | + $texte = str_replace('<', '<', $texte); |
|
| 539 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 540 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 541 | + if (!function_exists('attribut_html')) { |
|
| 542 | + include_spip('inc/filtres'); |
|
| 543 | + } |
|
| 544 | + if (!empty($options['wrap_suspect'])) { |
|
| 545 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 546 | + } |
|
| 547 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + $texte = $collecteurModeles->retablir($texte); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // si on est là dans le public c'est le mode parano |
|
| 554 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 555 | + else { |
|
| 556 | + $collecteurLiens = $collecteurModeles = null; |
|
| 557 | + if (!empty($options['expanser_liens'])) { |
|
| 558 | + $texte = expanser_liens($texte, $connect, $env); |
|
| 559 | + } |
|
| 560 | + else { |
|
| 561 | + $collecteurLiens = new CollecteurLiens(); |
|
| 562 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 563 | + |
|
| 564 | + $collecteurModeles = new CollecteurModeles(); |
|
| 565 | + $texte = $collecteurModeles->echapper($texte); |
|
| 566 | + } |
|
| 567 | + $texte = safehtml($texte); |
|
| 568 | + if ($collecteurModeles) { |
|
| 569 | + $texte = $collecteurModeles->retablir($texte); |
|
| 570 | + } |
|
| 571 | + if ($collecteurLiens) { |
|
| 572 | + $texte = $collecteurLiens->retablir($texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + return $texte; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
@@ -594,48 +594,48 @@ discard block |
||
| 594 | 594 | * texte sécurisé |
| 595 | 595 | **/ |
| 596 | 596 | function safehtml($t) { |
| 597 | - static $safehtml; |
|
| 598 | - |
|
| 599 | - if (!$t || !is_string($t)) { |
|
| 600 | - return $t; |
|
| 601 | - } |
|
| 602 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 603 | - if (!str_contains($t, '<')) { |
|
| 604 | - return str_replace("\x00", '', $t); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $collecteurIdiomes = null; |
|
| 608 | - if (stripos($t, '<:') !== false) { |
|
| 609 | - $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 610 | - $t = $collecteurIdiomes->echapper($t); |
|
| 611 | - } |
|
| 612 | - $collecteurMultis = null; |
|
| 613 | - if (stripos($t, '<multi') !== false) { |
|
| 614 | - $collecteurMultis = new CollecteurMultis(); |
|
| 615 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - if (!function_exists('interdire_scripts')) { |
|
| 619 | - include_spip('inc/texte'); |
|
| 620 | - } |
|
| 621 | - $t = interdire_scripts($t); // jolifier le php |
|
| 622 | - $t = echappe_js($t); |
|
| 623 | - |
|
| 624 | - if (!isset($safehtml)) { |
|
| 625 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 626 | - } |
|
| 627 | - if ($safehtml) { |
|
| 628 | - $t = $safehtml($t); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ($collecteurMultis) { |
|
| 632 | - $t = $collecteurMultis->retablir($t); |
|
| 633 | - } |
|
| 634 | - if ($collecteurIdiomes) { |
|
| 635 | - $t = $collecteurIdiomes->retablir($t); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 597 | + static $safehtml; |
|
| 598 | + |
|
| 599 | + if (!$t || !is_string($t)) { |
|
| 600 | + return $t; |
|
| 601 | + } |
|
| 602 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 603 | + if (!str_contains($t, '<')) { |
|
| 604 | + return str_replace("\x00", '', $t); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $collecteurIdiomes = null; |
|
| 608 | + if (stripos($t, '<:') !== false) { |
|
| 609 | + $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 610 | + $t = $collecteurIdiomes->echapper($t); |
|
| 611 | + } |
|
| 612 | + $collecteurMultis = null; |
|
| 613 | + if (stripos($t, '<multi') !== false) { |
|
| 614 | + $collecteurMultis = new CollecteurMultis(); |
|
| 615 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + if (!function_exists('interdire_scripts')) { |
|
| 619 | + include_spip('inc/texte'); |
|
| 620 | + } |
|
| 621 | + $t = interdire_scripts($t); // jolifier le php |
|
| 622 | + $t = echappe_js($t); |
|
| 623 | + |
|
| 624 | + if (!isset($safehtml)) { |
|
| 625 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 626 | + } |
|
| 627 | + if ($safehtml) { |
|
| 628 | + $t = $safehtml($t); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ($collecteurMultis) { |
|
| 632 | + $t = $collecteurMultis->retablir($t); |
|
| 633 | + } |
|
| 634 | + if ($collecteurIdiomes) { |
|
| 635 | + $t = $collecteurIdiomes->retablir($t); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -643,29 +643,29 @@ discard block |
||
| 643 | 643 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 644 | 644 | */ |
| 645 | 645 | function is_html_safe(string $texte): bool { |
| 646 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 647 | - return $is_html_safe($texte); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 651 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 652 | - // safehtml reduit aussi potentiellement les |
|
| 653 | - $texte = str_replace(' ', ' ', $texte); |
|
| 654 | - // safehtml remplace les entités html |
|
| 655 | - if (str_contains($texte, '&') && str_contains($texte, ';')) { |
|
| 656 | - $texte = html2unicode($texte, true); |
|
| 657 | - } |
|
| 658 | - // safehtml remplace les entités numériques |
|
| 659 | - if (str_contains($texte, '&#')) { |
|
| 660 | - $texte = unicode2charset($texte); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $texte_safe = safehtml($texte); |
|
| 664 | - |
|
| 665 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 666 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 667 | - // donc un test d'egalite est trop strict |
|
| 668 | - return strlen($texte_safe) === strlen($texte); |
|
| 646 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 647 | + return $is_html_safe($texte); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 651 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 652 | + // safehtml reduit aussi potentiellement les |
|
| 653 | + $texte = str_replace(' ', ' ', $texte); |
|
| 654 | + // safehtml remplace les entités html |
|
| 655 | + if (str_contains($texte, '&') && str_contains($texte, ';')) { |
|
| 656 | + $texte = html2unicode($texte, true); |
|
| 657 | + } |
|
| 658 | + // safehtml remplace les entités numériques |
|
| 659 | + if (str_contains($texte, '&#')) { |
|
| 660 | + $texte = unicode2charset($texte); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $texte_safe = safehtml($texte); |
|
| 664 | + |
|
| 665 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 666 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 667 | + // donc un test d'egalite est trop strict |
|
| 668 | + return strlen($texte_safe) === strlen($texte); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -686,13 +686,13 @@ discard block |
||
| 686 | 686 | * texte sans les modèles d'image |
| 687 | 687 | **/ |
| 688 | 688 | function supprime_img($letexte, $message = null) { |
| 689 | - if ($message === null) { |
|
| 690 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return preg_replace( |
|
| 694 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 695 | - $message, |
|
| 696 | - $letexte |
|
| 697 | - ); |
|
| 689 | + if ($message === null) { |
|
| 690 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return preg_replace( |
|
| 694 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 695 | + $message, |
|
| 696 | + $letexte |
|
| 697 | + ); |
|
| 698 | 698 | } |
@@ -556,8 +556,7 @@ |
||
| 556 | 556 | $collecteurLiens = $collecteurModeles = null; |
| 557 | 557 | if (!empty($options['expanser_liens'])) { |
| 558 | 558 | $texte = expanser_liens($texte, $connect, $env); |
| 559 | - } |
|
| 560 | - else { |
|
| 559 | + } else { |
|
| 561 | 560 | $collecteurLiens = new CollecteurLiens(); |
| 562 | 561 | $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
| 563 | 562 | |