@@ -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 | |
| 23 | 23 | /** |
@@ -39,36 +39,36 @@ discard block |
||
| 39 | 39 | * Liste (identifiant de l'article, texte d'erreur éventuel) |
| 40 | 40 | */ |
| 41 | 41 | function action_editer_article_dist($arg = null) { |
| 42 | - include_spip('inc/autoriser'); |
|
| 43 | - $err = ''; |
|
| 44 | - if (is_null($arg)) { |
|
| 45 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | - $arg = $securiser_action(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // si id_article 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_article = intval($arg)) { |
|
| 52 | - $id_parent = _request('id_parent'); |
|
| 53 | - if (!$id_parent) { |
|
| 54 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | - } else { |
|
| 58 | - $id_article = article_inserer($id_parent); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - if ($id_article > 0) { |
|
| 64 | - $err = article_modifier($id_article); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if ($err) { |
|
| 68 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return [$id_article, $err]; |
|
| 42 | + include_spip('inc/autoriser'); |
|
| 43 | + $err = ''; |
|
| 44 | + if (is_null($arg)) { |
|
| 45 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $arg = $securiser_action(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // si id_article 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_article = intval($arg)) { |
|
| 52 | + $id_parent = _request('id_parent'); |
|
| 53 | + if (!$id_parent) { |
|
| 54 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | + } else { |
|
| 58 | + $id_article = article_inserer($id_parent); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + if ($id_article > 0) { |
|
| 64 | + $err = article_modifier($id_article); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if ($err) { |
|
| 68 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return [$id_article, $err]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -90,50 +90,50 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | function article_modifier($id_article, $set = null) { |
| 92 | 92 | |
| 93 | - // unifier $texte en cas de texte trop long |
|
| 94 | - trop_longs_articles(); |
|
| 95 | - |
|
| 96 | - include_spip('inc/modifier'); |
|
| 97 | - include_spip('inc/filtres'); |
|
| 98 | - $c = collecter_requests( |
|
| 99 | - // include list |
|
| 100 | - objet_info('article', 'champs_editables'), |
|
| 101 | - // exclude list |
|
| 102 | - ['date', 'statut', 'id_parent'], |
|
| 103 | - // donnees eventuellement fournies |
|
| 104 | - $set |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | - $invalideur = $indexation = false; |
|
| 110 | - if ($t == 'publie') { |
|
| 111 | - $invalideur = "id='article/$id_article'"; |
|
| 112 | - $indexation = true; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( |
|
| 116 | - $err = objet_modifier_champs( |
|
| 117 | - 'article', |
|
| 118 | - $id_article, |
|
| 119 | - [ |
|
| 120 | - 'data' => $set, |
|
| 121 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | - 'invalideur' => $invalideur, |
|
| 123 | - 'indexation' => $indexation, |
|
| 124 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | - ], |
|
| 126 | - $c |
|
| 127 | - ) |
|
| 128 | - ) { |
|
| 129 | - return $err; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Modification de statut, changement de rubrique ? |
|
| 133 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | - $err = article_instituer($id_article, $c); |
|
| 135 | - |
|
| 136 | - return $err; |
|
| 93 | + // unifier $texte en cas de texte trop long |
|
| 94 | + trop_longs_articles(); |
|
| 95 | + |
|
| 96 | + include_spip('inc/modifier'); |
|
| 97 | + include_spip('inc/filtres'); |
|
| 98 | + $c = collecter_requests( |
|
| 99 | + // include list |
|
| 100 | + objet_info('article', 'champs_editables'), |
|
| 101 | + // exclude list |
|
| 102 | + ['date', 'statut', 'id_parent'], |
|
| 103 | + // donnees eventuellement fournies |
|
| 104 | + $set |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | + $invalideur = $indexation = false; |
|
| 110 | + if ($t == 'publie') { |
|
| 111 | + $invalideur = "id='article/$id_article'"; |
|
| 112 | + $indexation = true; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( |
|
| 116 | + $err = objet_modifier_champs( |
|
| 117 | + 'article', |
|
| 118 | + $id_article, |
|
| 119 | + [ |
|
| 120 | + 'data' => $set, |
|
| 121 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | + 'invalideur' => $invalideur, |
|
| 123 | + 'indexation' => $indexation, |
|
| 124 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | + ], |
|
| 126 | + $c |
|
| 127 | + ) |
|
| 128 | + ) { |
|
| 129 | + return $err; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Modification de statut, changement de rubrique ? |
|
| 133 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | + $err = article_instituer($id_article, $c); |
|
| 135 | + |
|
| 136 | + return $err; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -169,120 +169,120 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function article_inserer($id_rubrique, $set = null) { |
| 171 | 171 | |
| 172 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | - // dans la premiere rubrique racine |
|
| 174 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | - $id_rubrique = $row['id_rubrique']; |
|
| 177 | - } else { |
|
| 178 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | - $lang_rub = $row['lang'] ?? ''; |
|
| 185 | - |
|
| 186 | - $lang = ''; |
|
| 187 | - $choisie = 'non'; |
|
| 188 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | - // ou a defaut celle de la rubrique |
|
| 191 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | - if ( |
|
| 193 | - !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | - 'spip_articles', |
|
| 195 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | - if ( |
|
| 200 | - in_array( |
|
| 201 | - $GLOBALS['spip_lang'], |
|
| 202 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | - ) |
|
| 204 | - ) { |
|
| 205 | - $lang = $GLOBALS['spip_lang']; |
|
| 206 | - $choisie = 'oui'; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!$lang) { |
|
| 211 | - $choisie = 'non'; |
|
| 212 | - $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $champs = [ |
|
| 216 | - 'id_rubrique' => $id_rubrique, |
|
| 217 | - 'id_secteur' => $id_secteur, |
|
| 218 | - 'statut' => 'prepa', |
|
| 219 | - 'date' => date('Y-m-d H:i:s'), |
|
| 220 | - 'lang' => $lang, |
|
| 221 | - 'langue_choisie' => $choisie |
|
| 222 | - ]; |
|
| 223 | - |
|
| 224 | - if ($set) { |
|
| 225 | - $champs = array_merge($champs, $set); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Envoyer aux plugins |
|
| 229 | - $champs = pipeline( |
|
| 230 | - 'pre_insertion', |
|
| 231 | - [ |
|
| 232 | - 'args' => [ |
|
| 233 | - 'table' => 'spip_articles', |
|
| 234 | - ], |
|
| 235 | - 'data' => $champs |
|
| 236 | - ] |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | - |
|
| 241 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | - if ($id_article > 0) { |
|
| 243 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | - : _request('id_auteur')); |
|
| 246 | - if ($id_auteur) { |
|
| 247 | - include_spip('action/editer_auteur'); |
|
| 248 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - pipeline( |
|
| 253 | - 'post_insertion', |
|
| 254 | - [ |
|
| 255 | - 'args' => [ |
|
| 256 | - 'table' => 'spip_articles', |
|
| 257 | - 'id_objet' => $id_article |
|
| 258 | - ], |
|
| 259 | - 'data' => $champs |
|
| 260 | - ] |
|
| 261 | - ); |
|
| 172 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | + // dans la premiere rubrique racine |
|
| 174 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | + $id_rubrique = $row['id_rubrique']; |
|
| 177 | + } else { |
|
| 178 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | + $lang_rub = $row['lang'] ?? ''; |
|
| 185 | + |
|
| 186 | + $lang = ''; |
|
| 187 | + $choisie = 'non'; |
|
| 188 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | + // ou a defaut celle de la rubrique |
|
| 191 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | + if ( |
|
| 193 | + !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | + 'spip_articles', |
|
| 195 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | + if ( |
|
| 200 | + in_array( |
|
| 201 | + $GLOBALS['spip_lang'], |
|
| 202 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | + ) |
|
| 204 | + ) { |
|
| 205 | + $lang = $GLOBALS['spip_lang']; |
|
| 206 | + $choisie = 'oui'; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!$lang) { |
|
| 211 | + $choisie = 'non'; |
|
| 212 | + $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $champs = [ |
|
| 216 | + 'id_rubrique' => $id_rubrique, |
|
| 217 | + 'id_secteur' => $id_secteur, |
|
| 218 | + 'statut' => 'prepa', |
|
| 219 | + 'date' => date('Y-m-d H:i:s'), |
|
| 220 | + 'lang' => $lang, |
|
| 221 | + 'langue_choisie' => $choisie |
|
| 222 | + ]; |
|
| 223 | + |
|
| 224 | + if ($set) { |
|
| 225 | + $champs = array_merge($champs, $set); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Envoyer aux plugins |
|
| 229 | + $champs = pipeline( |
|
| 230 | + 'pre_insertion', |
|
| 231 | + [ |
|
| 232 | + 'args' => [ |
|
| 233 | + 'table' => 'spip_articles', |
|
| 234 | + ], |
|
| 235 | + 'data' => $champs |
|
| 236 | + ] |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | + |
|
| 241 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | + if ($id_article > 0) { |
|
| 243 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | + : _request('id_auteur')); |
|
| 246 | + if ($id_auteur) { |
|
| 247 | + include_spip('action/editer_auteur'); |
|
| 248 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + pipeline( |
|
| 253 | + 'post_insertion', |
|
| 254 | + [ |
|
| 255 | + 'args' => [ |
|
| 256 | + 'table' => 'spip_articles', |
|
| 257 | + 'id_objet' => $id_article |
|
| 258 | + ], |
|
| 259 | + 'data' => $champs |
|
| 260 | + ] |
|
| 261 | + ); |
|
| 262 | 262 | |
| 263 | - // Appeler une notification |
|
| 264 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 265 | - $notifications( |
|
| 266 | - 'article_inserer', |
|
| 267 | - $id_article, |
|
| 268 | - [ |
|
| 269 | - 'id_parent' => $id_rubrique, |
|
| 270 | - 'champs' => $champs, |
|
| 271 | - ] |
|
| 272 | - ); |
|
| 273 | - $notifications( |
|
| 274 | - 'objet_inserer', |
|
| 275 | - $id_article, |
|
| 276 | - [ |
|
| 277 | - 'objet' => 'article', |
|
| 278 | - 'id_objet' => $id_article, |
|
| 279 | - 'id_parent' => $id_rubrique, |
|
| 280 | - 'champs' => $champs, |
|
| 281 | - ] |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $id_article; |
|
| 263 | + // Appeler une notification |
|
| 264 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 265 | + $notifications( |
|
| 266 | + 'article_inserer', |
|
| 267 | + $id_article, |
|
| 268 | + [ |
|
| 269 | + 'id_parent' => $id_rubrique, |
|
| 270 | + 'champs' => $champs, |
|
| 271 | + ] |
|
| 272 | + ); |
|
| 273 | + $notifications( |
|
| 274 | + 'objet_inserer', |
|
| 275 | + $id_article, |
|
| 276 | + [ |
|
| 277 | + 'objet' => 'article', |
|
| 278 | + 'id_objet' => $id_article, |
|
| 279 | + 'id_parent' => $id_rubrique, |
|
| 280 | + 'champs' => $champs, |
|
| 281 | + ] |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $id_article; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | |
@@ -310,153 +310,153 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 312 | 312 | |
| 313 | - include_spip('inc/autoriser'); |
|
| 314 | - include_spip('inc/rubriques'); |
|
| 315 | - include_spip('inc/modifier'); |
|
| 316 | - |
|
| 317 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 318 | - $id_rubrique = $row['id_rubrique']; |
|
| 319 | - $statut_ancien = $statut = $row['statut']; |
|
| 320 | - $date_ancienne = $date = $row['date']; |
|
| 321 | - $champs = []; |
|
| 322 | - |
|
| 323 | - $d = $c['date'] ?? null; |
|
| 324 | - $s = $c['statut'] ?? $statut; |
|
| 325 | - |
|
| 326 | - // cf autorisations dans inc/instituer_article |
|
| 327 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 328 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 329 | - $statut = $champs['statut'] = $s; |
|
| 330 | - } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 331 | - $statut = $champs['statut'] = $s; |
|
| 332 | - } else { |
|
| 333 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - // En cas de publication, fixer la date a "maintenant" |
|
| 337 | - // sauf si $c commande autre chose |
|
| 338 | - // ou si l'article est deja date dans le futur |
|
| 339 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 340 | - if ( |
|
| 341 | - $champs['statut'] == 'publie' |
|
| 342 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 343 | - ) { |
|
| 344 | - if ($d or strtotime($d = $date) > time()) { |
|
| 345 | - $champs['date'] = $date = $d; |
|
| 346 | - } else { |
|
| 347 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // Verifier que la rubrique demandee existe et est differente |
|
| 353 | - // de la rubrique actuelle |
|
| 354 | - if ( |
|
| 355 | - isset($c['id_parent']) |
|
| 356 | - and $id_parent = $c['id_parent'] |
|
| 357 | - and $id_parent != $id_rubrique |
|
| 358 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 359 | - ) { |
|
| 360 | - $champs['id_rubrique'] = $id_parent; |
|
| 361 | - |
|
| 362 | - // si l'article etait publie |
|
| 363 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 364 | - // repasser l'article en statut 'propose'. |
|
| 365 | - if ( |
|
| 366 | - $statut == 'publie' |
|
| 367 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 368 | - ) { |
|
| 369 | - $champs['statut'] = 'prop'; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // Envoyer aux plugins |
|
| 374 | - $champs = pipeline( |
|
| 375 | - 'pre_edition', |
|
| 376 | - [ |
|
| 377 | - 'args' => [ |
|
| 378 | - 'table' => 'spip_articles', |
|
| 379 | - 'id_objet' => $id_article, |
|
| 380 | - 'action' => 'instituer', |
|
| 381 | - 'statut_ancien' => $statut_ancien, |
|
| 382 | - 'date_ancienne' => $date_ancienne, |
|
| 383 | - ], |
|
| 384 | - 'data' => $champs |
|
| 385 | - ] |
|
| 386 | - ); |
|
| 387 | - |
|
| 388 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 389 | - return ''; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // Envoyer les modifs. |
|
| 393 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 394 | - |
|
| 395 | - // Invalider les caches |
|
| 396 | - include_spip('inc/invalideur'); |
|
| 397 | - suivre_invalideur("id='article/$id_article'"); |
|
| 398 | - |
|
| 399 | - if ($date) { |
|
| 400 | - $t = strtotime($date); |
|
| 401 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 402 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 403 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - // Pipeline |
|
| 408 | - pipeline( |
|
| 409 | - 'post_edition', |
|
| 410 | - [ |
|
| 411 | - 'args' => [ |
|
| 412 | - 'table' => 'spip_articles', |
|
| 413 | - 'id_objet' => $id_article, |
|
| 414 | - 'action' => 'instituer', |
|
| 415 | - 'statut_ancien' => $statut_ancien, |
|
| 416 | - 'date_ancienne' => $date_ancienne, |
|
| 417 | - ], |
|
| 418 | - 'data' => $champs |
|
| 419 | - ] |
|
| 420 | - ); |
|
| 421 | - |
|
| 422 | - // Notifications |
|
| 423 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 424 | - $notifications( |
|
| 425 | - 'article_instituer', |
|
| 426 | - $id_article, |
|
| 427 | - [ |
|
| 428 | - 'statut' => $statut, |
|
| 429 | - 'statut_ancien' => $statut_ancien, |
|
| 430 | - 'date' => $date, |
|
| 431 | - 'date_ancienne' => $date_ancienne, |
|
| 432 | - 'id_parent_ancien' => $id_rubrique, |
|
| 433 | - 'champs' => $champs, |
|
| 434 | - ] |
|
| 435 | - ); |
|
| 436 | - $notifications( |
|
| 437 | - 'objet_instituer', |
|
| 438 | - $id_article, |
|
| 439 | - [ |
|
| 440 | - 'objet' => 'article', |
|
| 441 | - 'id_objet' => $id_article, |
|
| 442 | - 'statut' => $statut, |
|
| 443 | - 'statut_ancien' => $statut_ancien, |
|
| 444 | - 'date' => $date, |
|
| 445 | - 'date_ancienne' => $date_ancienne, |
|
| 446 | - 'id_parent_ancien' => $id_rubrique, |
|
| 447 | - 'champs' => $champs, |
|
| 448 | - ] |
|
| 449 | - ); |
|
| 313 | + include_spip('inc/autoriser'); |
|
| 314 | + include_spip('inc/rubriques'); |
|
| 315 | + include_spip('inc/modifier'); |
|
| 316 | + |
|
| 317 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 318 | + $id_rubrique = $row['id_rubrique']; |
|
| 319 | + $statut_ancien = $statut = $row['statut']; |
|
| 320 | + $date_ancienne = $date = $row['date']; |
|
| 321 | + $champs = []; |
|
| 322 | + |
|
| 323 | + $d = $c['date'] ?? null; |
|
| 324 | + $s = $c['statut'] ?? $statut; |
|
| 325 | + |
|
| 326 | + // cf autorisations dans inc/instituer_article |
|
| 327 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 328 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 329 | + $statut = $champs['statut'] = $s; |
|
| 330 | + } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 331 | + $statut = $champs['statut'] = $s; |
|
| 332 | + } else { |
|
| 333 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + // En cas de publication, fixer la date a "maintenant" |
|
| 337 | + // sauf si $c commande autre chose |
|
| 338 | + // ou si l'article est deja date dans le futur |
|
| 339 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 340 | + if ( |
|
| 341 | + $champs['statut'] == 'publie' |
|
| 342 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 343 | + ) { |
|
| 344 | + if ($d or strtotime($d = $date) > time()) { |
|
| 345 | + $champs['date'] = $date = $d; |
|
| 346 | + } else { |
|
| 347 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // Verifier que la rubrique demandee existe et est differente |
|
| 353 | + // de la rubrique actuelle |
|
| 354 | + if ( |
|
| 355 | + isset($c['id_parent']) |
|
| 356 | + and $id_parent = $c['id_parent'] |
|
| 357 | + and $id_parent != $id_rubrique |
|
| 358 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 359 | + ) { |
|
| 360 | + $champs['id_rubrique'] = $id_parent; |
|
| 361 | + |
|
| 362 | + // si l'article etait publie |
|
| 363 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 364 | + // repasser l'article en statut 'propose'. |
|
| 365 | + if ( |
|
| 366 | + $statut == 'publie' |
|
| 367 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 368 | + ) { |
|
| 369 | + $champs['statut'] = 'prop'; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // Envoyer aux plugins |
|
| 374 | + $champs = pipeline( |
|
| 375 | + 'pre_edition', |
|
| 376 | + [ |
|
| 377 | + 'args' => [ |
|
| 378 | + 'table' => 'spip_articles', |
|
| 379 | + 'id_objet' => $id_article, |
|
| 380 | + 'action' => 'instituer', |
|
| 381 | + 'statut_ancien' => $statut_ancien, |
|
| 382 | + 'date_ancienne' => $date_ancienne, |
|
| 383 | + ], |
|
| 384 | + 'data' => $champs |
|
| 385 | + ] |
|
| 386 | + ); |
|
| 387 | + |
|
| 388 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 389 | + return ''; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // Envoyer les modifs. |
|
| 393 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 394 | + |
|
| 395 | + // Invalider les caches |
|
| 396 | + include_spip('inc/invalideur'); |
|
| 397 | + suivre_invalideur("id='article/$id_article'"); |
|
| 398 | + |
|
| 399 | + if ($date) { |
|
| 400 | + $t = strtotime($date); |
|
| 401 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 402 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 403 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + // Pipeline |
|
| 408 | + pipeline( |
|
| 409 | + 'post_edition', |
|
| 410 | + [ |
|
| 411 | + 'args' => [ |
|
| 412 | + 'table' => 'spip_articles', |
|
| 413 | + 'id_objet' => $id_article, |
|
| 414 | + 'action' => 'instituer', |
|
| 415 | + 'statut_ancien' => $statut_ancien, |
|
| 416 | + 'date_ancienne' => $date_ancienne, |
|
| 417 | + ], |
|
| 418 | + 'data' => $champs |
|
| 419 | + ] |
|
| 420 | + ); |
|
| 421 | + |
|
| 422 | + // Notifications |
|
| 423 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 424 | + $notifications( |
|
| 425 | + 'article_instituer', |
|
| 426 | + $id_article, |
|
| 427 | + [ |
|
| 428 | + 'statut' => $statut, |
|
| 429 | + 'statut_ancien' => $statut_ancien, |
|
| 430 | + 'date' => $date, |
|
| 431 | + 'date_ancienne' => $date_ancienne, |
|
| 432 | + 'id_parent_ancien' => $id_rubrique, |
|
| 433 | + 'champs' => $champs, |
|
| 434 | + ] |
|
| 435 | + ); |
|
| 436 | + $notifications( |
|
| 437 | + 'objet_instituer', |
|
| 438 | + $id_article, |
|
| 439 | + [ |
|
| 440 | + 'objet' => 'article', |
|
| 441 | + 'id_objet' => $id_article, |
|
| 442 | + 'statut' => $statut, |
|
| 443 | + 'statut_ancien' => $statut_ancien, |
|
| 444 | + 'date' => $date, |
|
| 445 | + 'date_ancienne' => $date_ancienne, |
|
| 446 | + 'id_parent_ancien' => $id_rubrique, |
|
| 447 | + 'champs' => $champs, |
|
| 448 | + ] |
|
| 449 | + ); |
|
| 450 | 450 | |
| 451 | - // Rétro-compat |
|
| 452 | - $notifications( |
|
| 453 | - 'instituerarticle', |
|
| 454 | - $id_article, |
|
| 455 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 456 | - ); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return ''; // pas d'erreur |
|
| 451 | + // Rétro-compat |
|
| 452 | + $notifications( |
|
| 453 | + 'instituerarticle', |
|
| 454 | + $id_article, |
|
| 455 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return ''; // pas d'erreur |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -481,37 +481,37 @@ discard block |
||
| 481 | 481 | */ |
| 482 | 482 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 483 | 483 | |
| 484 | - // Si on deplace l'article |
|
| 485 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 486 | - if (isset($champs['id_rubrique'])) { |
|
| 487 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 488 | - |
|
| 489 | - $langue = $row_rub['lang']; |
|
| 490 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 491 | - if ( |
|
| 492 | - sql_fetsel( |
|
| 493 | - '1', |
|
| 494 | - 'spip_articles', |
|
| 495 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 496 | - ) |
|
| 497 | - ) { |
|
| 498 | - $champs['lang'] = $langue; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if (!$champs) { |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 507 | - |
|
| 508 | - // Changer le statut des rubriques concernees |
|
| 509 | - |
|
| 510 | - if ($cond) { |
|
| 511 | - include_spip('inc/rubriques'); |
|
| 512 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 513 | - calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 514 | - } |
|
| 484 | + // Si on deplace l'article |
|
| 485 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 486 | + if (isset($champs['id_rubrique'])) { |
|
| 487 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 488 | + |
|
| 489 | + $langue = $row_rub['lang']; |
|
| 490 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 491 | + if ( |
|
| 492 | + sql_fetsel( |
|
| 493 | + '1', |
|
| 494 | + 'spip_articles', |
|
| 495 | + 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 496 | + ) |
|
| 497 | + ) { |
|
| 498 | + $champs['lang'] = $langue; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if (!$champs) { |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 507 | + |
|
| 508 | + // Changer le statut des rubriques concernees |
|
| 509 | + |
|
| 510 | + if ($cond) { |
|
| 511 | + include_spip('inc/rubriques'); |
|
| 512 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 513 | + calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** |
@@ -520,10 +520,10 @@ discard block |
||
| 520 | 520 | * @return void |
| 521 | 521 | */ |
| 522 | 522 | function trop_longs_articles() { |
| 523 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 524 | - foreach ($plus as $n => $t) { |
|
| 525 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 526 | - } |
|
| 527 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 528 | - } |
|
| 523 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 524 | + foreach ($plus as $n => $t) { |
|
| 525 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 526 | + } |
|
| 527 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 528 | + } |
|
| 529 | 529 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 55 | - |
|
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - '&' |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - redirige_par_entete($redirect); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return [$id_rubrique, $err]; |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | + |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + '&' |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + redirige_par_entete($redirect); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return [$id_rubrique, $err]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -80,64 +80,64 @@ discard block |
||
| 80 | 80 | * Identifiant de la rubrique crée |
| 81 | 81 | */ |
| 82 | 82 | function rubrique_inserer($id_parent, $set = null) { |
| 83 | - $champs = [ |
|
| 84 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | - 'id_parent' => intval($id_parent), |
|
| 86 | - 'statut' => 'prepa' |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if ($set) { |
|
| 90 | - $champs = array_merge($champs, $set); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Envoyer aux plugins |
|
| 94 | - $champs = pipeline( |
|
| 95 | - 'pre_insertion', |
|
| 96 | - [ |
|
| 97 | - 'args' => [ |
|
| 98 | - 'table' => 'spip_rubriques', |
|
| 99 | - ], |
|
| 100 | - 'data' => $champs |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | - pipeline( |
|
| 106 | - 'post_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_rubriques', |
|
| 110 | - 'id_objet' => $id_rubrique |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - propager_les_secteurs(); |
|
| 116 | - calculer_langues_rubriques(); |
|
| 117 | - |
|
| 118 | - // Appeler une notification |
|
| 119 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | - $notifications( |
|
| 121 | - 'rubrique_inserer', |
|
| 122 | - $id_rubrique, |
|
| 123 | - [ |
|
| 124 | - 'id_parent' => $id_parent, |
|
| 125 | - 'champs' => $champs, |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $notifications( |
|
| 129 | - 'objet_inserer', |
|
| 130 | - $id_rubrique, |
|
| 131 | - [ |
|
| 132 | - 'objet' => 'rubrique', |
|
| 133 | - 'id_objet' => $id_rubrique, |
|
| 134 | - 'id_parent' => $id_parent, |
|
| 135 | - 'champs' => $champs, |
|
| 136 | - ] |
|
| 137 | - ); |
|
| 138 | - } |
|
| 83 | + $champs = [ |
|
| 84 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | + 'id_parent' => intval($id_parent), |
|
| 86 | + 'statut' => 'prepa' |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if ($set) { |
|
| 90 | + $champs = array_merge($champs, $set); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Envoyer aux plugins |
|
| 94 | + $champs = pipeline( |
|
| 95 | + 'pre_insertion', |
|
| 96 | + [ |
|
| 97 | + 'args' => [ |
|
| 98 | + 'table' => 'spip_rubriques', |
|
| 99 | + ], |
|
| 100 | + 'data' => $champs |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | + pipeline( |
|
| 106 | + 'post_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_rubriques', |
|
| 110 | + 'id_objet' => $id_rubrique |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + propager_les_secteurs(); |
|
| 116 | + calculer_langues_rubriques(); |
|
| 117 | + |
|
| 118 | + // Appeler une notification |
|
| 119 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | + $notifications( |
|
| 121 | + 'rubrique_inserer', |
|
| 122 | + $id_rubrique, |
|
| 123 | + [ |
|
| 124 | + 'id_parent' => $id_parent, |
|
| 125 | + 'champs' => $champs, |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $notifications( |
|
| 129 | + 'objet_inserer', |
|
| 130 | + $id_rubrique, |
|
| 131 | + [ |
|
| 132 | + 'objet' => 'rubrique', |
|
| 133 | + 'id_objet' => $id_rubrique, |
|
| 134 | + 'id_parent' => $id_parent, |
|
| 135 | + 'champs' => $champs, |
|
| 136 | + ] |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return $id_rubrique; |
|
| 140 | + return $id_rubrique; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,46 +153,46 @@ discard block |
||
| 153 | 153 | * - chaîne : texte d'un message d'erreur |
| 154 | 154 | */ |
| 155 | 155 | function rubrique_modifier($id_rubrique, $set = null) { |
| 156 | - include_spip('inc/autoriser'); |
|
| 157 | - include_spip('inc/filtres'); |
|
| 158 | - |
|
| 159 | - include_spip('inc/modifier'); |
|
| 160 | - $c = collecter_requests( |
|
| 161 | - // include list |
|
| 162 | - objet_info('rubrique', 'champs_editables'), |
|
| 163 | - // exclude list |
|
| 164 | - ['id_parent', 'confirme_deplace'], |
|
| 165 | - // donnees eventuellement fournies |
|
| 166 | - $set |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - if ( |
|
| 170 | - $err = objet_modifier_champs( |
|
| 171 | - 'rubrique', |
|
| 172 | - $id_rubrique, |
|
| 173 | - [ |
|
| 174 | - 'data' => $set, |
|
| 175 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | - ], |
|
| 177 | - $c |
|
| 178 | - ) |
|
| 179 | - ) { |
|
| 180 | - return $err; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | - // Deplacer la rubrique |
|
| 185 | - if (isset($c['id_parent'])) { |
|
| 186 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // invalider les caches marques de cette rubrique |
|
| 190 | - include_spip('inc/invalideur'); |
|
| 191 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | - // et celui de menu_rubriques |
|
| 193 | - effacer_meta('date_calcul_rubriques'); |
|
| 194 | - |
|
| 195 | - return $err; |
|
| 156 | + include_spip('inc/autoriser'); |
|
| 157 | + include_spip('inc/filtres'); |
|
| 158 | + |
|
| 159 | + include_spip('inc/modifier'); |
|
| 160 | + $c = collecter_requests( |
|
| 161 | + // include list |
|
| 162 | + objet_info('rubrique', 'champs_editables'), |
|
| 163 | + // exclude list |
|
| 164 | + ['id_parent', 'confirme_deplace'], |
|
| 165 | + // donnees eventuellement fournies |
|
| 166 | + $set |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + if ( |
|
| 170 | + $err = objet_modifier_champs( |
|
| 171 | + 'rubrique', |
|
| 172 | + $id_rubrique, |
|
| 173 | + [ |
|
| 174 | + 'data' => $set, |
|
| 175 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | + ], |
|
| 177 | + $c |
|
| 178 | + ) |
|
| 179 | + ) { |
|
| 180 | + return $err; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | + // Deplacer la rubrique |
|
| 185 | + if (isset($c['id_parent'])) { |
|
| 186 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // invalider les caches marques de cette rubrique |
|
| 190 | + include_spip('inc/invalideur'); |
|
| 191 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | + // et celui de menu_rubriques |
|
| 193 | + effacer_meta('date_calcul_rubriques'); |
|
| 194 | + |
|
| 195 | + return $err; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -215,29 +215,29 @@ discard block |
||
| 215 | 215 | * false si la confirmation du déplacement n'est pas présente |
| 216 | 216 | */ |
| 217 | 217 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 218 | - if (!sql_table_exists('spip_breves')) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( |
|
| 231 | - $id_secteur = sql_getfetsel( |
|
| 232 | - 'id_secteur', |
|
| 233 | - 'spip_rubriques', |
|
| 234 | - "id_rubrique=$id_parent" |
|
| 235 | - ) |
|
| 236 | - ) { |
|
| 237 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return true; |
|
| 218 | + if (!sql_table_exists('spip_breves')) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( |
|
| 231 | + $id_secteur = sql_getfetsel( |
|
| 232 | + 'id_secteur', |
|
| 233 | + 'spip_rubriques', |
|
| 234 | + "id_rubrique=$id_parent" |
|
| 235 | + ) |
|
| 236 | + ) { |
|
| 237 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return true; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | |
@@ -259,72 +259,72 @@ discard block |
||
| 259 | 259 | * Chaîne : texte du message d'erreur |
| 260 | 260 | */ |
| 261 | 261 | function rubrique_instituer($id_rubrique, $c) { |
| 262 | - // traitement de la rubrique parente |
|
| 263 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | - // qu'on n'administre pas. |
|
| 265 | - |
|
| 266 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | - $id_parent = intval($id_parent); |
|
| 268 | - $filles = calcul_branche_in($id_rubrique); |
|
| 269 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | - } else { |
|
| 272 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | - $old_parent = $s['id_parent']; |
|
| 274 | - |
|
| 275 | - if ( |
|
| 276 | - !($id_parent != $old_parent |
|
| 277 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | - ) |
|
| 281 | - ) { |
|
| 282 | - if ($s['statut'] != 'prepa') { |
|
| 283 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | - } |
|
| 285 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | - $statut_ancien = $s['statut']; |
|
| 287 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - propager_les_secteurs(); |
|
| 291 | - |
|
| 292 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | - if ($statut_ancien == 'publie') { |
|
| 294 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | - } |
|
| 296 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | - // invalider le cache de leur menu |
|
| 298 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | - effacer_meta('date_calcul_rubriques'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - calculer_langues_rubriques(); |
|
| 262 | + // traitement de la rubrique parente |
|
| 263 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | + // qu'on n'administre pas. |
|
| 265 | + |
|
| 266 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | + $id_parent = intval($id_parent); |
|
| 268 | + $filles = calcul_branche_in($id_rubrique); |
|
| 269 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | + } else { |
|
| 272 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | + $old_parent = $s['id_parent']; |
|
| 274 | + |
|
| 275 | + if ( |
|
| 276 | + !($id_parent != $old_parent |
|
| 277 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | + ) |
|
| 281 | + ) { |
|
| 282 | + if ($s['statut'] != 'prepa') { |
|
| 283 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | + } |
|
| 285 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | + $statut_ancien = $s['statut']; |
|
| 287 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + propager_les_secteurs(); |
|
| 291 | + |
|
| 292 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | + if ($statut_ancien == 'publie') { |
|
| 294 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | + } |
|
| 296 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | + // invalider le cache de leur menu |
|
| 298 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | + effacer_meta('date_calcul_rubriques'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + calculer_langues_rubriques(); |
|
| 303 | 303 | |
| 304 | - // Appeler une notification |
|
| 305 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | - $notifications( |
|
| 307 | - 'rubrique_instituer', |
|
| 308 | - $id_rubrique, |
|
| 309 | - [ |
|
| 310 | - 'statut_ancien' => $statut_ancien, |
|
| 311 | - 'id_parent_ancien' => $old_parent, |
|
| 312 | - ] |
|
| 313 | - ); |
|
| 314 | - $notifications( |
|
| 315 | - 'objet_instituer', |
|
| 316 | - $id_rubrique, |
|
| 317 | - [ |
|
| 318 | - 'objet' => 'rubrique', |
|
| 319 | - 'id_objet' => $id_rubrique, |
|
| 320 | - 'statut_ancien' => $statut_ancien, |
|
| 321 | - 'id_parent_ancien' => $old_parent, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return ''; // pas d'erreur |
|
| 304 | + // Appeler une notification |
|
| 305 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | + $notifications( |
|
| 307 | + 'rubrique_instituer', |
|
| 308 | + $id_rubrique, |
|
| 309 | + [ |
|
| 310 | + 'statut_ancien' => $statut_ancien, |
|
| 311 | + 'id_parent_ancien' => $old_parent, |
|
| 312 | + ] |
|
| 313 | + ); |
|
| 314 | + $notifications( |
|
| 315 | + 'objet_instituer', |
|
| 316 | + $id_rubrique, |
|
| 317 | + [ |
|
| 318 | + 'objet' => 'rubrique', |
|
| 319 | + 'id_objet' => $id_rubrique, |
|
| 320 | + 'statut_ancien' => $statut_ancien, |
|
| 321 | + 'id_parent_ancien' => $old_parent, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return ''; // pas d'erreur |
|
| 330 | 330 | } |
@@ -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 | |
| 23 | 23 | /** |
@@ -37,41 +37,41 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | - # cf. GROS HACK |
|
| 50 | - # recuperer l'eventuel logo charge avant la creation |
|
| 51 | - # ils ont un id = 0-id_auteur de la session |
|
| 52 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | - foreach (['on', 'off'] as $type) { |
|
| 55 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | - if ($logo = reset($logo)) { |
|
| 57 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Enregistre l'envoi dans la BD |
|
| 65 | - $err = ''; |
|
| 66 | - if ($id_auteur > 0) { |
|
| 67 | - $err = auteur_modifier($id_auteur); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ($err) { |
|
| 71 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$id_auteur, $err]; |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | + # cf. GROS HACK |
|
| 50 | + # recuperer l'eventuel logo charge avant la creation |
|
| 51 | + # ils ont un id = 0-id_auteur de la session |
|
| 52 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | + foreach (['on', 'off'] as $type) { |
|
| 55 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | + if ($logo = reset($logo)) { |
|
| 57 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Enregistre l'envoi dans la BD |
|
| 65 | + $err = ''; |
|
| 66 | + if ($id_auteur > 0) { |
|
| 67 | + $err = auteur_modifier($id_auteur); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ($err) { |
|
| 71 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$id_auteur, $err]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -88,64 +88,64 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function auteur_inserer($source = null, $set = null) { |
| 90 | 90 | |
| 91 | - // Ce qu'on va demander comme modifications |
|
| 92 | - $champs = []; |
|
| 93 | - $champs['source'] = $source ?: 'spip'; |
|
| 94 | - |
|
| 95 | - $champs['login'] = ''; |
|
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | - $champs['webmestre'] = 'non'; |
|
| 98 | - if (empty($champs['imessage'])) { |
|
| 99 | - $champs['imessage'] = 'oui'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($set) { |
|
| 103 | - $champs = array_merge($champs, $set); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Envoyer aux plugins |
|
| 107 | - $champs = pipeline( |
|
| 108 | - 'pre_insertion', |
|
| 109 | - [ |
|
| 110 | - 'args' => [ |
|
| 111 | - 'table' => 'spip_auteurs', |
|
| 112 | - ], |
|
| 113 | - 'data' => $champs |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | - pipeline( |
|
| 118 | - 'post_insertion', |
|
| 119 | - [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'table' => 'spip_auteurs', |
|
| 122 | - 'id_objet' => $id_auteur |
|
| 123 | - ], |
|
| 124 | - 'data' => $champs |
|
| 125 | - ] |
|
| 126 | - ); |
|
| 91 | + // Ce qu'on va demander comme modifications |
|
| 92 | + $champs = []; |
|
| 93 | + $champs['source'] = $source ?: 'spip'; |
|
| 94 | + |
|
| 95 | + $champs['login'] = ''; |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | + $champs['webmestre'] = 'non'; |
|
| 98 | + if (empty($champs['imessage'])) { |
|
| 99 | + $champs['imessage'] = 'oui'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($set) { |
|
| 103 | + $champs = array_merge($champs, $set); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Envoyer aux plugins |
|
| 107 | + $champs = pipeline( |
|
| 108 | + 'pre_insertion', |
|
| 109 | + [ |
|
| 110 | + 'args' => [ |
|
| 111 | + 'table' => 'spip_auteurs', |
|
| 112 | + ], |
|
| 113 | + 'data' => $champs |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | + pipeline( |
|
| 118 | + 'post_insertion', |
|
| 119 | + [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'table' => 'spip_auteurs', |
|
| 122 | + 'id_objet' => $id_auteur |
|
| 123 | + ], |
|
| 124 | + 'data' => $champs |
|
| 125 | + ] |
|
| 126 | + ); |
|
| 127 | 127 | |
| 128 | - // Appeler une notification |
|
| 129 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 130 | - $notifications( |
|
| 131 | - 'auteur_inserer', |
|
| 132 | - $id_auteur, |
|
| 133 | - [ |
|
| 134 | - 'champs' => $champs, |
|
| 135 | - ] |
|
| 136 | - ); |
|
| 137 | - $notifications( |
|
| 138 | - 'objet_inserer', |
|
| 139 | - $id_auteur, |
|
| 140 | - [ |
|
| 141 | - 'objet' => 'auteur', |
|
| 142 | - 'id_objet' => $id_auteur, |
|
| 143 | - 'champs' => $champs, |
|
| 144 | - ] |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $id_auteur; |
|
| 128 | + // Appeler une notification |
|
| 129 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 130 | + $notifications( |
|
| 131 | + 'auteur_inserer', |
|
| 132 | + $id_auteur, |
|
| 133 | + [ |
|
| 134 | + 'champs' => $champs, |
|
| 135 | + ] |
|
| 136 | + ); |
|
| 137 | + $notifications( |
|
| 138 | + 'objet_inserer', |
|
| 139 | + $id_auteur, |
|
| 140 | + [ |
|
| 141 | + 'objet' => 'auteur', |
|
| 142 | + 'id_objet' => $id_auteur, |
|
| 143 | + 'champs' => $champs, |
|
| 144 | + ] |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $id_auteur; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
@@ -170,70 +170,70 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 172 | 172 | |
| 173 | - include_spip('inc/modifier'); |
|
| 174 | - include_spip('inc/filtres'); |
|
| 175 | - $c = collecter_requests( |
|
| 176 | - // include list |
|
| 177 | - objet_info('auteur', 'champs_editables'), |
|
| 178 | - // exclude list |
|
| 179 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 180 | - // donnees eventuellement fournies |
|
| 181 | - $set |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - if ( |
|
| 185 | - $err = objet_modifier_champs( |
|
| 186 | - 'auteur', |
|
| 187 | - $id_auteur, |
|
| 188 | - [ |
|
| 189 | - 'data' => $set, |
|
| 190 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 191 | - ], |
|
| 192 | - $c |
|
| 193 | - ) |
|
| 194 | - ) { |
|
| 195 | - return $err; |
|
| 196 | - } |
|
| 197 | - $session = $c; |
|
| 198 | - |
|
| 199 | - $err = ''; |
|
| 200 | - if (!$force_update) { |
|
| 201 | - // Modification de statut, changement de rubrique ? |
|
| 202 | - $c = collecter_requests( |
|
| 203 | - // include list |
|
| 204 | - [ |
|
| 205 | - 'statut', |
|
| 206 | - 'new_login', |
|
| 207 | - 'new_pass', |
|
| 208 | - 'login', |
|
| 209 | - 'pass', |
|
| 210 | - 'webmestre', |
|
| 211 | - 'restreintes', |
|
| 212 | - 'id_parent' |
|
| 213 | - ], |
|
| 214 | - // exclude list |
|
| 215 | - [], |
|
| 216 | - // donnees eventuellement fournies |
|
| 217 | - $set |
|
| 218 | - ); |
|
| 219 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 220 | - $c['login'] = $c['new_login']; |
|
| 221 | - } |
|
| 222 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 223 | - $c['pass'] = $c['new_pass']; |
|
| 224 | - } |
|
| 225 | - $err = auteur_instituer($id_auteur, $c); |
|
| 226 | - $session = array_merge($session, $c); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // .. mettre a jour les sessions de cet auteur |
|
| 230 | - include_spip('inc/session'); |
|
| 231 | - $session['id_auteur'] = $id_auteur; |
|
| 232 | - unset($session['new_login']); |
|
| 233 | - unset($session['new_pass']); |
|
| 234 | - actualiser_sessions($session); |
|
| 235 | - |
|
| 236 | - return $err; |
|
| 173 | + include_spip('inc/modifier'); |
|
| 174 | + include_spip('inc/filtres'); |
|
| 175 | + $c = collecter_requests( |
|
| 176 | + // include list |
|
| 177 | + objet_info('auteur', 'champs_editables'), |
|
| 178 | + // exclude list |
|
| 179 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 180 | + // donnees eventuellement fournies |
|
| 181 | + $set |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + if ( |
|
| 185 | + $err = objet_modifier_champs( |
|
| 186 | + 'auteur', |
|
| 187 | + $id_auteur, |
|
| 188 | + [ |
|
| 189 | + 'data' => $set, |
|
| 190 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 191 | + ], |
|
| 192 | + $c |
|
| 193 | + ) |
|
| 194 | + ) { |
|
| 195 | + return $err; |
|
| 196 | + } |
|
| 197 | + $session = $c; |
|
| 198 | + |
|
| 199 | + $err = ''; |
|
| 200 | + if (!$force_update) { |
|
| 201 | + // Modification de statut, changement de rubrique ? |
|
| 202 | + $c = collecter_requests( |
|
| 203 | + // include list |
|
| 204 | + [ |
|
| 205 | + 'statut', |
|
| 206 | + 'new_login', |
|
| 207 | + 'new_pass', |
|
| 208 | + 'login', |
|
| 209 | + 'pass', |
|
| 210 | + 'webmestre', |
|
| 211 | + 'restreintes', |
|
| 212 | + 'id_parent' |
|
| 213 | + ], |
|
| 214 | + // exclude list |
|
| 215 | + [], |
|
| 216 | + // donnees eventuellement fournies |
|
| 217 | + $set |
|
| 218 | + ); |
|
| 219 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 220 | + $c['login'] = $c['new_login']; |
|
| 221 | + } |
|
| 222 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 223 | + $c['pass'] = $c['new_pass']; |
|
| 224 | + } |
|
| 225 | + $err = auteur_instituer($id_auteur, $c); |
|
| 226 | + $session = array_merge($session, $c); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // .. mettre a jour les sessions de cet auteur |
|
| 230 | + include_spip('inc/session'); |
|
| 231 | + $session['id_auteur'] = $id_auteur; |
|
| 232 | + unset($session['new_login']); |
|
| 233 | + unset($session['new_pass']); |
|
| 234 | + actualiser_sessions($session); |
|
| 235 | + |
|
| 236 | + return $err; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | * @return string |
| 255 | 255 | */ |
| 256 | 256 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 257 | - include_spip('action/editer_liens'); |
|
| 257 | + include_spip('action/editer_liens'); |
|
| 258 | 258 | |
| 259 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 259 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function auteur_dissocier($id_auteur, $objets) { |
| 278 | - include_spip('action/editer_liens'); |
|
| 278 | + include_spip('action/editer_liens'); |
|
| 279 | 279 | |
| 280 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 280 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | * @return bool|int |
| 299 | 299 | */ |
| 300 | 300 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 301 | - include_spip('action/editer_liens'); |
|
| 301 | + include_spip('action/editer_liens'); |
|
| 302 | 302 | |
| 303 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 303 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
@@ -319,160 +319,160 @@ discard block |
||
| 319 | 319 | * @return bool|string |
| 320 | 320 | */ |
| 321 | 321 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 322 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 326 | - $champs = []; |
|
| 327 | - |
|
| 328 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 329 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 330 | - $champs['login'] = $c['login']; |
|
| 331 | - } |
|
| 332 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 333 | - $champs['pass'] = $c['pass']; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 337 | - |
|
| 338 | - if ( |
|
| 339 | - isset($c['statut']) |
|
| 340 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 341 | - ) { |
|
| 342 | - $statut = $champs['statut'] = $c['statut']; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - // Restreindre avant de declarer l'auteur |
|
| 346 | - // (section critique sur les droits) |
|
| 347 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 348 | - if (is_array($c['restreintes'])) { |
|
| 349 | - $c['restreintes'][] = $c['id_parent']; |
|
| 350 | - } else { |
|
| 351 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ( |
|
| 356 | - isset($c['webmestre']) |
|
| 357 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 358 | - ) { |
|
| 359 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 363 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 364 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - // Envoyer aux plugins |
|
| 368 | - $champs = pipeline( |
|
| 369 | - 'pre_edition', |
|
| 370 | - [ |
|
| 371 | - 'args' => [ |
|
| 372 | - 'table' => 'spip_auteurs', |
|
| 373 | - 'id_objet' => $id_auteur, |
|
| 374 | - 'action' => 'instituer', |
|
| 375 | - 'statut_ancien' => $statut_ancien, |
|
| 376 | - ], |
|
| 377 | - 'data' => $champs |
|
| 378 | - ] |
|
| 379 | - ); |
|
| 380 | - |
|
| 381 | - if ( |
|
| 382 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 383 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 384 | - ) { |
|
| 385 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 386 | - $rubriques = array_unique($rubriques); |
|
| 387 | - $rubriques = array_diff($rubriques, [0]); |
|
| 388 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 389 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - $flag_ecrire_acces = false; |
|
| 393 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 394 | - // avant les autres ecritures en base |
|
| 395 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 396 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 397 | - include_spip('inc/auth'); |
|
| 398 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 399 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 400 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 404 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 405 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 406 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - unset($champs['login']); |
|
| 410 | - unset($champs['pass']); |
|
| 411 | - $flag_ecrire_acces = true; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 415 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 416 | - } |
|
| 417 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 418 | - |
|
| 419 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 420 | - if ( |
|
| 421 | - $flag_ecrire_acces |
|
| 422 | - or isset($champs['statut']) |
|
| 423 | - ) { |
|
| 424 | - include_spip('inc/acces'); |
|
| 425 | - ecrire_acces(); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // Invalider les caches |
|
| 429 | - include_spip('inc/invalideur'); |
|
| 430 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 431 | - |
|
| 432 | - // Pipeline |
|
| 433 | - pipeline( |
|
| 434 | - 'post_edition', |
|
| 435 | - [ |
|
| 436 | - 'args' => [ |
|
| 437 | - 'table' => 'spip_auteurs', |
|
| 438 | - 'id_objet' => $id_auteur, |
|
| 439 | - 'action' => 'instituer', |
|
| 440 | - 'statut_ancien' => $statut_ancien, |
|
| 441 | - ], |
|
| 442 | - 'data' => $champs |
|
| 443 | - ] |
|
| 444 | - ); |
|
| 445 | - |
|
| 446 | - // Notifications |
|
| 447 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 448 | - $notifications( |
|
| 449 | - 'auteur_instituer', |
|
| 450 | - $id_auteur, |
|
| 451 | - [ |
|
| 452 | - 'statut' => $statut, |
|
| 453 | - 'statut_ancien' => $statut_ancien, |
|
| 454 | - 'champs' => $champs, |
|
| 455 | - ] |
|
| 456 | - ); |
|
| 457 | - $notifications( |
|
| 458 | - 'objet_instituer', |
|
| 459 | - $id_auteur, |
|
| 460 | - [ |
|
| 461 | - 'objet' => 'auteur', |
|
| 462 | - 'id_objet' => $id_auteur, |
|
| 463 | - 'statut' => $statut, |
|
| 464 | - 'statut_ancien' => $statut_ancien, |
|
| 465 | - 'champs' => $champs, |
|
| 466 | - ] |
|
| 467 | - ); |
|
| 322 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 326 | + $champs = []; |
|
| 327 | + |
|
| 328 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 329 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 330 | + $champs['login'] = $c['login']; |
|
| 331 | + } |
|
| 332 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 333 | + $champs['pass'] = $c['pass']; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 337 | + |
|
| 338 | + if ( |
|
| 339 | + isset($c['statut']) |
|
| 340 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 341 | + ) { |
|
| 342 | + $statut = $champs['statut'] = $c['statut']; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + // Restreindre avant de declarer l'auteur |
|
| 346 | + // (section critique sur les droits) |
|
| 347 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 348 | + if (is_array($c['restreintes'])) { |
|
| 349 | + $c['restreintes'][] = $c['id_parent']; |
|
| 350 | + } else { |
|
| 351 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ( |
|
| 356 | + isset($c['webmestre']) |
|
| 357 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 358 | + ) { |
|
| 359 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 363 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 364 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + // Envoyer aux plugins |
|
| 368 | + $champs = pipeline( |
|
| 369 | + 'pre_edition', |
|
| 370 | + [ |
|
| 371 | + 'args' => [ |
|
| 372 | + 'table' => 'spip_auteurs', |
|
| 373 | + 'id_objet' => $id_auteur, |
|
| 374 | + 'action' => 'instituer', |
|
| 375 | + 'statut_ancien' => $statut_ancien, |
|
| 376 | + ], |
|
| 377 | + 'data' => $champs |
|
| 378 | + ] |
|
| 379 | + ); |
|
| 380 | + |
|
| 381 | + if ( |
|
| 382 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 383 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 384 | + ) { |
|
| 385 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 386 | + $rubriques = array_unique($rubriques); |
|
| 387 | + $rubriques = array_diff($rubriques, [0]); |
|
| 388 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 389 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + $flag_ecrire_acces = false; |
|
| 393 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 394 | + // avant les autres ecritures en base |
|
| 395 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 396 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 397 | + include_spip('inc/auth'); |
|
| 398 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 399 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 400 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 404 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 405 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 406 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + unset($champs['login']); |
|
| 410 | + unset($champs['pass']); |
|
| 411 | + $flag_ecrire_acces = true; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 415 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 416 | + } |
|
| 417 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 418 | + |
|
| 419 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 420 | + if ( |
|
| 421 | + $flag_ecrire_acces |
|
| 422 | + or isset($champs['statut']) |
|
| 423 | + ) { |
|
| 424 | + include_spip('inc/acces'); |
|
| 425 | + ecrire_acces(); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // Invalider les caches |
|
| 429 | + include_spip('inc/invalideur'); |
|
| 430 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 431 | + |
|
| 432 | + // Pipeline |
|
| 433 | + pipeline( |
|
| 434 | + 'post_edition', |
|
| 435 | + [ |
|
| 436 | + 'args' => [ |
|
| 437 | + 'table' => 'spip_auteurs', |
|
| 438 | + 'id_objet' => $id_auteur, |
|
| 439 | + 'action' => 'instituer', |
|
| 440 | + 'statut_ancien' => $statut_ancien, |
|
| 441 | + ], |
|
| 442 | + 'data' => $champs |
|
| 443 | + ] |
|
| 444 | + ); |
|
| 445 | + |
|
| 446 | + // Notifications |
|
| 447 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 448 | + $notifications( |
|
| 449 | + 'auteur_instituer', |
|
| 450 | + $id_auteur, |
|
| 451 | + [ |
|
| 452 | + 'statut' => $statut, |
|
| 453 | + 'statut_ancien' => $statut_ancien, |
|
| 454 | + 'champs' => $champs, |
|
| 455 | + ] |
|
| 456 | + ); |
|
| 457 | + $notifications( |
|
| 458 | + 'objet_instituer', |
|
| 459 | + $id_auteur, |
|
| 460 | + [ |
|
| 461 | + 'objet' => 'auteur', |
|
| 462 | + 'id_objet' => $id_auteur, |
|
| 463 | + 'statut' => $statut, |
|
| 464 | + 'statut_ancien' => $statut_ancien, |
|
| 465 | + 'champs' => $champs, |
|
| 466 | + ] |
|
| 467 | + ); |
|
| 468 | 468 | |
| 469 | - // Rétro-compat |
|
| 470 | - $notifications( |
|
| 471 | - 'instituerauteur', |
|
| 472 | - $id_auteur, |
|
| 473 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 474 | - ); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 469 | + // Rétro-compat |
|
| 470 | + $notifications( |
|
| 471 | + 'instituerauteur', |
|
| 472 | + $id_auteur, |
|
| 473 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 478 | 478 | } |
@@ -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 | |
| 23 | 23 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return [$id, _L('echec enregistrement en base')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return [$id, $err]; |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return [$id, _L('echec enregistrement en base')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return [$id, $err]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,85 +75,85 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if ( |
|
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 85 | - ) { |
|
| 86 | - return $modifier($id, $set); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $table_sql = table_objet_sql($objet); |
|
| 90 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | - $desc = $trouver_table($table_sql); |
|
| 92 | - if (!$desc or !isset($desc['field'])) { |
|
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | - |
|
| 95 | - return _L("Erreur objet $objet inconnu"); |
|
| 96 | - } |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - |
|
| 99 | - $champ_date = ''; |
|
| 100 | - if (isset($desc['date']) and $desc['date']) { |
|
| 101 | - $champ_date = $desc['date']; |
|
| 102 | - } elseif (isset($desc['field']['date'])) { |
|
| 103 | - $champ_date = 'date'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $include_list = array_keys($desc['field']); |
|
| 107 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $include_list = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // include list |
|
| 116 | - $include_list, |
|
| 117 | - // exclude list |
|
| 118 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | - // donnees eventuellement fournies |
|
| 120 | - $set |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | - if (objet_test_si_publie($objet, $id)) { |
|
| 125 | - $invalideur = "id='$objet/$id'"; |
|
| 126 | - $indexation = true; |
|
| 127 | - } else { |
|
| 128 | - $invalideur = ''; |
|
| 129 | - $indexation = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( |
|
| 133 | - $err = objet_modifier_champs( |
|
| 134 | - $objet, |
|
| 135 | - $id, |
|
| 136 | - [ |
|
| 137 | - 'data' => $set, |
|
| 138 | - 'nonvide' => '', |
|
| 139 | - 'invalideur' => $invalideur, |
|
| 140 | - 'indexation' => $indexation, |
|
| 141 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | - ], |
|
| 144 | - $c |
|
| 145 | - ) |
|
| 146 | - ) { |
|
| 147 | - return $err; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Modification de statut, changement de rubrique ? |
|
| 151 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | - $err = objet_instituer($objet, $id, $c); |
|
| 155 | - |
|
| 156 | - return $err; |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if ( |
|
| 83 | + include_spip('action/editer_' . $objet) |
|
| 84 | + and function_exists($modifier = $objet . '_modifier') |
|
| 85 | + ) { |
|
| 86 | + return $modifier($id, $set); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $table_sql = table_objet_sql($objet); |
|
| 90 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | + $desc = $trouver_table($table_sql); |
|
| 92 | + if (!$desc or !isset($desc['field'])) { |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | + |
|
| 95 | + return _L("Erreur objet $objet inconnu"); |
|
| 96 | + } |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + |
|
| 99 | + $champ_date = ''; |
|
| 100 | + if (isset($desc['date']) and $desc['date']) { |
|
| 101 | + $champ_date = $desc['date']; |
|
| 102 | + } elseif (isset($desc['field']['date'])) { |
|
| 103 | + $champ_date = 'date'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $include_list = array_keys($desc['field']); |
|
| 107 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $include_list = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // include list |
|
| 116 | + $include_list, |
|
| 117 | + // exclude list |
|
| 118 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | + // donnees eventuellement fournies |
|
| 120 | + $set |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | + if (objet_test_si_publie($objet, $id)) { |
|
| 125 | + $invalideur = "id='$objet/$id'"; |
|
| 126 | + $indexation = true; |
|
| 127 | + } else { |
|
| 128 | + $invalideur = ''; |
|
| 129 | + $indexation = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( |
|
| 133 | + $err = objet_modifier_champs( |
|
| 134 | + $objet, |
|
| 135 | + $id, |
|
| 136 | + [ |
|
| 137 | + 'data' => $set, |
|
| 138 | + 'nonvide' => '', |
|
| 139 | + 'invalideur' => $invalideur, |
|
| 140 | + 'indexation' => $indexation, |
|
| 141 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | + ], |
|
| 144 | + $c |
|
| 145 | + ) |
|
| 146 | + ) { |
|
| 147 | + return $err; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Modification de statut, changement de rubrique ? |
|
| 151 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | + $err = objet_instituer($objet, $id, $c); |
|
| 155 | + |
|
| 156 | + return $err; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,157 +168,157 @@ discard block |
||
| 168 | 168 | * @return bool|int |
| 169 | 169 | */ |
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | - $d = null; |
|
| 172 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | - $objet = $t; |
|
| 175 | - } |
|
| 176 | - if ( |
|
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 179 | - ) { |
|
| 180 | - return $inserer($id_parent, $set); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $table_sql = table_objet_sql($objet); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $desc = $trouver_table($table_sql); |
|
| 186 | - if (!$desc or !isset($desc['field'])) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $lang_rub = ''; |
|
| 191 | - $champs = []; |
|
| 192 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | - // dans la premiere rubrique racine |
|
| 195 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | - $id_rubrique = $row['id_rubrique']; |
|
| 198 | - } else { |
|
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | - if (isset($desc['field']['id_secteur'])) { |
|
| 204 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | - } |
|
| 206 | - $lang_rub = $row['lang']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | - // ou a defaut celle de la rubrique |
|
| 212 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | - if ( |
|
| 214 | - isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | - $table_sql, |
|
| 216 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | - if ( |
|
| 221 | - in_array( |
|
| 222 | - $GLOBALS['spip_lang'], |
|
| 223 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | - ) |
|
| 225 | - ) { |
|
| 226 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | - $champs['langue_choisie'] = 'oui'; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | - $champs['langue_choisie'] = 'non'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (isset($desc['field']['statut'])) { |
|
| 237 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | - $champs['statut'] = reset($cles_statut); |
|
| 240 | - } else { |
|
| 241 | - $champs['statut'] = 'prepa'; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($set) { |
|
| 251 | - $champs = array_merge($champs, $set); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Envoyer aux plugins |
|
| 255 | - $champs = pipeline( |
|
| 256 | - 'pre_insertion', |
|
| 257 | - [ |
|
| 258 | - 'args' => [ |
|
| 259 | - 'table' => $table_sql, |
|
| 260 | - 'id_parent' => $id_parent, |
|
| 261 | - ], |
|
| 262 | - 'data' => $champs |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - $id = sql_insertq($table_sql, $champs); |
|
| 267 | - |
|
| 268 | - if ($id) { |
|
| 269 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | - // et associer l'auteur sinon |
|
| 271 | - // si la table n'a pas deja un champ id_auteur |
|
| 272 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | - if ( |
|
| 274 | - $id > 0 |
|
| 275 | - and !isset($desc['field']['id_auteur']) |
|
| 276 | - ) { |
|
| 277 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | - : _request('id_auteur')); |
|
| 280 | - if ($id_auteur) { |
|
| 281 | - include_spip('action/editer_auteur'); |
|
| 282 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - pipeline( |
|
| 287 | - 'post_insertion', |
|
| 288 | - [ |
|
| 289 | - 'args' => [ |
|
| 290 | - 'table' => $table_sql, |
|
| 291 | - 'id_parent' => $id_parent, |
|
| 292 | - 'id_objet' => $id, |
|
| 293 | - ], |
|
| 294 | - 'data' => $champs |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 171 | + $d = null; |
|
| 172 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | + $objet = $t; |
|
| 175 | + } |
|
| 176 | + if ( |
|
| 177 | + include_spip('action/editer_' . $objet) |
|
| 178 | + and function_exists($inserer = $objet . '_inserer') |
|
| 179 | + ) { |
|
| 180 | + return $inserer($id_parent, $set); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $table_sql = table_objet_sql($objet); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $desc = $trouver_table($table_sql); |
|
| 186 | + if (!$desc or !isset($desc['field'])) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $lang_rub = ''; |
|
| 191 | + $champs = []; |
|
| 192 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | + // dans la premiere rubrique racine |
|
| 195 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | + $id_rubrique = $row['id_rubrique']; |
|
| 198 | + } else { |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | + if (isset($desc['field']['id_secteur'])) { |
|
| 204 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | + } |
|
| 206 | + $lang_rub = $row['lang']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | + // ou a defaut celle de la rubrique |
|
| 212 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | + if ( |
|
| 214 | + isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | + $table_sql, |
|
| 216 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | + if ( |
|
| 221 | + in_array( |
|
| 222 | + $GLOBALS['spip_lang'], |
|
| 223 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | + ) |
|
| 225 | + ) { |
|
| 226 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | + $champs['langue_choisie'] = 'oui'; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | + $champs['langue_choisie'] = 'non'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (isset($desc['field']['statut'])) { |
|
| 237 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | + $champs['statut'] = reset($cles_statut); |
|
| 240 | + } else { |
|
| 241 | + $champs['statut'] = 'prepa'; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($set) { |
|
| 251 | + $champs = array_merge($champs, $set); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // Envoyer aux plugins |
|
| 255 | + $champs = pipeline( |
|
| 256 | + 'pre_insertion', |
|
| 257 | + [ |
|
| 258 | + 'args' => [ |
|
| 259 | + 'table' => $table_sql, |
|
| 260 | + 'id_parent' => $id_parent, |
|
| 261 | + ], |
|
| 262 | + 'data' => $champs |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + $id = sql_insertq($table_sql, $champs); |
|
| 267 | + |
|
| 268 | + if ($id) { |
|
| 269 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | + // et associer l'auteur sinon |
|
| 271 | + // si la table n'a pas deja un champ id_auteur |
|
| 272 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | + if ( |
|
| 274 | + $id > 0 |
|
| 275 | + and !isset($desc['field']['id_auteur']) |
|
| 276 | + ) { |
|
| 277 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | + : _request('id_auteur')); |
|
| 280 | + if ($id_auteur) { |
|
| 281 | + include_spip('action/editer_auteur'); |
|
| 282 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + pipeline( |
|
| 287 | + 'post_insertion', |
|
| 288 | + [ |
|
| 289 | + 'args' => [ |
|
| 290 | + 'table' => $table_sql, |
|
| 291 | + 'id_parent' => $id_parent, |
|
| 292 | + 'id_objet' => $id, |
|
| 293 | + ], |
|
| 294 | + 'data' => $champs |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Appeler une notification |
|
| 300 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | - $notifications( |
|
| 302 | - "{$objet}_inserer", |
|
| 303 | - $id, |
|
| 304 | - [ |
|
| 305 | - 'id_parent' => $id_parent, |
|
| 306 | - 'champs' => $champs, |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - $notifications( |
|
| 310 | - 'objet_inserer', |
|
| 311 | - $id, |
|
| 312 | - [ |
|
| 313 | - 'objet' => $objet, |
|
| 314 | - 'id_objet' => $id, |
|
| 315 | - 'id_parent' => $id_parent, |
|
| 316 | - 'champs' => $champs, |
|
| 317 | - ] |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return $id; |
|
| 299 | + // Appeler une notification |
|
| 300 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | + $notifications( |
|
| 302 | + "{$objet}_inserer", |
|
| 303 | + $id, |
|
| 304 | + [ |
|
| 305 | + 'id_parent' => $id_parent, |
|
| 306 | + 'champs' => $champs, |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + $notifications( |
|
| 310 | + 'objet_inserer', |
|
| 311 | + $id, |
|
| 312 | + [ |
|
| 313 | + 'objet' => $objet, |
|
| 314 | + 'id_objet' => $id, |
|
| 315 | + 'id_parent' => $id_parent, |
|
| 316 | + 'champs' => $champs, |
|
| 317 | + ] |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return $id; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -335,138 +335,138 @@ discard block |
||
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | 337 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 338 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | - $objet = $t; |
|
| 341 | - } |
|
| 342 | - if ( |
|
| 343 | - include_spip('action/editer_' . $objet) |
|
| 344 | - and function_exists($instituer = $objet . '_instituer') |
|
| 345 | - ) { |
|
| 346 | - return $instituer($id, $c, $calcul_rub); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $table_sql = table_objet_sql($objet); |
|
| 350 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | - $desc = $trouver_table($table_sql); |
|
| 352 | - if (!$desc or !isset($desc['field'])) { |
|
| 353 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - include_spip('inc/autoriser'); |
|
| 357 | - include_spip('inc/rubriques'); |
|
| 358 | - include_spip('inc/modifier'); |
|
| 359 | - |
|
| 360 | - $sel = []; |
|
| 361 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | - |
|
| 363 | - $champ_date = ''; |
|
| 364 | - if (isset($desc['date']) and $desc['date']) { |
|
| 365 | - $champ_date = $desc['date']; |
|
| 366 | - } elseif (isset($desc['field']['date'])) { |
|
| 367 | - $champ_date = 'date'; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | - |
|
| 373 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | - |
|
| 375 | - $id_rubrique = $row['id_rubrique']; |
|
| 376 | - $statut_ancien = $statut = $row['statut']; |
|
| 377 | - $date_ancienne = $date = $row['date']; |
|
| 378 | - $champs = []; |
|
| 379 | - |
|
| 380 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | - |
|
| 383 | - // cf autorisations dans inc/instituer_objet |
|
| 384 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | - if ( |
|
| 386 | - $id_rubrique ? |
|
| 387 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | - : |
|
| 389 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | - ) { |
|
| 391 | - $statut = $champs['statut'] = $s; |
|
| 392 | - } else { |
|
| 393 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | - $statut = $champs['statut'] = $s; |
|
| 395 | - } else { |
|
| 396 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // En cas de publication, fixer la date a "maintenant" |
|
| 401 | - // sauf si $c commande autre chose |
|
| 402 | - // ou si l'objet est deja date dans le futur |
|
| 403 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | - if ($champ_date) { |
|
| 405 | - if ( |
|
| 406 | - $champs['statut'] == 'publie' |
|
| 407 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | - or $d |
|
| 409 | - ) { |
|
| 410 | - if ($d or strtotime($d = $date) > time()) { |
|
| 411 | - $champs[$champ_date] = $date = $d; |
|
| 412 | - } else { |
|
| 413 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // Verifier que la rubrique demandee existe et est differente |
|
| 420 | - // de la rubrique actuelle |
|
| 421 | - if ( |
|
| 422 | - $id_rubrique |
|
| 423 | - and isset($c['id_parent']) |
|
| 424 | - and $id_parent = $c['id_parent'] |
|
| 425 | - and $id_parent != $id_rubrique |
|
| 426 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | - ) { |
|
| 428 | - $champs['id_rubrique'] = $id_parent; |
|
| 429 | - |
|
| 430 | - // si l'objet etait publie |
|
| 431 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | - // repasser l'objet en statut 'propose'. |
|
| 433 | - if ( |
|
| 434 | - $statut == 'publie' |
|
| 435 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | - ) { |
|
| 437 | - $champs['statut'] = 'prop'; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - // Envoyer aux plugins |
|
| 443 | - $champs = pipeline( |
|
| 444 | - 'pre_edition', |
|
| 445 | - [ |
|
| 446 | - 'args' => [ |
|
| 447 | - 'table' => $table_sql, |
|
| 448 | - 'id_objet' => $id, |
|
| 449 | - 'action' => 'instituer', |
|
| 450 | - 'statut_ancien' => $statut_ancien, |
|
| 451 | - 'date_ancienne' => $date_ancienne, |
|
| 452 | - 'id_parent_ancien' => $id_rubrique, |
|
| 453 | - ], |
|
| 454 | - 'data' => $champs |
|
| 455 | - ] |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | - return ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // Envoyer les modifs. |
|
| 463 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | - |
|
| 465 | - // Invalider les caches |
|
| 466 | - include_spip('inc/invalideur'); |
|
| 467 | - suivre_invalideur("id='$objet/$id'"); |
|
| 468 | - |
|
| 469 | - /* |
|
| 338 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | + $objet = $t; |
|
| 341 | + } |
|
| 342 | + if ( |
|
| 343 | + include_spip('action/editer_' . $objet) |
|
| 344 | + and function_exists($instituer = $objet . '_instituer') |
|
| 345 | + ) { |
|
| 346 | + return $instituer($id, $c, $calcul_rub); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $table_sql = table_objet_sql($objet); |
|
| 350 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | + $desc = $trouver_table($table_sql); |
|
| 352 | + if (!$desc or !isset($desc['field'])) { |
|
| 353 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + include_spip('inc/autoriser'); |
|
| 357 | + include_spip('inc/rubriques'); |
|
| 358 | + include_spip('inc/modifier'); |
|
| 359 | + |
|
| 360 | + $sel = []; |
|
| 361 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | + |
|
| 363 | + $champ_date = ''; |
|
| 364 | + if (isset($desc['date']) and $desc['date']) { |
|
| 365 | + $champ_date = $desc['date']; |
|
| 366 | + } elseif (isset($desc['field']['date'])) { |
|
| 367 | + $champ_date = 'date'; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | + |
|
| 373 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | + |
|
| 375 | + $id_rubrique = $row['id_rubrique']; |
|
| 376 | + $statut_ancien = $statut = $row['statut']; |
|
| 377 | + $date_ancienne = $date = $row['date']; |
|
| 378 | + $champs = []; |
|
| 379 | + |
|
| 380 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | + |
|
| 383 | + // cf autorisations dans inc/instituer_objet |
|
| 384 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | + if ( |
|
| 386 | + $id_rubrique ? |
|
| 387 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | + : |
|
| 389 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | + ) { |
|
| 391 | + $statut = $champs['statut'] = $s; |
|
| 392 | + } else { |
|
| 393 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | + $statut = $champs['statut'] = $s; |
|
| 395 | + } else { |
|
| 396 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // En cas de publication, fixer la date a "maintenant" |
|
| 401 | + // sauf si $c commande autre chose |
|
| 402 | + // ou si l'objet est deja date dans le futur |
|
| 403 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | + if ($champ_date) { |
|
| 405 | + if ( |
|
| 406 | + $champs['statut'] == 'publie' |
|
| 407 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | + or $d |
|
| 409 | + ) { |
|
| 410 | + if ($d or strtotime($d = $date) > time()) { |
|
| 411 | + $champs[$champ_date] = $date = $d; |
|
| 412 | + } else { |
|
| 413 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // Verifier que la rubrique demandee existe et est differente |
|
| 420 | + // de la rubrique actuelle |
|
| 421 | + if ( |
|
| 422 | + $id_rubrique |
|
| 423 | + and isset($c['id_parent']) |
|
| 424 | + and $id_parent = $c['id_parent'] |
|
| 425 | + and $id_parent != $id_rubrique |
|
| 426 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | + ) { |
|
| 428 | + $champs['id_rubrique'] = $id_parent; |
|
| 429 | + |
|
| 430 | + // si l'objet etait publie |
|
| 431 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | + // repasser l'objet en statut 'propose'. |
|
| 433 | + if ( |
|
| 434 | + $statut == 'publie' |
|
| 435 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | + ) { |
|
| 437 | + $champs['statut'] = 'prop'; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + // Envoyer aux plugins |
|
| 443 | + $champs = pipeline( |
|
| 444 | + 'pre_edition', |
|
| 445 | + [ |
|
| 446 | + 'args' => [ |
|
| 447 | + 'table' => $table_sql, |
|
| 448 | + 'id_objet' => $id, |
|
| 449 | + 'action' => 'instituer', |
|
| 450 | + 'statut_ancien' => $statut_ancien, |
|
| 451 | + 'date_ancienne' => $date_ancienne, |
|
| 452 | + 'id_parent_ancien' => $id_rubrique, |
|
| 453 | + ], |
|
| 454 | + 'data' => $champs |
|
| 455 | + ] |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | + return ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // Envoyer les modifs. |
|
| 463 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | + |
|
| 465 | + // Invalider les caches |
|
| 466 | + include_spip('inc/invalideur'); |
|
| 467 | + suivre_invalideur("id='$objet/$id'"); |
|
| 468 | + |
|
| 469 | + /* |
|
| 470 | 470 | if ($date) { |
| 471 | 471 | $t = strtotime($date); |
| 472 | 472 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -475,60 +475,60 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | }*/ |
| 477 | 477 | |
| 478 | - // Pipeline |
|
| 479 | - pipeline( |
|
| 480 | - 'post_edition', |
|
| 481 | - [ |
|
| 482 | - 'args' => [ |
|
| 483 | - 'table' => $table_sql, |
|
| 484 | - 'id_objet' => $id, |
|
| 485 | - 'action' => 'instituer', |
|
| 486 | - 'statut_ancien' => $statut_ancien, |
|
| 487 | - 'date_ancienne' => $date_ancienne, |
|
| 488 | - 'id_parent_ancien' => $id_rubrique, |
|
| 489 | - ], |
|
| 490 | - 'data' => $champs |
|
| 491 | - ] |
|
| 492 | - ); |
|
| 493 | - |
|
| 494 | - // Notifications |
|
| 495 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | - $notifications( |
|
| 497 | - "{$objet}_instituer", |
|
| 498 | - $id, |
|
| 499 | - [ |
|
| 500 | - 'statut' => $statut, |
|
| 501 | - 'statut_ancien' => $statut_ancien, |
|
| 502 | - 'date' => $date, |
|
| 503 | - 'date_ancienne' => $date_ancienne, |
|
| 504 | - 'id_parent_ancien' => $id_rubrique, |
|
| 505 | - 'champs' => $champs, |
|
| 506 | - ] |
|
| 507 | - ); |
|
| 508 | - $notifications( |
|
| 509 | - 'objet_instituer', |
|
| 510 | - $id, |
|
| 511 | - [ |
|
| 512 | - 'objet' => $objet, |
|
| 513 | - 'id_objet' => $id, |
|
| 514 | - 'statut' => $statut, |
|
| 515 | - 'statut_ancien' => $statut_ancien, |
|
| 516 | - 'date' => $date, |
|
| 517 | - 'date_ancienne' => $date_ancienne, |
|
| 518 | - 'id_parent_ancien' => $id_rubrique, |
|
| 519 | - 'champs' => $champs, |
|
| 520 | - ] |
|
| 521 | - ); |
|
| 478 | + // Pipeline |
|
| 479 | + pipeline( |
|
| 480 | + 'post_edition', |
|
| 481 | + [ |
|
| 482 | + 'args' => [ |
|
| 483 | + 'table' => $table_sql, |
|
| 484 | + 'id_objet' => $id, |
|
| 485 | + 'action' => 'instituer', |
|
| 486 | + 'statut_ancien' => $statut_ancien, |
|
| 487 | + 'date_ancienne' => $date_ancienne, |
|
| 488 | + 'id_parent_ancien' => $id_rubrique, |
|
| 489 | + ], |
|
| 490 | + 'data' => $champs |
|
| 491 | + ] |
|
| 492 | + ); |
|
| 493 | + |
|
| 494 | + // Notifications |
|
| 495 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | + $notifications( |
|
| 497 | + "{$objet}_instituer", |
|
| 498 | + $id, |
|
| 499 | + [ |
|
| 500 | + 'statut' => $statut, |
|
| 501 | + 'statut_ancien' => $statut_ancien, |
|
| 502 | + 'date' => $date, |
|
| 503 | + 'date_ancienne' => $date_ancienne, |
|
| 504 | + 'id_parent_ancien' => $id_rubrique, |
|
| 505 | + 'champs' => $champs, |
|
| 506 | + ] |
|
| 507 | + ); |
|
| 508 | + $notifications( |
|
| 509 | + 'objet_instituer', |
|
| 510 | + $id, |
|
| 511 | + [ |
|
| 512 | + 'objet' => $objet, |
|
| 513 | + 'id_objet' => $id, |
|
| 514 | + 'statut' => $statut, |
|
| 515 | + 'statut_ancien' => $statut_ancien, |
|
| 516 | + 'date' => $date, |
|
| 517 | + 'date_ancienne' => $date_ancienne, |
|
| 518 | + 'id_parent_ancien' => $id_rubrique, |
|
| 519 | + 'champs' => $champs, |
|
| 520 | + ] |
|
| 521 | + ); |
|
| 522 | 522 | |
| 523 | - // Rétro-compat |
|
| 524 | - $notifications( |
|
| 525 | - "instituer$objet", |
|
| 526 | - $id, |
|
| 527 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - return ''; // pas d'erreur |
|
| 523 | + // Rétro-compat |
|
| 524 | + $notifications( |
|
| 525 | + "instituer$objet", |
|
| 526 | + $id, |
|
| 527 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + return ''; // pas d'erreur |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -543,51 +543,51 @@ discard block |
||
| 543 | 543 | * @return void |
| 544 | 544 | */ |
| 545 | 545 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 546 | - $table_sql = table_objet_sql($objet); |
|
| 547 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | - $desc = $trouver_table($table_sql); |
|
| 549 | - |
|
| 550 | - // Si on deplace l'objet |
|
| 551 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | - if (isset($champs['id_rubrique'])) { |
|
| 553 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | - $langue = $row_rub['lang']; |
|
| 555 | - |
|
| 556 | - if (isset($desc['field']['id_secteur'])) { |
|
| 557 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | - if ( |
|
| 562 | - sql_fetsel( |
|
| 563 | - '1', |
|
| 564 | - $table_sql, |
|
| 565 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | - ) |
|
| 567 | - ) { |
|
| 568 | - $champs['lang'] = $langue; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if (!$champs) { |
|
| 574 | - return; |
|
| 575 | - } |
|
| 576 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | - |
|
| 578 | - // Changer le statut des rubriques concernees |
|
| 579 | - if ($cond) { |
|
| 580 | - include_spip('inc/rubriques'); |
|
| 581 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | - $postdate = false; |
|
| 583 | - // On rajoute les infos de l'objet |
|
| 584 | - $infos = [ |
|
| 585 | - 'objet' => $objet, |
|
| 586 | - 'id_objet' => $id, |
|
| 587 | - 'statut_ancien' => $statut, |
|
| 588 | - ]; |
|
| 589 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | - } |
|
| 546 | + $table_sql = table_objet_sql($objet); |
|
| 547 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | + $desc = $trouver_table($table_sql); |
|
| 549 | + |
|
| 550 | + // Si on deplace l'objet |
|
| 551 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | + if (isset($champs['id_rubrique'])) { |
|
| 553 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | + $langue = $row_rub['lang']; |
|
| 555 | + |
|
| 556 | + if (isset($desc['field']['id_secteur'])) { |
|
| 557 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | + if ( |
|
| 562 | + sql_fetsel( |
|
| 563 | + '1', |
|
| 564 | + $table_sql, |
|
| 565 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | + ) |
|
| 567 | + ) { |
|
| 568 | + $champs['lang'] = $langue; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if (!$champs) { |
|
| 574 | + return; |
|
| 575 | + } |
|
| 576 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | + |
|
| 578 | + // Changer le statut des rubriques concernees |
|
| 579 | + if ($cond) { |
|
| 580 | + include_spip('inc/rubriques'); |
|
| 581 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | + $postdate = false; |
|
| 583 | + // On rajoute les infos de l'objet |
|
| 584 | + $infos = [ |
|
| 585 | + 'objet' => $objet, |
|
| 586 | + 'id_objet' => $id, |
|
| 587 | + 'statut_ancien' => $statut, |
|
| 588 | + ]; |
|
| 589 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -616,75 +616,75 @@ discard block |
||
| 616 | 616 | * string|int : valeur du champ demande pour l'objet demande |
| 617 | 617 | */ |
| 618 | 618 | function objet_lire($objet, $valeur_id, $options = []) { |
| 619 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | - $objet = $t; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | - static $descriptions = []; |
|
| 627 | - |
|
| 628 | - // On détermine le nom du champ id de la table. |
|
| 629 | - include_spip('base/objets'); |
|
| 630 | - $primary = id_table_objet($objet); |
|
| 631 | - |
|
| 632 | - // On détermine l'id à utiliser. |
|
| 633 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | - |
|
| 635 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | - if ( |
|
| 637 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | - or (isset($options['force']) and $options['force']) |
|
| 639 | - ) { |
|
| 640 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | - if ( |
|
| 642 | - include_spip('action/editer_' . $objet) |
|
| 643 | - and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | - ) { |
|
| 645 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | - } else { |
|
| 647 | - // On récupère la table SQL à partir du type d'objet. |
|
| 648 | - $table = table_objet_sql($objet); |
|
| 649 | - |
|
| 650 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | - $where = [ |
|
| 652 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | - ]; |
|
| 654 | - |
|
| 655 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - if (!$valeurs) { |
|
| 660 | - $valeurs = false; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | - |
|
| 665 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | - |
|
| 673 | - // On ne retourne maintenant que les champs demandés. |
|
| 674 | - // - on détermine les informations à renvoyer. |
|
| 675 | - if ($retour and !empty($options['champs'])) { |
|
| 676 | - $champs = $options['champs']; |
|
| 677 | - // Extraction des seules informations demandées. |
|
| 678 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | - if (is_array($champs)) { |
|
| 681 | - // Tableau des informations valides |
|
| 682 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | - } else { |
|
| 684 | - // Valeur unique demandée. |
|
| 685 | - $retour = ($retour[$champs] ?? false); |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return $retour; |
|
| 619 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | + $objet = $t; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | + static $descriptions = []; |
|
| 627 | + |
|
| 628 | + // On détermine le nom du champ id de la table. |
|
| 629 | + include_spip('base/objets'); |
|
| 630 | + $primary = id_table_objet($objet); |
|
| 631 | + |
|
| 632 | + // On détermine l'id à utiliser. |
|
| 633 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | + |
|
| 635 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | + if ( |
|
| 637 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | + or (isset($options['force']) and $options['force']) |
|
| 639 | + ) { |
|
| 640 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | + if ( |
|
| 642 | + include_spip('action/editer_' . $objet) |
|
| 643 | + and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | + ) { |
|
| 645 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | + } else { |
|
| 647 | + // On récupère la table SQL à partir du type d'objet. |
|
| 648 | + $table = table_objet_sql($objet); |
|
| 649 | + |
|
| 650 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | + $where = [ |
|
| 652 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | + ]; |
|
| 654 | + |
|
| 655 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + if (!$valeurs) { |
|
| 660 | + $valeurs = false; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | + |
|
| 665 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | + |
|
| 673 | + // On ne retourne maintenant que les champs demandés. |
|
| 674 | + // - on détermine les informations à renvoyer. |
|
| 675 | + if ($retour and !empty($options['champs'])) { |
|
| 676 | + $champs = $options['champs']; |
|
| 677 | + // Extraction des seules informations demandées. |
|
| 678 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | + if (is_array($champs)) { |
|
| 681 | + // Tableau des informations valides |
|
| 682 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | + } else { |
|
| 684 | + // Valeur unique demandée. |
|
| 685 | + $retour = ($retour[$champs] ?? false); |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return $retour; |
|
| 690 | 690 | } |
@@ -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 | |
| 23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = []; |
|
| 45 | - foreach ($include_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($exclude_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = []; |
|
| 45 | + foreach ($include_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($exclude_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,262 +97,262 @@ discard block |
||
| 97 | 97 | * - chaîne : texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // N'accepter que les champs qui existent dans la table |
|
| 141 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | - // et dont la valeur n'est pas null |
|
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 144 | - return $var !== null; |
|
| 145 | - }); |
|
| 146 | - // TODO: ici aussi on peut valider les contenus |
|
| 147 | - // en fonction du type |
|
| 148 | - |
|
| 149 | - // Nettoyer les valeurs |
|
| 150 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | - |
|
| 152 | - // On récupère l'état avant toute modification |
|
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | - |
|
| 155 | - // Envoyer aux plugins |
|
| 156 | - $champs = pipeline( |
|
| 157 | - 'pre_edition', |
|
| 158 | - [ |
|
| 159 | - 'args' => [ |
|
| 160 | - 'table' => $spip_table_objet, // compatibilite |
|
| 161 | - 'table_objet' => $table_objet, |
|
| 162 | - 'spip_table_objet' => $spip_table_objet, |
|
| 163 | - 'desc' => $desc, |
|
| 164 | - 'type' => $objet, |
|
| 165 | - 'id_objet' => $id_objet, |
|
| 166 | - 'data' => $options['data'] ?? null, |
|
| 167 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | - 'serveur' => $serveur, |
|
| 170 | - 'action' => $options['action'] ?? 'modifier' |
|
| 171 | - ], |
|
| 172 | - 'data' => $champs |
|
| 173 | - ] |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - if (!$champs) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | - include_spip('inc/config'); |
|
| 183 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | - include_spip('inc/drapeau_edition'); |
|
| 185 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | - include_spip('inc/editer'); |
|
| 190 | - if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | - $options['data'] = &$_POST; |
|
| 192 | - } |
|
| 193 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | - // et gere l'interface |
|
| 196 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | - if ($conflits) { |
|
| 198 | - return _T('titre_conflit_edition'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($champs) { |
|
| 202 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | - if (isset($champs['lang'])) { |
|
| 204 | - if ($changer_lang = $champs['lang']) { |
|
| 205 | - $id_rubrique = 0; |
|
| 206 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | - } |
|
| 210 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | - } |
|
| 213 | - // on laisse 'lang' dans $champs, |
|
| 214 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | - // deja pris en compte |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // la modif peut avoir lieu |
|
| 220 | - |
|
| 221 | - // faut-il ajouter date_modif ? |
|
| 222 | - if ( |
|
| 223 | - !empty($options['date_modif']) |
|
| 224 | - and !isset($champs[$options['date_modif']]) |
|
| 225 | - ) { |
|
| 226 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // allez on commit la modif |
|
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | - |
|
| 232 | - // on verifie si elle est bien passee |
|
| 233 | - $moof = sql_fetsel( |
|
| 234 | - array_keys($champs), |
|
| 235 | - $spip_table_objet, |
|
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 237 | - [], |
|
| 238 | - [], |
|
| 239 | - '', |
|
| 240 | - [], |
|
| 241 | - $serveur |
|
| 242 | - ); |
|
| 243 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | - if ($moof != $champs) { |
|
| 245 | - $liste = []; |
|
| 246 | - foreach ($moof as $k => $v) { |
|
| 247 | - if ( |
|
| 248 | - $v !== $champs[$k] |
|
| 249 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | - ) { |
|
| 254 | - $liste[] = $k; |
|
| 255 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | - $conflits[$k]['save'] = $v; |
|
| 257 | - |
|
| 258 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | - include_spip('inc/charsets'); |
|
| 262 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | - array_pop($liste); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | - // c'est un cas exceptionnel |
|
| 270 | - if (count($liste)) { |
|
| 271 | - spip_log( |
|
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return _T( |
|
| 277 | - 'erreur_technique_enregistrement_champs', |
|
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Invalider les caches |
|
| 284 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | - include_spip('inc/invalideur'); |
|
| 286 | - if (is_array($options['invalideur'])) { |
|
| 287 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | - } else { |
|
| 289 | - suivre_invalideur($options['invalideur']); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Notifications, gestion des revisions... |
|
| 294 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | - pipeline( |
|
| 296 | - 'post_edition', |
|
| 297 | - [ |
|
| 298 | - 'args' => [ |
|
| 299 | - 'table' => $spip_table_objet, |
|
| 300 | - 'table_objet' => $table_objet, |
|
| 301 | - 'spip_table_objet' => $spip_table_objet, |
|
| 302 | - 'desc' => $desc, |
|
| 303 | - 'type' => $objet, |
|
| 304 | - 'id_objet' => $id_objet, |
|
| 305 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | - 'serveur' => $serveur, |
|
| 308 | - 'action' => $options['action'] ?? 'modifier' |
|
| 309 | - ], |
|
| 310 | - 'data' => $champs |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // N'accepter que les champs qui existent dans la table |
|
| 141 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | + // et dont la valeur n'est pas null |
|
| 143 | + $champs = array_filter($champs, static function ($var) { |
|
| 144 | + return $var !== null; |
|
| 145 | + }); |
|
| 146 | + // TODO: ici aussi on peut valider les contenus |
|
| 147 | + // en fonction du type |
|
| 148 | + |
|
| 149 | + // Nettoyer les valeurs |
|
| 150 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | + |
|
| 152 | + // On récupère l'état avant toute modification |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | + |
|
| 155 | + // Envoyer aux plugins |
|
| 156 | + $champs = pipeline( |
|
| 157 | + 'pre_edition', |
|
| 158 | + [ |
|
| 159 | + 'args' => [ |
|
| 160 | + 'table' => $spip_table_objet, // compatibilite |
|
| 161 | + 'table_objet' => $table_objet, |
|
| 162 | + 'spip_table_objet' => $spip_table_objet, |
|
| 163 | + 'desc' => $desc, |
|
| 164 | + 'type' => $objet, |
|
| 165 | + 'id_objet' => $id_objet, |
|
| 166 | + 'data' => $options['data'] ?? null, |
|
| 167 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | + 'serveur' => $serveur, |
|
| 170 | + 'action' => $options['action'] ?? 'modifier' |
|
| 171 | + ], |
|
| 172 | + 'data' => $champs |
|
| 173 | + ] |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + if (!$champs) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | + include_spip('inc/config'); |
|
| 183 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | + include_spip('inc/drapeau_edition'); |
|
| 185 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | + include_spip('inc/editer'); |
|
| 190 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | + $options['data'] = &$_POST; |
|
| 192 | + } |
|
| 193 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | + // et gere l'interface |
|
| 196 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | + if ($conflits) { |
|
| 198 | + return _T('titre_conflit_edition'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($champs) { |
|
| 202 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | + if (isset($champs['lang'])) { |
|
| 204 | + if ($changer_lang = $champs['lang']) { |
|
| 205 | + $id_rubrique = 0; |
|
| 206 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | + } |
|
| 210 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | + } |
|
| 213 | + // on laisse 'lang' dans $champs, |
|
| 214 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | + // deja pris en compte |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // la modif peut avoir lieu |
|
| 220 | + |
|
| 221 | + // faut-il ajouter date_modif ? |
|
| 222 | + if ( |
|
| 223 | + !empty($options['date_modif']) |
|
| 224 | + and !isset($champs[$options['date_modif']]) |
|
| 225 | + ) { |
|
| 226 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // allez on commit la modif |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | + |
|
| 232 | + // on verifie si elle est bien passee |
|
| 233 | + $moof = sql_fetsel( |
|
| 234 | + array_keys($champs), |
|
| 235 | + $spip_table_objet, |
|
| 236 | + "$id_table_objet=" . intval($id_objet), |
|
| 237 | + [], |
|
| 238 | + [], |
|
| 239 | + '', |
|
| 240 | + [], |
|
| 241 | + $serveur |
|
| 242 | + ); |
|
| 243 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | + if ($moof != $champs) { |
|
| 245 | + $liste = []; |
|
| 246 | + foreach ($moof as $k => $v) { |
|
| 247 | + if ( |
|
| 248 | + $v !== $champs[$k] |
|
| 249 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | + ) { |
|
| 254 | + $liste[] = $k; |
|
| 255 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | + $conflits[$k]['save'] = $v; |
|
| 257 | + |
|
| 258 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | + include_spip('inc/charsets'); |
|
| 262 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | + array_pop($liste); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | + // c'est un cas exceptionnel |
|
| 270 | + if (count($liste)) { |
|
| 271 | + spip_log( |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | + 'modifier.' . _LOG_CRITIQUE |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return _T( |
|
| 277 | + 'erreur_technique_enregistrement_champs', |
|
| 278 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Invalider les caches |
|
| 284 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | + include_spip('inc/invalideur'); |
|
| 286 | + if (is_array($options['invalideur'])) { |
|
| 287 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | + } else { |
|
| 289 | + suivre_invalideur($options['invalideur']); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Notifications, gestion des revisions... |
|
| 294 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | + pipeline( |
|
| 296 | + 'post_edition', |
|
| 297 | + [ |
|
| 298 | + 'args' => [ |
|
| 299 | + 'table' => $spip_table_objet, |
|
| 300 | + 'table_objet' => $table_objet, |
|
| 301 | + 'spip_table_objet' => $spip_table_objet, |
|
| 302 | + 'desc' => $desc, |
|
| 303 | + 'type' => $objet, |
|
| 304 | + 'id_objet' => $id_objet, |
|
| 305 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | + 'serveur' => $serveur, |
|
| 308 | + 'action' => $options['action'] ?? 'modifier' |
|
| 309 | + ], |
|
| 310 | + 'data' => $champs |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Appeler une notification |
|
| 316 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | - $notifications( |
|
| 318 | - "{$objet}_modifier", |
|
| 319 | - $id_objet, |
|
| 320 | - [ |
|
| 321 | - 'champs' => $champs, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - $notifications( |
|
| 325 | - 'objet_modifier', |
|
| 326 | - $id_objet, |
|
| 327 | - [ |
|
| 328 | - 'objet' => $objet, |
|
| 329 | - 'id_objet' => $id_objet, |
|
| 330 | - 'champs' => $champs, |
|
| 331 | - ] |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // journaliser l'affaire |
|
| 336 | - // message a affiner :-) |
|
| 337 | - include_spip('inc/filtres_mini'); |
|
| 338 | - $qui = ''; |
|
| 339 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | - } |
|
| 342 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | - } |
|
| 345 | - if ($qui == '') { |
|
| 346 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | - } |
|
| 348 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | - '+', |
|
| 350 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | - ) . ')'), [ |
|
| 352 | - 'faire' => 'modifier', |
|
| 353 | - 'quoi' => $objet, |
|
| 354 | - 'id' => $id_objet |
|
| 355 | - ]); |
|
| 356 | - |
|
| 357 | - return ''; |
|
| 315 | + // Appeler une notification |
|
| 316 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | + $notifications( |
|
| 318 | + "{$objet}_modifier", |
|
| 319 | + $id_objet, |
|
| 320 | + [ |
|
| 321 | + 'champs' => $champs, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + $notifications( |
|
| 325 | + 'objet_modifier', |
|
| 326 | + $id_objet, |
|
| 327 | + [ |
|
| 328 | + 'objet' => $objet, |
|
| 329 | + 'id_objet' => $id_objet, |
|
| 330 | + 'champs' => $champs, |
|
| 331 | + ] |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // journaliser l'affaire |
|
| 336 | + // message a affiner :-) |
|
| 337 | + include_spip('inc/filtres_mini'); |
|
| 338 | + $qui = ''; |
|
| 339 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | + } |
|
| 342 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | + } |
|
| 345 | + if ($qui == '') { |
|
| 346 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | + } |
|
| 348 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | + '+', |
|
| 350 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | + ) . ')'), [ |
|
| 352 | + 'faire' => 'modifier', |
|
| 353 | + 'quoi' => $objet, |
|
| 354 | + 'id' => $id_objet |
|
| 355 | + ]); |
|
| 356 | + |
|
| 357 | + return ''; |
|
| 358 | 358 | } |