@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - list($objet, $id) = array_pad(explode("/", $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return array($id, _L('echec enregistrement en base')); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return array($id, $err); |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + list($objet, $id) = array_pad(explode("/", $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return array($id, _L('echec enregistrement en base')); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return array($id, $err); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,80 +75,80 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if (include_spip('action/editer_' . $objet) |
|
| 83 | - and function_exists($modifier = $objet . "_modifier") |
|
| 84 | - ) { |
|
| 85 | - return $modifier($id, $set); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $table_sql = table_objet_sql($objet); |
|
| 89 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 90 | - $desc = $trouver_table($table_sql); |
|
| 91 | - if (!$desc or !isset($desc['field'])) { |
|
| 92 | - spip_log("Objet $objet inconnu dans objet_modifier", "editer" . _LOG_ERREUR); |
|
| 93 | - |
|
| 94 | - return _L("Erreur objet $objet inconnu"); |
|
| 95 | - } |
|
| 96 | - include_spip('inc/modifier'); |
|
| 97 | - |
|
| 98 | - $champ_date = ''; |
|
| 99 | - if (isset($desc['date']) and $desc['date']) { |
|
| 100 | - $champ_date = $desc['date']; |
|
| 101 | - } elseif (isset($desc['field']['date'])) { |
|
| 102 | - $champ_date = 'date'; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $white = array_keys($desc['field']); |
|
| 106 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 107 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 108 | - $white = array_diff($white, array($desc['key']['PRIMARY KEY'])); |
|
| 109 | - |
|
| 110 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 111 | - $white = $desc['champs_editables']; |
|
| 112 | - } |
|
| 113 | - $c = collecter_requests( |
|
| 114 | - // white list |
|
| 115 | - $white, |
|
| 116 | - // black list |
|
| 117 | - array($champ_date, 'statut', 'id_parent', 'id_secteur'), |
|
| 118 | - // donnees eventuellement fournies |
|
| 119 | - $set |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 123 | - if (objet_test_si_publie($objet, $id)) { |
|
| 124 | - $invalideur = "id='$objet/$id'"; |
|
| 125 | - $indexation = true; |
|
| 126 | - } else { |
|
| 127 | - $invalideur = ""; |
|
| 128 | - $indexation = false; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if ($err = objet_modifier_champs($objet, $id, |
|
| 132 | - array( |
|
| 133 | - 'data' => $set, |
|
| 134 | - 'nonvide' => '', |
|
| 135 | - 'invalideur' => $invalideur, |
|
| 136 | - 'indexation' => $indexation, |
|
| 137 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 138 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 139 | - ), |
|
| 140 | - $c) |
|
| 141 | - ) { |
|
| 142 | - return $err; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // Modification de statut, changement de rubrique ? |
|
| 146 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 147 | - // le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. |
|
| 148 | - $c = collecter_requests(array($champ_date, 'statut', 'id_parent'), array(), $set); |
|
| 149 | - $err = objet_instituer($objet, $id, $c); |
|
| 150 | - |
|
| 151 | - return $err; |
|
| 78 | + if (($t=objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if (include_spip('action/editer_' . $objet) |
|
| 83 | + and function_exists($modifier = $objet . "_modifier") |
|
| 84 | + ) { |
|
| 85 | + return $modifier($id, $set); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $table_sql = table_objet_sql($objet); |
|
| 89 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 90 | + $desc = $trouver_table($table_sql); |
|
| 91 | + if (!$desc or !isset($desc['field'])) { |
|
| 92 | + spip_log("Objet $objet inconnu dans objet_modifier", "editer" . _LOG_ERREUR); |
|
| 93 | + |
|
| 94 | + return _L("Erreur objet $objet inconnu"); |
|
| 95 | + } |
|
| 96 | + include_spip('inc/modifier'); |
|
| 97 | + |
|
| 98 | + $champ_date = ''; |
|
| 99 | + if (isset($desc['date']) and $desc['date']) { |
|
| 100 | + $champ_date = $desc['date']; |
|
| 101 | + } elseif (isset($desc['field']['date'])) { |
|
| 102 | + $champ_date = 'date'; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $white = array_keys($desc['field']); |
|
| 106 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 107 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 108 | + $white = array_diff($white, array($desc['key']['PRIMARY KEY'])); |
|
| 109 | + |
|
| 110 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 111 | + $white = $desc['champs_editables']; |
|
| 112 | + } |
|
| 113 | + $c = collecter_requests( |
|
| 114 | + // white list |
|
| 115 | + $white, |
|
| 116 | + // black list |
|
| 117 | + array($champ_date, 'statut', 'id_parent', 'id_secteur'), |
|
| 118 | + // donnees eventuellement fournies |
|
| 119 | + $set |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 123 | + if (objet_test_si_publie($objet, $id)) { |
|
| 124 | + $invalideur = "id='$objet/$id'"; |
|
| 125 | + $indexation = true; |
|
| 126 | + } else { |
|
| 127 | + $invalideur = ""; |
|
| 128 | + $indexation = false; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if ($err = objet_modifier_champs($objet, $id, |
|
| 132 | + array( |
|
| 133 | + 'data' => $set, |
|
| 134 | + 'nonvide' => '', |
|
| 135 | + 'invalideur' => $invalideur, |
|
| 136 | + 'indexation' => $indexation, |
|
| 137 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 138 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 139 | + ), |
|
| 140 | + $c) |
|
| 141 | + ) { |
|
| 142 | + return $err; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // Modification de statut, changement de rubrique ? |
|
| 146 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 147 | + // le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. |
|
| 148 | + $c = collecter_requests(array($champ_date, 'statut', 'id_parent'), array(), $set); |
|
| 149 | + $err = objet_instituer($objet, $id, $c); |
|
| 150 | + |
|
| 151 | + return $err; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -163,124 +163,124 @@ discard block |
||
| 163 | 163 | * @return bool|int |
| 164 | 164 | */ |
| 165 | 165 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 166 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 167 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 168 | - $objet = $t; |
|
| 169 | - } |
|
| 170 | - if (include_spip('action/editer_' . $objet) |
|
| 171 | - and function_exists($inserer = $objet . "_inserer") |
|
| 172 | - ) { |
|
| 173 | - return $inserer($id_parent, $set); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $table_sql = table_objet_sql($objet); |
|
| 177 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 178 | - $desc = $trouver_table($table_sql); |
|
| 179 | - if (!$desc or !isset($desc['field'])) { |
|
| 180 | - return 0; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $lang_rub = ""; |
|
| 184 | - $champs = array(); |
|
| 185 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 186 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 187 | - // dans la premiere rubrique racine |
|
| 188 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 189 | - $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1"); |
|
| 190 | - $id_rubrique = $row['id_rubrique']; |
|
| 191 | - } else { |
|
| 192 | - $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique)); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 196 | - if (isset($desc['field']['id_secteur'])) { |
|
| 197 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 198 | - } |
|
| 199 | - $lang_rub = $row['lang']; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 203 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 204 | - // ou a defaut celle de la rubrique |
|
| 205 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 206 | - if (isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array($table_sql, |
|
| 207 | - explode(',', $GLOBALS['meta']['multi_objets'])) |
|
| 208 | - ) { |
|
| 209 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 210 | - if (in_array($GLOBALS['spip_lang'], |
|
| 211 | - explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 212 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 213 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 214 | - $champs['langue_choisie'] = 'oui'; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 218 | - $champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']); |
|
| 219 | - $champs['langue_choisie'] = 'non'; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (isset($desc['field']['statut'])) { |
|
| 223 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 224 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 225 | - $champs['statut'] = reset($cles_statut); |
|
| 226 | - } else { |
|
| 227 | - $champs['statut'] = 'prepa'; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 233 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if ($set) { |
|
| 237 | - $champs = array_merge($champs, $set); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Envoyer aux plugins |
|
| 241 | - $champs = pipeline('pre_insertion', |
|
| 242 | - array( |
|
| 243 | - 'args' => array( |
|
| 244 | - 'table' => $table_sql, |
|
| 245 | - 'id_parent' => $id_parent, |
|
| 246 | - ), |
|
| 247 | - 'data' => $champs |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - |
|
| 251 | - $id = sql_insertq($table_sql, $champs); |
|
| 252 | - |
|
| 253 | - if ($id) { |
|
| 254 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 255 | - // et associer l'auteur sinon |
|
| 256 | - // si la table n'a pas deja un champ id_auteur |
|
| 257 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 258 | - if ($id > 0 |
|
| 259 | - and !isset($desc['field']['id_auteur']) |
|
| 260 | - ) { |
|
| 261 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 262 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 263 | - : _request('id_auteur')); |
|
| 264 | - if ($id_auteur) { |
|
| 265 | - include_spip('action/editer_auteur'); |
|
| 266 | - auteur_associer($id_auteur, array($objet => $id)); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - pipeline('post_insertion', |
|
| 271 | - array( |
|
| 272 | - 'args' => array( |
|
| 273 | - 'table' => $table_sql, |
|
| 274 | - 'id_parent' => $id_parent, |
|
| 275 | - 'id_objet' => $id, |
|
| 276 | - ), |
|
| 277 | - 'data' => $champs |
|
| 278 | - ) |
|
| 279 | - ); |
|
| 280 | - |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - return $id; |
|
| 166 | + if (($t=objet_type($objet)) !== $objet) { |
|
| 167 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 168 | + $objet = $t; |
|
| 169 | + } |
|
| 170 | + if (include_spip('action/editer_' . $objet) |
|
| 171 | + and function_exists($inserer = $objet . "_inserer") |
|
| 172 | + ) { |
|
| 173 | + return $inserer($id_parent, $set); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $table_sql = table_objet_sql($objet); |
|
| 177 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 178 | + $desc = $trouver_table($table_sql); |
|
| 179 | + if (!$desc or !isset($desc['field'])) { |
|
| 180 | + return 0; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $lang_rub = ""; |
|
| 184 | + $champs = array(); |
|
| 185 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 186 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 187 | + // dans la premiere rubrique racine |
|
| 188 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 189 | + $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1"); |
|
| 190 | + $id_rubrique = $row['id_rubrique']; |
|
| 191 | + } else { |
|
| 192 | + $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique)); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 196 | + if (isset($desc['field']['id_secteur'])) { |
|
| 197 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 198 | + } |
|
| 199 | + $lang_rub = $row['lang']; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 203 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 204 | + // ou a defaut celle de la rubrique |
|
| 205 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 206 | + if (isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array($table_sql, |
|
| 207 | + explode(',', $GLOBALS['meta']['multi_objets'])) |
|
| 208 | + ) { |
|
| 209 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 210 | + if (in_array($GLOBALS['spip_lang'], |
|
| 211 | + explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 212 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 213 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 214 | + $champs['langue_choisie'] = 'oui'; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 218 | + $champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']); |
|
| 219 | + $champs['langue_choisie'] = 'non'; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (isset($desc['field']['statut'])) { |
|
| 223 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 224 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 225 | + $champs['statut'] = reset($cles_statut); |
|
| 226 | + } else { |
|
| 227 | + $champs['statut'] = 'prepa'; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 233 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if ($set) { |
|
| 237 | + $champs = array_merge($champs, $set); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // Envoyer aux plugins |
|
| 241 | + $champs = pipeline('pre_insertion', |
|
| 242 | + array( |
|
| 243 | + 'args' => array( |
|
| 244 | + 'table' => $table_sql, |
|
| 245 | + 'id_parent' => $id_parent, |
|
| 246 | + ), |
|
| 247 | + 'data' => $champs |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + |
|
| 251 | + $id = sql_insertq($table_sql, $champs); |
|
| 252 | + |
|
| 253 | + if ($id) { |
|
| 254 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 255 | + // et associer l'auteur sinon |
|
| 256 | + // si la table n'a pas deja un champ id_auteur |
|
| 257 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 258 | + if ($id > 0 |
|
| 259 | + and !isset($desc['field']['id_auteur']) |
|
| 260 | + ) { |
|
| 261 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 262 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 263 | + : _request('id_auteur')); |
|
| 264 | + if ($id_auteur) { |
|
| 265 | + include_spip('action/editer_auteur'); |
|
| 266 | + auteur_associer($id_auteur, array($objet => $id)); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + pipeline('post_insertion', |
|
| 271 | + array( |
|
| 272 | + 'args' => array( |
|
| 273 | + 'table' => $table_sql, |
|
| 274 | + 'id_parent' => $id_parent, |
|
| 275 | + 'id_objet' => $id, |
|
| 276 | + ), |
|
| 277 | + 'data' => $champs |
|
| 278 | + ) |
|
| 279 | + ); |
|
| 280 | + |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + return $id; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -297,132 +297,132 @@ discard block |
||
| 297 | 297 | * @return string |
| 298 | 298 | */ |
| 299 | 299 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 300 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 301 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 302 | - $objet = $t; |
|
| 303 | - } |
|
| 304 | - if (include_spip('action/editer_' . $objet) |
|
| 305 | - and function_exists($instituer = $objet . "_instituer") |
|
| 306 | - ) { |
|
| 307 | - return $instituer($id, $c, $calcul_rub); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $table_sql = table_objet_sql($objet); |
|
| 311 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 312 | - $desc = $trouver_table($table_sql); |
|
| 313 | - if (!$desc or !isset($desc['field'])) { |
|
| 314 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - include_spip('inc/autoriser'); |
|
| 318 | - include_spip('inc/rubriques'); |
|
| 319 | - include_spip('inc/modifier'); |
|
| 320 | - |
|
| 321 | - $sel = array(); |
|
| 322 | - $sel[] = (isset($desc['field']['statut']) ? "statut" : "'' as statut"); |
|
| 323 | - |
|
| 324 | - $champ_date = ''; |
|
| 325 | - if (isset($desc['date']) and $desc['date']) { |
|
| 326 | - $champ_date = $desc['date']; |
|
| 327 | - } elseif (isset($desc['field']['date'])) { |
|
| 328 | - $champ_date = 'date'; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 332 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique"); |
|
| 333 | - |
|
| 334 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 335 | - |
|
| 336 | - $id_rubrique = $row['id_rubrique']; |
|
| 337 | - $statut_ancien = $statut = $row['statut']; |
|
| 338 | - $date_ancienne = $date = $row['date']; |
|
| 339 | - $champs = array(); |
|
| 340 | - |
|
| 341 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 342 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 343 | - |
|
| 344 | - // cf autorisations dans inc/instituer_objet |
|
| 345 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 346 | - if ($id_rubrique ? |
|
| 347 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 348 | - : |
|
| 349 | - autoriser('instituer', $objet, $id, null, array('statut' => $s)) |
|
| 350 | - ) { |
|
| 351 | - $statut = $champs['statut'] = $s; |
|
| 352 | - } else { |
|
| 353 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 354 | - $statut = $champs['statut'] = $s; |
|
| 355 | - } else { |
|
| 356 | - spip_log("editer_objet $objet #$id refus " . json_encode($c), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // En cas de publication, fixer la date a "maintenant" |
|
| 361 | - // sauf si $c commande autre chose |
|
| 362 | - // ou si l'objet est deja date dans le futur |
|
| 363 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 364 | - if ($champ_date) { |
|
| 365 | - if ($champs['statut'] == 'publie' |
|
| 366 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, array('publie', 'prop'))) |
|
| 367 | - or $d |
|
| 368 | - ) { |
|
| 369 | - if ($d or strtotime($d = $date) > time()) { |
|
| 370 | - $champs[$champ_date] = $date = $d; |
|
| 371 | - } else { |
|
| 372 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Verifier que la rubrique demandee existe et est differente |
|
| 379 | - // de la rubrique actuelle |
|
| 380 | - if ($id_rubrique |
|
| 381 | - and isset($c['id_parent']) |
|
| 382 | - and $id_parent = $c['id_parent'] |
|
| 383 | - and $id_parent != $id_rubrique |
|
| 384 | - and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 385 | - ) { |
|
| 386 | - $champs['id_rubrique'] = $id_parent; |
|
| 387 | - |
|
| 388 | - // si l'objet etait publie |
|
| 389 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 390 | - // repasser l'objet en statut 'propose'. |
|
| 391 | - if ($statut == 'publie' |
|
| 392 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 393 | - ) { |
|
| 394 | - $champs['statut'] = 'prop'; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - // Envoyer aux plugins |
|
| 400 | - $champs = pipeline('pre_edition', |
|
| 401 | - array( |
|
| 402 | - 'args' => array( |
|
| 403 | - 'table' => $table_sql, |
|
| 404 | - 'id_objet' => $id, |
|
| 405 | - 'action' => 'instituer', |
|
| 406 | - 'statut_ancien' => $statut_ancien, |
|
| 407 | - 'date_ancienne' => $date_ancienne, |
|
| 408 | - 'id_parent_ancien' => $id_rubrique, |
|
| 409 | - ), |
|
| 410 | - 'data' => $champs |
|
| 411 | - ) |
|
| 412 | - ); |
|
| 413 | - |
|
| 414 | - if (!count($champs)) { |
|
| 415 | - return ''; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Envoyer les modifs. |
|
| 419 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 420 | - |
|
| 421 | - // Invalider les caches |
|
| 422 | - include_spip('inc/invalideur'); |
|
| 423 | - suivre_invalideur("id='$objet/$id'"); |
|
| 424 | - |
|
| 425 | - /* |
|
| 300 | + if (($t=objet_type($objet)) !== $objet) { |
|
| 301 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 302 | + $objet = $t; |
|
| 303 | + } |
|
| 304 | + if (include_spip('action/editer_' . $objet) |
|
| 305 | + and function_exists($instituer = $objet . "_instituer") |
|
| 306 | + ) { |
|
| 307 | + return $instituer($id, $c, $calcul_rub); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $table_sql = table_objet_sql($objet); |
|
| 311 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 312 | + $desc = $trouver_table($table_sql); |
|
| 313 | + if (!$desc or !isset($desc['field'])) { |
|
| 314 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + include_spip('inc/autoriser'); |
|
| 318 | + include_spip('inc/rubriques'); |
|
| 319 | + include_spip('inc/modifier'); |
|
| 320 | + |
|
| 321 | + $sel = array(); |
|
| 322 | + $sel[] = (isset($desc['field']['statut']) ? "statut" : "'' as statut"); |
|
| 323 | + |
|
| 324 | + $champ_date = ''; |
|
| 325 | + if (isset($desc['date']) and $desc['date']) { |
|
| 326 | + $champ_date = $desc['date']; |
|
| 327 | + } elseif (isset($desc['field']['date'])) { |
|
| 328 | + $champ_date = 'date'; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 332 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique"); |
|
| 333 | + |
|
| 334 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 335 | + |
|
| 336 | + $id_rubrique = $row['id_rubrique']; |
|
| 337 | + $statut_ancien = $statut = $row['statut']; |
|
| 338 | + $date_ancienne = $date = $row['date']; |
|
| 339 | + $champs = array(); |
|
| 340 | + |
|
| 341 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 342 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 343 | + |
|
| 344 | + // cf autorisations dans inc/instituer_objet |
|
| 345 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 346 | + if ($id_rubrique ? |
|
| 347 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 348 | + : |
|
| 349 | + autoriser('instituer', $objet, $id, null, array('statut' => $s)) |
|
| 350 | + ) { |
|
| 351 | + $statut = $champs['statut'] = $s; |
|
| 352 | + } else { |
|
| 353 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 354 | + $statut = $champs['statut'] = $s; |
|
| 355 | + } else { |
|
| 356 | + spip_log("editer_objet $objet #$id refus " . json_encode($c), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // En cas de publication, fixer la date a "maintenant" |
|
| 361 | + // sauf si $c commande autre chose |
|
| 362 | + // ou si l'objet est deja date dans le futur |
|
| 363 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 364 | + if ($champ_date) { |
|
| 365 | + if ($champs['statut'] == 'publie' |
|
| 366 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, array('publie', 'prop'))) |
|
| 367 | + or $d |
|
| 368 | + ) { |
|
| 369 | + if ($d or strtotime($d = $date) > time()) { |
|
| 370 | + $champs[$champ_date] = $date = $d; |
|
| 371 | + } else { |
|
| 372 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Verifier que la rubrique demandee existe et est differente |
|
| 379 | + // de la rubrique actuelle |
|
| 380 | + if ($id_rubrique |
|
| 381 | + and isset($c['id_parent']) |
|
| 382 | + and $id_parent = $c['id_parent'] |
|
| 383 | + and $id_parent != $id_rubrique |
|
| 384 | + and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 385 | + ) { |
|
| 386 | + $champs['id_rubrique'] = $id_parent; |
|
| 387 | + |
|
| 388 | + // si l'objet etait publie |
|
| 389 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 390 | + // repasser l'objet en statut 'propose'. |
|
| 391 | + if ($statut == 'publie' |
|
| 392 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 393 | + ) { |
|
| 394 | + $champs['statut'] = 'prop'; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + // Envoyer aux plugins |
|
| 400 | + $champs = pipeline('pre_edition', |
|
| 401 | + array( |
|
| 402 | + 'args' => array( |
|
| 403 | + 'table' => $table_sql, |
|
| 404 | + 'id_objet' => $id, |
|
| 405 | + 'action' => 'instituer', |
|
| 406 | + 'statut_ancien' => $statut_ancien, |
|
| 407 | + 'date_ancienne' => $date_ancienne, |
|
| 408 | + 'id_parent_ancien' => $id_rubrique, |
|
| 409 | + ), |
|
| 410 | + 'data' => $champs |
|
| 411 | + ) |
|
| 412 | + ); |
|
| 413 | + |
|
| 414 | + if (!count($champs)) { |
|
| 415 | + return ''; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Envoyer les modifs. |
|
| 419 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 420 | + |
|
| 421 | + // Invalider les caches |
|
| 422 | + include_spip('inc/invalideur'); |
|
| 423 | + suivre_invalideur("id='$objet/$id'"); |
|
| 424 | + |
|
| 425 | + /* |
|
| 426 | 426 | if ($date) { |
| 427 | 427 | $t = strtotime($date); |
| 428 | 428 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -431,29 +431,29 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | }*/ |
| 433 | 433 | |
| 434 | - // Pipeline |
|
| 435 | - pipeline('post_edition', |
|
| 436 | - array( |
|
| 437 | - 'args' => array( |
|
| 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 | - // Notifications |
|
| 450 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 451 | - $notifications("instituer$objet", $id, |
|
| 452 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne) |
|
| 453 | - ); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return ''; // pas d'erreur |
|
| 434 | + // Pipeline |
|
| 435 | + pipeline('post_edition', |
|
| 436 | + array( |
|
| 437 | + 'args' => array( |
|
| 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 | + // Notifications |
|
| 450 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 451 | + $notifications("instituer$objet", $id, |
|
| 452 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne) |
|
| 453 | + ); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return ''; // pas d'erreur |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -468,47 +468,47 @@ discard block |
||
| 468 | 468 | * @return void |
| 469 | 469 | */ |
| 470 | 470 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 471 | - $table_sql = table_objet_sql($objet); |
|
| 472 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 473 | - $desc = $trouver_table($table_sql); |
|
| 474 | - |
|
| 475 | - // Si on deplace l'objet |
|
| 476 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 477 | - if (isset($champs['id_rubrique'])) { |
|
| 478 | - |
|
| 479 | - $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 480 | - $langue = $row_rub['lang']; |
|
| 481 | - |
|
| 482 | - if (isset($desc['field']['id_secteur'])) { |
|
| 483 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 487 | - if (sql_fetsel('1', $table_sql, |
|
| 488 | - id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 489 | - $champs['lang'] = $langue; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - if (!$champs) { |
|
| 495 | - return; |
|
| 496 | - } |
|
| 497 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 498 | - |
|
| 499 | - // Changer le statut des rubriques concernees |
|
| 500 | - if ($cond) { |
|
| 501 | - include_spip('inc/rubriques'); |
|
| 502 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 503 | - $postdate = false; |
|
| 504 | - // On rajoute les infos de l'objet |
|
| 505 | - $infos = array( |
|
| 506 | - 'objet' => $objet, |
|
| 507 | - 'id_objet' => $id, |
|
| 508 | - 'statut_ancien' => $statut, |
|
| 509 | - ); |
|
| 510 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 511 | - } |
|
| 471 | + $table_sql = table_objet_sql($objet); |
|
| 472 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 473 | + $desc = $trouver_table($table_sql); |
|
| 474 | + |
|
| 475 | + // Si on deplace l'objet |
|
| 476 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 477 | + if (isset($champs['id_rubrique'])) { |
|
| 478 | + |
|
| 479 | + $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 480 | + $langue = $row_rub['lang']; |
|
| 481 | + |
|
| 482 | + if (isset($desc['field']['id_secteur'])) { |
|
| 483 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 487 | + if (sql_fetsel('1', $table_sql, |
|
| 488 | + id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 489 | + $champs['lang'] = $langue; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + if (!$champs) { |
|
| 495 | + return; |
|
| 496 | + } |
|
| 497 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 498 | + |
|
| 499 | + // Changer le statut des rubriques concernees |
|
| 500 | + if ($cond) { |
|
| 501 | + include_spip('inc/rubriques'); |
|
| 502 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 503 | + $postdate = false; |
|
| 504 | + // On rajoute les infos de l'objet |
|
| 505 | + $infos = array( |
|
| 506 | + 'objet' => $objet, |
|
| 507 | + 'id_objet' => $id, |
|
| 508 | + 'statut_ancien' => $statut, |
|
| 509 | + ); |
|
| 510 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 511 | + } |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | |
@@ -537,73 +537,73 @@ discard block |
||
| 537 | 537 | * string|int : valeur du champ demande pour l'objet demande |
| 538 | 538 | */ |
| 539 | 539 | function objet_lire($objet, $valeur_id, $options = array()) { |
| 540 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 541 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 542 | - $objet = $t; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 546 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 547 | - static $descriptions = array(); |
|
| 548 | - |
|
| 549 | - // On détermine le nom du champ id de la table. |
|
| 550 | - include_spip('base/objets'); |
|
| 551 | - $primary = id_table_objet($objet); |
|
| 552 | - |
|
| 553 | - // On détermine l'id à utiliser. |
|
| 554 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 555 | - |
|
| 556 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 557 | - if (!isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 558 | - or (isset($options['force']) and $options['force'])) { |
|
| 559 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 560 | - if ( |
|
| 561 | - include_spip('action/editer_' . $objet) |
|
| 562 | - and function_exists($lire = "${objet}_lire_champs") |
|
| 563 | - ) { |
|
| 564 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 565 | - } else { |
|
| 566 | - // On récupère la table SQL à partir du type d'objet. |
|
| 567 | - $table = table_objet_sql($objet); |
|
| 568 | - |
|
| 569 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 570 | - $where = array( |
|
| 571 | - "${champ_id}=" . sql_quote($valeur_id) |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 575 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if (!$valeurs) { |
|
| 579 | - $valeurs = false; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 583 | - |
|
| 584 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 585 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 586 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 591 | - |
|
| 592 | - // On ne retourne maintenant que les champs demandés. |
|
| 593 | - // - on détermine les informations à renvoyer. |
|
| 594 | - if ($retour and !empty($options['champs'])) { |
|
| 595 | - $champs = $options['champs']; |
|
| 596 | - // Extraction des seules informations demandées. |
|
| 597 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 598 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 599 | - if (is_array($champs)) { |
|
| 600 | - // Tableau des informations valides |
|
| 601 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 602 | - } else { |
|
| 603 | - // Valeur unique demandée. |
|
| 604 | - $retour = (isset($retour[$champs]) ? $retour[$champs] : false); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $retour; |
|
| 540 | + if (($t=objet_type($objet)) !== $objet) { |
|
| 541 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 542 | + $objet = $t; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 546 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 547 | + static $descriptions = array(); |
|
| 548 | + |
|
| 549 | + // On détermine le nom du champ id de la table. |
|
| 550 | + include_spip('base/objets'); |
|
| 551 | + $primary = id_table_objet($objet); |
|
| 552 | + |
|
| 553 | + // On détermine l'id à utiliser. |
|
| 554 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 555 | + |
|
| 556 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 557 | + if (!isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 558 | + or (isset($options['force']) and $options['force'])) { |
|
| 559 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 560 | + if ( |
|
| 561 | + include_spip('action/editer_' . $objet) |
|
| 562 | + and function_exists($lire = "${objet}_lire_champs") |
|
| 563 | + ) { |
|
| 564 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 565 | + } else { |
|
| 566 | + // On récupère la table SQL à partir du type d'objet. |
|
| 567 | + $table = table_objet_sql($objet); |
|
| 568 | + |
|
| 569 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 570 | + $where = array( |
|
| 571 | + "${champ_id}=" . sql_quote($valeur_id) |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 575 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if (!$valeurs) { |
|
| 579 | + $valeurs = false; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 583 | + |
|
| 584 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 585 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 586 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 591 | + |
|
| 592 | + // On ne retourne maintenant que les champs demandés. |
|
| 593 | + // - on détermine les informations à renvoyer. |
|
| 594 | + if ($retour and !empty($options['champs'])) { |
|
| 595 | + $champs = $options['champs']; |
|
| 596 | + // Extraction des seules informations demandées. |
|
| 597 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 598 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 599 | + if (is_array($champs)) { |
|
| 600 | + // Tableau des informations valides |
|
| 601 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 602 | + } else { |
|
| 603 | + // Valeur unique demandée. |
|
| 604 | + $retour = (isset($retour[$champs]) ? $retour[$champs] : false); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $retour; |
|
| 609 | 609 | } |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", "editer"._LOG_INFO_IMPORTANTE); |
|
| 80 | 80 | $objet = $t; |
| 81 | 81 | } |
| 82 | - if (include_spip('action/editer_' . $objet) |
|
| 83 | - and function_exists($modifier = $objet . "_modifier") |
|
| 82 | + if (include_spip('action/editer_'.$objet) |
|
| 83 | + and function_exists($modifier = $objet."_modifier") |
|
| 84 | 84 | ) { |
| 85 | 85 | return $modifier($id, $set); |
| 86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 90 | 90 | $desc = $trouver_table($table_sql); |
| 91 | 91 | if (!$desc or !isset($desc['field'])) { |
| 92 | - spip_log("Objet $objet inconnu dans objet_modifier", "editer" . _LOG_ERREUR); |
|
| 92 | + spip_log("Objet $objet inconnu dans objet_modifier", "editer"._LOG_ERREUR); |
|
| 93 | 93 | |
| 94 | 94 | return _L("Erreur objet $objet inconnu"); |
| 95 | 95 | } |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | * @return bool|int |
| 164 | 164 | */ |
| 165 | 165 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 166 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 167 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 166 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 167 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", "editer"._LOG_INFO_IMPORTANTE); |
|
| 168 | 168 | $objet = $t; |
| 169 | 169 | } |
| 170 | - if (include_spip('action/editer_' . $objet) |
|
| 171 | - and function_exists($inserer = $objet . "_inserer") |
|
| 170 | + if (include_spip('action/editer_'.$objet) |
|
| 171 | + and function_exists($inserer = $objet."_inserer") |
|
| 172 | 172 | ) { |
| 173 | 173 | return $inserer($id_parent, $set); |
| 174 | 174 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1"); |
| 190 | 190 | $id_rubrique = $row['id_rubrique']; |
| 191 | 191 | } else { |
| 192 | - $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique)); |
|
| 192 | + $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique)); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $champs['id_rubrique'] = $id_rubrique; |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | * @return string |
| 298 | 298 | */ |
| 299 | 299 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 300 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 301 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 300 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 301 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", "editer"._LOG_INFO_IMPORTANTE); |
|
| 302 | 302 | $objet = $t; |
| 303 | 303 | } |
| 304 | - if (include_spip('action/editer_' . $objet) |
|
| 305 | - and function_exists($instituer = $objet . "_instituer") |
|
| 304 | + if (include_spip('action/editer_'.$objet) |
|
| 305 | + and function_exists($instituer = $objet."_instituer") |
|
| 306 | 306 | ) { |
| 307 | 307 | return $instituer($id, $c, $calcul_rub); |
| 308 | 308 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
| 332 | 332 | $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique"); |
| 333 | 333 | |
| 334 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 334 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 335 | 335 | |
| 336 | 336 | $id_rubrique = $row['id_rubrique']; |
| 337 | 337 | $statut_ancien = $statut = $row['statut']; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
| 354 | 354 | $statut = $champs['statut'] = $s; |
| 355 | 355 | } else { |
| 356 | - spip_log("editer_objet $objet #$id refus " . json_encode($c), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 356 | + spip_log("editer_objet $objet #$id refus ".json_encode($c), 'editer'._LOG_INFO_IMPORTANTE); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | and isset($c['id_parent']) |
| 382 | 382 | and $id_parent = $c['id_parent'] |
| 383 | 383 | and $id_parent != $id_rubrique |
| 384 | - and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 384 | + and (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent))) |
|
| 385 | 385 | ) { |
| 386 | 386 | $champs['id_rubrique'] = $id_parent; |
| 387 | 387 | |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | // changer aussi son secteur et sa langue (si heritee) |
| 477 | 477 | if (isset($champs['id_rubrique'])) { |
| 478 | 478 | |
| 479 | - $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 479 | + $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique'])); |
|
| 480 | 480 | $langue = $row_rub['lang']; |
| 481 | 481 | |
| 482 | 482 | if (isset($desc['field']['id_secteur'])) { |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
| 487 | 487 | if (sql_fetsel('1', $table_sql, |
| 488 | - id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 488 | + id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue))) { |
|
| 489 | 489 | $champs['lang'] = $langue; |
| 490 | 490 | } |
| 491 | 491 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | if (!$champs) { |
| 495 | 495 | return; |
| 496 | 496 | } |
| 497 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 497 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 498 | 498 | |
| 499 | 499 | // Changer le statut des rubriques concernees |
| 500 | 500 | if ($cond) { |
@@ -537,8 +537,8 @@ discard block |
||
| 537 | 537 | * string|int : valeur du champ demande pour l'objet demande |
| 538 | 538 | */ |
| 539 | 539 | function objet_lire($objet, $valeur_id, $options = array()) { |
| 540 | - if (($t=objet_type($objet)) !== $objet) { |
|
| 541 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", "editer" . _LOG_INFO_IMPORTANTE); |
|
| 540 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 541 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", "editer"._LOG_INFO_IMPORTANTE); |
|
| 542 | 542 | $objet = $t; |
| 543 | 543 | } |
| 544 | 544 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | or (isset($options['force']) and $options['force'])) { |
| 559 | 559 | // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
| 560 | 560 | if ( |
| 561 | - include_spip('action/editer_' . $objet) |
|
| 561 | + include_spip('action/editer_'.$objet) |
|
| 562 | 562 | and function_exists($lire = "${objet}_lire_champs") |
| 563 | 563 | ) { |
| 564 | 564 | $valeurs = $lire($objet, $valeur_id, $champ_id); |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | |
| 569 | 569 | // La condition est appliquée sur le champ désigné par l'utilisateur. |
| 570 | 570 | $where = array( |
| 571 | - "${champ_id}=" . sql_quote($valeur_id) |
|
| 571 | + "${champ_id}=".sql_quote($valeur_id) |
|
| 572 | 572 | ); |
| 573 | 573 | |
| 574 | 574 | // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |