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