@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Langue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (is_null($liste_langues)) { |
|
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | - } else { |
|
| 44 | - if (is_array($liste_langues)) { |
|
| 45 | - $liste_langues = implode(',', $liste_langues); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | - |
|
| 50 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | - if (!$lang) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( |
|
| 58 | - str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | - || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | - ) { |
|
| 61 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | - |
|
| 65 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | - } else { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 41 | + if (is_null($liste_langues)) { |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + } else { |
|
| 44 | + if (is_array($liste_langues)) { |
|
| 45 | + $liste_langues = implode(',', $liste_langues); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + |
|
| 50 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | + if (!$lang) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( |
|
| 58 | + str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | + || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | + ) { |
|
| 61 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | + |
|
| 65 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | + } else { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 79 | 79 | |
| 80 | 80 | function choisir_traduction($trads, $lang = '') { |
| 81 | - $k = approcher_langue($trads, $lang); |
|
| 81 | + $k = approcher_langue($trads, $lang); |
|
| 82 | 82 | |
| 83 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 83 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // retourne son 2e argument si c'est un index du premier |
@@ -88,21 +88,21 @@ discard block |
||
| 88 | 88 | // la langue X etant consideree comme une approche de X_Y |
| 89 | 89 | function approcher_langue($trads, $lang = '') { |
| 90 | 90 | |
| 91 | - if (!$lang) { |
|
| 92 | - $lang = $GLOBALS['spip_lang']; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (isset($trads[$lang])) { |
|
| 96 | - return $lang; |
|
| 97 | - } // cas des langues xx_yy |
|
| 98 | - else { |
|
| 99 | - $r = explode('_', (string) $lang); |
|
| 100 | - if (isset($trads[$r[0]])) { |
|
| 101 | - return $r[0]; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return ''; |
|
| 91 | + if (!$lang) { |
|
| 92 | + $lang = $GLOBALS['spip_lang']; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (isset($trads[$lang])) { |
|
| 96 | + return $lang; |
|
| 97 | + } // cas des langues xx_yy |
|
| 98 | + else { |
|
| 99 | + $r = explode('_', (string) $lang); |
|
| 100 | + if (isset($trads[$r[0]])) { |
|
| 101 | + return $r[0]; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return ''; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * Nom de la langue, sinon son code. |
| 118 | 118 | **/ |
| 119 | 119 | function traduire_nom_langue($lang) { |
| 120 | - include_spip('inc/lang_liste'); |
|
| 121 | - include_spip('inc/charsets'); |
|
| 120 | + include_spip('inc/lang_liste'); |
|
| 121 | + include_spip('inc/charsets'); |
|
| 122 | 122 | |
| 123 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 123 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | // hebreu a priori), 'droitier' sinon. |
| 134 | 134 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 135 | 135 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 136 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 136 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | 137 | |
| 138 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | - $gaucher : $droitier; |
|
| 138 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | + $gaucher : $droitier; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // typo francaise ou anglaise ? |
@@ -145,29 +145,29 @@ discard block |
||
| 145 | 145 | // sinon determiner la typo en fonction de la langue courante |
| 146 | 146 | |
| 147 | 147 | function lang_typo($lang = '') { |
| 148 | - if (!$lang) { |
|
| 149 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | - } |
|
| 151 | - if ( |
|
| 152 | - $lang == 'eo' |
|
| 153 | - || $lang == 'fr' |
|
| 154 | - || str_starts_with((string) $lang, 'fr_') |
|
| 155 | - || $lang == 'cpf' |
|
| 156 | - ) { |
|
| 157 | - return 'fr'; |
|
| 158 | - } else { |
|
| 159 | - return 'en'; |
|
| 160 | - } |
|
| 148 | + if (!$lang) { |
|
| 149 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | + } |
|
| 151 | + if ( |
|
| 152 | + $lang == 'eo' |
|
| 153 | + || $lang == 'fr' |
|
| 154 | + || str_starts_with((string) $lang, 'fr_') |
|
| 155 | + || $lang == 'cpf' |
|
| 156 | + ) { |
|
| 157 | + return 'fr'; |
|
| 158 | + } else { |
|
| 159 | + return 'en'; |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 164 | 164 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 165 | 165 | function changer_typo($lang = '') { |
| 166 | - if ($lang) { |
|
| 167 | - $GLOBALS['lang_objet'] = $lang; |
|
| 168 | - } else { |
|
| 169 | - unset($GLOBALS['lang_objet']); |
|
| 170 | - } |
|
| 166 | + if ($lang) { |
|
| 167 | + $GLOBALS['lang_objet'] = $lang; |
|
| 168 | + } else { |
|
| 169 | + unset($GLOBALS['lang_objet']); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // |
@@ -177,56 +177,56 @@ discard block |
||
| 177 | 177 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 178 | 178 | // |
| 179 | 179 | function menu_langues($nom_select, $default = '') { |
| 180 | - include_spip('inc/actions'); |
|
| 181 | - |
|
| 182 | - $langues = liste_options_langues($nom_select); |
|
| 183 | - $ret = ''; |
|
| 184 | - if ($langues === []) { |
|
| 185 | - return ''; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!$default) { |
|
| 189 | - $default = $GLOBALS['spip_lang']; |
|
| 190 | - } |
|
| 191 | - foreach ($langues as $l) { |
|
| 192 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!test_espace_prive()) { |
|
| 197 | - $cible = self(); |
|
| 198 | - $base = ''; |
|
| 199 | - } else { |
|
| 200 | - $cible = self(); |
|
| 201 | - $base = spip_connect() ? 'base' : ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | - |
|
| 206 | - return generer_action_auteur( |
|
| 207 | - 'converser', |
|
| 208 | - $base, |
|
| 209 | - $cible, |
|
| 210 | - (select_langues($nom_select, $change, $ret) |
|
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | - " method='post'" |
|
| 213 | - ); |
|
| 180 | + include_spip('inc/actions'); |
|
| 181 | + |
|
| 182 | + $langues = liste_options_langues($nom_select); |
|
| 183 | + $ret = ''; |
|
| 184 | + if ($langues === []) { |
|
| 185 | + return ''; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!$default) { |
|
| 189 | + $default = $GLOBALS['spip_lang']; |
|
| 190 | + } |
|
| 191 | + foreach ($langues as $l) { |
|
| 192 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!test_espace_prive()) { |
|
| 197 | + $cible = self(); |
|
| 198 | + $base = ''; |
|
| 199 | + } else { |
|
| 200 | + $cible = self(); |
|
| 201 | + $base = spip_connect() ? 'base' : ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | + |
|
| 206 | + return generer_action_auteur( |
|
| 207 | + 'converser', |
|
| 208 | + $base, |
|
| 209 | + $cible, |
|
| 210 | + (select_langues($nom_select, $change, $ret) |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | + " method='post'" |
|
| 213 | + ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | - static $cpt = 0; |
|
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 219 | - |
|
| 220 | - return |
|
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | - "<select name='$nom_select' id='$id' " |
|
| 223 | - . ((test_espace_prive()) ? |
|
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 226 | - . $change |
|
| 227 | - . ">\n" |
|
| 228 | - . $options |
|
| 229 | - . '</select>'; |
|
| 217 | + static $cpt = 0; |
|
| 218 | + $id = 'menu_langues' . $cpt++; |
|
| 219 | + |
|
| 220 | + return |
|
| 221 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | + "<select name='$nom_select' id='$id' " |
|
| 223 | + . ((test_espace_prive()) ? |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | + ("class='forml menu_langues'")) |
|
| 226 | + . $change |
|
| 227 | + . ">\n" |
|
| 228 | + . $options |
|
| 229 | + . '</select>'; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -248,34 +248,34 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | function liste_options_langues($nom_select) { |
| 250 | 250 | |
| 251 | - switch ($nom_select) { |
|
| 252 | - # #MENU_LANG |
|
| 253 | - case 'var_lang': |
|
| 254 | - # menu de changement de la langue d'un article |
|
| 255 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | - case 'changer_lang': |
|
| 257 | - $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | - break; |
|
| 259 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | - # les langues presentes sous forme de fichiers de langue |
|
| 261 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | - case 'var_lang_ecrire': |
|
| 263 | - default: |
|
| 264 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | - init_langues(); |
|
| 266 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | - break; |
|
| 251 | + switch ($nom_select) { |
|
| 252 | + # #MENU_LANG |
|
| 253 | + case 'var_lang': |
|
| 254 | + # menu de changement de la langue d'un article |
|
| 255 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | + case 'changer_lang': |
|
| 257 | + $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | + break; |
|
| 259 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | + # les langues presentes sous forme de fichiers de langue |
|
| 261 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | + case 'var_lang_ecrire': |
|
| 263 | + default: |
|
| 264 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | + init_langues(); |
|
| 266 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | + break; |
|
| 268 | 268 | |
| 269 | 269 | # dernier choix possible : toutes les langues = langues_proposees |
| 270 | 270 | # + langues_multilingues ; mais, ne sert pas |
| 271 | 271 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 272 | - } |
|
| 273 | - if (count($langues) <= 1) { |
|
| 274 | - return []; |
|
| 275 | - } |
|
| 276 | - sort($langues); |
|
| 272 | + } |
|
| 273 | + if (count($langues) <= 1) { |
|
| 274 | + return []; |
|
| 275 | + } |
|
| 276 | + sort($langues); |
|
| 277 | 277 | |
| 278 | - return $langues; |
|
| 278 | + return $langues; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,39 +290,39 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function verifier_lang_url() { |
| 292 | 292 | |
| 293 | - // quelle langue est demandee ? |
|
| 294 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | - } |
|
| 298 | - if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | - } |
|
| 301 | - if (isset($_GET['lang'])) { |
|
| 302 | - $lang_demandee = $_GET['lang']; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | - if ( |
|
| 307 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | - && changer_langue($lang_demandee) |
|
| 309 | - && $lang_demandee != @$_GET['lang'] |
|
| 310 | - ) { |
|
| 311 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | - // ici on a besoin des var_truc |
|
| 313 | - foreach ($_GET as $var => $val) { |
|
| 314 | - if (!strncmp('var_', $var, 4)) { |
|
| 315 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - include_spip('inc/headers'); |
|
| 319 | - redirige_par_entete($destination); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | - // (pour criteres {lang}). |
|
| 325 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 293 | + // quelle langue est demandee ? |
|
| 294 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | + } |
|
| 298 | + if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | + } |
|
| 301 | + if (isset($_GET['lang'])) { |
|
| 302 | + $lang_demandee = $_GET['lang']; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | + if ( |
|
| 307 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | + && changer_langue($lang_demandee) |
|
| 309 | + && $lang_demandee != @$_GET['lang'] |
|
| 310 | + ) { |
|
| 311 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | + // ici on a besoin des var_truc |
|
| 313 | + foreach ($_GET as $var => $val) { |
|
| 314 | + if (!strncmp('var_', $var, 4)) { |
|
| 315 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + include_spip('inc/headers'); |
|
| 319 | + redirige_par_entete($destination); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | + // (pour criteres {lang}). |
|
| 325 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -340,19 +340,19 @@ discard block |
||
| 340 | 340 | * La langue sélectionnée |
| 341 | 341 | **/ |
| 342 | 342 | function utiliser_langue_site($liste_langues = null) { |
| 343 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | - if ( |
|
| 345 | - isset($GLOBALS['meta']['langue_site']) |
|
| 346 | - && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | - ) { |
|
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | - } |
|
| 350 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return $GLOBALS['spip_lang']; |
|
| 343 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | + if ( |
|
| 345 | + isset($GLOBALS['meta']['langue_site']) |
|
| 346 | + && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | + ) { |
|
| 348 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | + } |
|
| 350 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return $GLOBALS['spip_lang']; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -371,38 +371,38 @@ discard block |
||
| 371 | 371 | **/ |
| 372 | 372 | function utiliser_langue_visiteur($liste_langues = null) { |
| 373 | 373 | |
| 374 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | - if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | - if ( |
|
| 381 | - isset($_COOKIE[$l]) |
|
| 382 | - && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | - ) { |
|
| 384 | - return $l; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ( |
|
| 388 | - isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | - && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | - ) { |
|
| 391 | - return $l; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | - foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | - if ( |
|
| 397 | - preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | - && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | - ) { |
|
| 400 | - return $l; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return utiliser_langue_site($liste_langues); |
|
| 374 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | + if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | + if ( |
|
| 381 | + isset($_COOKIE[$l]) |
|
| 382 | + && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | + ) { |
|
| 384 | + return $l; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ( |
|
| 388 | + isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | + && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | + ) { |
|
| 391 | + return $l; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | + foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | + if ( |
|
| 397 | + preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | + && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | + ) { |
|
| 400 | + return $l; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return utiliser_langue_site($liste_langues); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | 414 | function match_langue($chaine) { |
| 415 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -430,38 +430,38 @@ discard block |
||
| 430 | 430 | **/ |
| 431 | 431 | function init_langues() { |
| 432 | 432 | |
| 433 | - // liste des langues dans les meta, sauf a l'install |
|
| 434 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | - |
|
| 436 | - $tout = []; |
|
| 437 | - if (!$all_langs) { |
|
| 438 | - // trouver tous les modules lang/spip_xx.php |
|
| 439 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | - foreach (array_keys($modules) as $name) { |
|
| 441 | - if ( |
|
| 442 | - preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | - && match_langue($regs[1]) |
|
| 444 | - ) { |
|
| 445 | - $tout[] = $regs[1]; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - sort($tout); |
|
| 449 | - $tout = implode(',', $tout); |
|
| 450 | - // Si les langues n'ont pas change, ne rien faire |
|
| 451 | - if ($tout != $all_langs) { |
|
| 452 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | - include_spip('inc/meta'); |
|
| 454 | - ecrire_meta('langues_proposees', $tout); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | - ? _LANGUE_PAR_DEFAUT |
|
| 462 | - : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | - ecrire_meta('langue_site', $tout); |
|
| 464 | - } |
|
| 433 | + // liste des langues dans les meta, sauf a l'install |
|
| 434 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | + |
|
| 436 | + $tout = []; |
|
| 437 | + if (!$all_langs) { |
|
| 438 | + // trouver tous les modules lang/spip_xx.php |
|
| 439 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | + foreach (array_keys($modules) as $name) { |
|
| 441 | + if ( |
|
| 442 | + preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | + && match_langue($regs[1]) |
|
| 444 | + ) { |
|
| 445 | + $tout[] = $regs[1]; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + sort($tout); |
|
| 449 | + $tout = implode(',', $tout); |
|
| 450 | + // Si les langues n'ont pas change, ne rien faire |
|
| 451 | + if ($tout != $all_langs) { |
|
| 452 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | + include_spip('inc/meta'); |
|
| 454 | + ecrire_meta('langues_proposees', $tout); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | + (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | + ? _LANGUE_PAR_DEFAUT |
|
| 462 | + : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | + ecrire_meta('langue_site', $tout); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -475,10 +475,10 @@ discard block |
||
| 475 | 475 | * Code html de la balise <html> |
| 476 | 476 | **/ |
| 477 | 477 | function html_lang_attributes() { |
| 478 | - $lang = $GLOBALS['spip_lang']; |
|
| 479 | - $dir = lang_dir($lang); |
|
| 478 | + $lang = $GLOBALS['spip_lang']; |
|
| 479 | + $dir = lang_dir($lang); |
|
| 480 | 480 | |
| 481 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 481 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | 494 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 495 | - return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 495 | + return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | 41 | if (is_null($liste_langues)) { |
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | 43 | } else { |
| 44 | 44 | if (is_array($liste_langues)) { |
| 45 | 45 | $liste_langues = implode(',', $liste_langues); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 48 | + $liste_langues = ','.$liste_langues.','; |
|
| 49 | 49 | |
| 50 | 50 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 51 | 51 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | foreach ($langues as $l) { |
| 192 | 192 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 193 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (!test_espace_prive()) { |
@@ -208,21 +208,20 @@ discard block |
||
| 208 | 208 | $base, |
| 209 | 209 | $cible, |
| 210 | 210 | (select_langues($nom_select, $change, $ret) |
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 212 | 212 | " method='post'" |
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | 217 | static $cpt = 0; |
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 218 | + $id = 'menu_langues'.$cpt++; |
|
| 219 | 219 | |
| 220 | 220 | return |
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 221 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 222 | 222 | "<select name='$nom_select' id='$id' " |
| 223 | 223 | . ((test_espace_prive()) ? |
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : ("class='forml menu_langues'")) |
|
| 226 | 225 | . $change |
| 227 | 226 | . ">\n" |
| 228 | 227 | . $options |
@@ -345,7 +344,7 @@ discard block |
||
| 345 | 344 | isset($GLOBALS['meta']['langue_site']) |
| 346 | 345 | && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 347 | 346 | ) { |
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 347 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 349 | 348 | } |
| 350 | 349 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 351 | 350 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -457,7 +456,7 @@ discard block |
||
| 457 | 456 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 458 | 457 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 459 | 458 | $GLOBALS['meta']['langue_site'] = $tout = |
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 459 | + (!$all_langs || str_contains(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,")) |
|
| 461 | 460 | ? _LANGUE_PAR_DEFAUT |
| 462 | 461 | : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
| 463 | 462 | ecrire_meta('langue_site', $tout); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | // |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // |
@@ -20,52 +20,52 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function produire_image_math($tex) { |
| 22 | 22 | |
| 23 | - switch ($GLOBALS['traiter_math']) { |
|
| 24 | - // Attention: mathml desactiv'e pour l'instant |
|
| 25 | - case 'mathml': |
|
| 26 | - $ext = '.xhtml'; |
|
| 27 | - $server = $GLOBALS['mathml_server']; |
|
| 28 | - break; |
|
| 29 | - case 'tex': |
|
| 30 | - $ext = '.png'; |
|
| 31 | - $server = $GLOBALS['tex_server']; |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - return $tex; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | - } |
|
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - // Aller chercher l'image sur le serveur |
|
| 45 | - if (!@file_exists($fichier) && $server) { |
|
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | - include_spip('inc/distant'); |
|
| 48 | - recuperer_url($url, ['file' => $fichier]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - // Composer la reponse selon presence ou non de l'image |
|
| 53 | - $tex = entites_html($tex); |
|
| 54 | - if (@file_exists($fichier)) { |
|
| 55 | - // MathML |
|
| 56 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | - return implode('', file($fichier)); |
|
| 58 | - } // TeX |
|
| 59 | - else { |
|
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | - |
|
| 63 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | - } |
|
| 65 | - } else // pas de fichier |
|
| 66 | - { |
|
| 67 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | - } |
|
| 23 | + switch ($GLOBALS['traiter_math']) { |
|
| 24 | + // Attention: mathml desactiv'e pour l'instant |
|
| 25 | + case 'mathml': |
|
| 26 | + $ext = '.xhtml'; |
|
| 27 | + $server = $GLOBALS['mathml_server']; |
|
| 28 | + break; |
|
| 29 | + case 'tex': |
|
| 30 | + $ext = '.png'; |
|
| 31 | + $server = $GLOBALS['tex_server']; |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + return $tex; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | + } |
|
| 41 | + $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + // Aller chercher l'image sur le serveur |
|
| 45 | + if (!@file_exists($fichier) && $server) { |
|
| 46 | + spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | + include_spip('inc/distant'); |
|
| 48 | + recuperer_url($url, ['file' => $fichier]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + // Composer la reponse selon presence ou non de l'image |
|
| 53 | + $tex = entites_html($tex); |
|
| 54 | + if (@file_exists($fichier)) { |
|
| 55 | + // MathML |
|
| 56 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | + return implode('', file($fichier)); |
|
| 58 | + } // TeX |
|
| 59 | + else { |
|
| 60 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | + |
|
| 63 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | + } |
|
| 65 | + } else // pas de fichier |
|
| 66 | + { |
|
| 67 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -100,52 +100,52 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 102 | 102 | |
| 103 | - $texte_a_voir = $letexte; |
|
| 104 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | - $fin = strlen($texte_a_voir); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | - $texte_milieu = substr( |
|
| 111 | - $texte_a_voir, |
|
| 112 | - $debut + strlen('<math>'), |
|
| 113 | - $fin - $debut - strlen('<math>') |
|
| 114 | - ); |
|
| 115 | - $texte_fin = substr( |
|
| 116 | - $texte_a_voir, |
|
| 117 | - $fin + strlen('</math>'), |
|
| 118 | - strlen($texte_a_voir) |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | - . code_echappement($echap, $source) |
|
| 131 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Les simples $x^2$ en mode 'span' |
|
| 135 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | - $expression = $regs[1]; |
|
| 137 | - if ($defaire_amp) { |
|
| 138 | - $expression = str_replace('&', '&', $expression); |
|
| 139 | - } |
|
| 140 | - $echap = produire_image_math($expression); |
|
| 141 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | - . code_echappement($echap, $source) |
|
| 144 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $texte_a_voir; |
|
| 103 | + $texte_a_voir = $letexte; |
|
| 104 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | + $fin = strlen($texte_a_voir); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | + $texte_milieu = substr( |
|
| 111 | + $texte_a_voir, |
|
| 112 | + $debut + strlen('<math>'), |
|
| 113 | + $fin - $debut - strlen('<math>') |
|
| 114 | + ); |
|
| 115 | + $texte_fin = substr( |
|
| 116 | + $texte_a_voir, |
|
| 117 | + $fin + strlen('</math>'), |
|
| 118 | + strlen($texte_a_voir) |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | + . code_echappement($echap, $source) |
|
| 131 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Les simples $x^2$ en mode 'span' |
|
| 135 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | + $expression = $regs[1]; |
|
| 137 | + if ($defaire_amp) { |
|
| 138 | + $expression = str_replace('&', '&', $expression); |
|
| 139 | + } |
|
| 140 | + $echap = produire_image_math($expression); |
|
| 141 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | + . code_echappement($echap, $source) |
|
| 144 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $texte_a_voir; |
|
| 151 | 151 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 39 | 39 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 40 | 40 | } |
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 41 | + $fichier = $dir_tex.md5(trim((string) $tex)).$ext; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // Aller chercher l'image sur le serveur |
| 45 | 45 | if (!@file_exists($fichier) && $server) { |
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 46 | + spip_log($url = $server.'?'.rawurlencode((string) $tex)); |
|
| 47 | 47 | include_spip('inc/distant'); |
| 48 | 48 | recuperer_url($url, ['file' => $fichier]); |
| 49 | 49 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | return implode('', file($fichier)); |
| 58 | 58 | } // TeX |
| 59 | 59 | else { |
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 60 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 61 | 61 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 62 | 62 | |
| 63 | 63 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if ($defaire_amp) { |
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 128 | 128 | $pos = strpos($texte_milieu, (string) $regs[0]); |
| 129 | 129 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 130 | 130 | . code_echappement($echap, $source) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 147 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $texte_a_voir; |
@@ -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 | /** |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | * Tableau des champs et valeurs collectées |
| 39 | 39 | */ |
| 40 | 40 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 41 | - $c = $set; |
|
| 42 | - if (!$c) { |
|
| 43 | - $c = []; |
|
| 44 | - foreach ($include_list as $champ) { |
|
| 45 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | - $val = _request($champ); |
|
| 48 | - if ($tous || $val !== null) { |
|
| 49 | - $c[$champ] = $val; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - // on ajoute toujours la lang en saisie possible |
|
| 53 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | - if ($l = _request('changer_lang')) { |
|
| 55 | - $c['lang'] = $l; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - foreach ($exclude_list as $champ) { |
|
| 59 | - unset($c[$champ]); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $c; |
|
| 41 | + $c = $set; |
|
| 42 | + if (!$c) { |
|
| 43 | + $c = []; |
|
| 44 | + foreach ($include_list as $champ) { |
|
| 45 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | + $val = _request($champ); |
|
| 48 | + if ($tous || $val !== null) { |
|
| 49 | + $c[$champ] = $val; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + // on ajoute toujours la lang en saisie possible |
|
| 53 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | + if ($l = _request('changer_lang')) { |
|
| 55 | + $c['lang'] = $l; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + foreach ($exclude_list as $champ) { |
|
| 59 | + unset($c[$champ]); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $c; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -96,259 +96,259 @@ discard block |
||
| 96 | 96 | * - chaîne : texte d'un message d'erreur |
| 97 | 97 | */ |
| 98 | 98 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 99 | - if (!$id_objet = (int) $id_objet) { |
|
| 100 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | - |
|
| 102 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - include_spip('inc/filtres'); |
|
| 106 | - |
|
| 107 | - $table_objet = table_objet($objet, $serveur); |
|
| 108 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | - |
|
| 113 | - // Appels incomplets (sans $c) |
|
| 114 | - if (!is_array($c)) { |
|
| 115 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | - |
|
| 117 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | - // il faut passer par instituer_XX() |
|
| 123 | - // TODO: faut-il passer ces variables interdites |
|
| 124 | - // dans un fichier de description separe ? |
|
| 125 | - unset($c['statut']); |
|
| 126 | - unset($c['id_parent']); |
|
| 127 | - unset($c['id_rubrique']); |
|
| 128 | - unset($c['id_secteur']); |
|
| 129 | - |
|
| 130 | - // Gerer les champs non vides |
|
| 131 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 132 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | - if (isset($c[$champ]) && $c[$champ] === '') { |
|
| 134 | - $c[$champ] = $sinon; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // N'accepter que les champs qui existent dans la table |
|
| 140 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | - // et dont la valeur n'est pas null |
|
| 142 | - $champs = array_filter($champs, static fn($var) => $var !== null); |
|
| 143 | - // TODO: ici aussi on peut valider les contenus |
|
| 144 | - // en fonction du type |
|
| 145 | - |
|
| 146 | - // Nettoyer les valeurs |
|
| 147 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 148 | - |
|
| 149 | - // On récupère l'état avant toute modification |
|
| 150 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 151 | - |
|
| 152 | - // Envoyer aux plugins |
|
| 153 | - $champs = pipeline( |
|
| 154 | - 'pre_edition', |
|
| 155 | - [ |
|
| 156 | - 'args' => [ |
|
| 157 | - 'table' => $spip_table_objet, // compatibilite |
|
| 158 | - 'table_objet' => $table_objet, |
|
| 159 | - 'spip_table_objet' => $spip_table_objet, |
|
| 160 | - 'desc' => $desc, |
|
| 161 | - 'type' => $objet, |
|
| 162 | - 'id_objet' => $id_objet, |
|
| 163 | - 'data' => $options['data'] ?? null, |
|
| 164 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 165 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 166 | - 'serveur' => $serveur, |
|
| 167 | - 'action' => $options['action'] ?? 'modifier' |
|
| 168 | - ], |
|
| 169 | - 'data' => $champs |
|
| 170 | - ] |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - if (!$champs) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | - include_spip('inc/config'); |
|
| 180 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 181 | - include_spip('inc/drapeau_edition'); |
|
| 182 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 186 | - include_spip('inc/editer'); |
|
| 187 | - if (!isset($options['data']) || is_null($options['data'])) { |
|
| 188 | - $options['data'] = &$_POST; |
|
| 189 | - } |
|
| 190 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 191 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 192 | - // et gere l'interface |
|
| 193 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 194 | - if ($conflits) { |
|
| 195 | - return _T('titre_conflit_edition'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($champs) { |
|
| 199 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 200 | - if (isset($champs['lang'])) { |
|
| 201 | - if ($changer_lang = $champs['lang']) { |
|
| 202 | - $id_rubrique = 0; |
|
| 203 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 204 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 205 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 206 | - } |
|
| 207 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 208 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 209 | - } |
|
| 210 | - // on laisse 'lang' dans $champs, |
|
| 211 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 212 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 213 | - // deja pris en compte |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // la modif peut avoir lieu |
|
| 217 | - |
|
| 218 | - // faut-il ajouter date_modif ? |
|
| 219 | - if ( |
|
| 220 | - !empty($options['date_modif']) && !isset($champs[$options['date_modif']]) |
|
| 221 | - ) { |
|
| 222 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // allez on commit la modif |
|
| 226 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 227 | - |
|
| 228 | - // on verifie si elle est bien passee |
|
| 229 | - $moof = sql_fetsel( |
|
| 230 | - array_keys($champs), |
|
| 231 | - $spip_table_objet, |
|
| 232 | - "$id_table_objet=" . (int) $id_objet, |
|
| 233 | - [], |
|
| 234 | - [], |
|
| 235 | - '', |
|
| 236 | - [], |
|
| 237 | - $serveur |
|
| 238 | - ); |
|
| 239 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 240 | - if ($moof != $champs) { |
|
| 241 | - $liste = []; |
|
| 242 | - foreach ($moof as $k => $v) { |
|
| 243 | - if ( |
|
| 244 | - $v !== $champs[$k] |
|
| 245 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 246 | - && (!is_numeric($v) || (int) $v !== (int) $champs[$k]) |
|
| 247 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 248 | - && (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 249 | - ) { |
|
| 250 | - $liste[] = $k; |
|
| 251 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 252 | - $conflits[$k]['save'] = $v; |
|
| 253 | - |
|
| 254 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 255 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 256 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 257 | - include_spip('inc/charsets'); |
|
| 258 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 259 | - array_pop($liste); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 265 | - // c'est un cas exceptionnel |
|
| 266 | - if ($liste !== []) { |
|
| 267 | - spip_log( |
|
| 268 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | - 'modifier.' . _LOG_CRITIQUE |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return _T( |
|
| 273 | - 'erreur_technique_enregistrement_champs', |
|
| 274 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // Invalider les caches |
|
| 280 | - if (isset($options['invalideur']) && $options['invalideur']) { |
|
| 281 | - include_spip('inc/invalideur'); |
|
| 282 | - if (is_array($options['invalideur'])) { |
|
| 283 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 284 | - } else { |
|
| 285 | - suivre_invalideur($options['invalideur']); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // Notifications, gestion des revisions... |
|
| 290 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 291 | - pipeline( |
|
| 292 | - 'post_edition', |
|
| 293 | - [ |
|
| 294 | - 'args' => [ |
|
| 295 | - 'table' => $spip_table_objet, |
|
| 296 | - 'table_objet' => $table_objet, |
|
| 297 | - 'spip_table_objet' => $spip_table_objet, |
|
| 298 | - 'desc' => $desc, |
|
| 299 | - 'type' => $objet, |
|
| 300 | - 'id_objet' => $id_objet, |
|
| 301 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 302 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 303 | - 'serveur' => $serveur, |
|
| 304 | - 'action' => $options['action'] ?? 'modifier' |
|
| 305 | - ], |
|
| 306 | - 'data' => $champs |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // Appeler une notification |
|
| 312 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 313 | - $notifications( |
|
| 314 | - "{$objet}_modifier", |
|
| 315 | - $id_objet, |
|
| 316 | - [ |
|
| 317 | - 'champs' => $champs, |
|
| 318 | - ] |
|
| 319 | - ); |
|
| 320 | - $notifications( |
|
| 321 | - 'objet_modifier', |
|
| 322 | - $id_objet, |
|
| 323 | - [ |
|
| 324 | - 'objet' => $objet, |
|
| 325 | - 'id_objet' => $id_objet, |
|
| 326 | - 'champs' => $champs, |
|
| 327 | - ] |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // journaliser l'affaire |
|
| 332 | - // message a affiner :-) |
|
| 333 | - include_spip('inc/filtres_mini'); |
|
| 334 | - $qui = ''; |
|
| 335 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 336 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 337 | - } |
|
| 338 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 339 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 340 | - } |
|
| 341 | - if ($qui == '') { |
|
| 342 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 343 | - } |
|
| 344 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 345 | - '+', |
|
| 346 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 347 | - ) . ')'), [ |
|
| 348 | - 'faire' => 'modifier', |
|
| 349 | - 'quoi' => $objet, |
|
| 350 | - 'id' => $id_objet |
|
| 351 | - ]); |
|
| 352 | - |
|
| 353 | - return ''; |
|
| 99 | + if (!$id_objet = (int) $id_objet) { |
|
| 100 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | + |
|
| 102 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + include_spip('inc/filtres'); |
|
| 106 | + |
|
| 107 | + $table_objet = table_objet($objet, $serveur); |
|
| 108 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | + |
|
| 113 | + // Appels incomplets (sans $c) |
|
| 114 | + if (!is_array($c)) { |
|
| 115 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + |
|
| 117 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | + // il faut passer par instituer_XX() |
|
| 123 | + // TODO: faut-il passer ces variables interdites |
|
| 124 | + // dans un fichier de description separe ? |
|
| 125 | + unset($c['statut']); |
|
| 126 | + unset($c['id_parent']); |
|
| 127 | + unset($c['id_rubrique']); |
|
| 128 | + unset($c['id_secteur']); |
|
| 129 | + |
|
| 130 | + // Gerer les champs non vides |
|
| 131 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 132 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | + if (isset($c[$champ]) && $c[$champ] === '') { |
|
| 134 | + $c[$champ] = $sinon; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // N'accepter que les champs qui existent dans la table |
|
| 140 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | + // et dont la valeur n'est pas null |
|
| 142 | + $champs = array_filter($champs, static fn($var) => $var !== null); |
|
| 143 | + // TODO: ici aussi on peut valider les contenus |
|
| 144 | + // en fonction du type |
|
| 145 | + |
|
| 146 | + // Nettoyer les valeurs |
|
| 147 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 148 | + |
|
| 149 | + // On récupère l'état avant toute modification |
|
| 150 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 151 | + |
|
| 152 | + // Envoyer aux plugins |
|
| 153 | + $champs = pipeline( |
|
| 154 | + 'pre_edition', |
|
| 155 | + [ |
|
| 156 | + 'args' => [ |
|
| 157 | + 'table' => $spip_table_objet, // compatibilite |
|
| 158 | + 'table_objet' => $table_objet, |
|
| 159 | + 'spip_table_objet' => $spip_table_objet, |
|
| 160 | + 'desc' => $desc, |
|
| 161 | + 'type' => $objet, |
|
| 162 | + 'id_objet' => $id_objet, |
|
| 163 | + 'data' => $options['data'] ?? null, |
|
| 164 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 165 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 166 | + 'serveur' => $serveur, |
|
| 167 | + 'action' => $options['action'] ?? 'modifier' |
|
| 168 | + ], |
|
| 169 | + 'data' => $champs |
|
| 170 | + ] |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + if (!$champs) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | + include_spip('inc/config'); |
|
| 180 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 181 | + include_spip('inc/drapeau_edition'); |
|
| 182 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 186 | + include_spip('inc/editer'); |
|
| 187 | + if (!isset($options['data']) || is_null($options['data'])) { |
|
| 188 | + $options['data'] = &$_POST; |
|
| 189 | + } |
|
| 190 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 191 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 192 | + // et gere l'interface |
|
| 193 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 194 | + if ($conflits) { |
|
| 195 | + return _T('titre_conflit_edition'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($champs) { |
|
| 199 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 200 | + if (isset($champs['lang'])) { |
|
| 201 | + if ($changer_lang = $champs['lang']) { |
|
| 202 | + $id_rubrique = 0; |
|
| 203 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 204 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 205 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 206 | + } |
|
| 207 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 208 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 209 | + } |
|
| 210 | + // on laisse 'lang' dans $champs, |
|
| 211 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 212 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 213 | + // deja pris en compte |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // la modif peut avoir lieu |
|
| 217 | + |
|
| 218 | + // faut-il ajouter date_modif ? |
|
| 219 | + if ( |
|
| 220 | + !empty($options['date_modif']) && !isset($champs[$options['date_modif']]) |
|
| 221 | + ) { |
|
| 222 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // allez on commit la modif |
|
| 226 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 227 | + |
|
| 228 | + // on verifie si elle est bien passee |
|
| 229 | + $moof = sql_fetsel( |
|
| 230 | + array_keys($champs), |
|
| 231 | + $spip_table_objet, |
|
| 232 | + "$id_table_objet=" . (int) $id_objet, |
|
| 233 | + [], |
|
| 234 | + [], |
|
| 235 | + '', |
|
| 236 | + [], |
|
| 237 | + $serveur |
|
| 238 | + ); |
|
| 239 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 240 | + if ($moof != $champs) { |
|
| 241 | + $liste = []; |
|
| 242 | + foreach ($moof as $k => $v) { |
|
| 243 | + if ( |
|
| 244 | + $v !== $champs[$k] |
|
| 245 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 246 | + && (!is_numeric($v) || (int) $v !== (int) $champs[$k]) |
|
| 247 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 248 | + && (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 249 | + ) { |
|
| 250 | + $liste[] = $k; |
|
| 251 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 252 | + $conflits[$k]['save'] = $v; |
|
| 253 | + |
|
| 254 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 255 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 256 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 257 | + include_spip('inc/charsets'); |
|
| 258 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 259 | + array_pop($liste); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 265 | + // c'est un cas exceptionnel |
|
| 266 | + if ($liste !== []) { |
|
| 267 | + spip_log( |
|
| 268 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | + 'modifier.' . _LOG_CRITIQUE |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return _T( |
|
| 273 | + 'erreur_technique_enregistrement_champs', |
|
| 274 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // Invalider les caches |
|
| 280 | + if (isset($options['invalideur']) && $options['invalideur']) { |
|
| 281 | + include_spip('inc/invalideur'); |
|
| 282 | + if (is_array($options['invalideur'])) { |
|
| 283 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 284 | + } else { |
|
| 285 | + suivre_invalideur($options['invalideur']); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // Notifications, gestion des revisions... |
|
| 290 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 291 | + pipeline( |
|
| 292 | + 'post_edition', |
|
| 293 | + [ |
|
| 294 | + 'args' => [ |
|
| 295 | + 'table' => $spip_table_objet, |
|
| 296 | + 'table_objet' => $table_objet, |
|
| 297 | + 'spip_table_objet' => $spip_table_objet, |
|
| 298 | + 'desc' => $desc, |
|
| 299 | + 'type' => $objet, |
|
| 300 | + 'id_objet' => $id_objet, |
|
| 301 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 302 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 303 | + 'serveur' => $serveur, |
|
| 304 | + 'action' => $options['action'] ?? 'modifier' |
|
| 305 | + ], |
|
| 306 | + 'data' => $champs |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // Appeler une notification |
|
| 312 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 313 | + $notifications( |
|
| 314 | + "{$objet}_modifier", |
|
| 315 | + $id_objet, |
|
| 316 | + [ |
|
| 317 | + 'champs' => $champs, |
|
| 318 | + ] |
|
| 319 | + ); |
|
| 320 | + $notifications( |
|
| 321 | + 'objet_modifier', |
|
| 322 | + $id_objet, |
|
| 323 | + [ |
|
| 324 | + 'objet' => $objet, |
|
| 325 | + 'id_objet' => $id_objet, |
|
| 326 | + 'champs' => $champs, |
|
| 327 | + ] |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // journaliser l'affaire |
|
| 332 | + // message a affiner :-) |
|
| 333 | + include_spip('inc/filtres_mini'); |
|
| 334 | + $qui = ''; |
|
| 335 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 336 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 337 | + } |
|
| 338 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 339 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 340 | + } |
|
| 341 | + if ($qui == '') { |
|
| 342 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 343 | + } |
|
| 344 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 345 | + '+', |
|
| 346 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 347 | + ) . ')'), [ |
|
| 348 | + 'faire' => 'modifier', |
|
| 349 | + 'quoi' => $objet, |
|
| 350 | + 'id' => $id_objet |
|
| 351 | + ]); |
|
| 352 | + |
|
| 353 | + return ''; |
|
| 354 | 354 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // Appels incomplets (sans $c) |
| 114 | 114 | if (!is_array($c)) { |
| 115 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 115 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 116 | 116 | |
| 117 | 117 | return _T('erreur_technique_enregistrement_impossible'); |
| 118 | 118 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $champs = array_map('corriger_caracteres', $champs); |
| 148 | 148 | |
| 149 | 149 | // On récupère l'état avant toute modification |
| 150 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 150 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 151 | 151 | |
| 152 | 152 | // Envoyer aux plugins |
| 153 | 153 | $champs = pipeline( |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $id_rubrique = 0; |
| 203 | 203 | if (isset($desc['field']['id_rubrique'])) { |
| 204 | 204 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 205 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 205 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".(int) $id_objet); |
|
| 206 | 206 | } |
| 207 | 207 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 208 | 208 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // allez on commit la modif |
| 226 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 226 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".(int) $id_objet, [], $serveur); |
|
| 227 | 227 | |
| 228 | 228 | // on verifie si elle est bien passee |
| 229 | 229 | $moof = sql_fetsel( |
| 230 | 230 | array_keys($champs), |
| 231 | 231 | $spip_table_objet, |
| 232 | - "$id_table_objet=" . (int) $id_objet, |
|
| 232 | + "$id_table_objet=".(int) $id_objet, |
|
| 233 | 233 | [], |
| 234 | 234 | [], |
| 235 | 235 | '', |
@@ -265,13 +265,13 @@ discard block |
||
| 265 | 265 | // c'est un cas exceptionnel |
| 266 | 266 | if ($liste !== []) { |
| 267 | 267 | spip_log( |
| 268 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | - 'modifier.' . _LOG_CRITIQUE |
|
| 268 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 269 | + 'modifier.'._LOG_CRITIQUE |
|
| 270 | 270 | ); |
| 271 | 271 | |
| 272 | 272 | return _T( |
| 273 | 273 | 'erreur_technique_enregistrement_champs', |
| 274 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 274 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 275 | 275 | ); |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -333,18 +333,18 @@ discard block |
||
| 333 | 333 | include_spip('inc/filtres_mini'); |
| 334 | 334 | $qui = ''; |
| 335 | 335 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 336 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 336 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 337 | 337 | } |
| 338 | 338 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 339 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 339 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 340 | 340 | } |
| 341 | 341 | if ($qui == '') { |
| 342 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 342 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 343 | 343 | } |
| 344 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 344 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.implode( |
|
| 345 | 345 | '+', |
| 346 | 346 | array_diff(array_keys($champs), ['date_modif']) |
| 347 | - ) . ')'), [ |
|
| 347 | + ).')'), [ |
|
| 348 | 348 | 'faire' => 'modifier', |
| 349 | 349 | 'quoi' => $objet, |
| 350 | 350 | 'id' => $id_objet |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @package SPIP\Core\Drapeaux\Edition |
| 30 | 30 | **/ |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -44,46 +44,46 @@ discard block |
||
| 44 | 44 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 45 | 45 | **/ |
| 46 | 46 | function lire_tableau_edition() { |
| 47 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | - if (!$edition) { |
|
| 49 | - return []; |
|
| 50 | - } |
|
| 51 | - $changed = false; |
|
| 47 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | + if (!$edition) { |
|
| 49 | + return []; |
|
| 50 | + } |
|
| 51 | + $changed = false; |
|
| 52 | 52 | |
| 53 | - $bon_pour_le_service = time() - 3600; |
|
| 54 | - // parcourir le tableau et virer les vieux |
|
| 55 | - foreach ($edition as $objet => $data) { |
|
| 56 | - if (!is_array($data)) { |
|
| 57 | - unset($edition[$objet]); |
|
| 58 | - } // vieille version |
|
| 59 | - else { |
|
| 60 | - foreach ($data as $id => $tab) { |
|
| 61 | - if (!is_array($tab)) { |
|
| 62 | - unset($edition[$objet][$tab]); |
|
| 63 | - } // vieille version |
|
| 64 | - else { |
|
| 65 | - foreach ($tab as $n => $duo) { |
|
| 66 | - if (current($duo) < $bon_pour_le_service) { |
|
| 67 | - unset($edition[$objet][$id][$n]); |
|
| 68 | - $changed = true; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - if (!$edition[$objet][$id]) { |
|
| 73 | - unset($edition[$objet][$id]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if (!$edition[$objet]) { |
|
| 78 | - unset($edition[$objet]); |
|
| 79 | - } |
|
| 80 | - } |
|
| 53 | + $bon_pour_le_service = time() - 3600; |
|
| 54 | + // parcourir le tableau et virer les vieux |
|
| 55 | + foreach ($edition as $objet => $data) { |
|
| 56 | + if (!is_array($data)) { |
|
| 57 | + unset($edition[$objet]); |
|
| 58 | + } // vieille version |
|
| 59 | + else { |
|
| 60 | + foreach ($data as $id => $tab) { |
|
| 61 | + if (!is_array($tab)) { |
|
| 62 | + unset($edition[$objet][$tab]); |
|
| 63 | + } // vieille version |
|
| 64 | + else { |
|
| 65 | + foreach ($tab as $n => $duo) { |
|
| 66 | + if (current($duo) < $bon_pour_le_service) { |
|
| 67 | + unset($edition[$objet][$id][$n]); |
|
| 68 | + $changed = true; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + if (!$edition[$objet][$id]) { |
|
| 73 | + unset($edition[$objet][$id]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if (!$edition[$objet]) { |
|
| 78 | + unset($edition[$objet]); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if ($changed) { |
|
| 83 | - ecrire_tableau_edition($edition); |
|
| 84 | - } |
|
| 82 | + if ($changed) { |
|
| 83 | + ecrire_tableau_edition($edition); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $edition; |
|
| 86 | + return $edition; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 97 | 97 | **/ |
| 98 | 98 | function ecrire_tableau_edition($edition) { |
| 99 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 99 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -116,22 +116,22 @@ discard block |
||
| 116 | 116 | * Type d'objet édité |
| 117 | 117 | */ |
| 118 | 118 | function signale_edition($id, $auteur, $type = 'article') { |
| 119 | - include_spip('base/objets'); |
|
| 120 | - include_spip('inc/filtres'); |
|
| 121 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 119 | + include_spip('base/objets'); |
|
| 120 | + include_spip('inc/filtres'); |
|
| 121 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $edition = lire_tableau_edition(); |
|
| 125 | + $edition = lire_tableau_edition(); |
|
| 126 | 126 | |
| 127 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 127 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 129 | 129 | |
| 130 | - if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | - $edition[$type][$id] = []; |
|
| 132 | - } |
|
| 133 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | - ecrire_tableau_edition($edition); |
|
| 130 | + if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | + $edition[$type][$id] = []; |
|
| 132 | + } |
|
| 133 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | + ecrire_tableau_edition($edition); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function qui_edite($id, $type = 'article') { |
| 150 | 150 | |
| 151 | - $edition = lire_tableau_edition(); |
|
| 151 | + $edition = lire_tableau_edition(); |
|
| 152 | 152 | |
| 153 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 153 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -164,23 +164,23 @@ discard block |
||
| 164 | 164 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 165 | 165 | */ |
| 166 | 166 | function mention_qui_edite($id, $type = 'article'): array { |
| 167 | - $modif = qui_edite($id, $type); |
|
| 168 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 167 | + $modif = qui_edite($id, $type); |
|
| 168 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 169 | 169 | |
| 170 | - if ($modif) { |
|
| 171 | - $quand = 0; |
|
| 172 | - foreach ($modif as $duo) { |
|
| 173 | - $auteurs[] = typo(key($duo)); |
|
| 174 | - $quand = max($quand, current($duo)); |
|
| 175 | - } |
|
| 170 | + if ($modif) { |
|
| 171 | + $quand = 0; |
|
| 172 | + foreach ($modif as $duo) { |
|
| 173 | + $auteurs[] = typo(key($duo)); |
|
| 174 | + $quand = max($quand, current($duo)); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | - return [ |
|
| 179 | - 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | - ]; |
|
| 182 | - } |
|
| 183 | - return []; |
|
| 177 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | + return [ |
|
| 179 | + 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | + ]; |
|
| 182 | + } |
|
| 183 | + return []; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 195 | 195 | */ |
| 196 | 196 | function liste_drapeau_edition($id_auteur) { |
| 197 | - $edition = lire_tableau_edition(); |
|
| 198 | - $objets_ouverts = []; |
|
| 197 | + $edition = lire_tableau_edition(); |
|
| 198 | + $objets_ouverts = []; |
|
| 199 | 199 | |
| 200 | - foreach ($edition as $objet => $data) { |
|
| 201 | - foreach ($data as $id => $auteurs) { |
|
| 202 | - if ( |
|
| 203 | - isset($auteurs[$id_auteur]) |
|
| 204 | - && is_array($auteurs[$id_auteur]) |
|
| 205 | - && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | - ) { |
|
| 207 | - $objets_ouverts[] = [ |
|
| 208 | - 'objet' => $objet, |
|
| 209 | - 'id_objet' => $id, |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 200 | + foreach ($edition as $objet => $data) { |
|
| 201 | + foreach ($data as $id => $auteurs) { |
|
| 202 | + if ( |
|
| 203 | + isset($auteurs[$id_auteur]) |
|
| 204 | + && is_array($auteurs[$id_auteur]) |
|
| 205 | + && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | + ) { |
|
| 207 | + $objets_ouverts[] = [ |
|
| 208 | + 'objet' => $objet, |
|
| 209 | + 'id_objet' => $id, |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return $objets_ouverts; |
|
| 215 | + return $objets_ouverts; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * @return void |
| 226 | 226 | */ |
| 227 | 227 | function debloquer_tous($id_auteur) { |
| 228 | - $edition = lire_tableau_edition(); |
|
| 229 | - foreach ($edition as $objet => $data) { |
|
| 230 | - foreach ($data as $id => $auteurs) { |
|
| 231 | - if (isset($auteurs[$id_auteur])) { |
|
| 232 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | - ecrire_tableau_edition($edition); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 228 | + $edition = lire_tableau_edition(); |
|
| 229 | + foreach ($edition as $objet => $data) { |
|
| 230 | + foreach ($data as $id => $auteurs) { |
|
| 231 | + if (isset($auteurs[$id_auteur])) { |
|
| 232 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | + ecrire_tableau_edition($edition); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,19 +251,19 @@ discard block |
||
| 251 | 251 | * @return void |
| 252 | 252 | */ |
| 253 | 253 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 254 | - $edition = lire_tableau_edition(); |
|
| 254 | + $edition = lire_tableau_edition(); |
|
| 255 | 255 | |
| 256 | - foreach ($edition as $objet => $data) { |
|
| 257 | - if ($objet == $type) { |
|
| 258 | - foreach ($data as $id => $auteurs) { |
|
| 259 | - if ( |
|
| 260 | - $id == $id_objet |
|
| 261 | - && isset($auteurs[$id_auteur]) |
|
| 262 | - ) { |
|
| 263 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | - ecrire_tableau_edition($edition); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 256 | + foreach ($edition as $objet => $data) { |
|
| 257 | + if ($objet == $type) { |
|
| 258 | + foreach ($data as $id => $auteurs) { |
|
| 259 | + if ( |
|
| 260 | + $id == $id_objet |
|
| 261 | + && isset($auteurs[$id_auteur]) |
|
| 262 | + ) { |
|
| 263 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | + ecrire_tableau_edition($edition); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -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 | /** |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | 31 | function set_spip_doc(?string $fichier): string { |
| 32 | - if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 33 | - return substr($fichier, strlen((string) _DIR_IMG)); |
|
| 34 | - } else { |
|
| 35 | - // ex: fichier distant |
|
| 36 | - return $fichier ?? ''; |
|
| 37 | - } |
|
| 32 | + if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 33 | + return substr($fichier, strlen((string) _DIR_IMG)); |
|
| 34 | + } else { |
|
| 35 | + // ex: fichier distant |
|
| 36 | + return $fichier ?? ''; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,26 +46,26 @@ discard block |
||
| 46 | 46 | * @return bool|string |
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc(?string $fichier) { |
| 49 | - if ($fichier === null) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // fichier distant |
|
| 54 | - if (tester_url_absolue($fichier)) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // gestion d'erreurs, fichier='' |
|
| 59 | - if (!strlen($fichier)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 64 | - $fichier = _DIR_IMG . $fichier; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // fichier normal |
|
| 68 | - return $fichier; |
|
| 49 | + if ($fichier === null) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // fichier distant |
|
| 54 | + if (tester_url_absolue($fichier)) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // gestion d'erreurs, fichier='' |
|
| 59 | + if (!strlen($fichier)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 64 | + $fichier = _DIR_IMG . $fichier; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // fichier normal |
|
| 68 | + return $fichier; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function creer_repertoire_documents($ext) { |
| 82 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 83 | - |
|
| 84 | - if (!$ext || !$rep) { |
|
| 85 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 86 | - exit; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 90 | - // par exemple acces_restreint |
|
| 91 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 92 | - if ( |
|
| 93 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 94 | - && $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 95 | - && $ext !== 'logo' |
|
| 96 | - ) { |
|
| 97 | - include_spip('inc/acces'); |
|
| 98 | - verifier_htaccess($rep); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $rep; |
|
| 82 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 83 | + |
|
| 84 | + if (!$ext || !$rep) { |
|
| 85 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 86 | + exit; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 90 | + // par exemple acces_restreint |
|
| 91 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 92 | + if ( |
|
| 93 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 94 | + && $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 95 | + && $ext !== 'logo' |
|
| 96 | + ) { |
|
| 97 | + include_spip('inc/acces'); |
|
| 98 | + verifier_htaccess($rep); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $rep; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | * @param string $nom |
| 108 | 108 | */ |
| 109 | 109 | function effacer_repertoire_temporaire($nom) { |
| 110 | - if ($d = opendir($nom)) { |
|
| 111 | - while (($f = readdir($d)) !== false) { |
|
| 112 | - if (is_file("$nom/$f")) { |
|
| 113 | - spip_unlink("$nom/$f"); |
|
| 114 | - } else { |
|
| 115 | - if ($f != '.' && $f != '..' && is_dir("$nom/$f")) { |
|
| 116 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - closedir($d); |
|
| 122 | - @rmdir($nom); |
|
| 110 | + if ($d = opendir($nom)) { |
|
| 111 | + while (($f = readdir($d)) !== false) { |
|
| 112 | + if (is_file("$nom/$f")) { |
|
| 113 | + spip_unlink("$nom/$f"); |
|
| 114 | + } else { |
|
| 115 | + if ($f != '.' && $f != '..' && is_dir("$nom/$f")) { |
|
| 116 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + closedir($d); |
|
| 122 | + @rmdir($nom); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // |
@@ -136,44 +136,44 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 138 | 138 | |
| 139 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 140 | - $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 141 | - |
|
| 142 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 143 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 144 | - $dest = translitteration($dest); |
|
| 145 | - $dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest); |
|
| 146 | - |
|
| 147 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 148 | - // pour les images transformees par rotation (action/documenter) |
|
| 149 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 150 | - |
|
| 151 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 152 | - if ( |
|
| 153 | - !function_exists('verifier_upload_autorise') |
|
| 154 | - || !($r = verifier_upload_autorise($dest)) |
|
| 155 | - || !empty($r['autozip']) |
|
| 156 | - ) { |
|
| 157 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 158 | - break; |
|
| 159 | - } else { |
|
| 160 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | - $ext = $m[1] . '.' . $ext; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | - return $source; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | - $n = 0; |
|
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | - ; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return deplacer_fichier_upload($source, $newFile); |
|
| 139 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 140 | + $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 141 | + |
|
| 142 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 143 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 144 | + $dest = translitteration($dest); |
|
| 145 | + $dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest); |
|
| 146 | + |
|
| 147 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 148 | + // pour les images transformees par rotation (action/documenter) |
|
| 149 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 150 | + |
|
| 151 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 152 | + if ( |
|
| 153 | + !function_exists('verifier_upload_autorise') |
|
| 154 | + || !($r = verifier_upload_autorise($dest)) |
|
| 155 | + || !empty($r['autozip']) |
|
| 156 | + ) { |
|
| 157 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 158 | + break; |
|
| 159 | + } else { |
|
| 160 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | + $ext = $m[1] . '.' . $ext; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | + return $source; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | + $n = 0; |
|
| 172 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | + ; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return deplacer_fichier_upload($source, $newFile); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,28 +188,28 @@ discard block |
||
| 188 | 188 | * @return bool|string |
| 189 | 189 | */ |
| 190 | 190 | function determine_upload($type = '') { |
| 191 | - if (!function_exists('autoriser')) { |
|
| 192 | - include_spip('inc/autoriser'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ( |
|
| 196 | - !autoriser('chargerftp') |
|
| 197 | - || $type == 'logos' |
|
| 198 | - ) { # on ne le permet pas pour les logos |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $repertoire = _DIR_TRANSFERT; |
|
| 203 | - if (!@is_dir($repertoire)) { |
|
| 204 | - $repertoire = str_replace(_DIR_TMP, '', (string) $repertoire); |
|
| 205 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | - return $repertoire; |
|
| 210 | - } else { |
|
| 211 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | - } |
|
| 191 | + if (!function_exists('autoriser')) { |
|
| 192 | + include_spip('inc/autoriser'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ( |
|
| 196 | + !autoriser('chargerftp') |
|
| 197 | + || $type == 'logos' |
|
| 198 | + ) { # on ne le permet pas pour les logos |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $repertoire = _DIR_TRANSFERT; |
|
| 203 | + if (!@is_dir($repertoire)) { |
|
| 204 | + $repertoire = str_replace(_DIR_TMP, '', (string) $repertoire); |
|
| 205 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | + return $repertoire; |
|
| 210 | + } else { |
|
| 211 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -228,31 +228,31 @@ discard block |
||
| 228 | 228 | * @return bool|mixed|string |
| 229 | 229 | */ |
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | - // Securite |
|
| 232 | - if (str_starts_with($dest, (string) _DIR_RACINE)) { |
|
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | - } else { |
|
| 235 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $ok = $move ? @rename($source, $dest) : @copy($source, $dest); |
|
| 239 | - if (!$ok) { |
|
| 240 | - $ok = @move_uploaded_file($source, $dest); |
|
| 241 | - } |
|
| 242 | - if ($ok) { |
|
| 243 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 244 | - } else { |
|
| 245 | - $f = @fopen($dest, 'w'); |
|
| 246 | - if ($f) { |
|
| 247 | - fclose($f); |
|
| 248 | - } else { |
|
| 249 | - include_spip('inc/flock'); |
|
| 250 | - raler_fichier($dest); |
|
| 251 | - } |
|
| 252 | - spip_unlink($dest); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $ok ? $dest : false; |
|
| 231 | + // Securite |
|
| 232 | + if (str_starts_with($dest, (string) _DIR_RACINE)) { |
|
| 233 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | + } else { |
|
| 235 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $ok = $move ? @rename($source, $dest) : @copy($source, $dest); |
|
| 239 | + if (!$ok) { |
|
| 240 | + $ok = @move_uploaded_file($source, $dest); |
|
| 241 | + } |
|
| 242 | + if ($ok) { |
|
| 243 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 244 | + } else { |
|
| 245 | + $f = @fopen($dest, 'w'); |
|
| 246 | + if ($f) { |
|
| 247 | + fclose($f); |
|
| 248 | + } else { |
|
| 249 | + include_spip('inc/flock'); |
|
| 250 | + raler_fichier($dest); |
|
| 251 | + } |
|
| 252 | + spip_unlink($dest); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $ok ? $dest : false; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -276,60 +276,60 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | function check_upload_error($error, $msg = '', $return = false) { |
| 278 | 278 | |
| 279 | - if (!$error) { |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 284 | - |
|
| 285 | - switch ($error) { |
|
| 286 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 287 | - return true; |
|
| 288 | - |
|
| 289 | - # on peut affiner les differents messages d'erreur |
|
| 290 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 291 | - $msg = _T( |
|
| 292 | - 'upload_limit', |
|
| 293 | - ['max' => ini_get('upload_max_filesize')] |
|
| 294 | - ); |
|
| 295 | - break; |
|
| 296 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 297 | - $msg = _T( |
|
| 298 | - 'upload_limit', |
|
| 299 | - ['max' => ini_get('upload_max_filesize')] |
|
| 300 | - ); |
|
| 301 | - break; |
|
| 302 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 303 | - $msg = _T( |
|
| 304 | - 'upload_limit', |
|
| 305 | - ['max' => ini_get('upload_max_filesize')] |
|
| 306 | - ); |
|
| 307 | - break; |
|
| 308 | - |
|
| 309 | - default: /* autre */ |
|
| 310 | - if (!$msg) { |
|
| 311 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | - } |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - spip_log("erreur upload $error"); |
|
| 318 | - if ($return) { |
|
| 319 | - return $msg; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if (_request('iframe') == 'iframe') { |
|
| 323 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 324 | - exit; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - include_spip('inc/minipres'); |
|
| 328 | - echo minipres( |
|
| 329 | - $msg, |
|
| 330 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 331 | - ); |
|
| 332 | - exit; |
|
| 279 | + if (!$error) { |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 284 | + |
|
| 285 | + switch ($error) { |
|
| 286 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 287 | + return true; |
|
| 288 | + |
|
| 289 | + # on peut affiner les differents messages d'erreur |
|
| 290 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 291 | + $msg = _T( |
|
| 292 | + 'upload_limit', |
|
| 293 | + ['max' => ini_get('upload_max_filesize')] |
|
| 294 | + ); |
|
| 295 | + break; |
|
| 296 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 297 | + $msg = _T( |
|
| 298 | + 'upload_limit', |
|
| 299 | + ['max' => ini_get('upload_max_filesize')] |
|
| 300 | + ); |
|
| 301 | + break; |
|
| 302 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 303 | + $msg = _T( |
|
| 304 | + 'upload_limit', |
|
| 305 | + ['max' => ini_get('upload_max_filesize')] |
|
| 306 | + ); |
|
| 307 | + break; |
|
| 308 | + |
|
| 309 | + default: /* autre */ |
|
| 310 | + if (!$msg) { |
|
| 311 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | + } |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + spip_log("erreur upload $error"); |
|
| 318 | + if ($return) { |
|
| 319 | + return $msg; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if (_request('iframe') == 'iframe') { |
|
| 323 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 324 | + exit; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + include_spip('inc/minipres'); |
|
| 328 | + echo minipres( |
|
| 329 | + $msg, |
|
| 330 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 331 | + ); |
|
| 332 | + exit; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -346,14 +346,14 @@ discard block |
||
| 346 | 346 | * @return string |
| 347 | 347 | */ |
| 348 | 348 | function corriger_extension($ext) { |
| 349 | - $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 350 | - |
|
| 351 | - return match ($ext) { |
|
| 352 | - 'htm' => 'html', |
|
| 353 | - 'jpeg' => 'jpg', |
|
| 354 | - 'tiff' => 'tif', |
|
| 355 | - 'aif' => 'aiff', |
|
| 356 | - 'mpeg' => 'mpg', |
|
| 357 | - default => $ext, |
|
| 358 | - }; |
|
| 349 | + $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 350 | + |
|
| 351 | + return match ($ext) { |
|
| 352 | + 'htm' => 'html', |
|
| 353 | + 'jpeg' => 'jpg', |
|
| 354 | + 'tiff' => 'tif', |
|
| 355 | + 'aif' => 'aiff', |
|
| 356 | + 'mpeg' => 'mpg', |
|
| 357 | + default => $ext, |
|
| 358 | + }; |
|
| 359 | 359 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
| 64 | - $fichier = _DIR_IMG . $fichier; |
|
| 64 | + $fichier = _DIR_IMG.$fichier; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // fichier normal |
@@ -154,22 +154,22 @@ discard block |
||
| 154 | 154 | || !($r = verifier_upload_autorise($dest)) |
| 155 | 155 | || !empty($r['autozip']) |
| 156 | 156 | ) { |
| 157 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 157 | + $dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1]; |
|
| 158 | 158 | break; |
| 159 | 159 | } else { |
| 160 | 160 | $dest = substr($dest, 0, -strlen($m[0])); |
| 161 | - $ext = $m[1] . '.' . $ext; |
|
| 161 | + $ext = $m[1].'.'.$ext; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Si le document "source" est deja au bon endroit, ne rien faire |
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 166 | + if ($source == ($dir.$dest.'.'.$ext)) { |
|
| 167 | 167 | return $source; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // sinon tourner jusqu'a trouver un numero correct |
| 171 | 171 | $n = 0; |
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 172 | + while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) { |
|
| 173 | 173 | ; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | 231 | // Securite |
| 232 | 232 | if (str_starts_with($dest, (string) _DIR_RACINE)) { |
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 233 | + $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | 234 | } else { |
| 235 | 235 | $dest = preg_replace(',\.\.+,', '.', $dest); |
| 236 | 236 | } |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | default: /* autre */ |
| 310 | 310 | if (!$msg) { |
| 311 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 311 | + $msg = _T('pass_erreur').' '.$error |
|
| 312 | + . '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | 313 | } |
| 314 | 314 | break; |
| 315 | 315 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | include_spip('inc/minipres'); |
| 328 | 328 | echo minipres( |
| 329 | 329 | $msg, |
| 330 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 330 | + "<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode((string) $GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>' |
|
| 331 | 331 | ); |
| 332 | 332 | exit; |
| 333 | 333 | } |
@@ -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 | // Les parametres generaux du site sont dans une table SQL; |
@@ -26,51 +26,51 @@ discard block |
||
| 26 | 26 | define('_META_CACHE_TIME', 1 << 24); |
| 27 | 27 | |
| 28 | 28 | function inc_meta_dist($table = 'meta') { |
| 29 | - $new = null; |
|
| 30 | - // Lire les meta, en cache si present, valide et lisible |
|
| 31 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 32 | - $cache = cache_meta($table); |
|
| 29 | + $new = null; |
|
| 30 | + // Lire les meta, en cache si present, valide et lisible |
|
| 31 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 32 | + $cache = cache_meta($table); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - (!($exec = _request('exec')) || !autoriser_sans_cookie($exec)) |
|
| 36 | - && ($new = jeune_fichier($cache, _META_CACHE_TIME)) |
|
| 37 | - && lire_fichier_securise($cache, $meta) |
|
| 38 | - && ($meta = @unserialize($meta)) |
|
| 39 | - ) { |
|
| 40 | - $GLOBALS[$table] = $meta; |
|
| 41 | - } |
|
| 34 | + if ( |
|
| 35 | + (!($exec = _request('exec')) || !autoriser_sans_cookie($exec)) |
|
| 36 | + && ($new = jeune_fichier($cache, _META_CACHE_TIME)) |
|
| 37 | + && lire_fichier_securise($cache, $meta) |
|
| 38 | + && ($meta = @unserialize($meta)) |
|
| 39 | + ) { |
|
| 40 | + $GLOBALS[$table] = $meta; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if ( |
|
| 44 | - isset($GLOBALS[$table]['touch']) |
|
| 45 | - && $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME |
|
| 46 | - ) { |
|
| 47 | - $GLOBALS[$table] = []; |
|
| 48 | - } |
|
| 49 | - // sinon lire en base |
|
| 50 | - if (!$GLOBALS[$table]) { |
|
| 51 | - $new = !lire_metas($table); |
|
| 52 | - } |
|
| 43 | + if ( |
|
| 44 | + isset($GLOBALS[$table]['touch']) |
|
| 45 | + && $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME |
|
| 46 | + ) { |
|
| 47 | + $GLOBALS[$table] = []; |
|
| 48 | + } |
|
| 49 | + // sinon lire en base |
|
| 50 | + if (!$GLOBALS[$table]) { |
|
| 51 | + $new = !lire_metas($table); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 55 | - if ( |
|
| 56 | - (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 57 | - && $GLOBALS[$table] |
|
| 58 | - && time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0) |
|
| 59 | - ) { |
|
| 60 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 61 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 62 | - if (supprimer_fichier($cache)) { |
|
| 63 | - include_spip('inc/acces'); |
|
| 64 | - renouvelle_alea(); |
|
| 65 | - $new = false; |
|
| 66 | - } else { |
|
| 67 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - // et refaire le cache si on a du lire en base |
|
| 71 | - if (!$new) { |
|
| 72 | - touch_meta(false, $table); |
|
| 73 | - } |
|
| 54 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 55 | + if ( |
|
| 56 | + (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 57 | + && $GLOBALS[$table] |
|
| 58 | + && time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0) |
|
| 59 | + ) { |
|
| 60 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 61 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 62 | + if (supprimer_fichier($cache)) { |
|
| 63 | + include_spip('inc/acces'); |
|
| 64 | + renouvelle_alea(); |
|
| 65 | + $new = false; |
|
| 66 | + } else { |
|
| 67 | + spip_log("impossible d'ecrire dans " . $cache); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + // et refaire le cache si on a du lire en base |
|
| 71 | + if (!$new) { |
|
| 72 | + touch_meta(false, $table); |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -78,39 +78,39 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | function lire_metas($table = 'meta') { |
| 80 | 80 | |
| 81 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 82 | - include_spip('base/abstract_sql'); |
|
| 83 | - $GLOBALS[$table] = []; |
|
| 84 | - while ($row = sql_fetch($result)) { |
|
| 85 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 86 | - } |
|
| 87 | - sql_free($result); |
|
| 81 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 82 | + include_spip('base/abstract_sql'); |
|
| 83 | + $GLOBALS[$table] = []; |
|
| 84 | + while ($row = sql_fetch($result)) { |
|
| 85 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 86 | + } |
|
| 87 | + sql_free($result); |
|
| 88 | 88 | |
| 89 | - if ( |
|
| 90 | - !isset($GLOBALS[$table]['charset']) |
|
| 91 | - || !$GLOBALS[$table]['charset'] |
|
| 92 | - || $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 93 | - ) { |
|
| 94 | - ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 95 | - } |
|
| 89 | + if ( |
|
| 90 | + !isset($GLOBALS[$table]['charset']) |
|
| 91 | + || !$GLOBALS[$table]['charset'] |
|
| 92 | + || $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 93 | + ) { |
|
| 94 | + ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // noter cette table de configuration dans les meta de SPIP |
|
| 98 | - if ($table !== 'meta') { |
|
| 99 | - $liste = []; |
|
| 100 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 101 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 102 | - } |
|
| 103 | - if (!$liste) { |
|
| 104 | - $liste = []; |
|
| 105 | - } |
|
| 106 | - if (!in_array($table, $liste)) { |
|
| 107 | - $liste[] = $table; |
|
| 108 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 97 | + // noter cette table de configuration dans les meta de SPIP |
|
| 98 | + if ($table !== 'meta') { |
|
| 99 | + $liste = []; |
|
| 100 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 101 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 102 | + } |
|
| 103 | + if (!$liste) { |
|
| 104 | + $liste = []; |
|
| 105 | + } |
|
| 106 | + if (!in_array($table, $liste)) { |
|
| 107 | + $liste[] = $table; |
|
| 108 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $GLOBALS[$table] ?? null; |
|
| 113 | + return $GLOBALS[$table] ?? null; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -124,22 +124,22 @@ discard block |
||
| 124 | 124 | * Table SQL d'enregistrement des meta. |
| 125 | 125 | **/ |
| 126 | 126 | function touch_meta($antidate = false, $table = 'meta') { |
| 127 | - $file = cache_meta($table); |
|
| 128 | - if (!$antidate || !@touch($file, $antidate)) { |
|
| 129 | - $r = $GLOBALS[$table] ?? []; |
|
| 130 | - if ($table == 'meta') { |
|
| 131 | - unset($r['alea_ephemere']); |
|
| 132 | - unset($r['alea_ephemere_ancien']); |
|
| 133 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 134 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 135 | - // meme si son squelette est en cache |
|
| 136 | - //unset($r['secret_du_site']); |
|
| 137 | - if ($antidate) { |
|
| 138 | - $r['touch'] = $antidate; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 142 | - } |
|
| 127 | + $file = cache_meta($table); |
|
| 128 | + if (!$antidate || !@touch($file, $antidate)) { |
|
| 129 | + $r = $GLOBALS[$table] ?? []; |
|
| 130 | + if ($table == 'meta') { |
|
| 131 | + unset($r['alea_ephemere']); |
|
| 132 | + unset($r['alea_ephemere_ancien']); |
|
| 133 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 134 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 135 | + // meme si son squelette est en cache |
|
| 136 | + //unset($r['secret_du_site']); |
|
| 137 | + if ($antidate) { |
|
| 138 | + $r['touch'] = $antidate; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 142 | + } |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -155,21 +155,21 @@ discard block |
||
| 155 | 155 | * Table SQL d'enregistrement de la meta. |
| 156 | 156 | **/ |
| 157 | 157 | function effacer_meta($nom, $table = 'meta') { |
| 158 | - // section critique sur le cache: |
|
| 159 | - // l'invalider avant et apres la MAJ de la BD |
|
| 160 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 161 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 162 | - static $touch = []; |
|
| 163 | - $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 164 | - if (!isset($touch[$table])) { |
|
| 165 | - touch_meta($antidate, $table); |
|
| 166 | - } |
|
| 167 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 168 | - unset($GLOBALS[$table][$nom]); |
|
| 169 | - if (!isset($touch[$table])) { |
|
| 170 | - touch_meta($antidate, $table); |
|
| 171 | - $touch[$table] = false; |
|
| 172 | - } |
|
| 158 | + // section critique sur le cache: |
|
| 159 | + // l'invalider avant et apres la MAJ de la BD |
|
| 160 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 161 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 162 | + static $touch = []; |
|
| 163 | + $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 164 | + if (!isset($touch[$table])) { |
|
| 165 | + touch_meta($antidate, $table); |
|
| 166 | + } |
|
| 167 | + sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 168 | + unset($GLOBALS[$table][$nom]); |
|
| 169 | + if (!isset($touch[$table])) { |
|
| 170 | + touch_meta($antidate, $table); |
|
| 171 | + $touch[$table] = false; |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -191,54 +191,54 @@ discard block |
||
| 191 | 191 | **/ |
| 192 | 192 | function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') { |
| 193 | 193 | |
| 194 | - static $touch = []; |
|
| 195 | - if (!$nom) { |
|
| 196 | - return; |
|
| 197 | - } |
|
| 198 | - include_spip('base/abstract_sql'); |
|
| 199 | - $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | - // table pas encore installee, travailler en php seulement |
|
| 201 | - if (!$res) { |
|
| 202 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 194 | + static $touch = []; |
|
| 195 | + if (!$nom) { |
|
| 196 | + return; |
|
| 197 | + } |
|
| 198 | + include_spip('base/abstract_sql'); |
|
| 199 | + $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | + // table pas encore installee, travailler en php seulement |
|
| 201 | + if (!$res) { |
|
| 202 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 203 | 203 | |
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - $row = sql_fetch($res); |
|
| 207 | - sql_free($res); |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + $row = sql_fetch($res); |
|
| 207 | + sql_free($res); |
|
| 208 | 208 | |
| 209 | - // ne pas invalider le cache si affectation a l'identique |
|
| 210 | - // (tant pis si impt aurait du changer) |
|
| 211 | - if ( |
|
| 212 | - $row |
|
| 213 | - && $valeur == $row['valeur'] |
|
| 214 | - && isset($GLOBALS[$table][$nom]) |
|
| 215 | - && $GLOBALS[$table][$nom] == $valeur |
|
| 216 | - ) { |
|
| 217 | - return; |
|
| 218 | - } |
|
| 209 | + // ne pas invalider le cache si affectation a l'identique |
|
| 210 | + // (tant pis si impt aurait du changer) |
|
| 211 | + if ( |
|
| 212 | + $row |
|
| 213 | + && $valeur == $row['valeur'] |
|
| 214 | + && isset($GLOBALS[$table][$nom]) |
|
| 215 | + && $GLOBALS[$table][$nom] == $valeur |
|
| 216 | + ) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | - // cf effacer pour comprendre le double touch |
|
| 222 | - $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | - if (!isset($touch[$table])) { |
|
| 224 | - touch_meta($antidate, $table); |
|
| 225 | - } |
|
| 226 | - $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | - // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | - // de lecture des descriptions des tables |
|
| 230 | - if ($importable && isset($row['impt'])) { |
|
| 231 | - $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | - } |
|
| 233 | - if ($row) { |
|
| 234 | - sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | - } else { |
|
| 236 | - sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')'); |
|
| 237 | - } |
|
| 238 | - if (!isset($touch[$table])) { |
|
| 239 | - touch_meta($antidate, $table); |
|
| 240 | - $touch[$table] = false; |
|
| 241 | - } |
|
| 220 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | + // cf effacer pour comprendre le double touch |
|
| 222 | + $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | + if (!isset($touch[$table])) { |
|
| 224 | + touch_meta($antidate, $table); |
|
| 225 | + } |
|
| 226 | + $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | + // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | + // de lecture des descriptions des tables |
|
| 230 | + if ($importable && isset($row['impt'])) { |
|
| 231 | + $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | + } |
|
| 233 | + if ($row) { |
|
| 234 | + sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | + } else { |
|
| 236 | + sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')'); |
|
| 237 | + } |
|
| 238 | + if (!isset($touch[$table])) { |
|
| 239 | + touch_meta($antidate, $table); |
|
| 240 | + $touch[$table] = false; |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * Nom du fichier cache |
| 251 | 251 | **/ |
| 252 | 252 | function cache_meta($table = 'meta') { |
| 253 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 253 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | * @param string $table |
| 260 | 260 | */ |
| 261 | 261 | function installer_table_meta($table) { |
| 262 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | - if (!$trouver_table("spip_$table")) { |
|
| 264 | - include_spip('base/auxiliaires'); |
|
| 265 | - include_spip('base/create'); |
|
| 266 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | - $trouver_table(''); |
|
| 268 | - } |
|
| 269 | - lire_metas($table); |
|
| 262 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | + if (!$trouver_table("spip_$table")) { |
|
| 264 | + include_spip('base/auxiliaires'); |
|
| 265 | + include_spip('base/create'); |
|
| 266 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | + $trouver_table(''); |
|
| 268 | + } |
|
| 269 | + lire_metas($table); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -278,44 +278,44 @@ discard block |
||
| 278 | 278 | * @param bool $force |
| 279 | 279 | */ |
| 280 | 280 | function supprimer_table_meta($table, $force = false) { |
| 281 | - if ($table !== 'meta') { |
|
| 282 | - // Vérifier le contenu restant de la table |
|
| 283 | - $nb_variables = sql_countsel("spip_$table"); |
|
| 281 | + if ($table !== 'meta') { |
|
| 282 | + // Vérifier le contenu restant de la table |
|
| 283 | + $nb_variables = sql_countsel("spip_$table"); |
|
| 284 | 284 | |
| 285 | - // Supprimer si : |
|
| 286 | - // - la table est vide |
|
| 287 | - // - ou limitée à la variable charset |
|
| 288 | - // - ou qu'on force la suppression |
|
| 289 | - if ( |
|
| 290 | - $force |
|
| 291 | - || !$nb_variables |
|
| 292 | - || $nb_variables == 1 && isset($GLOBALS[$table]['charset']) |
|
| 293 | - ) { |
|
| 294 | - // Supprimer la table des globaleset de la base |
|
| 295 | - unset($GLOBALS[$table]); |
|
| 296 | - sql_drop_table("spip_$table"); |
|
| 297 | - // Supprimer le fichier cache |
|
| 298 | - include_spip('inc/flock'); |
|
| 299 | - $cache = cache_meta($table); |
|
| 300 | - supprimer_fichier($cache); |
|
| 285 | + // Supprimer si : |
|
| 286 | + // - la table est vide |
|
| 287 | + // - ou limitée à la variable charset |
|
| 288 | + // - ou qu'on force la suppression |
|
| 289 | + if ( |
|
| 290 | + $force |
|
| 291 | + || !$nb_variables |
|
| 292 | + || $nb_variables == 1 && isset($GLOBALS[$table]['charset']) |
|
| 293 | + ) { |
|
| 294 | + // Supprimer la table des globaleset de la base |
|
| 295 | + unset($GLOBALS[$table]); |
|
| 296 | + sql_drop_table("spip_$table"); |
|
| 297 | + // Supprimer le fichier cache |
|
| 298 | + include_spip('inc/flock'); |
|
| 299 | + $cache = cache_meta($table); |
|
| 300 | + supprimer_fichier($cache); |
|
| 301 | 301 | |
| 302 | - // vider le cache des tables |
|
| 303 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | - $trouver_table(''); |
|
| 302 | + // vider le cache des tables |
|
| 303 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | + $trouver_table(''); |
|
| 305 | 305 | |
| 306 | - // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 307 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 308 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 309 | - $cle = array_search($table, $liste); |
|
| 310 | - if ($cle !== false) { |
|
| 311 | - unset($liste[$cle]); |
|
| 312 | - if ($liste) { |
|
| 313 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 314 | - } else { |
|
| 315 | - effacer_meta('tables_config'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 306 | + // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 307 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 308 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 309 | + $cle = array_search($table, $liste); |
|
| 310 | + if ($cle !== false) { |
|
| 311 | + unset($liste[$cle]); |
|
| 312 | + if ($liste) { |
|
| 313 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 314 | + } else { |
|
| 315 | + effacer_meta('tables_config'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | 321 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | renouvelle_alea(); |
| 65 | 65 | $new = false; |
| 66 | 66 | } else { |
| 67 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 67 | + spip_log("impossible d'ecrire dans ".$cache); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | // et refaire le cache si on a du lire en base |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if (!isset($touch[$table])) { |
| 165 | 165 | touch_meta($antidate, $table); |
| 166 | 166 | } |
| 167 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 167 | + sql_delete('spip_'.$table, "nom='$nom'", '', 'continue'); |
|
| 168 | 168 | unset($GLOBALS[$table][$nom]); |
| 169 | 169 | if (!isset($touch[$table])) { |
| 170 | 170 | touch_meta($antidate, $table); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | return; |
| 197 | 197 | } |
| 198 | 198 | include_spip('base/abstract_sql'); |
| 199 | - $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 199 | + $res = sql_select('*', 'spip_'.$table, 'nom='.sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | 200 | // table pas encore installee, travailler en php seulement |
| 201 | 201 | if (!$res) { |
| 202 | 202 | $GLOBALS[$table][$nom] = $valeur; |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | $r['impt'] = sql_quote($importable, '', 'text'); |
| 232 | 232 | } |
| 233 | 233 | if ($row) { |
| 234 | - sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 234 | + sql_update('spip_'.$table, $r, 'nom='.sql_quote($nom)); |
|
| 235 | 235 | } else { |
| 236 | - sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')'); |
|
| 236 | + sql_insert('spip_'.$table, '('.implode(',', array_keys($r)).')', '('.implode(',', array_values($r)).')'); |
|
| 237 | 237 | } |
| 238 | 238 | if (!isset($touch[$table])) { |
| 239 | 239 | touch_meta($antidate, $table); |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * Nom du fichier cache |
| 251 | 251 | **/ |
| 252 | 252 | function cache_meta($table = 'meta') { |
| 253 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 253 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE.$table.'.php'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -19,19 +19,19 @@ |
||
| 19 | 19 | * Retourne la liste des menus favoris par défaut ainsi que leur rang |
| 20 | 20 | */ |
| 21 | 21 | function inc_definir_menus_favoris_dist() { |
| 22 | - return [ |
|
| 22 | + return [ |
|
| 23 | 23 | |
| 24 | - // Menu Édition, |
|
| 25 | - 'auteurs' => 1, |
|
| 26 | - 'rubriques' => 2, |
|
| 27 | - 'articles' => 3, |
|
| 24 | + // Menu Édition, |
|
| 25 | + 'auteurs' => 1, |
|
| 26 | + 'rubriques' => 2, |
|
| 27 | + 'articles' => 3, |
|
| 28 | 28 | |
| 29 | - // Menu Maintenance |
|
| 30 | - 'admin_vider' => 1, |
|
| 29 | + // Menu Maintenance |
|
| 30 | + 'admin_vider' => 1, |
|
| 31 | 31 | |
| 32 | - // Menu Configurations |
|
| 33 | - 'configurer_identite' => 1, |
|
| 34 | - 'admin_plugin' => 2, |
|
| 32 | + // Menu Configurations |
|
| 33 | + 'configurer_identite' => 1, |
|
| 34 | + 'admin_plugin' => 2, |
|
| 35 | 35 | |
| 36 | - ]; |
|
| 36 | + ]; |
|
| 37 | 37 | } |
@@ -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 | /** |
@@ -44,29 +44,29 @@ discard block |
||
| 44 | 44 | * sinon code HTML de la page après le traitement effectué. |
| 45 | 45 | **/ |
| 46 | 46 | function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) { |
| 47 | - $reprise = true; |
|
| 48 | - if ( |
|
| 49 | - !isset($GLOBALS['meta'][$script]) |
|
| 50 | - || !isset($GLOBALS['meta']['admin']) |
|
| 51 | - ) { |
|
| 52 | - $reprise = false; |
|
| 53 | - $res = debut_admin($script, $titre, $comment); |
|
| 54 | - if ($res) { |
|
| 55 | - return $res; |
|
| 56 | - } |
|
| 57 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | - ecrire_meta($script, serialize($_POST)); |
|
| 59 | - } |
|
| 47 | + $reprise = true; |
|
| 48 | + if ( |
|
| 49 | + !isset($GLOBALS['meta'][$script]) |
|
| 50 | + || !isset($GLOBALS['meta']['admin']) |
|
| 51 | + ) { |
|
| 52 | + $reprise = false; |
|
| 53 | + $res = debut_admin($script, $titre, $comment); |
|
| 54 | + if ($res) { |
|
| 55 | + return $res; |
|
| 56 | + } |
|
| 57 | + spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | + ecrire_meta($script, serialize($_POST)); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $res = admin_verifie_session($script, $anonymous); |
|
| 62 | - if ($res) { |
|
| 63 | - return $res; |
|
| 64 | - } |
|
| 65 | - $base = charger_fonction($script, 'base'); |
|
| 66 | - $base($titre, $reprise); |
|
| 67 | - fin_admin($script); |
|
| 61 | + $res = admin_verifie_session($script, $anonymous); |
|
| 62 | + if ($res) { |
|
| 63 | + return $res; |
|
| 64 | + } |
|
| 65 | + $base = charger_fonction($script, 'base'); |
|
| 66 | + $base($titre, $reprise); |
|
| 67 | + fin_admin($script); |
|
| 68 | 68 | |
| 69 | - return ''; |
|
| 69 | + return ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -97,36 +97,36 @@ discard block |
||
| 97 | 97 | * Code HTML si message d'erreur, '' sinon; |
| 98 | 98 | */ |
| 99 | 99 | function admin_verifie_session($script, $anonymous = false) { |
| 100 | - include_spip('base/abstract_sql'); |
|
| 101 | - $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | - $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | - $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | - if ($valeur === null) { |
|
| 105 | - ecrire_meta('admin', $signal, 'non'); |
|
| 106 | - } else { |
|
| 107 | - if ( |
|
| 108 | - !$anonymous |
|
| 109 | - && $valeur != $signal |
|
| 110 | - && ( |
|
| 111 | - !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | - || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | - ) |
|
| 114 | - ) { |
|
| 115 | - include_spip('inc/minipres'); |
|
| 116 | - spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | - return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $journal = 'spip'; |
|
| 121 | - if (autoriser('configurer')) { |
|
| 122 | - // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | - $journal = 'webmestre'; |
|
| 124 | - } |
|
| 125 | - // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 100 | + include_spip('base/abstract_sql'); |
|
| 101 | + $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | + $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | + $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | + if ($valeur === null) { |
|
| 105 | + ecrire_meta('admin', $signal, 'non'); |
|
| 106 | + } else { |
|
| 107 | + if ( |
|
| 108 | + !$anonymous |
|
| 109 | + && $valeur != $signal |
|
| 110 | + && ( |
|
| 111 | + !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | + || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | + ) |
|
| 114 | + ) { |
|
| 115 | + include_spip('inc/minipres'); |
|
| 116 | + spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | + return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $journal = 'spip'; |
|
| 121 | + if (autoriser('configurer')) { |
|
| 122 | + // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | + $journal = 'webmestre'; |
|
| 124 | + } |
|
| 125 | + // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Chemin du répertoire. |
| 140 | 140 | **/ |
| 141 | 141 | function dir_admin() { |
| 142 | - if (autoriser('configurer')) { |
|
| 143 | - return _DIR_TMP; |
|
| 144 | - } else { |
|
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | - } |
|
| 142 | + if (autoriser('configurer')) { |
|
| 143 | + return _DIR_TMP; |
|
| 144 | + } else { |
|
| 145 | + return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref . |
|
| 164 | + substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -187,76 +187,76 @@ discard block |
||
| 187 | 187 | * sinon chaîne vide si déjà fait. |
| 188 | 188 | **/ |
| 189 | 189 | function debut_admin($script, $action = '', $corps = '') { |
| 190 | - if ( |
|
| 191 | - !$action |
|
| 192 | - || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | - ) { |
|
| 194 | - include_spip('inc/minipres'); |
|
| 190 | + if ( |
|
| 191 | + !$action |
|
| 192 | + || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | + ) { |
|
| 194 | + include_spip('inc/minipres'); |
|
| 195 | 195 | |
| 196 | - return minipres(); |
|
| 197 | - } else { |
|
| 198 | - $dir = dir_admin(); |
|
| 199 | - $signal = fichier_admin($script); |
|
| 200 | - if (@file_exists($dir . $signal)) { |
|
| 201 | - spip_log("Action admin: $action"); |
|
| 196 | + return minipres(); |
|
| 197 | + } else { |
|
| 198 | + $dir = dir_admin(); |
|
| 199 | + $signal = fichier_admin($script); |
|
| 200 | + if (@file_exists($dir . $signal)) { |
|
| 201 | + spip_log("Action admin: $action"); |
|
| 202 | 202 | |
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - include_spip('inc/minipres'); |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + include_spip('inc/minipres'); |
|
| 206 | 206 | |
| 207 | - // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | - // sauf dans les cas destroy |
|
| 209 | - if ( |
|
| 210 | - (autoriser('webmestre') || $script === 'repair') |
|
| 211 | - && $script != 'delete_all' |
|
| 212 | - ) { |
|
| 213 | - if (_request('validation_admin') == $signal) { |
|
| 214 | - spip_log("Action super-admin: $action"); |
|
| 207 | + // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | + // sauf dans les cas destroy |
|
| 209 | + if ( |
|
| 210 | + (autoriser('webmestre') || $script === 'repair') |
|
| 211 | + && $script != 'delete_all' |
|
| 212 | + ) { |
|
| 213 | + if (_request('validation_admin') == $signal) { |
|
| 214 | + spip_log("Action super-admin: $action"); |
|
| 215 | 215 | |
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | - $suivant = _T('bouton_valider'); |
|
| 220 | - $js = ''; |
|
| 221 | - } else { |
|
| 222 | - // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | - // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | - // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | - $corps .= http_script('', 'spip_barre.js'); |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | + $suivant = _T('bouton_valider'); |
|
| 220 | + $js = ''; |
|
| 221 | + } else { |
|
| 222 | + // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | + // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | + // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | + $corps .= http_script('', 'spip_barre.js'); |
|
| 226 | 226 | |
| 227 | - $corps .= '<fieldset><legend>' |
|
| 228 | - . _T('info_authentification_ftp') |
|
| 229 | - . aider('ftp_auth') |
|
| 230 | - . "</legend>\n<label for='fichier'>" |
|
| 231 | - . _T('info_creer_repertoire') |
|
| 232 | - . "</label>\n" |
|
| 233 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | - . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | - . $signal |
|
| 236 | - . "' />" |
|
| 237 | - . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | - . '</fieldset>'; |
|
| 227 | + $corps .= '<fieldset><legend>' |
|
| 228 | + . _T('info_authentification_ftp') |
|
| 229 | + . aider('ftp_auth') |
|
| 230 | + . "</legend>\n<label for='fichier'>" |
|
| 231 | + . _T('info_creer_repertoire') |
|
| 232 | + . "</label>\n" |
|
| 233 | + . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | + . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | + . $signal |
|
| 236 | + . "' />" |
|
| 237 | + . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | + . '</fieldset>'; |
|
| 239 | 239 | |
| 240 | - $suivant = _T('bouton_recharger_page'); |
|
| 240 | + $suivant = _T('bouton_recharger_page'); |
|
| 241 | 241 | |
| 242 | - // code volontairement tordu: |
|
| 243 | - // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | - // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | - // de JavaScript inactif. |
|
| 246 | - $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | - } |
|
| 242 | + // code volontairement tordu: |
|
| 243 | + // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | + // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | + // de JavaScript inactif. |
|
| 246 | + $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - // admin/xxx correspond |
|
| 250 | - // a exec/base_xxx de preference |
|
| 251 | - // et exec/xxx sinon (compat) |
|
| 252 | - if (tester_url_ecrire("base_$script")) { |
|
| 253 | - $script = "base_$script"; |
|
| 254 | - } |
|
| 255 | - $form = copy_request($script, $corps, $suivant); |
|
| 256 | - $info_action = _T('info_action', ['action' => "$action"]); |
|
| 249 | + // admin/xxx correspond |
|
| 250 | + // a exec/base_xxx de preference |
|
| 251 | + // et exec/xxx sinon (compat) |
|
| 252 | + if (tester_url_ecrire("base_$script")) { |
|
| 253 | + $script = "base_$script"; |
|
| 254 | + } |
|
| 255 | + $form = copy_request($script, $corps, $suivant); |
|
| 256 | + $info_action = _T('info_action', ['action' => "$action"]); |
|
| 257 | 257 | |
| 258 | - return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | - } |
|
| 258 | + return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * Nom de l'action (en base) qui a été exécutée |
| 268 | 268 | **/ |
| 269 | 269 | function fin_admin($action) { |
| 270 | - $signal = dir_admin() . fichier_admin($action); |
|
| 271 | - spip_unlink($signal); |
|
| 272 | - if ($action != 'delete_all') { |
|
| 273 | - effacer_meta($action); |
|
| 274 | - effacer_meta('admin'); |
|
| 275 | - spip_log("efface les meta admin et $action "); |
|
| 276 | - } |
|
| 270 | + $signal = dir_admin() . fichier_admin($action); |
|
| 271 | + spip_unlink($signal); |
|
| 272 | + if ($action != 'delete_all') { |
|
| 273 | + effacer_meta($action); |
|
| 274 | + effacer_meta('admin'); |
|
| 275 | + spip_log("efface les meta admin et $action "); |
|
| 276 | + } |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | * Code HTML du formulaire |
| 293 | 293 | **/ |
| 294 | 294 | function copy_request($script, $suite, $submit = '') { |
| 295 | - include_spip('inc/filtres'); |
|
| 296 | - foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | - if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | - entites_html($c) . |
|
| 300 | - "' />"; |
|
| 301 | - } |
|
| 302 | - } |
|
| 295 | + include_spip('inc/filtres'); |
|
| 296 | + foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | + if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | + $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | + entites_html($c) . |
|
| 300 | + "' />"; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - return generer_form_ecrire($script, $suite, '', $submit); |
|
| 304 | + return generer_form_ecrire($script, $suite, '', $submit); |
|
| 305 | 305 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | if ($res) { |
| 55 | 55 | return $res; |
| 56 | 56 | } |
| 57 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 57 | + spip_log("meta: $script ".print_r($_POST, true)); |
|
| 58 | 58 | ecrire_meta($script, serialize($_POST)); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref".($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | 129 | return ''; |
| 130 | 130 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (autoriser('configurer')) { |
| 143 | 143 | return _DIR_TMP; |
| 144 | 144 | } else { |
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 145 | + return _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/'; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref. |
|
| 164 | + substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | } else { |
| 198 | 198 | $dir = dir_admin(); |
| 199 | 199 | $signal = fichier_admin($script); |
| 200 | - if (@file_exists($dir . $signal)) { |
|
| 200 | + if (@file_exists($dir.$signal)) { |
|
| 201 | 201 | spip_log("Action admin: $action"); |
| 202 | 202 | |
| 203 | 203 | return ''; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | return ''; |
| 217 | 217 | } |
| 218 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 218 | + $corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />'; |
|
| 219 | 219 | $suivant = _T('bouton_valider'); |
| 220 | 220 | $js = ''; |
| 221 | 221 | } else { |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | . "</legend>\n<label for='fichier'>" |
| 231 | 231 | . _T('info_creer_repertoire') |
| 232 | 232 | . "</label>\n" |
| 233 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 233 | + . "<span id='signal' class='formo'>".$signal.'</span>' |
|
| 234 | 234 | . "<input type='hidden' id='fichier' name='fichier' value='" |
| 235 | 235 | . $signal |
| 236 | 236 | . "' />" |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * Nom de l'action (en base) qui a été exécutée |
| 268 | 268 | **/ |
| 269 | 269 | function fin_admin($action) { |
| 270 | - $signal = dir_admin() . fichier_admin($action); |
|
| 270 | + $signal = dir_admin().fichier_admin($action); |
|
| 271 | 271 | spip_unlink($signal); |
| 272 | 272 | if ($action != 'delete_all') { |
| 273 | 273 | effacer_meta($action); |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | include_spip('inc/filtres'); |
| 296 | 296 | foreach ([...$_POST, ...$_GET] as $n => $c) { |
| 297 | 297 | if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
| 298 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | - entites_html($c) . |
|
| 298 | + $suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='". |
|
| 299 | + entites_html($c). |
|
| 300 | 300 | "' />"; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -336,8 +336,7 @@ |
||
| 336 | 336 | if (!autoriser('modifier', $type, (int) $id)) { |
| 337 | 337 | $contexte['editable'] = ''; |
| 338 | 338 | } |
| 339 | - } |
|
| 340 | - else { |
|
| 339 | + } else { |
|
| 341 | 340 | if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
| 342 | 341 | $contexte['editable'] = ''; |
| 343 | 342 | } |
@@ -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/abstract_sql'); |
| 22 | 22 | |
@@ -58,56 +58,56 @@ discard block |
||
| 58 | 58 | * Retour des traitements. |
| 59 | 59 | **/ |
| 60 | 60 | function formulaires_editer_objet_traiter( |
| 61 | - $type, |
|
| 62 | - $id = 'new', |
|
| 63 | - $id_parent = 0, |
|
| 64 | - $lier_trad = 0, |
|
| 65 | - $retour = '', |
|
| 66 | - $config_fonc = 'articles_edit_config', |
|
| 67 | - $row = [], |
|
| 68 | - $hidden = '' |
|
| 61 | + $type, |
|
| 62 | + $id = 'new', |
|
| 63 | + $id_parent = 0, |
|
| 64 | + $lier_trad = 0, |
|
| 65 | + $retour = '', |
|
| 66 | + $config_fonc = 'articles_edit_config', |
|
| 67 | + $row = [], |
|
| 68 | + $hidden = '' |
|
| 69 | 69 | ) { |
| 70 | 70 | |
| 71 | - $res = []; |
|
| 72 | - // eviter la redirection forcee par l'action... |
|
| 73 | - set_request('redirect'); |
|
| 74 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | - [$id, $err] = $action_editer($id); |
|
| 76 | - } else { |
|
| 77 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | - [$id, $err] = $action_editer($id, $type); |
|
| 79 | - } |
|
| 80 | - $id_table_objet = id_table_objet($type); |
|
| 81 | - $res[$id_table_objet] = $id; |
|
| 82 | - if ($err || !$id) { |
|
| 83 | - $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | - } else { |
|
| 85 | - // Un lien de trad a prendre en compte |
|
| 86 | - if ($lier_trad) { |
|
| 87 | - // referencer la traduction |
|
| 88 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | - if ($err) { |
|
| 94 | - $res['message_erreur'] = $err; |
|
| 95 | - return $res; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | - if ($retour) { |
|
| 101 | - if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | - $res['editable'] = true; |
|
| 104 | - } else { |
|
| 105 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $res; |
|
| 71 | + $res = []; |
|
| 72 | + // eviter la redirection forcee par l'action... |
|
| 73 | + set_request('redirect'); |
|
| 74 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | + [$id, $err] = $action_editer($id); |
|
| 76 | + } else { |
|
| 77 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | + [$id, $err] = $action_editer($id, $type); |
|
| 79 | + } |
|
| 80 | + $id_table_objet = id_table_objet($type); |
|
| 81 | + $res[$id_table_objet] = $id; |
|
| 82 | + if ($err || !$id) { |
|
| 83 | + $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | + } else { |
|
| 85 | + // Un lien de trad a prendre en compte |
|
| 86 | + if ($lier_trad) { |
|
| 87 | + // referencer la traduction |
|
| 88 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | + if ($err) { |
|
| 94 | + $res['message_erreur'] = $err; |
|
| 95 | + return $res; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | + if ($retour) { |
|
| 101 | + if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | + $res['editable'] = true; |
|
| 104 | + } else { |
|
| 105 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $res; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -131,29 +131,29 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | **/ |
| 133 | 133 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) { |
| 134 | - $erreurs = []; |
|
| 135 | - if ((int) $id) { |
|
| 136 | - $conflits = controler_contenu($type, $id); |
|
| 137 | - if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | - foreach ($conflits as $champ => $conflit) { |
|
| 139 | - if (!isset($erreurs[$champ])) { |
|
| 140 | - $erreurs[$champ] = ''; |
|
| 141 | - } |
|
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($oblis as $obli) { |
|
| 147 | - $value = _request($obli); |
|
| 148 | - if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | - if (!isset($erreurs[$obli])) { |
|
| 150 | - $erreurs[$obli] = ''; |
|
| 151 | - } |
|
| 152 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + if ((int) $id) { |
|
| 136 | + $conflits = controler_contenu($type, $id); |
|
| 137 | + if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | + foreach ($conflits as $champ => $conflit) { |
|
| 139 | + if (!isset($erreurs[$champ])) { |
|
| 140 | + $erreurs[$champ] = ''; |
|
| 141 | + } |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($oblis as $obli) { |
|
| 147 | + $value = _request($obli); |
|
| 148 | + if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | + if (!isset($erreurs[$obli])) { |
|
| 150 | + $erreurs[$obli] = ''; |
|
| 151 | + } |
|
| 152 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $erreurs; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -198,150 +198,150 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = [], |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = [], |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | 210 | |
| 211 | - $table_objet = table_objet($type); |
|
| 212 | - $table_objet_sql = table_objet_sql($type); |
|
| 213 | - $id_table_objet = id_table_objet($type); |
|
| 214 | - if (!is_array($row)) { |
|
| 215 | - $row = []; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | - if ( |
|
| 220 | - $config_fonc |
|
| 221 | - && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | - && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | - && in_array($config_fonc, $args) |
|
| 225 | - ) { |
|
| 226 | - $config_fonc = ''; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $new = !is_numeric($id); |
|
| 230 | - $lang_default = ''; |
|
| 231 | - // Appel direct dans un squelette |
|
| 232 | - if (!$row) { |
|
| 233 | - if (!$new || $lier_trad) { |
|
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | - // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | - $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | - } else { |
|
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | - } |
|
| 241 | - if (!$new) { |
|
| 242 | - $md5 = controles_md5($row ?: []); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if (!$row) { |
|
| 246 | - $row = []; |
|
| 247 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | - if ($desc = $trouver_table($table_objet)) { |
|
| 249 | - foreach ($desc['field'] as $k => $v) { |
|
| 250 | - $row[$k] = ''; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | - // (et donc: pas de lien de traduction) |
|
| 258 | - $id = ($new || $lier_trad) |
|
| 259 | - ? 'oui' |
|
| 260 | - : $row[$id_table_objet]; |
|
| 261 | - $row[$id_table_objet] = $id; |
|
| 262 | - |
|
| 263 | - $contexte = $row; |
|
| 264 | - if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | - if (!isset($contexte['id_parent'])) { |
|
| 266 | - unset($contexte['id_rubrique']); |
|
| 267 | - } |
|
| 268 | - $contexte['id_parent'] = $id_parent; |
|
| 269 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | - // id_rubrique dans id_parent si possible |
|
| 271 | - if (isset($contexte['id_rubrique'])) { |
|
| 272 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | - unset($contexte['id_rubrique']); |
|
| 274 | - } else { |
|
| 275 | - $contexte['id_parent'] = ''; |
|
| 276 | - } |
|
| 277 | - if ( |
|
| 278 | - !$contexte['id_parent'] |
|
| 279 | - && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | - ) { |
|
| 281 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $config = []; |
|
| 286 | - if ($config_fonc) { |
|
| 287 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | - if (!$lang_default) { |
|
| 289 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - $config += [ |
|
| 293 | - 'lignes' => 0, |
|
| 294 | - 'langue' => '', |
|
| 295 | - ]; |
|
| 296 | - |
|
| 297 | - $att_text = " class='textarea' " |
|
| 298 | - . " rows='" |
|
| 299 | - . ($config['lignes'] + 15) |
|
| 300 | - . "' cols='40'"; |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - // on veut conserver la langue de l'interface ; |
|
| 304 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 305 | - // voudrait l'exploiter |
|
| 306 | - if (isset($contexte['lang'])) { |
|
| 307 | - $contexte['langue'] = $contexte['lang']; |
|
| 308 | - unset($contexte['lang']); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 312 | - ($lier_trad |
|
| 313 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 314 | - $lier_trad . |
|
| 315 | - "' />" . |
|
| 316 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 317 | - $lang_default . |
|
| 318 | - "' />" |
|
| 319 | - : '') |
|
| 320 | - . $hidden |
|
| 321 | - . ($md5 ?? ''); |
|
| 322 | - |
|
| 323 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 324 | - $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 325 | - |
|
| 326 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 327 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 328 | - // on le garde pour compat |
|
| 329 | - $contexte['_action'] = ["editer_$type", $id]; |
|
| 330 | - |
|
| 331 | - // et in fine placer l'autorisation |
|
| 332 | - include_spip('inc/autoriser'); |
|
| 333 | - if ((int) $id) { |
|
| 334 | - if (!autoriser('modifier', $type, (int) $id)) { |
|
| 335 | - $contexte['editable'] = ''; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - else { |
|
| 339 | - if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 340 | - $contexte['editable'] = ''; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return $contexte; |
|
| 211 | + $table_objet = table_objet($type); |
|
| 212 | + $table_objet_sql = table_objet_sql($type); |
|
| 213 | + $id_table_objet = id_table_objet($type); |
|
| 214 | + if (!is_array($row)) { |
|
| 215 | + $row = []; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | + if ( |
|
| 220 | + $config_fonc |
|
| 221 | + && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | + && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | + && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | + && in_array($config_fonc, $args) |
|
| 225 | + ) { |
|
| 226 | + $config_fonc = ''; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $new = !is_numeric($id); |
|
| 230 | + $lang_default = ''; |
|
| 231 | + // Appel direct dans un squelette |
|
| 232 | + if (!$row) { |
|
| 233 | + if (!$new || $lier_trad) { |
|
| 234 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | + // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | + $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | + } else { |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | + } |
|
| 241 | + if (!$new) { |
|
| 242 | + $md5 = controles_md5($row ?: []); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + if (!$row) { |
|
| 246 | + $row = []; |
|
| 247 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | + if ($desc = $trouver_table($table_objet)) { |
|
| 249 | + foreach ($desc['field'] as $k => $v) { |
|
| 250 | + $row[$k] = ''; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | + // (et donc: pas de lien de traduction) |
|
| 258 | + $id = ($new || $lier_trad) |
|
| 259 | + ? 'oui' |
|
| 260 | + : $row[$id_table_objet]; |
|
| 261 | + $row[$id_table_objet] = $id; |
|
| 262 | + |
|
| 263 | + $contexte = $row; |
|
| 264 | + if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | + if (!isset($contexte['id_parent'])) { |
|
| 266 | + unset($contexte['id_rubrique']); |
|
| 267 | + } |
|
| 268 | + $contexte['id_parent'] = $id_parent; |
|
| 269 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | + // id_rubrique dans id_parent si possible |
|
| 271 | + if (isset($contexte['id_rubrique'])) { |
|
| 272 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | + unset($contexte['id_rubrique']); |
|
| 274 | + } else { |
|
| 275 | + $contexte['id_parent'] = ''; |
|
| 276 | + } |
|
| 277 | + if ( |
|
| 278 | + !$contexte['id_parent'] |
|
| 279 | + && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | + ) { |
|
| 281 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $config = []; |
|
| 286 | + if ($config_fonc) { |
|
| 287 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | + if (!$lang_default) { |
|
| 289 | + $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + $config += [ |
|
| 293 | + 'lignes' => 0, |
|
| 294 | + 'langue' => '', |
|
| 295 | + ]; |
|
| 296 | + |
|
| 297 | + $att_text = " class='textarea' " |
|
| 298 | + . " rows='" |
|
| 299 | + . ($config['lignes'] + 15) |
|
| 300 | + . "' cols='40'"; |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + // on veut conserver la langue de l'interface ; |
|
| 304 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 305 | + // voudrait l'exploiter |
|
| 306 | + if (isset($contexte['lang'])) { |
|
| 307 | + $contexte['langue'] = $contexte['lang']; |
|
| 308 | + unset($contexte['lang']); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 312 | + ($lier_trad |
|
| 313 | + ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 314 | + $lier_trad . |
|
| 315 | + "' />" . |
|
| 316 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 317 | + $lang_default . |
|
| 318 | + "' />" |
|
| 319 | + : '') |
|
| 320 | + . $hidden |
|
| 321 | + . ($md5 ?? ''); |
|
| 322 | + |
|
| 323 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 324 | + $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 325 | + |
|
| 326 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 327 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 328 | + // on le garde pour compat |
|
| 329 | + $contexte['_action'] = ["editer_$type", $id]; |
|
| 330 | + |
|
| 331 | + // et in fine placer l'autorisation |
|
| 332 | + include_spip('inc/autoriser'); |
|
| 333 | + if ((int) $id) { |
|
| 334 | + if (!autoriser('modifier', $type, (int) $id)) { |
|
| 335 | + $contexte['editable'] = ''; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + else { |
|
| 339 | + if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 340 | + $contexte['editable'] = ''; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return $contexte; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -352,29 +352,29 @@ discard block |
||
| 352 | 352 | * @return array |
| 353 | 353 | */ |
| 354 | 354 | function coupe_trop_long($texte) { |
| 355 | - $aider = charger_fonction('aider', 'inc'); |
|
| 356 | - if (strlen($texte) > 28 * 1024) { |
|
| 357 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 358 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 359 | - if ($pos > 0 && $pos < 32 * 1024) { |
|
| 360 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 361 | - $suite = substr($texte, $pos + 2); |
|
| 362 | - } else { |
|
| 363 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 364 | - if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 365 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 366 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 367 | - } else { |
|
| 368 | - $decalage = 1; |
|
| 369 | - } |
|
| 370 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 371 | - $suite = substr($texte, $pos + $decalage); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - return ([$debut, $suite]); |
|
| 375 | - } else { |
|
| 376 | - return ([$texte, '']); |
|
| 377 | - } |
|
| 355 | + $aider = charger_fonction('aider', 'inc'); |
|
| 356 | + if (strlen($texte) > 28 * 1024) { |
|
| 357 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 358 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 359 | + if ($pos > 0 && $pos < 32 * 1024) { |
|
| 360 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 361 | + $suite = substr($texte, $pos + 2); |
|
| 362 | + } else { |
|
| 363 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 364 | + if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 365 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 366 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 367 | + } else { |
|
| 368 | + $decalage = 1; |
|
| 369 | + } |
|
| 370 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 371 | + $suite = substr($texte, $pos + $decalage); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + return ([$debut, $suite]); |
|
| 375 | + } else { |
|
| 376 | + return ([$texte, '']); |
|
| 377 | + } |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -385,13 +385,13 @@ discard block |
||
| 385 | 385 | * @param int $longueur |
| 386 | 386 | */ |
| 387 | 387 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 388 | - if (!_request($champ_titre)) { |
|
| 389 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 390 | - $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 391 | - if ($t) { |
|
| 392 | - set_request($champ_titre, $t); |
|
| 393 | - } |
|
| 394 | - } |
|
| 388 | + if (!_request($champ_titre)) { |
|
| 389 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 390 | + $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 391 | + if ($t) { |
|
| 392 | + set_request($champ_titre, $t); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -411,20 +411,20 @@ discard block |
||
| 411 | 411 | * @return string |
| 412 | 412 | */ |
| 413 | 413 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 414 | - // trouver un champ texte non vide |
|
| 415 | - $t = ''; |
|
| 416 | - foreach ($champs_contenu as $champ) { |
|
| 417 | - if ($t = _request($champ, $c)) { |
|
| 418 | - break; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - if ($t) { |
|
| 423 | - include_spip('inc/texte_mini'); |
|
| 424 | - $t = couper($t, $longueur, '...'); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return $t; |
|
| 414 | + // trouver un champ texte non vide |
|
| 415 | + $t = ''; |
|
| 416 | + foreach ($champs_contenu as $champ) { |
|
| 417 | + if ($t = _request($champ, $c)) { |
|
| 418 | + break; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + if ($t) { |
|
| 423 | + include_spip('inc/texte_mini'); |
|
| 424 | + $t = couper($t, $longueur, '...'); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return $t; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -446,22 +446,22 @@ discard block |
||
| 446 | 446 | * - array sinon couples ('$prefixe$colonne => md5) |
| 447 | 447 | **/ |
| 448 | 448 | function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') { |
| 449 | - $ctr = []; |
|
| 450 | - foreach ($data as $key => $val) { |
|
| 451 | - $m = md5($val ?? ''); |
|
| 452 | - $k = $prefixe . $key; |
|
| 453 | - |
|
| 454 | - $ctr[$k] = match ($format) { |
|
| 455 | - 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 456 | - default => $m, |
|
| 457 | - }; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - if ($format === 'html') { |
|
| 461 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 462 | - } else { |
|
| 463 | - return $ctr; |
|
| 464 | - } |
|
| 449 | + $ctr = []; |
|
| 450 | + foreach ($data as $key => $val) { |
|
| 451 | + $m = md5($val ?? ''); |
|
| 452 | + $k = $prefixe . $key; |
|
| 453 | + |
|
| 454 | + $ctr[$k] = match ($format) { |
|
| 455 | + 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 456 | + default => $m, |
|
| 457 | + }; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + if ($format === 'html') { |
|
| 461 | + return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 462 | + } else { |
|
| 463 | + return $ctr; |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -500,80 +500,80 @@ discard block |
||
| 500 | 500 | * - post : le contenu posté |
| 501 | 501 | **/ |
| 502 | 502 | function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') { |
| 503 | - include_spip('inc/filtres'); |
|
| 504 | - |
|
| 505 | - $table_objet = table_objet($type); |
|
| 506 | - $spip_table_objet = table_objet_sql($type); |
|
| 507 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 508 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 509 | - |
|
| 510 | - // Appels incomplets (sans $c) |
|
| 511 | - if (!is_array($c)) { |
|
| 512 | - $c = []; |
|
| 513 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 514 | - if (_request($champ)) { |
|
| 515 | - $c[$champ] = _request($champ); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 521 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 522 | - // il faut passer par instituer_XX() |
|
| 523 | - // TODO: faut-il passer ces variables interdites |
|
| 524 | - // dans un fichier de description separe ? |
|
| 525 | - unset($c['statut']); |
|
| 526 | - unset($c['id_parent']); |
|
| 527 | - unset($c['id_rubrique']); |
|
| 528 | - unset($c['id_secteur']); |
|
| 529 | - |
|
| 530 | - // Gerer les champs non vides |
|
| 531 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 532 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 533 | - if ($c[$champ] === '') { |
|
| 534 | - $c[$champ] = $sinon; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - // N'accepter que les champs qui existent |
|
| 540 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 541 | - $champs = []; |
|
| 542 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 543 | - if (isset($c[$champ])) { |
|
| 544 | - $champs[$champ] = $c[$champ]; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // Nettoyer les valeurs |
|
| 549 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 550 | - |
|
| 551 | - // Envoyer aux plugins |
|
| 552 | - $champs = pipeline( |
|
| 553 | - 'pre_edition', |
|
| 554 | - [ |
|
| 555 | - 'args' => [ |
|
| 556 | - 'table' => $spip_table_objet, // compatibilite |
|
| 557 | - 'table_objet' => $table_objet, |
|
| 558 | - 'spip_table_objet' => $spip_table_objet, |
|
| 559 | - 'type' => $type, |
|
| 560 | - 'id_objet' => $id, |
|
| 561 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 562 | - 'action' => 'controler', |
|
| 563 | - 'serveur' => $serveur, |
|
| 564 | - ], |
|
| 565 | - 'data' => $champs |
|
| 566 | - ] |
|
| 567 | - ); |
|
| 568 | - |
|
| 569 | - if (!$champs) { |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 574 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 575 | - |
|
| 576 | - return $conflits; |
|
| 503 | + include_spip('inc/filtres'); |
|
| 504 | + |
|
| 505 | + $table_objet = table_objet($type); |
|
| 506 | + $spip_table_objet = table_objet_sql($type); |
|
| 507 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 508 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 509 | + |
|
| 510 | + // Appels incomplets (sans $c) |
|
| 511 | + if (!is_array($c)) { |
|
| 512 | + $c = []; |
|
| 513 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 514 | + if (_request($champ)) { |
|
| 515 | + $c[$champ] = _request($champ); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 521 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 522 | + // il faut passer par instituer_XX() |
|
| 523 | + // TODO: faut-il passer ces variables interdites |
|
| 524 | + // dans un fichier de description separe ? |
|
| 525 | + unset($c['statut']); |
|
| 526 | + unset($c['id_parent']); |
|
| 527 | + unset($c['id_rubrique']); |
|
| 528 | + unset($c['id_secteur']); |
|
| 529 | + |
|
| 530 | + // Gerer les champs non vides |
|
| 531 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 532 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 533 | + if ($c[$champ] === '') { |
|
| 534 | + $c[$champ] = $sinon; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + // N'accepter que les champs qui existent |
|
| 540 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 541 | + $champs = []; |
|
| 542 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 543 | + if (isset($c[$champ])) { |
|
| 544 | + $champs[$champ] = $c[$champ]; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // Nettoyer les valeurs |
|
| 549 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 550 | + |
|
| 551 | + // Envoyer aux plugins |
|
| 552 | + $champs = pipeline( |
|
| 553 | + 'pre_edition', |
|
| 554 | + [ |
|
| 555 | + 'args' => [ |
|
| 556 | + 'table' => $spip_table_objet, // compatibilite |
|
| 557 | + 'table_objet' => $table_objet, |
|
| 558 | + 'spip_table_objet' => $spip_table_objet, |
|
| 559 | + 'type' => $type, |
|
| 560 | + 'id_objet' => $id, |
|
| 561 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 562 | + 'action' => 'controler', |
|
| 563 | + 'serveur' => $serveur, |
|
| 564 | + ], |
|
| 565 | + 'data' => $champs |
|
| 566 | + ] |
|
| 567 | + ); |
|
| 568 | + |
|
| 569 | + if (!$champs) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 574 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 575 | + |
|
| 576 | + return $conflits; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
@@ -603,66 +603,66 @@ discard block |
||
| 603 | 603 | * - post : le contenu posté |
| 604 | 604 | **/ |
| 605 | 605 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 606 | - $spip_table_objet = table_objet_sql($type); |
|
| 607 | - $id_table_objet = id_table_objet($type); |
|
| 608 | - |
|
| 609 | - // Controle des MD5 envoyes |
|
| 610 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 611 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 612 | - foreach ($champs as $key => $val) { |
|
| 613 | - if ( |
|
| 614 | - isset($ctr[$prefix . $key]) |
|
| 615 | - && ($m = $ctr[$prefix . $key]) |
|
| 616 | - && (is_scalar($val) && $m == md5($val)) |
|
| 617 | - ) { |
|
| 618 | - unset($champs[$key]); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - if (!$champs) { |
|
| 622 | - return; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // On veut savoir si notre modif va avoir un impact |
|
| 626 | - // par rapport aux donnees contenues dans la base |
|
| 627 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 628 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 629 | - $intact = true; |
|
| 630 | - foreach ($champs as $ch => $val) { |
|
| 631 | - $intact &= ($s[$ch] == $val); |
|
| 632 | - } |
|
| 633 | - if ($intact) { |
|
| 634 | - return; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - // Detection de conflits : |
|
| 638 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 639 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 640 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 641 | - // de conflit. |
|
| 642 | - $ctrh = $ctrq = $conflits = []; |
|
| 643 | - foreach (array_keys($champs) as $key) { |
|
| 644 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 645 | - $ctrh[$key] = $m; |
|
| 646 | - $ctrq[] = $key; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - if ($ctrq) { |
|
| 650 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 651 | - foreach ($ctrh as $key => $m) { |
|
| 652 | - if ( |
|
| 653 | - $m != md5((string) $ctrq[$key]) |
|
| 654 | - && $champs[$key] !== $ctrq[$key] |
|
| 655 | - ) { |
|
| 656 | - $conflits[$key] = [ |
|
| 657 | - 'base' => $ctrq[$key], |
|
| 658 | - 'post' => $champs[$key] |
|
| 659 | - ]; |
|
| 660 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 661 | - } |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return $conflits; |
|
| 606 | + $spip_table_objet = table_objet_sql($type); |
|
| 607 | + $id_table_objet = id_table_objet($type); |
|
| 608 | + |
|
| 609 | + // Controle des MD5 envoyes |
|
| 610 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 611 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 612 | + foreach ($champs as $key => $val) { |
|
| 613 | + if ( |
|
| 614 | + isset($ctr[$prefix . $key]) |
|
| 615 | + && ($m = $ctr[$prefix . $key]) |
|
| 616 | + && (is_scalar($val) && $m == md5($val)) |
|
| 617 | + ) { |
|
| 618 | + unset($champs[$key]); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + if (!$champs) { |
|
| 622 | + return; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // On veut savoir si notre modif va avoir un impact |
|
| 626 | + // par rapport aux donnees contenues dans la base |
|
| 627 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 628 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 629 | + $intact = true; |
|
| 630 | + foreach ($champs as $ch => $val) { |
|
| 631 | + $intact &= ($s[$ch] == $val); |
|
| 632 | + } |
|
| 633 | + if ($intact) { |
|
| 634 | + return; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + // Detection de conflits : |
|
| 638 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 639 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 640 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 641 | + // de conflit. |
|
| 642 | + $ctrh = $ctrq = $conflits = []; |
|
| 643 | + foreach (array_keys($champs) as $key) { |
|
| 644 | + if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 645 | + $ctrh[$key] = $m; |
|
| 646 | + $ctrq[] = $key; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + if ($ctrq) { |
|
| 650 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 651 | + foreach ($ctrh as $key => $m) { |
|
| 652 | + if ( |
|
| 653 | + $m != md5((string) $ctrq[$key]) |
|
| 654 | + && $champs[$key] !== $ctrq[$key] |
|
| 655 | + ) { |
|
| 656 | + $conflits[$key] = [ |
|
| 657 | + 'base' => $ctrq[$key], |
|
| 658 | + 'post' => $champs[$key] |
|
| 659 | + ]; |
|
| 660 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 661 | + } |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return $conflits; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -674,9 +674,9 @@ discard block |
||
| 674 | 674 | * @return string |
| 675 | 675 | */ |
| 676 | 676 | function display_conflit_champ($x) { |
| 677 | - if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 678 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 679 | - } else { |
|
| 680 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 681 | - } |
|
| 677 | + if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 678 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 679 | + } else { |
|
| 680 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 681 | + } |
|
| 682 | 682 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $res['message_ok'] = _T('info_modification_enregistree'); |
| 100 | 100 | if ($retour) { |
| 101 | 101 | if (str_starts_with($retour, 'javascript:')) { |
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>'; |
|
| 103 | 103 | $res['editable'] = true; |
| 104 | 104 | } else { |
| 105 | 105 | $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | if (!isset($erreurs[$champ])) { |
| 140 | 140 | $erreurs[$champ] = ''; |
| 141 | 141 | } |
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if ( |
| 220 | 220 | $config_fonc |
| 221 | 221 | && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 222 | + && $config_fonc !== $table_objet.'_edit_config' |
|
| 223 | 223 | && ($args = test_formulaire_inclus_par_modele()) |
| 224 | 224 | && in_array($config_fonc, $args) |
| 225 | 225 | ) { |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | // Appel direct dans un squelette |
| 232 | 232 | if (!$row) { |
| 233 | 233 | if (!$new || $lier_trad) { |
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 234 | + if ($select = charger_fonction('precharger_'.$type, 'inc', true)) { |
|
| 235 | 235 | $row = $select($id, $id_parent, $lier_trad); |
| 236 | 236 | // si on a une fonction precharger, elle pu faire un reglage de langue |
| 237 | 237 | $lang_default = (empty($row['lang']) ? null : $row['lang']); |
| 238 | 238 | } else { |
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.(int) $id); |
|
| 240 | 240 | } |
| 241 | 241 | if (!$new) { |
| 242 | 242 | $md5 = controles_md5($row ?: []); |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | if ($config_fonc) { |
| 287 | 287 | $contexte['config'] = $config = $config_fonc($contexte); |
| 288 | 288 | if (!$lang_default) { |
| 289 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 289 | + $lang_default = $config['langue'] ?? session_get('lang'); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | $config += [ |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | unset($contexte['lang']); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 311 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n". |
|
| 312 | 312 | ($lier_trad |
| 313 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 314 | - $lier_trad . |
|
| 315 | - "' />" . |
|
| 316 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 317 | - $lang_default . |
|
| 313 | + ? "\n<input type='hidden' name='lier_trad' value='". |
|
| 314 | + $lier_trad. |
|
| 315 | + "' />". |
|
| 316 | + "\n<input type='hidden' name='changer_lang' value='". |
|
| 317 | + $lang_default. |
|
| 318 | 318 | "' />" |
| 319 | 319 | : '') |
| 320 | 320 | . $hidden |
@@ -355,14 +355,14 @@ discard block |
||
| 355 | 355 | $aider = charger_fonction('aider', 'inc'); |
| 356 | 356 | if (strlen($texte) > 28 * 1024) { |
| 357 | 357 | $texte = str_replace("\r\n", "\n", $texte); |
| 358 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 358 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 359 | 359 | if ($pos > 0 && $pos < 32 * 1024) { |
| 360 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 360 | + $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 361 | 361 | $suite = substr($texte, $pos + 2); |
| 362 | 362 | } else { |
| 363 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 363 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 364 | 364 | if (!($pos > 0 && $pos < 32 * 1024)) { |
| 365 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 365 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 366 | 366 | $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
| 367 | 367 | } else { |
| 368 | 368 | $decalage = 1; |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | $ctr = []; |
| 450 | 450 | foreach ($data as $key => $val) { |
| 451 | 451 | $m = md5($val ?? ''); |
| 452 | - $k = $prefixe . $key; |
|
| 452 | + $k = $prefixe.$key; |
|
| 453 | 453 | |
| 454 | 454 | $ctr[$k] = match ($format) { |
| 455 | 455 | 'html' => "<input type='hidden' value='$m' name='$k' />", |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | if ($format === 'html') { |
| 461 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 461 | + return "\n\n<!-- controles md5 -->\n".implode("\n", $ctr)."\n\n"; |
|
| 462 | 462 | } else { |
| 463 | 463 | return $ctr; |
| 464 | 464 | } |
@@ -611,8 +611,8 @@ discard block |
||
| 611 | 611 | // potentiellement modifiees entre temps par un autre utilisateur) |
| 612 | 612 | foreach ($champs as $key => $val) { |
| 613 | 613 | if ( |
| 614 | - isset($ctr[$prefix . $key]) |
|
| 615 | - && ($m = $ctr[$prefix . $key]) |
|
| 614 | + isset($ctr[$prefix.$key]) |
|
| 615 | + && ($m = $ctr[$prefix.$key]) |
|
| 616 | 616 | && (is_scalar($val) && $m == md5($val)) |
| 617 | 617 | ) { |
| 618 | 618 | unset($champs[$key]); |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | // de conflit. |
| 642 | 642 | $ctrh = $ctrq = $conflits = []; |
| 643 | 643 | foreach (array_keys($champs) as $key) { |
| 644 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 644 | + if (isset($ctr[$prefix.$key]) && ($m = $ctr[$prefix.$key])) { |
|
| 645 | 645 | $ctrh[$key] = $m; |
| 646 | 646 | $ctrq[] = $key; |
| 647 | 647 | } |
@@ -675,8 +675,8 @@ discard block |
||
| 675 | 675 | */ |
| 676 | 676 | function display_conflit_champ($x) { |
| 677 | 677 | if (strstr($x, "\n") || strlen($x) > 80) { |
| 678 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 678 | + return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 679 | 679 | } else { |
| 680 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 680 | + return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 681 | 681 | } |
| 682 | 682 | } |