@@ -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,65 +54,65 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 57 | - $statuts_publies = null; |
|
| 58 | - $neuf = false; |
|
| 59 | - |
|
| 60 | - // Compat avec l'ancienne signature |
|
| 61 | - if (is_string($infos)) { |
|
| 62 | - $infos = ['statut_ancien' => $infos]; |
|
| 63 | - } |
|
| 64 | - if (!isset($infos['statut_ancien'])) { |
|
| 65 | - $infos['statut_ancien'] = ''; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // On recherche quels statuts tester |
|
| 69 | - if ( |
|
| 70 | - isset($infos['objet']) |
|
| 71 | - and include_spip('inc/filtres') |
|
| 72 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | - and is_array($declaration_statut) |
|
| 74 | - ) { |
|
| 75 | - foreach ($declaration_statut as $champ_statut) { |
|
| 76 | - if ($champ_statut['champ'] == 'statut') { |
|
| 77 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | - break; // stop on a trouvé le bon champ |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } else { |
|
| 82 | - $statuts_publies = ['publie']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if ( |
|
| 87 | - isset($modifs['statut']) |
|
| 88 | - or isset($modifs['id_rubrique']) |
|
| 89 | - or ($postdate and strtotime($postdate) > time()) |
|
| 90 | - ) { |
|
| 91 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | - } |
|
| 93 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | - if ($postdate) { |
|
| 95 | - calculer_prochain_postdate(true); |
|
| 96 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | - } |
|
| 100 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | - if ($postdate) { |
|
| 102 | - calculer_prochain_postdate(true); |
|
| 103 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | - } else { |
|
| 105 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($neuf) { |
|
| 110 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $langues = calculer_langues_utilisees(); |
|
| 115 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $statuts_publies = null; |
|
| 58 | + $neuf = false; |
|
| 59 | + |
|
| 60 | + // Compat avec l'ancienne signature |
|
| 61 | + if (is_string($infos)) { |
|
| 62 | + $infos = ['statut_ancien' => $infos]; |
|
| 63 | + } |
|
| 64 | + if (!isset($infos['statut_ancien'])) { |
|
| 65 | + $infos['statut_ancien'] = ''; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // On recherche quels statuts tester |
|
| 69 | + if ( |
|
| 70 | + isset($infos['objet']) |
|
| 71 | + and include_spip('inc/filtres') |
|
| 72 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | + and is_array($declaration_statut) |
|
| 74 | + ) { |
|
| 75 | + foreach ($declaration_statut as $champ_statut) { |
|
| 76 | + if ($champ_statut['champ'] == 'statut') { |
|
| 77 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | + break; // stop on a trouvé le bon champ |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + $statuts_publies = ['publie']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if ( |
|
| 87 | + isset($modifs['statut']) |
|
| 88 | + or isset($modifs['id_rubrique']) |
|
| 89 | + or ($postdate and strtotime($postdate) > time()) |
|
| 90 | + ) { |
|
| 91 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | + } |
|
| 93 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | + if ($postdate) { |
|
| 95 | + calculer_prochain_postdate(true); |
|
| 96 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | + } |
|
| 100 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | + if ($postdate) { |
|
| 102 | + calculer_prochain_postdate(true); |
|
| 103 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | + } else { |
|
| 105 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($neuf) { |
|
| 110 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $langues = calculer_langues_utilisees(); |
|
| 115 | + ecrire_meta('langues_utilisees', $langues); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | * true si le statut change effectivement |
| 131 | 131 | */ |
| 132 | 132 | function publier_branche_rubrique($id_rubrique) { |
| 133 | - $id_pred = $id_rubrique; |
|
| 134 | - while (true) { |
|
| 135 | - sql_updateq( |
|
| 136 | - 'spip_rubriques', |
|
| 137 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | - ); |
|
| 140 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | - if (!$id_parent) { |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - $id_rubrique = $id_parent; |
|
| 145 | - } |
|
| 133 | + $id_pred = $id_rubrique; |
|
| 134 | + while (true) { |
|
| 135 | + sql_updateq( |
|
| 136 | + 'spip_rubriques', |
|
| 137 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | + ); |
|
| 140 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | + if (!$id_parent) { |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + $id_rubrique = $id_parent; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 148 | - return $id_pred != $id_rubrique; |
|
| 148 | + return $id_pred != $id_rubrique; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * true si le statut change effectivement |
| 164 | 164 | */ |
| 165 | 165 | function depublier_branche_rubrique_if($id_rubrique) { |
| 166 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | - |
|
| 168 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | - $id_pred = $id_rubrique; |
|
| 170 | - while ($id_pred) { |
|
| 171 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | - return $id_pred != $id_rubrique; |
|
| 173 | - } |
|
| 174 | - // passer au parent si on a depublie |
|
| 175 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | - $id_pred = $r['id_parent']; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $id_pred != $id_rubrique; |
|
| 166 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | + |
|
| 168 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | + $id_pred = $id_rubrique; |
|
| 170 | + while ($id_pred) { |
|
| 171 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | + return $id_pred != $id_rubrique; |
|
| 173 | + } |
|
| 174 | + // passer au parent si on a depublie |
|
| 175 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | + $id_pred = $r['id_parent']; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $id_pred != $id_rubrique; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -193,61 +193,61 @@ discard block |
||
| 193 | 193 | * true si la rubrique a été dépubliée |
| 194 | 194 | */ |
| 195 | 195 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 196 | - if (is_null($date)) { |
|
| 197 | - $date = date('Y-m-d H:i:s'); |
|
| 198 | - } |
|
| 199 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | - |
|
| 202 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // verifier qu'elle existe et est bien publiee |
|
| 207 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | - // Le type de l'objet est au pluriel |
|
| 214 | - $compte = [ |
|
| 215 | - 'articles' => sql_countsel( |
|
| 216 | - 'spip_articles', |
|
| 217 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | - ), |
|
| 219 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | - 'documents' => sql_countsel( |
|
| 221 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | - ) |
|
| 224 | - ]; |
|
| 225 | - |
|
| 226 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | - $compte = pipeline( |
|
| 228 | - 'objet_compte_enfants', |
|
| 229 | - [ |
|
| 230 | - 'args' => [ |
|
| 231 | - 'objet' => 'rubrique', |
|
| 232 | - 'id_objet' => $id_rubrique, |
|
| 233 | - 'statut' => 'publie', |
|
| 234 | - 'date' => $date |
|
| 235 | - ], |
|
| 236 | - 'data' => $compte |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | - foreach ($compte as $objet => $n) { |
|
| 242 | - if ($n) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 196 | + if (is_null($date)) { |
|
| 197 | + $date = date('Y-m-d H:i:s'); |
|
| 198 | + } |
|
| 199 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | + |
|
| 202 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // verifier qu'elle existe et est bien publiee |
|
| 207 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | + // Le type de l'objet est au pluriel |
|
| 214 | + $compte = [ |
|
| 215 | + 'articles' => sql_countsel( |
|
| 216 | + 'spip_articles', |
|
| 217 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | + ), |
|
| 219 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | + 'documents' => sql_countsel( |
|
| 221 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | + ) |
|
| 224 | + ]; |
|
| 225 | + |
|
| 226 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | + $compte = pipeline( |
|
| 228 | + 'objet_compte_enfants', |
|
| 229 | + [ |
|
| 230 | + 'args' => [ |
|
| 231 | + 'objet' => 'rubrique', |
|
| 232 | + 'id_objet' => $id_rubrique, |
|
| 233 | + 'statut' => 'publie', |
|
| 234 | + 'date' => $date |
|
| 235 | + ], |
|
| 236 | + 'data' => $compte |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | + foreach ($compte as $objet => $n) { |
|
| 242 | + if ($n) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 248 | 248 | |
| 249 | 249 | # spip_log("depublier_rubrique $id_pred"); |
| 250 | - return true; |
|
| 250 | + return true; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | **/ |
| 271 | 271 | function calculer_rubriques() { |
| 272 | 272 | |
| 273 | - calculer_rubriques_publiees(); |
|
| 273 | + calculer_rubriques_publiees(); |
|
| 274 | 274 | |
| 275 | - // Apres chaque (de)publication |
|
| 276 | - // recalculer les langues utilisees sur le site |
|
| 277 | - $langues = calculer_langues_utilisees(); |
|
| 278 | - ecrire_meta('langues_utilisees', $langues); |
|
| 275 | + // Apres chaque (de)publication |
|
| 276 | + // recalculer les langues utilisees sur le site |
|
| 277 | + $langues = calculer_langues_utilisees(); |
|
| 278 | + ecrire_meta('langues_utilisees', $langues); |
|
| 279 | 279 | |
| 280 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 280 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 282 | 282 | |
| 283 | - // on calcule la date du prochain article post-date |
|
| 284 | - calculer_prochain_postdate(); |
|
| 283 | + // on calcule la date du prochain article post-date |
|
| 284 | + calculer_prochain_postdate(); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -298,61 +298,61 @@ discard block |
||
| 298 | 298 | **/ |
| 299 | 299 | function calculer_rubriques_publiees() { |
| 300 | 300 | |
| 301 | - // Mettre les compteurs a zero |
|
| 302 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | - |
|
| 304 | - // |
|
| 305 | - // Publier et dater les rubriques qui ont un article publie |
|
| 306 | - // |
|
| 307 | - |
|
| 308 | - // Afficher les articles post-dates ? |
|
| 309 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | - |
|
| 312 | - $r = sql_select( |
|
| 313 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | - 'R.id_rubrique' |
|
| 317 | - ); |
|
| 318 | - while ($row = sql_fetch($r)) { |
|
| 319 | - sql_updateq( |
|
| 320 | - 'spip_rubriques', |
|
| 321 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | - 'id_rubrique=' . intval($row['id']) |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | - pipeline('calculer_rubriques', null); |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | - do { |
|
| 337 | - $continuer = false; |
|
| 338 | - $r = sql_select( |
|
| 339 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | - 'R.id_rubrique' |
|
| 343 | - ); |
|
| 344 | - while ($row = sql_fetch($r)) { |
|
| 345 | - sql_updateq( |
|
| 346 | - 'spip_rubriques', |
|
| 347 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | - 'id_rubrique=' . intval($row['id']) |
|
| 349 | - ); |
|
| 350 | - $continuer = true; |
|
| 351 | - } |
|
| 352 | - } while ($continuer); |
|
| 353 | - |
|
| 354 | - // Enregistrement des modifs |
|
| 355 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 301 | + // Mettre les compteurs a zero |
|
| 302 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | + |
|
| 304 | + // |
|
| 305 | + // Publier et dater les rubriques qui ont un article publie |
|
| 306 | + // |
|
| 307 | + |
|
| 308 | + // Afficher les articles post-dates ? |
|
| 309 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | + |
|
| 312 | + $r = sql_select( |
|
| 313 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | + 'R.id_rubrique' |
|
| 317 | + ); |
|
| 318 | + while ($row = sql_fetch($r)) { |
|
| 319 | + sql_updateq( |
|
| 320 | + 'spip_rubriques', |
|
| 321 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | + 'id_rubrique=' . intval($row['id']) |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | + pipeline('calculer_rubriques', null); |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | + do { |
|
| 337 | + $continuer = false; |
|
| 338 | + $r = sql_select( |
|
| 339 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | + 'R.id_rubrique' |
|
| 343 | + ); |
|
| 344 | + while ($row = sql_fetch($r)) { |
|
| 345 | + sql_updateq( |
|
| 346 | + 'spip_rubriques', |
|
| 347 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | + 'id_rubrique=' . intval($row['id']) |
|
| 349 | + ); |
|
| 350 | + $continuer = true; |
|
| 351 | + } |
|
| 352 | + } while ($continuer); |
|
| 353 | + |
|
| 354 | + // Enregistrement des modifs |
|
| 355 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -367,123 +367,123 @@ discard block |
||
| 367 | 367 | * @return void |
| 368 | 368 | **/ |
| 369 | 369 | function propager_les_secteurs() { |
| 370 | - // Profondeur 0 |
|
| 371 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | - // et fixer les id_secteur des rubriques racines |
|
| 373 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | - // Toute rubrique non racine est de profondeur >0 |
|
| 375 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | - |
|
| 377 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | - |
|
| 380 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | - // on fait profondeur par profondeur |
|
| 382 | - |
|
| 383 | - $prof = 0; |
|
| 384 | - do { |
|
| 385 | - $continuer = false; |
|
| 386 | - |
|
| 387 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | - // on fixe le profondeur $prof+1 |
|
| 389 | - |
|
| 390 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | - // on teste A.profondeur > $prof+1 car : |
|
| 392 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | - $maxiter2 = $maxiter; |
|
| 396 | - while ( |
|
| 397 | - $maxiter2-- |
|
| 398 | - and $rows = sql_allfetsel( |
|
| 399 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | - '', |
|
| 403 | - 'R.id_secteur', |
|
| 404 | - '0,100' |
|
| 405 | - ) |
|
| 406 | - ) { |
|
| 407 | - $id_secteur = null; |
|
| 408 | - $ids = []; |
|
| 409 | - while ($row = array_shift($rows)) { |
|
| 410 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | - if (count($ids)) { |
|
| 412 | - sql_updateq( |
|
| 413 | - 'spip_rubriques', |
|
| 414 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | - sql_in('id_rubrique', $ids) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - $id_secteur = $row['id_secteur']; |
|
| 419 | - $ids = []; |
|
| 420 | - } |
|
| 421 | - $ids[] = $row['id']; |
|
| 422 | - } |
|
| 423 | - if (count($ids)) { |
|
| 424 | - sql_updateq( |
|
| 425 | - 'spip_rubriques', |
|
| 426 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | - sql_in('id_rubrique', $ids) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | - $maxiter2 = $maxiter; |
|
| 435 | - while ( |
|
| 436 | - $maxiter2-- |
|
| 437 | - and $rows = sql_allfetsel( |
|
| 438 | - 'id_rubrique as id', |
|
| 439 | - 'spip_rubriques', |
|
| 440 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | - 'zzz.id_rubrique', |
|
| 442 | - 'spip_rubriques AS zzz', |
|
| 443 | - 'zzz.profondeur=' . intval($prof) |
|
| 444 | - ) . ')', |
|
| 445 | - '', |
|
| 446 | - '', |
|
| 447 | - '0,100' |
|
| 448 | - ) |
|
| 449 | - ) { |
|
| 450 | - $rows = array_column($rows, 'id'); |
|
| 451 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | - // on arrete les frais |
|
| 458 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | - $prof++; |
|
| 460 | - $continuer = true; |
|
| 461 | - } |
|
| 462 | - } while ($continuer and $maxiter--); |
|
| 463 | - |
|
| 464 | - // loger si la table des rubriques semble foireuse |
|
| 465 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | - spip_log( |
|
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | - _LOG_CRITIQUE |
|
| 470 | - ); |
|
| 471 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // reparer les articles |
|
| 475 | - $r = sql_select( |
|
| 476 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | - ); |
|
| 480 | - |
|
| 481 | - while ($row = sql_fetch($r)) { |
|
| 482 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 370 | + // Profondeur 0 |
|
| 371 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | + // et fixer les id_secteur des rubriques racines |
|
| 373 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | + // Toute rubrique non racine est de profondeur >0 |
|
| 375 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | + |
|
| 377 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | + |
|
| 380 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | + // on fait profondeur par profondeur |
|
| 382 | + |
|
| 383 | + $prof = 0; |
|
| 384 | + do { |
|
| 385 | + $continuer = false; |
|
| 386 | + |
|
| 387 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | + // on fixe le profondeur $prof+1 |
|
| 389 | + |
|
| 390 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | + // on teste A.profondeur > $prof+1 car : |
|
| 392 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | + $maxiter2 = $maxiter; |
|
| 396 | + while ( |
|
| 397 | + $maxiter2-- |
|
| 398 | + and $rows = sql_allfetsel( |
|
| 399 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | + '', |
|
| 403 | + 'R.id_secteur', |
|
| 404 | + '0,100' |
|
| 405 | + ) |
|
| 406 | + ) { |
|
| 407 | + $id_secteur = null; |
|
| 408 | + $ids = []; |
|
| 409 | + while ($row = array_shift($rows)) { |
|
| 410 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | + if (count($ids)) { |
|
| 412 | + sql_updateq( |
|
| 413 | + 'spip_rubriques', |
|
| 414 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | + sql_in('id_rubrique', $ids) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + $id_secteur = $row['id_secteur']; |
|
| 419 | + $ids = []; |
|
| 420 | + } |
|
| 421 | + $ids[] = $row['id']; |
|
| 422 | + } |
|
| 423 | + if (count($ids)) { |
|
| 424 | + sql_updateq( |
|
| 425 | + 'spip_rubriques', |
|
| 426 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | + sql_in('id_rubrique', $ids) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | + $maxiter2 = $maxiter; |
|
| 435 | + while ( |
|
| 436 | + $maxiter2-- |
|
| 437 | + and $rows = sql_allfetsel( |
|
| 438 | + 'id_rubrique as id', |
|
| 439 | + 'spip_rubriques', |
|
| 440 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | + 'zzz.id_rubrique', |
|
| 442 | + 'spip_rubriques AS zzz', |
|
| 443 | + 'zzz.profondeur=' . intval($prof) |
|
| 444 | + ) . ')', |
|
| 445 | + '', |
|
| 446 | + '', |
|
| 447 | + '0,100' |
|
| 448 | + ) |
|
| 449 | + ) { |
|
| 450 | + $rows = array_column($rows, 'id'); |
|
| 451 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | + // on arrete les frais |
|
| 458 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | + $prof++; |
|
| 460 | + $continuer = true; |
|
| 461 | + } |
|
| 462 | + } while ($continuer and $maxiter--); |
|
| 463 | + |
|
| 464 | + // loger si la table des rubriques semble foireuse |
|
| 465 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | + spip_log( |
|
| 468 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | + _LOG_CRITIQUE |
|
| 470 | + ); |
|
| 471 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // reparer les articles |
|
| 475 | + $r = sql_select( |
|
| 476 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | + ); |
|
| 480 | + |
|
| 481 | + while ($row = sql_fetch($r)) { |
|
| 482 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -498,23 +498,23 @@ discard block |
||
| 498 | 498 | * true si un changement a eu lieu |
| 499 | 499 | **/ |
| 500 | 500 | function calculer_langues_rubriques_etape() { |
| 501 | - $s = sql_select( |
|
| 502 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | - ); |
|
| 506 | - |
|
| 507 | - $t = false; |
|
| 508 | - while ($row = sql_fetch($s)) { |
|
| 509 | - $id_rubrique = $row['id_rubrique']; |
|
| 510 | - $t = sql_updateq( |
|
| 511 | - 'spip_rubriques', |
|
| 512 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return $t; |
|
| 501 | + $s = sql_select( |
|
| 502 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | + ); |
|
| 506 | + |
|
| 507 | + $t = false; |
|
| 508 | + while ($row = sql_fetch($s)) { |
|
| 509 | + $id_rubrique = $row['id_rubrique']; |
|
| 510 | + $t = sql_updateq( |
|
| 511 | + 'spip_rubriques', |
|
| 512 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return $t; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -534,38 +534,38 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_langues_rubriques() { |
| 536 | 536 | |
| 537 | - // rubriques (recursivite) |
|
| 538 | - sql_updateq( |
|
| 539 | - 'spip_rubriques', |
|
| 540 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | - ); |
|
| 543 | - while (calculer_langues_rubriques_etape()) { |
|
| 544 | - ; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // articles |
|
| 548 | - $s = sql_select( |
|
| 549 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | - "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" |
|
| 552 | - ); |
|
| 553 | - while ($row = sql_fetch($s)) { |
|
| 554 | - $id_article = $row['id_article']; |
|
| 555 | - sql_updateq( |
|
| 556 | - 'spip_articles', |
|
| 557 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | - 'id_article=' . intval($id_article) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | - $langues = calculer_langues_utilisees(); |
|
| 564 | - ecrire_meta('langues_utilisees', $langues); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 537 | + // rubriques (recursivite) |
|
| 538 | + sql_updateq( |
|
| 539 | + 'spip_rubriques', |
|
| 540 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | + ); |
|
| 543 | + while (calculer_langues_rubriques_etape()) { |
|
| 544 | + ; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // articles |
|
| 548 | + $s = sql_select( |
|
| 549 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | + "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" |
|
| 552 | + ); |
|
| 553 | + while ($row = sql_fetch($s)) { |
|
| 554 | + $id_article = $row['id_article']; |
|
| 555 | + sql_updateq( |
|
| 556 | + 'spip_articles', |
|
| 557 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | + 'id_article=' . intval($id_article) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | + $langues = calculer_langues_utilisees(); |
|
| 564 | + ecrire_meta('langues_utilisees', $langues); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -582,80 +582,80 @@ discard block |
||
| 582 | 582 | * Liste des langues utilisées séparées par des virgules |
| 583 | 583 | **/ |
| 584 | 584 | function calculer_langues_utilisees($serveur = '') { |
| 585 | - include_spip('public/interfaces'); |
|
| 586 | - include_spip('public/compiler'); |
|
| 587 | - include_spip('public/composer'); |
|
| 588 | - include_spip('public/phraser_html'); |
|
| 589 | - $langues = []; |
|
| 590 | - |
|
| 591 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | - |
|
| 593 | - include_spip('base/objets'); |
|
| 594 | - $tables = lister_tables_objets_sql(); |
|
| 595 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | - |
|
| 597 | - foreach (array_keys($tables) as $t) { |
|
| 598 | - $desc = $trouver_table($t, $serveur); |
|
| 599 | - // c'est une table avec des langues |
|
| 600 | - if ( |
|
| 601 | - $desc['exist'] |
|
| 602 | - and isset($desc['field']['lang']) |
|
| 603 | - and isset($desc['field']['langue_choisie']) |
|
| 604 | - ) { |
|
| 605 | - $boucle = new Boucle(); |
|
| 606 | - $boucle->show = $desc; |
|
| 607 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | - $boucle->id_table = $desc['table_objet']; |
|
| 610 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | - $boucle->sql_serveur = $serveur; |
|
| 612 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | - $boucle->separateur[] = ','; |
|
| 615 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | - $boucle->iterateur = 'sql'; |
|
| 617 | - |
|
| 618 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | - $boucle->descr['gram'] = 'html'; |
|
| 621 | - |
|
| 622 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - isset($desc['statut']) |
|
| 626 | - and $desc['statut'] |
|
| 627 | - ) { |
|
| 628 | - $boucles = [ |
|
| 629 | - 'calculer_langues_utilisees' => $boucle, |
|
| 630 | - ]; |
|
| 631 | - // generer un nom de fonction "anonyme" unique |
|
| 632 | - do { |
|
| 633 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | - } while (function_exists($functionname)); |
|
| 635 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | - $res = ''; |
|
| 639 | - eval($code); |
|
| 640 | - $res = explode(',', $res); |
|
| 641 | - foreach ($res as $lang) { |
|
| 642 | - $langues[$lang] = 1; |
|
| 643 | - } |
|
| 644 | - } else { |
|
| 645 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | - while ($row = sql_fetch($res)) { |
|
| 647 | - $langues[$row['lang']] = 1; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - $langues = array_filter(array_keys($langues)); |
|
| 654 | - sort($langues); |
|
| 655 | - $langues = join(',', $langues); |
|
| 656 | - spip_log("langues utilisees: $langues"); |
|
| 657 | - |
|
| 658 | - return $langues; |
|
| 585 | + include_spip('public/interfaces'); |
|
| 586 | + include_spip('public/compiler'); |
|
| 587 | + include_spip('public/composer'); |
|
| 588 | + include_spip('public/phraser_html'); |
|
| 589 | + $langues = []; |
|
| 590 | + |
|
| 591 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | + |
|
| 593 | + include_spip('base/objets'); |
|
| 594 | + $tables = lister_tables_objets_sql(); |
|
| 595 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | + |
|
| 597 | + foreach (array_keys($tables) as $t) { |
|
| 598 | + $desc = $trouver_table($t, $serveur); |
|
| 599 | + // c'est une table avec des langues |
|
| 600 | + if ( |
|
| 601 | + $desc['exist'] |
|
| 602 | + and isset($desc['field']['lang']) |
|
| 603 | + and isset($desc['field']['langue_choisie']) |
|
| 604 | + ) { |
|
| 605 | + $boucle = new Boucle(); |
|
| 606 | + $boucle->show = $desc; |
|
| 607 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | + $boucle->id_table = $desc['table_objet']; |
|
| 610 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | + $boucle->sql_serveur = $serveur; |
|
| 612 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | + $boucle->separateur[] = ','; |
|
| 615 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | + $boucle->iterateur = 'sql'; |
|
| 617 | + |
|
| 618 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | + $boucle->descr['gram'] = 'html'; |
|
| 621 | + |
|
| 622 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + isset($desc['statut']) |
|
| 626 | + and $desc['statut'] |
|
| 627 | + ) { |
|
| 628 | + $boucles = [ |
|
| 629 | + 'calculer_langues_utilisees' => $boucle, |
|
| 630 | + ]; |
|
| 631 | + // generer un nom de fonction "anonyme" unique |
|
| 632 | + do { |
|
| 633 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | + } while (function_exists($functionname)); |
|
| 635 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | + $res = ''; |
|
| 639 | + eval($code); |
|
| 640 | + $res = explode(',', $res); |
|
| 641 | + foreach ($res as $lang) { |
|
| 642 | + $langues[$lang] = 1; |
|
| 643 | + } |
|
| 644 | + } else { |
|
| 645 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | + while ($row = sql_fetch($res)) { |
|
| 647 | + $langues[$row['lang']] = 1; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + $langues = array_filter(array_keys($langues)); |
|
| 654 | + sort($langues); |
|
| 655 | + $langues = join(',', $langues); |
|
| 656 | + spip_log("langues utilisees: $langues"); |
|
| 657 | + |
|
| 658 | + return $langues; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -672,9 +672,9 @@ discard block |
||
| 672 | 672 | * incluant les rubriques noeuds et toutes leurs descendances |
| 673 | 673 | */ |
| 674 | 674 | function calcul_branche_in($id) { |
| 675 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 676 | 676 | |
| 677 | - return $calcul_branche_in($id); |
|
| 677 | + return $calcul_branche_in($id); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * incluant les rubriques transmises et toutes leurs parentées |
| 693 | 693 | */ |
| 694 | 694 | function calcul_hierarchie_in($id, $tout = true) { |
| 695 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 696 | 696 | |
| 697 | - return $calcul_hierarchie_in($id, $tout); |
|
| 697 | + return $calcul_hierarchie_in($id, $tout); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -715,40 +715,40 @@ discard block |
||
| 715 | 715 | * incluant les rubriques noeuds et toutes leurs descendances |
| 716 | 716 | */ |
| 717 | 717 | function inc_calcul_branche_in_dist($id) { |
| 718 | - static $b = []; |
|
| 719 | - |
|
| 720 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | - if (!is_array($id)) { |
|
| 722 | - $id = explode(',', $id); |
|
| 723 | - } |
|
| 724 | - $id = join(',', array_map('intval', $id)); |
|
| 725 | - if (isset($b[$id])) { |
|
| 726 | - return $b[$id]; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // Notre branche commence par la rubrique de depart |
|
| 730 | - $branche = $r = $id; |
|
| 731 | - |
|
| 732 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | - $maxiter = 10000; |
|
| 735 | - while ( |
|
| 736 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | - 'id_rubrique', |
|
| 738 | - 'spip_rubriques', |
|
| 739 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | - ) |
|
| 741 | - ) { |
|
| 742 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | - $branche .= ',' . $r; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | - if (strlen($branche) < 10000) { |
|
| 748 | - $b[$id] = $branche; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $branche; |
|
| 718 | + static $b = []; |
|
| 719 | + |
|
| 720 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | + if (!is_array($id)) { |
|
| 722 | + $id = explode(',', $id); |
|
| 723 | + } |
|
| 724 | + $id = join(',', array_map('intval', $id)); |
|
| 725 | + if (isset($b[$id])) { |
|
| 726 | + return $b[$id]; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // Notre branche commence par la rubrique de depart |
|
| 730 | + $branche = $r = $id; |
|
| 731 | + |
|
| 732 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | + $maxiter = 10000; |
|
| 735 | + while ( |
|
| 736 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | + 'id_rubrique', |
|
| 738 | + 'spip_rubriques', |
|
| 739 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | + ) |
|
| 741 | + ) { |
|
| 742 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | + $branche .= ',' . $r; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | + if (strlen($branche) < 10000) { |
|
| 748 | + $b[$id] = $branche; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $branche; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -770,45 +770,45 @@ discard block |
||
| 770 | 770 | * incluant les rubriques transmises et toutes leurs parentées |
| 771 | 771 | */ |
| 772 | 772 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 773 | - static $b = []; |
|
| 774 | - |
|
| 775 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | - if (!is_array($id)) { |
|
| 777 | - $id = explode(',', $id); |
|
| 778 | - } |
|
| 779 | - $id = join(',', array_map('intval', $id)); |
|
| 780 | - |
|
| 781 | - if (isset($b[$id])) { |
|
| 782 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - $hier = ''; |
|
| 787 | - |
|
| 788 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | - $ids_nouveaux_parents = $id; |
|
| 791 | - $maxiter = 10000; |
|
| 792 | - while ( |
|
| 793 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | - 'id_parent', |
|
| 795 | - 'spip_rubriques', |
|
| 796 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | - ) |
|
| 798 | - ) { |
|
| 799 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | - if (strlen($hier) < 10000) { |
|
| 805 | - $b[$id] = $hier; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | - |
|
| 811 | - return $hier; |
|
| 773 | + static $b = []; |
|
| 774 | + |
|
| 775 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | + if (!is_array($id)) { |
|
| 777 | + $id = explode(',', $id); |
|
| 778 | + } |
|
| 779 | + $id = join(',', array_map('intval', $id)); |
|
| 780 | + |
|
| 781 | + if (isset($b[$id])) { |
|
| 782 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + $hier = ''; |
|
| 787 | + |
|
| 788 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | + $ids_nouveaux_parents = $id; |
|
| 791 | + $maxiter = 10000; |
|
| 792 | + while ( |
|
| 793 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | + 'id_parent', |
|
| 795 | + 'spip_rubriques', |
|
| 796 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | + ) |
|
| 798 | + ) { |
|
| 799 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | + if (strlen($hier) < 10000) { |
|
| 805 | + $b[$id] = $hier; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | + |
|
| 811 | + return $hier; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | |
@@ -826,47 +826,47 @@ discard block |
||
| 826 | 826 | * @return void |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_prochain_postdate($check = false) { |
| 829 | - include_spip('base/abstract_sql'); |
|
| 830 | - if ($check) { |
|
| 831 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | - |
|
| 834 | - $r = sql_select( |
|
| 835 | - 'DISTINCT A.id_rubrique AS id', |
|
| 836 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | - ); |
|
| 839 | - while ($row = sql_fetch($r)) { |
|
| 840 | - publier_branche_rubrique($row['id']); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $t = sql_fetsel( |
|
| 847 | - 'date', |
|
| 848 | - 'spip_articles', |
|
| 849 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | - '', |
|
| 851 | - 'date', |
|
| 852 | - '1' |
|
| 853 | - ); |
|
| 854 | - |
|
| 855 | - if ($t) { |
|
| 856 | - $t = $t['date']; |
|
| 857 | - if ( |
|
| 858 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | - ) { |
|
| 861 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | - ecrire_meta('derniere_modif', time()); |
|
| 863 | - } |
|
| 864 | - } else { |
|
| 865 | - effacer_meta('date_prochain_postdate'); |
|
| 866 | - ecrire_meta('derniere_modif', time()); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - spip_log("prochain postdate: $t"); |
|
| 829 | + include_spip('base/abstract_sql'); |
|
| 830 | + if ($check) { |
|
| 831 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | + |
|
| 834 | + $r = sql_select( |
|
| 835 | + 'DISTINCT A.id_rubrique AS id', |
|
| 836 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | + ); |
|
| 839 | + while ($row = sql_fetch($r)) { |
|
| 840 | + publier_branche_rubrique($row['id']); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $t = sql_fetsel( |
|
| 847 | + 'date', |
|
| 848 | + 'spip_articles', |
|
| 849 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | + '', |
|
| 851 | + 'date', |
|
| 852 | + '1' |
|
| 853 | + ); |
|
| 854 | + |
|
| 855 | + if ($t) { |
|
| 856 | + $t = $t['date']; |
|
| 857 | + if ( |
|
| 858 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | + ) { |
|
| 861 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | + ecrire_meta('derniere_modif', time()); |
|
| 863 | + } |
|
| 864 | + } else { |
|
| 865 | + effacer_meta('date_prochain_postdate'); |
|
| 866 | + ecrire_meta('derniere_modif', time()); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + spip_log("prochain postdate: $t"); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -891,62 +891,62 @@ discard block |
||
| 891 | 891 | */ |
| 892 | 892 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 893 | 893 | |
| 894 | - // eclater l'arborescence demandee |
|
| 895 | - // echapper les </multi> et autres balises fermantes html |
|
| 896 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | - include_spip('base/abstract_sql'); |
|
| 899 | - foreach ($arbo as $titre) { |
|
| 900 | - // retablir les </multi> et autres balises fermantes html |
|
| 901 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | - $r = sql_getfetsel( |
|
| 903 | - 'id_rubrique', |
|
| 904 | - 'spip_rubriques', |
|
| 905 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | - $groupby = [], |
|
| 907 | - $orderby = [], |
|
| 908 | - $limit = '', |
|
| 909 | - $having = [], |
|
| 910 | - $serveur |
|
| 911 | - ); |
|
| 912 | - if ($r !== null) { |
|
| 913 | - $id_parent = $r; |
|
| 914 | - } else { |
|
| 915 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | - 'titre' => $titre, |
|
| 917 | - 'id_parent' => $id_parent, |
|
| 918 | - 'statut' => 'prepa' |
|
| 919 | - ], $desc = [], $serveur); |
|
| 920 | - if ($id_parent > 0) { |
|
| 921 | - $data = sql_fetsel( |
|
| 922 | - 'id_secteur,lang', |
|
| 923 | - 'spip_rubriques', |
|
| 924 | - "id_rubrique=$id_parent", |
|
| 925 | - $groupby = [], |
|
| 926 | - $orderby = [], |
|
| 927 | - $limit = '', |
|
| 928 | - $having = [], |
|
| 929 | - $serveur |
|
| 930 | - ); |
|
| 931 | - $id_secteur = $data['id_secteur']; |
|
| 932 | - $lang = $data['lang']; |
|
| 933 | - } else { |
|
| 934 | - $id_secteur = $id_rubrique; |
|
| 935 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - sql_updateq( |
|
| 939 | - 'spip_rubriques', |
|
| 940 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | - $desc = '', |
|
| 943 | - $serveur |
|
| 944 | - ); |
|
| 945 | - |
|
| 946 | - // pour la recursion |
|
| 947 | - $id_parent = $id_rubrique; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return intval($id_parent); |
|
| 894 | + // eclater l'arborescence demandee |
|
| 895 | + // echapper les </multi> et autres balises fermantes html |
|
| 896 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | + include_spip('base/abstract_sql'); |
|
| 899 | + foreach ($arbo as $titre) { |
|
| 900 | + // retablir les </multi> et autres balises fermantes html |
|
| 901 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | + $r = sql_getfetsel( |
|
| 903 | + 'id_rubrique', |
|
| 904 | + 'spip_rubriques', |
|
| 905 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | + $groupby = [], |
|
| 907 | + $orderby = [], |
|
| 908 | + $limit = '', |
|
| 909 | + $having = [], |
|
| 910 | + $serveur |
|
| 911 | + ); |
|
| 912 | + if ($r !== null) { |
|
| 913 | + $id_parent = $r; |
|
| 914 | + } else { |
|
| 915 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | + 'titre' => $titre, |
|
| 917 | + 'id_parent' => $id_parent, |
|
| 918 | + 'statut' => 'prepa' |
|
| 919 | + ], $desc = [], $serveur); |
|
| 920 | + if ($id_parent > 0) { |
|
| 921 | + $data = sql_fetsel( |
|
| 922 | + 'id_secteur,lang', |
|
| 923 | + 'spip_rubriques', |
|
| 924 | + "id_rubrique=$id_parent", |
|
| 925 | + $groupby = [], |
|
| 926 | + $orderby = [], |
|
| 927 | + $limit = '', |
|
| 928 | + $having = [], |
|
| 929 | + $serveur |
|
| 930 | + ); |
|
| 931 | + $id_secteur = $data['id_secteur']; |
|
| 932 | + $lang = $data['lang']; |
|
| 933 | + } else { |
|
| 934 | + $id_secteur = $id_rubrique; |
|
| 935 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + sql_updateq( |
|
| 939 | + 'spip_rubriques', |
|
| 940 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | + $desc = '', |
|
| 943 | + $serveur |
|
| 944 | + ); |
|
| 945 | + |
|
| 946 | + // pour la recursion |
|
| 947 | + $id_parent = $id_rubrique; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return intval($id_parent); |
|
| 952 | 952 | } |
@@ -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 | /** |
@@ -45,29 +45,29 @@ discard block |
||
| 45 | 45 | * sinon code HTML de la page après le traitement effectué. |
| 46 | 46 | **/ |
| 47 | 47 | function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) { |
| 48 | - $reprise = true; |
|
| 49 | - if ( |
|
| 50 | - !isset($GLOBALS['meta'][$script]) |
|
| 51 | - or !isset($GLOBALS['meta']['admin']) |
|
| 52 | - ) { |
|
| 53 | - $reprise = false; |
|
| 54 | - $res = debut_admin($script, $titre, $comment); |
|
| 55 | - if ($res) { |
|
| 56 | - return $res; |
|
| 57 | - } |
|
| 58 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 59 | - ecrire_meta($script, serialize($_POST)); |
|
| 60 | - } |
|
| 48 | + $reprise = true; |
|
| 49 | + if ( |
|
| 50 | + !isset($GLOBALS['meta'][$script]) |
|
| 51 | + or !isset($GLOBALS['meta']['admin']) |
|
| 52 | + ) { |
|
| 53 | + $reprise = false; |
|
| 54 | + $res = debut_admin($script, $titre, $comment); |
|
| 55 | + if ($res) { |
|
| 56 | + return $res; |
|
| 57 | + } |
|
| 58 | + spip_log("meta: $script " . print_r($_POST, true)); |
|
| 59 | + ecrire_meta($script, serialize($_POST)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $res = admin_verifie_session($script, $anonymous); |
|
| 63 | - if ($res) { |
|
| 64 | - return $res; |
|
| 65 | - } |
|
| 66 | - $base = charger_fonction($script, 'base'); |
|
| 67 | - $base($titre, $reprise); |
|
| 68 | - fin_admin($script); |
|
| 62 | + $res = admin_verifie_session($script, $anonymous); |
|
| 63 | + if ($res) { |
|
| 64 | + return $res; |
|
| 65 | + } |
|
| 66 | + $base = charger_fonction($script, 'base'); |
|
| 67 | + $base($titre, $reprise); |
|
| 68 | + fin_admin($script); |
|
| 69 | 69 | |
| 70 | - return ''; |
|
| 70 | + return ''; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -98,35 +98,35 @@ discard block |
||
| 98 | 98 | * Code HTML si message d'erreur, '' sinon; |
| 99 | 99 | */ |
| 100 | 100 | function admin_verifie_session($script, $anonymous = false) { |
| 101 | - include_spip('base/abstract_sql'); |
|
| 102 | - $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 103 | - $signal = fichier_admin($script, "$script$pref"); |
|
| 104 | - $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 105 | - if ($valeur === null) { |
|
| 106 | - ecrire_meta('admin', $signal, 'non'); |
|
| 107 | - } else { |
|
| 108 | - if (!$anonymous and ($valeur != $signal)) { |
|
| 109 | - if ( |
|
| 110 | - !preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l) |
|
| 111 | - or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 112 | - ) { |
|
| 113 | - include_spip('inc/minipres'); |
|
| 114 | - spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 101 | + include_spip('base/abstract_sql'); |
|
| 102 | + $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 103 | + $signal = fichier_admin($script, "$script$pref"); |
|
| 104 | + $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 105 | + if ($valeur === null) { |
|
| 106 | + ecrire_meta('admin', $signal, 'non'); |
|
| 107 | + } else { |
|
| 108 | + if (!$anonymous and ($valeur != $signal)) { |
|
| 109 | + if ( |
|
| 110 | + !preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l) |
|
| 111 | + or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 112 | + ) { |
|
| 113 | + include_spip('inc/minipres'); |
|
| 114 | + spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 115 | 115 | |
| 116 | - return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $journal = 'spip'; |
|
| 121 | - if (autoriser('configurer')) { |
|
| 122 | - // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | - $journal = 'webmestre'; |
|
| 124 | - } |
|
| 125 | - // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 116 | + return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $journal = 'spip'; |
|
| 121 | + if (autoriser('configurer')) { |
|
| 122 | + // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | + $journal = 'webmestre'; |
|
| 124 | + } |
|
| 125 | + // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Chemin du répertoire. |
| 140 | 140 | **/ |
| 141 | 141 | function dir_admin() { |
| 142 | - if (autoriser('configurer')) { |
|
| 143 | - return _DIR_TMP; |
|
| 144 | - } else { |
|
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | - } |
|
| 142 | + if (autoriser('configurer')) { |
|
| 143 | + return _DIR_TMP; |
|
| 144 | + } else { |
|
| 145 | + return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref . |
|
| 164 | + substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -187,73 +187,73 @@ discard block |
||
| 187 | 187 | * sinon chaîne vide si déjà fait. |
| 188 | 188 | **/ |
| 189 | 189 | function debut_admin($script, $action = '', $corps = '') { |
| 190 | - if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) { |
|
| 191 | - include_spip('inc/minipres'); |
|
| 190 | + if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) { |
|
| 191 | + include_spip('inc/minipres'); |
|
| 192 | 192 | |
| 193 | - return minipres(); |
|
| 194 | - } else { |
|
| 195 | - $dir = dir_admin(); |
|
| 196 | - $signal = fichier_admin($script); |
|
| 197 | - if (@file_exists($dir . $signal)) { |
|
| 198 | - spip_log("Action admin: $action"); |
|
| 193 | + return minipres(); |
|
| 194 | + } else { |
|
| 195 | + $dir = dir_admin(); |
|
| 196 | + $signal = fichier_admin($script); |
|
| 197 | + if (@file_exists($dir . $signal)) { |
|
| 198 | + spip_log("Action admin: $action"); |
|
| 199 | 199 | |
| 200 | - return ''; |
|
| 201 | - } |
|
| 202 | - include_spip('inc/minipres'); |
|
| 200 | + return ''; |
|
| 201 | + } |
|
| 202 | + include_spip('inc/minipres'); |
|
| 203 | 203 | |
| 204 | - // Si on est un super-admin, un bouton de validation suffit |
|
| 205 | - // sauf dans les cas destroy |
|
| 206 | - if ( |
|
| 207 | - (autoriser('webmestre') or $script === 'repair') |
|
| 208 | - and $script != 'delete_all' |
|
| 209 | - ) { |
|
| 210 | - if (_request('validation_admin') == $signal) { |
|
| 211 | - spip_log("Action super-admin: $action"); |
|
| 204 | + // Si on est un super-admin, un bouton de validation suffit |
|
| 205 | + // sauf dans les cas destroy |
|
| 206 | + if ( |
|
| 207 | + (autoriser('webmestre') or $script === 'repair') |
|
| 208 | + and $script != 'delete_all' |
|
| 209 | + ) { |
|
| 210 | + if (_request('validation_admin') == $signal) { |
|
| 211 | + spip_log("Action super-admin: $action"); |
|
| 212 | 212 | |
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 216 | - $suivant = _T('bouton_valider'); |
|
| 217 | - $js = ''; |
|
| 218 | - } else { |
|
| 219 | - // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 220 | - // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 221 | - // mais evite de l'embarquer dans toutes les pages minipres |
|
| 222 | - $corps .= http_script('', 'spip_barre.js'); |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 216 | + $suivant = _T('bouton_valider'); |
|
| 217 | + $js = ''; |
|
| 218 | + } else { |
|
| 219 | + // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 220 | + // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 221 | + // mais evite de l'embarquer dans toutes les pages minipres |
|
| 222 | + $corps .= http_script('', 'spip_barre.js'); |
|
| 223 | 223 | |
| 224 | - $corps .= '<fieldset><legend>' |
|
| 225 | - . _T('info_authentification_ftp') |
|
| 226 | - . aider('ftp_auth') |
|
| 227 | - . "</legend>\n<label for='fichier'>" |
|
| 228 | - . _T('info_creer_repertoire') |
|
| 229 | - . "</label>\n" |
|
| 230 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 231 | - . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 232 | - . $signal |
|
| 233 | - . "' />" |
|
| 234 | - . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 235 | - . '</fieldset>'; |
|
| 224 | + $corps .= '<fieldset><legend>' |
|
| 225 | + . _T('info_authentification_ftp') |
|
| 226 | + . aider('ftp_auth') |
|
| 227 | + . "</legend>\n<label for='fichier'>" |
|
| 228 | + . _T('info_creer_repertoire') |
|
| 229 | + . "</label>\n" |
|
| 230 | + . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 231 | + . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 232 | + . $signal |
|
| 233 | + . "' />" |
|
| 234 | + . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 235 | + . '</fieldset>'; |
|
| 236 | 236 | |
| 237 | - $suivant = _T('bouton_recharger_page'); |
|
| 237 | + $suivant = _T('bouton_recharger_page'); |
|
| 238 | 238 | |
| 239 | - // code volontairement tordu: |
|
| 240 | - // provoquer la copie dans le presse papier du nom du repertoire |
|
| 241 | - // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 242 | - // de JavaScript inactif. |
|
| 243 | - $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 244 | - } |
|
| 239 | + // code volontairement tordu: |
|
| 240 | + // provoquer la copie dans le presse papier du nom du repertoire |
|
| 241 | + // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 242 | + // de JavaScript inactif. |
|
| 243 | + $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - // admin/xxx correspond |
|
| 247 | - // a exec/base_xxx de preference |
|
| 248 | - // et exec/xxx sinon (compat) |
|
| 249 | - if (tester_url_ecrire("base_$script")) { |
|
| 250 | - $script = "base_$script"; |
|
| 251 | - } |
|
| 252 | - $form = copy_request($script, $corps, $suivant); |
|
| 253 | - $info_action = _T('info_action', ['action' => "$action"]); |
|
| 246 | + // admin/xxx correspond |
|
| 247 | + // a exec/base_xxx de preference |
|
| 248 | + // et exec/xxx sinon (compat) |
|
| 249 | + if (tester_url_ecrire("base_$script")) { |
|
| 250 | + $script = "base_$script"; |
|
| 251 | + } |
|
| 252 | + $form = copy_request($script, $corps, $suivant); |
|
| 253 | + $info_action = _T('info_action', ['action' => "$action"]); |
|
| 254 | 254 | |
| 255 | - return minipres($info_action, $form, ['onload' => $js]); |
|
| 256 | - } |
|
| 255 | + return minipres($info_action, $form, ['onload' => $js]); |
|
| 256 | + } |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | * Nom de l'action (en base) qui a été exécutée |
| 265 | 265 | **/ |
| 266 | 266 | function fin_admin($action) { |
| 267 | - $signal = dir_admin() . fichier_admin($action); |
|
| 268 | - spip_unlink($signal); |
|
| 269 | - if ($action != 'delete_all') { |
|
| 270 | - effacer_meta($action); |
|
| 271 | - effacer_meta('admin'); |
|
| 272 | - spip_log("efface les meta admin et $action "); |
|
| 273 | - } |
|
| 267 | + $signal = dir_admin() . fichier_admin($action); |
|
| 268 | + spip_unlink($signal); |
|
| 269 | + if ($action != 'delete_all') { |
|
| 270 | + effacer_meta($action); |
|
| 271 | + effacer_meta('admin'); |
|
| 272 | + spip_log("efface les meta admin et $action "); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | * Code HTML du formulaire |
| 290 | 290 | **/ |
| 291 | 291 | function copy_request($script, $suite, $submit = '') { |
| 292 | - include_spip('inc/filtres'); |
|
| 293 | - foreach (array_merge($_POST, $_GET) as $n => $c) { |
|
| 294 | - if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) { |
|
| 295 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 296 | - entites_html($c) . |
|
| 297 | - "' />"; |
|
| 298 | - } |
|
| 299 | - } |
|
| 292 | + include_spip('inc/filtres'); |
|
| 293 | + foreach (array_merge($_POST, $_GET) as $n => $c) { |
|
| 294 | + if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) { |
|
| 295 | + $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 296 | + entites_html($c) . |
|
| 297 | + "' />"; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - return generer_form_ecrire($script, $suite, '', $submit); |
|
| 301 | + return generer_form_ecrire($script, $suite, '', $submit); |
|
| 302 | 302 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/cookie'); |
@@ -30,21 +30,21 @@ discard block |
||
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | 32 | function action_converser_dist() { |
| 33 | - $update_session = false; |
|
| 34 | - if (_request('arg') and spip_connect()) { |
|
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $securiser_action(); |
|
| 37 | - $update_session = true; |
|
| 38 | - } |
|
| 33 | + $update_session = false; |
|
| 34 | + if (_request('arg') and spip_connect()) { |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $securiser_action(); |
|
| 37 | + $update_session = true; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $lang = action_converser_changer_langue($update_session); |
|
| 41 | - $redirect = rawurldecode(_request('redirect')); |
|
| 40 | + $lang = action_converser_changer_langue($update_session); |
|
| 41 | + $redirect = rawurldecode(_request('redirect')); |
|
| 42 | 42 | |
| 43 | - if (!$redirect) { |
|
| 44 | - $redirect = _DIR_RESTREINT_ABS; |
|
| 45 | - } |
|
| 46 | - $redirect = parametre_url($redirect, 'lang', $lang, '&'); |
|
| 47 | - redirige_par_entete($redirect, true); |
|
| 43 | + if (!$redirect) { |
|
| 44 | + $redirect = _DIR_RESTREINT_ABS; |
|
| 45 | + } |
|
| 46 | + $redirect = parametre_url($redirect, 'lang', $lang, '&'); |
|
| 47 | + redirige_par_entete($redirect, true); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | function action_converser_changer_langue($update_session) { |
| 59 | - if ($lang = _request('var_lang')) { |
|
| 60 | - action_converser_post($lang); |
|
| 61 | - } elseif ($lang = _request('var_lang_ecrire')) { |
|
| 62 | - if ($update_session) { |
|
| 63 | - sql_updateq('spip_auteurs', ['lang' => $lang], 'id_auteur = ' . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 64 | - $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 65 | - $session = charger_fonction('session', 'inc'); |
|
| 66 | - if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 67 | - spip_setcookie('spip_session', $spip_session, [ |
|
| 68 | - 'expires' => time() + 3600 * 24 * 14 |
|
| 69 | - ]); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - action_converser_post($lang, true); |
|
| 73 | - } |
|
| 59 | + if ($lang = _request('var_lang')) { |
|
| 60 | + action_converser_post($lang); |
|
| 61 | + } elseif ($lang = _request('var_lang_ecrire')) { |
|
| 62 | + if ($update_session) { |
|
| 63 | + sql_updateq('spip_auteurs', ['lang' => $lang], 'id_auteur = ' . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 64 | + $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 65 | + $session = charger_fonction('session', 'inc'); |
|
| 66 | + if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 67 | + spip_setcookie('spip_session', $spip_session, [ |
|
| 68 | + 'expires' => time() + 3600 * 24 * 14 |
|
| 69 | + ]); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + action_converser_post($lang, true); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $lang; |
|
| 75 | + return $lang; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * @return void |
| 84 | 84 | */ |
| 85 | 85 | function action_converser_post($lang, $ecrire = false) { |
| 86 | - if ($lang) { |
|
| 87 | - include_spip('inc/lang'); |
|
| 88 | - if (changer_langue($lang)) { |
|
| 89 | - spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, [ |
|
| 90 | - 'expires' => time() + 365 * 24 * 3600 |
|
| 91 | - ]); |
|
| 92 | - if ($ecrire) { |
|
| 93 | - spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, [ |
|
| 94 | - 'expires' => time() + 365 * 24 * 3600 |
|
| 95 | - ]); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 86 | + if ($lang) { |
|
| 87 | + include_spip('inc/lang'); |
|
| 88 | + if (changer_langue($lang)) { |
|
| 89 | + spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, [ |
|
| 90 | + 'expires' => time() + 365 * 24 * 3600 |
|
| 91 | + ]); |
|
| 92 | + if ($ecrire) { |
|
| 93 | + spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, [ |
|
| 94 | + 'expires' => time() + 365 * 24 * 3600 |
|
| 95 | + ]); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 55 | - |
|
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - '&' |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - redirige_par_entete($redirect); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return [$id_rubrique, $err]; |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | + |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + '&' |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + redirige_par_entete($redirect); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return [$id_rubrique, $err]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -80,42 +80,42 @@ discard block |
||
| 80 | 80 | * Identifiant de la rubrique crée |
| 81 | 81 | */ |
| 82 | 82 | function rubrique_inserer($id_parent, $set = null) { |
| 83 | - $champs = [ |
|
| 84 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | - 'id_parent' => intval($id_parent), |
|
| 86 | - 'statut' => 'prepa' |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if ($set) { |
|
| 90 | - $champs = array_merge($champs, $set); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Envoyer aux plugins |
|
| 94 | - $champs = pipeline( |
|
| 95 | - 'pre_insertion', |
|
| 96 | - [ |
|
| 97 | - 'args' => [ |
|
| 98 | - 'table' => 'spip_rubriques', |
|
| 99 | - ], |
|
| 100 | - 'data' => $champs |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | - pipeline( |
|
| 106 | - 'post_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_rubriques', |
|
| 110 | - 'id_objet' => $id_rubrique |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - propager_les_secteurs(); |
|
| 116 | - calculer_langues_rubriques(); |
|
| 117 | - |
|
| 118 | - return $id_rubrique; |
|
| 83 | + $champs = [ |
|
| 84 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | + 'id_parent' => intval($id_parent), |
|
| 86 | + 'statut' => 'prepa' |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if ($set) { |
|
| 90 | + $champs = array_merge($champs, $set); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Envoyer aux plugins |
|
| 94 | + $champs = pipeline( |
|
| 95 | + 'pre_insertion', |
|
| 96 | + [ |
|
| 97 | + 'args' => [ |
|
| 98 | + 'table' => 'spip_rubriques', |
|
| 99 | + ], |
|
| 100 | + 'data' => $champs |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | + pipeline( |
|
| 106 | + 'post_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_rubriques', |
|
| 110 | + 'id_objet' => $id_rubrique |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + propager_les_secteurs(); |
|
| 116 | + calculer_langues_rubriques(); |
|
| 117 | + |
|
| 118 | + return $id_rubrique; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,46 +131,46 @@ discard block |
||
| 131 | 131 | * - chaîne : Texte d'un message d'erreur |
| 132 | 132 | */ |
| 133 | 133 | function rubrique_modifier($id_rubrique, $set = null) { |
| 134 | - include_spip('inc/autoriser'); |
|
| 135 | - include_spip('inc/filtres'); |
|
| 136 | - |
|
| 137 | - include_spip('inc/modifier'); |
|
| 138 | - $c = collecter_requests( |
|
| 139 | - // white list |
|
| 140 | - objet_info('rubrique', 'champs_editables'), |
|
| 141 | - // black list |
|
| 142 | - ['id_parent', 'confirme_deplace'], |
|
| 143 | - // donnees eventuellement fournies |
|
| 144 | - $set |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - if ( |
|
| 148 | - $err = objet_modifier_champs( |
|
| 149 | - 'rubrique', |
|
| 150 | - $id_rubrique, |
|
| 151 | - [ |
|
| 152 | - 'data' => $set, |
|
| 153 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | - ], |
|
| 155 | - $c |
|
| 156 | - ) |
|
| 157 | - ) { |
|
| 158 | - return $err; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | - // Deplacer la rubrique |
|
| 163 | - if (isset($c['id_parent'])) { |
|
| 164 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // invalider les caches marques de cette rubrique |
|
| 168 | - include_spip('inc/invalideur'); |
|
| 169 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | - // et celui de menu_rubriques |
|
| 171 | - effacer_meta('date_calcul_rubriques'); |
|
| 172 | - |
|
| 173 | - return $err; |
|
| 134 | + include_spip('inc/autoriser'); |
|
| 135 | + include_spip('inc/filtres'); |
|
| 136 | + |
|
| 137 | + include_spip('inc/modifier'); |
|
| 138 | + $c = collecter_requests( |
|
| 139 | + // white list |
|
| 140 | + objet_info('rubrique', 'champs_editables'), |
|
| 141 | + // black list |
|
| 142 | + ['id_parent', 'confirme_deplace'], |
|
| 143 | + // donnees eventuellement fournies |
|
| 144 | + $set |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + if ( |
|
| 148 | + $err = objet_modifier_champs( |
|
| 149 | + 'rubrique', |
|
| 150 | + $id_rubrique, |
|
| 151 | + [ |
|
| 152 | + 'data' => $set, |
|
| 153 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 154 | + ], |
|
| 155 | + $c |
|
| 156 | + ) |
|
| 157 | + ) { |
|
| 158 | + return $err; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 162 | + // Deplacer la rubrique |
|
| 163 | + if (isset($c['id_parent'])) { |
|
| 164 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // invalider les caches marques de cette rubrique |
|
| 168 | + include_spip('inc/invalideur'); |
|
| 169 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 170 | + // et celui de menu_rubriques |
|
| 171 | + effacer_meta('date_calcul_rubriques'); |
|
| 172 | + |
|
| 173 | + return $err; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -193,25 +193,25 @@ discard block |
||
| 193 | 193 | * false si la confirmation du déplacement n'est pas présente |
| 194 | 194 | */ |
| 195 | 195 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 196 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ( |
|
| 205 | - $id_secteur = sql_getfetsel( |
|
| 206 | - 'id_secteur', |
|
| 207 | - 'spip_rubriques', |
|
| 208 | - "id_rubrique=$id_parent" |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return true; |
|
| 196 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ( |
|
| 205 | + $id_secteur = sql_getfetsel( |
|
| 206 | + 'id_secteur', |
|
| 207 | + 'spip_rubriques', |
|
| 208 | + "id_rubrique=$id_parent" |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return true; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -233,50 +233,50 @@ discard block |
||
| 233 | 233 | * Chaîne : Texte du message d'erreur |
| 234 | 234 | */ |
| 235 | 235 | function rubrique_instituer($id_rubrique, $c) { |
| 236 | - // traitement de la rubrique parente |
|
| 237 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | - // qu'on n'administre pas. |
|
| 239 | - |
|
| 240 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | - $id_parent = intval($id_parent); |
|
| 242 | - $filles = calcul_branche_in($id_rubrique); |
|
| 243 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | - } else { |
|
| 246 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | - $old_parent = $s['id_parent']; |
|
| 248 | - |
|
| 249 | - if ( |
|
| 250 | - !($id_parent != $old_parent |
|
| 251 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | - ) |
|
| 255 | - ) { |
|
| 256 | - if ($s['statut'] != 'new') { |
|
| 257 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | - } |
|
| 259 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | - $statut_ancien = $s['statut']; |
|
| 261 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - propager_les_secteurs(); |
|
| 265 | - |
|
| 266 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | - if ($statut_ancien == 'publie') { |
|
| 268 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 269 | - } |
|
| 270 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | - // invalider le cache de leur menu |
|
| 272 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | - effacer_meta('date_calcul_rubriques'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - calculer_langues_rubriques(); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return ''; // pas d'erreur |
|
| 236 | + // traitement de la rubrique parente |
|
| 237 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 238 | + // qu'on n'administre pas. |
|
| 239 | + |
|
| 240 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 241 | + $id_parent = intval($id_parent); |
|
| 242 | + $filles = calcul_branche_in($id_rubrique); |
|
| 243 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 244 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 245 | + } else { |
|
| 246 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 247 | + $old_parent = $s['id_parent']; |
|
| 248 | + |
|
| 249 | + if ( |
|
| 250 | + !($id_parent != $old_parent |
|
| 251 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 252 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 253 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 254 | + ) |
|
| 255 | + ) { |
|
| 256 | + if ($s['statut'] != 'new') { |
|
| 257 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 258 | + } |
|
| 259 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 260 | + $statut_ancien = $s['statut']; |
|
| 261 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + propager_les_secteurs(); |
|
| 265 | + |
|
| 266 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 267 | + if ($statut_ancien == 'publie') { |
|
| 268 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 269 | + } |
|
| 270 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 271 | + // invalider le cache de leur menu |
|
| 272 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 273 | + effacer_meta('date_calcul_rubriques'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + calculer_langues_rubriques(); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return ''; // pas d'erreur |
|
| 282 | 282 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/cookie'); |
@@ -34,73 +34,73 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | */ |
| 36 | 36 | function action_logout_dist() { |
| 37 | - $logout = _request('logout'); |
|
| 38 | - $url = securiser_redirect_action(_request('url')); |
|
| 39 | - // cas particulier, logout dans l'espace public |
|
| 40 | - if ($logout == 'public' and !$url) { |
|
| 41 | - $url = url_de_base(); |
|
| 42 | - } |
|
| 37 | + $logout = _request('logout'); |
|
| 38 | + $url = securiser_redirect_action(_request('url')); |
|
| 39 | + // cas particulier, logout dans l'espace public |
|
| 40 | + if ($logout == 'public' and !$url) { |
|
| 41 | + $url = url_de_base(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | - if ( |
|
| 46 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | - and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | - // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | - and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | - ) { |
|
| 51 | - // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | - if ( |
|
| 53 | - !$jeton = _request('jeton') |
|
| 54 | - or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | - ) { |
|
| 56 | - $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | - $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | - $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | - $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | - include_spip('inc/minipres'); |
|
| 61 | - include_spip('inc/filtres'); |
|
| 62 | - $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | - $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | - $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | - $res = minipres(_T('spip:icone_deconnecter'), $texte, ['all_inline' => true]); |
|
| 66 | - echo $res; |
|
| 44 | + // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | + if ( |
|
| 46 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | + and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | + // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | + and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | + ) { |
|
| 51 | + // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | + if ( |
|
| 53 | + !$jeton = _request('jeton') |
|
| 54 | + or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | + ) { |
|
| 56 | + $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | + $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | + $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | + $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | + include_spip('inc/minipres'); |
|
| 61 | + include_spip('inc/filtres'); |
|
| 62 | + $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | + $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | + $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | + $res = minipres(_T('spip:icone_deconnecter'), $texte, ['all_inline' => true]); |
|
| 66 | + echo $res; |
|
| 67 | 67 | |
| 68 | - return; |
|
| 69 | - } |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - include_spip('inc/auth'); |
|
| 72 | - auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | - // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | - if (isset($_COOKIE['spip_session'])) { |
|
| 75 | - $session = charger_fonction('session', 'inc'); |
|
| 76 | - $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | - 'expires' => time() - 3600 |
|
| 79 | - ]); |
|
| 80 | - } |
|
| 81 | - // si authentification http, et que la personne est loge, |
|
| 82 | - // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | - if ( |
|
| 84 | - isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | - and !$GLOBALS['ignore_auth_http'] |
|
| 86 | - and $GLOBALS['auth_can_disconnect'] |
|
| 87 | - ) { |
|
| 88 | - ask_php_auth( |
|
| 89 | - _T('login_deconnexion_ok'), |
|
| 90 | - _T('login_verifiez_navigateur'), |
|
| 91 | - _T('login_retour_public'), |
|
| 92 | - 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | - _T('login_test_navigateur'), |
|
| 94 | - true |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 71 | + include_spip('inc/auth'); |
|
| 72 | + auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | + // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | + if (isset($_COOKIE['spip_session'])) { |
|
| 75 | + $session = charger_fonction('session', 'inc'); |
|
| 76 | + $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | + 'expires' => time() - 3600 |
|
| 79 | + ]); |
|
| 80 | + } |
|
| 81 | + // si authentification http, et que la personne est loge, |
|
| 82 | + // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | + if ( |
|
| 84 | + isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | + and !$GLOBALS['ignore_auth_http'] |
|
| 86 | + and $GLOBALS['auth_can_disconnect'] |
|
| 87 | + ) { |
|
| 88 | + ask_php_auth( |
|
| 89 | + _T('login_deconnexion_ok'), |
|
| 90 | + _T('login_verifiez_navigateur'), |
|
| 91 | + _T('login_retour_public'), |
|
| 92 | + 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | + _T('login_test_navigateur'), |
|
| 94 | + true |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | - include_spip('inc/headers'); |
|
| 101 | - redirige_par_entete($url |
|
| 102 | - ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | - : generer_url_public('login')); |
|
| 99 | + // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | + include_spip('inc/headers'); |
|
| 101 | + redirige_par_entete($url |
|
| 102 | + ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | + : generer_url_public('login')); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | 113 | function generer_jeton_logout($session, $alea = null) { |
| 114 | - if (is_null($alea)) { |
|
| 115 | - include_spip('inc/acces'); |
|
| 116 | - $alea = charger_aleas(); |
|
| 117 | - } |
|
| 114 | + if (is_null($alea)) { |
|
| 115 | + include_spip('inc/acces'); |
|
| 116 | + $alea = charger_aleas(); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $jeton = md5($session['date_session'] |
|
| 120 | - . $session['id_auteur'] |
|
| 121 | - . $session['statut'] |
|
| 122 | - . $alea); |
|
| 119 | + $jeton = md5($session['date_session'] |
|
| 120 | + . $session['id_auteur'] |
|
| 121 | + . $session['statut'] |
|
| 122 | + . $alea); |
|
| 123 | 123 | |
| 124 | - return $jeton; |
|
| 124 | + return $jeton; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | * @return bool |
| 136 | 136 | */ |
| 137 | 137 | function verifier_jeton_logout($jeton, $session) { |
| 138 | - if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 138 | + if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 142 | + if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return false; |
|
| 146 | + return false; |
|
| 147 | 147 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,43 +31,43 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | function action_instituer_langue_objet_dist($objet, $id, $id_rubrique, $changer_lang, $serveur = '') { |
| 34 | - if ($changer_lang) { |
|
| 35 | - $table_objet_sql = table_objet_sql($objet); |
|
| 36 | - $id_table_objet = id_table_objet($objet); |
|
| 37 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 38 | - $desc = $trouver_table($table_objet_sql, $serveur); |
|
| 34 | + if ($changer_lang) { |
|
| 35 | + $table_objet_sql = table_objet_sql($objet); |
|
| 36 | + $id_table_objet = id_table_objet($objet); |
|
| 37 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 38 | + $desc = $trouver_table($table_objet_sql, $serveur); |
|
| 39 | 39 | |
| 40 | - $set = []; |
|
| 41 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 42 | - $set['langue_choisie'] = 'oui'; |
|
| 43 | - } |
|
| 40 | + $set = []; |
|
| 41 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 42 | + $set['langue_choisie'] = 'oui'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if ($changer_lang != 'herit') { |
|
| 46 | - $set['lang'] = $changer_lang; |
|
| 47 | - sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 48 | - include_spip('inc/rubriques'); // pour calculer_langues_rubriques et calculer_langues_utilisees |
|
| 49 | - if ($table_objet_sql == 'spip_rubriques') { |
|
| 50 | - calculer_langues_rubriques(); |
|
| 51 | - } |
|
| 52 | - $langues = calculer_langues_utilisees($serveur); |
|
| 53 | - ecrire_meta('langues_utilisees', $langues); |
|
| 54 | - } else { |
|
| 55 | - $langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 56 | - if (!$langue_parent) { |
|
| 57 | - $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 58 | - } |
|
| 59 | - $changer_lang = $langue_parent; |
|
| 60 | - $set['lang'] = $changer_lang; |
|
| 61 | - if (isset($set['langue_choisie'])) { |
|
| 62 | - $set['langue_choisie'] = 'non'; |
|
| 63 | - } |
|
| 64 | - sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 65 | - if ($table_objet_sql == 'spip_rubriques') { |
|
| 66 | - include_spip('inc/rubriques'); |
|
| 67 | - calculer_langues_rubriques(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 45 | + if ($changer_lang != 'herit') { |
|
| 46 | + $set['lang'] = $changer_lang; |
|
| 47 | + sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 48 | + include_spip('inc/rubriques'); // pour calculer_langues_rubriques et calculer_langues_utilisees |
|
| 49 | + if ($table_objet_sql == 'spip_rubriques') { |
|
| 50 | + calculer_langues_rubriques(); |
|
| 51 | + } |
|
| 52 | + $langues = calculer_langues_utilisees($serveur); |
|
| 53 | + ecrire_meta('langues_utilisees', $langues); |
|
| 54 | + } else { |
|
| 55 | + $langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 56 | + if (!$langue_parent) { |
|
| 57 | + $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 58 | + } |
|
| 59 | + $changer_lang = $langue_parent; |
|
| 60 | + $set['lang'] = $changer_lang; |
|
| 61 | + if (isset($set['langue_choisie'])) { |
|
| 62 | + $set['langue_choisie'] = 'non'; |
|
| 63 | + } |
|
| 64 | + sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 65 | + if ($table_objet_sql == 'spip_rubriques') { |
|
| 66 | + include_spip('inc/rubriques'); |
|
| 67 | + calculer_langues_rubriques(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $changer_lang; |
|
| 72 | + return $changer_lang; |
|
| 73 | 73 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -39,36 +39,36 @@ discard block |
||
| 39 | 39 | * Liste (identifiant de l'article, Texte d'erreur éventuel) |
| 40 | 40 | */ |
| 41 | 41 | function action_editer_article_dist($arg = null) { |
| 42 | - include_spip('inc/autoriser'); |
|
| 43 | - $err = ''; |
|
| 44 | - if (is_null($arg)) { |
|
| 45 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | - $arg = $securiser_action(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 50 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | - if (!$id_article = intval($arg)) { |
|
| 52 | - $id_parent = _request('id_parent'); |
|
| 53 | - if (!$id_parent) { |
|
| 54 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | - } else { |
|
| 58 | - $id_article = article_inserer($id_parent); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - if ($id_article > 0) { |
|
| 64 | - $err = article_modifier($id_article); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if ($err) { |
|
| 68 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return [$id_article, $err]; |
|
| 42 | + include_spip('inc/autoriser'); |
|
| 43 | + $err = ''; |
|
| 44 | + if (is_null($arg)) { |
|
| 45 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $arg = $securiser_action(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 50 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | + if (!$id_article = intval($arg)) { |
|
| 52 | + $id_parent = _request('id_parent'); |
|
| 53 | + if (!$id_parent) { |
|
| 54 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | + } else { |
|
| 58 | + $id_article = article_inserer($id_parent); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + if ($id_article > 0) { |
|
| 64 | + $err = article_modifier($id_article); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if ($err) { |
|
| 68 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return [$id_article, $err]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -90,50 +90,50 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | function article_modifier($id_article, $set = null) { |
| 92 | 92 | |
| 93 | - // unifier $texte en cas de texte trop long |
|
| 94 | - trop_longs_articles(); |
|
| 95 | - |
|
| 96 | - include_spip('inc/modifier'); |
|
| 97 | - include_spip('inc/filtres'); |
|
| 98 | - $c = collecter_requests( |
|
| 99 | - // white list |
|
| 100 | - objet_info('article', 'champs_editables'), |
|
| 101 | - // black list |
|
| 102 | - ['date', 'statut', 'id_parent'], |
|
| 103 | - // donnees eventuellement fournies |
|
| 104 | - $set |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | - $invalideur = $indexation = false; |
|
| 110 | - if ($t == 'publie') { |
|
| 111 | - $invalideur = "id='article/$id_article'"; |
|
| 112 | - $indexation = true; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( |
|
| 116 | - $err = objet_modifier_champs( |
|
| 117 | - 'article', |
|
| 118 | - $id_article, |
|
| 119 | - [ |
|
| 120 | - 'data' => $set, |
|
| 121 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | - 'invalideur' => $invalideur, |
|
| 123 | - 'indexation' => $indexation, |
|
| 124 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | - ], |
|
| 126 | - $c |
|
| 127 | - ) |
|
| 128 | - ) { |
|
| 129 | - return $err; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Modification de statut, changement de rubrique ? |
|
| 133 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | - $err = article_instituer($id_article, $c); |
|
| 135 | - |
|
| 136 | - return $err; |
|
| 93 | + // unifier $texte en cas de texte trop long |
|
| 94 | + trop_longs_articles(); |
|
| 95 | + |
|
| 96 | + include_spip('inc/modifier'); |
|
| 97 | + include_spip('inc/filtres'); |
|
| 98 | + $c = collecter_requests( |
|
| 99 | + // white list |
|
| 100 | + objet_info('article', 'champs_editables'), |
|
| 101 | + // black list |
|
| 102 | + ['date', 'statut', 'id_parent'], |
|
| 103 | + // donnees eventuellement fournies |
|
| 104 | + $set |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | + $invalideur = $indexation = false; |
|
| 110 | + if ($t == 'publie') { |
|
| 111 | + $invalideur = "id='article/$id_article'"; |
|
| 112 | + $indexation = true; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( |
|
| 116 | + $err = objet_modifier_champs( |
|
| 117 | + 'article', |
|
| 118 | + $id_article, |
|
| 119 | + [ |
|
| 120 | + 'data' => $set, |
|
| 121 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | + 'invalideur' => $invalideur, |
|
| 123 | + 'indexation' => $indexation, |
|
| 124 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | + ], |
|
| 126 | + $c |
|
| 127 | + ) |
|
| 128 | + ) { |
|
| 129 | + return $err; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Modification de statut, changement de rubrique ? |
|
| 133 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | + $err = article_instituer($id_article, $c); |
|
| 135 | + |
|
| 136 | + return $err; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -169,98 +169,98 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function article_inserer($id_rubrique, $set = null) { |
| 171 | 171 | |
| 172 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | - // dans la premiere rubrique racine |
|
| 174 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | - $id_rubrique = $row['id_rubrique']; |
|
| 177 | - } else { |
|
| 178 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | - $lang_rub = $row['lang'] ?? ''; |
|
| 185 | - |
|
| 186 | - $lang = ''; |
|
| 187 | - $choisie = 'non'; |
|
| 188 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | - // ou a defaut celle de la rubrique |
|
| 191 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | - if ( |
|
| 193 | - !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | - 'spip_articles', |
|
| 195 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | - if ( |
|
| 200 | - in_array( |
|
| 201 | - $GLOBALS['spip_lang'], |
|
| 202 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | - ) |
|
| 204 | - ) { |
|
| 205 | - $lang = $GLOBALS['spip_lang']; |
|
| 206 | - $choisie = 'oui'; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!$lang) { |
|
| 211 | - $choisie = 'non'; |
|
| 212 | - $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $champs = [ |
|
| 216 | - 'id_rubrique' => $id_rubrique, |
|
| 217 | - 'id_secteur' => $id_secteur, |
|
| 218 | - 'statut' => 'prepa', |
|
| 219 | - 'date' => date('Y-m-d H:i:s'), |
|
| 220 | - 'lang' => $lang, |
|
| 221 | - 'langue_choisie' => $choisie |
|
| 222 | - ]; |
|
| 223 | - |
|
| 224 | - if ($set) { |
|
| 225 | - $champs = array_merge($champs, $set); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Envoyer aux plugins |
|
| 229 | - $champs = pipeline( |
|
| 230 | - 'pre_insertion', |
|
| 231 | - [ |
|
| 232 | - 'args' => [ |
|
| 233 | - 'table' => 'spip_articles', |
|
| 234 | - ], |
|
| 235 | - 'data' => $champs |
|
| 236 | - ] |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | - |
|
| 241 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | - if ($id_article > 0) { |
|
| 243 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | - : _request('id_auteur')); |
|
| 246 | - if ($id_auteur) { |
|
| 247 | - include_spip('action/editer_auteur'); |
|
| 248 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - pipeline( |
|
| 253 | - 'post_insertion', |
|
| 254 | - [ |
|
| 255 | - 'args' => [ |
|
| 256 | - 'table' => 'spip_articles', |
|
| 257 | - 'id_objet' => $id_article |
|
| 258 | - ], |
|
| 259 | - 'data' => $champs |
|
| 260 | - ] |
|
| 261 | - ); |
|
| 262 | - |
|
| 263 | - return $id_article; |
|
| 172 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | + // dans la premiere rubrique racine |
|
| 174 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | + $id_rubrique = $row['id_rubrique']; |
|
| 177 | + } else { |
|
| 178 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | + $lang_rub = $row['lang'] ?? ''; |
|
| 185 | + |
|
| 186 | + $lang = ''; |
|
| 187 | + $choisie = 'non'; |
|
| 188 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | + // ou a defaut celle de la rubrique |
|
| 191 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | + if ( |
|
| 193 | + !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | + 'spip_articles', |
|
| 195 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | + if ( |
|
| 200 | + in_array( |
|
| 201 | + $GLOBALS['spip_lang'], |
|
| 202 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | + ) |
|
| 204 | + ) { |
|
| 205 | + $lang = $GLOBALS['spip_lang']; |
|
| 206 | + $choisie = 'oui'; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!$lang) { |
|
| 211 | + $choisie = 'non'; |
|
| 212 | + $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $champs = [ |
|
| 216 | + 'id_rubrique' => $id_rubrique, |
|
| 217 | + 'id_secteur' => $id_secteur, |
|
| 218 | + 'statut' => 'prepa', |
|
| 219 | + 'date' => date('Y-m-d H:i:s'), |
|
| 220 | + 'lang' => $lang, |
|
| 221 | + 'langue_choisie' => $choisie |
|
| 222 | + ]; |
|
| 223 | + |
|
| 224 | + if ($set) { |
|
| 225 | + $champs = array_merge($champs, $set); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Envoyer aux plugins |
|
| 229 | + $champs = pipeline( |
|
| 230 | + 'pre_insertion', |
|
| 231 | + [ |
|
| 232 | + 'args' => [ |
|
| 233 | + 'table' => 'spip_articles', |
|
| 234 | + ], |
|
| 235 | + 'data' => $champs |
|
| 236 | + ] |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | + |
|
| 241 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | + if ($id_article > 0) { |
|
| 243 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | + : _request('id_auteur')); |
|
| 246 | + if ($id_auteur) { |
|
| 247 | + include_spip('action/editer_auteur'); |
|
| 248 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + pipeline( |
|
| 253 | + 'post_insertion', |
|
| 254 | + [ |
|
| 255 | + 'args' => [ |
|
| 256 | + 'table' => 'spip_articles', |
|
| 257 | + 'id_objet' => $id_article |
|
| 258 | + ], |
|
| 259 | + 'data' => $champs |
|
| 260 | + ] |
|
| 261 | + ); |
|
| 262 | + |
|
| 263 | + return $id_article; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -288,125 +288,125 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 290 | 290 | |
| 291 | - include_spip('inc/autoriser'); |
|
| 292 | - include_spip('inc/rubriques'); |
|
| 293 | - include_spip('inc/modifier'); |
|
| 294 | - |
|
| 295 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 296 | - $id_rubrique = $row['id_rubrique']; |
|
| 297 | - $statut_ancien = $statut = $row['statut']; |
|
| 298 | - $date_ancienne = $date = $row['date']; |
|
| 299 | - $champs = []; |
|
| 300 | - |
|
| 301 | - $d = $c['date'] ?? null; |
|
| 302 | - $s = $c['statut'] ?? $statut; |
|
| 303 | - |
|
| 304 | - // cf autorisations dans inc/instituer_article |
|
| 305 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 306 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 307 | - $statut = $champs['statut'] = $s; |
|
| 308 | - } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 309 | - $statut = $champs['statut'] = $s; |
|
| 310 | - } else { |
|
| 311 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // En cas de publication, fixer la date a "maintenant" |
|
| 315 | - // sauf si $c commande autre chose |
|
| 316 | - // ou si l'article est deja date dans le futur |
|
| 317 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 318 | - if ( |
|
| 319 | - $champs['statut'] == 'publie' |
|
| 320 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 321 | - ) { |
|
| 322 | - if ($d or strtotime($d = $date) > time()) { |
|
| 323 | - $champs['date'] = $date = $d; |
|
| 324 | - } else { |
|
| 325 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // Verifier que la rubrique demandee existe et est differente |
|
| 331 | - // de la rubrique actuelle |
|
| 332 | - if ( |
|
| 333 | - isset($c['id_parent']) |
|
| 334 | - and $id_parent = $c['id_parent'] |
|
| 335 | - and $id_parent != $id_rubrique |
|
| 336 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | - ) { |
|
| 338 | - $champs['id_rubrique'] = $id_parent; |
|
| 339 | - |
|
| 340 | - // si l'article etait publie |
|
| 341 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 342 | - // repasser l'article en statut 'propose'. |
|
| 343 | - if ( |
|
| 344 | - $statut == 'publie' |
|
| 345 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 346 | - ) { |
|
| 347 | - $champs['statut'] = 'prop'; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Envoyer aux plugins |
|
| 352 | - $champs = pipeline( |
|
| 353 | - 'pre_edition', |
|
| 354 | - [ |
|
| 355 | - 'args' => [ |
|
| 356 | - 'table' => 'spip_articles', |
|
| 357 | - 'id_objet' => $id_article, |
|
| 358 | - 'action' => 'instituer', |
|
| 359 | - 'statut_ancien' => $statut_ancien, |
|
| 360 | - 'date_ancienne' => $date_ancienne, |
|
| 361 | - ], |
|
| 362 | - 'data' => $champs |
|
| 363 | - ] |
|
| 364 | - ); |
|
| 365 | - |
|
| 366 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 367 | - return ''; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Envoyer les modifs. |
|
| 371 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 372 | - |
|
| 373 | - // Invalider les caches |
|
| 374 | - include_spip('inc/invalideur'); |
|
| 375 | - suivre_invalideur("id='article/$id_article'"); |
|
| 376 | - |
|
| 377 | - if ($date) { |
|
| 378 | - $t = strtotime($date); |
|
| 379 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 380 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 381 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // Pipeline |
|
| 386 | - pipeline( |
|
| 387 | - 'post_edition', |
|
| 388 | - [ |
|
| 389 | - 'args' => [ |
|
| 390 | - 'table' => 'spip_articles', |
|
| 391 | - 'id_objet' => $id_article, |
|
| 392 | - 'action' => 'instituer', |
|
| 393 | - 'statut_ancien' => $statut_ancien, |
|
| 394 | - 'date_ancienne' => $date_ancienne, |
|
| 395 | - ], |
|
| 396 | - 'data' => $champs |
|
| 397 | - ] |
|
| 398 | - ); |
|
| 399 | - |
|
| 400 | - // Notifications |
|
| 401 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 402 | - $notifications( |
|
| 403 | - 'instituerarticle', |
|
| 404 | - $id_article, |
|
| 405 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 406 | - ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return ''; // pas d'erreur |
|
| 291 | + include_spip('inc/autoriser'); |
|
| 292 | + include_spip('inc/rubriques'); |
|
| 293 | + include_spip('inc/modifier'); |
|
| 294 | + |
|
| 295 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 296 | + $id_rubrique = $row['id_rubrique']; |
|
| 297 | + $statut_ancien = $statut = $row['statut']; |
|
| 298 | + $date_ancienne = $date = $row['date']; |
|
| 299 | + $champs = []; |
|
| 300 | + |
|
| 301 | + $d = $c['date'] ?? null; |
|
| 302 | + $s = $c['statut'] ?? $statut; |
|
| 303 | + |
|
| 304 | + // cf autorisations dans inc/instituer_article |
|
| 305 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 306 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 307 | + $statut = $champs['statut'] = $s; |
|
| 308 | + } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 309 | + $statut = $champs['statut'] = $s; |
|
| 310 | + } else { |
|
| 311 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // En cas de publication, fixer la date a "maintenant" |
|
| 315 | + // sauf si $c commande autre chose |
|
| 316 | + // ou si l'article est deja date dans le futur |
|
| 317 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 318 | + if ( |
|
| 319 | + $champs['statut'] == 'publie' |
|
| 320 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 321 | + ) { |
|
| 322 | + if ($d or strtotime($d = $date) > time()) { |
|
| 323 | + $champs['date'] = $date = $d; |
|
| 324 | + } else { |
|
| 325 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // Verifier que la rubrique demandee existe et est differente |
|
| 331 | + // de la rubrique actuelle |
|
| 332 | + if ( |
|
| 333 | + isset($c['id_parent']) |
|
| 334 | + and $id_parent = $c['id_parent'] |
|
| 335 | + and $id_parent != $id_rubrique |
|
| 336 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | + ) { |
|
| 338 | + $champs['id_rubrique'] = $id_parent; |
|
| 339 | + |
|
| 340 | + // si l'article etait publie |
|
| 341 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 342 | + // repasser l'article en statut 'propose'. |
|
| 343 | + if ( |
|
| 344 | + $statut == 'publie' |
|
| 345 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 346 | + ) { |
|
| 347 | + $champs['statut'] = 'prop'; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Envoyer aux plugins |
|
| 352 | + $champs = pipeline( |
|
| 353 | + 'pre_edition', |
|
| 354 | + [ |
|
| 355 | + 'args' => [ |
|
| 356 | + 'table' => 'spip_articles', |
|
| 357 | + 'id_objet' => $id_article, |
|
| 358 | + 'action' => 'instituer', |
|
| 359 | + 'statut_ancien' => $statut_ancien, |
|
| 360 | + 'date_ancienne' => $date_ancienne, |
|
| 361 | + ], |
|
| 362 | + 'data' => $champs |
|
| 363 | + ] |
|
| 364 | + ); |
|
| 365 | + |
|
| 366 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 367 | + return ''; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Envoyer les modifs. |
|
| 371 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 372 | + |
|
| 373 | + // Invalider les caches |
|
| 374 | + include_spip('inc/invalideur'); |
|
| 375 | + suivre_invalideur("id='article/$id_article'"); |
|
| 376 | + |
|
| 377 | + if ($date) { |
|
| 378 | + $t = strtotime($date); |
|
| 379 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 380 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 381 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // Pipeline |
|
| 386 | + pipeline( |
|
| 387 | + 'post_edition', |
|
| 388 | + [ |
|
| 389 | + 'args' => [ |
|
| 390 | + 'table' => 'spip_articles', |
|
| 391 | + 'id_objet' => $id_article, |
|
| 392 | + 'action' => 'instituer', |
|
| 393 | + 'statut_ancien' => $statut_ancien, |
|
| 394 | + 'date_ancienne' => $date_ancienne, |
|
| 395 | + ], |
|
| 396 | + 'data' => $champs |
|
| 397 | + ] |
|
| 398 | + ); |
|
| 399 | + |
|
| 400 | + // Notifications |
|
| 401 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 402 | + $notifications( |
|
| 403 | + 'instituerarticle', |
|
| 404 | + $id_article, |
|
| 405 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return ''; // pas d'erreur |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -431,37 +431,37 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 433 | 433 | |
| 434 | - // Si on deplace l'article |
|
| 435 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 436 | - if (isset($champs['id_rubrique'])) { |
|
| 437 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | - |
|
| 439 | - $langue = $row_rub['lang']; |
|
| 440 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 441 | - if ( |
|
| 442 | - sql_fetsel( |
|
| 443 | - '1', |
|
| 444 | - 'spip_articles', |
|
| 445 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | - ) |
|
| 447 | - ) { |
|
| 448 | - $champs['lang'] = $langue; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - if (!$champs) { |
|
| 453 | - return; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | - |
|
| 458 | - // Changer le statut des rubriques concernees |
|
| 459 | - |
|
| 460 | - if ($cond) { |
|
| 461 | - include_spip('inc/rubriques'); |
|
| 462 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 463 | - calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 464 | - } |
|
| 434 | + // Si on deplace l'article |
|
| 435 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 436 | + if (isset($champs['id_rubrique'])) { |
|
| 437 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | + |
|
| 439 | + $langue = $row_rub['lang']; |
|
| 440 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 441 | + if ( |
|
| 442 | + sql_fetsel( |
|
| 443 | + '1', |
|
| 444 | + 'spip_articles', |
|
| 445 | + 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | + ) |
|
| 447 | + ) { |
|
| 448 | + $champs['lang'] = $langue; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + if (!$champs) { |
|
| 453 | + return; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | + |
|
| 458 | + // Changer le statut des rubriques concernees |
|
| 459 | + |
|
| 460 | + if ($cond) { |
|
| 461 | + include_spip('inc/rubriques'); |
|
| 462 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 463 | + calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -470,10 +470,10 @@ discard block |
||
| 470 | 470 | * @return void |
| 471 | 471 | */ |
| 472 | 472 | function trop_longs_articles() { |
| 473 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 474 | - foreach ($plus as $n => $t) { |
|
| 475 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 476 | - } |
|
| 477 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | - } |
|
| 473 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 474 | + foreach ($plus as $n => $t) { |
|
| 475 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 476 | + } |
|
| 477 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | + } |
|
| 479 | 479 | } |