@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * Infos sur l'objet modifié : statut_ancien, objet, id_objet… |
| 51 | 51 | * @param bool $postdate |
| 52 | 52 | * true pour recalculer aussi la date du prochain article post-daté |
| 53 | - * @return bool |
|
| 53 | + * @return boolean|null |
|
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = array(), $postdate = false) { |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | * de la rubrique parente lorsque langue_choisie est différent de oui, |
| 454 | 454 | * et les corrige. |
| 455 | 455 | * |
| 456 | - * @return bool |
|
| 456 | + * @return boolean|string |
|
| 457 | 457 | * true si un changement a eu lieu |
| 458 | 458 | **/ |
| 459 | 459 | function calculer_langues_rubriques_etape() { |
@@ -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 | |
@@ -54,64 +54,64 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = array(), $postdate = false) { |
| 57 | - $neuf = false; |
|
| 57 | + $neuf = false; |
|
| 58 | 58 | |
| 59 | - // Compat avec l'ancienne signature |
|
| 60 | - if (is_string($infos)) { |
|
| 61 | - $infos = array('statut_ancien' => $infos); |
|
| 62 | - } |
|
| 63 | - if (!isset($infos['statut_ancien'])) { |
|
| 64 | - $infos['statut_ancien'] = ''; |
|
| 65 | - } |
|
| 59 | + // Compat avec l'ancienne signature |
|
| 60 | + if (is_string($infos)) { |
|
| 61 | + $infos = array('statut_ancien' => $infos); |
|
| 62 | + } |
|
| 63 | + if (!isset($infos['statut_ancien'])) { |
|
| 64 | + $infos['statut_ancien'] = ''; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // On recherche quels statuts tester |
|
| 68 | - if ( |
|
| 69 | - isset($infos['objet']) |
|
| 70 | - and include_spip('inc/filtres') |
|
| 71 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | - and is_array($declaration_statut) |
|
| 73 | - ) { |
|
| 74 | - foreach ($declaration_statut as $champ_statut) { |
|
| 75 | - if ($champ_statut['champ'] == 'statut') { |
|
| 76 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | - break; // stop on a trouvé le bon champ |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $statuts_publies = array('publie'); |
|
| 83 | - } |
|
| 67 | + // On recherche quels statuts tester |
|
| 68 | + if ( |
|
| 69 | + isset($infos['objet']) |
|
| 70 | + and include_spip('inc/filtres') |
|
| 71 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | + and is_array($declaration_statut) |
|
| 73 | + ) { |
|
| 74 | + foreach ($declaration_statut as $champ_statut) { |
|
| 75 | + if ($champ_statut['champ'] == 'statut') { |
|
| 76 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | + break; // stop on a trouvé le bon champ |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $statuts_publies = array('publie'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if (isset($modifs['statut']) |
|
| 87 | - or isset($modifs['id_rubrique']) |
|
| 88 | - or ($postdate and strtotime($postdate) > time()) |
|
| 89 | - ) { |
|
| 90 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 91 | - } |
|
| 92 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 93 | - if ($postdate) { |
|
| 94 | - calculer_prochain_postdate(true); |
|
| 95 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 96 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 97 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 98 | - } |
|
| 99 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 100 | - if ($postdate) { |
|
| 101 | - calculer_prochain_postdate(true); |
|
| 102 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 103 | - } else { |
|
| 104 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 109 | - { |
|
| 110 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $langues = calculer_langues_utilisees(); |
|
| 114 | - ecrire_meta('langues_utilisees', $langues); |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if (isset($modifs['statut']) |
|
| 87 | + or isset($modifs['id_rubrique']) |
|
| 88 | + or ($postdate and strtotime($postdate) > time()) |
|
| 89 | + ) { |
|
| 90 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 91 | + } |
|
| 92 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 93 | + if ($postdate) { |
|
| 94 | + calculer_prochain_postdate(true); |
|
| 95 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 96 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 97 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 98 | + } |
|
| 99 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 100 | + if ($postdate) { |
|
| 101 | + calculer_prochain_postdate(true); |
|
| 102 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 103 | + } else { |
|
| 104 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 109 | + { |
|
| 110 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $langues = calculer_langues_utilisees(); |
|
| 114 | + ecrire_meta('langues_utilisees', $langues); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * true si le statut change effectivement |
| 130 | 130 | */ |
| 131 | 131 | function publier_branche_rubrique($id_rubrique) { |
| 132 | - $id_pred = $id_rubrique; |
|
| 133 | - while (true) { |
|
| 134 | - sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 135 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 136 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 137 | - if (!$id_parent) { |
|
| 138 | - break; |
|
| 139 | - } |
|
| 140 | - $id_rubrique = $id_parent; |
|
| 141 | - } |
|
| 132 | + $id_pred = $id_rubrique; |
|
| 133 | + while (true) { |
|
| 134 | + sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 135 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 136 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 137 | + if (!$id_parent) { |
|
| 138 | + break; |
|
| 139 | + } |
|
| 140 | + $id_rubrique = $id_parent; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 144 | - return $id_pred != $id_rubrique; |
|
| 144 | + return $id_pred != $id_rubrique; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -159,21 +159,21 @@ discard block |
||
| 159 | 159 | * true si le statut change effectivement |
| 160 | 160 | */ |
| 161 | 161 | function depublier_branche_rubrique_if($id_rubrique) { |
| 162 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 162 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 163 | 163 | |
| 164 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 165 | - $id_pred = $id_rubrique; |
|
| 166 | - while ($id_pred) { |
|
| 164 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 165 | + $id_pred = $id_rubrique; |
|
| 166 | + while ($id_pred) { |
|
| 167 | 167 | |
| 168 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 169 | - return $id_pred != $id_rubrique; |
|
| 170 | - } |
|
| 171 | - // passer au parent si on a depublie |
|
| 172 | - $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 173 | - $id_pred = $r['id_parent']; |
|
| 174 | - } |
|
| 168 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 169 | + return $id_pred != $id_rubrique; |
|
| 170 | + } |
|
| 171 | + // passer au parent si on a depublie |
|
| 172 | + $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 173 | + $id_pred = $r['id_parent']; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - return $id_pred != $id_rubrique; |
|
| 176 | + return $id_pred != $id_rubrique; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -190,57 +190,57 @@ discard block |
||
| 190 | 190 | * true si la rubrique a été dépubliée |
| 191 | 191 | */ |
| 192 | 192 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 193 | - if (is_null($date)) { |
|
| 194 | - $date = date('Y-m-d H:i:s'); |
|
| 195 | - } |
|
| 196 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 197 | - " AND date <= " . sql_quote($date) : ''; |
|
| 198 | - |
|
| 199 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // verifier qu'elle existe et est bien publiee |
|
| 204 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 205 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 210 | - // Le type de l'objet est au pluriel |
|
| 211 | - $compte = array( |
|
| 212 | - 'articles' => sql_countsel("spip_articles", |
|
| 213 | - "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 214 | - 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 215 | - 'documents' => sql_countsel( |
|
| 216 | - "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", |
|
| 217 | - "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ") |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 221 | - $compte = pipeline('objet_compte_enfants', |
|
| 222 | - array( |
|
| 223 | - 'args' => array( |
|
| 224 | - 'objet' => 'rubrique', |
|
| 225 | - 'id_objet' => $id_rubrique, |
|
| 226 | - 'statut' => 'publie', |
|
| 227 | - 'date' => $date |
|
| 228 | - ), |
|
| 229 | - 'data' => $compte |
|
| 230 | - ) |
|
| 231 | - ); |
|
| 232 | - |
|
| 233 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 234 | - foreach ($compte as $objet => $n) { |
|
| 235 | - if ($n) { |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 193 | + if (is_null($date)) { |
|
| 194 | + $date = date('Y-m-d H:i:s'); |
|
| 195 | + } |
|
| 196 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 197 | + " AND date <= " . sql_quote($date) : ''; |
|
| 198 | + |
|
| 199 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // verifier qu'elle existe et est bien publiee |
|
| 204 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 205 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 210 | + // Le type de l'objet est au pluriel |
|
| 211 | + $compte = array( |
|
| 212 | + 'articles' => sql_countsel("spip_articles", |
|
| 213 | + "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 214 | + 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 215 | + 'documents' => sql_countsel( |
|
| 216 | + "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", |
|
| 217 | + "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ") |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 221 | + $compte = pipeline('objet_compte_enfants', |
|
| 222 | + array( |
|
| 223 | + 'args' => array( |
|
| 224 | + 'objet' => 'rubrique', |
|
| 225 | + 'id_objet' => $id_rubrique, |
|
| 226 | + 'statut' => 'publie', |
|
| 227 | + 'date' => $date |
|
| 228 | + ), |
|
| 229 | + 'data' => $compte |
|
| 230 | + ) |
|
| 231 | + ); |
|
| 232 | + |
|
| 233 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 234 | + foreach ($compte as $objet => $n) { |
|
| 235 | + if ($n) { |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 241 | 241 | |
| 242 | 242 | # spip_log("depublier_rubrique $id_pred"); |
| 243 | - return true; |
|
| 243 | + return true; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -263,18 +263,18 @@ discard block |
||
| 263 | 263 | **/ |
| 264 | 264 | function calculer_rubriques() { |
| 265 | 265 | |
| 266 | - calculer_rubriques_publiees(); |
|
| 266 | + calculer_rubriques_publiees(); |
|
| 267 | 267 | |
| 268 | - // Apres chaque (de)publication |
|
| 269 | - // recalculer les langues utilisees sur le site |
|
| 270 | - $langues = calculer_langues_utilisees(); |
|
| 271 | - ecrire_meta('langues_utilisees', $langues); |
|
| 268 | + // Apres chaque (de)publication |
|
| 269 | + // recalculer les langues utilisees sur le site |
|
| 270 | + $langues = calculer_langues_utilisees(); |
|
| 271 | + ecrire_meta('langues_utilisees', $langues); |
|
| 272 | 272 | |
| 273 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 274 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 273 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 274 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 275 | 275 | |
| 276 | - // on calcule la date du prochain article post-date |
|
| 277 | - calculer_prochain_postdate(); |
|
| 276 | + // on calcule la date du prochain article post-date |
|
| 277 | + calculer_prochain_postdate(); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
@@ -291,51 +291,51 @@ discard block |
||
| 291 | 291 | **/ |
| 292 | 292 | function calculer_rubriques_publiees() { |
| 293 | 293 | |
| 294 | - // Mettre les compteurs a zero |
|
| 295 | - sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 296 | - |
|
| 297 | - // |
|
| 298 | - // Publier et dater les rubriques qui ont un article publie |
|
| 299 | - // |
|
| 300 | - |
|
| 301 | - // Afficher les articles post-dates ? |
|
| 302 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 303 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 304 | - |
|
| 305 | - $r = sql_select( |
|
| 306 | - "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 307 | - "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 308 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 309 | - while ($row = sql_fetch($r)) { |
|
| 310 | - sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 311 | - "id_rubrique=" . intval($row['id'])); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 315 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 316 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 317 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 318 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 319 | - pipeline('calculer_rubriques', null); |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 323 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 324 | - do { |
|
| 325 | - $continuer = false; |
|
| 326 | - $r = sql_select( |
|
| 327 | - "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 328 | - "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 329 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 330 | - while ($row = sql_fetch($r)) { |
|
| 331 | - sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 332 | - "id_rubrique=" . intval($row['id'])); |
|
| 333 | - $continuer = true; |
|
| 334 | - } |
|
| 335 | - } while ($continuer); |
|
| 336 | - |
|
| 337 | - // Enregistrement des modifs |
|
| 338 | - sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 294 | + // Mettre les compteurs a zero |
|
| 295 | + sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 296 | + |
|
| 297 | + // |
|
| 298 | + // Publier et dater les rubriques qui ont un article publie |
|
| 299 | + // |
|
| 300 | + |
|
| 301 | + // Afficher les articles post-dates ? |
|
| 302 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 303 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 304 | + |
|
| 305 | + $r = sql_select( |
|
| 306 | + "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 307 | + "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 308 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 309 | + while ($row = sql_fetch($r)) { |
|
| 310 | + sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 311 | + "id_rubrique=" . intval($row['id'])); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 315 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 316 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 317 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 318 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 319 | + pipeline('calculer_rubriques', null); |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 323 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 324 | + do { |
|
| 325 | + $continuer = false; |
|
| 326 | + $r = sql_select( |
|
| 327 | + "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 328 | + "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 329 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 330 | + while ($row = sql_fetch($r)) { |
|
| 331 | + sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 332 | + "id_rubrique=" . intval($row['id'])); |
|
| 333 | + $continuer = true; |
|
| 334 | + } |
|
| 335 | + } while ($continuer); |
|
| 336 | + |
|
| 337 | + // Enregistrement des modifs |
|
| 338 | + sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -350,99 +350,99 @@ discard block |
||
| 350 | 350 | * @return void |
| 351 | 351 | **/ |
| 352 | 352 | function propager_les_secteurs() { |
| 353 | - // Profondeur 0 |
|
| 354 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 355 | - // et fixer les id_secteur des rubriques racines |
|
| 356 | - sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 357 | - // Toute rubrique non racine est de profondeur >0 |
|
| 358 | - sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 359 | - |
|
| 360 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 361 | - $maxiter = sql_countsel("spip_rubriques"); |
|
| 362 | - |
|
| 363 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 364 | - // on fait profondeur par profondeur |
|
| 365 | - |
|
| 366 | - $prof = 0; |
|
| 367 | - do { |
|
| 368 | - $continuer = false; |
|
| 369 | - |
|
| 370 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 371 | - // on fixe le profondeur $prof+1 |
|
| 372 | - |
|
| 373 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 374 | - // on teste A.profondeur > $prof+1 car : |
|
| 375 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 376 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 377 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 378 | - $maxiter2 = $maxiter; |
|
| 379 | - while ($maxiter2-- |
|
| 380 | - and $rows = sql_allfetsel( |
|
| 381 | - "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 382 | - "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 383 | - "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 384 | - "", "R.id_secteur", "0,100")) { |
|
| 385 | - |
|
| 386 | - $id_secteur = null; |
|
| 387 | - $ids = array(); |
|
| 388 | - while ($row = array_shift($rows)) { |
|
| 389 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 390 | - if (count($ids)) { |
|
| 391 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 392 | - sql_in('id_rubrique', $ids)); |
|
| 393 | - } |
|
| 394 | - $id_secteur = $row['id_secteur']; |
|
| 395 | - $ids = array(); |
|
| 396 | - } |
|
| 397 | - $ids[] = $row['id']; |
|
| 398 | - } |
|
| 399 | - if (count($ids)) { |
|
| 400 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 401 | - sql_in('id_rubrique', $ids)); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 407 | - $maxiter2 = $maxiter; |
|
| 408 | - while ($maxiter2-- |
|
| 409 | - and $rows = sql_allfetsel( |
|
| 410 | - "id_rubrique as id", |
|
| 411 | - "spip_rubriques", |
|
| 412 | - "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 413 | - "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 414 | - $rows = array_column($rows, 'id'); |
|
| 415 | - sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 419 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 420 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 421 | - // on arrete les frais |
|
| 422 | - if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 423 | - $prof++; |
|
| 424 | - $continuer = true; |
|
| 425 | - } |
|
| 426 | - } while ($continuer and $maxiter--); |
|
| 427 | - |
|
| 428 | - // loger si la table des rubriques semble foireuse |
|
| 429 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 430 | - if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 431 | - spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 432 | - _LOG_CRITIQUE); |
|
| 433 | - sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // reparer les articles |
|
| 437 | - $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 438 | - "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 439 | - |
|
| 440 | - while ($row = sql_fetch($r)) { |
|
| 441 | - sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 445 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 353 | + // Profondeur 0 |
|
| 354 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 355 | + // et fixer les id_secteur des rubriques racines |
|
| 356 | + sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 357 | + // Toute rubrique non racine est de profondeur >0 |
|
| 358 | + sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 359 | + |
|
| 360 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 361 | + $maxiter = sql_countsel("spip_rubriques"); |
|
| 362 | + |
|
| 363 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 364 | + // on fait profondeur par profondeur |
|
| 365 | + |
|
| 366 | + $prof = 0; |
|
| 367 | + do { |
|
| 368 | + $continuer = false; |
|
| 369 | + |
|
| 370 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 371 | + // on fixe le profondeur $prof+1 |
|
| 372 | + |
|
| 373 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 374 | + // on teste A.profondeur > $prof+1 car : |
|
| 375 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 376 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 377 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 378 | + $maxiter2 = $maxiter; |
|
| 379 | + while ($maxiter2-- |
|
| 380 | + and $rows = sql_allfetsel( |
|
| 381 | + "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 382 | + "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 383 | + "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 384 | + "", "R.id_secteur", "0,100")) { |
|
| 385 | + |
|
| 386 | + $id_secteur = null; |
|
| 387 | + $ids = array(); |
|
| 388 | + while ($row = array_shift($rows)) { |
|
| 389 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 390 | + if (count($ids)) { |
|
| 391 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 392 | + sql_in('id_rubrique', $ids)); |
|
| 393 | + } |
|
| 394 | + $id_secteur = $row['id_secteur']; |
|
| 395 | + $ids = array(); |
|
| 396 | + } |
|
| 397 | + $ids[] = $row['id']; |
|
| 398 | + } |
|
| 399 | + if (count($ids)) { |
|
| 400 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 401 | + sql_in('id_rubrique', $ids)); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 407 | + $maxiter2 = $maxiter; |
|
| 408 | + while ($maxiter2-- |
|
| 409 | + and $rows = sql_allfetsel( |
|
| 410 | + "id_rubrique as id", |
|
| 411 | + "spip_rubriques", |
|
| 412 | + "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 413 | + "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 414 | + $rows = array_column($rows, 'id'); |
|
| 415 | + sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 419 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 420 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 421 | + // on arrete les frais |
|
| 422 | + if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 423 | + $prof++; |
|
| 424 | + $continuer = true; |
|
| 425 | + } |
|
| 426 | + } while ($continuer and $maxiter--); |
|
| 427 | + |
|
| 428 | + // loger si la table des rubriques semble foireuse |
|
| 429 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 430 | + if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 431 | + spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 432 | + _LOG_CRITIQUE); |
|
| 433 | + sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // reparer les articles |
|
| 437 | + $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 438 | + "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 439 | + |
|
| 440 | + while ($row = sql_fetch($r)) { |
|
| 441 | + sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 445 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -457,17 +457,17 @@ discard block |
||
| 457 | 457 | * true si un changement a eu lieu |
| 458 | 458 | **/ |
| 459 | 459 | function calculer_langues_rubriques_etape() { |
| 460 | - $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 461 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 460 | + $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 461 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 462 | 462 | |
| 463 | - $t = false; |
|
| 464 | - while ($row = sql_fetch($s)) { |
|
| 465 | - $id_rubrique = $row['id_rubrique']; |
|
| 466 | - $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 467 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 468 | - } |
|
| 463 | + $t = false; |
|
| 464 | + while ($row = sql_fetch($s)) { |
|
| 465 | + $id_rubrique = $row['id_rubrique']; |
|
| 466 | + $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 467 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - return $t; |
|
| 470 | + return $t; |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -487,30 +487,30 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function calculer_langues_rubriques() { |
| 489 | 489 | |
| 490 | - // rubriques (recursivite) |
|
| 491 | - sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 492 | - "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 493 | - while (calculer_langues_rubriques_etape()) { |
|
| 494 | - ; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // articles |
|
| 498 | - $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 499 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 500 | - while ($row = sql_fetch($s)) { |
|
| 501 | - $id_article = $row['id_article']; |
|
| 502 | - sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 503 | - "id_article=" . intval($id_article)); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 507 | - |
|
| 508 | - $langues = calculer_langues_utilisees(); |
|
| 509 | - ecrire_meta('langues_utilisees', $langues); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 513 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 490 | + // rubriques (recursivite) |
|
| 491 | + sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 492 | + "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 493 | + while (calculer_langues_rubriques_etape()) { |
|
| 494 | + ; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // articles |
|
| 498 | + $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 499 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 500 | + while ($row = sql_fetch($s)) { |
|
| 501 | + $id_article = $row['id_article']; |
|
| 502 | + sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 503 | + "id_article=" . intval($id_article)); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 507 | + |
|
| 508 | + $langues = calculer_langues_utilisees(); |
|
| 509 | + ecrire_meta('langues_utilisees', $langues); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 513 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | |
@@ -527,77 +527,77 @@ discard block |
||
| 527 | 527 | * Liste des langues utilisées séparées par des virgules |
| 528 | 528 | **/ |
| 529 | 529 | function calculer_langues_utilisees($serveur = '') { |
| 530 | - include_spip('public/interfaces'); |
|
| 531 | - include_spip('public/compiler'); |
|
| 532 | - include_spip('public/composer'); |
|
| 533 | - include_spip('public/phraser_html'); |
|
| 534 | - $langues = array(); |
|
| 535 | - |
|
| 536 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 537 | - |
|
| 538 | - include_spip('base/objets'); |
|
| 539 | - $tables = lister_tables_objets_sql(); |
|
| 540 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 541 | - |
|
| 542 | - foreach (array_keys($tables) as $t) { |
|
| 543 | - $desc = $trouver_table($t, $serveur); |
|
| 544 | - // c'est une table avec des langues |
|
| 545 | - if ($desc['exist'] |
|
| 546 | - and isset($desc['field']['lang']) |
|
| 547 | - and isset($desc['field']['langue_choisie']) |
|
| 548 | - ) { |
|
| 549 | - |
|
| 550 | - $boucle = new Boucle(); |
|
| 551 | - $boucle->show = $desc; |
|
| 552 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 553 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 554 | - $boucle->id_table = $desc['table_objet']; |
|
| 555 | - $boucle->sql_serveur = $serveur; |
|
| 556 | - $boucle->select[] = "DISTINCT lang"; |
|
| 557 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 558 | - $boucle->separateur[] = ','; |
|
| 559 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 560 | - $boucle->iterateur = 'sql'; |
|
| 561 | - |
|
| 562 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 563 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 564 | - |
|
| 565 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 566 | - |
|
| 567 | - if (isset($desc['statut']) |
|
| 568 | - and $desc['statut'] |
|
| 569 | - ) { |
|
| 570 | - $boucles = array( |
|
| 571 | - 'calculer_langues_utilisees' => $boucle, |
|
| 572 | - ); |
|
| 573 | - // generer un nom de fonction "anonyme" unique |
|
| 574 | - do { |
|
| 575 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 576 | - } while (function_exists($functionname)); |
|
| 577 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 578 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 579 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 580 | - $res = ''; |
|
| 581 | - eval($code); |
|
| 582 | - $res = explode(',', $res); |
|
| 583 | - foreach ($res as $lang) { |
|
| 584 | - $langues[$lang] = 1; |
|
| 585 | - } |
|
| 586 | - } else { |
|
| 587 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 588 | - while ($row = sql_fetch($res)) { |
|
| 589 | - $langues[$row['lang']] = 1; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $langues = array_filter(array_keys($langues)); |
|
| 596 | - sort($langues); |
|
| 597 | - $langues = join(',', $langues); |
|
| 598 | - spip_log("langues utilisees: $langues"); |
|
| 599 | - |
|
| 600 | - return $langues; |
|
| 530 | + include_spip('public/interfaces'); |
|
| 531 | + include_spip('public/compiler'); |
|
| 532 | + include_spip('public/composer'); |
|
| 533 | + include_spip('public/phraser_html'); |
|
| 534 | + $langues = array(); |
|
| 535 | + |
|
| 536 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 537 | + |
|
| 538 | + include_spip('base/objets'); |
|
| 539 | + $tables = lister_tables_objets_sql(); |
|
| 540 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 541 | + |
|
| 542 | + foreach (array_keys($tables) as $t) { |
|
| 543 | + $desc = $trouver_table($t, $serveur); |
|
| 544 | + // c'est une table avec des langues |
|
| 545 | + if ($desc['exist'] |
|
| 546 | + and isset($desc['field']['lang']) |
|
| 547 | + and isset($desc['field']['langue_choisie']) |
|
| 548 | + ) { |
|
| 549 | + |
|
| 550 | + $boucle = new Boucle(); |
|
| 551 | + $boucle->show = $desc; |
|
| 552 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 553 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 554 | + $boucle->id_table = $desc['table_objet']; |
|
| 555 | + $boucle->sql_serveur = $serveur; |
|
| 556 | + $boucle->select[] = "DISTINCT lang"; |
|
| 557 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 558 | + $boucle->separateur[] = ','; |
|
| 559 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 560 | + $boucle->iterateur = 'sql'; |
|
| 561 | + |
|
| 562 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 563 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 564 | + |
|
| 565 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 566 | + |
|
| 567 | + if (isset($desc['statut']) |
|
| 568 | + and $desc['statut'] |
|
| 569 | + ) { |
|
| 570 | + $boucles = array( |
|
| 571 | + 'calculer_langues_utilisees' => $boucle, |
|
| 572 | + ); |
|
| 573 | + // generer un nom de fonction "anonyme" unique |
|
| 574 | + do { |
|
| 575 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 576 | + } while (function_exists($functionname)); |
|
| 577 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 578 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 579 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 580 | + $res = ''; |
|
| 581 | + eval($code); |
|
| 582 | + $res = explode(',', $res); |
|
| 583 | + foreach ($res as $lang) { |
|
| 584 | + $langues[$lang] = 1; |
|
| 585 | + } |
|
| 586 | + } else { |
|
| 587 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 588 | + while ($row = sql_fetch($res)) { |
|
| 589 | + $langues[$row['lang']] = 1; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $langues = array_filter(array_keys($langues)); |
|
| 596 | + sort($langues); |
|
| 597 | + $langues = join(',', $langues); |
|
| 598 | + spip_log("langues utilisees: $langues"); |
|
| 599 | + |
|
| 600 | + return $langues; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -627,9 +627,9 @@ discard block |
||
| 627 | 627 | * incluant les rubriques noeuds et toutes leurs descendances |
| 628 | 628 | */ |
| 629 | 629 | function calcul_branche_in($id) { |
| 630 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 630 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 631 | 631 | |
| 632 | - return $calcul_branche_in($id); |
|
| 632 | + return $calcul_branche_in($id); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -647,9 +647,9 @@ discard block |
||
| 647 | 647 | * incluant les rubriques transmises et toutes leurs parentées |
| 648 | 648 | */ |
| 649 | 649 | function calcul_hierarchie_in($id, $tout = true) { |
| 650 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 650 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 651 | 651 | |
| 652 | - return $calcul_hierarchie_in($id, $tout); |
|
| 652 | + return $calcul_hierarchie_in($id, $tout); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | |
@@ -670,38 +670,38 @@ discard block |
||
| 670 | 670 | * incluant les rubriques noeuds et toutes leurs descendances |
| 671 | 671 | */ |
| 672 | 672 | function inc_calcul_branche_in_dist($id) { |
| 673 | - static $b = array(); |
|
| 674 | - |
|
| 675 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 676 | - if (!is_array($id)) { |
|
| 677 | - $id = explode(',', $id); |
|
| 678 | - } |
|
| 679 | - $id = join(',', array_map('intval', $id)); |
|
| 680 | - if (isset($b[$id])) { |
|
| 681 | - return $b[$id]; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // Notre branche commence par la rubrique de depart |
|
| 685 | - $branche = $r = $id; |
|
| 686 | - |
|
| 687 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 688 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 689 | - $maxiter = 10000; |
|
| 690 | - while ($maxiter-- and $filles = sql_allfetsel( |
|
| 691 | - 'id_rubrique', |
|
| 692 | - 'spip_rubriques', |
|
| 693 | - sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 694 | - )) { |
|
| 695 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 696 | - $branche .= ',' . $r; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 700 | - if (strlen($branche) < 10000) { |
|
| 701 | - $b[$id] = $branche; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - return $branche; |
|
| 673 | + static $b = array(); |
|
| 674 | + |
|
| 675 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 676 | + if (!is_array($id)) { |
|
| 677 | + $id = explode(',', $id); |
|
| 678 | + } |
|
| 679 | + $id = join(',', array_map('intval', $id)); |
|
| 680 | + if (isset($b[$id])) { |
|
| 681 | + return $b[$id]; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // Notre branche commence par la rubrique de depart |
|
| 685 | + $branche = $r = $id; |
|
| 686 | + |
|
| 687 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 688 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 689 | + $maxiter = 10000; |
|
| 690 | + while ($maxiter-- and $filles = sql_allfetsel( |
|
| 691 | + 'id_rubrique', |
|
| 692 | + 'spip_rubriques', |
|
| 693 | + sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 694 | + )) { |
|
| 695 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 696 | + $branche .= ',' . $r; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 700 | + if (strlen($branche) < 10000) { |
|
| 701 | + $b[$id] = $branche; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + return $branche; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -723,43 +723,43 @@ discard block |
||
| 723 | 723 | * incluant les rubriques transmises et toutes leurs parentées |
| 724 | 724 | */ |
| 725 | 725 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 726 | - static $b = array(); |
|
| 727 | - |
|
| 728 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 729 | - if (!is_array($id)) { |
|
| 730 | - $id = explode(',', $id); |
|
| 731 | - } |
|
| 732 | - $id = join(',', array_map('intval', $id)); |
|
| 733 | - |
|
| 734 | - if (isset($b[$id])) { |
|
| 735 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 736 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - $hier = ""; |
|
| 740 | - |
|
| 741 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 742 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 743 | - $ids_nouveaux_parents = $id; |
|
| 744 | - $maxiter = 10000; |
|
| 745 | - while ($maxiter-- and $parents = sql_allfetsel( |
|
| 746 | - 'id_parent', |
|
| 747 | - 'spip_rubriques', |
|
| 748 | - sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 749 | - )) { |
|
| 750 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 751 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 755 | - if (strlen($hier) < 10000) { |
|
| 756 | - $b[$id] = $hier; |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 760 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 761 | - |
|
| 762 | - return $hier; |
|
| 726 | + static $b = array(); |
|
| 727 | + |
|
| 728 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 729 | + if (!is_array($id)) { |
|
| 730 | + $id = explode(',', $id); |
|
| 731 | + } |
|
| 732 | + $id = join(',', array_map('intval', $id)); |
|
| 733 | + |
|
| 734 | + if (isset($b[$id])) { |
|
| 735 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 736 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + $hier = ""; |
|
| 740 | + |
|
| 741 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 742 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 743 | + $ids_nouveaux_parents = $id; |
|
| 744 | + $maxiter = 10000; |
|
| 745 | + while ($maxiter-- and $parents = sql_allfetsel( |
|
| 746 | + 'id_parent', |
|
| 747 | + 'spip_rubriques', |
|
| 748 | + sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 749 | + )) { |
|
| 750 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 751 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 755 | + if (strlen($hier) < 10000) { |
|
| 756 | + $b[$id] = $hier; |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 760 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 761 | + |
|
| 762 | + return $hier; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
@@ -777,38 +777,38 @@ discard block |
||
| 777 | 777 | * @return void |
| 778 | 778 | **/ |
| 779 | 779 | function calculer_prochain_postdate($check = false) { |
| 780 | - include_spip('base/abstract_sql'); |
|
| 781 | - if ($check) { |
|
| 782 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 783 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 784 | - |
|
| 785 | - $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 786 | - "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 787 | - "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 788 | - while ($row = sql_fetch($r)) { |
|
| 789 | - publier_branche_rubrique($row['id']); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 796 | - "1"); |
|
| 797 | - |
|
| 798 | - if ($t) { |
|
| 799 | - $t = $t['date']; |
|
| 800 | - if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 801 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 802 | - ) { |
|
| 803 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 804 | - ecrire_meta('derniere_modif', time()); |
|
| 805 | - } |
|
| 806 | - } else { |
|
| 807 | - effacer_meta('date_prochain_postdate'); |
|
| 808 | - ecrire_meta('derniere_modif', time()); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - spip_log("prochain postdate: $t"); |
|
| 780 | + include_spip('base/abstract_sql'); |
|
| 781 | + if ($check) { |
|
| 782 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 783 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 784 | + |
|
| 785 | + $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 786 | + "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 787 | + "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 788 | + while ($row = sql_fetch($r)) { |
|
| 789 | + publier_branche_rubrique($row['id']); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 796 | + "1"); |
|
| 797 | + |
|
| 798 | + if ($t) { |
|
| 799 | + $t = $t['date']; |
|
| 800 | + if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 801 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 802 | + ) { |
|
| 803 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 804 | + ecrire_meta('derniere_modif', time()); |
|
| 805 | + } |
|
| 806 | + } else { |
|
| 807 | + effacer_meta('date_prochain_postdate'); |
|
| 808 | + ecrire_meta('derniere_modif', time()); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + spip_log("prochain postdate: $t"); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -833,42 +833,42 @@ discard block |
||
| 833 | 833 | */ |
| 834 | 834 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 835 | 835 | |
| 836 | - // eclater l'arborescence demandee |
|
| 837 | - // echapper les </multi> et autres balises fermantes html |
|
| 838 | - $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 839 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 840 | - include_spip('base/abstract_sql'); |
|
| 841 | - foreach ($arbo as $titre) { |
|
| 842 | - // retablir les </multi> et autres balises fermantes html |
|
| 843 | - $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 844 | - $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 845 | - "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 846 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 847 | - if ($r !== null) { |
|
| 848 | - $id_parent = $r; |
|
| 849 | - } else { |
|
| 850 | - $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 851 | - 'titre' => $titre, |
|
| 852 | - 'id_parent' => $id_parent, |
|
| 853 | - 'statut' => 'prepa' |
|
| 854 | - ), $desc = array(), $serveur); |
|
| 855 | - if ($id_parent > 0) { |
|
| 856 | - $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 857 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 858 | - $id_secteur = $data['id_secteur']; |
|
| 859 | - $lang = $data['lang']; |
|
| 860 | - } else { |
|
| 861 | - $id_secteur = $id_rubrique; |
|
| 862 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 866 | - "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 867 | - |
|
| 868 | - // pour la recursion |
|
| 869 | - $id_parent = $id_rubrique; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - return intval($id_parent); |
|
| 836 | + // eclater l'arborescence demandee |
|
| 837 | + // echapper les </multi> et autres balises fermantes html |
|
| 838 | + $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 839 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 840 | + include_spip('base/abstract_sql'); |
|
| 841 | + foreach ($arbo as $titre) { |
|
| 842 | + // retablir les </multi> et autres balises fermantes html |
|
| 843 | + $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 844 | + $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 845 | + "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 846 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 847 | + if ($r !== null) { |
|
| 848 | + $id_parent = $r; |
|
| 849 | + } else { |
|
| 850 | + $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 851 | + 'titre' => $titre, |
|
| 852 | + 'id_parent' => $id_parent, |
|
| 853 | + 'statut' => 'prepa' |
|
| 854 | + ), $desc = array(), $serveur); |
|
| 855 | + if ($id_parent > 0) { |
|
| 856 | + $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 857 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 858 | + $id_secteur = $data['id_secteur']; |
|
| 859 | + $lang = $data['lang']; |
|
| 860 | + } else { |
|
| 861 | + $id_secteur = $id_rubrique; |
|
| 862 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 866 | + "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 867 | + |
|
| 868 | + // pour la recursion |
|
| 869 | + $id_parent = $id_rubrique; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + return intval($id_parent); |
|
| 874 | 874 | } |
@@ -77,8 +77,7 @@ discard block |
||
| 77 | 77 | break; // stop on a trouvé le bon champ |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $statuts_publies = array('publie'); |
| 83 | 82 | } |
| 84 | 83 | |
@@ -105,10 +104,12 @@ discard block |
||
| 105 | 104 | } |
| 106 | 105 | } |
| 107 | 106 | |
| 108 | - if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 107 | + if ($neuf) { |
|
| 108 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 109 | 109 | { |
| 110 | 110 | ecrire_meta("date_calcul_rubriques", date("U")); |
| 111 | 111 | } |
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | $langues = calculer_langues_utilisees(); |
| 114 | 115 | ecrire_meta('langues_utilisees', $langues); |
@@ -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", _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", _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 $id refus " . join(' ', $c)); |
|
| 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 $id refus " . join(' ', $c)); |
|
| 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 | } |