@@ -16,92 +16,92 @@ |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | function action_api_transmettre_dist($arg = null) { |
| 24 | 24 | |
| 25 | - // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 26 | - if (is_null($arg)) { |
|
| 27 | - $arg = _request('arg'); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - $args = explode('/', (string) $arg); |
|
| 31 | - |
|
| 32 | - if (count($args) !== 4) { |
|
| 33 | - action_api_transmettre_fail($arg); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - [$id_auteur, $cle, $format, $fond] = $args; |
|
| 37 | - $id_auteur = (int) $id_auteur; |
|
| 38 | - |
|
| 39 | - if (preg_match(',[^\w\\.-],', $format)) { |
|
| 40 | - action_api_transmettre_fail("format $format ??"); |
|
| 41 | - } |
|
| 42 | - if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 43 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - // verifier la cle |
|
| 47 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 48 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | - |
|
| 50 | - $qs = $_SERVER['QUERY_STRING']; |
|
| 51 | - // retirer action et arg de la qs |
|
| 52 | - $contexte = []; |
|
| 53 | - parse_str((string) $qs, $contexte); |
|
| 54 | - foreach (array_keys($contexte) as $k) { |
|
| 55 | - if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 56 | - unset($contexte[$k]); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $qs = http_build_query($contexte); |
|
| 60 | - include_spip('inc/acces'); |
|
| 61 | - if (!securiser_acces_low_sec((int) $id_auteur, $cle, "transmettre/$format", $fond, $qs)) { |
|
| 62 | - // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 63 | - include_spip('inc/autoriser'); |
|
| 64 | - $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 65 | - if ( |
|
| 66 | - !$id_auteur |
|
| 67 | - || empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 68 | - || $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 69 | - || !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 70 | - ) { |
|
| 71 | - action_api_transmettre_fail("auth QS $qs ??"); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $contexte['id_auteur'] = $id_auteur; |
|
| 76 | - |
|
| 77 | - $fond = "transmettre/$format/$fond"; |
|
| 78 | - |
|
| 79 | - if (!trouver_fond($fond)) { |
|
| 80 | - $fond = "prive/$fond"; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if (!trouver_fond($fond)) { |
|
| 84 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 88 | - if (!empty($res['entetes'])) { |
|
| 89 | - foreach ($res['entetes'] as $h => $v) { |
|
| 90 | - header("$h: $v"); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $res = ltrim((string) $res['texte']); |
|
| 95 | - if (empty($res)) { |
|
| 96 | - spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - echo $res; |
|
| 100 | - exit(); |
|
| 25 | + // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 26 | + if (is_null($arg)) { |
|
| 27 | + $arg = _request('arg'); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + $args = explode('/', (string) $arg); |
|
| 31 | + |
|
| 32 | + if (count($args) !== 4) { |
|
| 33 | + action_api_transmettre_fail($arg); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + [$id_auteur, $cle, $format, $fond] = $args; |
|
| 37 | + $id_auteur = (int) $id_auteur; |
|
| 38 | + |
|
| 39 | + if (preg_match(',[^\w\\.-],', $format)) { |
|
| 40 | + action_api_transmettre_fail("format $format ??"); |
|
| 41 | + } |
|
| 42 | + if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 43 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + // verifier la cle |
|
| 47 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 48 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | + |
|
| 50 | + $qs = $_SERVER['QUERY_STRING']; |
|
| 51 | + // retirer action et arg de la qs |
|
| 52 | + $contexte = []; |
|
| 53 | + parse_str((string) $qs, $contexte); |
|
| 54 | + foreach (array_keys($contexte) as $k) { |
|
| 55 | + if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 56 | + unset($contexte[$k]); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $qs = http_build_query($contexte); |
|
| 60 | + include_spip('inc/acces'); |
|
| 61 | + if (!securiser_acces_low_sec((int) $id_auteur, $cle, "transmettre/$format", $fond, $qs)) { |
|
| 62 | + // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 63 | + include_spip('inc/autoriser'); |
|
| 64 | + $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 65 | + if ( |
|
| 66 | + !$id_auteur |
|
| 67 | + || empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 68 | + || $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 69 | + || !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 70 | + ) { |
|
| 71 | + action_api_transmettre_fail("auth QS $qs ??"); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $contexte['id_auteur'] = $id_auteur; |
|
| 76 | + |
|
| 77 | + $fond = "transmettre/$format/$fond"; |
|
| 78 | + |
|
| 79 | + if (!trouver_fond($fond)) { |
|
| 80 | + $fond = "prive/$fond"; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if (!trouver_fond($fond)) { |
|
| 84 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 88 | + if (!empty($res['entetes'])) { |
|
| 89 | + foreach ($res['entetes'] as $h => $v) { |
|
| 90 | + header("$h: $v"); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $res = ltrim((string) $res['texte']); |
|
| 95 | + if (empty($res)) { |
|
| 96 | + spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + echo $res; |
|
| 100 | + exit(); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function action_api_transmettre_fail($arg): never { |
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres(_T('info_acces_interdit'), $arg); |
|
| 106 | - exit; |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres(_T('info_acces_interdit'), $arg); |
|
| 106 | + exit; |
|
| 107 | 107 | } |
@@ -93,7 +93,7 @@ |
||
| 93 | 93 | |
| 94 | 94 | $res = ltrim((string) $res['texte']); |
| 95 | 95 | if (empty($res)) { |
| 96 | - spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 96 | + spip_log("$arg $qs resultat vide", 'transmettre'._LOG_INFO_IMPORTANTE); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | echo $res; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | 27 | function action_forcer_job_dist() { |
| 28 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | - $id_job = $securiser_action(); |
|
| 28 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | + $id_job = $securiser_action(); |
|
| 30 | 30 | |
| 31 | - if ( |
|
| 32 | - ($id_job = (int) $id_job) |
|
| 33 | - && autoriser('forcer', 'job', $id_job) |
|
| 34 | - ) { |
|
| 35 | - include_spip('inc/queue'); |
|
| 36 | - include_spip('inc/genie'); |
|
| 37 | - queue_schedule([$id_job]); |
|
| 38 | - } |
|
| 31 | + if ( |
|
| 32 | + ($id_job = (int) $id_job) |
|
| 33 | + && autoriser('forcer', 'job', $id_job) |
|
| 34 | + ) { |
|
| 35 | + include_spip('inc/queue'); |
|
| 36 | + include_spip('inc/genie'); |
|
| 37 | + queue_schedule([$id_job]); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | 36 | function action_supprimer_lien_dist($arg = null) { |
| 37 | - if (is_null($arg)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - } |
|
| 37 | + if (is_null($arg)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $arg = explode('-', (string) $arg); |
|
| 43 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 42 | + $arg = explode('-', (string) $arg); |
|
| 43 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 44 | 44 | |
| 45 | - include_spip('action/editer_liens'); |
|
| 46 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 45 | + include_spip('action/editer_liens'); |
|
| 46 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 47 | 47 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/actions'); |
@@ -28,23 +28,23 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function action_etre_webmestre_dist() { |
| 31 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 32 | - $time = $securiser_action(); |
|
| 31 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 32 | + $time = $securiser_action(); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - time() - $time < 15 * 60 |
|
| 36 | - && $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | - && $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | - ) { |
|
| 39 | - $action = _T('info_admin_etre_webmestre'); |
|
| 40 | - $admin = charger_fonction('admin', 'inc'); |
|
| 41 | - // lance la verif par ftp et l'appel |
|
| 42 | - // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | - if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | - echo $r; |
|
| 45 | - exit; |
|
| 46 | - } |
|
| 47 | - } |
|
| 34 | + if ( |
|
| 35 | + time() - $time < 15 * 60 |
|
| 36 | + && $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | + && $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | + ) { |
|
| 39 | + $action = _T('info_admin_etre_webmestre'); |
|
| 40 | + $admin = charger_fonction('admin', 'inc'); |
|
| 41 | + // lance la verif par ftp et l'appel |
|
| 42 | + // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | + if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | + echo $r; |
|
| 45 | + exit; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | 55 | function base_etre_webmestre_dist() { |
| 56 | - if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' && $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 57 | - include_spip('action/editer_auteur'); |
|
| 58 | - auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], ['webmestre' => 'oui'], true); |
|
| 59 | - } |
|
| 56 | + if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' && $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 57 | + include_spip('action/editer_auteur'); |
|
| 58 | + auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], ['webmestre' => 'oui'], true); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -36,40 +36,40 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function action_editer_auteur_dist($arg = null) { |
| 38 | 38 | |
| 39 | - if (is_null($arg)) { |
|
| 40 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 41 | - $arg = $securiser_action(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 46 | - if ( |
|
| 47 | - !($id_auteur = (int) $arg) |
|
| 48 | - && ($id_auteur = auteur_inserer()) > 0 |
|
| 49 | - ) { |
|
| 50 | - # cf. GROS HACK |
|
| 51 | - # recuperer l'eventuel logo charge avant la creation |
|
| 52 | - # ils ont un id = 0-id_auteur de la session |
|
| 53 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 54 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 55 | - foreach (['on', 'off'] as $type) { |
|
| 56 | - if (($logo = $chercher_logo($id_hack, 'id_auteur', $type)) && ($logo = reset($logo))) { |
|
| 57 | - rename($logo, str_replace($id_hack, $id_auteur, (string) $logo)); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = ''; |
|
| 64 | - if ($id_auteur > 0) { |
|
| 65 | - $err = auteur_modifier($id_auteur); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($err) { |
|
| 69 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return [$id_auteur, $err]; |
|
| 39 | + if (is_null($arg)) { |
|
| 40 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 41 | + $arg = $securiser_action(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 46 | + if ( |
|
| 47 | + !($id_auteur = (int) $arg) |
|
| 48 | + && ($id_auteur = auteur_inserer()) > 0 |
|
| 49 | + ) { |
|
| 50 | + # cf. GROS HACK |
|
| 51 | + # recuperer l'eventuel logo charge avant la creation |
|
| 52 | + # ils ont un id = 0-id_auteur de la session |
|
| 53 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 54 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 55 | + foreach (['on', 'off'] as $type) { |
|
| 56 | + if (($logo = $chercher_logo($id_hack, 'id_auteur', $type)) && ($logo = reset($logo))) { |
|
| 57 | + rename($logo, str_replace($id_hack, $id_auteur, (string) $logo)); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = ''; |
|
| 64 | + if ($id_auteur > 0) { |
|
| 65 | + $err = auteur_modifier($id_auteur); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($err) { |
|
| 69 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return [$id_auteur, $err]; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -86,64 +86,64 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function auteur_inserer($source = null, $set = null) { |
| 88 | 88 | |
| 89 | - // Ce qu'on va demander comme modifications |
|
| 90 | - $champs = []; |
|
| 91 | - $champs['source'] = $source ?: 'spip'; |
|
| 92 | - |
|
| 93 | - $champs['login'] = ''; |
|
| 94 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 95 | - $champs['webmestre'] = 'non'; |
|
| 96 | - if (empty($champs['imessage'])) { |
|
| 97 | - $champs['imessage'] = 'oui'; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($set) { |
|
| 101 | - $champs = array_merge($champs, $set); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // Envoyer aux plugins |
|
| 105 | - $champs = pipeline( |
|
| 106 | - 'pre_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_auteurs', |
|
| 110 | - ], |
|
| 111 | - 'data' => $champs |
|
| 112 | - ] |
|
| 113 | - ); |
|
| 114 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 115 | - pipeline( |
|
| 116 | - 'post_insertion', |
|
| 117 | - [ |
|
| 118 | - 'args' => [ |
|
| 119 | - 'table' => 'spip_auteurs', |
|
| 120 | - 'id_objet' => $id_auteur |
|
| 121 | - ], |
|
| 122 | - 'data' => $champs |
|
| 123 | - ] |
|
| 124 | - ); |
|
| 125 | - |
|
| 126 | - // Appeler une notification |
|
| 127 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 128 | - $notifications( |
|
| 129 | - 'auteur_inserer', |
|
| 130 | - $id_auteur, |
|
| 131 | - [ |
|
| 132 | - 'champs' => $champs, |
|
| 133 | - ] |
|
| 134 | - ); |
|
| 135 | - $notifications( |
|
| 136 | - 'objet_inserer', |
|
| 137 | - $id_auteur, |
|
| 138 | - [ |
|
| 139 | - 'objet' => 'auteur', |
|
| 140 | - 'id_objet' => $id_auteur, |
|
| 141 | - 'champs' => $champs, |
|
| 142 | - ] |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $id_auteur; |
|
| 89 | + // Ce qu'on va demander comme modifications |
|
| 90 | + $champs = []; |
|
| 91 | + $champs['source'] = $source ?: 'spip'; |
|
| 92 | + |
|
| 93 | + $champs['login'] = ''; |
|
| 94 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 95 | + $champs['webmestre'] = 'non'; |
|
| 96 | + if (empty($champs['imessage'])) { |
|
| 97 | + $champs['imessage'] = 'oui'; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($set) { |
|
| 101 | + $champs = array_merge($champs, $set); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // Envoyer aux plugins |
|
| 105 | + $champs = pipeline( |
|
| 106 | + 'pre_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_auteurs', |
|
| 110 | + ], |
|
| 111 | + 'data' => $champs |
|
| 112 | + ] |
|
| 113 | + ); |
|
| 114 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 115 | + pipeline( |
|
| 116 | + 'post_insertion', |
|
| 117 | + [ |
|
| 118 | + 'args' => [ |
|
| 119 | + 'table' => 'spip_auteurs', |
|
| 120 | + 'id_objet' => $id_auteur |
|
| 121 | + ], |
|
| 122 | + 'data' => $champs |
|
| 123 | + ] |
|
| 124 | + ); |
|
| 125 | + |
|
| 126 | + // Appeler une notification |
|
| 127 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 128 | + $notifications( |
|
| 129 | + 'auteur_inserer', |
|
| 130 | + $id_auteur, |
|
| 131 | + [ |
|
| 132 | + 'champs' => $champs, |
|
| 133 | + ] |
|
| 134 | + ); |
|
| 135 | + $notifications( |
|
| 136 | + 'objet_inserer', |
|
| 137 | + $id_auteur, |
|
| 138 | + [ |
|
| 139 | + 'objet' => 'auteur', |
|
| 140 | + 'id_objet' => $id_auteur, |
|
| 141 | + 'champs' => $champs, |
|
| 142 | + ] |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $id_auteur; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -168,70 +168,70 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 170 | 170 | |
| 171 | - include_spip('inc/modifier'); |
|
| 172 | - include_spip('inc/filtres'); |
|
| 173 | - $c = collecter_requests( |
|
| 174 | - // include list |
|
| 175 | - objet_info('auteur', 'champs_editables'), |
|
| 176 | - // exclude list |
|
| 177 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 178 | - // donnees eventuellement fournies |
|
| 179 | - $set |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - if ( |
|
| 183 | - $err = objet_modifier_champs( |
|
| 184 | - 'auteur', |
|
| 185 | - $id_auteur, |
|
| 186 | - [ |
|
| 187 | - 'data' => $set, |
|
| 188 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 189 | - ], |
|
| 190 | - $c |
|
| 191 | - ) |
|
| 192 | - ) { |
|
| 193 | - return $err; |
|
| 194 | - } |
|
| 195 | - $session = $c; |
|
| 196 | - |
|
| 197 | - $err = ''; |
|
| 198 | - if (!$force_update) { |
|
| 199 | - // Modification de statut, changement de rubrique ? |
|
| 200 | - $c = collecter_requests( |
|
| 201 | - // include list |
|
| 202 | - [ |
|
| 203 | - 'statut', |
|
| 204 | - 'new_login', |
|
| 205 | - 'new_pass', |
|
| 206 | - 'login', |
|
| 207 | - 'pass', |
|
| 208 | - 'webmestre', |
|
| 209 | - 'restreintes', |
|
| 210 | - 'id_parent' |
|
| 211 | - ], |
|
| 212 | - // exclude list |
|
| 213 | - [], |
|
| 214 | - // donnees eventuellement fournies |
|
| 215 | - $set |
|
| 216 | - ); |
|
| 217 | - if (isset($c['new_login']) && !isset($c['login'])) { |
|
| 218 | - $c['login'] = $c['new_login']; |
|
| 219 | - } |
|
| 220 | - if (isset($c['new_pass']) && !isset($c['pass'])) { |
|
| 221 | - $c['pass'] = $c['new_pass']; |
|
| 222 | - } |
|
| 223 | - $err = auteur_instituer($id_auteur, $c); |
|
| 224 | - $session = array_merge($session, $c); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // .. mettre a jour les sessions de cet auteur |
|
| 228 | - include_spip('inc/session'); |
|
| 229 | - $session['id_auteur'] = $id_auteur; |
|
| 230 | - unset($session['new_login']); |
|
| 231 | - unset($session['new_pass']); |
|
| 232 | - actualiser_sessions($session); |
|
| 233 | - |
|
| 234 | - return $err; |
|
| 171 | + include_spip('inc/modifier'); |
|
| 172 | + include_spip('inc/filtres'); |
|
| 173 | + $c = collecter_requests( |
|
| 174 | + // include list |
|
| 175 | + objet_info('auteur', 'champs_editables'), |
|
| 176 | + // exclude list |
|
| 177 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 178 | + // donnees eventuellement fournies |
|
| 179 | + $set |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + if ( |
|
| 183 | + $err = objet_modifier_champs( |
|
| 184 | + 'auteur', |
|
| 185 | + $id_auteur, |
|
| 186 | + [ |
|
| 187 | + 'data' => $set, |
|
| 188 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 189 | + ], |
|
| 190 | + $c |
|
| 191 | + ) |
|
| 192 | + ) { |
|
| 193 | + return $err; |
|
| 194 | + } |
|
| 195 | + $session = $c; |
|
| 196 | + |
|
| 197 | + $err = ''; |
|
| 198 | + if (!$force_update) { |
|
| 199 | + // Modification de statut, changement de rubrique ? |
|
| 200 | + $c = collecter_requests( |
|
| 201 | + // include list |
|
| 202 | + [ |
|
| 203 | + 'statut', |
|
| 204 | + 'new_login', |
|
| 205 | + 'new_pass', |
|
| 206 | + 'login', |
|
| 207 | + 'pass', |
|
| 208 | + 'webmestre', |
|
| 209 | + 'restreintes', |
|
| 210 | + 'id_parent' |
|
| 211 | + ], |
|
| 212 | + // exclude list |
|
| 213 | + [], |
|
| 214 | + // donnees eventuellement fournies |
|
| 215 | + $set |
|
| 216 | + ); |
|
| 217 | + if (isset($c['new_login']) && !isset($c['login'])) { |
|
| 218 | + $c['login'] = $c['new_login']; |
|
| 219 | + } |
|
| 220 | + if (isset($c['new_pass']) && !isset($c['pass'])) { |
|
| 221 | + $c['pass'] = $c['new_pass']; |
|
| 222 | + } |
|
| 223 | + $err = auteur_instituer($id_auteur, $c); |
|
| 224 | + $session = array_merge($session, $c); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + // .. mettre a jour les sessions de cet auteur |
|
| 228 | + include_spip('inc/session'); |
|
| 229 | + $session['id_auteur'] = $id_auteur; |
|
| 230 | + unset($session['new_login']); |
|
| 231 | + unset($session['new_pass']); |
|
| 232 | + actualiser_sessions($session); |
|
| 233 | + |
|
| 234 | + return $err; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | * @return string |
| 253 | 253 | */ |
| 254 | 254 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 255 | - include_spip('action/editer_liens'); |
|
| 255 | + include_spip('action/editer_liens'); |
|
| 256 | 256 | |
| 257 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 257 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | * @return string |
| 274 | 274 | */ |
| 275 | 275 | function auteur_dissocier($id_auteur, $objets) { |
| 276 | - include_spip('action/editer_liens'); |
|
| 276 | + include_spip('action/editer_liens'); |
|
| 277 | 277 | |
| 278 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 278 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -296,9 +296,9 @@ discard block |
||
| 296 | 296 | * @return bool|int |
| 297 | 297 | */ |
| 298 | 298 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 299 | - include_spip('action/editer_liens'); |
|
| 299 | + include_spip('action/editer_liens'); |
|
| 300 | 300 | |
| 301 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 301 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -317,158 +317,158 @@ discard block |
||
| 317 | 317 | * @return bool|string |
| 318 | 318 | */ |
| 319 | 319 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 320 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 324 | - $champs = []; |
|
| 325 | - |
|
| 326 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 327 | - if (isset($c['login']) && strlen((string) $c['login'])) { |
|
| 328 | - $champs['login'] = $c['login']; |
|
| 329 | - } |
|
| 330 | - if (isset($c['pass']) && strlen((string) $c['pass'])) { |
|
| 331 | - $champs['pass'] = $c['pass']; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 335 | - |
|
| 336 | - if ( |
|
| 337 | - isset($c['statut']) && autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]) |
|
| 338 | - ) { |
|
| 339 | - $statut = $champs['statut'] = $c['statut']; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // Restreindre avant de declarer l'auteur |
|
| 343 | - // (section critique sur les droits) |
|
| 344 | - if (isset($c['id_parent']) && $c['id_parent']) { |
|
| 345 | - if (is_array($c['restreintes'])) { |
|
| 346 | - $c['restreintes'][] = $c['id_parent']; |
|
| 347 | - } else { |
|
| 348 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if ( |
|
| 353 | - isset($c['webmestre']) |
|
| 354 | - && ($force_webmestre || autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 355 | - ) { |
|
| 356 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 360 | - if (isset($c['statut']) && $c['statut'] !== '0minirezo') { |
|
| 361 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // Envoyer aux plugins |
|
| 365 | - $champs = pipeline( |
|
| 366 | - 'pre_edition', |
|
| 367 | - [ |
|
| 368 | - 'args' => [ |
|
| 369 | - 'table' => 'spip_auteurs', |
|
| 370 | - 'id_objet' => $id_auteur, |
|
| 371 | - 'action' => 'instituer', |
|
| 372 | - 'statut_ancien' => $statut_ancien, |
|
| 373 | - ], |
|
| 374 | - 'data' => $champs |
|
| 375 | - ] |
|
| 376 | - ); |
|
| 377 | - |
|
| 378 | - if ( |
|
| 379 | - isset($c['restreintes']) && is_array($c['restreintes']) |
|
| 380 | - && autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 381 | - ) { |
|
| 382 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 383 | - $rubriques = array_unique($rubriques); |
|
| 384 | - $rubriques = array_diff($rubriques, [0]); |
|
| 385 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 386 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - $flag_ecrire_acces = false; |
|
| 390 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 391 | - // avant les autres ecritures en base |
|
| 392 | - if (isset($champs['login']) || isset($champs['pass'])) { |
|
| 393 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 394 | - include_spip('inc/auth'); |
|
| 395 | - if ( |
|
| 396 | - isset($champs['login']) |
|
| 397 | - && strlen((string) $champs['login']) |
|
| 398 | - && !auth_modifier_login($auth_methode, $champs['login'], $id_auteur) |
|
| 399 | - ) { |
|
| 400 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 401 | - } |
|
| 402 | - if (isset($champs['pass']) && strlen((string) $champs['pass'])) { |
|
| 403 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 404 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 405 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - unset($champs['login']); |
|
| 409 | - unset($champs['pass']); |
|
| 410 | - $flag_ecrire_acces = true; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 414 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 415 | - } |
|
| 416 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 417 | - |
|
| 418 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 419 | - if ($flag_ecrire_acces || isset($champs['statut'])) { |
|
| 420 | - include_spip('inc/acces'); |
|
| 421 | - ecrire_acces(); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // Invalider les caches |
|
| 425 | - include_spip('inc/invalideur'); |
|
| 426 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 427 | - |
|
| 428 | - // Pipeline |
|
| 429 | - pipeline( |
|
| 430 | - 'post_edition', |
|
| 431 | - [ |
|
| 432 | - 'args' => [ |
|
| 433 | - 'table' => 'spip_auteurs', |
|
| 434 | - 'id_objet' => $id_auteur, |
|
| 435 | - 'action' => 'instituer', |
|
| 436 | - 'statut_ancien' => $statut_ancien, |
|
| 437 | - ], |
|
| 438 | - 'data' => $champs |
|
| 439 | - ] |
|
| 440 | - ); |
|
| 441 | - |
|
| 442 | - // Notifications |
|
| 443 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 444 | - $notifications( |
|
| 445 | - 'auteur_instituer', |
|
| 446 | - $id_auteur, |
|
| 447 | - [ |
|
| 448 | - 'statut' => $statut, |
|
| 449 | - 'statut_ancien' => $statut_ancien, |
|
| 450 | - 'champs' => $champs, |
|
| 451 | - ] |
|
| 452 | - ); |
|
| 453 | - $notifications( |
|
| 454 | - 'objet_instituer', |
|
| 455 | - $id_auteur, |
|
| 456 | - [ |
|
| 457 | - 'objet' => 'auteur', |
|
| 458 | - 'id_objet' => $id_auteur, |
|
| 459 | - 'statut' => $statut, |
|
| 460 | - 'statut_ancien' => $statut_ancien, |
|
| 461 | - 'champs' => $champs, |
|
| 462 | - ] |
|
| 463 | - ); |
|
| 464 | - |
|
| 465 | - // Rétro-compat |
|
| 466 | - $notifications( |
|
| 467 | - 'instituerauteur', |
|
| 468 | - $id_auteur, |
|
| 469 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 470 | - ); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 320 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 324 | + $champs = []; |
|
| 325 | + |
|
| 326 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 327 | + if (isset($c['login']) && strlen((string) $c['login'])) { |
|
| 328 | + $champs['login'] = $c['login']; |
|
| 329 | + } |
|
| 330 | + if (isset($c['pass']) && strlen((string) $c['pass'])) { |
|
| 331 | + $champs['pass'] = $c['pass']; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 335 | + |
|
| 336 | + if ( |
|
| 337 | + isset($c['statut']) && autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]) |
|
| 338 | + ) { |
|
| 339 | + $statut = $champs['statut'] = $c['statut']; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // Restreindre avant de declarer l'auteur |
|
| 343 | + // (section critique sur les droits) |
|
| 344 | + if (isset($c['id_parent']) && $c['id_parent']) { |
|
| 345 | + if (is_array($c['restreintes'])) { |
|
| 346 | + $c['restreintes'][] = $c['id_parent']; |
|
| 347 | + } else { |
|
| 348 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if ( |
|
| 353 | + isset($c['webmestre']) |
|
| 354 | + && ($force_webmestre || autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 355 | + ) { |
|
| 356 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 360 | + if (isset($c['statut']) && $c['statut'] !== '0minirezo') { |
|
| 361 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // Envoyer aux plugins |
|
| 365 | + $champs = pipeline( |
|
| 366 | + 'pre_edition', |
|
| 367 | + [ |
|
| 368 | + 'args' => [ |
|
| 369 | + 'table' => 'spip_auteurs', |
|
| 370 | + 'id_objet' => $id_auteur, |
|
| 371 | + 'action' => 'instituer', |
|
| 372 | + 'statut_ancien' => $statut_ancien, |
|
| 373 | + ], |
|
| 374 | + 'data' => $champs |
|
| 375 | + ] |
|
| 376 | + ); |
|
| 377 | + |
|
| 378 | + if ( |
|
| 379 | + isset($c['restreintes']) && is_array($c['restreintes']) |
|
| 380 | + && autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 381 | + ) { |
|
| 382 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 383 | + $rubriques = array_unique($rubriques); |
|
| 384 | + $rubriques = array_diff($rubriques, [0]); |
|
| 385 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 386 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + $flag_ecrire_acces = false; |
|
| 390 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 391 | + // avant les autres ecritures en base |
|
| 392 | + if (isset($champs['login']) || isset($champs['pass'])) { |
|
| 393 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 394 | + include_spip('inc/auth'); |
|
| 395 | + if ( |
|
| 396 | + isset($champs['login']) |
|
| 397 | + && strlen((string) $champs['login']) |
|
| 398 | + && !auth_modifier_login($auth_methode, $champs['login'], $id_auteur) |
|
| 399 | + ) { |
|
| 400 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 401 | + } |
|
| 402 | + if (isset($champs['pass']) && strlen((string) $champs['pass'])) { |
|
| 403 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 404 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 405 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + unset($champs['login']); |
|
| 409 | + unset($champs['pass']); |
|
| 410 | + $flag_ecrire_acces = true; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 414 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 415 | + } |
|
| 416 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 417 | + |
|
| 418 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 419 | + if ($flag_ecrire_acces || isset($champs['statut'])) { |
|
| 420 | + include_spip('inc/acces'); |
|
| 421 | + ecrire_acces(); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // Invalider les caches |
|
| 425 | + include_spip('inc/invalideur'); |
|
| 426 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 427 | + |
|
| 428 | + // Pipeline |
|
| 429 | + pipeline( |
|
| 430 | + 'post_edition', |
|
| 431 | + [ |
|
| 432 | + 'args' => [ |
|
| 433 | + 'table' => 'spip_auteurs', |
|
| 434 | + 'id_objet' => $id_auteur, |
|
| 435 | + 'action' => 'instituer', |
|
| 436 | + 'statut_ancien' => $statut_ancien, |
|
| 437 | + ], |
|
| 438 | + 'data' => $champs |
|
| 439 | + ] |
|
| 440 | + ); |
|
| 441 | + |
|
| 442 | + // Notifications |
|
| 443 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 444 | + $notifications( |
|
| 445 | + 'auteur_instituer', |
|
| 446 | + $id_auteur, |
|
| 447 | + [ |
|
| 448 | + 'statut' => $statut, |
|
| 449 | + 'statut_ancien' => $statut_ancien, |
|
| 450 | + 'champs' => $champs, |
|
| 451 | + ] |
|
| 452 | + ); |
|
| 453 | + $notifications( |
|
| 454 | + 'objet_instituer', |
|
| 455 | + $id_auteur, |
|
| 456 | + [ |
|
| 457 | + 'objet' => 'auteur', |
|
| 458 | + 'id_objet' => $id_auteur, |
|
| 459 | + 'statut' => $statut, |
|
| 460 | + 'statut_ancien' => $statut_ancien, |
|
| 461 | + 'champs' => $champs, |
|
| 462 | + ] |
|
| 463 | + ); |
|
| 464 | + |
|
| 465 | + // Rétro-compat |
|
| 466 | + $notifications( |
|
| 467 | + 'instituerauteur', |
|
| 468 | + $id_auteur, |
|
| 469 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 470 | + ); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 474 | 474 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $champs['source'] = $source ?: 'spip'; |
| 92 | 92 | |
| 93 | 93 | $champs['login'] = ''; |
| 94 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 94 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 95 | 95 | $champs['webmestre'] = 'non'; |
| 96 | 96 | if (empty($champs['imessage'])) { |
| 97 | 97 | $champs['imessage'] = 'oui'; |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $champs['pass'] = $c['pass']; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 334 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.(int) $id_auteur); |
|
| 335 | 335 | |
| 336 | 336 | if ( |
| 337 | 337 | isset($c['statut']) && autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]) |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | // commencer par traiter les cas particuliers des logins et pass |
| 391 | 391 | // avant les autres ecritures en base |
| 392 | 392 | if (isset($champs['login']) || isset($champs['pass'])) { |
| 393 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 393 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.(int) $id_auteur); |
|
| 394 | 394 | include_spip('inc/auth'); |
| 395 | 395 | if ( |
| 396 | 396 | isset($champs['login']) |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
| 401 | 401 | } |
| 402 | 402 | if (isset($champs['pass']) && strlen((string) $champs['pass'])) { |
| 403 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur); |
|
| 403 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.(int) $id_auteur); |
|
| 404 | 404 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
| 405 | 405 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 406 | 406 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | if (!(is_countable($champs) ? count($champs) : 0)) { |
| 414 | 414 | return implode(' ', array_map('_T', $erreurs)); |
| 415 | 415 | } |
| 416 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 416 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 417 | 417 | |
| 418 | 418 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 419 | 419 | if ($flag_ecrire_acces || isset($champs['statut'])) { |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | 35 | function action_ajouter_lien_dist($arg = null) { |
| 36 | - if (is_null($arg)) { |
|
| 37 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | - $arg = $securiser_action(); |
|
| 39 | - } |
|
| 36 | + if (is_null($arg)) { |
|
| 37 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | + $arg = $securiser_action(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $arg = explode('-', (string) $arg); |
|
| 42 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 41 | + $arg = explode('-', (string) $arg); |
|
| 42 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 43 | 43 | |
| 44 | - include_spip('action/editer_liens'); |
|
| 45 | - objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 44 | + include_spip('action/editer_liens'); |
|
| 45 | + objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 46 | 46 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | * Envoyer en réponse : json contenant toutes les variables publiques de la session |
| 32 | 32 | **/ |
| 33 | 33 | function action_session_dist() { |
| 34 | - if ( |
|
| 35 | - ($var = _request('var')) |
|
| 36 | - && preg_match(',^[a-z_0-9-]+$,i', (string) $var) |
|
| 37 | - && $_SERVER['REQUEST_METHOD'] == 'POST' |
|
| 38 | - ) { |
|
| 39 | - include_spip('inc/session'); |
|
| 40 | - session_set('session_' . $var, $val = _request('val')); |
|
| 41 | - #spip_log("autosave:$var:$val",'autosave'); |
|
| 42 | - } |
|
| 34 | + if ( |
|
| 35 | + ($var = _request('var')) |
|
| 36 | + && preg_match(',^[a-z_0-9-]+$,i', (string) $var) |
|
| 37 | + && $_SERVER['REQUEST_METHOD'] == 'POST' |
|
| 38 | + ) { |
|
| 39 | + include_spip('inc/session'); |
|
| 40 | + session_set('session_' . $var, $val = _request('val')); |
|
| 41 | + #spip_log("autosave:$var:$val",'autosave'); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - # TODO: mode lecture de session ; n'afficher que ce qu'il faut |
|
| 45 | - #echo json_encode($GLOBALS['visiteur_session']); |
|
| 44 | + # TODO: mode lecture de session ; n'afficher que ce qu'il faut |
|
| 45 | + #echo json_encode($GLOBALS['visiteur_session']); |
|
| 46 | 46 | } |
@@ -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,53 +35,53 @@ discard block |
||
| 35 | 35 | * ``` |
| 36 | 36 | **/ |
| 37 | 37 | function action_redirect_dist() { |
| 38 | - $type = _request('type'); |
|
| 39 | - $id = (int) _request('id'); |
|
| 40 | - $page = false; |
|
| 38 | + $type = _request('type'); |
|
| 39 | + $id = (int) _request('id'); |
|
| 40 | + $page = false; |
|
| 41 | 41 | |
| 42 | - // verifier le type ou page transmis |
|
| 43 | - if (!preg_match('/^\w+$/', (string) $type)) { |
|
| 44 | - $page = _request('page'); |
|
| 45 | - if (!preg_match('/^\w+$/', (string) $page)) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - } |
|
| 42 | + // verifier le type ou page transmis |
|
| 43 | + if (!preg_match('/^\w+$/', (string) $type)) { |
|
| 44 | + $page = _request('page'); |
|
| 45 | + if (!preg_match('/^\w+$/', (string) $page)) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $var_mode = _request('var_mode'); |
|
| 51 | - // forcer la mise a jour de l'url de cet objet ! |
|
| 52 | - if ($var_mode && !defined('_VAR_URLS')) { |
|
| 53 | - define('_VAR_URLS', true); |
|
| 54 | - } |
|
| 50 | + $var_mode = _request('var_mode'); |
|
| 51 | + // forcer la mise a jour de l'url de cet objet ! |
|
| 52 | + if ($var_mode && !defined('_VAR_URLS')) { |
|
| 53 | + define('_VAR_URLS', true); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $url = $page |
|
| 57 | - ? generer_url_public($page, '', true) |
|
| 58 | - : calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 56 | + $url = $page |
|
| 57 | + ? generer_url_public($page, '', true) |
|
| 58 | + : calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 59 | 59 | |
| 60 | - $status = '302'; |
|
| 61 | - if ($url) { |
|
| 62 | - if ($var_mode) { |
|
| 63 | - $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 64 | - } |
|
| 60 | + $status = '302'; |
|
| 61 | + if ($url) { |
|
| 62 | + if ($var_mode) { |
|
| 63 | + $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( |
|
| 67 | - $var_mode == 'preview' |
|
| 68 | - && defined('_PREVIEW_TOKEN') |
|
| 69 | - && _PREVIEW_TOKEN |
|
| 70 | - && autoriser('previsualiser') |
|
| 71 | - ) { |
|
| 72 | - include_spip('inc/securiser_action'); |
|
| 73 | - $token = calculer_token_previsu($url); |
|
| 74 | - $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 75 | - } |
|
| 66 | + if ( |
|
| 67 | + $var_mode == 'preview' |
|
| 68 | + && defined('_PREVIEW_TOKEN') |
|
| 69 | + && _PREVIEW_TOKEN |
|
| 70 | + && autoriser('previsualiser') |
|
| 71 | + ) { |
|
| 72 | + include_spip('inc/securiser_action'); |
|
| 73 | + $token = calculer_token_previsu($url); |
|
| 74 | + $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - if (_request('status') && _request('status') == '301') { |
|
| 78 | - $status = '301'; |
|
| 79 | - } |
|
| 80 | - } else { |
|
| 81 | - $url = generer_url_public('404', '', true); |
|
| 82 | - } |
|
| 77 | + if (_request('status') && _request('status') == '301') { |
|
| 78 | + $status = '301'; |
|
| 79 | + } |
|
| 80 | + } else { |
|
| 81 | + $url = generer_url_public('404', '', true); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - redirige_par_entete(str_replace('&', '&', (string) $url), '', $status); |
|
| 84 | + redirige_par_entete(str_replace('&', '&', (string) $url), '', $status); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -96,35 +96,35 @@ discard block |
||
| 96 | 96 | * @return string|null |
| 97 | 97 | */ |
| 98 | 98 | function calculer_url_redirect_entite($type, $id, $var_mode) { |
| 99 | - $desc = null; |
|
| 100 | - $publie = null; |
|
| 101 | - $url = null; |
|
| 102 | - // invalider le cache à chaque modif en bdd |
|
| 103 | - $date = 0; |
|
| 104 | - if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 105 | - $date = $GLOBALS['meta']['derniere_modif']; |
|
| 106 | - } |
|
| 107 | - $key = "url-$date-$type-$id"; |
|
| 99 | + $desc = null; |
|
| 100 | + $publie = null; |
|
| 101 | + $url = null; |
|
| 102 | + // invalider le cache à chaque modif en bdd |
|
| 103 | + $date = 0; |
|
| 104 | + if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 105 | + $date = $GLOBALS['meta']['derniere_modif']; |
|
| 106 | + } |
|
| 107 | + $key = "url-$date-$type-$id"; |
|
| 108 | 108 | |
| 109 | - // Obtenir l’url et si elle est publié du cache memoization |
|
| 110 | - if (function_exists('cache_get') && ($desc = cache_get($key))) { |
|
| 111 | - [$url, $publie] = $desc; |
|
| 112 | - } |
|
| 113 | - // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 114 | - if (empty($desc) || $var_mode) { |
|
| 115 | - $publie = objet_test_si_publie($type, $id); |
|
| 116 | - $url = generer_objet_url_absolue($id, $type, '', '', true); |
|
| 117 | - if (function_exists('cache_set')) { |
|
| 118 | - cache_set($key, [$url, $publie], 3600); |
|
| 119 | - } |
|
| 120 | - } |
|
| 109 | + // Obtenir l’url et si elle est publié du cache memoization |
|
| 110 | + if (function_exists('cache_get') && ($desc = cache_get($key))) { |
|
| 111 | + [$url, $publie] = $desc; |
|
| 112 | + } |
|
| 113 | + // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 114 | + if (empty($desc) || $var_mode) { |
|
| 115 | + $publie = objet_test_si_publie($type, $id); |
|
| 116 | + $url = generer_objet_url_absolue($id, $type, '', '', true); |
|
| 117 | + if (function_exists('cache_set')) { |
|
| 118 | + cache_set($key, [$url, $publie], 3600); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 123 | - if ($publie) { |
|
| 124 | - return $url; |
|
| 125 | - } elseif (defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id)) { |
|
| 126 | - return $url; |
|
| 127 | - } |
|
| 122 | + // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 123 | + if ($publie) { |
|
| 124 | + return $url; |
|
| 125 | + } elseif (defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id)) { |
|
| 126 | + return $url; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return; |
|
| 129 | + return; |
|
| 130 | 130 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -32,36 +32,36 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 34 | 34 | |
| 35 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 36 | - if (is_null($id) || is_null($objet)) { |
|
| 37 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | - $arg = $securiser_action(); |
|
| 39 | - [$objet, $id] = array_pad(explode('/', (string) $arg, 2), 2, null); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 43 | - if (is_null($id) || is_null($objet)) { |
|
| 44 | - include_spip('inc/minipres'); |
|
| 45 | - echo minipres(_T('info_acces_interdit')); |
|
| 46 | - die(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // si id n'est pas un nombre, c'est une creation |
|
| 50 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | - if (!$id = (int) $id) { |
|
| 52 | - // on ne sait pas si un parent existe mais on essaye |
|
| 53 | - $id_parent = _request('id_parent'); |
|
| 54 | - $id = objet_inserer($objet, $id_parent); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if (!($id = (int) $id) > 0) { |
|
| 58 | - return [$id, _L('echec enregistrement en base')]; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Enregistre l'envoi dans la BD |
|
| 62 | - $err = objet_modifier($objet, $id, $set); |
|
| 63 | - |
|
| 64 | - return [$id, $err]; |
|
| 35 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 36 | + if (is_null($id) || is_null($objet)) { |
|
| 37 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 38 | + $arg = $securiser_action(); |
|
| 39 | + [$objet, $id] = array_pad(explode('/', (string) $arg, 2), 2, null); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 43 | + if (is_null($id) || is_null($objet)) { |
|
| 44 | + include_spip('inc/minipres'); |
|
| 45 | + echo minipres(_T('info_acces_interdit')); |
|
| 46 | + die(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // si id n'est pas un nombre, c'est une creation |
|
| 50 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | + if (!$id = (int) $id) { |
|
| 52 | + // on ne sait pas si un parent existe mais on essaye |
|
| 53 | + $id_parent = _request('id_parent'); |
|
| 54 | + $id = objet_inserer($objet, $id_parent); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if (!($id = (int) $id) > 0) { |
|
| 58 | + return [$id, _L('echec enregistrement en base')]; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Enregistre l'envoi dans la BD |
|
| 62 | + $err = objet_modifier($objet, $id, $set); |
|
| 63 | + |
|
| 64 | + return [$id, $err]; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -74,83 +74,83 @@ discard block |
||
| 74 | 74 | * @return mixed|string |
| 75 | 75 | */ |
| 76 | 76 | function objet_modifier($objet, $id, $set = null) { |
| 77 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 78 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 79 | - $objet = $t; |
|
| 80 | - } |
|
| 81 | - if ( |
|
| 82 | - include_spip('action/editer_' . $objet) && function_exists($modifier = $objet . '_modifier') |
|
| 83 | - ) { |
|
| 84 | - return $modifier($id, $set); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $table_sql = table_objet_sql($objet); |
|
| 88 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 89 | - $desc = $trouver_table($table_sql); |
|
| 90 | - if (!$desc || !isset($desc['field'])) { |
|
| 91 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 92 | - |
|
| 93 | - return _L("Erreur objet $objet inconnu"); |
|
| 94 | - } |
|
| 95 | - include_spip('inc/modifier'); |
|
| 96 | - |
|
| 97 | - $champ_date = ''; |
|
| 98 | - if (isset($desc['date']) && $desc['date']) { |
|
| 99 | - $champ_date = $desc['date']; |
|
| 100 | - } elseif (isset($desc['field']['date'])) { |
|
| 101 | - $champ_date = 'date'; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $include_list = array_keys($desc['field']); |
|
| 105 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 106 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 107 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 108 | - |
|
| 109 | - if (isset($desc['champs_editables']) && is_array($desc['champs_editables'])) { |
|
| 110 | - $include_list = $desc['champs_editables']; |
|
| 111 | - } |
|
| 112 | - $c = collecter_requests( |
|
| 113 | - // include list |
|
| 114 | - $include_list, |
|
| 115 | - // exclude list |
|
| 116 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 117 | - // donnees eventuellement fournies |
|
| 118 | - $set |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 122 | - if (objet_test_si_publie($objet, $id)) { |
|
| 123 | - $invalideur = "id='$objet/$id'"; |
|
| 124 | - $indexation = true; |
|
| 125 | - } else { |
|
| 126 | - $invalideur = ''; |
|
| 127 | - $indexation = false; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ( |
|
| 131 | - $err = objet_modifier_champs( |
|
| 132 | - $objet, |
|
| 133 | - $id, |
|
| 134 | - [ |
|
| 135 | - 'data' => $set, |
|
| 136 | - 'nonvide' => '', |
|
| 137 | - 'invalideur' => $invalideur, |
|
| 138 | - 'indexation' => $indexation, |
|
| 139 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 140 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 141 | - ], |
|
| 142 | - $c |
|
| 143 | - ) |
|
| 144 | - ) { |
|
| 145 | - return $err; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Modification de statut, changement de rubrique ? |
|
| 149 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 150 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 151 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 152 | - |
|
| 153 | - return objet_instituer($objet, $id, $c); |
|
| 77 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 78 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 79 | + $objet = $t; |
|
| 80 | + } |
|
| 81 | + if ( |
|
| 82 | + include_spip('action/editer_' . $objet) && function_exists($modifier = $objet . '_modifier') |
|
| 83 | + ) { |
|
| 84 | + return $modifier($id, $set); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $table_sql = table_objet_sql($objet); |
|
| 88 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 89 | + $desc = $trouver_table($table_sql); |
|
| 90 | + if (!$desc || !isset($desc['field'])) { |
|
| 91 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 92 | + |
|
| 93 | + return _L("Erreur objet $objet inconnu"); |
|
| 94 | + } |
|
| 95 | + include_spip('inc/modifier'); |
|
| 96 | + |
|
| 97 | + $champ_date = ''; |
|
| 98 | + if (isset($desc['date']) && $desc['date']) { |
|
| 99 | + $champ_date = $desc['date']; |
|
| 100 | + } elseif (isset($desc['field']['date'])) { |
|
| 101 | + $champ_date = 'date'; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $include_list = array_keys($desc['field']); |
|
| 105 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 106 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 107 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 108 | + |
|
| 109 | + if (isset($desc['champs_editables']) && is_array($desc['champs_editables'])) { |
|
| 110 | + $include_list = $desc['champs_editables']; |
|
| 111 | + } |
|
| 112 | + $c = collecter_requests( |
|
| 113 | + // include list |
|
| 114 | + $include_list, |
|
| 115 | + // exclude list |
|
| 116 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 117 | + // donnees eventuellement fournies |
|
| 118 | + $set |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 122 | + if (objet_test_si_publie($objet, $id)) { |
|
| 123 | + $invalideur = "id='$objet/$id'"; |
|
| 124 | + $indexation = true; |
|
| 125 | + } else { |
|
| 126 | + $invalideur = ''; |
|
| 127 | + $indexation = false; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ( |
|
| 131 | + $err = objet_modifier_champs( |
|
| 132 | + $objet, |
|
| 133 | + $id, |
|
| 134 | + [ |
|
| 135 | + 'data' => $set, |
|
| 136 | + 'nonvide' => '', |
|
| 137 | + 'invalideur' => $invalideur, |
|
| 138 | + 'indexation' => $indexation, |
|
| 139 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 140 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 141 | + ], |
|
| 142 | + $c |
|
| 143 | + ) |
|
| 144 | + ) { |
|
| 145 | + return $err; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Modification de statut, changement de rubrique ? |
|
| 149 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 150 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 151 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 152 | + |
|
| 153 | + return objet_instituer($objet, $id, $c); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,154 +165,154 @@ discard block |
||
| 165 | 165 | * @return bool|int |
| 166 | 166 | */ |
| 167 | 167 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 168 | - $d = null; |
|
| 169 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 170 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 171 | - $objet = $t; |
|
| 172 | - } |
|
| 173 | - if ( |
|
| 174 | - include_spip('action/editer_' . $objet) |
|
| 175 | - && function_exists($inserer = $objet . '_inserer') |
|
| 176 | - ) { |
|
| 177 | - return $inserer($id_parent, $set); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $table_sql = table_objet_sql($objet); |
|
| 181 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 182 | - $desc = $trouver_table($table_sql); |
|
| 183 | - if (!$desc || !isset($desc['field'])) { |
|
| 184 | - return 0; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $lang_rub = ''; |
|
| 188 | - $champs = []; |
|
| 189 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 190 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 191 | - // dans la premiere rubrique racine |
|
| 192 | - if (!$id_rubrique = (int) $id_parent) { |
|
| 193 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 194 | - $id_rubrique = $row['id_rubrique']; |
|
| 195 | - } else { |
|
| 196 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 200 | - if (isset($desc['field']['id_secteur'])) { |
|
| 201 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 202 | - } |
|
| 203 | - $lang_rub = $row['lang']; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 207 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 208 | - // ou a defaut celle de la rubrique |
|
| 209 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 210 | - if ( |
|
| 211 | - isset($desc['field']['lang']) && !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 212 | - $table_sql, |
|
| 213 | - explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 214 | - ) |
|
| 215 | - ) { |
|
| 216 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 217 | - if ( |
|
| 218 | - in_array( |
|
| 219 | - $GLOBALS['spip_lang'], |
|
| 220 | - explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 221 | - ) |
|
| 222 | - ) { |
|
| 223 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 224 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 225 | - $champs['langue_choisie'] = 'oui'; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } elseif (isset($desc['field']['lang']) && isset($desc['field']['langue_choisie'])) { |
|
| 229 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 230 | - $champs['langue_choisie'] = 'non'; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if (isset($desc['field']['statut'])) { |
|
| 234 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 235 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 236 | - $champs['statut'] = reset($cles_statut); |
|
| 237 | - } else { |
|
| 238 | - $champs['statut'] = 'prepa'; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - if (isset($desc['date']) && ($d = $desc['date']) || isset($desc['field'][$d = 'date'])) { |
|
| 244 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($set) { |
|
| 248 | - $champs = array_merge($champs, $set); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // Envoyer aux plugins |
|
| 252 | - $champs = pipeline( |
|
| 253 | - 'pre_insertion', |
|
| 254 | - [ |
|
| 255 | - 'args' => [ |
|
| 256 | - 'table' => $table_sql, |
|
| 257 | - 'id_parent' => $id_parent, |
|
| 258 | - ], |
|
| 259 | - 'data' => $champs |
|
| 260 | - ] |
|
| 261 | - ); |
|
| 262 | - |
|
| 263 | - $id = sql_insertq($table_sql, $champs); |
|
| 264 | - |
|
| 265 | - if ($id) { |
|
| 266 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 267 | - // et associer l'auteur sinon |
|
| 268 | - // si la table n'a pas deja un champ id_auteur |
|
| 269 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 270 | - if ($id > 0 && !isset($desc['field']['id_auteur'])) { |
|
| 271 | - $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) |
|
| 272 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 273 | - : _request('id_auteur')); |
|
| 274 | - if ($id_auteur) { |
|
| 275 | - include_spip('action/editer_auteur'); |
|
| 276 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - pipeline( |
|
| 281 | - 'post_insertion', |
|
| 282 | - [ |
|
| 283 | - 'args' => [ |
|
| 284 | - 'table' => $table_sql, |
|
| 285 | - 'id_parent' => $id_parent, |
|
| 286 | - 'id_objet' => $id, |
|
| 287 | - ], |
|
| 288 | - 'data' => $champs |
|
| 289 | - ] |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Appeler une notification |
|
| 294 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 295 | - $notifications( |
|
| 296 | - "{$objet}_inserer", |
|
| 297 | - $id, |
|
| 298 | - [ |
|
| 299 | - 'id_parent' => $id_parent, |
|
| 300 | - 'champs' => $champs, |
|
| 301 | - ] |
|
| 302 | - ); |
|
| 303 | - $notifications( |
|
| 304 | - 'objet_inserer', |
|
| 305 | - $id, |
|
| 306 | - [ |
|
| 307 | - 'objet' => $objet, |
|
| 308 | - 'id_objet' => $id, |
|
| 309 | - 'id_parent' => $id_parent, |
|
| 310 | - 'champs' => $champs, |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $id; |
|
| 168 | + $d = null; |
|
| 169 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 170 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 171 | + $objet = $t; |
|
| 172 | + } |
|
| 173 | + if ( |
|
| 174 | + include_spip('action/editer_' . $objet) |
|
| 175 | + && function_exists($inserer = $objet . '_inserer') |
|
| 176 | + ) { |
|
| 177 | + return $inserer($id_parent, $set); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $table_sql = table_objet_sql($objet); |
|
| 181 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 182 | + $desc = $trouver_table($table_sql); |
|
| 183 | + if (!$desc || !isset($desc['field'])) { |
|
| 184 | + return 0; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $lang_rub = ''; |
|
| 188 | + $champs = []; |
|
| 189 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 190 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 191 | + // dans la premiere rubrique racine |
|
| 192 | + if (!$id_rubrique = (int) $id_parent) { |
|
| 193 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 194 | + $id_rubrique = $row['id_rubrique']; |
|
| 195 | + } else { |
|
| 196 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 200 | + if (isset($desc['field']['id_secteur'])) { |
|
| 201 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 202 | + } |
|
| 203 | + $lang_rub = $row['lang']; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 207 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 208 | + // ou a defaut celle de la rubrique |
|
| 209 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 210 | + if ( |
|
| 211 | + isset($desc['field']['lang']) && !empty($GLOBALS['meta']['multi_objets']) && in_array( |
|
| 212 | + $table_sql, |
|
| 213 | + explode(',', (string) $GLOBALS['meta']['multi_objets']) |
|
| 214 | + ) |
|
| 215 | + ) { |
|
| 216 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 217 | + if ( |
|
| 218 | + in_array( |
|
| 219 | + $GLOBALS['spip_lang'], |
|
| 220 | + explode(',', (string) $GLOBALS['meta']['langues_multilingue']) |
|
| 221 | + ) |
|
| 222 | + ) { |
|
| 223 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 224 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 225 | + $champs['langue_choisie'] = 'oui'; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } elseif (isset($desc['field']['lang']) && isset($desc['field']['langue_choisie'])) { |
|
| 229 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 230 | + $champs['langue_choisie'] = 'non'; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if (isset($desc['field']['statut'])) { |
|
| 234 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 235 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 236 | + $champs['statut'] = reset($cles_statut); |
|
| 237 | + } else { |
|
| 238 | + $champs['statut'] = 'prepa'; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + if (isset($desc['date']) && ($d = $desc['date']) || isset($desc['field'][$d = 'date'])) { |
|
| 244 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($set) { |
|
| 248 | + $champs = array_merge($champs, $set); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // Envoyer aux plugins |
|
| 252 | + $champs = pipeline( |
|
| 253 | + 'pre_insertion', |
|
| 254 | + [ |
|
| 255 | + 'args' => [ |
|
| 256 | + 'table' => $table_sql, |
|
| 257 | + 'id_parent' => $id_parent, |
|
| 258 | + ], |
|
| 259 | + 'data' => $champs |
|
| 260 | + ] |
|
| 261 | + ); |
|
| 262 | + |
|
| 263 | + $id = sql_insertq($table_sql, $champs); |
|
| 264 | + |
|
| 265 | + if ($id) { |
|
| 266 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 267 | + // et associer l'auteur sinon |
|
| 268 | + // si la table n'a pas deja un champ id_auteur |
|
| 269 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 270 | + if ($id > 0 && !isset($desc['field']['id_auteur'])) { |
|
| 271 | + $id_auteur = ((is_null(_request('id_auteur')) && isset($GLOBALS['visiteur_session']['id_auteur'])) |
|
| 272 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 273 | + : _request('id_auteur')); |
|
| 274 | + if ($id_auteur) { |
|
| 275 | + include_spip('action/editer_auteur'); |
|
| 276 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + pipeline( |
|
| 281 | + 'post_insertion', |
|
| 282 | + [ |
|
| 283 | + 'args' => [ |
|
| 284 | + 'table' => $table_sql, |
|
| 285 | + 'id_parent' => $id_parent, |
|
| 286 | + 'id_objet' => $id, |
|
| 287 | + ], |
|
| 288 | + 'data' => $champs |
|
| 289 | + ] |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Appeler une notification |
|
| 294 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 295 | + $notifications( |
|
| 296 | + "{$objet}_inserer", |
|
| 297 | + $id, |
|
| 298 | + [ |
|
| 299 | + 'id_parent' => $id_parent, |
|
| 300 | + 'champs' => $champs, |
|
| 301 | + ] |
|
| 302 | + ); |
|
| 303 | + $notifications( |
|
| 304 | + 'objet_inserer', |
|
| 305 | + $id, |
|
| 306 | + [ |
|
| 307 | + 'objet' => $objet, |
|
| 308 | + 'id_objet' => $id, |
|
| 309 | + 'id_parent' => $id_parent, |
|
| 310 | + 'champs' => $champs, |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $id; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
@@ -329,135 +329,135 @@ discard block |
||
| 329 | 329 | * @return string |
| 330 | 330 | */ |
| 331 | 331 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 332 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 333 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 334 | - $objet = $t; |
|
| 335 | - } |
|
| 336 | - if ( |
|
| 337 | - include_spip('action/editer_' . $objet) && function_exists($instituer = $objet . '_instituer') |
|
| 338 | - ) { |
|
| 339 | - return $instituer($id, $c, $calcul_rub); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $table_sql = table_objet_sql($objet); |
|
| 343 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 344 | - $desc = $trouver_table($table_sql); |
|
| 345 | - if (!$desc || !isset($desc['field'])) { |
|
| 346 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - include_spip('inc/autoriser'); |
|
| 350 | - include_spip('inc/rubriques'); |
|
| 351 | - include_spip('inc/modifier'); |
|
| 352 | - |
|
| 353 | - $sel = []; |
|
| 354 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 355 | - |
|
| 356 | - $champ_date = ''; |
|
| 357 | - if (isset($desc['date']) && $desc['date']) { |
|
| 358 | - $champ_date = $desc['date']; |
|
| 359 | - } elseif (isset($desc['field']['date'])) { |
|
| 360 | - $champ_date = 'date'; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 364 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 365 | - |
|
| 366 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . (int) $id); |
|
| 367 | - |
|
| 368 | - $id_rubrique = $row['id_rubrique']; |
|
| 369 | - $statut_ancien = $statut = $row['statut']; |
|
| 370 | - $date_ancienne = $date = $row['date']; |
|
| 371 | - $champs = []; |
|
| 372 | - |
|
| 373 | - $d = ($date && isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 374 | - $s = (isset($desc['field']['statut']) && isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 375 | - |
|
| 376 | - // cf autorisations dans inc/instituer_objet |
|
| 377 | - if ($s != $statut || $d && $d != $date) { |
|
| 378 | - if ( |
|
| 379 | - $id_rubrique ? |
|
| 380 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 381 | - : |
|
| 382 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 383 | - ) { |
|
| 384 | - $statut = $champs['statut'] = $s; |
|
| 385 | - } else { |
|
| 386 | - if ($s != 'publie' && autoriser('modifier', $objet, $id)) { |
|
| 387 | - $statut = $champs['statut'] = $s; |
|
| 388 | - } else { |
|
| 389 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // En cas de publication, fixer la date a "maintenant" |
|
| 394 | - // sauf si $c commande autre chose |
|
| 395 | - // ou si l'objet est deja date dans le futur |
|
| 396 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 397 | - if ( |
|
| 398 | - $champ_date |
|
| 399 | - && ( |
|
| 400 | - $champs['statut'] == 'publie' |
|
| 401 | - || $champs['statut'] == 'prop' && !in_array($statut_ancien, ['publie', 'prop']) |
|
| 402 | - || $d |
|
| 403 | - ) |
|
| 404 | - ) { |
|
| 405 | - $date = ($d || strtotime((string) ($d = $date)) > time()) ? $d : date('Y-m-d H:i:s'); |
|
| 406 | - $champs[$champ_date] = $date; |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - // Verifier que la rubrique demandee existe et est differente |
|
| 411 | - // de la rubrique actuelle |
|
| 412 | - if ( |
|
| 413 | - $id_rubrique |
|
| 414 | - && isset($c['id_parent']) |
|
| 415 | - && ($id_parent = $c['id_parent']) |
|
| 416 | - && $id_parent != $id_rubrique |
|
| 417 | - && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 418 | - ) { |
|
| 419 | - $champs['id_rubrique'] = $id_parent; |
|
| 420 | - |
|
| 421 | - // si l'objet etait publie |
|
| 422 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 423 | - // repasser l'objet en statut 'propose'. |
|
| 424 | - if ( |
|
| 425 | - $statut == 'publie' |
|
| 426 | - && !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 427 | - ) { |
|
| 428 | - $champs['statut'] = 'prop'; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - // Envoyer aux plugins |
|
| 434 | - $champs = pipeline( |
|
| 435 | - 'pre_edition', |
|
| 436 | - [ |
|
| 437 | - 'args' => [ |
|
| 438 | - 'table' => $table_sql, |
|
| 439 | - 'id_objet' => $id, |
|
| 440 | - 'action' => 'instituer', |
|
| 441 | - 'statut_ancien' => $statut_ancien, |
|
| 442 | - 'date_ancienne' => $date_ancienne, |
|
| 443 | - 'id_parent_ancien' => $id_rubrique, |
|
| 444 | - ], |
|
| 445 | - 'data' => $champs |
|
| 446 | - ] |
|
| 447 | - ); |
|
| 448 | - |
|
| 449 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 450 | - return ''; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Envoyer les modifs. |
|
| 454 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 455 | - |
|
| 456 | - // Invalider les caches |
|
| 457 | - include_spip('inc/invalideur'); |
|
| 458 | - suivre_invalideur("id='$objet/$id'"); |
|
| 459 | - |
|
| 460 | - /* |
|
| 332 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 333 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 334 | + $objet = $t; |
|
| 335 | + } |
|
| 336 | + if ( |
|
| 337 | + include_spip('action/editer_' . $objet) && function_exists($instituer = $objet . '_instituer') |
|
| 338 | + ) { |
|
| 339 | + return $instituer($id, $c, $calcul_rub); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $table_sql = table_objet_sql($objet); |
|
| 343 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 344 | + $desc = $trouver_table($table_sql); |
|
| 345 | + if (!$desc || !isset($desc['field'])) { |
|
| 346 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + include_spip('inc/autoriser'); |
|
| 350 | + include_spip('inc/rubriques'); |
|
| 351 | + include_spip('inc/modifier'); |
|
| 352 | + |
|
| 353 | + $sel = []; |
|
| 354 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 355 | + |
|
| 356 | + $champ_date = ''; |
|
| 357 | + if (isset($desc['date']) && $desc['date']) { |
|
| 358 | + $champ_date = $desc['date']; |
|
| 359 | + } elseif (isset($desc['field']['date'])) { |
|
| 360 | + $champ_date = 'date'; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 364 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 365 | + |
|
| 366 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . (int) $id); |
|
| 367 | + |
|
| 368 | + $id_rubrique = $row['id_rubrique']; |
|
| 369 | + $statut_ancien = $statut = $row['statut']; |
|
| 370 | + $date_ancienne = $date = $row['date']; |
|
| 371 | + $champs = []; |
|
| 372 | + |
|
| 373 | + $d = ($date && isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 374 | + $s = (isset($desc['field']['statut']) && isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 375 | + |
|
| 376 | + // cf autorisations dans inc/instituer_objet |
|
| 377 | + if ($s != $statut || $d && $d != $date) { |
|
| 378 | + if ( |
|
| 379 | + $id_rubrique ? |
|
| 380 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 381 | + : |
|
| 382 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 383 | + ) { |
|
| 384 | + $statut = $champs['statut'] = $s; |
|
| 385 | + } else { |
|
| 386 | + if ($s != 'publie' && autoriser('modifier', $objet, $id)) { |
|
| 387 | + $statut = $champs['statut'] = $s; |
|
| 388 | + } else { |
|
| 389 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // En cas de publication, fixer la date a "maintenant" |
|
| 394 | + // sauf si $c commande autre chose |
|
| 395 | + // ou si l'objet est deja date dans le futur |
|
| 396 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 397 | + if ( |
|
| 398 | + $champ_date |
|
| 399 | + && ( |
|
| 400 | + $champs['statut'] == 'publie' |
|
| 401 | + || $champs['statut'] == 'prop' && !in_array($statut_ancien, ['publie', 'prop']) |
|
| 402 | + || $d |
|
| 403 | + ) |
|
| 404 | + ) { |
|
| 405 | + $date = ($d || strtotime((string) ($d = $date)) > time()) ? $d : date('Y-m-d H:i:s'); |
|
| 406 | + $champs[$champ_date] = $date; |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + // Verifier que la rubrique demandee existe et est differente |
|
| 411 | + // de la rubrique actuelle |
|
| 412 | + if ( |
|
| 413 | + $id_rubrique |
|
| 414 | + && isset($c['id_parent']) |
|
| 415 | + && ($id_parent = $c['id_parent']) |
|
| 416 | + && $id_parent != $id_rubrique |
|
| 417 | + && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 418 | + ) { |
|
| 419 | + $champs['id_rubrique'] = $id_parent; |
|
| 420 | + |
|
| 421 | + // si l'objet etait publie |
|
| 422 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 423 | + // repasser l'objet en statut 'propose'. |
|
| 424 | + if ( |
|
| 425 | + $statut == 'publie' |
|
| 426 | + && !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 427 | + ) { |
|
| 428 | + $champs['statut'] = 'prop'; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + // Envoyer aux plugins |
|
| 434 | + $champs = pipeline( |
|
| 435 | + 'pre_edition', |
|
| 436 | + [ |
|
| 437 | + 'args' => [ |
|
| 438 | + 'table' => $table_sql, |
|
| 439 | + 'id_objet' => $id, |
|
| 440 | + 'action' => 'instituer', |
|
| 441 | + 'statut_ancien' => $statut_ancien, |
|
| 442 | + 'date_ancienne' => $date_ancienne, |
|
| 443 | + 'id_parent_ancien' => $id_rubrique, |
|
| 444 | + ], |
|
| 445 | + 'data' => $champs |
|
| 446 | + ] |
|
| 447 | + ); |
|
| 448 | + |
|
| 449 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 450 | + return ''; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Envoyer les modifs. |
|
| 454 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 455 | + |
|
| 456 | + // Invalider les caches |
|
| 457 | + include_spip('inc/invalideur'); |
|
| 458 | + suivre_invalideur("id='$objet/$id'"); |
|
| 459 | + |
|
| 460 | + /* |
|
| 461 | 461 | if ($date) { |
| 462 | 462 | $t = strtotime($date); |
| 463 | 463 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -466,60 +466,60 @@ discard block |
||
| 466 | 466 | } |
| 467 | 467 | }*/ |
| 468 | 468 | |
| 469 | - // Pipeline |
|
| 470 | - pipeline( |
|
| 471 | - 'post_edition', |
|
| 472 | - [ |
|
| 473 | - 'args' => [ |
|
| 474 | - 'table' => $table_sql, |
|
| 475 | - 'id_objet' => $id, |
|
| 476 | - 'action' => 'instituer', |
|
| 477 | - 'statut_ancien' => $statut_ancien, |
|
| 478 | - 'date_ancienne' => $date_ancienne, |
|
| 479 | - 'id_parent_ancien' => $id_rubrique, |
|
| 480 | - ], |
|
| 481 | - 'data' => $champs |
|
| 482 | - ] |
|
| 483 | - ); |
|
| 484 | - |
|
| 485 | - // Notifications |
|
| 486 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 487 | - $notifications( |
|
| 488 | - "{$objet}_instituer", |
|
| 489 | - $id, |
|
| 490 | - [ |
|
| 491 | - 'statut' => $statut, |
|
| 492 | - 'statut_ancien' => $statut_ancien, |
|
| 493 | - 'date' => $date, |
|
| 494 | - 'date_ancienne' => $date_ancienne, |
|
| 495 | - 'id_parent_ancien' => $id_rubrique, |
|
| 496 | - 'champs' => $champs, |
|
| 497 | - ] |
|
| 498 | - ); |
|
| 499 | - $notifications( |
|
| 500 | - 'objet_instituer', |
|
| 501 | - $id, |
|
| 502 | - [ |
|
| 503 | - 'objet' => $objet, |
|
| 504 | - 'id_objet' => $id, |
|
| 505 | - 'statut' => $statut, |
|
| 506 | - 'statut_ancien' => $statut_ancien, |
|
| 507 | - 'date' => $date, |
|
| 508 | - 'date_ancienne' => $date_ancienne, |
|
| 509 | - 'id_parent_ancien' => $id_rubrique, |
|
| 510 | - 'champs' => $champs, |
|
| 511 | - ] |
|
| 512 | - ); |
|
| 513 | - |
|
| 514 | - // Rétro-compat |
|
| 515 | - $notifications( |
|
| 516 | - "instituer$objet", |
|
| 517 | - $id, |
|
| 518 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - return ''; // pas d'erreur |
|
| 469 | + // Pipeline |
|
| 470 | + pipeline( |
|
| 471 | + 'post_edition', |
|
| 472 | + [ |
|
| 473 | + 'args' => [ |
|
| 474 | + 'table' => $table_sql, |
|
| 475 | + 'id_objet' => $id, |
|
| 476 | + 'action' => 'instituer', |
|
| 477 | + 'statut_ancien' => $statut_ancien, |
|
| 478 | + 'date_ancienne' => $date_ancienne, |
|
| 479 | + 'id_parent_ancien' => $id_rubrique, |
|
| 480 | + ], |
|
| 481 | + 'data' => $champs |
|
| 482 | + ] |
|
| 483 | + ); |
|
| 484 | + |
|
| 485 | + // Notifications |
|
| 486 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 487 | + $notifications( |
|
| 488 | + "{$objet}_instituer", |
|
| 489 | + $id, |
|
| 490 | + [ |
|
| 491 | + 'statut' => $statut, |
|
| 492 | + 'statut_ancien' => $statut_ancien, |
|
| 493 | + 'date' => $date, |
|
| 494 | + 'date_ancienne' => $date_ancienne, |
|
| 495 | + 'id_parent_ancien' => $id_rubrique, |
|
| 496 | + 'champs' => $champs, |
|
| 497 | + ] |
|
| 498 | + ); |
|
| 499 | + $notifications( |
|
| 500 | + 'objet_instituer', |
|
| 501 | + $id, |
|
| 502 | + [ |
|
| 503 | + 'objet' => $objet, |
|
| 504 | + 'id_objet' => $id, |
|
| 505 | + 'statut' => $statut, |
|
| 506 | + 'statut_ancien' => $statut_ancien, |
|
| 507 | + 'date' => $date, |
|
| 508 | + 'date_ancienne' => $date_ancienne, |
|
| 509 | + 'id_parent_ancien' => $id_rubrique, |
|
| 510 | + 'champs' => $champs, |
|
| 511 | + ] |
|
| 512 | + ); |
|
| 513 | + |
|
| 514 | + // Rétro-compat |
|
| 515 | + $notifications( |
|
| 516 | + "instituer$objet", |
|
| 517 | + $id, |
|
| 518 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + return ''; // pas d'erreur |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
@@ -534,51 +534,51 @@ discard block |
||
| 534 | 534 | * @return void |
| 535 | 535 | */ |
| 536 | 536 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 537 | - $table_sql = table_objet_sql($objet); |
|
| 538 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 539 | - $desc = $trouver_table($table_sql); |
|
| 540 | - |
|
| 541 | - // Si on deplace l'objet |
|
| 542 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 543 | - if (isset($champs['id_rubrique'])) { |
|
| 544 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 545 | - $langue = $row_rub['lang']; |
|
| 546 | - |
|
| 547 | - if (isset($desc['field']['id_secteur'])) { |
|
| 548 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - if ( |
|
| 552 | - isset($desc['field']['lang']) |
|
| 553 | - && isset($desc['field']['langue_choisie']) |
|
| 554 | - && sql_fetsel( |
|
| 555 | - '1', |
|
| 556 | - $table_sql, |
|
| 557 | - id_table_objet($objet) . '=' . (int) $id . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 558 | - ) |
|
| 559 | - ) { |
|
| 560 | - $champs['lang'] = $langue; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - if (!$champs) { |
|
| 565 | - return; |
|
| 566 | - } |
|
| 567 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . (int) $id); |
|
| 568 | - |
|
| 569 | - // Changer le statut des rubriques concernees |
|
| 570 | - if ($cond) { |
|
| 571 | - include_spip('inc/rubriques'); |
|
| 572 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 573 | - $postdate = false; |
|
| 574 | - // On rajoute les infos de l'objet |
|
| 575 | - $infos = [ |
|
| 576 | - 'objet' => $objet, |
|
| 577 | - 'id_objet' => $id, |
|
| 578 | - 'statut_ancien' => $statut, |
|
| 579 | - ]; |
|
| 580 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 581 | - } |
|
| 537 | + $table_sql = table_objet_sql($objet); |
|
| 538 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 539 | + $desc = $trouver_table($table_sql); |
|
| 540 | + |
|
| 541 | + // Si on deplace l'objet |
|
| 542 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 543 | + if (isset($champs['id_rubrique'])) { |
|
| 544 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 545 | + $langue = $row_rub['lang']; |
|
| 546 | + |
|
| 547 | + if (isset($desc['field']['id_secteur'])) { |
|
| 548 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if ( |
|
| 552 | + isset($desc['field']['lang']) |
|
| 553 | + && isset($desc['field']['langue_choisie']) |
|
| 554 | + && sql_fetsel( |
|
| 555 | + '1', |
|
| 556 | + $table_sql, |
|
| 557 | + id_table_objet($objet) . '=' . (int) $id . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 558 | + ) |
|
| 559 | + ) { |
|
| 560 | + $champs['lang'] = $langue; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + if (!$champs) { |
|
| 565 | + return; |
|
| 566 | + } |
|
| 567 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . (int) $id); |
|
| 568 | + |
|
| 569 | + // Changer le statut des rubriques concernees |
|
| 570 | + if ($cond) { |
|
| 571 | + include_spip('inc/rubriques'); |
|
| 572 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 573 | + $postdate = false; |
|
| 574 | + // On rajoute les infos de l'objet |
|
| 575 | + $infos = [ |
|
| 576 | + 'objet' => $objet, |
|
| 577 | + 'id_objet' => $id, |
|
| 578 | + 'statut_ancien' => $statut, |
|
| 579 | + ]; |
|
| 580 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 581 | + } |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
@@ -607,71 +607,71 @@ discard block |
||
| 607 | 607 | * string|int : valeur du champ demande pour l'objet demande |
| 608 | 608 | */ |
| 609 | 609 | function objet_lire($objet, $valeur_id, $options = []) { |
| 610 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 611 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 612 | - $objet = $t; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 616 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 617 | - static $descriptions = []; |
|
| 618 | - |
|
| 619 | - // On détermine le nom du champ id de la table. |
|
| 620 | - include_spip('base/objets'); |
|
| 621 | - $primary = id_table_objet($objet); |
|
| 622 | - |
|
| 623 | - // On détermine l'id à utiliser. |
|
| 624 | - $champ_id = (empty($options['champ_id']) ? $primary : $options['champ_id']); |
|
| 625 | - |
|
| 626 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 627 | - if ( |
|
| 628 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 629 | - || isset($options['force']) && $options['force'] |
|
| 630 | - ) { |
|
| 631 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 632 | - if ( |
|
| 633 | - include_spip('action/editer_' . $objet) |
|
| 634 | - && function_exists($lire = "{$objet}_lire_champs") |
|
| 635 | - ) { |
|
| 636 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 637 | - } else { |
|
| 638 | - // On récupère la table SQL à partir du type d'objet. |
|
| 639 | - $table = table_objet_sql($objet); |
|
| 640 | - |
|
| 641 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 642 | - $where = [ |
|
| 643 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 644 | - ]; |
|
| 645 | - |
|
| 646 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 647 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - if (!$valeurs) { |
|
| 651 | - $valeurs = false; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 655 | - |
|
| 656 | - if ($champ_id !== $primary && isset($valeurs[$primary])) { |
|
| 657 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 658 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 663 | - |
|
| 664 | - // On ne retourne maintenant que les champs demandés. |
|
| 665 | - // - on détermine les informations à renvoyer. |
|
| 666 | - if ($retour && !empty($options['champs'])) { |
|
| 667 | - $champs = $options['champs']; |
|
| 668 | - // Extraction des seules informations demandées. |
|
| 669 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 670 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 671 | - $retour = is_array($champs) |
|
| 672 | - ? array_intersect_key($retour, array_flip($champs)) |
|
| 673 | - : $retour[$champs] ?? false; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - return $retour; |
|
| 610 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 611 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 612 | + $objet = $t; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 616 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 617 | + static $descriptions = []; |
|
| 618 | + |
|
| 619 | + // On détermine le nom du champ id de la table. |
|
| 620 | + include_spip('base/objets'); |
|
| 621 | + $primary = id_table_objet($objet); |
|
| 622 | + |
|
| 623 | + // On détermine l'id à utiliser. |
|
| 624 | + $champ_id = (empty($options['champ_id']) ? $primary : $options['champ_id']); |
|
| 625 | + |
|
| 626 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 627 | + if ( |
|
| 628 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 629 | + || isset($options['force']) && $options['force'] |
|
| 630 | + ) { |
|
| 631 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 632 | + if ( |
|
| 633 | + include_spip('action/editer_' . $objet) |
|
| 634 | + && function_exists($lire = "{$objet}_lire_champs") |
|
| 635 | + ) { |
|
| 636 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 637 | + } else { |
|
| 638 | + // On récupère la table SQL à partir du type d'objet. |
|
| 639 | + $table = table_objet_sql($objet); |
|
| 640 | + |
|
| 641 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 642 | + $where = [ |
|
| 643 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 644 | + ]; |
|
| 645 | + |
|
| 646 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 647 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + if (!$valeurs) { |
|
| 651 | + $valeurs = false; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 655 | + |
|
| 656 | + if ($champ_id !== $primary && isset($valeurs[$primary])) { |
|
| 657 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 658 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 663 | + |
|
| 664 | + // On ne retourne maintenant que les champs demandés. |
|
| 665 | + // - on détermine les informations à renvoyer. |
|
| 666 | + if ($retour && !empty($options['champs'])) { |
|
| 667 | + $champs = $options['champs']; |
|
| 668 | + // Extraction des seules informations demandées. |
|
| 669 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 670 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 671 | + $retour = is_array($champs) |
|
| 672 | + ? array_intersect_key($retour, array_flip($champs)) |
|
| 673 | + : $retour[$champs] ?? false; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + return $retour; |
|
| 677 | 677 | } |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function objet_modifier($objet, $id, $set = null) { |
| 77 | 77 | if (($t = objet_type($objet)) !== $objet) { |
| 78 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 78 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 79 | 79 | $objet = $t; |
| 80 | 80 | } |
| 81 | 81 | if ( |
| 82 | - include_spip('action/editer_' . $objet) && function_exists($modifier = $objet . '_modifier') |
|
| 82 | + include_spip('action/editer_'.$objet) && function_exists($modifier = $objet.'_modifier') |
|
| 83 | 83 | ) { |
| 84 | 84 | return $modifier($id, $set); |
| 85 | 85 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 89 | 89 | $desc = $trouver_table($table_sql); |
| 90 | 90 | if (!$desc || !isset($desc['field'])) { |
| 91 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 91 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer'._LOG_ERREUR); |
|
| 92 | 92 | |
| 93 | 93 | return _L("Erreur objet $objet inconnu"); |
| 94 | 94 | } |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 168 | 168 | $d = null; |
| 169 | 169 | if (($t = objet_type($objet)) !== $objet) { |
| 170 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 170 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 171 | 171 | $objet = $t; |
| 172 | 172 | } |
| 173 | 173 | if ( |
| 174 | - include_spip('action/editer_' . $objet) |
|
| 175 | - && function_exists($inserer = $objet . '_inserer') |
|
| 174 | + include_spip('action/editer_'.$objet) |
|
| 175 | + && function_exists($inserer = $objet.'_inserer') |
|
| 176 | 176 | ) { |
| 177 | 177 | return $inserer($id_parent, $set); |
| 178 | 178 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
| 194 | 194 | $id_rubrique = $row['id_rubrique']; |
| 195 | 195 | } else { |
| 196 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 196 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $champs['id_rubrique'] = $id_rubrique; |
@@ -330,11 +330,11 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 332 | 332 | if (($t = objet_type($objet)) !== $objet) { |
| 333 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 333 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 334 | 334 | $objet = $t; |
| 335 | 335 | } |
| 336 | 336 | if ( |
| 337 | - include_spip('action/editer_' . $objet) && function_exists($instituer = $objet . '_instituer') |
|
| 337 | + include_spip('action/editer_'.$objet) && function_exists($instituer = $objet.'_instituer') |
|
| 338 | 338 | ) { |
| 339 | 339 | return $instituer($id, $c, $calcul_rub); |
| 340 | 340 | } |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
| 364 | 364 | $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
| 365 | 365 | |
| 366 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . (int) $id); |
|
| 366 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.(int) $id); |
|
| 367 | 367 | |
| 368 | 368 | $id_rubrique = $row['id_rubrique']; |
| 369 | 369 | $statut_ancien = $statut = $row['statut']; |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | if ($s != 'publie' && autoriser('modifier', $objet, $id)) { |
| 387 | 387 | $statut = $champs['statut'] = $s; |
| 388 | 388 | } else { |
| 389 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 389 | + spip_log("editer_objet $objet #$id refus ".json_encode($c, JSON_THROW_ON_ERROR), 'editer'._LOG_INFO_IMPORTANTE); |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | && isset($c['id_parent']) |
| 415 | 415 | && ($id_parent = $c['id_parent']) |
| 416 | 416 | && $id_parent != $id_rubrique |
| 417 | - && sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . (int) $id_parent) |
|
| 417 | + && sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.(int) $id_parent) |
|
| 418 | 418 | ) { |
| 419 | 419 | $champs['id_rubrique'] = $id_parent; |
| 420 | 420 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | // Si on deplace l'objet |
| 542 | 542 | // changer aussi son secteur et sa langue (si heritee) |
| 543 | 543 | if (isset($champs['id_rubrique'])) { |
| 544 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 544 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 545 | 545 | $langue = $row_rub['lang']; |
| 546 | 546 | |
| 547 | 547 | if (isset($desc['field']['id_secteur'])) { |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | && sql_fetsel( |
| 555 | 555 | '1', |
| 556 | 556 | $table_sql, |
| 557 | - id_table_objet($objet) . '=' . (int) $id . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 557 | + id_table_objet($objet).'='.(int) $id." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 558 | 558 | ) |
| 559 | 559 | ) { |
| 560 | 560 | $champs['lang'] = $langue; |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | if (!$champs) { |
| 565 | 565 | return; |
| 566 | 566 | } |
| 567 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . (int) $id); |
|
| 567 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.(int) $id); |
|
| 568 | 568 | |
| 569 | 569 | // Changer le statut des rubriques concernees |
| 570 | 570 | if ($cond) { |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | */ |
| 609 | 609 | function objet_lire($objet, $valeur_id, $options = []) { |
| 610 | 610 | if (($t = objet_type($objet)) !== $objet) { |
| 611 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 611 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 612 | 612 | $objet = $t; |
| 613 | 613 | } |
| 614 | 614 | |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | ) { |
| 631 | 631 | // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
| 632 | 632 | if ( |
| 633 | - include_spip('action/editer_' . $objet) |
|
| 633 | + include_spip('action/editer_'.$objet) |
|
| 634 | 634 | && function_exists($lire = "{$objet}_lire_champs") |
| 635 | 635 | ) { |
| 636 | 636 | $valeurs = $lire($objet, $valeur_id, $champ_id); |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | |
| 641 | 641 | // La condition est appliquée sur le champ désigné par l'utilisateur. |
| 642 | 642 | $where = [ |
| 643 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 643 | + $champ_id.'='.sql_quote($valeur_id) |
|
| 644 | 644 | ]; |
| 645 | 645 | |
| 646 | 646 | // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |