@@ -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,44 +88,44 @@ 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 | - ); |
|
| 127 | - |
|
| 128 | - return $id_auteur; |
|
| 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 | + |
|
| 128 | + return $id_auteur; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -150,70 +150,70 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 152 | 152 | |
| 153 | - include_spip('inc/modifier'); |
|
| 154 | - include_spip('inc/filtres'); |
|
| 155 | - $c = collecter_requests( |
|
| 156 | - // white list |
|
| 157 | - objet_info('auteur', 'champs_editables'), |
|
| 158 | - // black list |
|
| 159 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | - // donnees eventuellement fournies |
|
| 161 | - $set |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - if ( |
|
| 165 | - $err = objet_modifier_champs( |
|
| 166 | - 'auteur', |
|
| 167 | - $id_auteur, |
|
| 168 | - [ |
|
| 169 | - 'data' => $set, |
|
| 170 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | - ], |
|
| 172 | - $c |
|
| 173 | - ) |
|
| 174 | - ) { |
|
| 175 | - return $err; |
|
| 176 | - } |
|
| 177 | - $session = $c; |
|
| 178 | - |
|
| 179 | - $err = ''; |
|
| 180 | - if (!$force_update) { |
|
| 181 | - // Modification de statut, changement de rubrique ? |
|
| 182 | - $c = collecter_requests( |
|
| 183 | - // white list |
|
| 184 | - [ |
|
| 185 | - 'statut', |
|
| 186 | - 'new_login', |
|
| 187 | - 'new_pass', |
|
| 188 | - 'login', |
|
| 189 | - 'pass', |
|
| 190 | - 'webmestre', |
|
| 191 | - 'restreintes', |
|
| 192 | - 'id_parent' |
|
| 193 | - ], |
|
| 194 | - // black list |
|
| 195 | - [], |
|
| 196 | - // donnees eventuellement fournies |
|
| 197 | - $set |
|
| 198 | - ); |
|
| 199 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | - $c['login'] = $c['new_login']; |
|
| 201 | - } |
|
| 202 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | - $c['pass'] = $c['new_pass']; |
|
| 204 | - } |
|
| 205 | - $err = auteur_instituer($id_auteur, $c); |
|
| 206 | - $session = array_merge($session, $c); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // .. mettre a jour les sessions de cet auteur |
|
| 210 | - include_spip('inc/session'); |
|
| 211 | - $session['id_auteur'] = $id_auteur; |
|
| 212 | - unset($session['new_login']); |
|
| 213 | - unset($session['new_pass']); |
|
| 214 | - actualiser_sessions($session); |
|
| 215 | - |
|
| 216 | - return $err; |
|
| 153 | + include_spip('inc/modifier'); |
|
| 154 | + include_spip('inc/filtres'); |
|
| 155 | + $c = collecter_requests( |
|
| 156 | + // white list |
|
| 157 | + objet_info('auteur', 'champs_editables'), |
|
| 158 | + // black list |
|
| 159 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | + // donnees eventuellement fournies |
|
| 161 | + $set |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + if ( |
|
| 165 | + $err = objet_modifier_champs( |
|
| 166 | + 'auteur', |
|
| 167 | + $id_auteur, |
|
| 168 | + [ |
|
| 169 | + 'data' => $set, |
|
| 170 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | + ], |
|
| 172 | + $c |
|
| 173 | + ) |
|
| 174 | + ) { |
|
| 175 | + return $err; |
|
| 176 | + } |
|
| 177 | + $session = $c; |
|
| 178 | + |
|
| 179 | + $err = ''; |
|
| 180 | + if (!$force_update) { |
|
| 181 | + // Modification de statut, changement de rubrique ? |
|
| 182 | + $c = collecter_requests( |
|
| 183 | + // white list |
|
| 184 | + [ |
|
| 185 | + 'statut', |
|
| 186 | + 'new_login', |
|
| 187 | + 'new_pass', |
|
| 188 | + 'login', |
|
| 189 | + 'pass', |
|
| 190 | + 'webmestre', |
|
| 191 | + 'restreintes', |
|
| 192 | + 'id_parent' |
|
| 193 | + ], |
|
| 194 | + // black list |
|
| 195 | + [], |
|
| 196 | + // donnees eventuellement fournies |
|
| 197 | + $set |
|
| 198 | + ); |
|
| 199 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | + $c['login'] = $c['new_login']; |
|
| 201 | + } |
|
| 202 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | + $c['pass'] = $c['new_pass']; |
|
| 204 | + } |
|
| 205 | + $err = auteur_instituer($id_auteur, $c); |
|
| 206 | + $session = array_merge($session, $c); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // .. mettre a jour les sessions de cet auteur |
|
| 210 | + include_spip('inc/session'); |
|
| 211 | + $session['id_auteur'] = $id_auteur; |
|
| 212 | + unset($session['new_login']); |
|
| 213 | + unset($session['new_pass']); |
|
| 214 | + actualiser_sessions($session); |
|
| 215 | + |
|
| 216 | + return $err; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 237 | - include_spip('action/editer_liens'); |
|
| 237 | + include_spip('action/editer_liens'); |
|
| 238 | 238 | |
| 239 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 239 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function auteur_dissocier($id_auteur, $objets) { |
| 258 | - include_spip('action/editer_liens'); |
|
| 258 | + include_spip('action/editer_liens'); |
|
| 259 | 259 | |
| 260 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 260 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * @return bool|int |
| 279 | 279 | */ |
| 280 | 280 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 281 | - include_spip('action/editer_liens'); |
|
| 281 | + include_spip('action/editer_liens'); |
|
| 282 | 282 | |
| 283 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 283 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -299,139 +299,139 @@ discard block |
||
| 299 | 299 | * @return bool|string |
| 300 | 300 | */ |
| 301 | 301 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 302 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | - $champs = []; |
|
| 307 | - |
|
| 308 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | - $champs['login'] = $c['login']; |
|
| 311 | - } |
|
| 312 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | - $champs['pass'] = $c['pass']; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | - |
|
| 318 | - if ( |
|
| 319 | - isset($c['statut']) |
|
| 320 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | - ) { |
|
| 322 | - $statut = $champs['statut'] = $c['statut']; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Restreindre avant de declarer l'auteur |
|
| 326 | - // (section critique sur les droits) |
|
| 327 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | - if (is_array($c['restreintes'])) { |
|
| 329 | - $c['restreintes'][] = $c['id_parent']; |
|
| 330 | - } else { |
|
| 331 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( |
|
| 336 | - isset($c['webmestre']) |
|
| 337 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | - ) { |
|
| 339 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - // Envoyer aux plugins |
|
| 348 | - $champs = pipeline( |
|
| 349 | - 'pre_edition', |
|
| 350 | - [ |
|
| 351 | - 'args' => [ |
|
| 352 | - 'table' => 'spip_auteurs', |
|
| 353 | - 'id_objet' => $id_auteur, |
|
| 354 | - 'action' => 'instituer', |
|
| 355 | - 'statut_ancien' => $statut_ancien, |
|
| 356 | - ], |
|
| 357 | - 'data' => $champs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - if ( |
|
| 362 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | - ) { |
|
| 365 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | - $rubriques = array_unique($rubriques); |
|
| 367 | - $rubriques = array_diff($rubriques, [0]); |
|
| 368 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - $flag_ecrire_acces = false; |
|
| 373 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | - // avant les autres ecritures en base |
|
| 375 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | - include_spip('inc/auth'); |
|
| 378 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - unset($champs['login']); |
|
| 390 | - unset($champs['pass']); |
|
| 391 | - $flag_ecrire_acces = true; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | - } |
|
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | - |
|
| 399 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | - if ( |
|
| 401 | - $flag_ecrire_acces |
|
| 402 | - or isset($champs['statut']) |
|
| 403 | - ) { |
|
| 404 | - include_spip('inc/acces'); |
|
| 405 | - ecrire_acces(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // Invalider les caches |
|
| 409 | - include_spip('inc/invalideur'); |
|
| 410 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | - |
|
| 412 | - // Pipeline |
|
| 413 | - pipeline( |
|
| 414 | - 'post_edition', |
|
| 415 | - [ |
|
| 416 | - 'args' => [ |
|
| 417 | - 'table' => 'spip_auteurs', |
|
| 418 | - 'id_objet' => $id_auteur, |
|
| 419 | - 'action' => 'instituer', |
|
| 420 | - 'statut_ancien' => $statut_ancien, |
|
| 421 | - ], |
|
| 422 | - 'data' => $champs |
|
| 423 | - ] |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - // Notifications |
|
| 428 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | - $notifications( |
|
| 430 | - 'instituerauteur', |
|
| 431 | - $id_auteur, |
|
| 432 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 302 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | + $champs = []; |
|
| 307 | + |
|
| 308 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | + $champs['login'] = $c['login']; |
|
| 311 | + } |
|
| 312 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | + $champs['pass'] = $c['pass']; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | + |
|
| 318 | + if ( |
|
| 319 | + isset($c['statut']) |
|
| 320 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | + ) { |
|
| 322 | + $statut = $champs['statut'] = $c['statut']; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Restreindre avant de declarer l'auteur |
|
| 326 | + // (section critique sur les droits) |
|
| 327 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | + if (is_array($c['restreintes'])) { |
|
| 329 | + $c['restreintes'][] = $c['id_parent']; |
|
| 330 | + } else { |
|
| 331 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( |
|
| 336 | + isset($c['webmestre']) |
|
| 337 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | + ) { |
|
| 339 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + // Envoyer aux plugins |
|
| 348 | + $champs = pipeline( |
|
| 349 | + 'pre_edition', |
|
| 350 | + [ |
|
| 351 | + 'args' => [ |
|
| 352 | + 'table' => 'spip_auteurs', |
|
| 353 | + 'id_objet' => $id_auteur, |
|
| 354 | + 'action' => 'instituer', |
|
| 355 | + 'statut_ancien' => $statut_ancien, |
|
| 356 | + ], |
|
| 357 | + 'data' => $champs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + if ( |
|
| 362 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | + ) { |
|
| 365 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | + $rubriques = array_unique($rubriques); |
|
| 367 | + $rubriques = array_diff($rubriques, [0]); |
|
| 368 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + $flag_ecrire_acces = false; |
|
| 373 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | + // avant les autres ecritures en base |
|
| 375 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | + include_spip('inc/auth'); |
|
| 378 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + unset($champs['login']); |
|
| 390 | + unset($champs['pass']); |
|
| 391 | + $flag_ecrire_acces = true; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | + } |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | + |
|
| 399 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | + if ( |
|
| 401 | + $flag_ecrire_acces |
|
| 402 | + or isset($champs['statut']) |
|
| 403 | + ) { |
|
| 404 | + include_spip('inc/acces'); |
|
| 405 | + ecrire_acces(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // Invalider les caches |
|
| 409 | + include_spip('inc/invalideur'); |
|
| 410 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | + |
|
| 412 | + // Pipeline |
|
| 413 | + pipeline( |
|
| 414 | + 'post_edition', |
|
| 415 | + [ |
|
| 416 | + 'args' => [ |
|
| 417 | + 'table' => 'spip_auteurs', |
|
| 418 | + 'id_objet' => $id_auteur, |
|
| 419 | + 'action' => 'instituer', |
|
| 420 | + 'statut_ancien' => $statut_ancien, |
|
| 421 | + ], |
|
| 422 | + 'data' => $champs |
|
| 423 | + ] |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + // Notifications |
|
| 428 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | + $notifications( |
|
| 430 | + 'instituerauteur', |
|
| 431 | + $id_auteur, |
|
| 432 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 437 | 437 | } |
@@ -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 | /** |
@@ -29,24 +29,24 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function action_instituer_objet_dist($arg = null) { |
| 31 | 31 | |
| 32 | - if (is_null($arg)) { |
|
| 33 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | - $arg = $securiser_action(); |
|
| 35 | - } |
|
| 32 | + if (is_null($arg)) { |
|
| 33 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | + $arg = $securiser_action(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | - if (!$statut) { |
|
| 39 | - $statut = _request('statut_nouv'); |
|
| 40 | - } // cas POST |
|
| 41 | - if (!$statut) { |
|
| 42 | - return; |
|
| 43 | - } // impossible mais sait-on jamais |
|
| 37 | + [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | + if (!$statut) { |
|
| 39 | + $statut = _request('statut_nouv'); |
|
| 40 | + } // cas POST |
|
| 41 | + if (!$statut) { |
|
| 42 | + return; |
|
| 43 | + } // impossible mais sait-on jamais |
|
| 44 | 44 | |
| 45 | - if ( |
|
| 46 | - $id_objet = intval($id_objet) |
|
| 47 | - and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | - ) { |
|
| 49 | - include_spip('action/editer_objet'); |
|
| 50 | - objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | - } |
|
| 45 | + if ( |
|
| 46 | + $id_objet = intval($id_objet) |
|
| 47 | + and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | + ) { |
|
| 49 | + include_spip('action/editer_objet'); |
|
| 50 | + objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // charger la gestion les rôles sur les objets |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | * - array(clé primaire, nom de la table de lien) si associable |
| 48 | 48 | */ |
| 49 | 49 | function objet_associable($objet) { |
| 50 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | - $table_sql = table_objet_sql($objet); |
|
| 52 | - |
|
| 53 | - $l = ''; |
|
| 54 | - if ( |
|
| 55 | - $primary = id_table_objet($objet) |
|
| 56 | - and $trouver_table($l = $table_sql . '_liens', '', true, ['log_missing' => false]) |
|
| 57 | - and !preg_match(',[^\w],', $primary) |
|
| 58 | - and !preg_match(',[^\w],', $l) |
|
| 59 | - ) { |
|
| 60 | - return [$primary, $l]; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 64 | - |
|
| 65 | - return false; |
|
| 50 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | + $table_sql = table_objet_sql($objet); |
|
| 52 | + |
|
| 53 | + $l = ''; |
|
| 54 | + if ( |
|
| 55 | + $primary = id_table_objet($objet) |
|
| 56 | + and $trouver_table($l = $table_sql . '_liens', '', true, ['log_missing' => false]) |
|
| 57 | + and !preg_match(',[^\w],', $primary) |
|
| 58 | + and !preg_match(',[^\w],', $l) |
|
| 59 | + ) { |
|
| 60 | + return [$primary, $l]; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 64 | + |
|
| 65 | + return false; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @return bool|int |
| 89 | 89 | */ |
| 90 | 90 | function objet_associer($objets_source, $objets_lies, $qualif = null) { |
| 91 | - $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 91 | + $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 92 | 92 | |
| 93 | - if ($qualif) { |
|
| 94 | - objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 95 | - } |
|
| 93 | + if ($qualif) { |
|
| 94 | + objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $modifs; // pas d'erreur |
|
| 97 | + return $modifs; // pas d'erreur |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return bool|int |
| 129 | 129 | */ |
| 130 | 130 | function objet_dissocier($objets_source, $objets_lies, $cond = null) { |
| 131 | - return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 131 | + return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return bool|int |
| 154 | 154 | */ |
| 155 | 155 | function objet_qualifier_liens($objets_source, $objets_lies, $qualif) { |
| 156 | - return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 156 | + return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * Liste des trouvailles |
| 189 | 189 | */ |
| 190 | 190 | function objet_trouver_liens($objets_source, $objets_lies, $cond = null) { |
| 191 | - return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 191 | + return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @return int |
| 213 | 213 | */ |
| 214 | 214 | function objet_optimiser_liens($objets_source, $objets_lies) { |
| 215 | - spip_log('objet_optimiser_liens : ' . json_encode($objets_source, JSON_THROW_ON_ERROR) . ', ' . json_encode($objets_lies, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 216 | - return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 215 | + spip_log('objet_optimiser_liens : ' . json_encode($objets_source, JSON_THROW_ON_ERROR) . ', ' . json_encode($objets_lies, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 216 | + return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | |
@@ -233,37 +233,37 @@ discard block |
||
| 233 | 233 | * Nombre de liens copiés |
| 234 | 234 | */ |
| 235 | 235 | function objet_dupliquer_liens($objet, $id_source, $id_cible, $types = null, $exclure_types = null) { |
| 236 | - include_spip('base/objets'); |
|
| 237 | - $tables = lister_tables_objets_sql(); |
|
| 238 | - $n = 0; |
|
| 239 | - foreach ($tables as $table_sql => $infos) { |
|
| 240 | - if ( |
|
| 241 | - (is_null($types) or in_array($infos['type'], $types)) |
|
| 242 | - and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 243 | - ) { |
|
| 244 | - if (objet_associable($infos['type'])) { |
|
| 245 | - $liens = (($infos['type'] == $objet) ? |
|
| 246 | - objet_trouver_liens([$objet => $id_source], '*') |
|
| 247 | - : |
|
| 248 | - objet_trouver_liens([$infos['type'] => '*'], [$objet => $id_source])); |
|
| 249 | - foreach ($liens as $lien) { |
|
| 250 | - $n++; |
|
| 251 | - if ($infos['type'] == $objet) { |
|
| 252 | - if ( |
|
| 253 | - (is_null($types) or in_array($lien['objet'], $types)) |
|
| 254 | - and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types)) |
|
| 255 | - ) { |
|
| 256 | - objet_associer([$objet => $id_cible], [$lien['objet'] => $lien[$lien['objet']]], $lien); |
|
| 257 | - } |
|
| 258 | - } else { |
|
| 259 | - objet_associer([$infos['type'] => $lien[$infos['type']]], [$objet => $id_cible], $lien); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $n; |
|
| 236 | + include_spip('base/objets'); |
|
| 237 | + $tables = lister_tables_objets_sql(); |
|
| 238 | + $n = 0; |
|
| 239 | + foreach ($tables as $table_sql => $infos) { |
|
| 240 | + if ( |
|
| 241 | + (is_null($types) or in_array($infos['type'], $types)) |
|
| 242 | + and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 243 | + ) { |
|
| 244 | + if (objet_associable($infos['type'])) { |
|
| 245 | + $liens = (($infos['type'] == $objet) ? |
|
| 246 | + objet_trouver_liens([$objet => $id_source], '*') |
|
| 247 | + : |
|
| 248 | + objet_trouver_liens([$infos['type'] => '*'], [$objet => $id_source])); |
|
| 249 | + foreach ($liens as $lien) { |
|
| 250 | + $n++; |
|
| 251 | + if ($infos['type'] == $objet) { |
|
| 252 | + if ( |
|
| 253 | + (is_null($types) or in_array($lien['objet'], $types)) |
|
| 254 | + and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types)) |
|
| 255 | + ) { |
|
| 256 | + objet_associer([$objet => $id_cible], [$lien['objet'] => $lien[$lien['objet']]], $lien); |
|
| 257 | + } |
|
| 258 | + } else { |
|
| 259 | + objet_associer([$infos['type'] => $lien[$infos['type']]], [$objet => $id_cible], $lien); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $n; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -305,38 +305,38 @@ discard block |
||
| 305 | 305 | * @return bool|int|array |
| 306 | 306 | */ |
| 307 | 307 | function objet_traiter_liaisons($operation, $objets_source, $objets_lies, $set = null) { |
| 308 | - // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 309 | - if ($objets_lies == '*') { |
|
| 310 | - $objets_lies = ['*' => '*']; |
|
| 311 | - } |
|
| 312 | - $modifs = 0; // compter le nombre de modifications |
|
| 313 | - $echec = null; |
|
| 314 | - foreach ($objets_source as $objet => $ids) { |
|
| 315 | - if ($a = objet_associable($objet)) { |
|
| 316 | - [$primary, $l] = $a; |
|
| 317 | - if (!is_array($ids)) { |
|
| 318 | - $ids = [$ids]; |
|
| 319 | - } elseif (reset($ids) == 'NOT') { |
|
| 320 | - // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 321 | - $where = lien_where($primary, $ids, '*', '*'); |
|
| 322 | - $ids = sql_allfetsel($primary, $l, $where); |
|
| 323 | - $ids = array_map('reset', $ids); |
|
| 324 | - } |
|
| 325 | - foreach ($ids as $id) { |
|
| 326 | - $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 327 | - if ($res === false) { |
|
| 328 | - spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 329 | - $echec = true; |
|
| 330 | - } else { |
|
| 331 | - $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } else { |
|
| 335 | - $echec = true; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return ($echec ? false : $modifs); // pas d'erreur |
|
| 308 | + // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 309 | + if ($objets_lies == '*') { |
|
| 310 | + $objets_lies = ['*' => '*']; |
|
| 311 | + } |
|
| 312 | + $modifs = 0; // compter le nombre de modifications |
|
| 313 | + $echec = null; |
|
| 314 | + foreach ($objets_source as $objet => $ids) { |
|
| 315 | + if ($a = objet_associable($objet)) { |
|
| 316 | + [$primary, $l] = $a; |
|
| 317 | + if (!is_array($ids)) { |
|
| 318 | + $ids = [$ids]; |
|
| 319 | + } elseif (reset($ids) == 'NOT') { |
|
| 320 | + // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 321 | + $where = lien_where($primary, $ids, '*', '*'); |
|
| 322 | + $ids = sql_allfetsel($primary, $l, $where); |
|
| 323 | + $ids = array_map('reset', $ids); |
|
| 324 | + } |
|
| 325 | + foreach ($ids as $id) { |
|
| 326 | + $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 327 | + if ($res === false) { |
|
| 328 | + spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 329 | + $echec = true; |
|
| 330 | + } else { |
|
| 331 | + $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } else { |
|
| 335 | + $echec = true; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return ($echec ? false : $modifs); // pas d'erreur |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -365,117 +365,117 @@ discard block |
||
| 365 | 365 | * Nombre d'insertions faites, false si échec. |
| 366 | 366 | */ |
| 367 | 367 | function lien_insert($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 368 | - $ins = 0; |
|
| 369 | - $echec = null; |
|
| 370 | - if (is_null($qualif)) { |
|
| 371 | - $qualif = []; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - foreach ($objets as $objet => $id_objets) { |
|
| 375 | - if (!is_array($id_objets)) { |
|
| 376 | - $id_objets = [$id_objets]; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // role, colonne, where par défaut |
|
| 380 | - [$role, $colonne_role, $cond] = |
|
| 381 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 382 | - |
|
| 383 | - foreach ($id_objets as $id_objet) { |
|
| 384 | - $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 385 | - |
|
| 386 | - $insertions = [ |
|
| 387 | - 'id_objet' => $id_objet, |
|
| 388 | - 'objet' => $objet, |
|
| 389 | - $primary => $id |
|
| 390 | - ]; |
|
| 391 | - // rôle en plus s'il est défini |
|
| 392 | - if ($role) { |
|
| 393 | - $insertions += [ |
|
| 394 | - $colonne_role => $role |
|
| 395 | - ]; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if (lien_triables($table_lien)) { |
|
| 399 | - if (isset($qualif['rang_lien'])) { |
|
| 400 | - $rang = $qualif['rang_lien']; |
|
| 401 | - } |
|
| 402 | - else { |
|
| 403 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 404 | - // si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul |
|
| 405 | - if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) { |
|
| 406 | - $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 407 | - $rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where)); |
|
| 408 | - // si aucun lien n'a de rang, on en introduit pas, on garde zero |
|
| 409 | - if ($rang > 0) { |
|
| 410 | - $rang = intval($rang) + 1; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - $insertions['rang_lien'] = $rang; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $args = [ |
|
| 418 | - 'table_lien' => $table_lien, |
|
| 419 | - 'objet_source' => $objet_source, |
|
| 420 | - 'id_objet_source' => $id, |
|
| 421 | - 'objet' => $objet, |
|
| 422 | - 'id_objet' => $id_objet, |
|
| 423 | - 'role' => $role, |
|
| 424 | - 'colonne_role' => $colonne_role, |
|
| 425 | - 'action' => 'insert', |
|
| 426 | - ]; |
|
| 427 | - |
|
| 428 | - // Envoyer aux plugins |
|
| 429 | - $insertions = pipeline( |
|
| 430 | - 'pre_edition_lien', |
|
| 431 | - [ |
|
| 432 | - 'args' => $args, |
|
| 433 | - 'data' => $insertions |
|
| 434 | - ] |
|
| 435 | - ); |
|
| 436 | - $args['id_objet'] = $insertions['id_objet']; |
|
| 437 | - |
|
| 438 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 439 | - |
|
| 440 | - if ( |
|
| 441 | - ($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique'])) |
|
| 442 | - and !sql_getfetsel($primary, $table_lien, $where) |
|
| 443 | - ) { |
|
| 444 | - if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) { |
|
| 445 | - $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 446 | - $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 447 | - // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 448 | - // sauf sur le meme lien avec un role eventuellement different |
|
| 449 | - $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($insertions['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 450 | - sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - $e = sql_insertq($table_lien, $insertions); |
|
| 454 | - if ($e !== false) { |
|
| 455 | - $ins++; |
|
| 456 | - lien_propage_date_modif($objet, $id_objet); |
|
| 457 | - lien_propage_date_modif($objet_source, $id); |
|
| 458 | - // Envoyer aux plugins |
|
| 459 | - pipeline( |
|
| 460 | - 'post_edition_lien', |
|
| 461 | - [ |
|
| 462 | - 'args' => $args, |
|
| 463 | - 'data' => $insertions |
|
| 464 | - ] |
|
| 465 | - ); |
|
| 466 | - } else { |
|
| 467 | - $echec = true; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - // si on a fait des insertions, on reordonne les liens concernes |
|
| 473 | - // pas la peine si $qualif['rang_lien'] etait fournie, on va passer dans lien_set a suivre et donc finir le recomptage |
|
| 474 | - if ($ins > 0 and empty($qualif['rang_lien'])) { |
|
| 475 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - return ($echec ? false : $ins); |
|
| 368 | + $ins = 0; |
|
| 369 | + $echec = null; |
|
| 370 | + if (is_null($qualif)) { |
|
| 371 | + $qualif = []; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + foreach ($objets as $objet => $id_objets) { |
|
| 375 | + if (!is_array($id_objets)) { |
|
| 376 | + $id_objets = [$id_objets]; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // role, colonne, where par défaut |
|
| 380 | + [$role, $colonne_role, $cond] = |
|
| 381 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 382 | + |
|
| 383 | + foreach ($id_objets as $id_objet) { |
|
| 384 | + $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 385 | + |
|
| 386 | + $insertions = [ |
|
| 387 | + 'id_objet' => $id_objet, |
|
| 388 | + 'objet' => $objet, |
|
| 389 | + $primary => $id |
|
| 390 | + ]; |
|
| 391 | + // rôle en plus s'il est défini |
|
| 392 | + if ($role) { |
|
| 393 | + $insertions += [ |
|
| 394 | + $colonne_role => $role |
|
| 395 | + ]; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if (lien_triables($table_lien)) { |
|
| 399 | + if (isset($qualif['rang_lien'])) { |
|
| 400 | + $rang = $qualif['rang_lien']; |
|
| 401 | + } |
|
| 402 | + else { |
|
| 403 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 404 | + // si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul |
|
| 405 | + if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) { |
|
| 406 | + $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 407 | + $rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where)); |
|
| 408 | + // si aucun lien n'a de rang, on en introduit pas, on garde zero |
|
| 409 | + if ($rang > 0) { |
|
| 410 | + $rang = intval($rang) + 1; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + $insertions['rang_lien'] = $rang; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $args = [ |
|
| 418 | + 'table_lien' => $table_lien, |
|
| 419 | + 'objet_source' => $objet_source, |
|
| 420 | + 'id_objet_source' => $id, |
|
| 421 | + 'objet' => $objet, |
|
| 422 | + 'id_objet' => $id_objet, |
|
| 423 | + 'role' => $role, |
|
| 424 | + 'colonne_role' => $colonne_role, |
|
| 425 | + 'action' => 'insert', |
|
| 426 | + ]; |
|
| 427 | + |
|
| 428 | + // Envoyer aux plugins |
|
| 429 | + $insertions = pipeline( |
|
| 430 | + 'pre_edition_lien', |
|
| 431 | + [ |
|
| 432 | + 'args' => $args, |
|
| 433 | + 'data' => $insertions |
|
| 434 | + ] |
|
| 435 | + ); |
|
| 436 | + $args['id_objet'] = $insertions['id_objet']; |
|
| 437 | + |
|
| 438 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 439 | + |
|
| 440 | + if ( |
|
| 441 | + ($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique'])) |
|
| 442 | + and !sql_getfetsel($primary, $table_lien, $where) |
|
| 443 | + ) { |
|
| 444 | + if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) { |
|
| 445 | + $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 446 | + $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 447 | + // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 448 | + // sauf sur le meme lien avec un role eventuellement different |
|
| 449 | + $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($insertions['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 450 | + sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + $e = sql_insertq($table_lien, $insertions); |
|
| 454 | + if ($e !== false) { |
|
| 455 | + $ins++; |
|
| 456 | + lien_propage_date_modif($objet, $id_objet); |
|
| 457 | + lien_propage_date_modif($objet_source, $id); |
|
| 458 | + // Envoyer aux plugins |
|
| 459 | + pipeline( |
|
| 460 | + 'post_edition_lien', |
|
| 461 | + [ |
|
| 462 | + 'args' => $args, |
|
| 463 | + 'data' => $insertions |
|
| 464 | + ] |
|
| 465 | + ); |
|
| 466 | + } else { |
|
| 467 | + $echec = true; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + // si on a fait des insertions, on reordonne les liens concernes |
|
| 473 | + // pas la peine si $qualif['rang_lien'] etait fournie, on va passer dans lien_set a suivre et donc finir le recomptage |
|
| 474 | + if ($ins > 0 and empty($qualif['rang_lien'])) { |
|
| 475 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + return ($echec ? false : $ins); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -488,47 +488,47 @@ discard block |
||
| 488 | 488 | * @param array|string $objets |
| 489 | 489 | */ |
| 490 | 490 | function lien_ordonner($objet_source, $primary, $table_lien, $id, $objets) { |
| 491 | - if (!lien_triables($table_lien)) { |
|
| 492 | - return; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $deja_reordonne = []; |
|
| 496 | - |
|
| 497 | - foreach ($objets as $objet => $id_objets) { |
|
| 498 | - if (!is_array($id_objets)) { |
|
| 499 | - $id_objets = [$id_objets]; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - foreach ($id_objets as $id_objet) { |
|
| 503 | - if (empty($deja_reordonne[$id][$objet][$id_objet])) { |
|
| 504 | - $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 505 | - |
|
| 506 | - $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 507 | - $liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, '', 'rang_lien'); |
|
| 508 | - |
|
| 509 | - $rangs = array_column($liens, 'rang_lien'); |
|
| 510 | - if (count($rangs) and (max($rangs) > 0 or min($rangs) < 0)) { |
|
| 511 | - $rang = 1; |
|
| 512 | - foreach ($liens as $lien) { |
|
| 513 | - if (empty($deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']])) { |
|
| 514 | - $where = lien_where($primary, $lien[$primary], $lien['objet'], $lien['id_objet'], ['rang_lien!=' . intval($rang)]); |
|
| 515 | - sql_updateq($table_lien, ['rang_lien' => $rang], $where); |
|
| 516 | - |
|
| 517 | - if (empty($deja_reordonne[$lien[$primary]])) { |
|
| 518 | - $deja_reordonne[$lien[$primary]] = []; |
|
| 519 | - } |
|
| 520 | - if (empty($deja_reordonne[$lien[$primary]][$lien['objet']])) { |
|
| 521 | - $deja_reordonne[$lien[$primary]][$lien['objet']] = []; |
|
| 522 | - } |
|
| 523 | - $deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']] = $rang; |
|
| 524 | - |
|
| 525 | - $rang++; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - } |
|
| 491 | + if (!lien_triables($table_lien)) { |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $deja_reordonne = []; |
|
| 496 | + |
|
| 497 | + foreach ($objets as $objet => $id_objets) { |
|
| 498 | + if (!is_array($id_objets)) { |
|
| 499 | + $id_objets = [$id_objets]; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + foreach ($id_objets as $id_objet) { |
|
| 503 | + if (empty($deja_reordonne[$id][$objet][$id_objet])) { |
|
| 504 | + $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 505 | + |
|
| 506 | + $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 507 | + $liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, '', 'rang_lien'); |
|
| 508 | + |
|
| 509 | + $rangs = array_column($liens, 'rang_lien'); |
|
| 510 | + if (count($rangs) and (max($rangs) > 0 or min($rangs) < 0)) { |
|
| 511 | + $rang = 1; |
|
| 512 | + foreach ($liens as $lien) { |
|
| 513 | + if (empty($deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']])) { |
|
| 514 | + $where = lien_where($primary, $lien[$primary], $lien['objet'], $lien['id_objet'], ['rang_lien!=' . intval($rang)]); |
|
| 515 | + sql_updateq($table_lien, ['rang_lien' => $rang], $where); |
|
| 516 | + |
|
| 517 | + if (empty($deja_reordonne[$lien[$primary]])) { |
|
| 518 | + $deja_reordonne[$lien[$primary]] = []; |
|
| 519 | + } |
|
| 520 | + if (empty($deja_reordonne[$lien[$primary]][$lien['objet']])) { |
|
| 521 | + $deja_reordonne[$lien[$primary]][$lien['objet']] = []; |
|
| 522 | + } |
|
| 523 | + $deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']] = $rang; |
|
| 524 | + |
|
| 525 | + $rang++; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | |
@@ -539,18 +539,18 @@ discard block |
||
| 539 | 539 | * @return mixed |
| 540 | 540 | */ |
| 541 | 541 | function lien_triables($table_lien) { |
| 542 | - static $triables = []; |
|
| 543 | - if (!isset($triables[$table_lien])) { |
|
| 544 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 545 | - $desc = $trouver_table($table_lien); |
|
| 546 | - if ($desc and isset($desc['field']['rang_lien'])) { |
|
| 547 | - $triables[$table_lien] = true; |
|
| 548 | - } |
|
| 549 | - else { |
|
| 550 | - $triables[$table_lien] = false; |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - return $triables[$table_lien]; |
|
| 542 | + static $triables = []; |
|
| 543 | + if (!isset($triables[$table_lien])) { |
|
| 544 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 545 | + $desc = $trouver_table($table_lien); |
|
| 546 | + if ($desc and isset($desc['field']['rang_lien'])) { |
|
| 547 | + $triables[$table_lien] = true; |
|
| 548 | + } |
|
| 549 | + else { |
|
| 550 | + $triables[$table_lien] = false; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + return $triables[$table_lien]; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -566,52 +566,52 @@ discard block |
||
| 566 | 566 | * @return array Liste des conditions |
| 567 | 567 | */ |
| 568 | 568 | function lien_where($primary, $id_source, $objet, $id_objet, $cond = []) { |
| 569 | - if ( |
|
| 570 | - (!is_array($id_source) and !strlen($id_source)) |
|
| 571 | - or !strlen($objet) |
|
| 572 | - or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 573 | - ) { |
|
| 574 | - return ['0=1']; |
|
| 575 | - } // securite |
|
| 576 | - |
|
| 577 | - $not = ''; |
|
| 578 | - if (is_array($id_source) and reset($id_source) == 'NOT') { |
|
| 579 | - $not = array_shift($id_source); |
|
| 580 | - $id_source = reset($id_source); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - $where = $cond; |
|
| 584 | - |
|
| 585 | - if ($id_source !== '*') { |
|
| 586 | - $where[] = (is_array($id_source) ? sql_in( |
|
| 587 | - addslashes($primary), |
|
| 588 | - array_map('intval', $id_source), |
|
| 589 | - $not |
|
| 590 | - ) : addslashes($primary) . ($not ? '<>' : '=') . intval($id_source)); |
|
| 591 | - } elseif ($not) { |
|
| 592 | - $where[] = '0=1'; |
|
| 593 | - } // idiot mais quand meme |
|
| 594 | - |
|
| 595 | - $not = ''; |
|
| 596 | - if (is_array($id_objet) and reset($id_objet) == 'NOT') { |
|
| 597 | - $not = array_shift($id_objet); |
|
| 598 | - $id_objet = reset($id_objet); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - if ($objet !== '*') { |
|
| 602 | - $where[] = 'objet=' . sql_quote($objet); |
|
| 603 | - } |
|
| 604 | - if ($id_objet !== '*') { |
|
| 605 | - $where[] = (is_array($id_objet) ? sql_in( |
|
| 606 | - 'id_objet', |
|
| 607 | - array_map('intval', $id_objet), |
|
| 608 | - $not |
|
| 609 | - ) : 'id_objet' . ($not ? '<>' : '=') . intval($id_objet)); |
|
| 610 | - } elseif ($not) { |
|
| 611 | - $where[] = '0=1'; |
|
| 612 | - } // idiot mais quand meme |
|
| 613 | - |
|
| 614 | - return $where; |
|
| 569 | + if ( |
|
| 570 | + (!is_array($id_source) and !strlen($id_source)) |
|
| 571 | + or !strlen($objet) |
|
| 572 | + or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 573 | + ) { |
|
| 574 | + return ['0=1']; |
|
| 575 | + } // securite |
|
| 576 | + |
|
| 577 | + $not = ''; |
|
| 578 | + if (is_array($id_source) and reset($id_source) == 'NOT') { |
|
| 579 | + $not = array_shift($id_source); |
|
| 580 | + $id_source = reset($id_source); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $where = $cond; |
|
| 584 | + |
|
| 585 | + if ($id_source !== '*') { |
|
| 586 | + $where[] = (is_array($id_source) ? sql_in( |
|
| 587 | + addslashes($primary), |
|
| 588 | + array_map('intval', $id_source), |
|
| 589 | + $not |
|
| 590 | + ) : addslashes($primary) . ($not ? '<>' : '=') . intval($id_source)); |
|
| 591 | + } elseif ($not) { |
|
| 592 | + $where[] = '0=1'; |
|
| 593 | + } // idiot mais quand meme |
|
| 594 | + |
|
| 595 | + $not = ''; |
|
| 596 | + if (is_array($id_objet) and reset($id_objet) == 'NOT') { |
|
| 597 | + $not = array_shift($id_objet); |
|
| 598 | + $id_objet = reset($id_objet); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + if ($objet !== '*') { |
|
| 602 | + $where[] = 'objet=' . sql_quote($objet); |
|
| 603 | + } |
|
| 604 | + if ($id_objet !== '*') { |
|
| 605 | + $where[] = (is_array($id_objet) ? sql_in( |
|
| 606 | + 'id_objet', |
|
| 607 | + array_map('intval', $id_objet), |
|
| 608 | + $not |
|
| 609 | + ) : 'id_objet' . ($not ? '<>' : '=') . intval($id_objet)); |
|
| 610 | + } elseif ($not) { |
|
| 611 | + $where[] = '0=1'; |
|
| 612 | + } // idiot mais quand meme |
|
| 613 | + |
|
| 614 | + return $where; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -626,13 +626,13 @@ discard block |
||
| 626 | 626 | */ |
| 627 | 627 | function lien_rang_where($table_lien, $primary, $id_source, $objet, $id_objet, $cond = []) { |
| 628 | 628 | |
| 629 | - // si on veut compter les rangs autrement que le core ne le fait par defaut, fournir le where adhoc |
|
| 630 | - if (function_exists($f = 'lien_rang_where_' . $table_lien)) { |
|
| 631 | - return $f($primary, $id_source, $objet, $id_objet, $cond); |
|
| 632 | - } |
|
| 629 | + // si on veut compter les rangs autrement que le core ne le fait par defaut, fournir le where adhoc |
|
| 630 | + if (function_exists($f = 'lien_rang_where_' . $table_lien)) { |
|
| 631 | + return $f($primary, $id_source, $objet, $id_objet, $cond); |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | - // par defaut c'est un rang compté pour tous les id_source d'un couple objet-id_objet |
|
| 635 | - return lien_where($primary, '*', $objet, $id_objet, $cond); |
|
| 634 | + // par defaut c'est un rang compté pour tous les id_source d'un couple objet-id_objet |
|
| 635 | + return lien_where($primary, '*', $objet, $id_objet, $cond); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -663,90 +663,90 @@ discard block |
||
| 663 | 663 | */ |
| 664 | 664 | function lien_delete($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 665 | 665 | |
| 666 | - $retire = []; |
|
| 667 | - $dels = 0; |
|
| 668 | - $echec = false; |
|
| 669 | - if (is_null($cond)) { |
|
| 670 | - $cond = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - foreach ($objets as $objet => $id_objets) { |
|
| 674 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 675 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 676 | - $id_objets = [$id_objets]; |
|
| 677 | - } |
|
| 678 | - foreach ($id_objets as $id_objet) { |
|
| 679 | - [$cond, $colonne_role, $role] = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 680 | - // id_objet peut valoir '*' |
|
| 681 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 682 | - |
|
| 683 | - // lire les liens existants pour propager la date de modif |
|
| 684 | - $select = "$primary,id_objet,objet"; |
|
| 685 | - if ($colonne_role) { |
|
| 686 | - $select .= ",$colonne_role"; |
|
| 687 | - } |
|
| 688 | - $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 689 | - |
|
| 690 | - // iterer sur les liens pour permettre aux plugins de gerer |
|
| 691 | - foreach ($liens as $l) { |
|
| 692 | - $args = [ |
|
| 693 | - 'table_lien' => $table_lien, |
|
| 694 | - 'objet_source' => $objet_source, |
|
| 695 | - 'id_objet_source' => $l[$primary], |
|
| 696 | - 'objet' => $l['objet'], |
|
| 697 | - 'id_objet' => $l['id_objet'], |
|
| 698 | - 'colonne_role' => $colonne_role, |
|
| 699 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 700 | - 'action' => 'delete', |
|
| 701 | - ]; |
|
| 702 | - |
|
| 703 | - // Envoyer aux plugins |
|
| 704 | - $l = pipeline( |
|
| 705 | - 'pre_edition_lien', |
|
| 706 | - [ |
|
| 707 | - 'args' => $args, |
|
| 708 | - 'data' => $l |
|
| 709 | - ] |
|
| 710 | - ); |
|
| 711 | - $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 712 | - |
|
| 713 | - if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) { |
|
| 714 | - $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 715 | - $e = sql_delete($table_lien, $where); |
|
| 716 | - if ($e !== false) { |
|
| 717 | - $dels += $e; |
|
| 718 | - lien_propage_date_modif($l['objet'], $id_o); |
|
| 719 | - lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 720 | - } else { |
|
| 721 | - $echec = true; |
|
| 722 | - } |
|
| 723 | - $retire[] = [ |
|
| 724 | - 'source' => [$objet_source => $l[$primary]], |
|
| 725 | - 'lien' => [$l['objet'] => $id_o], |
|
| 726 | - 'type' => $l['objet'], |
|
| 727 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 728 | - 'id' => $id_o |
|
| 729 | - ]; |
|
| 730 | - // Envoyer aux plugins |
|
| 731 | - pipeline( |
|
| 732 | - 'post_edition_lien', |
|
| 733 | - [ |
|
| 734 | - 'args' => $args, |
|
| 735 | - 'data' => $l |
|
| 736 | - ] |
|
| 737 | - ); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - // si on a supprime des liens, on reordonne les liens concernes |
|
| 743 | - if ($dels) { |
|
| 744 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - pipeline('trig_supprimer_objets_lies', $retire); |
|
| 748 | - |
|
| 749 | - return ($echec ? false : $dels); |
|
| 666 | + $retire = []; |
|
| 667 | + $dels = 0; |
|
| 668 | + $echec = false; |
|
| 669 | + if (is_null($cond)) { |
|
| 670 | + $cond = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + foreach ($objets as $objet => $id_objets) { |
|
| 674 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 675 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 676 | + $id_objets = [$id_objets]; |
|
| 677 | + } |
|
| 678 | + foreach ($id_objets as $id_objet) { |
|
| 679 | + [$cond, $colonne_role, $role] = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 680 | + // id_objet peut valoir '*' |
|
| 681 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 682 | + |
|
| 683 | + // lire les liens existants pour propager la date de modif |
|
| 684 | + $select = "$primary,id_objet,objet"; |
|
| 685 | + if ($colonne_role) { |
|
| 686 | + $select .= ",$colonne_role"; |
|
| 687 | + } |
|
| 688 | + $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 689 | + |
|
| 690 | + // iterer sur les liens pour permettre aux plugins de gerer |
|
| 691 | + foreach ($liens as $l) { |
|
| 692 | + $args = [ |
|
| 693 | + 'table_lien' => $table_lien, |
|
| 694 | + 'objet_source' => $objet_source, |
|
| 695 | + 'id_objet_source' => $l[$primary], |
|
| 696 | + 'objet' => $l['objet'], |
|
| 697 | + 'id_objet' => $l['id_objet'], |
|
| 698 | + 'colonne_role' => $colonne_role, |
|
| 699 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 700 | + 'action' => 'delete', |
|
| 701 | + ]; |
|
| 702 | + |
|
| 703 | + // Envoyer aux plugins |
|
| 704 | + $l = pipeline( |
|
| 705 | + 'pre_edition_lien', |
|
| 706 | + [ |
|
| 707 | + 'args' => $args, |
|
| 708 | + 'data' => $l |
|
| 709 | + ] |
|
| 710 | + ); |
|
| 711 | + $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 712 | + |
|
| 713 | + if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) { |
|
| 714 | + $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 715 | + $e = sql_delete($table_lien, $where); |
|
| 716 | + if ($e !== false) { |
|
| 717 | + $dels += $e; |
|
| 718 | + lien_propage_date_modif($l['objet'], $id_o); |
|
| 719 | + lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 720 | + } else { |
|
| 721 | + $echec = true; |
|
| 722 | + } |
|
| 723 | + $retire[] = [ |
|
| 724 | + 'source' => [$objet_source => $l[$primary]], |
|
| 725 | + 'lien' => [$l['objet'] => $id_o], |
|
| 726 | + 'type' => $l['objet'], |
|
| 727 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 728 | + 'id' => $id_o |
|
| 729 | + ]; |
|
| 730 | + // Envoyer aux plugins |
|
| 731 | + pipeline( |
|
| 732 | + 'post_edition_lien', |
|
| 733 | + [ |
|
| 734 | + 'args' => $args, |
|
| 735 | + 'data' => $l |
|
| 736 | + ] |
|
| 737 | + ); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + // si on a supprime des liens, on reordonne les liens concernes |
|
| 743 | + if ($dels) { |
|
| 744 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + pipeline('trig_supprimer_objets_lies', $retire); |
|
| 748 | + |
|
| 749 | + return ($echec ? false : $dels); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | |
@@ -769,67 +769,67 @@ discard block |
||
| 769 | 769 | * @return bool|int |
| 770 | 770 | */ |
| 771 | 771 | function lien_optimise($objet_source, $primary, $table_lien, $id, $objets) { |
| 772 | - include_spip('genie/optimiser'); |
|
| 773 | - $echec = false; |
|
| 774 | - $dels = 0; |
|
| 775 | - foreach ($objets as $objet => $id_objets) { |
|
| 776 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 777 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 778 | - $id_objets = [$id_objets]; |
|
| 779 | - } |
|
| 780 | - foreach ($id_objets as $id_objet) { |
|
| 781 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 782 | - # les liens vers un objet inexistant |
|
| 783 | - $r = sql_select('DISTINCT objet', $table_lien, $where); |
|
| 784 | - while ($t = sql_fetch($r)) { |
|
| 785 | - $type = $t['objet']; |
|
| 786 | - $spip_table_objet = table_objet_sql($type); |
|
| 787 | - $id_table_objet = id_table_objet($type); |
|
| 788 | - $res = sql_select( |
|
| 789 | - "L.$primary AS id,L.id_objet", |
|
| 790 | - // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 791 | - // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 792 | - // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 793 | - "$table_lien AS L |
|
| 772 | + include_spip('genie/optimiser'); |
|
| 773 | + $echec = false; |
|
| 774 | + $dels = 0; |
|
| 775 | + foreach ($objets as $objet => $id_objets) { |
|
| 776 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 777 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 778 | + $id_objets = [$id_objets]; |
|
| 779 | + } |
|
| 780 | + foreach ($id_objets as $id_objet) { |
|
| 781 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 782 | + # les liens vers un objet inexistant |
|
| 783 | + $r = sql_select('DISTINCT objet', $table_lien, $where); |
|
| 784 | + while ($t = sql_fetch($r)) { |
|
| 785 | + $type = $t['objet']; |
|
| 786 | + $spip_table_objet = table_objet_sql($type); |
|
| 787 | + $id_table_objet = id_table_objet($type); |
|
| 788 | + $res = sql_select( |
|
| 789 | + "L.$primary AS id,L.id_objet", |
|
| 790 | + // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 791 | + // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 792 | + // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 793 | + "$table_lien AS L |
|
| 794 | 794 | LEFT JOIN $spip_table_objet AS O |
| 795 | 795 | ON (O.$id_table_objet=L.id_objet AND L.objet=" . sql_quote($type) . ')', |
| 796 | - 'L.objet=' . sql_quote($type) . " AND O.$id_table_objet IS NULL" |
|
| 797 | - ); |
|
| 798 | - // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 799 | - while ($row = sql_fetch($res)) { |
|
| 800 | - if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) { |
|
| 801 | - continue; // gaffe, c'est le logo du site ou des rubriques! |
|
| 802 | - } |
|
| 803 | - $e = sql_delete( |
|
| 804 | - $table_lien, |
|
| 805 | - ["$primary=" . $row['id'], 'id_objet=' . $row['id_objet'], 'objet=' . sql_quote($type)] |
|
| 806 | - ); |
|
| 807 | - if ($e != false) { |
|
| 808 | - $dels += $e; |
|
| 809 | - spip_log( |
|
| 810 | - 'lien_optimise: Entree ' . $row['id'] . '/' . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 811 | - 'genie' . _LOG_INFO_IMPORTANTE |
|
| 812 | - ); |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - # les liens depuis un objet inexistant |
|
| 818 | - $table_source = table_objet_sql($objet_source); |
|
| 819 | - // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 820 | - // (en general '*' pour chaque) |
|
| 821 | - $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 822 | - $where[] = "O.$primary IS NULL"; |
|
| 823 | - $res = sql_select( |
|
| 824 | - "L.$primary AS id", |
|
| 825 | - "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 826 | - $where |
|
| 827 | - ); |
|
| 828 | - $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return ($echec ? false : $dels); |
|
| 796 | + 'L.objet=' . sql_quote($type) . " AND O.$id_table_objet IS NULL" |
|
| 797 | + ); |
|
| 798 | + // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 799 | + while ($row = sql_fetch($res)) { |
|
| 800 | + if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) { |
|
| 801 | + continue; // gaffe, c'est le logo du site ou des rubriques! |
|
| 802 | + } |
|
| 803 | + $e = sql_delete( |
|
| 804 | + $table_lien, |
|
| 805 | + ["$primary=" . $row['id'], 'id_objet=' . $row['id_objet'], 'objet=' . sql_quote($type)] |
|
| 806 | + ); |
|
| 807 | + if ($e != false) { |
|
| 808 | + $dels += $e; |
|
| 809 | + spip_log( |
|
| 810 | + 'lien_optimise: Entree ' . $row['id'] . '/' . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 811 | + 'genie' . _LOG_INFO_IMPORTANTE |
|
| 812 | + ); |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + # les liens depuis un objet inexistant |
|
| 818 | + $table_source = table_objet_sql($objet_source); |
|
| 819 | + // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 820 | + // (en general '*' pour chaque) |
|
| 821 | + $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 822 | + $where[] = "O.$primary IS NULL"; |
|
| 823 | + $res = sql_select( |
|
| 824 | + "L.$primary AS id", |
|
| 825 | + "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 826 | + $where |
|
| 827 | + ); |
|
| 828 | + $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + return ($echec ? false : $dels); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | |
@@ -861,92 +861,92 @@ discard block |
||
| 861 | 861 | * Nombre de modifications faites, false si échec. |
| 862 | 862 | */ |
| 863 | 863 | function lien_set($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 864 | - $echec = null; |
|
| 865 | - $ok = 0; |
|
| 866 | - $reordonner = false; |
|
| 867 | - if (!$qualif) { |
|
| 868 | - return false; |
|
| 869 | - } |
|
| 870 | - // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 871 | - unset($qualif[$primary]); |
|
| 872 | - unset($qualif[$objet_source]); |
|
| 873 | - if (isset($qualif['objet'])) { |
|
| 874 | - unset($qualif[$qualif['objet']]); |
|
| 875 | - } |
|
| 876 | - unset($qualif['objet']); |
|
| 877 | - unset($qualif['id_objet']); |
|
| 878 | - foreach ($objets as $objet => $id_objets) { |
|
| 879 | - // role, colonne, where par défaut |
|
| 880 | - [$role, $colonne_role, $cond] = |
|
| 881 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 882 | - |
|
| 883 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 884 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 885 | - $id_objets = [$id_objets]; |
|
| 886 | - } |
|
| 887 | - foreach ($id_objets as $id_objet) { |
|
| 888 | - $args = [ |
|
| 889 | - 'table_lien' => $table_lien, |
|
| 890 | - 'objet_source' => $objet_source, |
|
| 891 | - 'id_objet_source' => $id, |
|
| 892 | - 'objet' => $objet, |
|
| 893 | - 'id_objet' => $id_objet, |
|
| 894 | - 'role' => $role, |
|
| 895 | - 'colonne_role' => $colonne_role, |
|
| 896 | - 'action' => 'modifier', |
|
| 897 | - ]; |
|
| 898 | - |
|
| 899 | - // Envoyer aux plugins |
|
| 900 | - $qualif = pipeline( |
|
| 901 | - 'pre_edition_lien', |
|
| 902 | - [ |
|
| 903 | - 'args' => $args, |
|
| 904 | - 'data' => $qualif, |
|
| 905 | - ] |
|
| 906 | - ); |
|
| 907 | - $args['id_objet'] = $id_objet; |
|
| 908 | - |
|
| 909 | - if (lien_triables($table_lien) and isset($qualif['rang_lien'])) { |
|
| 910 | - if (intval($qualif['rang_lien'])) { |
|
| 911 | - // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 912 | - // sauf sur le meme lien avec un role eventuellement different |
|
| 913 | - $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 914 | - $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 915 | - $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($qualif['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 916 | - sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 917 | - } |
|
| 918 | - // tous les liens de même rôle recoivent le rang indiqué aussi |
|
| 919 | - if (roles_colonne($objet_source, $objet)) { |
|
| 920 | - $w = lien_where($primary, $id, $objet, $id_objet); |
|
| 921 | - sql_updateq($table_lien, ['rang_lien' => intval($qualif['rang_lien'])], $w); |
|
| 922 | - } |
|
| 923 | - $reordonner = true; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 927 | - $e = sql_updateq($table_lien, $qualif, $where); |
|
| 928 | - |
|
| 929 | - if ($e === false) { |
|
| 930 | - $echec = true; |
|
| 931 | - } else { |
|
| 932 | - // Envoyer aux plugins |
|
| 933 | - pipeline( |
|
| 934 | - 'post_edition_lien', |
|
| 935 | - [ |
|
| 936 | - 'args' => $args, |
|
| 937 | - 'data' => $qualif |
|
| 938 | - ] |
|
| 939 | - ); |
|
| 940 | - $ok++; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - // si on a fait des modif de rang, on reordonne les liens concernes |
|
| 945 | - if ($reordonner) { |
|
| 946 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return ($echec ? false : $ok); |
|
| 864 | + $echec = null; |
|
| 865 | + $ok = 0; |
|
| 866 | + $reordonner = false; |
|
| 867 | + if (!$qualif) { |
|
| 868 | + return false; |
|
| 869 | + } |
|
| 870 | + // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 871 | + unset($qualif[$primary]); |
|
| 872 | + unset($qualif[$objet_source]); |
|
| 873 | + if (isset($qualif['objet'])) { |
|
| 874 | + unset($qualif[$qualif['objet']]); |
|
| 875 | + } |
|
| 876 | + unset($qualif['objet']); |
|
| 877 | + unset($qualif['id_objet']); |
|
| 878 | + foreach ($objets as $objet => $id_objets) { |
|
| 879 | + // role, colonne, where par défaut |
|
| 880 | + [$role, $colonne_role, $cond] = |
|
| 881 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 882 | + |
|
| 883 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 884 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 885 | + $id_objets = [$id_objets]; |
|
| 886 | + } |
|
| 887 | + foreach ($id_objets as $id_objet) { |
|
| 888 | + $args = [ |
|
| 889 | + 'table_lien' => $table_lien, |
|
| 890 | + 'objet_source' => $objet_source, |
|
| 891 | + 'id_objet_source' => $id, |
|
| 892 | + 'objet' => $objet, |
|
| 893 | + 'id_objet' => $id_objet, |
|
| 894 | + 'role' => $role, |
|
| 895 | + 'colonne_role' => $colonne_role, |
|
| 896 | + 'action' => 'modifier', |
|
| 897 | + ]; |
|
| 898 | + |
|
| 899 | + // Envoyer aux plugins |
|
| 900 | + $qualif = pipeline( |
|
| 901 | + 'pre_edition_lien', |
|
| 902 | + [ |
|
| 903 | + 'args' => $args, |
|
| 904 | + 'data' => $qualif, |
|
| 905 | + ] |
|
| 906 | + ); |
|
| 907 | + $args['id_objet'] = $id_objet; |
|
| 908 | + |
|
| 909 | + if (lien_triables($table_lien) and isset($qualif['rang_lien'])) { |
|
| 910 | + if (intval($qualif['rang_lien'])) { |
|
| 911 | + // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 912 | + // sauf sur le meme lien avec un role eventuellement different |
|
| 913 | + $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 914 | + $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 915 | + $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($qualif['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 916 | + sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 917 | + } |
|
| 918 | + // tous les liens de même rôle recoivent le rang indiqué aussi |
|
| 919 | + if (roles_colonne($objet_source, $objet)) { |
|
| 920 | + $w = lien_where($primary, $id, $objet, $id_objet); |
|
| 921 | + sql_updateq($table_lien, ['rang_lien' => intval($qualif['rang_lien'])], $w); |
|
| 922 | + } |
|
| 923 | + $reordonner = true; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 927 | + $e = sql_updateq($table_lien, $qualif, $where); |
|
| 928 | + |
|
| 929 | + if ($e === false) { |
|
| 930 | + $echec = true; |
|
| 931 | + } else { |
|
| 932 | + // Envoyer aux plugins |
|
| 933 | + pipeline( |
|
| 934 | + 'post_edition_lien', |
|
| 935 | + [ |
|
| 936 | + 'args' => $args, |
|
| 937 | + 'data' => $qualif |
|
| 938 | + ] |
|
| 939 | + ); |
|
| 940 | + $ok++; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + // si on a fait des modif de rang, on reordonne les liens concernes |
|
| 945 | + if ($reordonner) { |
|
| 946 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return ($echec ? false : $ok); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | /** |
@@ -976,23 +976,23 @@ discard block |
||
| 976 | 976 | * @return array |
| 977 | 977 | */ |
| 978 | 978 | function lien_find($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 979 | - $trouve = []; |
|
| 980 | - foreach ($objets as $objet => $id_objets) { |
|
| 981 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 982 | - // gerer les roles s'il y en a dans $cond |
|
| 983 | - [$cond] = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 984 | - // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 985 | - $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 986 | - $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 987 | - // ajouter les entrees objet_source et objet cible par convenance |
|
| 988 | - foreach ($liens as $l) { |
|
| 989 | - $l[$objet_source] = $l[$primary]; |
|
| 990 | - $l[$l['objet']] = $l['id_objet']; |
|
| 991 | - $trouve[] = $l; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - return $trouve; |
|
| 979 | + $trouve = []; |
|
| 980 | + foreach ($objets as $objet => $id_objets) { |
|
| 981 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 982 | + // gerer les roles s'il y en a dans $cond |
|
| 983 | + [$cond] = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 984 | + // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 985 | + $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 986 | + $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 987 | + // ajouter les entrees objet_source et objet cible par convenance |
|
| 988 | + foreach ($liens as $l) { |
|
| 989 | + $l[$objet_source] = $l[$primary]; |
|
| 990 | + $l[$l['objet']] = $l['id_objet']; |
|
| 991 | + $trouve[] = $l; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + return $trouve; |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | /** |
@@ -1003,26 +1003,26 @@ discard block |
||
| 1003 | 1003 | * @param array|int $ids |
| 1004 | 1004 | */ |
| 1005 | 1005 | function lien_propage_date_modif($objet, $ids) { |
| 1006 | - static $done = []; |
|
| 1007 | - $hash = md5($objet . serialize($ids)); |
|
| 1008 | - |
|
| 1009 | - // sql_updateq, peut être un rien lent. |
|
| 1010 | - // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 1011 | - if (isset($done[$hash])) { |
|
| 1012 | - return; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1016 | - |
|
| 1017 | - $table = table_objet_sql($objet); |
|
| 1018 | - if ( |
|
| 1019 | - $desc = $trouver_table($table) |
|
| 1020 | - and isset($desc['field']['date_modif']) |
|
| 1021 | - ) { |
|
| 1022 | - $primary = id_table_objet($objet); |
|
| 1023 | - $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 1024 | - sql_updateq($table, ['date_modif' => date('Y-m-d H:i:s')], $where); |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - $done[$hash] = true; |
|
| 1006 | + static $done = []; |
|
| 1007 | + $hash = md5($objet . serialize($ids)); |
|
| 1008 | + |
|
| 1009 | + // sql_updateq, peut être un rien lent. |
|
| 1010 | + // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 1011 | + if (isset($done[$hash])) { |
|
| 1012 | + return; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1016 | + |
|
| 1017 | + $table = table_objet_sql($objet); |
|
| 1018 | + if ( |
|
| 1019 | + $desc = $trouver_table($table) |
|
| 1020 | + and isset($desc['field']['date_modif']) |
|
| 1021 | + ) { |
|
| 1022 | + $primary = id_table_objet($objet); |
|
| 1023 | + $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 1024 | + sql_updateq($table, ['date_modif' => date('Y-m-d H:i:s')], $where); |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + $done[$hash] = true; |
|
| 1028 | 1028 | } |
@@ -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 | /** |
@@ -25,41 +25,41 @@ discard block |
||
| 25 | 25 | **/ |
| 26 | 26 | function action_instituer_langue_rubrique_dist() { |
| 27 | 27 | |
| 28 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | - $arg = $securiser_action(); |
|
| 30 | - $changer_lang = _request('changer_lang'); |
|
| 28 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | + $arg = $securiser_action(); |
|
| 30 | + $changer_lang = _request('changer_lang'); |
|
| 31 | 31 | |
| 32 | - [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 32 | + [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - $changer_lang |
|
| 36 | - and $id_rubrique > 0 |
|
| 37 | - and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | - and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | - ) { |
|
| 40 | - if ($changer_lang != 'herit') { |
|
| 41 | - sql_updateq( |
|
| 42 | - 'spip_rubriques', |
|
| 43 | - ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | - "id_rubrique=$id_rubrique" |
|
| 45 | - ); |
|
| 46 | - } else { |
|
| 47 | - if ($id_parent == 0) { |
|
| 48 | - $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | - } else { |
|
| 50 | - $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | - } |
|
| 52 | - sql_updateq( |
|
| 53 | - 'spip_rubriques', |
|
| 54 | - ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | - "id_rubrique=$id_rubrique" |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - include_spip('inc/rubriques'); |
|
| 59 | - calculer_langues_rubriques(); |
|
| 34 | + if ( |
|
| 35 | + $changer_lang |
|
| 36 | + and $id_rubrique > 0 |
|
| 37 | + and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | + and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | + ) { |
|
| 40 | + if ($changer_lang != 'herit') { |
|
| 41 | + sql_updateq( |
|
| 42 | + 'spip_rubriques', |
|
| 43 | + ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | + "id_rubrique=$id_rubrique" |
|
| 45 | + ); |
|
| 46 | + } else { |
|
| 47 | + if ($id_parent == 0) { |
|
| 48 | + $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | + } else { |
|
| 50 | + $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | + } |
|
| 52 | + sql_updateq( |
|
| 53 | + 'spip_rubriques', |
|
| 54 | + ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | + "id_rubrique=$id_rubrique" |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + include_spip('inc/rubriques'); |
|
| 59 | + calculer_langues_rubriques(); |
|
| 60 | 60 | |
| 61 | - // invalider les caches marques de cette rubrique |
|
| 62 | - include_spip('inc/invalideur'); |
|
| 63 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | - } |
|
| 61 | + // invalider les caches marques de cette rubrique |
|
| 62 | + include_spip('inc/invalideur'); |
|
| 63 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -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 | include_spip('inc/cookie'); |
@@ -34,73 +34,73 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | */ |
| 36 | 36 | function action_logout_dist() { |
| 37 | - $logout = _request('logout'); |
|
| 38 | - $url = securiser_redirect_action(_request('url')); |
|
| 39 | - // cas particulier, logout dans l'espace public |
|
| 40 | - if ($logout == 'public' and !$url) { |
|
| 41 | - $url = url_de_base(); |
|
| 42 | - } |
|
| 37 | + $logout = _request('logout'); |
|
| 38 | + $url = securiser_redirect_action(_request('url')); |
|
| 39 | + // cas particulier, logout dans l'espace public |
|
| 40 | + if ($logout == 'public' and !$url) { |
|
| 41 | + $url = url_de_base(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | - if ( |
|
| 46 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | - and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | - // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | - and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | - ) { |
|
| 51 | - // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | - if ( |
|
| 53 | - !$jeton = _request('jeton') |
|
| 54 | - or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | - ) { |
|
| 56 | - $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | - $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | - $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | - $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | - include_spip('inc/minipres'); |
|
| 61 | - include_spip('inc/filtres'); |
|
| 62 | - $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | - $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | - $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | - $res = minipres(_T('spip:icone_deconnecter'), $texte, '', true); |
|
| 66 | - echo $res; |
|
| 44 | + // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | + if ( |
|
| 46 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | + and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | + // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | + and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | + ) { |
|
| 51 | + // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | + if ( |
|
| 53 | + !$jeton = _request('jeton') |
|
| 54 | + or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | + ) { |
|
| 56 | + $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | + $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | + $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | + $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | + include_spip('inc/minipres'); |
|
| 61 | + include_spip('inc/filtres'); |
|
| 62 | + $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | + $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | + $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | + $res = minipres(_T('spip:icone_deconnecter'), $texte, '', true); |
|
| 66 | + echo $res; |
|
| 67 | 67 | |
| 68 | - return; |
|
| 69 | - } |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - include_spip('inc/auth'); |
|
| 72 | - auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | - // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | - if (isset($_COOKIE['spip_session'])) { |
|
| 75 | - $session = charger_fonction('session', 'inc'); |
|
| 76 | - $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | - 'expires' => time() - 3600 |
|
| 79 | - ]); |
|
| 80 | - } |
|
| 81 | - // si authentification http, et que la personne est loge, |
|
| 82 | - // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | - if ( |
|
| 84 | - isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | - and !$GLOBALS['ignore_auth_http'] |
|
| 86 | - and $GLOBALS['auth_can_disconnect'] |
|
| 87 | - ) { |
|
| 88 | - ask_php_auth( |
|
| 89 | - _T('login_deconnexion_ok'), |
|
| 90 | - _T('login_verifiez_navigateur'), |
|
| 91 | - _T('login_retour_public'), |
|
| 92 | - 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | - _T('login_test_navigateur'), |
|
| 94 | - true |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 71 | + include_spip('inc/auth'); |
|
| 72 | + auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | + // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | + if (isset($_COOKIE['spip_session'])) { |
|
| 75 | + $session = charger_fonction('session', 'inc'); |
|
| 76 | + $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | + 'expires' => time() - 3600 |
|
| 79 | + ]); |
|
| 80 | + } |
|
| 81 | + // si authentification http, et que la personne est loge, |
|
| 82 | + // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | + if ( |
|
| 84 | + isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | + and !$GLOBALS['ignore_auth_http'] |
|
| 86 | + and $GLOBALS['auth_can_disconnect'] |
|
| 87 | + ) { |
|
| 88 | + ask_php_auth( |
|
| 89 | + _T('login_deconnexion_ok'), |
|
| 90 | + _T('login_verifiez_navigateur'), |
|
| 91 | + _T('login_retour_public'), |
|
| 92 | + 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | + _T('login_test_navigateur'), |
|
| 94 | + true |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | - include_spip('inc/headers'); |
|
| 101 | - redirige_par_entete($url |
|
| 102 | - ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | - : generer_url_public('login')); |
|
| 99 | + // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | + include_spip('inc/headers'); |
|
| 101 | + redirige_par_entete($url |
|
| 102 | + ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | + : generer_url_public('login')); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | 113 | function generer_jeton_logout($session, $alea = null) { |
| 114 | - if (is_null($alea)) { |
|
| 115 | - include_spip('inc/acces'); |
|
| 116 | - $alea = charger_aleas(); |
|
| 117 | - } |
|
| 114 | + if (is_null($alea)) { |
|
| 115 | + include_spip('inc/acces'); |
|
| 116 | + $alea = charger_aleas(); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $jeton = md5($session['date_session'] |
|
| 120 | - . $session['id_auteur'] |
|
| 121 | - . $session['statut'] |
|
| 122 | - . $alea); |
|
| 119 | + $jeton = md5($session['date_session'] |
|
| 120 | + . $session['id_auteur'] |
|
| 121 | + . $session['statut'] |
|
| 122 | + . $alea); |
|
| 123 | 123 | |
| 124 | - return $jeton; |
|
| 124 | + return $jeton; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | * @return bool |
| 136 | 136 | */ |
| 137 | 137 | function verifier_jeton_logout($jeton, $session) { |
| 138 | - if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 138 | + if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 142 | + if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return false; |
|
| 146 | + return false; |
|
| 147 | 147 | } |
@@ -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 | - $white = 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 | - $white = array_diff($white, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $white = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // white list |
|
| 116 | - $white, |
|
| 117 | - // black 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 black liste, 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 | + $white = 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 | + $white = array_diff($white, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $white = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // white list |
|
| 116 | + $white, |
|
| 117 | + // black 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 black liste, 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,135 +168,135 @@ 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 | - } |
|
| 298 | - |
|
| 299 | - return $id; |
|
| 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 | + |
|
| 299 | + return $id; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -313,138 +313,138 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | - $objet = $t; |
|
| 319 | - } |
|
| 320 | - if ( |
|
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 323 | - ) { |
|
| 324 | - return $instituer($id, $c, $calcul_rub); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $table_sql = table_objet_sql($objet); |
|
| 328 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | - $desc = $trouver_table($table_sql); |
|
| 330 | - if (!$desc or !isset($desc['field'])) { |
|
| 331 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - include_spip('inc/autoriser'); |
|
| 335 | - include_spip('inc/rubriques'); |
|
| 336 | - include_spip('inc/modifier'); |
|
| 337 | - |
|
| 338 | - $sel = []; |
|
| 339 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | - |
|
| 341 | - $champ_date = ''; |
|
| 342 | - if (isset($desc['date']) and $desc['date']) { |
|
| 343 | - $champ_date = $desc['date']; |
|
| 344 | - } elseif (isset($desc['field']['date'])) { |
|
| 345 | - $champ_date = 'date'; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | - |
|
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | - |
|
| 353 | - $id_rubrique = $row['id_rubrique']; |
|
| 354 | - $statut_ancien = $statut = $row['statut']; |
|
| 355 | - $date_ancienne = $date = $row['date']; |
|
| 356 | - $champs = []; |
|
| 357 | - |
|
| 358 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | - |
|
| 361 | - // cf autorisations dans inc/instituer_objet |
|
| 362 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | - if ( |
|
| 364 | - $id_rubrique ? |
|
| 365 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | - : |
|
| 367 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | - ) { |
|
| 369 | - $statut = $champs['statut'] = $s; |
|
| 370 | - } else { |
|
| 371 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | - $statut = $champs['statut'] = $s; |
|
| 373 | - } else { |
|
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // En cas de publication, fixer la date a "maintenant" |
|
| 379 | - // sauf si $c commande autre chose |
|
| 380 | - // ou si l'objet est deja date dans le futur |
|
| 381 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | - if ($champ_date) { |
|
| 383 | - if ( |
|
| 384 | - $champs['statut'] == 'publie' |
|
| 385 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | - or $d |
|
| 387 | - ) { |
|
| 388 | - if ($d or strtotime($d = $date) > time()) { |
|
| 389 | - $champs[$champ_date] = $date = $d; |
|
| 390 | - } else { |
|
| 391 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Verifier que la rubrique demandee existe et est differente |
|
| 398 | - // de la rubrique actuelle |
|
| 399 | - if ( |
|
| 400 | - $id_rubrique |
|
| 401 | - and isset($c['id_parent']) |
|
| 402 | - and $id_parent = $c['id_parent'] |
|
| 403 | - and $id_parent != $id_rubrique |
|
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | - ) { |
|
| 406 | - $champs['id_rubrique'] = $id_parent; |
|
| 407 | - |
|
| 408 | - // si l'objet etait publie |
|
| 409 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | - // repasser l'objet en statut 'propose'. |
|
| 411 | - if ( |
|
| 412 | - $statut == 'publie' |
|
| 413 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | - ) { |
|
| 415 | - $champs['statut'] = 'prop'; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - // Envoyer aux plugins |
|
| 421 | - $champs = pipeline( |
|
| 422 | - 'pre_edition', |
|
| 423 | - [ |
|
| 424 | - 'args' => [ |
|
| 425 | - 'table' => $table_sql, |
|
| 426 | - 'id_objet' => $id, |
|
| 427 | - 'action' => 'instituer', |
|
| 428 | - 'statut_ancien' => $statut_ancien, |
|
| 429 | - 'date_ancienne' => $date_ancienne, |
|
| 430 | - 'id_parent_ancien' => $id_rubrique, |
|
| 431 | - ], |
|
| 432 | - 'data' => $champs |
|
| 433 | - ] |
|
| 434 | - ); |
|
| 435 | - |
|
| 436 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | - return ''; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // Envoyer les modifs. |
|
| 441 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | - |
|
| 443 | - // Invalider les caches |
|
| 444 | - include_spip('inc/invalideur'); |
|
| 445 | - suivre_invalideur("id='$objet/$id'"); |
|
| 446 | - |
|
| 447 | - /* |
|
| 316 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | + $objet = $t; |
|
| 319 | + } |
|
| 320 | + if ( |
|
| 321 | + include_spip('action/editer_' . $objet) |
|
| 322 | + and function_exists($instituer = $objet . '_instituer') |
|
| 323 | + ) { |
|
| 324 | + return $instituer($id, $c, $calcul_rub); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $table_sql = table_objet_sql($objet); |
|
| 328 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | + $desc = $trouver_table($table_sql); |
|
| 330 | + if (!$desc or !isset($desc['field'])) { |
|
| 331 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + include_spip('inc/autoriser'); |
|
| 335 | + include_spip('inc/rubriques'); |
|
| 336 | + include_spip('inc/modifier'); |
|
| 337 | + |
|
| 338 | + $sel = []; |
|
| 339 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | + |
|
| 341 | + $champ_date = ''; |
|
| 342 | + if (isset($desc['date']) and $desc['date']) { |
|
| 343 | + $champ_date = $desc['date']; |
|
| 344 | + } elseif (isset($desc['field']['date'])) { |
|
| 345 | + $champ_date = 'date'; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | + |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | + |
|
| 353 | + $id_rubrique = $row['id_rubrique']; |
|
| 354 | + $statut_ancien = $statut = $row['statut']; |
|
| 355 | + $date_ancienne = $date = $row['date']; |
|
| 356 | + $champs = []; |
|
| 357 | + |
|
| 358 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | + |
|
| 361 | + // cf autorisations dans inc/instituer_objet |
|
| 362 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | + if ( |
|
| 364 | + $id_rubrique ? |
|
| 365 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | + : |
|
| 367 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | + ) { |
|
| 369 | + $statut = $champs['statut'] = $s; |
|
| 370 | + } else { |
|
| 371 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | + $statut = $champs['statut'] = $s; |
|
| 373 | + } else { |
|
| 374 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // En cas de publication, fixer la date a "maintenant" |
|
| 379 | + // sauf si $c commande autre chose |
|
| 380 | + // ou si l'objet est deja date dans le futur |
|
| 381 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | + if ($champ_date) { |
|
| 383 | + if ( |
|
| 384 | + $champs['statut'] == 'publie' |
|
| 385 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | + or $d |
|
| 387 | + ) { |
|
| 388 | + if ($d or strtotime($d = $date) > time()) { |
|
| 389 | + $champs[$champ_date] = $date = $d; |
|
| 390 | + } else { |
|
| 391 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Verifier que la rubrique demandee existe et est differente |
|
| 398 | + // de la rubrique actuelle |
|
| 399 | + if ( |
|
| 400 | + $id_rubrique |
|
| 401 | + and isset($c['id_parent']) |
|
| 402 | + and $id_parent = $c['id_parent'] |
|
| 403 | + and $id_parent != $id_rubrique |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | + ) { |
|
| 406 | + $champs['id_rubrique'] = $id_parent; |
|
| 407 | + |
|
| 408 | + // si l'objet etait publie |
|
| 409 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | + // repasser l'objet en statut 'propose'. |
|
| 411 | + if ( |
|
| 412 | + $statut == 'publie' |
|
| 413 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | + ) { |
|
| 415 | + $champs['statut'] = 'prop'; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + // Envoyer aux plugins |
|
| 421 | + $champs = pipeline( |
|
| 422 | + 'pre_edition', |
|
| 423 | + [ |
|
| 424 | + 'args' => [ |
|
| 425 | + 'table' => $table_sql, |
|
| 426 | + 'id_objet' => $id, |
|
| 427 | + 'action' => 'instituer', |
|
| 428 | + 'statut_ancien' => $statut_ancien, |
|
| 429 | + 'date_ancienne' => $date_ancienne, |
|
| 430 | + 'id_parent_ancien' => $id_rubrique, |
|
| 431 | + ], |
|
| 432 | + 'data' => $champs |
|
| 433 | + ] |
|
| 434 | + ); |
|
| 435 | + |
|
| 436 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | + return ''; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // Envoyer les modifs. |
|
| 441 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | + |
|
| 443 | + // Invalider les caches |
|
| 444 | + include_spip('inc/invalideur'); |
|
| 445 | + suivre_invalideur("id='$objet/$id'"); |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | if ($date) { |
| 449 | 449 | $t = strtotime($date); |
| 450 | 450 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -453,32 +453,32 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | }*/ |
| 455 | 455 | |
| 456 | - // Pipeline |
|
| 457 | - pipeline( |
|
| 458 | - 'post_edition', |
|
| 459 | - [ |
|
| 460 | - 'args' => [ |
|
| 461 | - 'table' => $table_sql, |
|
| 462 | - 'id_objet' => $id, |
|
| 463 | - 'action' => 'instituer', |
|
| 464 | - 'statut_ancien' => $statut_ancien, |
|
| 465 | - 'date_ancienne' => $date_ancienne, |
|
| 466 | - 'id_parent_ancien' => $id_rubrique, |
|
| 467 | - ], |
|
| 468 | - 'data' => $champs |
|
| 469 | - ] |
|
| 470 | - ); |
|
| 471 | - |
|
| 472 | - // Notifications |
|
| 473 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | - $notifications( |
|
| 475 | - "instituer$objet", |
|
| 476 | - $id, |
|
| 477 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return ''; // pas d'erreur |
|
| 456 | + // Pipeline |
|
| 457 | + pipeline( |
|
| 458 | + 'post_edition', |
|
| 459 | + [ |
|
| 460 | + 'args' => [ |
|
| 461 | + 'table' => $table_sql, |
|
| 462 | + 'id_objet' => $id, |
|
| 463 | + 'action' => 'instituer', |
|
| 464 | + 'statut_ancien' => $statut_ancien, |
|
| 465 | + 'date_ancienne' => $date_ancienne, |
|
| 466 | + 'id_parent_ancien' => $id_rubrique, |
|
| 467 | + ], |
|
| 468 | + 'data' => $champs |
|
| 469 | + ] |
|
| 470 | + ); |
|
| 471 | + |
|
| 472 | + // Notifications |
|
| 473 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | + $notifications( |
|
| 475 | + "instituer$objet", |
|
| 476 | + $id, |
|
| 477 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return ''; // pas d'erreur |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -493,51 +493,51 @@ discard block |
||
| 493 | 493 | * @return void |
| 494 | 494 | */ |
| 495 | 495 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 496 | - $table_sql = table_objet_sql($objet); |
|
| 497 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | - $desc = $trouver_table($table_sql); |
|
| 499 | - |
|
| 500 | - // Si on deplace l'objet |
|
| 501 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | - if (isset($champs['id_rubrique'])) { |
|
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | - $langue = $row_rub['lang']; |
|
| 505 | - |
|
| 506 | - if (isset($desc['field']['id_secteur'])) { |
|
| 507 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | - if ( |
|
| 512 | - sql_fetsel( |
|
| 513 | - '1', |
|
| 514 | - $table_sql, |
|
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | - ) |
|
| 517 | - ) { |
|
| 518 | - $champs['lang'] = $langue; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if (!$champs) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | - |
|
| 528 | - // Changer le statut des rubriques concernees |
|
| 529 | - if ($cond) { |
|
| 530 | - include_spip('inc/rubriques'); |
|
| 531 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | - $postdate = false; |
|
| 533 | - // On rajoute les infos de l'objet |
|
| 534 | - $infos = [ |
|
| 535 | - 'objet' => $objet, |
|
| 536 | - 'id_objet' => $id, |
|
| 537 | - 'statut_ancien' => $statut, |
|
| 538 | - ]; |
|
| 539 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | - } |
|
| 496 | + $table_sql = table_objet_sql($objet); |
|
| 497 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | + $desc = $trouver_table($table_sql); |
|
| 499 | + |
|
| 500 | + // Si on deplace l'objet |
|
| 501 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | + if (isset($champs['id_rubrique'])) { |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | + $langue = $row_rub['lang']; |
|
| 505 | + |
|
| 506 | + if (isset($desc['field']['id_secteur'])) { |
|
| 507 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | + if ( |
|
| 512 | + sql_fetsel( |
|
| 513 | + '1', |
|
| 514 | + $table_sql, |
|
| 515 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | + ) |
|
| 517 | + ) { |
|
| 518 | + $champs['lang'] = $langue; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if (!$champs) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | + |
|
| 528 | + // Changer le statut des rubriques concernees |
|
| 529 | + if ($cond) { |
|
| 530 | + include_spip('inc/rubriques'); |
|
| 531 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | + $postdate = false; |
|
| 533 | + // On rajoute les infos de l'objet |
|
| 534 | + $infos = [ |
|
| 535 | + 'objet' => $objet, |
|
| 536 | + 'id_objet' => $id, |
|
| 537 | + 'statut_ancien' => $statut, |
|
| 538 | + ]; |
|
| 539 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | + } |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | |
@@ -566,75 +566,75 @@ discard block |
||
| 566 | 566 | * string|int : valeur du champ demande pour l'objet demande |
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | - $objet = $t; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | - static $descriptions = []; |
|
| 577 | - |
|
| 578 | - // On détermine le nom du champ id de la table. |
|
| 579 | - include_spip('base/objets'); |
|
| 580 | - $primary = id_table_objet($objet); |
|
| 581 | - |
|
| 582 | - // On détermine l'id à utiliser. |
|
| 583 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | - |
|
| 585 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | - if ( |
|
| 587 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | - or (isset($options['force']) and $options['force']) |
|
| 589 | - ) { |
|
| 590 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | - if ( |
|
| 592 | - include_spip('action/editer_' . $objet) |
|
| 593 | - and function_exists($lire = "${objet}_lire_champs") |
|
| 594 | - ) { |
|
| 595 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | - } else { |
|
| 597 | - // On récupère la table SQL à partir du type d'objet. |
|
| 598 | - $table = table_objet_sql($objet); |
|
| 599 | - |
|
| 600 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | - $where = [ |
|
| 602 | - "${champ_id}=" . sql_quote($valeur_id) |
|
| 603 | - ]; |
|
| 604 | - |
|
| 605 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!$valeurs) { |
|
| 610 | - $valeurs = false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | - |
|
| 615 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | - |
|
| 623 | - // On ne retourne maintenant que les champs demandés. |
|
| 624 | - // - on détermine les informations à renvoyer. |
|
| 625 | - if ($retour and !empty($options['champs'])) { |
|
| 626 | - $champs = $options['champs']; |
|
| 627 | - // Extraction des seules informations demandées. |
|
| 628 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | - if (is_array($champs)) { |
|
| 631 | - // Tableau des informations valides |
|
| 632 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | - } else { |
|
| 634 | - // Valeur unique demandée. |
|
| 635 | - $retour = ($retour[$champs] ?? false); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - return $retour; |
|
| 569 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | + $objet = $t; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | + static $descriptions = []; |
|
| 577 | + |
|
| 578 | + // On détermine le nom du champ id de la table. |
|
| 579 | + include_spip('base/objets'); |
|
| 580 | + $primary = id_table_objet($objet); |
|
| 581 | + |
|
| 582 | + // On détermine l'id à utiliser. |
|
| 583 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | + |
|
| 585 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | + if ( |
|
| 587 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | + or (isset($options['force']) and $options['force']) |
|
| 589 | + ) { |
|
| 590 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | + if ( |
|
| 592 | + include_spip('action/editer_' . $objet) |
|
| 593 | + and function_exists($lire = "${objet}_lire_champs") |
|
| 594 | + ) { |
|
| 595 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | + } else { |
|
| 597 | + // On récupère la table SQL à partir du type d'objet. |
|
| 598 | + $table = table_objet_sql($objet); |
|
| 599 | + |
|
| 600 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | + $where = [ |
|
| 602 | + "${champ_id}=" . sql_quote($valeur_id) |
|
| 603 | + ]; |
|
| 604 | + |
|
| 605 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!$valeurs) { |
|
| 610 | + $valeurs = false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | + |
|
| 615 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | + |
|
| 623 | + // On ne retourne maintenant que les champs demandés. |
|
| 624 | + // - on détermine les informations à renvoyer. |
|
| 625 | + if ($retour and !empty($options['champs'])) { |
|
| 626 | + $champs = $options['champs']; |
|
| 627 | + // Extraction des seules informations demandées. |
|
| 628 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | + if (is_array($champs)) { |
|
| 631 | + // Tableau des informations valides |
|
| 632 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | + } else { |
|
| 634 | + // Valeur unique demandée. |
|
| 635 | + $retour = ($retour[$champs] ?? false); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + return $retour; |
|
| 640 | 640 | } |
@@ -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,42 +80,42 @@ 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 | - return $id_rubrique; |
|
| 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 | + return $id_rubrique; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,46 +131,46 @@ discard block |
||
| 131 | 131 | * - chaîne : Texte d'un message d'erreur |
| 132 | 132 | */ |
| 133 | 133 | function rubrique_modifier($id_rubrique, $set = null) { |
| 134 | - include_spip('inc/autoriser'); |
|
| 135 | - include_spip('inc/filtres'); |
|
| 136 | - |
|
| 137 | - include_spip('inc/modifier'); |
|
| 138 | - $c = collecter_requests( |
|
| 139 | - // white list |
|
| 140 | - objet_info('rubrique', 'champs_editables'), |
|
| 141 | - // black list |
|
| 142 | - ['id_parent', 'confirme_deplace'], |
|
| 143 | - // donnees eventuellement fournies |
|
| 144 | - $set |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - if ( |
|
| 148 | - $err = objet_modifier_champs( |
|
| 149 | - 'rubrique', |
|
| 150 | - $id_rubrique, |
|
| 151 | - [ |
|
| 152 | - 'data' => $set, |
|
| 153 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | - ], |
|
| 155 | - $c |
|
| 156 | - ) |
|
| 157 | - ) { |
|
| 158 | - return $err; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | - // Deplacer la rubrique |
|
| 163 | - if (isset($c['id_parent'])) { |
|
| 164 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // invalider les caches marques de cette rubrique |
|
| 168 | - include_spip('inc/invalideur'); |
|
| 169 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | - // et celui de menu_rubriques |
|
| 171 | - effacer_meta('date_calcul_rubriques'); |
|
| 172 | - |
|
| 173 | - return $err; |
|
| 134 | + include_spip('inc/autoriser'); |
|
| 135 | + include_spip('inc/filtres'); |
|
| 136 | + |
|
| 137 | + include_spip('inc/modifier'); |
|
| 138 | + $c = collecter_requests( |
|
| 139 | + // white list |
|
| 140 | + objet_info('rubrique', 'champs_editables'), |
|
| 141 | + // black list |
|
| 142 | + ['id_parent', 'confirme_deplace'], |
|
| 143 | + // donnees eventuellement fournies |
|
| 144 | + $set |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + if ( |
|
| 148 | + $err = objet_modifier_champs( |
|
| 149 | + 'rubrique', |
|
| 150 | + $id_rubrique, |
|
| 151 | + [ |
|
| 152 | + 'data' => $set, |
|
| 153 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | + ], |
|
| 155 | + $c |
|
| 156 | + ) |
|
| 157 | + ) { |
|
| 158 | + return $err; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | + // Deplacer la rubrique |
|
| 163 | + if (isset($c['id_parent'])) { |
|
| 164 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // invalider les caches marques de cette rubrique |
|
| 168 | + include_spip('inc/invalideur'); |
|
| 169 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | + // et celui de menu_rubriques |
|
| 171 | + effacer_meta('date_calcul_rubriques'); |
|
| 172 | + |
|
| 173 | + return $err; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -193,25 +193,25 @@ discard block |
||
| 193 | 193 | * false si la confirmation du déplacement n'est pas présente |
| 194 | 194 | */ |
| 195 | 195 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 196 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ( |
|
| 205 | - $id_secteur = sql_getfetsel( |
|
| 206 | - 'id_secteur', |
|
| 207 | - 'spip_rubriques', |
|
| 208 | - "id_rubrique=$id_parent" |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return true; |
|
| 196 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ( |
|
| 205 | + $id_secteur = sql_getfetsel( |
|
| 206 | + 'id_secteur', |
|
| 207 | + 'spip_rubriques', |
|
| 208 | + "id_rubrique=$id_parent" |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return true; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -233,50 +233,50 @@ discard block |
||
| 233 | 233 | * Chaîne : Texte du message d'erreur |
| 234 | 234 | */ |
| 235 | 235 | function rubrique_instituer($id_rubrique, $c) { |
| 236 | - // traitement de la rubrique parente |
|
| 237 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | - // qu'on n'administre pas. |
|
| 239 | - |
|
| 240 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | - $id_parent = intval($id_parent); |
|
| 242 | - $filles = calcul_branche_in($id_rubrique); |
|
| 243 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | - } else { |
|
| 246 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | - $old_parent = $s['id_parent']; |
|
| 248 | - |
|
| 249 | - if ( |
|
| 250 | - !($id_parent != $old_parent |
|
| 251 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | - ) |
|
| 255 | - ) { |
|
| 256 | - if ($s['statut'] != 'new') { |
|
| 257 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | - } |
|
| 259 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | - $statut_ancien = $s['statut']; |
|
| 261 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - propager_les_secteurs(); |
|
| 265 | - |
|
| 266 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | - if ($statut_ancien == 'publie') { |
|
| 268 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], $statut_ancien); |
|
| 269 | - } |
|
| 270 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | - // invalider le cache de leur menu |
|
| 272 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | - effacer_meta('date_calcul_rubriques'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - calculer_langues_rubriques(); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return ''; // pas d'erreur |
|
| 236 | + // traitement de la rubrique parente |
|
| 237 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | + // qu'on n'administre pas. |
|
| 239 | + |
|
| 240 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | + $id_parent = intval($id_parent); |
|
| 242 | + $filles = calcul_branche_in($id_rubrique); |
|
| 243 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | + } else { |
|
| 246 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | + $old_parent = $s['id_parent']; |
|
| 248 | + |
|
| 249 | + if ( |
|
| 250 | + !($id_parent != $old_parent |
|
| 251 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | + ) |
|
| 255 | + ) { |
|
| 256 | + if ($s['statut'] != 'new') { |
|
| 257 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | + } |
|
| 259 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | + $statut_ancien = $s['statut']; |
|
| 261 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + propager_les_secteurs(); |
|
| 265 | + |
|
| 266 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | + if ($statut_ancien == 'publie') { |
|
| 268 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], $statut_ancien); |
|
| 269 | + } |
|
| 270 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | + // invalider le cache de leur menu |
|
| 272 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | + effacer_meta('date_calcul_rubriques'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + calculer_langues_rubriques(); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return ''; // pas d'erreur |
|
| 282 | 282 | } |
@@ -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 | |
@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | * `on` ou `off` |
| 31 | 31 | */ |
| 32 | 32 | function logo_supprimer($objet, $id_objet, $etat) { |
| 33 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | - $objet = objet_type($objet); |
|
| 35 | - $primary = id_table_objet($objet); |
|
| 36 | - include_spip('inc/chercher_logo'); |
|
| 37 | - |
|
| 38 | - // existe-t-il deja un logo ? |
|
| 39 | - $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | - if ($logo) { |
|
| 41 | - # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | - if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | - spip_log("Supprimer ancien logo $logo", 'logo'); |
|
| 44 | - spip_unlink($logo[0]); |
|
| 45 | - } |
|
| 46 | - elseif ( |
|
| 47 | - $doc = $logo[5] |
|
| 48 | - and isset($doc['id_document']) |
|
| 49 | - and $id_document = $doc['id_document'] |
|
| 50 | - ) { |
|
| 51 | - include_spip('action/editer_liens'); |
|
| 52 | - // supprimer le lien dans la base |
|
| 53 | - objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | - |
|
| 55 | - // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | - $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | - if (!count($liens)) { |
|
| 58 | - $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | - $supprimer_document($doc['id_document']); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 33 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | + $objet = objet_type($objet); |
|
| 35 | + $primary = id_table_objet($objet); |
|
| 36 | + include_spip('inc/chercher_logo'); |
|
| 37 | + |
|
| 38 | + // existe-t-il deja un logo ? |
|
| 39 | + $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | + if ($logo) { |
|
| 41 | + # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | + if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | + spip_log("Supprimer ancien logo $logo", 'logo'); |
|
| 44 | + spip_unlink($logo[0]); |
|
| 45 | + } |
|
| 46 | + elseif ( |
|
| 47 | + $doc = $logo[5] |
|
| 48 | + and isset($doc['id_document']) |
|
| 49 | + and $id_document = $doc['id_document'] |
|
| 50 | + ) { |
|
| 51 | + include_spip('action/editer_liens'); |
|
| 52 | + // supprimer le lien dans la base |
|
| 53 | + objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | + |
|
| 55 | + // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | + $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | + if (!count($liens)) { |
|
| 58 | + $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | + $supprimer_document($doc['id_document']); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -76,177 +76,177 @@ discard block |
||
| 76 | 76 | * Erreur, sinon '' |
| 77 | 77 | */ |
| 78 | 78 | function logo_modifier($objet, $id_objet, $etat, $source) { |
| 79 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | - $objet = objet_type($objet); |
|
| 81 | - $primary = id_table_objet($objet); |
|
| 82 | - include_spip('inc/chercher_logo'); |
|
| 83 | - |
|
| 84 | - $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | - if (!$mode) { |
|
| 86 | - spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | - $erreur = 'etat invalide'; |
|
| 88 | - |
|
| 89 | - return $erreur; |
|
| 90 | - } |
|
| 91 | - // chercher dans la base |
|
| 92 | - $mode_document = 'logo' . $mode; |
|
| 93 | - |
|
| 94 | - include_spip('inc/documents'); |
|
| 95 | - $erreur = ''; |
|
| 96 | - |
|
| 97 | - if (!$source) { |
|
| 98 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | - $erreur = 'source inconnue'; |
|
| 100 | - |
|
| 101 | - return $erreur; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // fichier dans upload/ |
|
| 105 | - if (is_string($source)) { |
|
| 106 | - $tmp_name = false; |
|
| 107 | - if (file_exists($source)) { |
|
| 108 | - $tmp_name = $source; |
|
| 109 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | - $tmp_name = $f; |
|
| 111 | - } |
|
| 112 | - if (!$tmp_name) { |
|
| 113 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | - $erreur = 'source inconnue'; |
|
| 115 | - |
|
| 116 | - return $erreur; |
|
| 117 | - } |
|
| 118 | - $source = [ |
|
| 119 | - 'tmp_name' => $tmp_name, |
|
| 120 | - 'name' => basename($tmp_name), |
|
| 121 | - ]; |
|
| 122 | - } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | - return $erreur; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // supprimer le logo eventueel existant |
|
| 127 | - // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | - // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | - logo_supprimer($objet, $id_objet, $etat); |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - include_spip('inc/autoriser'); |
|
| 133 | - $source['mode'] = $mode_document; |
|
| 134 | - $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 135 | - autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 136 | - $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 137 | - autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 138 | - |
|
| 139 | - $id_document = reset($ajoutes); |
|
| 140 | - |
|
| 141 | - if (!is_numeric($id_document)) { |
|
| 142 | - $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 143 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 144 | - return $erreur; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ''; // tout est bon, pas d'erreur |
|
| 79 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | + $objet = objet_type($objet); |
|
| 81 | + $primary = id_table_objet($objet); |
|
| 82 | + include_spip('inc/chercher_logo'); |
|
| 83 | + |
|
| 84 | + $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | + if (!$mode) { |
|
| 86 | + spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | + $erreur = 'etat invalide'; |
|
| 88 | + |
|
| 89 | + return $erreur; |
|
| 90 | + } |
|
| 91 | + // chercher dans la base |
|
| 92 | + $mode_document = 'logo' . $mode; |
|
| 93 | + |
|
| 94 | + include_spip('inc/documents'); |
|
| 95 | + $erreur = ''; |
|
| 96 | + |
|
| 97 | + if (!$source) { |
|
| 98 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | + $erreur = 'source inconnue'; |
|
| 100 | + |
|
| 101 | + return $erreur; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // fichier dans upload/ |
|
| 105 | + if (is_string($source)) { |
|
| 106 | + $tmp_name = false; |
|
| 107 | + if (file_exists($source)) { |
|
| 108 | + $tmp_name = $source; |
|
| 109 | + } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | + $tmp_name = $f; |
|
| 111 | + } |
|
| 112 | + if (!$tmp_name) { |
|
| 113 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | + $erreur = 'source inconnue'; |
|
| 115 | + |
|
| 116 | + return $erreur; |
|
| 117 | + } |
|
| 118 | + $source = [ |
|
| 119 | + 'tmp_name' => $tmp_name, |
|
| 120 | + 'name' => basename($tmp_name), |
|
| 121 | + ]; |
|
| 122 | + } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | + return $erreur; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // supprimer le logo eventueel existant |
|
| 127 | + // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | + // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | + logo_supprimer($objet, $id_objet, $etat); |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + include_spip('inc/autoriser'); |
|
| 133 | + $source['mode'] = $mode_document; |
|
| 134 | + $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 135 | + autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 136 | + $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 137 | + autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 138 | + |
|
| 139 | + $id_document = reset($ajoutes); |
|
| 140 | + |
|
| 141 | + if (!is_numeric($id_document)) { |
|
| 142 | + $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 143 | + spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 144 | + return $erreur; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ''; // tout est bon, pas d'erreur |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | function logo_migrer_en_base($objet, $time_limit) { |
| 151 | 151 | |
| 152 | - $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 153 | - $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 154 | - $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 155 | - if (isset($GLOBALS['formats_logos'])) { |
|
| 156 | - $formats_logos = $GLOBALS['formats_logos']; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 161 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 162 | - include_spip('inc/chercher_logo'); |
|
| 163 | - $_id_objet = id_table_objet($objet); |
|
| 164 | - $table = table_objet_sql($objet); |
|
| 165 | - $type = type_du_logo($_id_objet); |
|
| 166 | - $desc = $trouver_table($table); |
|
| 167 | - |
|
| 168 | - foreach (['on', 'off'] as $mode) { |
|
| 169 | - $nom_base = $type . $mode; |
|
| 170 | - $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 171 | - |
|
| 172 | - $files = glob($dir . $nom_base . '*'); |
|
| 173 | - // est-ce que c'est une nouvelle tentative de migration ? |
|
| 174 | - // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 175 | - if (!(is_countable($files) ? count($files) : 0)) { |
|
| 176 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 177 | - if (is_countable($files) ? count($files) : 0) { |
|
| 178 | - // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 179 | - $filescheck = []; |
|
| 180 | - foreach ($files as $file) { |
|
| 181 | - $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 182 | - $filescheck[$short] = $file; |
|
| 183 | - } |
|
| 184 | - // trouver ceux deja migres |
|
| 185 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 186 | - if (is_countable($deja) ? count($deja) : 0) { |
|
| 187 | - $deja = array_column($deja, 'fichier'); |
|
| 188 | - $restant = array_diff(array_keys($filescheck), $deja); |
|
| 189 | - $files = []; |
|
| 190 | - if (count($restant)) { |
|
| 191 | - foreach ($restant as $r) { |
|
| 192 | - $files[] = $filescheck[$r]; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - // et si il en reste on peut y aller... |
|
| 197 | - // mais il faut modifier $dir qui sert de base dans la suite |
|
| 198 | - if (is_countable($files) ? count($files) : 0) { |
|
| 199 | - $dir = $dir_logos; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - spip_log("logo_migrer_en_base $objet $mode : " . (is_countable($files) ? count($files) : 0) . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 205 | - |
|
| 206 | - $deja = []; |
|
| 207 | - foreach ($files as $file) { |
|
| 208 | - $logo = substr($file, strlen($dir . $nom_base)); |
|
| 209 | - $logo = explode('.', $logo); |
|
| 210 | - if ( |
|
| 211 | - is_numeric($logo[0]) |
|
| 212 | - and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 213 | - ) { |
|
| 214 | - if (!isset($deja[$id_objet])) { |
|
| 215 | - $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 216 | - // if no logo in base |
|
| 217 | - if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 218 | - foreach ($formats_logos as $format) { |
|
| 219 | - if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 220 | - if (isset($desc['field']['date_modif'])) { |
|
| 221 | - $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 222 | - } else { |
|
| 223 | - $date_modif = null; |
|
| 224 | - } |
|
| 225 | - // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 226 | - @rename($d, $dir_logos . $nom); |
|
| 227 | - // et on le declare comme nouveau logo |
|
| 228 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 229 | - if ($date_modif) { |
|
| 230 | - sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 231 | - } |
|
| 232 | - break; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - $deja[$id_objet] = true; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - // si le fichier est encore la on le move : rien a faire ici |
|
| 240 | - // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 241 | - if ($dir !== $dir_logos and file_exists($file)) { |
|
| 242 | - @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if ($time_limit and time() > $time_limit) { |
|
| 246 | - effacer_meta('drapeau_edition'); |
|
| 247 | - return; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - effacer_meta('drapeau_edition'); |
|
| 152 | + $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 153 | + $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 154 | + $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 155 | + if (isset($GLOBALS['formats_logos'])) { |
|
| 156 | + $formats_logos = $GLOBALS['formats_logos']; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 161 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 162 | + include_spip('inc/chercher_logo'); |
|
| 163 | + $_id_objet = id_table_objet($objet); |
|
| 164 | + $table = table_objet_sql($objet); |
|
| 165 | + $type = type_du_logo($_id_objet); |
|
| 166 | + $desc = $trouver_table($table); |
|
| 167 | + |
|
| 168 | + foreach (['on', 'off'] as $mode) { |
|
| 169 | + $nom_base = $type . $mode; |
|
| 170 | + $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 171 | + |
|
| 172 | + $files = glob($dir . $nom_base . '*'); |
|
| 173 | + // est-ce que c'est une nouvelle tentative de migration ? |
|
| 174 | + // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 175 | + if (!(is_countable($files) ? count($files) : 0)) { |
|
| 176 | + $files = glob($dir_logos . $nom_base . '*'); |
|
| 177 | + if (is_countable($files) ? count($files) : 0) { |
|
| 178 | + // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 179 | + $filescheck = []; |
|
| 180 | + foreach ($files as $file) { |
|
| 181 | + $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 182 | + $filescheck[$short] = $file; |
|
| 183 | + } |
|
| 184 | + // trouver ceux deja migres |
|
| 185 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 186 | + if (is_countable($deja) ? count($deja) : 0) { |
|
| 187 | + $deja = array_column($deja, 'fichier'); |
|
| 188 | + $restant = array_diff(array_keys($filescheck), $deja); |
|
| 189 | + $files = []; |
|
| 190 | + if (count($restant)) { |
|
| 191 | + foreach ($restant as $r) { |
|
| 192 | + $files[] = $filescheck[$r]; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + // et si il en reste on peut y aller... |
|
| 197 | + // mais il faut modifier $dir qui sert de base dans la suite |
|
| 198 | + if (is_countable($files) ? count($files) : 0) { |
|
| 199 | + $dir = $dir_logos; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + spip_log("logo_migrer_en_base $objet $mode : " . (is_countable($files) ? count($files) : 0) . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 205 | + |
|
| 206 | + $deja = []; |
|
| 207 | + foreach ($files as $file) { |
|
| 208 | + $logo = substr($file, strlen($dir . $nom_base)); |
|
| 209 | + $logo = explode('.', $logo); |
|
| 210 | + if ( |
|
| 211 | + is_numeric($logo[0]) |
|
| 212 | + and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 213 | + ) { |
|
| 214 | + if (!isset($deja[$id_objet])) { |
|
| 215 | + $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 216 | + // if no logo in base |
|
| 217 | + if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 218 | + foreach ($formats_logos as $format) { |
|
| 219 | + if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 220 | + if (isset($desc['field']['date_modif'])) { |
|
| 221 | + $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 222 | + } else { |
|
| 223 | + $date_modif = null; |
|
| 224 | + } |
|
| 225 | + // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 226 | + @rename($d, $dir_logos . $nom); |
|
| 227 | + // et on le declare comme nouveau logo |
|
| 228 | + logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 229 | + if ($date_modif) { |
|
| 230 | + sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 231 | + } |
|
| 232 | + break; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + $deja[$id_objet] = true; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + // si le fichier est encore la on le move : rien a faire ici |
|
| 240 | + // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 241 | + if ($dir !== $dir_logos and file_exists($file)) { |
|
| 242 | + @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if ($time_limit and time() > $time_limit) { |
|
| 246 | + effacer_meta('drapeau_edition'); |
|
| 247 | + return; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + effacer_meta('drapeau_edition'); |
|
| 252 | 252 | } |
@@ -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 | |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | 37 | function action_supprimer_lien_dist($arg = null) { |
| 38 | - if (is_null($arg)) { |
|
| 39 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | - $arg = $securiser_action(); |
|
| 41 | - } |
|
| 38 | + if (is_null($arg)) { |
|
| 39 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | + $arg = $securiser_action(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $arg = explode('-', $arg); |
|
| 44 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 43 | + $arg = explode('-', $arg); |
|
| 44 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 45 | 45 | |
| 46 | - include_spip('action/editer_liens'); |
|
| 47 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 46 | + include_spip('action/editer_liens'); |
|
| 47 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 48 | 48 | } |