@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('base/abstract_sql'); |
| 23 | 23 | |
@@ -59,56 +59,56 @@ discard block |
||
| 59 | 59 | * Retour des traitements. |
| 60 | 60 | **/ |
| 61 | 61 | function formulaires_editer_objet_traiter( |
| 62 | - $type, |
|
| 63 | - $id = 'new', |
|
| 64 | - $id_parent = 0, |
|
| 65 | - $lier_trad = 0, |
|
| 66 | - $retour = '', |
|
| 67 | - $config_fonc = 'articles_edit_config', |
|
| 68 | - $row = [], |
|
| 69 | - $hidden = '' |
|
| 62 | + $type, |
|
| 63 | + $id = 'new', |
|
| 64 | + $id_parent = 0, |
|
| 65 | + $lier_trad = 0, |
|
| 66 | + $retour = '', |
|
| 67 | + $config_fonc = 'articles_edit_config', |
|
| 68 | + $row = [], |
|
| 69 | + $hidden = '' |
|
| 70 | 70 | ) { |
| 71 | 71 | |
| 72 | - $res = []; |
|
| 73 | - // eviter la redirection forcee par l'action... |
|
| 74 | - set_request('redirect'); |
|
| 75 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | - [$id, $err] = $action_editer($id); |
|
| 77 | - } else { |
|
| 78 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | - [$id, $err] = $action_editer($id, $type); |
|
| 80 | - } |
|
| 81 | - $id_table_objet = id_table_objet($type); |
|
| 82 | - $res[$id_table_objet] = $id; |
|
| 83 | - if ($err or !$id) { |
|
| 84 | - $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 85 | - } else { |
|
| 86 | - // Un lien de trad a prendre en compte |
|
| 87 | - if ($lier_trad) { |
|
| 88 | - // referencer la traduction |
|
| 89 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | - if ($err) { |
|
| 95 | - $res['message_erreur'] = $err; |
|
| 96 | - return $res; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | - if ($retour) { |
|
| 102 | - if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | - $res['editable'] = true; |
|
| 105 | - } else { |
|
| 106 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $res; |
|
| 72 | + $res = []; |
|
| 73 | + // eviter la redirection forcee par l'action... |
|
| 74 | + set_request('redirect'); |
|
| 75 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | + [$id, $err] = $action_editer($id); |
|
| 77 | + } else { |
|
| 78 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | + [$id, $err] = $action_editer($id, $type); |
|
| 80 | + } |
|
| 81 | + $id_table_objet = id_table_objet($type); |
|
| 82 | + $res[$id_table_objet] = $id; |
|
| 83 | + if ($err or !$id) { |
|
| 84 | + $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 85 | + } else { |
|
| 86 | + // Un lien de trad a prendre en compte |
|
| 87 | + if ($lier_trad) { |
|
| 88 | + // referencer la traduction |
|
| 89 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | + if ($err) { |
|
| 95 | + $res['message_erreur'] = $err; |
|
| 96 | + return $res; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | + if ($retour) { |
|
| 102 | + if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | + $res['editable'] = true; |
|
| 105 | + } else { |
|
| 106 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $res; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -132,29 +132,29 @@ discard block |
||
| 132 | 132 | * Tableau des erreurs |
| 133 | 133 | **/ |
| 134 | 134 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) { |
| 135 | - $erreurs = []; |
|
| 136 | - if (intval($id)) { |
|
| 137 | - $conflits = controler_contenu($type, $id); |
|
| 138 | - if ($conflits and is_countable($conflits) ? count($conflits) : 0) { |
|
| 139 | - foreach ($conflits as $champ => $conflit) { |
|
| 140 | - if (!isset($erreurs[$champ])) { |
|
| 141 | - $erreurs[$champ] = ''; |
|
| 142 | - } |
|
| 143 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($oblis as $obli) { |
|
| 148 | - $value = _request($obli); |
|
| 149 | - if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | - if (!isset($erreurs[$obli])) { |
|
| 151 | - $erreurs[$obli] = ''; |
|
| 152 | - } |
|
| 153 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return $erreurs; |
|
| 135 | + $erreurs = []; |
|
| 136 | + if (intval($id)) { |
|
| 137 | + $conflits = controler_contenu($type, $id); |
|
| 138 | + if ($conflits and is_countable($conflits) ? count($conflits) : 0) { |
|
| 139 | + foreach ($conflits as $champ => $conflit) { |
|
| 140 | + if (!isset($erreurs[$champ])) { |
|
| 141 | + $erreurs[$champ] = ''; |
|
| 142 | + } |
|
| 143 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($oblis as $obli) { |
|
| 148 | + $value = _request($obli); |
|
| 149 | + if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | + if (!isset($erreurs[$obli])) { |
|
| 151 | + $erreurs[$obli] = ''; |
|
| 152 | + } |
|
| 153 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return $erreurs; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -199,152 +199,152 @@ discard block |
||
| 199 | 199 | * Environnement du formulaire. |
| 200 | 200 | **/ |
| 201 | 201 | function formulaires_editer_objet_charger( |
| 202 | - $type, |
|
| 203 | - $id = 'new', |
|
| 204 | - $id_parent = 0, |
|
| 205 | - $lier_trad = 0, |
|
| 206 | - $retour = '', |
|
| 207 | - $config_fonc = 'articles_edit_config', |
|
| 208 | - $row = [], |
|
| 209 | - $hidden = '' |
|
| 202 | + $type, |
|
| 203 | + $id = 'new', |
|
| 204 | + $id_parent = 0, |
|
| 205 | + $lier_trad = 0, |
|
| 206 | + $retour = '', |
|
| 207 | + $config_fonc = 'articles_edit_config', |
|
| 208 | + $row = [], |
|
| 209 | + $hidden = '' |
|
| 210 | 210 | ) { |
| 211 | 211 | |
| 212 | - $valeurs = []; |
|
| 213 | - $table_objet = table_objet($type); |
|
| 214 | - $table_objet_sql = table_objet_sql($type); |
|
| 215 | - $id_table_objet = id_table_objet($type); |
|
| 216 | - |
|
| 217 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 218 | - if ( |
|
| 219 | - $config_fonc |
|
| 220 | - and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 221 | - and $config_fonc !== $table_objet . '_edit_config' |
|
| 222 | - ) { |
|
| 223 | - if ( |
|
| 224 | - $args = test_formulaire_inclus_par_modele() |
|
| 225 | - and in_array($config_fonc, $args) |
|
| 226 | - ) { |
|
| 227 | - $config_fonc = ''; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $new = !is_numeric($id); |
|
| 232 | - $lang_default = ''; |
|
| 233 | - // Appel direct dans un squelette |
|
| 234 | - if (!$row) { |
|
| 235 | - if (!$new or $lier_trad) { |
|
| 236 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 237 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 238 | - // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 239 | - $lang_default = (!empty($row['lang']) ? $row['lang'] : null); |
|
| 240 | - } else { |
|
| 241 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 242 | - } |
|
| 243 | - if (!$new) { |
|
| 244 | - $md5 = controles_md5($row ?? []); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - if (!$row) { |
|
| 248 | - $row = []; |
|
| 249 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 250 | - if ($desc = $trouver_table($table_objet)) { |
|
| 251 | - foreach ($desc['field'] as $k => $v) { |
|
| 252 | - $row[$k] = ''; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 259 | - // (et donc: pas de lien de traduction) |
|
| 260 | - $id = ($new or $lier_trad) |
|
| 261 | - ? 'oui' |
|
| 262 | - : $row[$id_table_objet]; |
|
| 263 | - $row[$id_table_objet] = $id; |
|
| 264 | - |
|
| 265 | - $contexte = $row; |
|
| 266 | - if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 267 | - if (!isset($contexte['id_parent'])) { |
|
| 268 | - unset($contexte['id_rubrique']); |
|
| 269 | - } |
|
| 270 | - $contexte['id_parent'] = $id_parent; |
|
| 271 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 272 | - // id_rubrique dans id_parent si possible |
|
| 273 | - if (isset($contexte['id_rubrique'])) { |
|
| 274 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 275 | - unset($contexte['id_rubrique']); |
|
| 276 | - } else { |
|
| 277 | - $contexte['id_parent'] = ''; |
|
| 278 | - } |
|
| 279 | - if ( |
|
| 280 | - !$contexte['id_parent'] |
|
| 281 | - and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 282 | - ) { |
|
| 283 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $config = []; |
|
| 288 | - if ($config_fonc) { |
|
| 289 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 290 | - if (!$lang_default) { |
|
| 291 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - $config = $config + [ |
|
| 295 | - 'lignes' => 0, |
|
| 296 | - 'langue' => '', |
|
| 297 | - ]; |
|
| 298 | - |
|
| 299 | - $att_text = " class='textarea' " |
|
| 300 | - . " rows='" |
|
| 301 | - . ($config['lignes'] + 15) |
|
| 302 | - . "' cols='40'"; |
|
| 303 | - if (isset($contexte['texte'])) { |
|
| 304 | - [$contexte['texte'], $contexte['_texte_trop_long']] = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // on veut conserver la langue de l'interface ; |
|
| 308 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 309 | - // voudrait l'exploiter |
|
| 310 | - if (isset($contexte['lang'])) { |
|
| 311 | - $contexte['langue'] = $contexte['lang']; |
|
| 312 | - unset($contexte['lang']); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 316 | - (!$lier_trad ? '' : |
|
| 317 | - ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 318 | - $lier_trad . |
|
| 319 | - "' />" . |
|
| 320 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 321 | - $lang_default . |
|
| 322 | - "' />")) |
|
| 323 | - . $hidden |
|
| 324 | - . ($md5 ?? ''); |
|
| 325 | - |
|
| 326 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 327 | - $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 328 | - |
|
| 329 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 330 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 331 | - // on le garde pour compat |
|
| 332 | - $contexte['_action'] = ["editer_$type", $id]; |
|
| 333 | - |
|
| 334 | - // et in fine placer l'autorisation |
|
| 335 | - include_spip('inc/autoriser'); |
|
| 336 | - if (intval($id)) { |
|
| 337 | - if (!autoriser('modifier', $type, intval($id))) { |
|
| 338 | - $valeurs['editable'] = ''; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - else { |
|
| 342 | - if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 343 | - $valeurs['editable'] = ''; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $contexte; |
|
| 212 | + $valeurs = []; |
|
| 213 | + $table_objet = table_objet($type); |
|
| 214 | + $table_objet_sql = table_objet_sql($type); |
|
| 215 | + $id_table_objet = id_table_objet($type); |
|
| 216 | + |
|
| 217 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 218 | + if ( |
|
| 219 | + $config_fonc |
|
| 220 | + and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 221 | + and $config_fonc !== $table_objet . '_edit_config' |
|
| 222 | + ) { |
|
| 223 | + if ( |
|
| 224 | + $args = test_formulaire_inclus_par_modele() |
|
| 225 | + and in_array($config_fonc, $args) |
|
| 226 | + ) { |
|
| 227 | + $config_fonc = ''; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $new = !is_numeric($id); |
|
| 232 | + $lang_default = ''; |
|
| 233 | + // Appel direct dans un squelette |
|
| 234 | + if (!$row) { |
|
| 235 | + if (!$new or $lier_trad) { |
|
| 236 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 237 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 238 | + // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 239 | + $lang_default = (!empty($row['lang']) ? $row['lang'] : null); |
|
| 240 | + } else { |
|
| 241 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 242 | + } |
|
| 243 | + if (!$new) { |
|
| 244 | + $md5 = controles_md5($row ?? []); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + if (!$row) { |
|
| 248 | + $row = []; |
|
| 249 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 250 | + if ($desc = $trouver_table($table_objet)) { |
|
| 251 | + foreach ($desc['field'] as $k => $v) { |
|
| 252 | + $row[$k] = ''; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 259 | + // (et donc: pas de lien de traduction) |
|
| 260 | + $id = ($new or $lier_trad) |
|
| 261 | + ? 'oui' |
|
| 262 | + : $row[$id_table_objet]; |
|
| 263 | + $row[$id_table_objet] = $id; |
|
| 264 | + |
|
| 265 | + $contexte = $row; |
|
| 266 | + if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 267 | + if (!isset($contexte['id_parent'])) { |
|
| 268 | + unset($contexte['id_rubrique']); |
|
| 269 | + } |
|
| 270 | + $contexte['id_parent'] = $id_parent; |
|
| 271 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 272 | + // id_rubrique dans id_parent si possible |
|
| 273 | + if (isset($contexte['id_rubrique'])) { |
|
| 274 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 275 | + unset($contexte['id_rubrique']); |
|
| 276 | + } else { |
|
| 277 | + $contexte['id_parent'] = ''; |
|
| 278 | + } |
|
| 279 | + if ( |
|
| 280 | + !$contexte['id_parent'] |
|
| 281 | + and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 282 | + ) { |
|
| 283 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $config = []; |
|
| 288 | + if ($config_fonc) { |
|
| 289 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 290 | + if (!$lang_default) { |
|
| 291 | + $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + $config = $config + [ |
|
| 295 | + 'lignes' => 0, |
|
| 296 | + 'langue' => '', |
|
| 297 | + ]; |
|
| 298 | + |
|
| 299 | + $att_text = " class='textarea' " |
|
| 300 | + . " rows='" |
|
| 301 | + . ($config['lignes'] + 15) |
|
| 302 | + . "' cols='40'"; |
|
| 303 | + if (isset($contexte['texte'])) { |
|
| 304 | + [$contexte['texte'], $contexte['_texte_trop_long']] = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // on veut conserver la langue de l'interface ; |
|
| 308 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 309 | + // voudrait l'exploiter |
|
| 310 | + if (isset($contexte['lang'])) { |
|
| 311 | + $contexte['langue'] = $contexte['lang']; |
|
| 312 | + unset($contexte['lang']); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 316 | + (!$lier_trad ? '' : |
|
| 317 | + ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 318 | + $lier_trad . |
|
| 319 | + "' />" . |
|
| 320 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 321 | + $lang_default . |
|
| 322 | + "' />")) |
|
| 323 | + . $hidden |
|
| 324 | + . ($md5 ?? ''); |
|
| 325 | + |
|
| 326 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 327 | + $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 328 | + |
|
| 329 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 330 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 331 | + // on le garde pour compat |
|
| 332 | + $contexte['_action'] = ["editer_$type", $id]; |
|
| 333 | + |
|
| 334 | + // et in fine placer l'autorisation |
|
| 335 | + include_spip('inc/autoriser'); |
|
| 336 | + if (intval($id)) { |
|
| 337 | + if (!autoriser('modifier', $type, intval($id))) { |
|
| 338 | + $valeurs['editable'] = ''; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + else { |
|
| 342 | + if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 343 | + $valeurs['editable'] = ''; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $contexte; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -355,29 +355,29 @@ discard block |
||
| 355 | 355 | * @return array |
| 356 | 356 | */ |
| 357 | 357 | function coupe_trop_long($texte) { |
| 358 | - $aider = charger_fonction('aider', 'inc'); |
|
| 359 | - if (strlen($texte) > 28 * 1024) { |
|
| 360 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 361 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 362 | - if ($pos > 0 and $pos < 32 * 1024) { |
|
| 363 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 364 | - $suite = substr($texte, $pos + 2); |
|
| 365 | - } else { |
|
| 366 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 367 | - if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 368 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 369 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 370 | - } else { |
|
| 371 | - $decalage = 1; |
|
| 372 | - } |
|
| 373 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 374 | - $suite = substr($texte, $pos + $decalage); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return ([$debut, $suite]); |
|
| 378 | - } else { |
|
| 379 | - return ([$texte, '']); |
|
| 380 | - } |
|
| 358 | + $aider = charger_fonction('aider', 'inc'); |
|
| 359 | + if (strlen($texte) > 28 * 1024) { |
|
| 360 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 361 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 362 | + if ($pos > 0 and $pos < 32 * 1024) { |
|
| 363 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 364 | + $suite = substr($texte, $pos + 2); |
|
| 365 | + } else { |
|
| 366 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 367 | + if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 368 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 369 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 370 | + } else { |
|
| 371 | + $decalage = 1; |
|
| 372 | + } |
|
| 373 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 374 | + $suite = substr($texte, $pos + $decalage); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return ([$debut, $suite]); |
|
| 378 | + } else { |
|
| 379 | + return ([$texte, '']); |
|
| 380 | + } |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * @return array |
| 389 | 389 | */ |
| 390 | 390 | function editer_texte_recolle($texte, $att_text) { |
| 391 | - if ( |
|
| 392 | - (strlen($texte) < 29 * 1024) |
|
| 393 | - or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 394 | - ) { |
|
| 395 | - return [$texte, '']; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - include_spip('inc/barre'); |
|
| 399 | - $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 400 | - $nombre = 0; |
|
| 401 | - |
|
| 402 | - while (strlen($texte) > 29 * 1024) { |
|
| 403 | - $nombre++; |
|
| 404 | - [$texte1, $texte] = coupe_trop_long($texte); |
|
| 405 | - $textes_supplement .= '<br />' . |
|
| 406 | - "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return [$texte, $textes_supplement]; |
|
| 391 | + if ( |
|
| 392 | + (strlen($texte) < 29 * 1024) |
|
| 393 | + or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 394 | + ) { |
|
| 395 | + return [$texte, '']; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + include_spip('inc/barre'); |
|
| 399 | + $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 400 | + $nombre = 0; |
|
| 401 | + |
|
| 402 | + while (strlen($texte) > 29 * 1024) { |
|
| 403 | + $nombre++; |
|
| 404 | + [$texte1, $texte] = coupe_trop_long($texte); |
|
| 405 | + $textes_supplement .= '<br />' . |
|
| 406 | + "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return [$texte, $textes_supplement]; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,17 +417,17 @@ discard block |
||
| 417 | 417 | * @param int $longueur |
| 418 | 418 | */ |
| 419 | 419 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 420 | - if (!_request($champ_titre)) { |
|
| 421 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 422 | - if (!is_null($longueur)) { |
|
| 423 | - $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 424 | - } else { |
|
| 425 | - $t = $titrer_contenu($champs_contenu); |
|
| 426 | - } |
|
| 427 | - if ($t) { |
|
| 428 | - set_request($champ_titre, $t); |
|
| 429 | - } |
|
| 430 | - } |
|
| 420 | + if (!_request($champ_titre)) { |
|
| 421 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 422 | + if (!is_null($longueur)) { |
|
| 423 | + $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 424 | + } else { |
|
| 425 | + $t = $titrer_contenu($champs_contenu); |
|
| 426 | + } |
|
| 427 | + if ($t) { |
|
| 428 | + set_request($champ_titre, $t); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -447,20 +447,20 @@ discard block |
||
| 447 | 447 | * @return string |
| 448 | 448 | */ |
| 449 | 449 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 450 | - // trouver un champ texte non vide |
|
| 451 | - $t = ''; |
|
| 452 | - foreach ($champs_contenu as $champ) { |
|
| 453 | - if ($t = _request($champ, $c)) { |
|
| 454 | - break; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - if ($t) { |
|
| 459 | - include_spip('inc/texte_mini'); |
|
| 460 | - $t = couper($t, $longueur, '...'); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - return $t; |
|
| 450 | + // trouver un champ texte non vide |
|
| 451 | + $t = ''; |
|
| 452 | + foreach ($champs_contenu as $champ) { |
|
| 453 | + if ($t = _request($champ, $c)) { |
|
| 454 | + break; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + if ($t) { |
|
| 459 | + include_spip('inc/texte_mini'); |
|
| 460 | + $t = couper($t, $longueur, '...'); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + return $t; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -482,26 +482,26 @@ discard block |
||
| 482 | 482 | * - array sinon couples ('$prefixe$colonne => md5) |
| 483 | 483 | **/ |
| 484 | 484 | function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') { |
| 485 | - $ctr = []; |
|
| 486 | - foreach ($data as $key => $val) { |
|
| 487 | - $m = md5($val ?? ''); |
|
| 488 | - $k = $prefixe . $key; |
|
| 489 | - |
|
| 490 | - switch ($format) { |
|
| 491 | - case 'html': |
|
| 492 | - $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 493 | - break; |
|
| 494 | - default: |
|
| 495 | - $ctr[$k] = $m; |
|
| 496 | - break; |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - if ($format === 'html') { |
|
| 501 | - return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 502 | - } else { |
|
| 503 | - return $ctr; |
|
| 504 | - } |
|
| 485 | + $ctr = []; |
|
| 486 | + foreach ($data as $key => $val) { |
|
| 487 | + $m = md5($val ?? ''); |
|
| 488 | + $k = $prefixe . $key; |
|
| 489 | + |
|
| 490 | + switch ($format) { |
|
| 491 | + case 'html': |
|
| 492 | + $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 493 | + break; |
|
| 494 | + default: |
|
| 495 | + $ctr[$k] = $m; |
|
| 496 | + break; |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + if ($format === 'html') { |
|
| 501 | + return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 502 | + } else { |
|
| 503 | + return $ctr; |
|
| 504 | + } |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -540,80 +540,80 @@ discard block |
||
| 540 | 540 | * - post : le contenu posté |
| 541 | 541 | **/ |
| 542 | 542 | function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') { |
| 543 | - include_spip('inc/filtres'); |
|
| 544 | - |
|
| 545 | - $table_objet = table_objet($type); |
|
| 546 | - $spip_table_objet = table_objet_sql($type); |
|
| 547 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 549 | - |
|
| 550 | - // Appels incomplets (sans $c) |
|
| 551 | - if (!is_array($c)) { |
|
| 552 | - $c = []; |
|
| 553 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 554 | - if (_request($champ)) { |
|
| 555 | - $c[$champ] = _request($champ); |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 561 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 562 | - // il faut passer par instituer_XX() |
|
| 563 | - // TODO: faut-il passer ces variables interdites |
|
| 564 | - // dans un fichier de description separe ? |
|
| 565 | - unset($c['statut']); |
|
| 566 | - unset($c['id_parent']); |
|
| 567 | - unset($c['id_rubrique']); |
|
| 568 | - unset($c['id_secteur']); |
|
| 569 | - |
|
| 570 | - // Gerer les champs non vides |
|
| 571 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 572 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 573 | - if ($c[$champ] === '') { |
|
| 574 | - $c[$champ] = $sinon; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // N'accepter que les champs qui existent |
|
| 580 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 581 | - $champs = []; |
|
| 582 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 583 | - if (isset($c[$champ])) { |
|
| 584 | - $champs[$champ] = $c[$champ]; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - // Nettoyer les valeurs |
|
| 589 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 590 | - |
|
| 591 | - // Envoyer aux plugins |
|
| 592 | - $champs = pipeline( |
|
| 593 | - 'pre_edition', |
|
| 594 | - [ |
|
| 595 | - 'args' => [ |
|
| 596 | - 'table' => $spip_table_objet, // compatibilite |
|
| 597 | - 'table_objet' => $table_objet, |
|
| 598 | - 'spip_table_objet' => $spip_table_objet, |
|
| 599 | - 'type' => $type, |
|
| 600 | - 'id_objet' => $id, |
|
| 601 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 602 | - 'action' => 'controler', |
|
| 603 | - 'serveur' => $serveur, |
|
| 604 | - ], |
|
| 605 | - 'data' => $champs |
|
| 606 | - ] |
|
| 607 | - ); |
|
| 608 | - |
|
| 609 | - if (!$champs) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 614 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 615 | - |
|
| 616 | - return $conflits; |
|
| 543 | + include_spip('inc/filtres'); |
|
| 544 | + |
|
| 545 | + $table_objet = table_objet($type); |
|
| 546 | + $spip_table_objet = table_objet_sql($type); |
|
| 547 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 549 | + |
|
| 550 | + // Appels incomplets (sans $c) |
|
| 551 | + if (!is_array($c)) { |
|
| 552 | + $c = []; |
|
| 553 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 554 | + if (_request($champ)) { |
|
| 555 | + $c[$champ] = _request($champ); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 561 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 562 | + // il faut passer par instituer_XX() |
|
| 563 | + // TODO: faut-il passer ces variables interdites |
|
| 564 | + // dans un fichier de description separe ? |
|
| 565 | + unset($c['statut']); |
|
| 566 | + unset($c['id_parent']); |
|
| 567 | + unset($c['id_rubrique']); |
|
| 568 | + unset($c['id_secteur']); |
|
| 569 | + |
|
| 570 | + // Gerer les champs non vides |
|
| 571 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 572 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 573 | + if ($c[$champ] === '') { |
|
| 574 | + $c[$champ] = $sinon; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // N'accepter que les champs qui existent |
|
| 580 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 581 | + $champs = []; |
|
| 582 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 583 | + if (isset($c[$champ])) { |
|
| 584 | + $champs[$champ] = $c[$champ]; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + // Nettoyer les valeurs |
|
| 589 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 590 | + |
|
| 591 | + // Envoyer aux plugins |
|
| 592 | + $champs = pipeline( |
|
| 593 | + 'pre_edition', |
|
| 594 | + [ |
|
| 595 | + 'args' => [ |
|
| 596 | + 'table' => $spip_table_objet, // compatibilite |
|
| 597 | + 'table_objet' => $table_objet, |
|
| 598 | + 'spip_table_objet' => $spip_table_objet, |
|
| 599 | + 'type' => $type, |
|
| 600 | + 'id_objet' => $id, |
|
| 601 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 602 | + 'action' => 'controler', |
|
| 603 | + 'serveur' => $serveur, |
|
| 604 | + ], |
|
| 605 | + 'data' => $champs |
|
| 606 | + ] |
|
| 607 | + ); |
|
| 608 | + |
|
| 609 | + if (!$champs) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 614 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 615 | + |
|
| 616 | + return $conflits; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
@@ -643,64 +643,64 @@ discard block |
||
| 643 | 643 | * - post : le contenu posté |
| 644 | 644 | **/ |
| 645 | 645 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 646 | - $spip_table_objet = table_objet_sql($type); |
|
| 647 | - $id_table_objet = id_table_objet($type); |
|
| 648 | - |
|
| 649 | - // Controle des MD5 envoyes |
|
| 650 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 651 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 652 | - foreach ($champs as $key => $val) { |
|
| 653 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 654 | - if (is_scalar($val) and $m == md5($val)) { |
|
| 655 | - unset($champs[$key]); |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - if (!$champs) { |
|
| 660 | - return; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - // On veut savoir si notre modif va avoir un impact |
|
| 664 | - // par rapport aux donnees contenues dans la base |
|
| 665 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 666 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 667 | - $intact = true; |
|
| 668 | - foreach ($champs as $ch => $val) { |
|
| 669 | - $intact &= ($s[$ch] == $val); |
|
| 670 | - } |
|
| 671 | - if ($intact) { |
|
| 672 | - return; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - // Detection de conflits : |
|
| 676 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 677 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 678 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 679 | - // de conflit. |
|
| 680 | - $ctrh = $ctrq = $conflits = []; |
|
| 681 | - foreach (array_keys($champs) as $key) { |
|
| 682 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 683 | - $ctrh[$key] = $m; |
|
| 684 | - $ctrq[] = $key; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - if ($ctrq) { |
|
| 688 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 689 | - foreach ($ctrh as $key => $m) { |
|
| 690 | - if ( |
|
| 691 | - $m != md5($ctrq[$key]) |
|
| 692 | - and $champs[$key] !== $ctrq[$key] |
|
| 693 | - ) { |
|
| 694 | - $conflits[$key] = [ |
|
| 695 | - 'base' => $ctrq[$key], |
|
| 696 | - 'post' => $champs[$key] |
|
| 697 | - ]; |
|
| 698 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - return $conflits; |
|
| 646 | + $spip_table_objet = table_objet_sql($type); |
|
| 647 | + $id_table_objet = id_table_objet($type); |
|
| 648 | + |
|
| 649 | + // Controle des MD5 envoyes |
|
| 650 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 651 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 652 | + foreach ($champs as $key => $val) { |
|
| 653 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 654 | + if (is_scalar($val) and $m == md5($val)) { |
|
| 655 | + unset($champs[$key]); |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + if (!$champs) { |
|
| 660 | + return; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + // On veut savoir si notre modif va avoir un impact |
|
| 664 | + // par rapport aux donnees contenues dans la base |
|
| 665 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 666 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 667 | + $intact = true; |
|
| 668 | + foreach ($champs as $ch => $val) { |
|
| 669 | + $intact &= ($s[$ch] == $val); |
|
| 670 | + } |
|
| 671 | + if ($intact) { |
|
| 672 | + return; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + // Detection de conflits : |
|
| 676 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 677 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 678 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 679 | + // de conflit. |
|
| 680 | + $ctrh = $ctrq = $conflits = []; |
|
| 681 | + foreach (array_keys($champs) as $key) { |
|
| 682 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 683 | + $ctrh[$key] = $m; |
|
| 684 | + $ctrq[] = $key; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + if ($ctrq) { |
|
| 688 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 689 | + foreach ($ctrh as $key => $m) { |
|
| 690 | + if ( |
|
| 691 | + $m != md5($ctrq[$key]) |
|
| 692 | + and $champs[$key] !== $ctrq[$key] |
|
| 693 | + ) { |
|
| 694 | + $conflits[$key] = [ |
|
| 695 | + 'base' => $ctrq[$key], |
|
| 696 | + 'post' => $champs[$key] |
|
| 697 | + ]; |
|
| 698 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + return $conflits; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
@@ -712,11 +712,11 @@ discard block |
||
| 712 | 712 | * @return string |
| 713 | 713 | */ |
| 714 | 714 | function display_conflit_champ($x) { |
| 715 | - if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 716 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 717 | - } else { |
|
| 718 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 719 | - } |
|
| 715 | + if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 716 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 717 | + } else { |
|
| 718 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 719 | + } |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -734,57 +734,57 @@ discard block |
||
| 734 | 734 | * @return string |
| 735 | 735 | */ |
| 736 | 736 | function signaler_conflits_edition($conflits, $redirect = '') { |
| 737 | - include_spip('inc/minipres'); |
|
| 738 | - include_spip('inc/revisions'); |
|
| 739 | - include_spip('afficher_diff/champ'); |
|
| 740 | - include_spip('inc/suivi_versions'); |
|
| 741 | - include_spip('inc/diff'); |
|
| 742 | - $diffs = []; |
|
| 743 | - foreach ($conflits as $champ => $a) { |
|
| 744 | - // probleme de stockage ou conflit d'edition ? |
|
| 745 | - $base = $a['save'] ?? $a['base']; |
|
| 746 | - |
|
| 747 | - $diff = new Diff(new DiffTexte()); |
|
| 748 | - $n = preparer_diff($a['post']); |
|
| 749 | - $o = preparer_diff($base); |
|
| 750 | - $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 751 | - |
|
| 752 | - $titre = isset($a['save']) ? _L( |
|
| 753 | - 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 754 | - ['champ' => $champ] |
|
| 755 | - ) : $champ; |
|
| 756 | - |
|
| 757 | - $diffs[] = "<h2>$titre</h2>\n" |
|
| 758 | - . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 759 | - . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 760 | - . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 761 | - . display_conflit_champ($a['post']) |
|
| 762 | - . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 763 | - . display_conflit_champ($base); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - if ($redirect) { |
|
| 767 | - $id = uniqid(random_int(0, mt_getrandmax())); |
|
| 768 | - $redirect = "<form action='$redirect' method='get' |
|
| 737 | + include_spip('inc/minipres'); |
|
| 738 | + include_spip('inc/revisions'); |
|
| 739 | + include_spip('afficher_diff/champ'); |
|
| 740 | + include_spip('inc/suivi_versions'); |
|
| 741 | + include_spip('inc/diff'); |
|
| 742 | + $diffs = []; |
|
| 743 | + foreach ($conflits as $champ => $a) { |
|
| 744 | + // probleme de stockage ou conflit d'edition ? |
|
| 745 | + $base = $a['save'] ?? $a['base']; |
|
| 746 | + |
|
| 747 | + $diff = new Diff(new DiffTexte()); |
|
| 748 | + $n = preparer_diff($a['post']); |
|
| 749 | + $o = preparer_diff($base); |
|
| 750 | + $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 751 | + |
|
| 752 | + $titre = isset($a['save']) ? _L( |
|
| 753 | + 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 754 | + ['champ' => $champ] |
|
| 755 | + ) : $champ; |
|
| 756 | + |
|
| 757 | + $diffs[] = "<h2>$titre</h2>\n" |
|
| 758 | + . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 759 | + . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 760 | + . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 761 | + . display_conflit_champ($a['post']) |
|
| 762 | + . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 763 | + . display_conflit_champ($base); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + if ($redirect) { |
|
| 767 | + $id = uniqid(random_int(0, mt_getrandmax())); |
|
| 768 | + $redirect = "<form action='$redirect' method='get' |
|
| 769 | 769 | id='$id' |
| 770 | 770 | style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n" |
| 771 | - . form_hidden($redirect) |
|
| 772 | - . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 771 | + . form_hidden($redirect) |
|
| 772 | + . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 773 | 773 | </form>\n"; |
| 774 | 774 | |
| 775 | - // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 776 | - if (_AJAX) { |
|
| 777 | - $redirect .= '<script type="text/javascript">' |
|
| 778 | - . 'setTimeout(function(){$("#' . $id . '") |
|
| 775 | + // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 776 | + if (_AJAX) { |
|
| 777 | + $redirect .= '<script type="text/javascript">' |
|
| 778 | + . 'setTimeout(function(){$("#' . $id . '") |
|
| 779 | 779 | .ajaxForm({target:$("#' . $id . '").parent()}); |
| 780 | 780 | }, 200);' |
| 781 | - . "</script>\n"; |
|
| 782 | - } |
|
| 783 | - } |
|
| 781 | + . "</script>\n"; |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | 784 | |
| 785 | - echo minipres( |
|
| 786 | - _T('titre_conflit_edition'), |
|
| 787 | - '<style> |
|
| 785 | + echo minipres( |
|
| 786 | + _T('titre_conflit_edition'), |
|
| 787 | + '<style> |
|
| 788 | 788 | .diff-para-deplace { background: #e8e8ff; } |
| 789 | 789 | .diff-para-ajoute { background: #d0ffc0; color: #000; } |
| 790 | 790 | .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; } |
@@ -795,12 +795,12 @@ discard block |
||
| 795 | 795 | .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; } |
| 796 | 796 | .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; } |
| 797 | 797 | </style>' |
| 798 | - . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 799 | - . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 800 | - . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 801 | - . join("\n", $diffs) |
|
| 802 | - . "</div>\n" |
|
| 803 | - |
|
| 804 | - . $redirect |
|
| 805 | - ); |
|
| 798 | + . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 799 | + . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 800 | + . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 801 | + . join("\n", $diffs) |
|
| 802 | + . "</div>\n" |
|
| 803 | + |
|
| 804 | + . $redirect |
|
| 805 | + ); |
|
| 806 | 806 | } |