@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_MENU_LANG_ECRIRE($p) { |
| 39 | - return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 39 | + return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * - string: Si pas de multilinguisme |
| 56 | 56 | */ |
| 57 | 57 | function balise_MENU_LANG_ECRIRE_stat($args, $context_compil) { |
| 58 | - include_spip('inc/lang'); |
|
| 59 | - if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 58 | + include_spip('inc/lang'); |
|
| 59 | + if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $args; |
|
| 63 | + return $args; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Liste : Chemin du squelette, durée du cache, contexte |
| 77 | 77 | **/ |
| 78 | 78 | function balise_MENU_LANG_ECRIRE_dyn($opt) { |
| 79 | - return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 79 | + return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -96,30 +96,30 @@ discard block |
||
| 96 | 96 | * Liste : Chemin du squelette, durée du cache, contexte |
| 97 | 97 | **/ |
| 98 | 98 | function menu_lang_pour_tous($nom, $default) { |
| 99 | - include_spip('inc/lang'); |
|
| 99 | + include_spip('inc/lang'); |
|
| 100 | 100 | |
| 101 | - if ($GLOBALS['spip_lang'] != $default) { |
|
| 102 | - $opt = lang_select($default); # et remplace |
|
| 103 | - if ($GLOBALS['spip_lang'] != $default) { |
|
| 104 | - $default = ''; # annule tout choix par defaut |
|
| 105 | - if ($opt) { |
|
| 106 | - lang_select(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 101 | + if ($GLOBALS['spip_lang'] != $default) { |
|
| 102 | + $opt = lang_select($default); # et remplace |
|
| 103 | + if ($GLOBALS['spip_lang'] != $default) { |
|
| 104 | + $default = ''; # annule tout choix par defaut |
|
| 105 | + if ($opt) { |
|
| 106 | + lang_select(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - # lien a partir de / |
|
| 112 | - $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | - $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true); |
|
| 111 | + # lien a partir de / |
|
| 112 | + $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | + $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true); |
|
| 114 | 114 | |
| 115 | - return [ |
|
| 116 | - 'formulaires/menu_lang', |
|
| 117 | - 3600, |
|
| 118 | - [ |
|
| 119 | - 'nom' => $nom, |
|
| 120 | - 'url' => $post, |
|
| 121 | - 'name' => $nom, |
|
| 122 | - 'default' => $default, |
|
| 123 | - ] |
|
| 124 | - ]; |
|
| 115 | + return [ |
|
| 116 | + 'formulaires/menu_lang', |
|
| 117 | + 3600, |
|
| 118 | + [ |
|
| 119 | + 'nom' => $nom, |
|
| 120 | + 'url' => $post, |
|
| 121 | + 'name' => $nom, |
|
| 122 | + 'default' => $default, |
|
| 123 | + ] |
|
| 124 | + ]; |
|
| 125 | 125 | } |
@@ -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 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Pile complétée du code compilé |
| 42 | 42 | **/ |
| 43 | 43 | function balise_FORMULAIRE_ADMIN($p) { |
| 44 | - return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 44 | + return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * - chaîne vide sinon. |
| 59 | 59 | */ |
| 60 | 60 | function balise_FORMULAIRE_ADMIN_stat($args, $context_compil) { |
| 61 | - return $args; |
|
| 61 | + return $args; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -83,64 +83,64 @@ discard block |
||
| 83 | 83 | **/ |
| 84 | 84 | function balise_FORMULAIRE_ADMIN_dyn($float = '', $debug = '') { |
| 85 | 85 | |
| 86 | - static $dejafait = false; |
|
| 86 | + static $dejafait = false; |
|
| 87 | 87 | |
| 88 | - if (empty($_COOKIE['spip_admin'])) { |
|
| 89 | - return ''; |
|
| 90 | - } |
|
| 88 | + if (empty($_COOKIE['spip_admin'])) { |
|
| 89 | + return ''; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - if (!is_array($debug)) { |
|
| 93 | - if ($dejafait) { |
|
| 94 | - return ''; |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - if ($dejafait) { |
|
| 98 | - if (empty($debug['sourcefile'])) { |
|
| 99 | - return ''; |
|
| 100 | - } |
|
| 101 | - foreach ($debug['sourcefile'] as $k => $v) { |
|
| 102 | - if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) { |
|
| 103 | - return $debug['resultat'][$k . 'tout']; |
|
| 104 | - } |
|
| 105 | - } |
|
| 92 | + if (!is_array($debug)) { |
|
| 93 | + if ($dejafait) { |
|
| 94 | + return ''; |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + if ($dejafait) { |
|
| 98 | + if (empty($debug['sourcefile'])) { |
|
| 99 | + return ''; |
|
| 100 | + } |
|
| 101 | + foreach ($debug['sourcefile'] as $k => $v) { |
|
| 102 | + if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) { |
|
| 103 | + return $debug['resultat'][$k . 'tout']; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - } |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - include_spip('inc/autoriser'); |
|
| 112 | - include_spip('base/abstract_sql'); |
|
| 111 | + include_spip('inc/autoriser'); |
|
| 112 | + include_spip('base/abstract_sql'); |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - $dejafait = true; |
|
| 115 | + $dejafait = true; |
|
| 116 | 116 | |
| 117 | - // Preparer le #ENV des boutons |
|
| 117 | + // Preparer le #ENV des boutons |
|
| 118 | 118 | |
| 119 | - $env = admin_objet(); |
|
| 119 | + $env = admin_objet(); |
|
| 120 | 120 | |
| 121 | - // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 122 | - if (!$env) { |
|
| 123 | - $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 124 | - } |
|
| 121 | + // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 122 | + if (!$env) { |
|
| 123 | + $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $env['divclass'] = $float; |
|
| 127 | - $env['lang'] = admin_lang(); |
|
| 128 | - $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 129 | - $env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 130 | - $env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 131 | - $env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : ''); |
|
| 126 | + $env['divclass'] = $float; |
|
| 127 | + $env['lang'] = admin_lang(); |
|
| 128 | + $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 129 | + $env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 130 | + $env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 131 | + $env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : ''); |
|
| 132 | 132 | |
| 133 | - if (empty($GLOBALS['use_cache'])) { |
|
| 134 | - $env['use_cache'] = ' *'; |
|
| 135 | - } |
|
| 133 | + if (empty($GLOBALS['use_cache'])) { |
|
| 134 | + $env['use_cache'] = ' *'; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - if (isset($debug['validation'])) { |
|
| 138 | - $env['xhtml_error'] = $debug['validation']; |
|
| 139 | - } |
|
| 137 | + if (isset($debug['validation'])) { |
|
| 138 | + $env['xhtml_error'] = $debug['validation']; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $env['_pipelines']['formulaire_admin'] = []; |
|
| 141 | + $env['_pipelines']['formulaire_admin'] = []; |
|
| 142 | 142 | |
| 143 | - return ['formulaires/administration', 0, $env]; |
|
| 143 | + return ['formulaires/administration', 0, $env]; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -158,46 +158,46 @@ discard block |
||
| 158 | 158 | * Tableau de l'environnement calculé |
| 159 | 159 | **/ |
| 160 | 160 | function admin_objet() { |
| 161 | - include_spip('inc/urls'); |
|
| 162 | - $env = []; |
|
| 163 | - |
|
| 164 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 165 | - $objets = urls_liste_objets(false); |
|
| 166 | - $objets = array_diff($objets, ['rubrique']); |
|
| 167 | - $objets = array_reverse($objets); |
|
| 168 | - array_unshift($objets, 'rubrique'); |
|
| 169 | - foreach ($objets as $obj) { |
|
| 170 | - $type = $obj; |
|
| 171 | - if ( |
|
| 172 | - $type == objet_type($type, false) |
|
| 173 | - && ($_id_type = id_table_objet($type)) |
|
| 174 | - && isset($GLOBALS['contexte'][$_id_type]) |
|
| 175 | - && ($id = $GLOBALS['contexte'][$_id_type]) |
|
| 176 | - && !is_array($id) |
|
| 177 | - && ($id = (int) $id) |
|
| 178 | - && ($desc = $trouver_table(table_objet_sql($type))) |
|
| 179 | - ) { |
|
| 180 | - $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id); |
|
| 181 | - if ($id) { |
|
| 182 | - $env[$_id_type] = $id; |
|
| 183 | - $env['objet'] = $type; |
|
| 184 | - $env['id_objet'] = $id; |
|
| 185 | - $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 186 | - if ( |
|
| 187 | - isset($desc['field']['id_rubrique']) |
|
| 188 | - && $type != 'rubrique' |
|
| 189 | - ) { |
|
| 190 | - unset($env['id_rubrique']); |
|
| 191 | - unset($env['voir_rubrique']); |
|
| 192 | - if (admin_preview($type, $id, $desc)) { |
|
| 193 | - $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $env; |
|
| 161 | + include_spip('inc/urls'); |
|
| 162 | + $env = []; |
|
| 163 | + |
|
| 164 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 165 | + $objets = urls_liste_objets(false); |
|
| 166 | + $objets = array_diff($objets, ['rubrique']); |
|
| 167 | + $objets = array_reverse($objets); |
|
| 168 | + array_unshift($objets, 'rubrique'); |
|
| 169 | + foreach ($objets as $obj) { |
|
| 170 | + $type = $obj; |
|
| 171 | + if ( |
|
| 172 | + $type == objet_type($type, false) |
|
| 173 | + && ($_id_type = id_table_objet($type)) |
|
| 174 | + && isset($GLOBALS['contexte'][$_id_type]) |
|
| 175 | + && ($id = $GLOBALS['contexte'][$_id_type]) |
|
| 176 | + && !is_array($id) |
|
| 177 | + && ($id = (int) $id) |
|
| 178 | + && ($desc = $trouver_table(table_objet_sql($type))) |
|
| 179 | + ) { |
|
| 180 | + $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id); |
|
| 181 | + if ($id) { |
|
| 182 | + $env[$_id_type] = $id; |
|
| 183 | + $env['objet'] = $type; |
|
| 184 | + $env['id_objet'] = $id; |
|
| 185 | + $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 186 | + if ( |
|
| 187 | + isset($desc['field']['id_rubrique']) |
|
| 188 | + && $type != 'rubrique' |
|
| 189 | + ) { |
|
| 190 | + unset($env['id_rubrique']); |
|
| 191 | + unset($env['voir_rubrique']); |
|
| 192 | + if (admin_preview($type, $id, $desc)) { |
|
| 193 | + $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $env; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -215,30 +215,30 @@ discard block |
||
| 215 | 215 | * - Tableau d'un élément sinon. |
| 216 | 216 | **/ |
| 217 | 217 | function admin_preview($type, $id, $desc = null) { |
| 218 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) { |
|
| 219 | - return ''; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (!$desc) { |
|
| 223 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 224 | - $desc = $trouver_table(table_objet_sql($type)); |
|
| 225 | - } |
|
| 226 | - if (!$desc || !isset($desc['field']['statut'])) { |
|
| 227 | - return ''; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - include_spip('inc/autoriser'); |
|
| 231 | - if (!autoriser('previsualiser')) { |
|
| 232 | - return ''; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 236 | - |
|
| 237 | - if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 238 | - $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 218 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) { |
|
| 219 | + return ''; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (!$desc) { |
|
| 223 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 224 | + $desc = $trouver_table(table_objet_sql($type)); |
|
| 225 | + } |
|
| 226 | + if (!$desc || !isset($desc['field']['statut'])) { |
|
| 227 | + return ''; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + include_spip('inc/autoriser'); |
|
| 231 | + if (!autoriser('previsualiser')) { |
|
| 232 | + return ''; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 236 | + |
|
| 237 | + if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 238 | + $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -249,25 +249,25 @@ discard block |
||
| 249 | 249 | * Code de langue |
| 250 | 250 | **/ |
| 251 | 251 | function admin_lang() { |
| 252 | - $alang = ''; |
|
| 253 | - if (!empty($_COOKIE['spip_admin'])) { |
|
| 254 | - $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']); |
|
| 255 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 256 | - if (!$alang) { |
|
| 257 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - if (!$alang) { |
|
| 261 | - return ''; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $l = lang_select($alang); |
|
| 265 | - $alang = $GLOBALS['spip_lang']; |
|
| 266 | - if ($l) { |
|
| 267 | - lang_select(); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return $alang; |
|
| 252 | + $alang = ''; |
|
| 253 | + if (!empty($_COOKIE['spip_admin'])) { |
|
| 254 | + $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']); |
|
| 255 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 256 | + if (!$alang) { |
|
| 257 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + if (!$alang) { |
|
| 261 | + return ''; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $l = lang_select($alang); |
|
| 265 | + $alang = $GLOBALS['spip_lang']; |
|
| 266 | + if ($l) { |
|
| 267 | + lang_select(); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return $alang; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | **/ |
| 278 | 278 | function admin_valider() { |
| 279 | 279 | |
| 280 | - return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ? |
|
| 281 | - (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 282 | - . '&var_mode_affiche=validation') : |
|
| 283 | - ('http://validator.w3.org/check?uri=' |
|
| 284 | - . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 280 | + return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ? |
|
| 281 | + (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 282 | + . '&var_mode_affiche=validation') : |
|
| 283 | + ('http://validator.w3.org/check?uri=' |
|
| 284 | + . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * @return string |
| 291 | 291 | **/ |
| 292 | 292 | function admin_debug() { |
| 293 | - return ( |
|
| 294 | - (isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug'] |
|
| 295 | - || isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug'] |
|
| 296 | - || defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug') |
|
| 297 | - ) |
|
| 298 | - ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 293 | + return ( |
|
| 294 | + (isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug'] |
|
| 295 | + || isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug'] |
|
| 296 | + || defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug') |
|
| 297 | + ) |
|
| 298 | + ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 299 | 299 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -34,49 +34,49 @@ discard block |
||
| 34 | 34 | **/ |
| 35 | 35 | function maj_timestamp_mysql($tables = null) { |
| 36 | 36 | |
| 37 | - include_spip('base/dump'); |
|
| 38 | - if (is_null($tables)) { |
|
| 39 | - $tables = base_lister_toutes_tables(); |
|
| 40 | - } elseif (is_string($tables)) { |
|
| 41 | - $tables = [$tables]; |
|
| 42 | - } elseif (!is_array($tables)) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 37 | + include_spip('base/dump'); |
|
| 38 | + if (is_null($tables)) { |
|
| 39 | + $tables = base_lister_toutes_tables(); |
|
| 40 | + } elseif (is_string($tables)) { |
|
| 41 | + $tables = [$tables]; |
|
| 42 | + } elseif (!is_array($tables)) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // rien a faire si base non mysql |
|
| 47 | - if (!str_starts_with((string) $GLOBALS['connexions'][0]['type'], 'mysql')) { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 46 | + // rien a faire si base non mysql |
|
| 47 | + if (!str_starts_with((string) $GLOBALS['connexions'][0]['type'], 'mysql')) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 52 | - // forcer le vidage de cache |
|
| 53 | - $trouver_table(''); |
|
| 51 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 52 | + // forcer le vidage de cache |
|
| 53 | + $trouver_table(''); |
|
| 54 | 54 | |
| 55 | - foreach ($tables as $table) { |
|
| 56 | - if (time() >= _TIME_OUT) { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - if ($desc = $trouver_table($table)) { |
|
| 60 | - $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 61 | - $d = array_diff($desc['field'], $fields_corrected); |
|
| 62 | - if ($d) { |
|
| 63 | - spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 64 | - foreach ($desc['field'] as $field => $type) { |
|
| 65 | - if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 66 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 67 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 68 | - $trouver_table(''); |
|
| 69 | - $new_desc = $trouver_table($table); |
|
| 70 | - spip_log( |
|
| 71 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 72 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 55 | + foreach ($tables as $table) { |
|
| 56 | + if (time() >= _TIME_OUT) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + if ($desc = $trouver_table($table)) { |
|
| 60 | + $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 61 | + $d = array_diff($desc['field'], $fields_corrected); |
|
| 62 | + if ($d) { |
|
| 63 | + spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 64 | + foreach ($desc['field'] as $field => $type) { |
|
| 65 | + if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 66 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 67 | + sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 68 | + $trouver_table(''); |
|
| 69 | + $new_desc = $trouver_table($table); |
|
| 70 | + spip_log( |
|
| 71 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 72 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // forcer le vidage de cache |
|
| 81 | - $trouver_table(''); |
|
| 80 | + // forcer le vidage de cache |
|
| 81 | + $trouver_table(''); |
|
| 82 | 82 | } |
@@ -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 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 25 | 25 | // ne pas ecraser une definition perso dans mes_options |
| 26 | 26 | if (!isset($GLOBALS['ldap_attributes']) || !is_array($GLOBALS['ldap_attributes'])) { |
| 27 | - $GLOBALS['ldap_attributes'] = [ |
|
| 28 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | - 'nom' => 'cn', |
|
| 30 | - 'email' => 'mail', |
|
| 31 | - 'bio' => 'description' |
|
| 32 | - ]; |
|
| 27 | + $GLOBALS['ldap_attributes'] = [ |
|
| 28 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | + 'nom' => 'cn', |
|
| 30 | + 'email' => 'mail', |
|
| 31 | + 'bio' => 'description' |
|
| 32 | + ]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,49 +55,49 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 57 | 57 | |
| 58 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | - |
|
| 60 | - // Utilisateur connu ? |
|
| 61 | - // si http auth, inutile de reauthentifier: cela |
|
| 62 | - // ne marchera pas avec auth http autre que basic. |
|
| 63 | - $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 67 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | - |
|
| 69 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | - |
|
| 72 | - if ($r) { |
|
| 73 | - return array_merge($r, $credentials_ldap); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // sinon importer les infos depuis LDAP, |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | - ) { |
|
| 81 | - // rajouter le statut indique a l'install |
|
| 82 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | - $desc['login'] = $login; |
|
| 84 | - $desc['source'] = 'ldap'; |
|
| 85 | - $desc['pass'] = ''; |
|
| 86 | - |
|
| 87 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - if ($r) { |
|
| 91 | - return array_merge( |
|
| 92 | - $credentials_ldap, |
|
| 93 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // sinon echec |
|
| 98 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 99 | - |
|
| 100 | - return []; |
|
| 58 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | + |
|
| 60 | + // Utilisateur connu ? |
|
| 61 | + // si http auth, inutile de reauthentifier: cela |
|
| 62 | + // ne marchera pas avec auth http autre que basic. |
|
| 63 | + $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | + |
|
| 69 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + |
|
| 72 | + if ($r) { |
|
| 73 | + return array_merge($r, $credentials_ldap); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // sinon importer les infos depuis LDAP, |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | + ) { |
|
| 81 | + // rajouter le statut indique a l'install |
|
| 82 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | + $desc['login'] = $login; |
|
| 84 | + $desc['source'] = 'ldap'; |
|
| 85 | + $desc['pass'] = ''; |
|
| 86 | + |
|
| 87 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + if ($r) { |
|
| 91 | + return array_merge( |
|
| 92 | + $credentials_ldap, |
|
| 93 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // sinon echec |
|
| 98 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 99 | + |
|
| 100 | + return []; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * @return array |
| 112 | 112 | */ |
| 113 | 113 | function auth_ldap_connect($serveur = '') { |
| 114 | - include_spip('base/connect_sql'); |
|
| 115 | - static $connexions_ldap = []; |
|
| 116 | - if (isset($connexions_ldap[$serveur])) { |
|
| 117 | - return $connexions_ldap[$serveur]; |
|
| 118 | - } |
|
| 119 | - $connexion = spip_connect($serveur); |
|
| 120 | - if (!is_array($connexion['ldap'])) { |
|
| 121 | - if ($connexion['authentification']['ldap']) { |
|
| 122 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | - unset($GLOBALS['ldap_link']); |
|
| 124 | - if (is_readable($f)) { |
|
| 125 | - include_once($f); |
|
| 126 | - }; |
|
| 127 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | - $connexion['ldap'] = [ |
|
| 129 | - 'link' => $GLOBALS['ldap_link'], |
|
| 130 | - 'base' => $GLOBALS['ldap_base'] |
|
| 131 | - ]; |
|
| 132 | - } else { |
|
| 133 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | - } |
|
| 135 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 114 | + include_spip('base/connect_sql'); |
|
| 115 | + static $connexions_ldap = []; |
|
| 116 | + if (isset($connexions_ldap[$serveur])) { |
|
| 117 | + return $connexions_ldap[$serveur]; |
|
| 118 | + } |
|
| 119 | + $connexion = spip_connect($serveur); |
|
| 120 | + if (!is_array($connexion['ldap'])) { |
|
| 121 | + if ($connexion['authentification']['ldap']) { |
|
| 122 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | + unset($GLOBALS['ldap_link']); |
|
| 124 | + if (is_readable($f)) { |
|
| 125 | + include_once($f); |
|
| 126 | + }; |
|
| 127 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | + $connexion['ldap'] = [ |
|
| 129 | + 'link' => $GLOBALS['ldap_link'], |
|
| 130 | + 'base' => $GLOBALS['ldap_base'] |
|
| 131 | + ]; |
|
| 132 | + } else { |
|
| 133 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | + } |
|
| 135 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,52 +154,52 @@ discard block |
||
| 154 | 154 | * Le login trouvé ou chaine vide si non trouvé |
| 155 | 155 | */ |
| 156 | 156 | function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') { |
| 157 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | - if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // verifier la connexion |
|
| 164 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | - return ''; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $ldap_link = $ldap['link'] ?? null; |
|
| 169 | - $ldap_base = $ldap['base'] ?? null; |
|
| 170 | - $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | - |
|
| 172 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | - |
|
| 174 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | - foreach ($logins as $att) { |
|
| 176 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | - // (on veut un attribut unique) |
|
| 180 | - |
|
| 181 | - if (is_array($info) && $info['count'] == 1) { |
|
| 182 | - $dn = $info[0]['dn']; |
|
| 183 | - if (!$checkpass) { |
|
| 184 | - return $dn; |
|
| 185 | - } |
|
| 186 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | - return $dn; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if ($checkpass && !isset($dn)) { |
|
| 193 | - // Si echec, essayer de deviner le DN |
|
| 194 | - foreach ($logins as $att) { |
|
| 195 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | - return "$att=$login_search, $ldap_base"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return ''; |
|
| 157 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | + if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // verifier la connexion |
|
| 164 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | + return ''; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $ldap_link = $ldap['link'] ?? null; |
|
| 169 | + $ldap_base = $ldap['base'] ?? null; |
|
| 170 | + $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | + |
|
| 172 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | + |
|
| 174 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | + foreach ($logins as $att) { |
|
| 176 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | + // (on veut un attribut unique) |
|
| 180 | + |
|
| 181 | + if (is_array($info) && $info['count'] == 1) { |
|
| 182 | + $dn = $info[0]['dn']; |
|
| 183 | + if (!$checkpass) { |
|
| 184 | + return $dn; |
|
| 185 | + } |
|
| 186 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | + return $dn; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if ($checkpass && !isset($dn)) { |
|
| 193 | + // Si echec, essayer de deviner le DN |
|
| 194 | + foreach ($logins as $att) { |
|
| 195 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | + return "$att=$login_search, $ldap_base"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return ''; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -211,40 +211,40 @@ discard block |
||
| 211 | 211 | * @return array |
| 212 | 212 | */ |
| 213 | 213 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 214 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 214 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 215 | 215 | |
| 216 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | - spip_log("ldap $serveur injoignable"); |
|
| 216 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | + spip_log("ldap $serveur injoignable"); |
|
| 218 | 218 | |
| 219 | - return []; |
|
| 220 | - } |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $ldap_link = $ldap['link']; |
|
| 223 | - if (!$desc) { |
|
| 224 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | - unset($desc['login']); |
|
| 226 | - } |
|
| 227 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 222 | + $ldap_link = $ldap['link']; |
|
| 223 | + if (!$desc) { |
|
| 224 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | + unset($desc['login']); |
|
| 226 | + } |
|
| 227 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 228 | 228 | |
| 229 | - if (!$result) { |
|
| 230 | - return []; |
|
| 231 | - } |
|
| 229 | + if (!$result) { |
|
| 230 | + return []; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | - if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | - return []; |
|
| 237 | - } |
|
| 238 | - $val = $val[0]; |
|
| 233 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | + if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | + return []; |
|
| 237 | + } |
|
| 238 | + $val = $val[0]; |
|
| 239 | 239 | |
| 240 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | - include_spip('inc/charsets'); |
|
| 240 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | + include_spip('inc/charsets'); |
|
| 242 | 242 | |
| 243 | - foreach ($desc as $k => $v) { |
|
| 244 | - $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | - } |
|
| 243 | + foreach ($desc as $k => $v) { |
|
| 244 | + $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $desc; |
|
| 247 | + return $desc; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 259 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 259 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * Message d'erreur si login non valide, chaîne vide sinon |
| 277 | 277 | */ |
| 278 | 278 | function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 279 | - include_spip('auth/spip'); |
|
| 279 | + include_spip('auth/spip'); |
|
| 280 | 280 | |
| 281 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 281 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * ``` |
| 300 | 300 | */ |
| 301 | 301 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 302 | - return true; |
|
| 302 | + return true; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -317,22 +317,22 @@ discard block |
||
| 317 | 317 | * Informe du succès ou de l'echec du changement du mot de passe |
| 318 | 318 | */ |
| 319 | 319 | function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 320 | - if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | - return false; |
|
| 325 | - } |
|
| 326 | - $link = $ldap['link']; |
|
| 327 | - include_spip('inc/session'); |
|
| 328 | - $dn = session_get('ldap_dn'); |
|
| 329 | - if ('' == $dn) { |
|
| 330 | - return false; |
|
| 331 | - } |
|
| 332 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | - |
|
| 337 | - return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 320 | + if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | + return false; |
|
| 325 | + } |
|
| 326 | + $link = $ldap['link']; |
|
| 327 | + include_spip('inc/session'); |
|
| 328 | + $dn = session_get('ldap_dn'); |
|
| 329 | + if ('' == $dn) { |
|
| 330 | + return false; |
|
| 331 | + } |
|
| 332 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | + |
|
| 337 | + return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 338 | 338 | } |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 25 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | * Description de la boucle complétée des champs |
| 44 | 44 | */ |
| 45 | 45 | function iterateur_DATA_dist($b) { |
| 46 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | - $b->show = [ |
|
| 48 | - 'field' => [ |
|
| 49 | - 'cle' => 'STRING', |
|
| 50 | - 'valeur' => 'STRING', |
|
| 51 | - '*' => 'ALL' // Champ joker * |
|
| 52 | - ] |
|
| 53 | - ]; |
|
| 54 | - $b->select[] = '.valeur'; |
|
| 55 | - |
|
| 56 | - return $b; |
|
| 46 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | + $b->show = [ |
|
| 48 | + 'field' => [ |
|
| 49 | + 'cle' => 'STRING', |
|
| 50 | + 'valeur' => 'STRING', |
|
| 51 | + '*' => 'ALL' // Champ joker * |
|
| 52 | + ] |
|
| 53 | + ]; |
|
| 54 | + $b->select[] = '.valeur'; |
|
| 55 | + |
|
| 56 | + return $b; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | 70 | function inc_file_to_array_dist($data) { |
| 71 | - return preg_split('/\r?\n/', $data); |
|
| 71 | + return preg_split('/\r?\n/', $data); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function inc_plugins_to_array_dist() { |
| 80 | - include_spip('inc/plugin'); |
|
| 80 | + include_spip('inc/plugin'); |
|
| 81 | 81 | |
| 82 | - return liste_chemin_plugin_actifs(); |
|
| 82 | + return liste_chemin_plugin_actifs(); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | 91 | function inc_xml_to_array_dist($data) { |
| 92 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 92 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | 103 | function inc_object_to_array($object) { |
| 104 | - if (!is_object($object) && !is_array($object)) { |
|
| 105 | - return $object; |
|
| 106 | - } |
|
| 107 | - if (is_object($object)) { |
|
| 108 | - $object = get_object_vars($object); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return array_map('inc_object_to_array', $object); |
|
| 104 | + if (!is_object($object) && !is_array($object)) { |
|
| 105 | + return $object; |
|
| 106 | + } |
|
| 107 | + if (is_object($object)) { |
|
| 108 | + $object = get_object_vars($object); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return array_map('inc_object_to_array', $object); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,20 +118,20 @@ discard block |
||
| 118 | 118 | * @return array|bool |
| 119 | 119 | */ |
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | - # sortir le connecteur de $data |
|
| 122 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | - $serveur = (string)$v[1]; |
|
| 124 | - $req = trim($v[2]); |
|
| 125 | - if ($s = sql_query($req, $serveur)) { |
|
| 126 | - $r = []; |
|
| 127 | - while ($t = sql_fetch($s)) { |
|
| 128 | - $r[] = $t; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $r; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return false; |
|
| 121 | + # sortir le connecteur de $data |
|
| 122 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | + $serveur = (string)$v[1]; |
|
| 124 | + $req = trim($v[2]); |
|
| 125 | + if ($s = sql_query($req, $serveur)) { |
|
| 126 | + $r = []; |
|
| 127 | + while ($t = sql_fetch($s)) { |
|
| 128 | + $r[] = $t; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $r; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @return array|bool |
| 142 | 142 | */ |
| 143 | 143 | function inc_json_to_array_dist($data) { |
| 144 | - try { |
|
| 145 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | - } catch (JsonException $e) { |
|
| 147 | - $json = null; |
|
| 148 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | - } |
|
| 150 | - return is_array($json) ? (array) $json : []; |
|
| 144 | + try { |
|
| 145 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | + } catch (JsonException $e) { |
|
| 147 | + $json = null; |
|
| 148 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | + } |
|
| 150 | + return is_array($json) ? (array) $json : []; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,30 +157,30 @@ discard block |
||
| 157 | 157 | * @return array|bool |
| 158 | 158 | */ |
| 159 | 159 | function inc_csv_to_array_dist($data) { |
| 160 | - include_spip('inc/csv'); |
|
| 161 | - [$entete, $csv] = analyse_csv($data); |
|
| 162 | - array_unshift($csv, $entete); |
|
| 163 | - |
|
| 164 | - include_spip('inc/charsets'); |
|
| 165 | - $i = 1; |
|
| 166 | - foreach ($entete as $k => $v) { |
|
| 167 | - if (trim((string) $v) == '') { |
|
| 168 | - $v = 'col' . $i; |
|
| 169 | - } // reperer des eventuelles cases vides |
|
| 170 | - if (is_numeric($v) && $v < 0) { |
|
| 171 | - $v = '__' . $v; |
|
| 172 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | - if (is_numeric($v)) { |
|
| 174 | - $v = '_' . $v; |
|
| 175 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | - $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | - foreach ($csv as &$item) { |
|
| 178 | - $item[$v] = &$item[$k]; |
|
| 179 | - } |
|
| 180 | - $i++; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $csv; |
|
| 160 | + include_spip('inc/csv'); |
|
| 161 | + [$entete, $csv] = analyse_csv($data); |
|
| 162 | + array_unshift($csv, $entete); |
|
| 163 | + |
|
| 164 | + include_spip('inc/charsets'); |
|
| 165 | + $i = 1; |
|
| 166 | + foreach ($entete as $k => $v) { |
|
| 167 | + if (trim((string) $v) == '') { |
|
| 168 | + $v = 'col' . $i; |
|
| 169 | + } // reperer des eventuelles cases vides |
|
| 170 | + if (is_numeric($v) && $v < 0) { |
|
| 171 | + $v = '__' . $v; |
|
| 172 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | + if (is_numeric($v)) { |
|
| 174 | + $v = '_' . $v; |
|
| 175 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | + $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | + foreach ($csv as &$item) { |
|
| 178 | + $item[$v] = &$item[$k]; |
|
| 179 | + } |
|
| 180 | + $i++; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $csv; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @return array|bool |
| 191 | 191 | */ |
| 192 | 192 | function inc_rss_to_array_dist($data) { |
| 193 | - $tableau = null; |
|
| 194 | - include_spip('inc/syndic'); |
|
| 195 | - if (is_array($rss = analyser_backend($data))) { |
|
| 196 | - $tableau = $rss; |
|
| 197 | - } |
|
| 193 | + $tableau = null; |
|
| 194 | + include_spip('inc/syndic'); |
|
| 195 | + if (is_array($rss = analyser_backend($data))) { |
|
| 196 | + $tableau = $rss; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $tableau; |
|
| 199 | + return $tableau; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @return array|bool |
| 207 | 207 | */ |
| 208 | 208 | function inc_atom_to_array_dist($data) { |
| 209 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 209 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | 210 | |
| 211 | - return $rss_to_array($data); |
|
| 211 | + return $rss_to_array($data); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @return array|bool |
| 220 | 220 | */ |
| 221 | 221 | function inc_glob_to_array_dist($data) { |
| 222 | - $a = glob( |
|
| 223 | - $data, |
|
| 224 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | - ); |
|
| 222 | + $a = glob( |
|
| 223 | + $data, |
|
| 224 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - return $a ?: []; |
|
| 227 | + return $a ?: []; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | * @throws Exception |
| 236 | 236 | */ |
| 237 | 237 | function inc_yaml_to_array_dist($data) { |
| 238 | - include_spip('inc/yaml-mini'); |
|
| 239 | - if (!function_exists('yaml_decode')) { |
|
| 240 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 238 | + include_spip('inc/yaml-mini'); |
|
| 239 | + if (!function_exists('yaml_decode')) { |
|
| 240 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 241 | 241 | |
| 242 | - return false; |
|
| 243 | - } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return yaml_decode($data); |
|
| 245 | + return yaml_decode($data); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -269,23 +269,23 @@ discard block |
||
| 269 | 269 | * @return array|bool |
| 270 | 270 | */ |
| 271 | 271 | function inc_ls_to_array_dist($data) { |
| 272 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | - $a = $glob_to_array($data); |
|
| 274 | - foreach ($a as &$v) { |
|
| 275 | - $b = (array)@stat($v); |
|
| 276 | - foreach (array_keys($b) as $k) { |
|
| 277 | - if (is_numeric($k)) { |
|
| 278 | - unset($b[$k]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | - $v = array_merge( |
|
| 283 | - pathinfo((string) $v), |
|
| 284 | - $b |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $a; |
|
| 272 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | + $a = $glob_to_array($data); |
|
| 274 | + foreach ($a as &$v) { |
|
| 275 | + $b = (array)@stat($v); |
|
| 276 | + foreach (array_keys($b) as $k) { |
|
| 277 | + if (is_numeric($k)) { |
|
| 278 | + unset($b[$k]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | + $v = array_merge( |
|
| 283 | + pathinfo((string) $v), |
|
| 284 | + $b |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $a; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | * @return array|bool |
| 296 | 296 | */ |
| 297 | 297 | function XMLObjectToArray($object) { |
| 298 | - $xml_array = []; |
|
| 299 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | - $key .= '-' . uniqid(); |
|
| 302 | - } |
|
| 303 | - $vars = get_object_vars($object->current()); |
|
| 304 | - if (isset($vars['@attributes'])) { |
|
| 305 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | - $xml_array[$key][$k] = $v; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - $xml_array[$key][] = $object->hasChildren() |
|
| 310 | - ? XMLObjectToArray($object->current()) |
|
| 311 | - : (string) $object->current(); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $xml_array; |
|
| 298 | + $xml_array = []; |
|
| 299 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | + $key .= '-' . uniqid(); |
|
| 302 | + } |
|
| 303 | + $vars = get_object_vars($object->current()); |
|
| 304 | + if (isset($vars['@attributes'])) { |
|
| 305 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | + $xml_array[$key][$k] = $v; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + $xml_array[$key][] = $object->hasChildren() |
|
| 310 | + ? XMLObjectToArray($object->current()) |
|
| 311 | + : (string) $object->current(); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $xml_array; |
|
| 315 | 315 | } |
@@ -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 | /** |
@@ -32,117 +32,117 @@ discard block |
||
| 32 | 32 | **/ |
| 33 | 33 | function analyse_csv($t) { |
| 34 | 34 | |
| 35 | - // Quel est le séparateur ? |
|
| 36 | - $virg = substr_count($t, ','); |
|
| 37 | - $pvirg = substr_count($t, ';'); |
|
| 38 | - $tab = substr_count($t, "\t"); |
|
| 39 | - if ($virg > $pvirg) { |
|
| 40 | - $sep = ','; |
|
| 41 | - $hs = ','; |
|
| 42 | - } else { |
|
| 43 | - $sep = ';'; |
|
| 44 | - $hs = ';'; |
|
| 45 | - $virg = $pvirg; |
|
| 46 | - } |
|
| 47 | - // un certain nombre de tab => le séparateur est tab |
|
| 48 | - if ($tab > $virg / 10) { |
|
| 49 | - $sep = "\t"; |
|
| 50 | - $hs = "\t"; |
|
| 51 | - } |
|
| 35 | + // Quel est le séparateur ? |
|
| 36 | + $virg = substr_count($t, ','); |
|
| 37 | + $pvirg = substr_count($t, ';'); |
|
| 38 | + $tab = substr_count($t, "\t"); |
|
| 39 | + if ($virg > $pvirg) { |
|
| 40 | + $sep = ','; |
|
| 41 | + $hs = ','; |
|
| 42 | + } else { |
|
| 43 | + $sep = ';'; |
|
| 44 | + $hs = ';'; |
|
| 45 | + $virg = $pvirg; |
|
| 46 | + } |
|
| 47 | + // un certain nombre de tab => le séparateur est tab |
|
| 48 | + if ($tab > $virg / 10) { |
|
| 49 | + $sep = "\t"; |
|
| 50 | + $hs = "\t"; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // un separateur suivi de 3 guillemets attention ! |
|
| 54 | - // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | - // on substitue un # et on remplacera a la fin |
|
| 56 | - $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | - $t = str_replace('""', '"#', $t); |
|
| 58 | - preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | - foreach ($r[0] as $cell) { |
|
| 60 | - $t = str_replace( |
|
| 61 | - $cell, |
|
| 62 | - str_replace( |
|
| 63 | - $sep, |
|
| 64 | - $hs, |
|
| 65 | - str_replace( |
|
| 66 | - "\n", |
|
| 67 | - '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | - substr((string) $cell, 1, -1) |
|
| 69 | - ) |
|
| 70 | - ), |
|
| 71 | - $t |
|
| 72 | - ); |
|
| 73 | - } |
|
| 53 | + // un separateur suivi de 3 guillemets attention ! |
|
| 54 | + // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | + // on substitue un # et on remplacera a la fin |
|
| 56 | + $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | + $t = str_replace('""', '"#', $t); |
|
| 58 | + preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | + foreach ($r[0] as $cell) { |
|
| 60 | + $t = str_replace( |
|
| 61 | + $cell, |
|
| 62 | + str_replace( |
|
| 63 | + $sep, |
|
| 64 | + $hs, |
|
| 65 | + str_replace( |
|
| 66 | + "\n", |
|
| 67 | + '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | + substr((string) $cell, 1, -1) |
|
| 69 | + ) |
|
| 70 | + ), |
|
| 71 | + $t |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $t = preg_replace( |
|
| 76 | - '/\r?\n/', |
|
| 77 | - "\n", |
|
| 78 | - preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | - ); |
|
| 75 | + $t = preg_replace( |
|
| 76 | + '/\r?\n/', |
|
| 77 | + "\n", |
|
| 78 | + preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | + ); |
|
| 80 | 80 | |
| 81 | - [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | - $caption = ''; |
|
| 83 | - // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | - if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | - } |
|
| 87 | - // si une seule colonne, en faire le titre |
|
| 88 | - if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | - $caption = "\n||" . $l[1] . '|'; |
|
| 90 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | - } |
|
| 92 | - // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | - if ($entete[0] == $sep) { |
|
| 94 | - $entete = ' ' . $entete; |
|
| 95 | - } |
|
| 81 | + [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | + $caption = ''; |
|
| 83 | + // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | + if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | + } |
|
| 87 | + // si une seule colonne, en faire le titre |
|
| 88 | + if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | + $caption = "\n||" . $l[1] . '|'; |
|
| 90 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | + } |
|
| 92 | + // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | + if ($entete[0] == $sep) { |
|
| 94 | + $entete = ' ' . $entete; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $lignes = explode("\n", $corps); |
|
| 97 | + $lignes = explode("\n", $corps); |
|
| 98 | 98 | |
| 99 | - // retrait des lignes vides finales |
|
| 100 | - while ( |
|
| 101 | - $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | - ) { |
|
| 103 | - unset($lignes[count($lignes) - 1]); |
|
| 104 | - } |
|
| 105 | - // calcul du nombre de colonne a chaque ligne |
|
| 106 | - $nbcols = []; |
|
| 107 | - $max = $mil = substr_count($entete, $sep); |
|
| 108 | - foreach ($lignes as $k => $v) { |
|
| 109 | - if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | - if ($max > $nbcols[$k]) { |
|
| 111 | - $mil = $nbcols[$k]; |
|
| 112 | - } else { |
|
| 113 | - $mil = $max; |
|
| 114 | - $max = $nbcols[$k]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | - if ($mil !== $max) { |
|
| 120 | - foreach ($nbcols as $k => $v) { |
|
| 121 | - if ($v < $max) { |
|
| 122 | - $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - // et retirer les colonnes integralement vides |
|
| 127 | - while (true) { |
|
| 128 | - $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | - foreach ($lignes as $v) { |
|
| 130 | - $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | - } |
|
| 132 | - if (!$nbcols) { |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - $entete = substr($entete, 0, -1); |
|
| 136 | - foreach ($lignes as $k => $v) { |
|
| 137 | - $lignes[$k] = substr($v, 0, -1); |
|
| 138 | - } |
|
| 139 | - } |
|
| 99 | + // retrait des lignes vides finales |
|
| 100 | + while ( |
|
| 101 | + $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | + ) { |
|
| 103 | + unset($lignes[count($lignes) - 1]); |
|
| 104 | + } |
|
| 105 | + // calcul du nombre de colonne a chaque ligne |
|
| 106 | + $nbcols = []; |
|
| 107 | + $max = $mil = substr_count($entete, $sep); |
|
| 108 | + foreach ($lignes as $k => $v) { |
|
| 109 | + if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | + if ($max > $nbcols[$k]) { |
|
| 111 | + $mil = $nbcols[$k]; |
|
| 112 | + } else { |
|
| 113 | + $mil = $max; |
|
| 114 | + $max = $nbcols[$k]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | + if ($mil !== $max) { |
|
| 120 | + foreach ($nbcols as $k => $v) { |
|
| 121 | + if ($v < $max) { |
|
| 122 | + $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + // et retirer les colonnes integralement vides |
|
| 127 | + while (true) { |
|
| 128 | + $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | + foreach ($lignes as $v) { |
|
| 130 | + $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | + } |
|
| 132 | + if (!$nbcols) { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + $entete = substr($entete, 0, -1); |
|
| 136 | + foreach ($lignes as $k => $v) { |
|
| 137 | + $lignes[$k] = substr($v, 0, -1); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - foreach ($lignes as &$l) { |
|
| 142 | - $l = str_replace('"#', '"', $l); |
|
| 143 | - $l = str_replace('``**``', "\n", $l); |
|
| 144 | - $l = explode($sep, $l); |
|
| 145 | - } |
|
| 141 | + foreach ($lignes as &$l) { |
|
| 142 | + $l = str_replace('"#', '"', $l); |
|
| 143 | + $l = str_replace('``**``', "\n", $l); |
|
| 144 | + $l = explode($sep, $l); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return [explode($sep, $entete), $lignes, $caption]; |
|
| 147 | + return [explode($sep, $entete), $lignes, $caption]; |
|
| 148 | 148 | } |
@@ -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 | } |
@@ -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 | } |