@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -32,36 +32,36 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 34 | 34 | |
| 35 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 36 | - if (is_null($id) || is_null($objet)) { |
|
| 37 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | - $arg = $securiser_action(); |
|
| 39 | - [$objet, $id] = array_pad(explode('/', (string) $arg, 2), 2, null); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 43 | - if (is_null($id) || is_null($objet)) { |
|
| 44 | - include_spip('inc/minipres'); |
|
| 45 | - echo minipres(_T('info_acces_interdit')); |
|
| 46 | - die(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // si id n'est pas un nombre, c'est une creation |
|
| 50 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | - if (!$id = (int) $id) { |
|
| 52 | - // on ne sait pas si un parent existe mais on essaye |
|
| 53 | - $id_parent = _request('id_parent'); |
|
| 54 | - $id = objet_inserer($objet, $id_parent); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if (!($id = (int) $id) > 0) { |
|
| 58 | - return [$id, _L('echec enregistrement en base')]; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Enregistre l'envoi dans la BD |
|
| 62 | - $err = objet_modifier($objet, $id, $set); |
|
| 63 | - |
|
| 64 | - return [$id, $err]; |
|
| 35 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 36 | + if (is_null($id) || is_null($objet)) { |
|
| 37 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | + $arg = $securiser_action(); |
|
| 39 | + [$objet, $id] = array_pad(explode('/', (string) $arg, 2), 2, null); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 43 | + if (is_null($id) || is_null($objet)) { |
|
| 44 | + include_spip('inc/minipres'); |
|
| 45 | + echo minipres(_T('info_acces_interdit')); |
|
| 46 | + die(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // si id n'est pas un nombre, c'est une creation |
|
| 50 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | + if (!$id = (int) $id) { |
|
| 52 | + // on ne sait pas si un parent existe mais on essaye |
|
| 53 | + $id_parent = _request('id_parent'); |
|
| 54 | + $id = objet_inserer($objet, $id_parent); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if (!($id = (int) $id) > 0) { |
|
| 58 | + return [$id, _L('echec enregistrement en base')]; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Enregistre l'envoi dans la BD |
|
| 62 | + $err = objet_modifier($objet, $id, $set); |
|
| 63 | + |
|
| 64 | + return [$id, $err]; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -90,83 +90,83 @@ discard block |
||
| 90 | 90 | * - En cas d'erreur : (string) message d'erreur |
| 91 | 91 | */ |
| 92 | 92 | function objet_modifier($objet, $id, $set = null) { |
| 93 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 94 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 95 | - $objet = $t; |
|
| 96 | - } |
|
| 97 | - if ( |
|
| 98 | - include_spip('action/editer_' . $objet) && function_exists($modifier = $objet . '_modifier') |
|
| 99 | - ) { |
|
| 100 | - return $modifier($id, $set); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $table_sql = table_objet_sql($objet); |
|
| 104 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 105 | - $desc = $trouver_table($table_sql); |
|
| 106 | - if (!$desc || !isset($desc['field'])) { |
|
| 107 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 108 | - |
|
| 109 | - return _L("Erreur objet $objet inconnu"); |
|
| 110 | - } |
|
| 111 | - include_spip('inc/modifier'); |
|
| 112 | - |
|
| 113 | - $champ_date = ''; |
|
| 114 | - if (isset($desc['date']) && $desc['date']) { |
|
| 115 | - $champ_date = $desc['date']; |
|
| 116 | - } elseif (isset($desc['field']['date'])) { |
|
| 117 | - $champ_date = 'date'; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $include_list = array_keys($desc['field']); |
|
| 121 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 122 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 123 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 124 | - |
|
| 125 | - if (isset($desc['champs_editables']) && is_array($desc['champs_editables'])) { |
|
| 126 | - $include_list = $desc['champs_editables']; |
|
| 127 | - } |
|
| 128 | - $c = collecter_requests( |
|
| 129 | - // include list |
|
| 130 | - $include_list, |
|
| 131 | - // exclude list |
|
| 132 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 133 | - // donnees eventuellement fournies |
|
| 134 | - $set |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 138 | - if (objet_test_si_publie($objet, $id)) { |
|
| 139 | - $invalideur = "id='$objet/$id'"; |
|
| 140 | - $indexation = true; |
|
| 141 | - } else { |
|
| 142 | - $invalideur = ''; |
|
| 143 | - $indexation = false; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ( |
|
| 147 | - $err = objet_modifier_champs( |
|
| 148 | - $objet, |
|
| 149 | - $id, |
|
| 150 | - [ |
|
| 151 | - 'data' => $set, |
|
| 152 | - 'nonvide' => '', |
|
| 153 | - 'invalideur' => $invalideur, |
|
| 154 | - 'indexation' => $indexation, |
|
| 155 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 156 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 157 | - ], |
|
| 158 | - $c |
|
| 159 | - ) |
|
| 160 | - ) { |
|
| 161 | - return $err; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // Modification de statut, changement de rubrique ? |
|
| 165 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 166 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 167 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 168 | - |
|
| 169 | - return objet_instituer($objet, $id, $c); |
|
| 93 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 94 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 95 | + $objet = $t; |
|
| 96 | + } |
|
| 97 | + if ( |
|
| 98 | + include_spip('action/editer_' . $objet) && function_exists($modifier = $objet . '_modifier') |
|
| 99 | + ) { |
|
| 100 | + return $modifier($id, $set); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $table_sql = table_objet_sql($objet); |
|
| 104 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 105 | + $desc = $trouver_table($table_sql); |
|
| 106 | + if (!$desc || !isset($desc['field'])) { |
|
| 107 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 108 | + |
|
| 109 | + return _L("Erreur objet $objet inconnu"); |
|
| 110 | + } |
|
| 111 | + include_spip('inc/modifier'); |
|
| 112 | + |
|
| 113 | + $champ_date = ''; |
|
| 114 | + if (isset($desc['date']) && $desc['date']) { |
|
| 115 | + $champ_date = $desc['date']; |
|
| 116 | + } elseif (isset($desc['field']['date'])) { |
|
| 117 | + $champ_date = 'date'; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $include_list = array_keys($desc['field']); |
|
| 121 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 122 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 123 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 124 | + |
|
| 125 | + if (isset($desc['champs_editables']) && is_array($desc['champs_editables'])) { |
|
| 126 | + $include_list = $desc['champs_editables']; |
|
| 127 | + } |
|
| 128 | + $c = collecter_requests( |
|
| 129 | + // include list |
|
| 130 | + $include_list, |
|
| 131 | + // exclude list |
|
| 132 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 133 | + // donnees eventuellement fournies |
|
| 134 | + $set |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 138 | + if (objet_test_si_publie($objet, $id)) { |
|
| 139 | + $invalideur = "id='$objet/$id'"; |
|
| 140 | + $indexation = true; |
|
| 141 | + } else { |
|
| 142 | + $invalideur = ''; |
|
| 143 | + $indexation = false; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ( |
|
| 147 | + $err = objet_modifier_champs( |
|
| 148 | + $objet, |
|
| 149 | + $id, |
|
| 150 | + [ |
|
| 151 | + 'data' => $set, |
|
| 152 | + 'nonvide' => '', |
|
| 153 | + 'invalideur' => $invalideur, |
|
| 154 | + 'indexation' => $indexation, |
|
| 155 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 156 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 157 | + ], |
|
| 158 | + $c |
|
| 159 | + ) |
|
| 160 | + ) { |
|
| 161 | + return $err; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // Modification de statut, changement de rubrique ? |
|
| 165 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 166 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 167 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 168 | + |
|
| 169 | + return objet_instituer($objet, $id, $c); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -197,154 +197,154 @@ discard block |
||
| 197 | 197 | * - (int) 0 si le type d'objet n'existe pas ou que la table est mal déclarée |
| 198 | 198 | */ |
| 199 | 199 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 200 | - $d = null; |
|
| 201 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 202 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 203 | - $objet = $t; |
|
| 204 | - } |
|
| 205 | - if ( |
|
| 206 | - include_spip('action/editer_' . $objet) |
|
| 207 | - && function_exists($inserer = $objet . '_inserer') |
|
| 208 | - ) { |
|
| 209 | - return $inserer($id_parent, $set); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $table_sql = table_objet_sql($objet); |
|
| 213 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 214 | - $desc = $trouver_table($table_sql); |
|
| 215 | - if (!$desc || !isset($desc['field'])) { |
|
| 216 | - return 0; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $lang_rub = ''; |
|
| 220 | - $champs = []; |
|
| 221 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 222 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 223 | - // dans la premiere rubrique racine |
|
| 224 | - if (!$id_rubrique = (int) $id_parent) { |
|
| 225 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 226 | - $id_rubrique = $row['id_rubrique']; |
|
| 227 | - } else { |
|
| 228 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 232 | - if (isset($desc['field']['id_secteur'])) { |
|
| 233 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 234 | - } |
|
| 235 | - $lang_rub = $row['lang']; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 239 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 240 | - // ou a defaut celle de la rubrique |
|
| 241 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 242 | - if ( |
|
| 243 | - isset($desc['field']['lang']) && !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 244 | - $table_sql, |
|
| 245 | - explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 246 | - ) |
|
| 247 | - ) { |
|
| 248 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? ''); |
|
| 249 | - if ( |
|
| 250 | - in_array( |
|
| 251 | - $GLOBALS['spip_lang'], |
|
| 252 | - explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 253 | - ) |
|
| 254 | - ) { |
|
| 255 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 256 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 257 | - $champs['langue_choisie'] = 'oui'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } elseif (isset($desc['field']['lang']) && isset($desc['field']['langue_choisie'])) { |
|
| 261 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 262 | - $champs['langue_choisie'] = 'non'; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if (isset($desc['field']['statut'])) { |
|
| 266 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 267 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 268 | - $champs['statut'] = reset($cles_statut); |
|
| 269 | - } else { |
|
| 270 | - $champs['statut'] = 'prepa'; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - if (isset($desc['date']) && ($d = $desc['date']) || isset($desc['field'][$d = 'date'])) { |
|
| 276 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if ($set) { |
|
| 280 | - $champs = array_merge($champs, $set); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Envoyer aux plugins |
|
| 284 | - $champs = pipeline( |
|
| 285 | - 'pre_insertion', |
|
| 286 | - [ |
|
| 287 | - 'args' => [ |
|
| 288 | - 'table' => $table_sql, |
|
| 289 | - 'id_parent' => $id_parent, |
|
| 290 | - ], |
|
| 291 | - 'data' => $champs |
|
| 292 | - ] |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - $id = sql_insertq($table_sql, $champs); |
|
| 296 | - |
|
| 297 | - if ($id) { |
|
| 298 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 299 | - // et associer l'auteur sinon |
|
| 300 | - // si la table n'a pas deja un champ id_auteur |
|
| 301 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 302 | - if ($id > 0 && !isset($desc['field']['id_auteur'])) { |
|
| 303 | - $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) |
|
| 304 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 305 | - : _request('id_auteur')); |
|
| 306 | - if ($id_auteur) { |
|
| 307 | - include_spip('action/editer_auteur'); |
|
| 308 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - pipeline( |
|
| 313 | - 'post_insertion', |
|
| 314 | - [ |
|
| 315 | - 'args' => [ |
|
| 316 | - 'table' => $table_sql, |
|
| 317 | - 'id_parent' => $id_parent, |
|
| 318 | - 'id_objet' => $id, |
|
| 319 | - ], |
|
| 320 | - 'data' => $champs |
|
| 321 | - ] |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Appeler une notification |
|
| 326 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 327 | - $notifications( |
|
| 328 | - "{$objet}_inserer", |
|
| 329 | - $id, |
|
| 330 | - [ |
|
| 331 | - 'id_parent' => $id_parent, |
|
| 332 | - 'champs' => $champs, |
|
| 333 | - ] |
|
| 334 | - ); |
|
| 335 | - $notifications( |
|
| 336 | - 'objet_inserer', |
|
| 337 | - $id, |
|
| 338 | - [ |
|
| 339 | - 'objet' => $objet, |
|
| 340 | - 'id_objet' => $id, |
|
| 341 | - 'id_parent' => $id_parent, |
|
| 342 | - 'champs' => $champs, |
|
| 343 | - ] |
|
| 344 | - ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $id; |
|
| 200 | + $d = null; |
|
| 201 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 202 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 203 | + $objet = $t; |
|
| 204 | + } |
|
| 205 | + if ( |
|
| 206 | + include_spip('action/editer_' . $objet) |
|
| 207 | + && function_exists($inserer = $objet . '_inserer') |
|
| 208 | + ) { |
|
| 209 | + return $inserer($id_parent, $set); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $table_sql = table_objet_sql($objet); |
|
| 213 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 214 | + $desc = $trouver_table($table_sql); |
|
| 215 | + if (!$desc || !isset($desc['field'])) { |
|
| 216 | + return 0; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $lang_rub = ''; |
|
| 220 | + $champs = []; |
|
| 221 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 222 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 223 | + // dans la premiere rubrique racine |
|
| 224 | + if (!$id_rubrique = (int) $id_parent) { |
|
| 225 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 226 | + $id_rubrique = $row['id_rubrique']; |
|
| 227 | + } else { |
|
| 228 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 232 | + if (isset($desc['field']['id_secteur'])) { |
|
| 233 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 234 | + } |
|
| 235 | + $lang_rub = $row['lang']; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 239 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 240 | + // ou a defaut celle de la rubrique |
|
| 241 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 242 | + if ( |
|
| 243 | + isset($desc['field']['lang']) && !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 244 | + $table_sql, |
|
| 245 | + explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 246 | + ) |
|
| 247 | + ) { |
|
| 248 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? ''); |
|
| 249 | + if ( |
|
| 250 | + in_array( |
|
| 251 | + $GLOBALS['spip_lang'], |
|
| 252 | + explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 253 | + ) |
|
| 254 | + ) { |
|
| 255 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 256 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 257 | + $champs['langue_choisie'] = 'oui'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } elseif (isset($desc['field']['lang']) && isset($desc['field']['langue_choisie'])) { |
|
| 261 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 262 | + $champs['langue_choisie'] = 'non'; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if (isset($desc['field']['statut'])) { |
|
| 266 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 267 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 268 | + $champs['statut'] = reset($cles_statut); |
|
| 269 | + } else { |
|
| 270 | + $champs['statut'] = 'prepa'; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + if (isset($desc['date']) && ($d = $desc['date']) || isset($desc['field'][$d = 'date'])) { |
|
| 276 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if ($set) { |
|
| 280 | + $champs = array_merge($champs, $set); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Envoyer aux plugins |
|
| 284 | + $champs = pipeline( |
|
| 285 | + 'pre_insertion', |
|
| 286 | + [ |
|
| 287 | + 'args' => [ |
|
| 288 | + 'table' => $table_sql, |
|
| 289 | + 'id_parent' => $id_parent, |
|
| 290 | + ], |
|
| 291 | + 'data' => $champs |
|
| 292 | + ] |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + $id = sql_insertq($table_sql, $champs); |
|
| 296 | + |
|
| 297 | + if ($id) { |
|
| 298 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 299 | + // et associer l'auteur sinon |
|
| 300 | + // si la table n'a pas deja un champ id_auteur |
|
| 301 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 302 | + if ($id > 0 && !isset($desc['field']['id_auteur'])) { |
|
| 303 | + $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) |
|
| 304 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 305 | + : _request('id_auteur')); |
|
| 306 | + if ($id_auteur) { |
|
| 307 | + include_spip('action/editer_auteur'); |
|
| 308 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + pipeline( |
|
| 313 | + 'post_insertion', |
|
| 314 | + [ |
|
| 315 | + 'args' => [ |
|
| 316 | + 'table' => $table_sql, |
|
| 317 | + 'id_parent' => $id_parent, |
|
| 318 | + 'id_objet' => $id, |
|
| 319 | + ], |
|
| 320 | + 'data' => $champs |
|
| 321 | + ] |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Appeler une notification |
|
| 326 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 327 | + $notifications( |
|
| 328 | + "{$objet}_inserer", |
|
| 329 | + $id, |
|
| 330 | + [ |
|
| 331 | + 'id_parent' => $id_parent, |
|
| 332 | + 'champs' => $champs, |
|
| 333 | + ] |
|
| 334 | + ); |
|
| 335 | + $notifications( |
|
| 336 | + 'objet_inserer', |
|
| 337 | + $id, |
|
| 338 | + [ |
|
| 339 | + 'objet' => $objet, |
|
| 340 | + 'id_objet' => $id, |
|
| 341 | + 'id_parent' => $id_parent, |
|
| 342 | + 'champs' => $champs, |
|
| 343 | + ] |
|
| 344 | + ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $id; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,139 +361,139 @@ discard block |
||
| 361 | 361 | * @return string |
| 362 | 362 | */ |
| 363 | 363 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 364 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 365 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 366 | - $objet = $t; |
|
| 367 | - } |
|
| 368 | - if ( |
|
| 369 | - include_spip('action/editer_' . $objet) && function_exists($instituer = $objet . '_instituer') |
|
| 370 | - ) { |
|
| 371 | - return $instituer($id, $c, $calcul_rub); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $table_sql = table_objet_sql($objet); |
|
| 375 | - $table_objet = table_objet($objet); |
|
| 376 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 377 | - $desc = $trouver_table($table_sql); |
|
| 378 | - if (!$desc || !isset($desc['field'])) { |
|
| 379 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - include_spip('inc/autoriser'); |
|
| 383 | - include_spip('inc/rubriques'); |
|
| 384 | - include_spip('inc/modifier'); |
|
| 385 | - |
|
| 386 | - $sel = []; |
|
| 387 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 388 | - |
|
| 389 | - $champ_date = ''; |
|
| 390 | - if (isset($desc['date']) && $desc['date']) { |
|
| 391 | - $champ_date = $desc['date']; |
|
| 392 | - } elseif (isset($desc['field']['date'])) { |
|
| 393 | - $champ_date = 'date'; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 397 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 398 | - |
|
| 399 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . (int) $id); |
|
| 400 | - |
|
| 401 | - $id_rubrique = $row['id_rubrique']; |
|
| 402 | - $statut_ancien = $statut = $row['statut']; |
|
| 403 | - $date_ancienne = $date = $row['date']; |
|
| 404 | - $champs = []; |
|
| 405 | - |
|
| 406 | - $d = ($date && isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 407 | - $s = (isset($desc['field']['statut']) && isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 408 | - |
|
| 409 | - // cf autorisations dans inc/instituer_objet |
|
| 410 | - if ($s != $statut || $d && $d != $date) { |
|
| 411 | - if ( |
|
| 412 | - $id_rubrique ? |
|
| 413 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | - : |
|
| 415 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 416 | - ) { |
|
| 417 | - $statut = $champs['statut'] = $s; |
|
| 418 | - } else { |
|
| 419 | - if ($s != 'publie' && autoriser('modifier', $objet, $id)) { |
|
| 420 | - $statut = $champs['statut'] = $s; |
|
| 421 | - } else { |
|
| 422 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // En cas de publication, fixer la date a "maintenant" |
|
| 427 | - // sauf si $c commande autre chose |
|
| 428 | - // ou si l'objet est deja date dans le futur |
|
| 429 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 430 | - if ( |
|
| 431 | - $champ_date |
|
| 432 | - && ( |
|
| 433 | - $champs['statut'] == 'publie' |
|
| 434 | - || $champs['statut'] == 'prop' && !in_array($statut_ancien, ['publie', 'prop']) |
|
| 435 | - || $d |
|
| 436 | - ) |
|
| 437 | - ) { |
|
| 438 | - $date = ($d || strtotime((string) ($d = $date)) > time()) ? $d : date('Y-m-d H:i:s'); |
|
| 439 | - $champs[$champ_date] = $date; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // Verifier que la rubrique demandee existe et est differente |
|
| 444 | - // de la rubrique actuelle |
|
| 445 | - if ( |
|
| 446 | - $id_rubrique |
|
| 447 | - && isset($c['id_parent']) |
|
| 448 | - && ($id_parent = $c['id_parent']) |
|
| 449 | - && $id_parent != $id_rubrique |
|
| 450 | - && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 451 | - ) { |
|
| 452 | - $champs['id_rubrique'] = $id_parent; |
|
| 453 | - |
|
| 454 | - // si l'objet etait publie |
|
| 455 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 456 | - // repasser l'objet en statut 'propose'. |
|
| 457 | - if ( |
|
| 458 | - $statut == 'publie' |
|
| 459 | - && !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 460 | - ) { |
|
| 461 | - $champs['statut'] = 'prop'; |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - // Envoyer aux plugins |
|
| 467 | - $champs = pipeline( |
|
| 468 | - 'pre_edition', |
|
| 469 | - [ |
|
| 470 | - 'args' => [ |
|
| 471 | - 'table' => $table_sql, |
|
| 472 | - 'table_objet' => $table_objet, |
|
| 473 | - 'spip_table_objet' => $table_sql, |
|
| 474 | - 'objet' => $objet, |
|
| 475 | - 'id_objet' => $id, |
|
| 476 | - 'action' => 'instituer', |
|
| 477 | - 'statut_ancien' => $statut_ancien, |
|
| 478 | - 'date_ancienne' => $date_ancienne, |
|
| 479 | - 'id_parent_ancien' => $id_rubrique, |
|
| 480 | - ], |
|
| 481 | - 'data' => $champs |
|
| 482 | - ] |
|
| 483 | - ); |
|
| 484 | - |
|
| 485 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 486 | - return ''; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // Envoyer les modifs. |
|
| 490 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 491 | - |
|
| 492 | - // Invalider les caches |
|
| 493 | - include_spip('inc/invalideur'); |
|
| 494 | - suivre_invalideur("id='$objet/$id'"); |
|
| 495 | - |
|
| 496 | - /* |
|
| 364 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 365 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 366 | + $objet = $t; |
|
| 367 | + } |
|
| 368 | + if ( |
|
| 369 | + include_spip('action/editer_' . $objet) && function_exists($instituer = $objet . '_instituer') |
|
| 370 | + ) { |
|
| 371 | + return $instituer($id, $c, $calcul_rub); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $table_sql = table_objet_sql($objet); |
|
| 375 | + $table_objet = table_objet($objet); |
|
| 376 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 377 | + $desc = $trouver_table($table_sql); |
|
| 378 | + if (!$desc || !isset($desc['field'])) { |
|
| 379 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + include_spip('inc/autoriser'); |
|
| 383 | + include_spip('inc/rubriques'); |
|
| 384 | + include_spip('inc/modifier'); |
|
| 385 | + |
|
| 386 | + $sel = []; |
|
| 387 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 388 | + |
|
| 389 | + $champ_date = ''; |
|
| 390 | + if (isset($desc['date']) && $desc['date']) { |
|
| 391 | + $champ_date = $desc['date']; |
|
| 392 | + } elseif (isset($desc['field']['date'])) { |
|
| 393 | + $champ_date = 'date'; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 397 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 398 | + |
|
| 399 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . (int) $id); |
|
| 400 | + |
|
| 401 | + $id_rubrique = $row['id_rubrique']; |
|
| 402 | + $statut_ancien = $statut = $row['statut']; |
|
| 403 | + $date_ancienne = $date = $row['date']; |
|
| 404 | + $champs = []; |
|
| 405 | + |
|
| 406 | + $d = ($date && isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 407 | + $s = (isset($desc['field']['statut']) && isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 408 | + |
|
| 409 | + // cf autorisations dans inc/instituer_objet |
|
| 410 | + if ($s != $statut || $d && $d != $date) { |
|
| 411 | + if ( |
|
| 412 | + $id_rubrique ? |
|
| 413 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | + : |
|
| 415 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 416 | + ) { |
|
| 417 | + $statut = $champs['statut'] = $s; |
|
| 418 | + } else { |
|
| 419 | + if ($s != 'publie' && autoriser('modifier', $objet, $id)) { |
|
| 420 | + $statut = $champs['statut'] = $s; |
|
| 421 | + } else { |
|
| 422 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // En cas de publication, fixer la date a "maintenant" |
|
| 427 | + // sauf si $c commande autre chose |
|
| 428 | + // ou si l'objet est deja date dans le futur |
|
| 429 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 430 | + if ( |
|
| 431 | + $champ_date |
|
| 432 | + && ( |
|
| 433 | + $champs['statut'] == 'publie' |
|
| 434 | + || $champs['statut'] == 'prop' && !in_array($statut_ancien, ['publie', 'prop']) |
|
| 435 | + || $d |
|
| 436 | + ) |
|
| 437 | + ) { |
|
| 438 | + $date = ($d || strtotime((string) ($d = $date)) > time()) ? $d : date('Y-m-d H:i:s'); |
|
| 439 | + $champs[$champ_date] = $date; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // Verifier que la rubrique demandee existe et est differente |
|
| 444 | + // de la rubrique actuelle |
|
| 445 | + if ( |
|
| 446 | + $id_rubrique |
|
| 447 | + && isset($c['id_parent']) |
|
| 448 | + && ($id_parent = $c['id_parent']) |
|
| 449 | + && $id_parent != $id_rubrique |
|
| 450 | + && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 451 | + ) { |
|
| 452 | + $champs['id_rubrique'] = $id_parent; |
|
| 453 | + |
|
| 454 | + // si l'objet etait publie |
|
| 455 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 456 | + // repasser l'objet en statut 'propose'. |
|
| 457 | + if ( |
|
| 458 | + $statut == 'publie' |
|
| 459 | + && !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 460 | + ) { |
|
| 461 | + $champs['statut'] = 'prop'; |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + // Envoyer aux plugins |
|
| 467 | + $champs = pipeline( |
|
| 468 | + 'pre_edition', |
|
| 469 | + [ |
|
| 470 | + 'args' => [ |
|
| 471 | + 'table' => $table_sql, |
|
| 472 | + 'table_objet' => $table_objet, |
|
| 473 | + 'spip_table_objet' => $table_sql, |
|
| 474 | + 'objet' => $objet, |
|
| 475 | + 'id_objet' => $id, |
|
| 476 | + 'action' => 'instituer', |
|
| 477 | + 'statut_ancien' => $statut_ancien, |
|
| 478 | + 'date_ancienne' => $date_ancienne, |
|
| 479 | + 'id_parent_ancien' => $id_rubrique, |
|
| 480 | + ], |
|
| 481 | + 'data' => $champs |
|
| 482 | + ] |
|
| 483 | + ); |
|
| 484 | + |
|
| 485 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 486 | + return ''; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // Envoyer les modifs. |
|
| 490 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 491 | + |
|
| 492 | + // Invalider les caches |
|
| 493 | + include_spip('inc/invalideur'); |
|
| 494 | + suivre_invalideur("id='$objet/$id'"); |
|
| 495 | + |
|
| 496 | + /* |
|
| 497 | 497 | if ($date) { |
| 498 | 498 | $t = strtotime($date); |
| 499 | 499 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -502,63 +502,63 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | }*/ |
| 504 | 504 | |
| 505 | - // Pipeline |
|
| 506 | - pipeline( |
|
| 507 | - 'post_edition', |
|
| 508 | - [ |
|
| 509 | - 'args' => [ |
|
| 510 | - 'table' => $table_sql, |
|
| 511 | - 'table_objet' => $table_objet, |
|
| 512 | - 'spip_table_objet' => $table_sql, |
|
| 513 | - 'objet' => $objet, |
|
| 514 | - 'id_objet' => $id, |
|
| 515 | - 'action' => 'instituer', |
|
| 516 | - 'statut_ancien' => $statut_ancien, |
|
| 517 | - 'date_ancienne' => $date_ancienne, |
|
| 518 | - 'id_parent_ancien' => $id_rubrique, |
|
| 519 | - ], |
|
| 520 | - 'data' => $champs |
|
| 521 | - ] |
|
| 522 | - ); |
|
| 523 | - |
|
| 524 | - // Notifications |
|
| 525 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 526 | - $notifications( |
|
| 527 | - "{$objet}_instituer", |
|
| 528 | - $id, |
|
| 529 | - [ |
|
| 530 | - 'statut' => $statut, |
|
| 531 | - 'statut_ancien' => $statut_ancien, |
|
| 532 | - 'date' => $date, |
|
| 533 | - 'date_ancienne' => $date_ancienne, |
|
| 534 | - 'id_parent_ancien' => $id_rubrique, |
|
| 535 | - 'champs' => $champs, |
|
| 536 | - ] |
|
| 537 | - ); |
|
| 538 | - $notifications( |
|
| 539 | - 'objet_instituer', |
|
| 540 | - $id, |
|
| 541 | - [ |
|
| 542 | - 'objet' => $objet, |
|
| 543 | - 'id_objet' => $id, |
|
| 544 | - 'statut' => $statut, |
|
| 545 | - 'statut_ancien' => $statut_ancien, |
|
| 546 | - 'date' => $date, |
|
| 547 | - 'date_ancienne' => $date_ancienne, |
|
| 548 | - 'id_parent_ancien' => $id_rubrique, |
|
| 549 | - 'champs' => $champs, |
|
| 550 | - ] |
|
| 551 | - ); |
|
| 552 | - |
|
| 553 | - // Rétro-compat |
|
| 554 | - $notifications( |
|
| 555 | - "instituer$objet", |
|
| 556 | - $id, |
|
| 557 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return ''; // pas d'erreur |
|
| 505 | + // Pipeline |
|
| 506 | + pipeline( |
|
| 507 | + 'post_edition', |
|
| 508 | + [ |
|
| 509 | + 'args' => [ |
|
| 510 | + 'table' => $table_sql, |
|
| 511 | + 'table_objet' => $table_objet, |
|
| 512 | + 'spip_table_objet' => $table_sql, |
|
| 513 | + 'objet' => $objet, |
|
| 514 | + 'id_objet' => $id, |
|
| 515 | + 'action' => 'instituer', |
|
| 516 | + 'statut_ancien' => $statut_ancien, |
|
| 517 | + 'date_ancienne' => $date_ancienne, |
|
| 518 | + 'id_parent_ancien' => $id_rubrique, |
|
| 519 | + ], |
|
| 520 | + 'data' => $champs |
|
| 521 | + ] |
|
| 522 | + ); |
|
| 523 | + |
|
| 524 | + // Notifications |
|
| 525 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 526 | + $notifications( |
|
| 527 | + "{$objet}_instituer", |
|
| 528 | + $id, |
|
| 529 | + [ |
|
| 530 | + 'statut' => $statut, |
|
| 531 | + 'statut_ancien' => $statut_ancien, |
|
| 532 | + 'date' => $date, |
|
| 533 | + 'date_ancienne' => $date_ancienne, |
|
| 534 | + 'id_parent_ancien' => $id_rubrique, |
|
| 535 | + 'champs' => $champs, |
|
| 536 | + ] |
|
| 537 | + ); |
|
| 538 | + $notifications( |
|
| 539 | + 'objet_instituer', |
|
| 540 | + $id, |
|
| 541 | + [ |
|
| 542 | + 'objet' => $objet, |
|
| 543 | + 'id_objet' => $id, |
|
| 544 | + 'statut' => $statut, |
|
| 545 | + 'statut_ancien' => $statut_ancien, |
|
| 546 | + 'date' => $date, |
|
| 547 | + 'date_ancienne' => $date_ancienne, |
|
| 548 | + 'id_parent_ancien' => $id_rubrique, |
|
| 549 | + 'champs' => $champs, |
|
| 550 | + ] |
|
| 551 | + ); |
|
| 552 | + |
|
| 553 | + // Rétro-compat |
|
| 554 | + $notifications( |
|
| 555 | + "instituer$objet", |
|
| 556 | + $id, |
|
| 557 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return ''; // pas d'erreur |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -573,51 +573,51 @@ discard block |
||
| 573 | 573 | * @return void |
| 574 | 574 | */ |
| 575 | 575 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 576 | - $table_sql = table_objet_sql($objet); |
|
| 577 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 578 | - $desc = $trouver_table($table_sql); |
|
| 579 | - |
|
| 580 | - // Si on deplace l'objet |
|
| 581 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 582 | - if (isset($champs['id_rubrique'])) { |
|
| 583 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 584 | - $langue = $row_rub['lang']; |
|
| 585 | - |
|
| 586 | - if (isset($desc['field']['id_secteur'])) { |
|
| 587 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - if ( |
|
| 591 | - isset($desc['field']['lang']) |
|
| 592 | - && isset($desc['field']['langue_choisie']) |
|
| 593 | - && sql_fetsel( |
|
| 594 | - '1', |
|
| 595 | - $table_sql, |
|
| 596 | - id_table_objet($objet) . '=' . (int) $id . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $champs['lang'] = $langue; |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - if (!$champs) { |
|
| 604 | - return; |
|
| 605 | - } |
|
| 606 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . (int) $id); |
|
| 607 | - |
|
| 608 | - // Changer le statut des rubriques concernees |
|
| 609 | - if ($cond) { |
|
| 610 | - include_spip('inc/rubriques'); |
|
| 611 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 612 | - $postdate = false; |
|
| 613 | - // On rajoute les infos de l'objet |
|
| 614 | - $infos = [ |
|
| 615 | - 'objet' => $objet, |
|
| 616 | - 'id_objet' => $id, |
|
| 617 | - 'statut_ancien' => $statut, |
|
| 618 | - ]; |
|
| 619 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 620 | - } |
|
| 576 | + $table_sql = table_objet_sql($objet); |
|
| 577 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 578 | + $desc = $trouver_table($table_sql); |
|
| 579 | + |
|
| 580 | + // Si on deplace l'objet |
|
| 581 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 582 | + if (isset($champs['id_rubrique'])) { |
|
| 583 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 584 | + $langue = $row_rub['lang']; |
|
| 585 | + |
|
| 586 | + if (isset($desc['field']['id_secteur'])) { |
|
| 587 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + if ( |
|
| 591 | + isset($desc['field']['lang']) |
|
| 592 | + && isset($desc['field']['langue_choisie']) |
|
| 593 | + && sql_fetsel( |
|
| 594 | + '1', |
|
| 595 | + $table_sql, |
|
| 596 | + id_table_objet($objet) . '=' . (int) $id . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $champs['lang'] = $langue; |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + if (!$champs) { |
|
| 604 | + return; |
|
| 605 | + } |
|
| 606 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . (int) $id); |
|
| 607 | + |
|
| 608 | + // Changer le statut des rubriques concernees |
|
| 609 | + if ($cond) { |
|
| 610 | + include_spip('inc/rubriques'); |
|
| 611 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 612 | + $postdate = false; |
|
| 613 | + // On rajoute les infos de l'objet |
|
| 614 | + $infos = [ |
|
| 615 | + 'objet' => $objet, |
|
| 616 | + 'id_objet' => $id, |
|
| 617 | + 'statut_ancien' => $statut, |
|
| 618 | + ]; |
|
| 619 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 620 | + } |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | |
@@ -646,71 +646,71 @@ discard block |
||
| 646 | 646 | * string|int : valeur du champ demande pour l'objet demande |
| 647 | 647 | */ |
| 648 | 648 | function objet_lire($objet, $valeur_id, $options = []) { |
| 649 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 650 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 651 | - $objet = $t; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 655 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 656 | - static $descriptions = []; |
|
| 657 | - |
|
| 658 | - // On détermine le nom du champ id de la table. |
|
| 659 | - include_spip('base/objets'); |
|
| 660 | - $primary = id_table_objet($objet); |
|
| 661 | - |
|
| 662 | - // On détermine l'id à utiliser. |
|
| 663 | - $champ_id = (empty($options['champ_id']) ? $primary : $options['champ_id']); |
|
| 664 | - |
|
| 665 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 666 | - if ( |
|
| 667 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 668 | - || isset($options['force']) && $options['force'] |
|
| 669 | - ) { |
|
| 670 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 671 | - if ( |
|
| 672 | - include_spip('action/editer_' . $objet) |
|
| 673 | - && function_exists($lire = "{$objet}_lire_champs") |
|
| 674 | - ) { |
|
| 675 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 676 | - } else { |
|
| 677 | - // On récupère la table SQL à partir du type d'objet. |
|
| 678 | - $table = table_objet_sql($objet); |
|
| 679 | - |
|
| 680 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 681 | - $where = [ |
|
| 682 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 683 | - ]; |
|
| 684 | - |
|
| 685 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 686 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - if (!$valeurs) { |
|
| 690 | - $valeurs = false; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 694 | - |
|
| 695 | - if ($champ_id !== $primary && isset($valeurs[$primary])) { |
|
| 696 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 697 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 702 | - |
|
| 703 | - // On ne retourne maintenant que les champs demandés. |
|
| 704 | - // - on détermine les informations à renvoyer. |
|
| 705 | - if ($retour && !empty($options['champs'])) { |
|
| 706 | - $champs = $options['champs']; |
|
| 707 | - // Extraction des seules informations demandées. |
|
| 708 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 709 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 710 | - $retour = is_array($champs) |
|
| 711 | - ? array_intersect_key($retour, array_flip($champs)) |
|
| 712 | - : $retour[$champs] ?? false; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - return $retour; |
|
| 649 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 650 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 651 | + $objet = $t; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 655 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 656 | + static $descriptions = []; |
|
| 657 | + |
|
| 658 | + // On détermine le nom du champ id de la table. |
|
| 659 | + include_spip('base/objets'); |
|
| 660 | + $primary = id_table_objet($objet); |
|
| 661 | + |
|
| 662 | + // On détermine l'id à utiliser. |
|
| 663 | + $champ_id = (empty($options['champ_id']) ? $primary : $options['champ_id']); |
|
| 664 | + |
|
| 665 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 666 | + if ( |
|
| 667 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 668 | + || isset($options['force']) && $options['force'] |
|
| 669 | + ) { |
|
| 670 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 671 | + if ( |
|
| 672 | + include_spip('action/editer_' . $objet) |
|
| 673 | + && function_exists($lire = "{$objet}_lire_champs") |
|
| 674 | + ) { |
|
| 675 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 676 | + } else { |
|
| 677 | + // On récupère la table SQL à partir du type d'objet. |
|
| 678 | + $table = table_objet_sql($objet); |
|
| 679 | + |
|
| 680 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 681 | + $where = [ |
|
| 682 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 683 | + ]; |
|
| 684 | + |
|
| 685 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 686 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + if (!$valeurs) { |
|
| 690 | + $valeurs = false; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 694 | + |
|
| 695 | + if ($champ_id !== $primary && isset($valeurs[$primary])) { |
|
| 696 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 697 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 702 | + |
|
| 703 | + // On ne retourne maintenant que les champs demandés. |
|
| 704 | + // - on détermine les informations à renvoyer. |
|
| 705 | + if ($retour && !empty($options['champs'])) { |
|
| 706 | + $champs = $options['champs']; |
|
| 707 | + // Extraction des seules informations demandées. |
|
| 708 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 709 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 710 | + $retour = is_array($champs) |
|
| 711 | + ? array_intersect_key($retour, array_flip($champs)) |
|
| 712 | + : $retour[$champs] ?? false; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + return $retour; |
|
| 716 | 716 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -38,36 +38,36 @@ discard block |
||
| 38 | 38 | * Liste (identifiant de l'article, texte d'erreur éventuel) |
| 39 | 39 | */ |
| 40 | 40 | function action_editer_article_dist($arg = null) { |
| 41 | - include_spip('inc/autoriser'); |
|
| 42 | - $err = ''; |
|
| 43 | - if (is_null($arg)) { |
|
| 44 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 45 | - $arg = $securiser_action(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 49 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 50 | - if (!$id_article = (int) $arg) { |
|
| 51 | - $id_parent = _request('id_parent'); |
|
| 52 | - if (!$id_parent) { |
|
| 53 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 54 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 55 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 56 | - } else { |
|
| 57 | - $id_article = article_inserer($id_parent); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Enregistre l'envoi dans la BD |
|
| 62 | - if ($id_article > 0) { |
|
| 63 | - $err = article_modifier($id_article); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - if ($err) { |
|
| 67 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [$id_article, $err]; |
|
| 41 | + include_spip('inc/autoriser'); |
|
| 42 | + $err = ''; |
|
| 43 | + if (is_null($arg)) { |
|
| 44 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 45 | + $arg = $securiser_action(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 49 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 50 | + if (!$id_article = (int) $arg) { |
|
| 51 | + $id_parent = _request('id_parent'); |
|
| 52 | + if (!$id_parent) { |
|
| 53 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 54 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 55 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 56 | + } else { |
|
| 57 | + $id_article = article_inserer($id_parent); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Enregistre l'envoi dans la BD |
|
| 62 | + if ($id_article > 0) { |
|
| 63 | + $err = article_modifier($id_article); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + if ($err) { |
|
| 67 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [$id_article, $err]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -89,49 +89,49 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | function article_modifier($id_article, $set = null) { |
| 91 | 91 | |
| 92 | - // unifier $texte en cas de texte trop long |
|
| 93 | - trop_longs_articles(); |
|
| 94 | - |
|
| 95 | - include_spip('inc/modifier'); |
|
| 96 | - include_spip('inc/filtres'); |
|
| 97 | - $c = collecter_requests( |
|
| 98 | - // include list |
|
| 99 | - objet_info('article', 'champs_editables'), |
|
| 100 | - // exclude list |
|
| 101 | - ['date', 'statut', 'id_parent'], |
|
| 102 | - // donnees eventuellement fournies |
|
| 103 | - $set |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 107 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id_article); |
|
| 108 | - $invalideur = $indexation = false; |
|
| 109 | - if ($t == 'publie') { |
|
| 110 | - $invalideur = "id='article/$id_article'"; |
|
| 111 | - $indexation = true; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ( |
|
| 115 | - $err = objet_modifier_champs( |
|
| 116 | - 'article', |
|
| 117 | - $id_article, |
|
| 118 | - [ |
|
| 119 | - 'data' => $set, |
|
| 120 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 121 | - 'invalideur' => $invalideur, |
|
| 122 | - 'indexation' => $indexation, |
|
| 123 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 124 | - ], |
|
| 125 | - $c |
|
| 126 | - ) |
|
| 127 | - ) { |
|
| 128 | - return $err; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Modification de statut, changement de rubrique ? |
|
| 132 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 133 | - |
|
| 134 | - return article_instituer($id_article, $c); |
|
| 92 | + // unifier $texte en cas de texte trop long |
|
| 93 | + trop_longs_articles(); |
|
| 94 | + |
|
| 95 | + include_spip('inc/modifier'); |
|
| 96 | + include_spip('inc/filtres'); |
|
| 97 | + $c = collecter_requests( |
|
| 98 | + // include list |
|
| 99 | + objet_info('article', 'champs_editables'), |
|
| 100 | + // exclude list |
|
| 101 | + ['date', 'statut', 'id_parent'], |
|
| 102 | + // donnees eventuellement fournies |
|
| 103 | + $set |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 107 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id_article); |
|
| 108 | + $invalideur = $indexation = false; |
|
| 109 | + if ($t == 'publie') { |
|
| 110 | + $invalideur = "id='article/$id_article'"; |
|
| 111 | + $indexation = true; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ( |
|
| 115 | + $err = objet_modifier_champs( |
|
| 116 | + 'article', |
|
| 117 | + $id_article, |
|
| 118 | + [ |
|
| 119 | + 'data' => $set, |
|
| 120 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 121 | + 'invalideur' => $invalideur, |
|
| 122 | + 'indexation' => $indexation, |
|
| 123 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 124 | + ], |
|
| 125 | + $c |
|
| 126 | + ) |
|
| 127 | + ) { |
|
| 128 | + return $err; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Modification de statut, changement de rubrique ? |
|
| 132 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 133 | + |
|
| 134 | + return article_instituer($id_article, $c); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -167,120 +167,120 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function article_inserer($id_rubrique, $set = null) { |
| 169 | 169 | |
| 170 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 171 | - // dans la premiere rubrique racine |
|
| 172 | - if (!$id_rubrique = (int) $id_rubrique) { |
|
| 173 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 174 | - $id_rubrique = $row['id_rubrique']; |
|
| 175 | - } else { |
|
| 176 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 180 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 181 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 182 | - $lang_rub = $row['lang'] ?? ''; |
|
| 183 | - |
|
| 184 | - $lang = ''; |
|
| 185 | - $choisie = 'non'; |
|
| 186 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 187 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 188 | - // ou a defaut celle de la rubrique |
|
| 189 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 190 | - if ( |
|
| 191 | - !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 192 | - 'spip_articles', |
|
| 193 | - explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? ''); |
|
| 197 | - if ( |
|
| 198 | - in_array( |
|
| 199 | - $GLOBALS['spip_lang'], |
|
| 200 | - explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 201 | - ) |
|
| 202 | - ) { |
|
| 203 | - $lang = $GLOBALS['spip_lang']; |
|
| 204 | - $choisie = 'oui'; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!$lang) { |
|
| 209 | - $choisie = 'non'; |
|
| 210 | - $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $champs = [ |
|
| 214 | - 'id_rubrique' => $id_rubrique, |
|
| 215 | - 'id_secteur' => $id_secteur, |
|
| 216 | - 'statut' => 'prepa', |
|
| 217 | - 'date' => date('Y-m-d H:i:s'), |
|
| 218 | - 'lang' => $lang, |
|
| 219 | - 'langue_choisie' => $choisie |
|
| 220 | - ]; |
|
| 221 | - |
|
| 222 | - if ($set) { |
|
| 223 | - $champs = array_merge($champs, $set); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Envoyer aux plugins |
|
| 227 | - $champs = pipeline( |
|
| 228 | - 'pre_insertion', |
|
| 229 | - [ |
|
| 230 | - 'args' => [ |
|
| 231 | - 'table' => 'spip_articles', |
|
| 232 | - ], |
|
| 233 | - 'data' => $champs |
|
| 234 | - ] |
|
| 235 | - ); |
|
| 236 | - |
|
| 237 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 238 | - |
|
| 239 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 240 | - if ($id_article > 0) { |
|
| 241 | - $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 242 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 243 | - : _request('id_auteur')); |
|
| 244 | - if ($id_auteur) { |
|
| 245 | - include_spip('action/editer_auteur'); |
|
| 246 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - pipeline( |
|
| 251 | - 'post_insertion', |
|
| 252 | - [ |
|
| 253 | - 'args' => [ |
|
| 254 | - 'table' => 'spip_articles', |
|
| 255 | - 'id_objet' => $id_article |
|
| 256 | - ], |
|
| 257 | - 'data' => $champs |
|
| 258 | - ] |
|
| 259 | - ); |
|
| 260 | - |
|
| 261 | - // Appeler une notification |
|
| 262 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 263 | - $notifications( |
|
| 264 | - 'article_inserer', |
|
| 265 | - $id_article, |
|
| 266 | - [ |
|
| 267 | - 'id_parent' => $id_rubrique, |
|
| 268 | - 'champs' => $champs, |
|
| 269 | - ] |
|
| 270 | - ); |
|
| 271 | - $notifications( |
|
| 272 | - 'objet_inserer', |
|
| 273 | - $id_article, |
|
| 274 | - [ |
|
| 275 | - 'objet' => 'article', |
|
| 276 | - 'id_objet' => $id_article, |
|
| 277 | - 'id_parent' => $id_rubrique, |
|
| 278 | - 'champs' => $champs, |
|
| 279 | - ] |
|
| 280 | - ); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - return $id_article; |
|
| 170 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 171 | + // dans la premiere rubrique racine |
|
| 172 | + if (!$id_rubrique = (int) $id_rubrique) { |
|
| 173 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 174 | + $id_rubrique = $row['id_rubrique']; |
|
| 175 | + } else { |
|
| 176 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 180 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 181 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 182 | + $lang_rub = $row['lang'] ?? ''; |
|
| 183 | + |
|
| 184 | + $lang = ''; |
|
| 185 | + $choisie = 'non'; |
|
| 186 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 187 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 188 | + // ou a defaut celle de la rubrique |
|
| 189 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 190 | + if ( |
|
| 191 | + !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 192 | + 'spip_articles', |
|
| 193 | + explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? ''); |
|
| 197 | + if ( |
|
| 198 | + in_array( |
|
| 199 | + $GLOBALS['spip_lang'], |
|
| 200 | + explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 201 | + ) |
|
| 202 | + ) { |
|
| 203 | + $lang = $GLOBALS['spip_lang']; |
|
| 204 | + $choisie = 'oui'; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!$lang) { |
|
| 209 | + $choisie = 'non'; |
|
| 210 | + $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $champs = [ |
|
| 214 | + 'id_rubrique' => $id_rubrique, |
|
| 215 | + 'id_secteur' => $id_secteur, |
|
| 216 | + 'statut' => 'prepa', |
|
| 217 | + 'date' => date('Y-m-d H:i:s'), |
|
| 218 | + 'lang' => $lang, |
|
| 219 | + 'langue_choisie' => $choisie |
|
| 220 | + ]; |
|
| 221 | + |
|
| 222 | + if ($set) { |
|
| 223 | + $champs = array_merge($champs, $set); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Envoyer aux plugins |
|
| 227 | + $champs = pipeline( |
|
| 228 | + 'pre_insertion', |
|
| 229 | + [ |
|
| 230 | + 'args' => [ |
|
| 231 | + 'table' => 'spip_articles', |
|
| 232 | + ], |
|
| 233 | + 'data' => $champs |
|
| 234 | + ] |
|
| 235 | + ); |
|
| 236 | + |
|
| 237 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 238 | + |
|
| 239 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 240 | + if ($id_article > 0) { |
|
| 241 | + $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 242 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 243 | + : _request('id_auteur')); |
|
| 244 | + if ($id_auteur) { |
|
| 245 | + include_spip('action/editer_auteur'); |
|
| 246 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + pipeline( |
|
| 251 | + 'post_insertion', |
|
| 252 | + [ |
|
| 253 | + 'args' => [ |
|
| 254 | + 'table' => 'spip_articles', |
|
| 255 | + 'id_objet' => $id_article |
|
| 256 | + ], |
|
| 257 | + 'data' => $champs |
|
| 258 | + ] |
|
| 259 | + ); |
|
| 260 | + |
|
| 261 | + // Appeler une notification |
|
| 262 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 263 | + $notifications( |
|
| 264 | + 'article_inserer', |
|
| 265 | + $id_article, |
|
| 266 | + [ |
|
| 267 | + 'id_parent' => $id_rubrique, |
|
| 268 | + 'champs' => $champs, |
|
| 269 | + ] |
|
| 270 | + ); |
|
| 271 | + $notifications( |
|
| 272 | + 'objet_inserer', |
|
| 273 | + $id_article, |
|
| 274 | + [ |
|
| 275 | + 'objet' => 'article', |
|
| 276 | + 'id_objet' => $id_article, |
|
| 277 | + 'id_parent' => $id_rubrique, |
|
| 278 | + 'champs' => $champs, |
|
| 279 | + ] |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + return $id_article; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -308,157 +308,157 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 310 | 310 | |
| 311 | - include_spip('inc/autoriser'); |
|
| 312 | - include_spip('inc/rubriques'); |
|
| 313 | - include_spip('inc/modifier'); |
|
| 314 | - |
|
| 315 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 316 | - $id_rubrique = $row['id_rubrique']; |
|
| 317 | - $statut_ancien = $statut = $row['statut']; |
|
| 318 | - $date_ancienne = $date = $row['date']; |
|
| 319 | - $champs = []; |
|
| 320 | - |
|
| 321 | - $d = $c['date'] ?? null; |
|
| 322 | - $s = $c['statut'] ?? $statut; |
|
| 323 | - |
|
| 324 | - // cf autorisations dans inc/instituer_article |
|
| 325 | - if ($s != $statut || $d && $d != $date) { |
|
| 326 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 327 | - $statut = $champs['statut'] = $s; |
|
| 328 | - } elseif (autoriser('modifier', 'article', $id_article) && $s != 'publie') { |
|
| 329 | - $statut = $champs['statut'] = $s; |
|
| 330 | - } else { |
|
| 331 | - spip_log("editer_article $id_article refus " . implode(' ', $c)); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - // En cas de publication, fixer la date a "maintenant" |
|
| 335 | - // sauf si $c commande autre chose |
|
| 336 | - // ou si l'article est deja date dans le futur |
|
| 337 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 338 | - if ( |
|
| 339 | - $champs['statut'] == 'publie' |
|
| 340 | - || $champs['statut'] == 'prop' && ($d || !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 341 | - ) { |
|
| 342 | - $champs['date'] = $d || strtotime((string) ($d = $date)) > time() |
|
| 343 | - ? $date = $d |
|
| 344 | - : ($date = date('Y-m-d H:i:s')); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // Verifier que la rubrique demandee existe et est differente |
|
| 349 | - // de la rubrique actuelle |
|
| 350 | - if ( |
|
| 351 | - isset($c['id_parent']) |
|
| 352 | - && ($id_parent = $c['id_parent']) |
|
| 353 | - && $id_parent != $id_rubrique |
|
| 354 | - && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 355 | - ) { |
|
| 356 | - $champs['id_rubrique'] = $id_parent; |
|
| 357 | - |
|
| 358 | - // si l'article etait publie |
|
| 359 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 360 | - // repasser l'article en statut 'propose'. |
|
| 361 | - if ( |
|
| 362 | - $statut == 'publie' |
|
| 363 | - && !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 364 | - ) { |
|
| 365 | - $champs['statut'] = 'prop'; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - // Envoyer aux plugins |
|
| 370 | - $champs = pipeline( |
|
| 371 | - 'pre_edition', |
|
| 372 | - [ |
|
| 373 | - 'args' => [ |
|
| 374 | - 'table' => 'spip_articles', |
|
| 375 | - 'table_objet' => 'articles', |
|
| 376 | - 'spip_table_objet' => 'spip_articles', |
|
| 377 | - 'objet' => 'article', |
|
| 378 | - 'id_objet' => $id_article, |
|
| 379 | - 'action' => 'instituer', |
|
| 380 | - 'statut_ancien' => $statut_ancien, |
|
| 381 | - 'date_ancienne' => $date_ancienne, |
|
| 382 | - ], |
|
| 383 | - 'data' => $champs |
|
| 384 | - ] |
|
| 385 | - ); |
|
| 386 | - |
|
| 387 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 388 | - return ''; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - // Envoyer les modifs. |
|
| 392 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 393 | - |
|
| 394 | - // Invalider les caches |
|
| 395 | - include_spip('inc/invalideur'); |
|
| 396 | - suivre_invalideur("id='article/$id_article'"); |
|
| 397 | - |
|
| 398 | - if ($date) { |
|
| 399 | - $t = strtotime((string) $date); |
|
| 400 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 401 | - if ($t > time() && (!$p || $t < $p)) { |
|
| 402 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // Pipeline |
|
| 407 | - pipeline( |
|
| 408 | - 'post_edition', |
|
| 409 | - [ |
|
| 410 | - 'args' => [ |
|
| 411 | - 'table' => 'spip_articles', |
|
| 412 | - 'table_objet' => 'articles', |
|
| 413 | - 'spip_table_objet' => 'spip_articles', |
|
| 414 | - 'objet' => 'article', |
|
| 415 | - 'id_objet' => $id_article, |
|
| 416 | - 'action' => 'instituer', |
|
| 417 | - 'statut_ancien' => $statut_ancien, |
|
| 418 | - 'date_ancienne' => $date_ancienne, |
|
| 419 | - ], |
|
| 420 | - 'data' => $champs |
|
| 421 | - ] |
|
| 422 | - ); |
|
| 423 | - |
|
| 424 | - // Notifications |
|
| 425 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 426 | - $notifications( |
|
| 427 | - 'article_instituer', |
|
| 428 | - $id_article, |
|
| 429 | - [ |
|
| 430 | - 'statut' => $statut, |
|
| 431 | - 'statut_ancien' => $statut_ancien, |
|
| 432 | - 'date' => $date, |
|
| 433 | - 'date_ancienne' => $date_ancienne, |
|
| 434 | - 'id_parent_ancien' => $id_rubrique, |
|
| 435 | - 'champs' => $champs, |
|
| 436 | - ] |
|
| 437 | - ); |
|
| 438 | - $notifications( |
|
| 439 | - 'objet_instituer', |
|
| 440 | - $id_article, |
|
| 441 | - [ |
|
| 442 | - 'objet' => 'article', |
|
| 443 | - 'id_objet' => $id_article, |
|
| 444 | - 'statut' => $statut, |
|
| 445 | - 'statut_ancien' => $statut_ancien, |
|
| 446 | - 'date' => $date, |
|
| 447 | - 'date_ancienne' => $date_ancienne, |
|
| 448 | - 'id_parent_ancien' => $id_rubrique, |
|
| 449 | - 'champs' => $champs, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - // Rétro-compat |
|
| 454 | - $notifications( |
|
| 455 | - 'instituerarticle', |
|
| 456 | - $id_article, |
|
| 457 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 458 | - ); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - return ''; // pas d'erreur |
|
| 311 | + include_spip('inc/autoriser'); |
|
| 312 | + include_spip('inc/rubriques'); |
|
| 313 | + include_spip('inc/modifier'); |
|
| 314 | + |
|
| 315 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 316 | + $id_rubrique = $row['id_rubrique']; |
|
| 317 | + $statut_ancien = $statut = $row['statut']; |
|
| 318 | + $date_ancienne = $date = $row['date']; |
|
| 319 | + $champs = []; |
|
| 320 | + |
|
| 321 | + $d = $c['date'] ?? null; |
|
| 322 | + $s = $c['statut'] ?? $statut; |
|
| 323 | + |
|
| 324 | + // cf autorisations dans inc/instituer_article |
|
| 325 | + if ($s != $statut || $d && $d != $date) { |
|
| 326 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 327 | + $statut = $champs['statut'] = $s; |
|
| 328 | + } elseif (autoriser('modifier', 'article', $id_article) && $s != 'publie') { |
|
| 329 | + $statut = $champs['statut'] = $s; |
|
| 330 | + } else { |
|
| 331 | + spip_log("editer_article $id_article refus " . implode(' ', $c)); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + // En cas de publication, fixer la date a "maintenant" |
|
| 335 | + // sauf si $c commande autre chose |
|
| 336 | + // ou si l'article est deja date dans le futur |
|
| 337 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 338 | + if ( |
|
| 339 | + $champs['statut'] == 'publie' |
|
| 340 | + || $champs['statut'] == 'prop' && ($d || !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 341 | + ) { |
|
| 342 | + $champs['date'] = $d || strtotime((string) ($d = $date)) > time() |
|
| 343 | + ? $date = $d |
|
| 344 | + : ($date = date('Y-m-d H:i:s')); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // Verifier que la rubrique demandee existe et est differente |
|
| 349 | + // de la rubrique actuelle |
|
| 350 | + if ( |
|
| 351 | + isset($c['id_parent']) |
|
| 352 | + && ($id_parent = $c['id_parent']) |
|
| 353 | + && $id_parent != $id_rubrique |
|
| 354 | + && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 355 | + ) { |
|
| 356 | + $champs['id_rubrique'] = $id_parent; |
|
| 357 | + |
|
| 358 | + // si l'article etait publie |
|
| 359 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 360 | + // repasser l'article en statut 'propose'. |
|
| 361 | + if ( |
|
| 362 | + $statut == 'publie' |
|
| 363 | + && !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 364 | + ) { |
|
| 365 | + $champs['statut'] = 'prop'; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + // Envoyer aux plugins |
|
| 370 | + $champs = pipeline( |
|
| 371 | + 'pre_edition', |
|
| 372 | + [ |
|
| 373 | + 'args' => [ |
|
| 374 | + 'table' => 'spip_articles', |
|
| 375 | + 'table_objet' => 'articles', |
|
| 376 | + 'spip_table_objet' => 'spip_articles', |
|
| 377 | + 'objet' => 'article', |
|
| 378 | + 'id_objet' => $id_article, |
|
| 379 | + 'action' => 'instituer', |
|
| 380 | + 'statut_ancien' => $statut_ancien, |
|
| 381 | + 'date_ancienne' => $date_ancienne, |
|
| 382 | + ], |
|
| 383 | + 'data' => $champs |
|
| 384 | + ] |
|
| 385 | + ); |
|
| 386 | + |
|
| 387 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 388 | + return ''; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + // Envoyer les modifs. |
|
| 392 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 393 | + |
|
| 394 | + // Invalider les caches |
|
| 395 | + include_spip('inc/invalideur'); |
|
| 396 | + suivre_invalideur("id='article/$id_article'"); |
|
| 397 | + |
|
| 398 | + if ($date) { |
|
| 399 | + $t = strtotime((string) $date); |
|
| 400 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 401 | + if ($t > time() && (!$p || $t < $p)) { |
|
| 402 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // Pipeline |
|
| 407 | + pipeline( |
|
| 408 | + 'post_edition', |
|
| 409 | + [ |
|
| 410 | + 'args' => [ |
|
| 411 | + 'table' => 'spip_articles', |
|
| 412 | + 'table_objet' => 'articles', |
|
| 413 | + 'spip_table_objet' => 'spip_articles', |
|
| 414 | + 'objet' => 'article', |
|
| 415 | + 'id_objet' => $id_article, |
|
| 416 | + 'action' => 'instituer', |
|
| 417 | + 'statut_ancien' => $statut_ancien, |
|
| 418 | + 'date_ancienne' => $date_ancienne, |
|
| 419 | + ], |
|
| 420 | + 'data' => $champs |
|
| 421 | + ] |
|
| 422 | + ); |
|
| 423 | + |
|
| 424 | + // Notifications |
|
| 425 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 426 | + $notifications( |
|
| 427 | + 'article_instituer', |
|
| 428 | + $id_article, |
|
| 429 | + [ |
|
| 430 | + 'statut' => $statut, |
|
| 431 | + 'statut_ancien' => $statut_ancien, |
|
| 432 | + 'date' => $date, |
|
| 433 | + 'date_ancienne' => $date_ancienne, |
|
| 434 | + 'id_parent_ancien' => $id_rubrique, |
|
| 435 | + 'champs' => $champs, |
|
| 436 | + ] |
|
| 437 | + ); |
|
| 438 | + $notifications( |
|
| 439 | + 'objet_instituer', |
|
| 440 | + $id_article, |
|
| 441 | + [ |
|
| 442 | + 'objet' => 'article', |
|
| 443 | + 'id_objet' => $id_article, |
|
| 444 | + 'statut' => $statut, |
|
| 445 | + 'statut_ancien' => $statut_ancien, |
|
| 446 | + 'date' => $date, |
|
| 447 | + 'date_ancienne' => $date_ancienne, |
|
| 448 | + 'id_parent_ancien' => $id_rubrique, |
|
| 449 | + 'champs' => $champs, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + // Rétro-compat |
|
| 454 | + $notifications( |
|
| 455 | + 'instituerarticle', |
|
| 456 | + $id_article, |
|
| 457 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 458 | + ); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + return ''; // pas d'erreur |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -483,37 +483,37 @@ discard block |
||
| 483 | 483 | */ |
| 484 | 484 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 485 | 485 | |
| 486 | - // Si on deplace l'article |
|
| 487 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 488 | - if (isset($champs['id_rubrique'])) { |
|
| 489 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 490 | - |
|
| 491 | - $langue = $row_rub['lang']; |
|
| 492 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 493 | - if ( |
|
| 494 | - sql_fetsel( |
|
| 495 | - '1', |
|
| 496 | - 'spip_articles', |
|
| 497 | - 'id_article=' . (int) $id_article . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 498 | - ) |
|
| 499 | - ) { |
|
| 500 | - $champs['lang'] = $langue; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - if (!$champs) { |
|
| 505 | - return; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - sql_updateq('spip_articles', $champs, 'id_article=' . (int) $id_article); |
|
| 509 | - |
|
| 510 | - // Changer le statut des rubriques concernees |
|
| 511 | - |
|
| 512 | - if ($cond) { |
|
| 513 | - include_spip('inc/rubriques'); |
|
| 514 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' && isset($champs['date']) && strtotime((string) $champs['date']) < time()) ? $champs['date'] : false; |
|
| 515 | - calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 516 | - } |
|
| 486 | + // Si on deplace l'article |
|
| 487 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 488 | + if (isset($champs['id_rubrique'])) { |
|
| 489 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 490 | + |
|
| 491 | + $langue = $row_rub['lang']; |
|
| 492 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 493 | + if ( |
|
| 494 | + sql_fetsel( |
|
| 495 | + '1', |
|
| 496 | + 'spip_articles', |
|
| 497 | + 'id_article=' . (int) $id_article . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 498 | + ) |
|
| 499 | + ) { |
|
| 500 | + $champs['lang'] = $langue; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if (!$champs) { |
|
| 505 | + return; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + sql_updateq('spip_articles', $champs, 'id_article=' . (int) $id_article); |
|
| 509 | + |
|
| 510 | + // Changer le statut des rubriques concernees |
|
| 511 | + |
|
| 512 | + if ($cond) { |
|
| 513 | + include_spip('inc/rubriques'); |
|
| 514 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' && isset($champs['date']) && strtotime((string) $champs['date']) < time()) ? $champs['date'] : false; |
|
| 515 | + calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -522,10 +522,10 @@ discard block |
||
| 522 | 522 | * @return void |
| 523 | 523 | */ |
| 524 | 524 | function trop_longs_articles() { |
| 525 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 526 | - foreach ($plus as $n => $t) { |
|
| 527 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', (string) $t); |
|
| 528 | - } |
|
| 529 | - set_request('texte', implode('', $plus) . _request('texte')); |
|
| 530 | - } |
|
| 525 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 526 | + foreach ($plus as $n => $t) { |
|
| 527 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', (string) $t); |
|
| 528 | + } |
|
| 529 | + set_request('texte', implode('', $plus) . _request('texte')); |
|
| 530 | + } |
|
| 531 | 531 | } |