@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -54,65 +54,65 @@ discard block |
||
| 54 | 54 | * @return void |
| 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 | - && include_spip('inc/filtres') |
|
| 72 | - && ($declaration_statut = objet_info($infos['objet'], 'statut')) |
|
| 73 | - && 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 | - || isset($modifs['id_rubrique']) |
|
| 89 | - || $postdate && 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']) && 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 | + && include_spip('inc/filtres') |
|
| 72 | + && ($declaration_statut = objet_info($infos['objet'], 'statut')) |
|
| 73 | + && 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 | + || isset($modifs['id_rubrique']) |
|
| 89 | + || $postdate && 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']) && 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_logger()->info(" 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_logger()->info("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_logger()->info("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 || $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 || $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_logger()->info("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,122 +367,122 @@ 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 | - && ($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 | - && ($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 && $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_logger()->critical( |
|
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | - ); |
|
| 470 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // reparer les articles |
|
| 474 | - $r = sql_select( |
|
| 475 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - while ($row = sql_fetch($r)) { |
|
| 481 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | - 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 | + && ($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 | + && ($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 && $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_logger()->critical( |
|
| 468 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | + ); |
|
| 470 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // reparer les articles |
|
| 474 | + $r = sql_select( |
|
| 475 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + while ($row = sql_fetch($r)) { |
|
| 481 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -497,23 +497,23 @@ discard block |
||
| 497 | 497 | * true si un changement a eu lieu |
| 498 | 498 | **/ |
| 499 | 499 | function calculer_langues_rubriques_etape() { |
| 500 | - $s = sql_select( |
|
| 501 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | - ); |
|
| 505 | - |
|
| 506 | - $t = false; |
|
| 507 | - while ($row = sql_fetch($s)) { |
|
| 508 | - $id_rubrique = $row['id_rubrique']; |
|
| 509 | - $t = sql_updateq( |
|
| 510 | - 'spip_rubriques', |
|
| 511 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | - ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $t; |
|
| 500 | + $s = sql_select( |
|
| 501 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | + ); |
|
| 505 | + |
|
| 506 | + $t = false; |
|
| 507 | + while ($row = sql_fetch($s)) { |
|
| 508 | + $id_rubrique = $row['id_rubrique']; |
|
| 509 | + $t = sql_updateq( |
|
| 510 | + 'spip_rubriques', |
|
| 511 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | + ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $t; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -533,38 +533,38 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function calculer_langues_rubriques() { |
| 535 | 535 | |
| 536 | - // rubriques (recursivite) |
|
| 537 | - sql_updateq( |
|
| 538 | - 'spip_rubriques', |
|
| 539 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | - ); |
|
| 542 | - while (calculer_langues_rubriques_etape()) { |
|
| 543 | - ; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // articles |
|
| 547 | - $s = sql_select( |
|
| 548 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | - "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" |
|
| 551 | - ); |
|
| 552 | - while ($row = sql_fetch($s)) { |
|
| 553 | - $id_article = $row['id_article']; |
|
| 554 | - sql_updateq( |
|
| 555 | - 'spip_articles', |
|
| 556 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | - 'id_article=' . intval($id_article) |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | - $langues = calculer_langues_utilisees(); |
|
| 563 | - ecrire_meta('langues_utilisees', $langues); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 536 | + // rubriques (recursivite) |
|
| 537 | + sql_updateq( |
|
| 538 | + 'spip_rubriques', |
|
| 539 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | + ); |
|
| 542 | + while (calculer_langues_rubriques_etape()) { |
|
| 543 | + ; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // articles |
|
| 547 | + $s = sql_select( |
|
| 548 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | + "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" |
|
| 551 | + ); |
|
| 552 | + while ($row = sql_fetch($s)) { |
|
| 553 | + $id_article = $row['id_article']; |
|
| 554 | + sql_updateq( |
|
| 555 | + 'spip_articles', |
|
| 556 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | + 'id_article=' . intval($id_article) |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | + $langues = calculer_langues_utilisees(); |
|
| 563 | + ecrire_meta('langues_utilisees', $langues); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -581,80 +581,80 @@ discard block |
||
| 581 | 581 | * Liste des langues utilisées séparées par des virgules |
| 582 | 582 | **/ |
| 583 | 583 | function calculer_langues_utilisees($serveur = '') { |
| 584 | - include_spip('public/interfaces'); |
|
| 585 | - include_spip('public/compiler'); |
|
| 586 | - include_spip('public/composer'); |
|
| 587 | - include_spip('public/phraser_html'); |
|
| 588 | - $langues = []; |
|
| 589 | - |
|
| 590 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | - |
|
| 592 | - include_spip('base/objets'); |
|
| 593 | - $tables = lister_tables_objets_sql(); |
|
| 594 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | - |
|
| 596 | - foreach (array_keys($tables) as $t) { |
|
| 597 | - $desc = $trouver_table($t, $serveur); |
|
| 598 | - // c'est une table avec des langues |
|
| 599 | - if ( |
|
| 600 | - $desc['exist'] |
|
| 601 | - && isset($desc['field']['lang']) |
|
| 602 | - && isset($desc['field']['langue_choisie']) |
|
| 603 | - ) { |
|
| 604 | - $boucle = new Boucle(); |
|
| 605 | - $boucle->show = $desc; |
|
| 606 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | - $boucle->id_table = $desc['table_objet']; |
|
| 609 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | - $boucle->sql_serveur = $serveur; |
|
| 611 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | - $boucle->separateur[] = ','; |
|
| 614 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | - $boucle->iterateur = 'sql'; |
|
| 616 | - |
|
| 617 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | - $boucle->descr['gram'] = 'html'; |
|
| 620 | - |
|
| 621 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | - |
|
| 623 | - if ( |
|
| 624 | - isset($desc['statut']) |
|
| 625 | - && $desc['statut'] |
|
| 626 | - ) { |
|
| 627 | - $boucles = [ |
|
| 628 | - 'calculer_langues_utilisees' => $boucle, |
|
| 629 | - ]; |
|
| 630 | - // generer un nom de fonction "anonyme" unique |
|
| 631 | - do { |
|
| 632 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 633 | - } while (function_exists($functionname)); |
|
| 634 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | - $res = ''; |
|
| 638 | - eval($code); |
|
| 639 | - $res = explode(',', $res); |
|
| 640 | - foreach ($res as $lang) { |
|
| 641 | - $langues[$lang] = 1; |
|
| 642 | - } |
|
| 643 | - } else { |
|
| 644 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | - while ($row = sql_fetch($res)) { |
|
| 646 | - $langues[$row['lang']] = 1; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $langues = array_filter(array_keys($langues)); |
|
| 653 | - sort($langues); |
|
| 654 | - $langues = join(',', $langues); |
|
| 655 | - spip_logger()->info("langues utilisees: $langues"); |
|
| 656 | - |
|
| 657 | - return $langues; |
|
| 584 | + include_spip('public/interfaces'); |
|
| 585 | + include_spip('public/compiler'); |
|
| 586 | + include_spip('public/composer'); |
|
| 587 | + include_spip('public/phraser_html'); |
|
| 588 | + $langues = []; |
|
| 589 | + |
|
| 590 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | + |
|
| 592 | + include_spip('base/objets'); |
|
| 593 | + $tables = lister_tables_objets_sql(); |
|
| 594 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | + |
|
| 596 | + foreach (array_keys($tables) as $t) { |
|
| 597 | + $desc = $trouver_table($t, $serveur); |
|
| 598 | + // c'est une table avec des langues |
|
| 599 | + if ( |
|
| 600 | + $desc['exist'] |
|
| 601 | + && isset($desc['field']['lang']) |
|
| 602 | + && isset($desc['field']['langue_choisie']) |
|
| 603 | + ) { |
|
| 604 | + $boucle = new Boucle(); |
|
| 605 | + $boucle->show = $desc; |
|
| 606 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | + $boucle->id_table = $desc['table_objet']; |
|
| 609 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | + $boucle->sql_serveur = $serveur; |
|
| 611 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | + $boucle->separateur[] = ','; |
|
| 614 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | + $boucle->iterateur = 'sql'; |
|
| 616 | + |
|
| 617 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | + $boucle->descr['gram'] = 'html'; |
|
| 620 | + |
|
| 621 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | + |
|
| 623 | + if ( |
|
| 624 | + isset($desc['statut']) |
|
| 625 | + && $desc['statut'] |
|
| 626 | + ) { |
|
| 627 | + $boucles = [ |
|
| 628 | + 'calculer_langues_utilisees' => $boucle, |
|
| 629 | + ]; |
|
| 630 | + // generer un nom de fonction "anonyme" unique |
|
| 631 | + do { |
|
| 632 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 633 | + } while (function_exists($functionname)); |
|
| 634 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | + $res = ''; |
|
| 638 | + eval($code); |
|
| 639 | + $res = explode(',', $res); |
|
| 640 | + foreach ($res as $lang) { |
|
| 641 | + $langues[$lang] = 1; |
|
| 642 | + } |
|
| 643 | + } else { |
|
| 644 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | + while ($row = sql_fetch($res)) { |
|
| 646 | + $langues[$row['lang']] = 1; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $langues = array_filter(array_keys($langues)); |
|
| 653 | + sort($langues); |
|
| 654 | + $langues = join(',', $langues); |
|
| 655 | + spip_logger()->info("langues utilisees: $langues"); |
|
| 656 | + |
|
| 657 | + return $langues; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -671,9 +671,9 @@ discard block |
||
| 671 | 671 | * incluant les rubriques noeuds et toutes leurs descendances |
| 672 | 672 | */ |
| 673 | 673 | function calcul_branche_in($id) { |
| 674 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 674 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | 675 | |
| 676 | - return $calcul_branche_in($id); |
|
| 676 | + return $calcul_branche_in($id); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -691,9 +691,9 @@ discard block |
||
| 691 | 691 | * incluant les rubriques transmises et toutes leurs parentées |
| 692 | 692 | */ |
| 693 | 693 | function calcul_hierarchie_in($id, $tout = true) { |
| 694 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 694 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | 695 | |
| 696 | - return $calcul_hierarchie_in($id, $tout); |
|
| 696 | + return $calcul_hierarchie_in($id, $tout); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -714,40 +714,40 @@ discard block |
||
| 714 | 714 | * incluant les rubriques noeuds et toutes leurs descendances |
| 715 | 715 | */ |
| 716 | 716 | function inc_calcul_branche_in_dist($id) { |
| 717 | - static $b = []; |
|
| 718 | - |
|
| 719 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | - if (!is_array($id)) { |
|
| 721 | - $id = explode(',', $id); |
|
| 722 | - } |
|
| 723 | - $id = join(',', array_map('intval', $id)); |
|
| 724 | - if (isset($b[$id])) { |
|
| 725 | - return $b[$id]; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // Notre branche commence par la rubrique de depart |
|
| 729 | - $branche = $r = $id; |
|
| 730 | - |
|
| 731 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | - $maxiter = 10000; |
|
| 734 | - while ( |
|
| 735 | - $maxiter-- && ($filles = sql_allfetsel( |
|
| 736 | - 'id_rubrique', |
|
| 737 | - 'spip_rubriques', |
|
| 738 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | - )) |
|
| 740 | - ) { |
|
| 741 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | - $branche .= ',' . $r; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | - if (strlen($branche) < 10000) { |
|
| 747 | - $b[$id] = $branche; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - return $branche; |
|
| 717 | + static $b = []; |
|
| 718 | + |
|
| 719 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | + if (!is_array($id)) { |
|
| 721 | + $id = explode(',', $id); |
|
| 722 | + } |
|
| 723 | + $id = join(',', array_map('intval', $id)); |
|
| 724 | + if (isset($b[$id])) { |
|
| 725 | + return $b[$id]; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // Notre branche commence par la rubrique de depart |
|
| 729 | + $branche = $r = $id; |
|
| 730 | + |
|
| 731 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | + $maxiter = 10000; |
|
| 734 | + while ( |
|
| 735 | + $maxiter-- && ($filles = sql_allfetsel( |
|
| 736 | + 'id_rubrique', |
|
| 737 | + 'spip_rubriques', |
|
| 738 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | + )) |
|
| 740 | + ) { |
|
| 741 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | + $branche .= ',' . $r; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | + if (strlen($branche) < 10000) { |
|
| 747 | + $b[$id] = $branche; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + return $branche; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | |
@@ -769,45 +769,45 @@ discard block |
||
| 769 | 769 | * incluant les rubriques transmises et toutes leurs parentées |
| 770 | 770 | */ |
| 771 | 771 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 772 | - static $b = []; |
|
| 773 | - |
|
| 774 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | - if (!is_array($id)) { |
|
| 776 | - $id = explode(',', $id); |
|
| 777 | - } |
|
| 778 | - $id = join(',', array_map('intval', $id)); |
|
| 779 | - |
|
| 780 | - if (isset($b[$id])) { |
|
| 781 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $hier = ''; |
|
| 786 | - |
|
| 787 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | - $ids_nouveaux_parents = $id; |
|
| 790 | - $maxiter = 10000; |
|
| 791 | - while ( |
|
| 792 | - $maxiter-- && ($parents = sql_allfetsel( |
|
| 793 | - 'id_parent', |
|
| 794 | - 'spip_rubriques', |
|
| 795 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | - )) |
|
| 797 | - ) { |
|
| 798 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | - if (strlen($hier) < 10000) { |
|
| 804 | - $b[$id] = $hier; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | - |
|
| 810 | - return $hier; |
|
| 772 | + static $b = []; |
|
| 773 | + |
|
| 774 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | + if (!is_array($id)) { |
|
| 776 | + $id = explode(',', $id); |
|
| 777 | + } |
|
| 778 | + $id = join(',', array_map('intval', $id)); |
|
| 779 | + |
|
| 780 | + if (isset($b[$id])) { |
|
| 781 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $hier = ''; |
|
| 786 | + |
|
| 787 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | + $ids_nouveaux_parents = $id; |
|
| 790 | + $maxiter = 10000; |
|
| 791 | + while ( |
|
| 792 | + $maxiter-- && ($parents = sql_allfetsel( |
|
| 793 | + 'id_parent', |
|
| 794 | + 'spip_rubriques', |
|
| 795 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | + )) |
|
| 797 | + ) { |
|
| 798 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | + if (strlen($hier) < 10000) { |
|
| 804 | + $b[$id] = $hier; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | + |
|
| 810 | + return $hier; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
@@ -825,47 +825,47 @@ discard block |
||
| 825 | 825 | * @return void |
| 826 | 826 | **/ |
| 827 | 827 | function calculer_prochain_postdate($check = false) { |
| 828 | - include_spip('base/abstract_sql'); |
|
| 829 | - if ($check) { |
|
| 830 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | - |
|
| 833 | - $r = sql_select( |
|
| 834 | - 'DISTINCT A.id_rubrique AS id', |
|
| 835 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | - ); |
|
| 838 | - while ($row = sql_fetch($r)) { |
|
| 839 | - publier_branche_rubrique($row['id']); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $t = sql_fetsel( |
|
| 846 | - 'date', |
|
| 847 | - 'spip_articles', |
|
| 848 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | - '', |
|
| 850 | - 'date', |
|
| 851 | - '1' |
|
| 852 | - ); |
|
| 853 | - |
|
| 854 | - if ($t) { |
|
| 855 | - $t = $t['date']; |
|
| 856 | - if ( |
|
| 857 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | - || $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | - ) { |
|
| 860 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | - ecrire_meta('derniere_modif', time()); |
|
| 862 | - } |
|
| 863 | - } else { |
|
| 864 | - effacer_meta('date_prochain_postdate'); |
|
| 865 | - ecrire_meta('derniere_modif', time()); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - spip_logger()->info("prochain postdate: $t"); |
|
| 828 | + include_spip('base/abstract_sql'); |
|
| 829 | + if ($check) { |
|
| 830 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | + |
|
| 833 | + $r = sql_select( |
|
| 834 | + 'DISTINCT A.id_rubrique AS id', |
|
| 835 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | + ); |
|
| 838 | + while ($row = sql_fetch($r)) { |
|
| 839 | + publier_branche_rubrique($row['id']); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $t = sql_fetsel( |
|
| 846 | + 'date', |
|
| 847 | + 'spip_articles', |
|
| 848 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | + '', |
|
| 850 | + 'date', |
|
| 851 | + '1' |
|
| 852 | + ); |
|
| 853 | + |
|
| 854 | + if ($t) { |
|
| 855 | + $t = $t['date']; |
|
| 856 | + if ( |
|
| 857 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | + || $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | + ) { |
|
| 860 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | + ecrire_meta('derniere_modif', time()); |
|
| 862 | + } |
|
| 863 | + } else { |
|
| 864 | + effacer_meta('date_prochain_postdate'); |
|
| 865 | + ecrire_meta('derniere_modif', time()); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + spip_logger()->info("prochain postdate: $t"); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -890,62 +890,62 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 892 | 892 | |
| 893 | - // eclater l'arborescence demandee |
|
| 894 | - // echapper les </multi> et autres balises fermantes html |
|
| 895 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | - include_spip('base/abstract_sql'); |
|
| 898 | - foreach ($arbo as $titre) { |
|
| 899 | - // retablir les </multi> et autres balises fermantes html |
|
| 900 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | - $r = sql_getfetsel( |
|
| 902 | - 'id_rubrique', |
|
| 903 | - 'spip_rubriques', |
|
| 904 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | - $groupby = [], |
|
| 906 | - $orderby = [], |
|
| 907 | - $limit = '', |
|
| 908 | - $having = [], |
|
| 909 | - $serveur |
|
| 910 | - ); |
|
| 911 | - if ($r !== null) { |
|
| 912 | - $id_parent = $r; |
|
| 913 | - } else { |
|
| 914 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | - 'titre' => $titre, |
|
| 916 | - 'id_parent' => $id_parent, |
|
| 917 | - 'statut' => 'prepa' |
|
| 918 | - ], $desc = [], $serveur); |
|
| 919 | - if ($id_parent > 0) { |
|
| 920 | - $data = sql_fetsel( |
|
| 921 | - 'id_secteur,lang', |
|
| 922 | - 'spip_rubriques', |
|
| 923 | - "id_rubrique=$id_parent", |
|
| 924 | - $groupby = [], |
|
| 925 | - $orderby = [], |
|
| 926 | - $limit = '', |
|
| 927 | - $having = [], |
|
| 928 | - $serveur |
|
| 929 | - ); |
|
| 930 | - $id_secteur = $data['id_secteur']; |
|
| 931 | - $lang = $data['lang']; |
|
| 932 | - } else { |
|
| 933 | - $id_secteur = $id_rubrique; |
|
| 934 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - sql_updateq( |
|
| 938 | - 'spip_rubriques', |
|
| 939 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | - [], |
|
| 942 | - $serveur |
|
| 943 | - ); |
|
| 944 | - |
|
| 945 | - // pour la recursion |
|
| 946 | - $id_parent = $id_rubrique; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return intval($id_parent); |
|
| 893 | + // eclater l'arborescence demandee |
|
| 894 | + // echapper les </multi> et autres balises fermantes html |
|
| 895 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | + include_spip('base/abstract_sql'); |
|
| 898 | + foreach ($arbo as $titre) { |
|
| 899 | + // retablir les </multi> et autres balises fermantes html |
|
| 900 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | + $r = sql_getfetsel( |
|
| 902 | + 'id_rubrique', |
|
| 903 | + 'spip_rubriques', |
|
| 904 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | + $groupby = [], |
|
| 906 | + $orderby = [], |
|
| 907 | + $limit = '', |
|
| 908 | + $having = [], |
|
| 909 | + $serveur |
|
| 910 | + ); |
|
| 911 | + if ($r !== null) { |
|
| 912 | + $id_parent = $r; |
|
| 913 | + } else { |
|
| 914 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | + 'titre' => $titre, |
|
| 916 | + 'id_parent' => $id_parent, |
|
| 917 | + 'statut' => 'prepa' |
|
| 918 | + ], $desc = [], $serveur); |
|
| 919 | + if ($id_parent > 0) { |
|
| 920 | + $data = sql_fetsel( |
|
| 921 | + 'id_secteur,lang', |
|
| 922 | + 'spip_rubriques', |
|
| 923 | + "id_rubrique=$id_parent", |
|
| 924 | + $groupby = [], |
|
| 925 | + $orderby = [], |
|
| 926 | + $limit = '', |
|
| 927 | + $having = [], |
|
| 928 | + $serveur |
|
| 929 | + ); |
|
| 930 | + $id_secteur = $data['id_secteur']; |
|
| 931 | + $lang = $data['lang']; |
|
| 932 | + } else { |
|
| 933 | + $id_secteur = $id_rubrique; |
|
| 934 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + sql_updateq( |
|
| 938 | + 'spip_rubriques', |
|
| 939 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | + [], |
|
| 942 | + $serveur |
|
| 943 | + ); |
|
| 944 | + |
|
| 945 | + // pour la recursion |
|
| 946 | + $id_parent = $id_rubrique; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return intval($id_parent); |
|
| 951 | 951 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Actions |
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | - use Spip\Chiffrer\SpipCles; |
|
| 18 | + use Spip\Chiffrer\SpipCles; |
|
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -51,19 +51,19 @@ discard block |
||
| 51 | 51 | * @return array|string |
| 52 | 52 | */ |
| 53 | 53 | function inc_securiser_action_dist($action = '', $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 54 | - if ($action) { |
|
| 55 | - return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 56 | - } else { |
|
| 57 | - $arg = _request('arg'); |
|
| 58 | - $hash = _request('hash'); |
|
| 59 | - $action = _request('action') ?: _request('formulaire_action'); |
|
| 60 | - if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 61 | - return $arg; |
|
| 62 | - } |
|
| 63 | - include_spip('inc/minipres'); |
|
| 64 | - echo minipres(); |
|
| 65 | - exit; |
|
| 66 | - } |
|
| 54 | + if ($action) { |
|
| 55 | + return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 56 | + } else { |
|
| 57 | + $arg = _request('arg'); |
|
| 58 | + $hash = _request('hash'); |
|
| 59 | + $action = _request('action') ?: _request('formulaire_action'); |
|
| 60 | + if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 61 | + return $arg; |
|
| 62 | + } |
|
| 63 | + include_spip('inc/minipres'); |
|
| 64 | + echo minipres(); |
|
| 65 | + exit; |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function demander_confirmation_avant_action($titre, $titre_bouton, $url_action = null) { |
| 84 | 84 | |
| 85 | - if (!$url_action) { |
|
| 86 | - $url_action = self(); |
|
| 87 | - $action = _request('action'); |
|
| 88 | - $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 89 | - } |
|
| 90 | - else { |
|
| 91 | - $action = parametre_url($url_action, 'action'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $arg = parametre_url($url_action, 'arg'); |
|
| 95 | - $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 96 | - if (_request('confirm_action') === $confirm) { |
|
| 97 | - return true; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 101 | - include_spip('inc/filtres'); |
|
| 102 | - $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 103 | - $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 104 | - |
|
| 105 | - include_spip('inc/minipres'); |
|
| 106 | - echo minipres($titre, $corps); |
|
| 107 | - exit; |
|
| 85 | + if (!$url_action) { |
|
| 86 | + $url_action = self(); |
|
| 87 | + $action = _request('action'); |
|
| 88 | + $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 89 | + } |
|
| 90 | + else { |
|
| 91 | + $action = parametre_url($url_action, 'action'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $arg = parametre_url($url_action, 'arg'); |
|
| 95 | + $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 96 | + if (_request('confirm_action') === $confirm) { |
|
| 97 | + return true; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 101 | + include_spip('inc/filtres'); |
|
| 102 | + $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 103 | + $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 104 | + |
|
| 105 | + include_spip('inc/minipres'); |
|
| 106 | + echo minipres($titre, $corps); |
|
| 107 | + exit; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -135,34 +135,34 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | function securiser_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) { |
| 137 | 137 | |
| 138 | - // mode URL ou array |
|
| 139 | - if (!is_string($mode)) { |
|
| 140 | - $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | - |
|
| 142 | - $r = rawurlencode($redirect); |
|
| 143 | - if ($mode === -1) { |
|
| 144 | - return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | - } else { |
|
| 146 | - return generer_url_action( |
|
| 147 | - $action, |
|
| 148 | - 'arg=' . rawurlencode($arg) . "&hash=$hash" . ($r ? "&redirect=$r" : ''), |
|
| 149 | - $mode, |
|
| 150 | - $public |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // mode formulaire |
|
| 156 | - $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | - $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | - if ($redirect) { |
|
| 159 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | - } |
|
| 161 | - $mode .= $redirect . " |
|
| 138 | + // mode URL ou array |
|
| 139 | + if (!is_string($mode)) { |
|
| 140 | + $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | + |
|
| 142 | + $r = rawurlencode($redirect); |
|
| 143 | + if ($mode === -1) { |
|
| 144 | + return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | + } else { |
|
| 146 | + return generer_url_action( |
|
| 147 | + $action, |
|
| 148 | + 'arg=' . rawurlencode($arg) . "&hash=$hash" . ($r ? "&redirect=$r" : ''), |
|
| 149 | + $mode, |
|
| 150 | + $public |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // mode formulaire |
|
| 156 | + $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | + $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | + if ($redirect) { |
|
| 159 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | + } |
|
| 161 | + $mode .= $redirect . " |
|
| 162 | 162 | <input name='hash' type='hidden' value='$hash' /> |
| 163 | 163 | <input name='arg' type='hidden' value='$arg' />"; |
| 164 | 164 | |
| 165 | - return generer_form_action($action, $mode, $att, $public); |
|
| 165 | + return generer_form_action($action, $mode, $att, $public); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,46 +172,46 @@ discard block |
||
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | 174 | function caracteriser_auteur($id_auteur = null) { |
| 175 | - static $caracterisation = []; |
|
| 176 | - |
|
| 177 | - if (is_null($id_auteur) && !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | - include_spip('inc/session'); |
|
| 179 | - // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 180 | - // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 181 | - // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 182 | - if ($cookie = lire_cookie_session()) { |
|
| 183 | - return [intval($cookie), '']; |
|
| 184 | - // Necessaire aux forums anonymes. |
|
| 185 | - // Pour le reste, ca echouera. |
|
| 186 | - } else { |
|
| 187 | - return ['0', '']; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - // Eviter l'acces SQL si le pass est connu de PHP |
|
| 191 | - if (is_null($id_auteur)) { |
|
| 192 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 193 | - if (isset($GLOBALS['visiteur_session']['pass']) && $GLOBALS['visiteur_session']['pass']) { |
|
| 194 | - return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (isset($caracterisation[$id_auteur])) { |
|
| 199 | - return $caracterisation[$id_auteur]; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($id_auteur) { |
|
| 203 | - include_spip('base/abstract_sql'); |
|
| 204 | - $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 205 | - if ($t) { |
|
| 206 | - return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 207 | - } |
|
| 208 | - include_spip('inc/minipres'); |
|
| 209 | - echo minipres(); |
|
| 210 | - exit; |
|
| 211 | - } // Visiteur anonyme, pour ls forums par exemple |
|
| 212 | - else { |
|
| 213 | - return ['0', '']; |
|
| 214 | - } |
|
| 175 | + static $caracterisation = []; |
|
| 176 | + |
|
| 177 | + if (is_null($id_auteur) && !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | + include_spip('inc/session'); |
|
| 179 | + // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 180 | + // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 181 | + // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 182 | + if ($cookie = lire_cookie_session()) { |
|
| 183 | + return [intval($cookie), '']; |
|
| 184 | + // Necessaire aux forums anonymes. |
|
| 185 | + // Pour le reste, ca echouera. |
|
| 186 | + } else { |
|
| 187 | + return ['0', '']; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + // Eviter l'acces SQL si le pass est connu de PHP |
|
| 191 | + if (is_null($id_auteur)) { |
|
| 192 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 193 | + if (isset($GLOBALS['visiteur_session']['pass']) && $GLOBALS['visiteur_session']['pass']) { |
|
| 194 | + return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (isset($caracterisation[$id_auteur])) { |
|
| 199 | + return $caracterisation[$id_auteur]; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($id_auteur) { |
|
| 203 | + include_spip('base/abstract_sql'); |
|
| 204 | + $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 205 | + if ($t) { |
|
| 206 | + return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 207 | + } |
|
| 208 | + include_spip('inc/minipres'); |
|
| 209 | + echo minipres(); |
|
| 210 | + exit; |
|
| 211 | + } // Visiteur anonyme, pour ls forums par exemple |
|
| 212 | + else { |
|
| 213 | + return ['0', '']; |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -220,31 +220,31 @@ discard block |
||
| 220 | 220 | * et verifier la legitimite de l'appel a l'action |
| 221 | 221 | */ |
| 222 | 222 | function _action_auteur(string $action, int $id_auteur, #[\SensitiveParameter] ?string $pass, string $alea): string { |
| 223 | - static $sha = []; |
|
| 224 | - $pass ??= ''; |
|
| 225 | - $entry = "$action:$id_auteur:$pass:$alea"; |
|
| 226 | - if (!isset($sha[$entry])) { |
|
| 227 | - $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea)); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $sha[$entry]; |
|
| 223 | + static $sha = []; |
|
| 224 | + $pass ??= ''; |
|
| 225 | + $entry = "$action:$id_auteur:$pass:$alea"; |
|
| 226 | + if (!isset($sha[$entry])) { |
|
| 227 | + $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea)); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $sha[$entry]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | function _action_get_alea(string $alea): string { |
| 234 | - if (!isset($GLOBALS['meta'][$alea])) { |
|
| 235 | - $exec = _request('exec'); |
|
| 236 | - if (!$exec || !autoriser_sans_cookie($exec)) { |
|
| 237 | - include_spip('inc/acces'); |
|
| 238 | - charger_aleas(); |
|
| 239 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 240 | - include_spip('inc/minipres'); |
|
| 241 | - echo minipres(); |
|
| 242 | - spip_logger()->info("$alea indisponible"); |
|
| 243 | - exit; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - return $GLOBALS['meta'][$alea] ?? ''; |
|
| 234 | + if (!isset($GLOBALS['meta'][$alea])) { |
|
| 235 | + $exec = _request('exec'); |
|
| 236 | + if (!$exec || !autoriser_sans_cookie($exec)) { |
|
| 237 | + include_spip('inc/acces'); |
|
| 238 | + charger_aleas(); |
|
| 239 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 240 | + include_spip('inc/minipres'); |
|
| 241 | + echo minipres(); |
|
| 242 | + spip_logger()->info("$alea indisponible"); |
|
| 243 | + exit; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + return $GLOBALS['meta'][$alea] ?? ''; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function calculer_action_auteur($action, $id_auteur = null) { |
| 258 | - [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 258 | + [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 259 | 259 | |
| 260 | - return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 260 | + return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -270,9 +270,9 @@ discard block |
||
| 270 | 270 | * @return bool |
| 271 | 271 | */ |
| 272 | 272 | function verifier_action_auteur($action, $hash) { |
| 273 | - [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 274 | - return hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) |
|
| 275 | - || hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')); |
|
| 273 | + [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 274 | + return hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) |
|
| 275 | + || hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * @return string |
| 288 | 288 | */ |
| 289 | 289 | function secret_du_site() { |
| 290 | - return SpipCles::secret_du_site(); |
|
| 290 | + return SpipCles::secret_du_site(); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @return string |
| 298 | 298 | */ |
| 299 | 299 | function calculer_cle_action($action) { |
| 300 | - return hash_hmac('sha256', $action, secret_du_site()); |
|
| 300 | + return hash_hmac('sha256', $action, secret_du_site()); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * @return bool |
| 309 | 309 | */ |
| 310 | 310 | function verifier_cle_action($action, #[\SensitiveParameter] $cle) { |
| 311 | - return hash_equals($cle, calculer_cle_action($action)); |
|
| 311 | + return hash_equals($cle, calculer_cle_action($action)); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -325,17 +325,17 @@ discard block |
||
| 325 | 325 | * @return string Token, de la forme "{id}*{hash}" |
| 326 | 326 | */ |
| 327 | 327 | function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') { |
| 328 | - if (is_null($id_auteur) && !empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 329 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 330 | - } |
|
| 331 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 332 | - return ''; |
|
| 333 | - } |
|
| 334 | - // On nettoie l’URL de tous les var_. |
|
| 335 | - $url = nettoyer_uri_var($url); |
|
| 336 | - |
|
| 337 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea); |
|
| 338 | - return "$id_auteur-$token"; |
|
| 328 | + if (is_null($id_auteur) && !empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 329 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 330 | + } |
|
| 331 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 332 | + return ''; |
|
| 333 | + } |
|
| 334 | + // On nettoie l’URL de tous les var_. |
|
| 335 | + $url = nettoyer_uri_var($url); |
|
| 336 | + |
|
| 337 | + $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea); |
|
| 338 | + return "$id_auteur-$token"; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -353,31 +353,31 @@ discard block |
||
| 353 | 353 | * + Tableau (id auteur, type d’objet, id_objet) sinon. |
| 354 | 354 | */ |
| 355 | 355 | function verifier_token_previsu(#[\SensitiveParameter] $token) { |
| 356 | - // retrouver auteur / hash |
|
| 357 | - $e = explode('-', $token, 2); |
|
| 358 | - if (count($e) == 2 && is_numeric(reset($e))) { |
|
| 359 | - $id_auteur = (int) reset($e); |
|
| 360 | - } else { |
|
| 361 | - return false; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // calculer le type et id de l’url actuelle |
|
| 365 | - include_spip('inc/urls'); |
|
| 366 | - include_spip('inc/filtres_mini'); |
|
| 367 | - $url = url_absolue(self()); |
|
| 368 | - |
|
| 369 | - // verifier le token |
|
| 370 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 371 | - if (!$_token || !hash_equals($token, $_token)) { |
|
| 372 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 373 | - if (!$_token || !hash_equals($token, $_token)) { |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return [ |
|
| 379 | - 'id_auteur' => $id_auteur, |
|
| 380 | - ]; |
|
| 356 | + // retrouver auteur / hash |
|
| 357 | + $e = explode('-', $token, 2); |
|
| 358 | + if (count($e) == 2 && is_numeric(reset($e))) { |
|
| 359 | + $id_auteur = (int) reset($e); |
|
| 360 | + } else { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // calculer le type et id de l’url actuelle |
|
| 365 | + include_spip('inc/urls'); |
|
| 366 | + include_spip('inc/filtres_mini'); |
|
| 367 | + $url = url_absolue(self()); |
|
| 368 | + |
|
| 369 | + // verifier le token |
|
| 370 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 371 | + if (!$_token || !hash_equals($token, $_token)) { |
|
| 372 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 373 | + if (!$_token || !hash_equals($token, $_token)) { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return [ |
|
| 379 | + 'id_auteur' => $id_auteur, |
|
| 380 | + ]; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -386,9 +386,9 @@ discard block |
||
| 386 | 386 | * @return bool|array |
| 387 | 387 | */ |
| 388 | 388 | function decrire_token_previsu() { |
| 389 | - static $desc = null; |
|
| 390 | - if (is_null($desc)) { |
|
| 391 | - $desc = ($token = _request('var_previewtoken')) ? verifier_token_previsu($token) : false; |
|
| 392 | - } |
|
| 393 | - return $desc; |
|
| 389 | + static $desc = null; |
|
| 390 | + if (is_null($desc)) { |
|
| 391 | + $desc = ($token = _request('var_previewtoken')) ? verifier_token_previsu($token) : false; |
|
| 392 | + } |
|
| 393 | + return $desc; |
|
| 394 | 394 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // securité |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // se faciliter la lecture du charset |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * Initialisation |
| 32 | 32 | */ |
| 33 | 33 | function init_charset(): void { |
| 34 | - // Initialisation |
|
| 35 | - $GLOBALS['CHARSET'] = []; |
|
| 36 | - |
|
| 37 | - // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | - // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | - // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | - if ( |
|
| 41 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | - || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | - ) { |
|
| 44 | - include_spip('inc/meta'); |
|
| 45 | - ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | - } |
|
| 34 | + // Initialisation |
|
| 35 | + $GLOBALS['CHARSET'] = []; |
|
| 36 | + |
|
| 37 | + // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | + // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | + // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | + if ( |
|
| 41 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | + || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | + ) { |
|
| 44 | + include_spip('inc/meta'); |
|
| 45 | + ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // TODO: code d’exécution en dehors du fichier. |
@@ -64,39 +64,39 @@ discard block |
||
| 64 | 64 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 65 | 65 | **/ |
| 66 | 66 | function load_charset($charset = 'AUTO') { |
| 67 | - if ($charset == 'AUTO') { |
|
| 68 | - $charset = $GLOBALS['meta']['charset']; |
|
| 69 | - } |
|
| 70 | - $charset = trim(strtolower((string) $charset)); |
|
| 71 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | - return $charset; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ($charset == 'utf-8') { |
|
| 76 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | - |
|
| 78 | - return $charset; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Quelques synonymes |
|
| 82 | - if ($charset === '') { |
|
| 83 | - $charset = 'iso-8859-1'; |
|
| 84 | - } elseif ($charset === 'windows-1250') { |
|
| 85 | - $charset = 'cp1250'; |
|
| 86 | - } elseif ($charset === 'windows-1251') { |
|
| 87 | - $charset = 'cp1251'; |
|
| 88 | - } elseif ($charset === 'windows-1256') { |
|
| 89 | - $charset = 'cp1256'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | - return $charset; |
|
| 94 | - } else { |
|
| 95 | - spip_logger()->info("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | - |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 67 | + if ($charset == 'AUTO') { |
|
| 68 | + $charset = $GLOBALS['meta']['charset']; |
|
| 69 | + } |
|
| 70 | + $charset = trim(strtolower((string) $charset)); |
|
| 71 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | + return $charset; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ($charset == 'utf-8') { |
|
| 76 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | + |
|
| 78 | + return $charset; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Quelques synonymes |
|
| 82 | + if ($charset === '') { |
|
| 83 | + $charset = 'iso-8859-1'; |
|
| 84 | + } elseif ($charset === 'windows-1250') { |
|
| 85 | + $charset = 'cp1250'; |
|
| 86 | + } elseif ($charset === 'windows-1251') { |
|
| 87 | + $charset = 'cp1251'; |
|
| 88 | + } elseif ($charset === 'windows-1256') { |
|
| 89 | + $charset = 'cp1256'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | + return $charset; |
|
| 94 | + } else { |
|
| 95 | + spip_logger()->info("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | + |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -109,19 +109,19 @@ discard block |
||
| 109 | 109 | * true si notre charset est utilisable par mb_strsing |
| 110 | 110 | **/ |
| 111 | 111 | function init_mb_string(): bool { |
| 112 | - static $mb; |
|
| 113 | - |
|
| 114 | - // verifier que le charset interne est connu de mb_string |
|
| 115 | - if (!$mb) { |
|
| 116 | - if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | - mb_internal_encoding('utf-8'); |
|
| 118 | - $mb = 1; |
|
| 119 | - } else { |
|
| 120 | - $mb = -1; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return ($mb === 1); |
|
| 112 | + static $mb; |
|
| 113 | + |
|
| 114 | + // verifier que le charset interne est connu de mb_string |
|
| 115 | + if (!$mb) { |
|
| 116 | + if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | + mb_internal_encoding('utf-8'); |
|
| 118 | + $mb = 1; |
|
| 119 | + } else { |
|
| 120 | + $mb = -1; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return ($mb === 1); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | * true si iconv fonctionne correctement |
| 137 | 137 | **/ |
| 138 | 138 | function test_iconv(): bool { |
| 139 | - static $iconv_ok; |
|
| 139 | + static $iconv_ok; |
|
| 140 | 140 | |
| 141 | - if (!$iconv_ok) { |
|
| 142 | - if (!function_exists('iconv')) { |
|
| 143 | - $iconv_ok = -1; |
|
| 144 | - } else { |
|
| 145 | - $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | - } |
|
| 147 | - } |
|
| 141 | + if (!$iconv_ok) { |
|
| 142 | + if (!function_exists('iconv')) { |
|
| 143 | + $iconv_ok = -1; |
|
| 144 | + } else { |
|
| 145 | + $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return ($iconv_ok === 1); |
|
| 149 | + return ($iconv_ok === 1); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -166,75 +166,75 @@ discard block |
||
| 166 | 166 | * texte corrigé |
| 167 | 167 | **/ |
| 168 | 168 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 169 | - static $trans; |
|
| 170 | - |
|
| 171 | - if (is_array($texte)) { |
|
| 172 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($charset == 'AUTO') { |
|
| 176 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | - } |
|
| 178 | - if ($charset == 'utf-8') { |
|
| 179 | - $p = chr(194); |
|
| 180 | - if (!str_contains($texte, $p)) { |
|
| 181 | - return $texte; |
|
| 182 | - } |
|
| 183 | - } else { |
|
| 184 | - if ($charset == 'iso-8859-1') { |
|
| 185 | - $p = ''; |
|
| 186 | - } else { |
|
| 187 | - return $texte; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | - $trans[$charset][$charset_cible] = [ |
|
| 193 | - $p . chr(128) => '€', |
|
| 194 | - $p . chr(129) => ' ', # pas affecte |
|
| 195 | - $p . chr(130) => '‚', |
|
| 196 | - $p . chr(131) => 'ƒ', |
|
| 197 | - $p . chr(132) => '„', |
|
| 198 | - $p . chr(133) => '…', |
|
| 199 | - $p . chr(134) => '†', |
|
| 200 | - $p . chr(135) => '‡', |
|
| 201 | - $p . chr(136) => 'ˆ', |
|
| 202 | - $p . chr(137) => '‰', |
|
| 203 | - $p . chr(138) => 'Š', |
|
| 204 | - $p . chr(139) => '‹', |
|
| 205 | - $p . chr(140) => 'Œ', |
|
| 206 | - $p . chr(141) => ' ', # pas affecte |
|
| 207 | - $p . chr(142) => 'Ž', |
|
| 208 | - $p . chr(143) => ' ', # pas affecte |
|
| 209 | - $p . chr(144) => ' ', # pas affecte |
|
| 210 | - $p . chr(145) => '‘', |
|
| 211 | - $p . chr(146) => '’', |
|
| 212 | - $p . chr(147) => '“', |
|
| 213 | - $p . chr(148) => '”', |
|
| 214 | - $p . chr(149) => '•', |
|
| 215 | - $p . chr(150) => '–', |
|
| 216 | - $p . chr(151) => '—', |
|
| 217 | - $p . chr(152) => '˜', |
|
| 218 | - $p . chr(153) => '™', |
|
| 219 | - $p . chr(154) => 'š', |
|
| 220 | - $p . chr(155) => '›', |
|
| 221 | - $p . chr(156) => 'œ', |
|
| 222 | - $p . chr(157) => ' ', # pas affecte |
|
| 223 | - $p . chr(158) => 'ž', |
|
| 224 | - $p . chr(159) => 'Ÿ', |
|
| 225 | - ]; |
|
| 226 | - if ($charset_cible != 'unicode') { |
|
| 227 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return @str_replace( |
|
| 234 | - array_keys($trans[$charset][$charset_cible]), |
|
| 235 | - array_values($trans[$charset][$charset_cible]), |
|
| 236 | - $texte |
|
| 237 | - ); |
|
| 169 | + static $trans; |
|
| 170 | + |
|
| 171 | + if (is_array($texte)) { |
|
| 172 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($charset == 'AUTO') { |
|
| 176 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | + } |
|
| 178 | + if ($charset == 'utf-8') { |
|
| 179 | + $p = chr(194); |
|
| 180 | + if (!str_contains($texte, $p)) { |
|
| 181 | + return $texte; |
|
| 182 | + } |
|
| 183 | + } else { |
|
| 184 | + if ($charset == 'iso-8859-1') { |
|
| 185 | + $p = ''; |
|
| 186 | + } else { |
|
| 187 | + return $texte; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | + $trans[$charset][$charset_cible] = [ |
|
| 193 | + $p . chr(128) => '€', |
|
| 194 | + $p . chr(129) => ' ', # pas affecte |
|
| 195 | + $p . chr(130) => '‚', |
|
| 196 | + $p . chr(131) => 'ƒ', |
|
| 197 | + $p . chr(132) => '„', |
|
| 198 | + $p . chr(133) => '…', |
|
| 199 | + $p . chr(134) => '†', |
|
| 200 | + $p . chr(135) => '‡', |
|
| 201 | + $p . chr(136) => 'ˆ', |
|
| 202 | + $p . chr(137) => '‰', |
|
| 203 | + $p . chr(138) => 'Š', |
|
| 204 | + $p . chr(139) => '‹', |
|
| 205 | + $p . chr(140) => 'Œ', |
|
| 206 | + $p . chr(141) => ' ', # pas affecte |
|
| 207 | + $p . chr(142) => 'Ž', |
|
| 208 | + $p . chr(143) => ' ', # pas affecte |
|
| 209 | + $p . chr(144) => ' ', # pas affecte |
|
| 210 | + $p . chr(145) => '‘', |
|
| 211 | + $p . chr(146) => '’', |
|
| 212 | + $p . chr(147) => '“', |
|
| 213 | + $p . chr(148) => '”', |
|
| 214 | + $p . chr(149) => '•', |
|
| 215 | + $p . chr(150) => '–', |
|
| 216 | + $p . chr(151) => '—', |
|
| 217 | + $p . chr(152) => '˜', |
|
| 218 | + $p . chr(153) => '™', |
|
| 219 | + $p . chr(154) => 'š', |
|
| 220 | + $p . chr(155) => '›', |
|
| 221 | + $p . chr(156) => 'œ', |
|
| 222 | + $p . chr(157) => ' ', # pas affecte |
|
| 223 | + $p . chr(158) => 'ž', |
|
| 224 | + $p . chr(159) => 'Ÿ', |
|
| 225 | + ]; |
|
| 226 | + if ($charset_cible != 'unicode') { |
|
| 227 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return @str_replace( |
|
| 234 | + array_keys($trans[$charset][$charset_cible]), |
|
| 235 | + array_values($trans[$charset][$charset_cible]), |
|
| 236 | + $texte |
|
| 237 | + ); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -251,31 +251,31 @@ discard block |
||
| 251 | 251 | * texte converti |
| 252 | 252 | **/ |
| 253 | 253 | function html2unicode(string $texte, bool $secure = false): string { |
| 254 | - static $trans = []; |
|
| 255 | - |
|
| 256 | - if ($texte === null || $texte === '') { |
|
| 257 | - return ''; |
|
| 258 | - } |
|
| 259 | - if (!str_contains($texte, '&')) { |
|
| 260 | - return $texte; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if (!$trans) { |
|
| 264 | - load_charset('html'); |
|
| 265 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | - $trans["&$key;"] = $val; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $texte = str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 271 | - if (!$secure) { |
|
| 272 | - $texte = str_replace( |
|
| 273 | - ['&', '"', '<', '>'], |
|
| 274 | - ['&', '"', '<', '>'], |
|
| 275 | - $texte |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - return $texte; |
|
| 254 | + static $trans = []; |
|
| 255 | + |
|
| 256 | + if ($texte === null || $texte === '') { |
|
| 257 | + return ''; |
|
| 258 | + } |
|
| 259 | + if (!str_contains($texte, '&')) { |
|
| 260 | + return $texte; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if (!$trans) { |
|
| 264 | + load_charset('html'); |
|
| 265 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | + $trans["&$key;"] = $val; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $texte = str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 271 | + if (!$secure) { |
|
| 272 | + $texte = str_replace( |
|
| 273 | + ['&', '"', '<', '>'], |
|
| 274 | + ['&', '"', '<', '>'], |
|
| 275 | + $texte |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + return $texte; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,16 +290,16 @@ discard block |
||
| 290 | 290 | * texte converti |
| 291 | 291 | **/ |
| 292 | 292 | function mathml2unicode($texte) { |
| 293 | - static $trans; |
|
| 294 | - if (!$trans) { |
|
| 295 | - load_charset('mathml'); |
|
| 293 | + static $trans; |
|
| 294 | + if (!$trans) { |
|
| 295 | + load_charset('mathml'); |
|
| 296 | 296 | |
| 297 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | - $trans["&$key;"] = $val; |
|
| 299 | - } |
|
| 300 | - } |
|
| 297 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | + $trans["&$key;"] = $val; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 302 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -321,74 +321,74 @@ discard block |
||
| 321 | 321 | * texte converti en unicode |
| 322 | 322 | **/ |
| 323 | 323 | function charset2unicode(?string $texte, string $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 324 | - static $trans; |
|
| 325 | - |
|
| 326 | - if ($texte === null || $texte === '') { |
|
| 327 | - return ''; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if ($charset === 'AUTO') { |
|
| 331 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ($charset === '') { |
|
| 335 | - $charset = 'iso-8859-1'; |
|
| 336 | - } |
|
| 337 | - $charset = strtolower((string) $charset); |
|
| 338 | - |
|
| 339 | - switch ($charset) { |
|
| 340 | - case 'utf-8': |
|
| 341 | - case 'utf8': |
|
| 342 | - return utf_8_to_unicode($texte); |
|
| 343 | - |
|
| 344 | - case 'iso-8859-1': |
|
| 345 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 346 | - // pas de break; ici, on suit sur default: |
|
| 347 | - |
|
| 348 | - default: |
|
| 349 | - // mbstring presente ? |
|
| 350 | - if (init_mb_string()) { |
|
| 351 | - $order = mb_detect_order(); |
|
| 352 | - try { |
|
| 353 | - # mb_string connait-il $charset? |
|
| 354 | - if ($order && mb_detect_order($charset)) { |
|
| 355 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 356 | - if ($s && $s != $texte) { |
|
| 357 | - return utf_8_to_unicode($s); |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - } catch (\Error) { |
|
| 361 | - // Le charset n'existe probablement pas |
|
| 362 | - } finally { |
|
| 363 | - mb_detect_order($order); # remettre comme precedemment |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 368 | - if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 369 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 374 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 378 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 379 | - // surtout en utf-8, gere ci-dessus) |
|
| 380 | - if (test_iconv()) { |
|
| 381 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 382 | - if ($s) { |
|
| 383 | - return utf_32_to_unicode($s); |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // Au pire ne rien faire |
|
| 388 | - spip_logger()->info("erreur charset '$charset' non supporte"); |
|
| 389 | - |
|
| 390 | - return $texte; |
|
| 391 | - } |
|
| 324 | + static $trans; |
|
| 325 | + |
|
| 326 | + if ($texte === null || $texte === '') { |
|
| 327 | + return ''; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if ($charset === 'AUTO') { |
|
| 331 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ($charset === '') { |
|
| 335 | + $charset = 'iso-8859-1'; |
|
| 336 | + } |
|
| 337 | + $charset = strtolower((string) $charset); |
|
| 338 | + |
|
| 339 | + switch ($charset) { |
|
| 340 | + case 'utf-8': |
|
| 341 | + case 'utf8': |
|
| 342 | + return utf_8_to_unicode($texte); |
|
| 343 | + |
|
| 344 | + case 'iso-8859-1': |
|
| 345 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 346 | + // pas de break; ici, on suit sur default: |
|
| 347 | + |
|
| 348 | + default: |
|
| 349 | + // mbstring presente ? |
|
| 350 | + if (init_mb_string()) { |
|
| 351 | + $order = mb_detect_order(); |
|
| 352 | + try { |
|
| 353 | + # mb_string connait-il $charset? |
|
| 354 | + if ($order && mb_detect_order($charset)) { |
|
| 355 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 356 | + if ($s && $s != $texte) { |
|
| 357 | + return utf_8_to_unicode($s); |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + } catch (\Error) { |
|
| 361 | + // Le charset n'existe probablement pas |
|
| 362 | + } finally { |
|
| 363 | + mb_detect_order($order); # remettre comme precedemment |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 368 | + if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 369 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 374 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 378 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 379 | + // surtout en utf-8, gere ci-dessus) |
|
| 380 | + if (test_iconv()) { |
|
| 381 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 382 | + if ($s) { |
|
| 383 | + return utf_32_to_unicode($s); |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // Au pire ne rien faire |
|
| 388 | + spip_logger()->info("erreur charset '$charset' non supporte"); |
|
| 389 | + |
|
| 390 | + return $texte; |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | |
@@ -407,42 +407,42 @@ discard block |
||
| 407 | 407 | * texte transformé dans le charset souhaité |
| 408 | 408 | **/ |
| 409 | 409 | function unicode2charset($texte, $charset = 'AUTO') { |
| 410 | - static $CHARSET_REVERSE = []; |
|
| 411 | - static $trans = []; |
|
| 412 | - |
|
| 413 | - if ($charset == 'AUTO') { |
|
| 414 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - switch ($charset) { |
|
| 418 | - case 'utf-8': |
|
| 419 | - return unicode_to_utf_8($texte); |
|
| 420 | - |
|
| 421 | - default: |
|
| 422 | - $charset = load_charset($charset); |
|
| 423 | - |
|
| 424 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 425 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - if (!isset($trans[$charset])) { |
|
| 429 | - $trans[$charset] = []; |
|
| 430 | - $t = &$trans[$charset]; |
|
| 431 | - for ($e = 128; $e < 255; $e++) { |
|
| 432 | - $h = dechex($e); |
|
| 433 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 434 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 435 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 436 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 437 | - } else { |
|
| 438 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 439 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | - } |
|
| 410 | + static $CHARSET_REVERSE = []; |
|
| 411 | + static $trans = []; |
|
| 412 | + |
|
| 413 | + if ($charset == 'AUTO') { |
|
| 414 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + switch ($charset) { |
|
| 418 | + case 'utf-8': |
|
| 419 | + return unicode_to_utf_8($texte); |
|
| 420 | + |
|
| 421 | + default: |
|
| 422 | + $charset = load_charset($charset); |
|
| 423 | + |
|
| 424 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 425 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + if (!isset($trans[$charset])) { |
|
| 429 | + $trans[$charset] = []; |
|
| 430 | + $t = &$trans[$charset]; |
|
| 431 | + for ($e = 128; $e < 255; $e++) { |
|
| 432 | + $h = dechex($e); |
|
| 433 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 434 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 435 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 436 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 437 | + } else { |
|
| 438 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 439 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -460,39 +460,39 @@ discard block |
||
| 460 | 460 | * texte transformé dans le charset site |
| 461 | 461 | **/ |
| 462 | 462 | function importer_charset($texte, $charset = 'AUTO') { |
| 463 | - $s = null; |
|
| 464 | - static $trans = []; |
|
| 465 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 466 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 467 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 468 | - if (init_mb_string()) { |
|
| 469 | - if ( |
|
| 470 | - ($order = mb_detect_order()) |
|
| 471 | - && mb_detect_order($charset) |
|
| 472 | - ) { |
|
| 473 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 474 | - } |
|
| 475 | - mb_detect_order($order); # remettre comme precedemment |
|
| 476 | - return $s; |
|
| 477 | - } |
|
| 478 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 479 | - if ( |
|
| 480 | - !isset($trans[$charset]) |
|
| 481 | - && (($cset = load_charset($charset)) |
|
| 482 | - && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 483 | - ) { |
|
| 484 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 485 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 489 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - return $texte; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 463 | + $s = null; |
|
| 464 | + static $trans = []; |
|
| 465 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 466 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 467 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 468 | + if (init_mb_string()) { |
|
| 469 | + if ( |
|
| 470 | + ($order = mb_detect_order()) |
|
| 471 | + && mb_detect_order($charset) |
|
| 472 | + ) { |
|
| 473 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 474 | + } |
|
| 475 | + mb_detect_order($order); # remettre comme precedemment |
|
| 476 | + return $s; |
|
| 477 | + } |
|
| 478 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 479 | + if ( |
|
| 480 | + !isset($trans[$charset]) |
|
| 481 | + && (($cset = load_charset($charset)) |
|
| 482 | + && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 483 | + ) { |
|
| 484 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 485 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 489 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + return $texte; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -508,92 +508,92 @@ discard block |
||
| 508 | 508 | **/ |
| 509 | 509 | function utf_8_to_unicode($source) { |
| 510 | 510 | |
| 511 | - // mb_string : methode rapide |
|
| 512 | - if (init_mb_string()) { |
|
| 513 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 514 | - |
|
| 515 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - // Sinon methode pas a pas |
|
| 519 | - static $decrement; |
|
| 520 | - static $shift; |
|
| 521 | - |
|
| 522 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 523 | - if (!is_array($decrement)) { |
|
| 524 | - // array used to figure what number to decrement from character order value |
|
| 525 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 526 | - $decrement[4] = 240; |
|
| 527 | - $decrement[3] = 224; |
|
| 528 | - $decrement[2] = 192; |
|
| 529 | - $decrement[1] = 0; |
|
| 530 | - // the number of bits to shift each charNum by |
|
| 531 | - $shift[1][0] = 0; |
|
| 532 | - $shift[2][0] = 6; |
|
| 533 | - $shift[2][1] = 0; |
|
| 534 | - $shift[3][0] = 12; |
|
| 535 | - $shift[3][1] = 6; |
|
| 536 | - $shift[3][2] = 0; |
|
| 537 | - $shift[4][0] = 18; |
|
| 538 | - $shift[4][1] = 12; |
|
| 539 | - $shift[4][2] = 6; |
|
| 540 | - $shift[4][3] = 0; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $pos = 0; |
|
| 544 | - $len = strlen($source); |
|
| 545 | - $encodedString = ''; |
|
| 546 | - while ($pos < $len) { |
|
| 547 | - $char = ''; |
|
| 548 | - $ischar = false; |
|
| 549 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 550 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 551 | - // 4 chars representing one unicode character |
|
| 552 | - $thisLetter = substr($source, $pos, 4); |
|
| 553 | - $pos += 4; |
|
| 554 | - } else { |
|
| 555 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 556 | - // 3 chars representing one unicode character |
|
| 557 | - $thisLetter = substr($source, $pos, 3); |
|
| 558 | - $pos += 3; |
|
| 559 | - } else { |
|
| 560 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 561 | - // 2 chars representing one unicode character |
|
| 562 | - $thisLetter = substr($source, $pos, 2); |
|
| 563 | - $pos += 2; |
|
| 564 | - } else { |
|
| 565 | - // 1 char (lower ascii) |
|
| 566 | - $thisLetter = substr($source, $pos, 1); |
|
| 567 | - $pos += 1; |
|
| 568 | - $char = $thisLetter; |
|
| 569 | - $ischar = true; |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - if ($ischar) { |
|
| 575 | - $encodedString .= $char; |
|
| 576 | - } else { // process the string representing the letter to a unicode entity |
|
| 577 | - $thisLen = strlen($thisLetter); |
|
| 578 | - $thisPos = 0; |
|
| 579 | - $decimalCode = 0; |
|
| 580 | - while ($thisPos < $thisLen) { |
|
| 581 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 582 | - if ($thisPos == 0) { |
|
| 583 | - $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 584 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 585 | - } else { |
|
| 586 | - $charNum = (int) ($thisCharOrd - 128); |
|
| 587 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | - } |
|
| 589 | - $thisPos++; |
|
| 590 | - } |
|
| 591 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 592 | - $encodedString .= $encodedLetter; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $encodedString; |
|
| 511 | + // mb_string : methode rapide |
|
| 512 | + if (init_mb_string()) { |
|
| 513 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 514 | + |
|
| 515 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + // Sinon methode pas a pas |
|
| 519 | + static $decrement; |
|
| 520 | + static $shift; |
|
| 521 | + |
|
| 522 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 523 | + if (!is_array($decrement)) { |
|
| 524 | + // array used to figure what number to decrement from character order value |
|
| 525 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 526 | + $decrement[4] = 240; |
|
| 527 | + $decrement[3] = 224; |
|
| 528 | + $decrement[2] = 192; |
|
| 529 | + $decrement[1] = 0; |
|
| 530 | + // the number of bits to shift each charNum by |
|
| 531 | + $shift[1][0] = 0; |
|
| 532 | + $shift[2][0] = 6; |
|
| 533 | + $shift[2][1] = 0; |
|
| 534 | + $shift[3][0] = 12; |
|
| 535 | + $shift[3][1] = 6; |
|
| 536 | + $shift[3][2] = 0; |
|
| 537 | + $shift[4][0] = 18; |
|
| 538 | + $shift[4][1] = 12; |
|
| 539 | + $shift[4][2] = 6; |
|
| 540 | + $shift[4][3] = 0; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $pos = 0; |
|
| 544 | + $len = strlen($source); |
|
| 545 | + $encodedString = ''; |
|
| 546 | + while ($pos < $len) { |
|
| 547 | + $char = ''; |
|
| 548 | + $ischar = false; |
|
| 549 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 550 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 551 | + // 4 chars representing one unicode character |
|
| 552 | + $thisLetter = substr($source, $pos, 4); |
|
| 553 | + $pos += 4; |
|
| 554 | + } else { |
|
| 555 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 556 | + // 3 chars representing one unicode character |
|
| 557 | + $thisLetter = substr($source, $pos, 3); |
|
| 558 | + $pos += 3; |
|
| 559 | + } else { |
|
| 560 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 561 | + // 2 chars representing one unicode character |
|
| 562 | + $thisLetter = substr($source, $pos, 2); |
|
| 563 | + $pos += 2; |
|
| 564 | + } else { |
|
| 565 | + // 1 char (lower ascii) |
|
| 566 | + $thisLetter = substr($source, $pos, 1); |
|
| 567 | + $pos += 1; |
|
| 568 | + $char = $thisLetter; |
|
| 569 | + $ischar = true; |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + if ($ischar) { |
|
| 575 | + $encodedString .= $char; |
|
| 576 | + } else { // process the string representing the letter to a unicode entity |
|
| 577 | + $thisLen = strlen($thisLetter); |
|
| 578 | + $thisPos = 0; |
|
| 579 | + $decimalCode = 0; |
|
| 580 | + while ($thisPos < $thisLen) { |
|
| 581 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 582 | + if ($thisPos == 0) { |
|
| 583 | + $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 584 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 585 | + } else { |
|
| 586 | + $charNum = (int) ($thisCharOrd - 128); |
|
| 587 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | + } |
|
| 589 | + $thisPos++; |
|
| 590 | + } |
|
| 591 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 592 | + $encodedString .= $encodedLetter; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $encodedString; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -612,32 +612,32 @@ discard block |
||
| 612 | 612 | **/ |
| 613 | 613 | function utf_32_to_unicode($source) { |
| 614 | 614 | |
| 615 | - // mb_string : methode rapide |
|
| 616 | - if (init_mb_string()) { |
|
| 617 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 618 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 619 | - |
|
| 620 | - return str_replace(chr(0), '', $source); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Sinon methode lente |
|
| 624 | - $texte = ''; |
|
| 625 | - while ($source) { |
|
| 626 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 627 | - $source = substr($source, 1024); |
|
| 628 | - foreach ($words as $word) { |
|
| 629 | - if ($word < 128) { |
|
| 630 | - $texte .= chr($word); |
|
| 631 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 632 | - else { |
|
| 633 | - if ($word != 65279) { |
|
| 634 | - $texte .= '&#' . $word . ';'; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $texte; |
|
| 615 | + // mb_string : methode rapide |
|
| 616 | + if (init_mb_string()) { |
|
| 617 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 618 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 619 | + |
|
| 620 | + return str_replace(chr(0), '', $source); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Sinon methode lente |
|
| 624 | + $texte = ''; |
|
| 625 | + while ($source) { |
|
| 626 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 627 | + $source = substr($source, 1024); |
|
| 628 | + foreach ($words as $word) { |
|
| 629 | + if ($word < 128) { |
|
| 630 | + $texte .= chr($word); |
|
| 631 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 632 | + else { |
|
| 633 | + if ($word != 65279) { |
|
| 634 | + $texte .= '&#' . $word . ';'; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $texte; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | |
@@ -654,21 +654,21 @@ discard block |
||
| 654 | 654 | * Caractère utf8 si trouvé, '' sinon |
| 655 | 655 | **/ |
| 656 | 656 | function caractere_utf_8($num) { |
| 657 | - $num = (int) $num; |
|
| 658 | - if ($num < 128) { |
|
| 659 | - return chr($num); |
|
| 660 | - } |
|
| 661 | - if ($num < 2048) { |
|
| 662 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 663 | - } |
|
| 664 | - if ($num < 65536) { |
|
| 665 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 666 | - } |
|
| 667 | - if ($num < 1_114_112) { |
|
| 668 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - return ''; |
|
| 657 | + $num = (int) $num; |
|
| 658 | + if ($num < 128) { |
|
| 659 | + return chr($num); |
|
| 660 | + } |
|
| 661 | + if ($num < 2048) { |
|
| 662 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 663 | + } |
|
| 664 | + if ($num < 65536) { |
|
| 665 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 666 | + } |
|
| 667 | + if ($num < 1_114_112) { |
|
| 668 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + return ''; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -681,42 +681,42 @@ discard block |
||
| 681 | 681 | **/ |
| 682 | 682 | function unicode_to_utf_8($texte) { |
| 683 | 683 | |
| 684 | - // 1. Entites € et suivantes |
|
| 685 | - $vu = []; |
|
| 686 | - if ( |
|
| 687 | - preg_match_all( |
|
| 688 | - ',�*([1-9]\d\d+);,S', |
|
| 689 | - $texte, |
|
| 690 | - $regs, |
|
| 691 | - PREG_SET_ORDER |
|
| 692 | - ) |
|
| 693 | - ) { |
|
| 694 | - foreach ($regs as $reg) { |
|
| 695 | - if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 696 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 701 | - |
|
| 702 | - // 2. Entites > ÿ |
|
| 703 | - //$vu = array(); |
|
| 704 | - if ( |
|
| 705 | - preg_match_all( |
|
| 706 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 707 | - $texte, |
|
| 708 | - $regs, |
|
| 709 | - PREG_SET_ORDER |
|
| 710 | - ) |
|
| 711 | - ) { |
|
| 712 | - foreach ($regs as $reg) { |
|
| 713 | - if (!isset($vu[$reg[0]])) { |
|
| 714 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 684 | + // 1. Entites € et suivantes |
|
| 685 | + $vu = []; |
|
| 686 | + if ( |
|
| 687 | + preg_match_all( |
|
| 688 | + ',�*([1-9]\d\d+);,S', |
|
| 689 | + $texte, |
|
| 690 | + $regs, |
|
| 691 | + PREG_SET_ORDER |
|
| 692 | + ) |
|
| 693 | + ) { |
|
| 694 | + foreach ($regs as $reg) { |
|
| 695 | + if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 696 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 701 | + |
|
| 702 | + // 2. Entites > ÿ |
|
| 703 | + //$vu = array(); |
|
| 704 | + if ( |
|
| 705 | + preg_match_all( |
|
| 706 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 707 | + $texte, |
|
| 708 | + $regs, |
|
| 709 | + PREG_SET_ORDER |
|
| 710 | + ) |
|
| 711 | + ) { |
|
| 712 | + foreach ($regs as $reg) { |
|
| 713 | + if (!isset($vu[$reg[0]])) { |
|
| 714 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -728,15 +728,15 @@ discard block |
||
| 728 | 728 | * texte converti |
| 729 | 729 | **/ |
| 730 | 730 | function unicode_to_javascript($texte) { |
| 731 | - $vu = []; |
|
| 732 | - while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 733 | - $num = $regs[1]; |
|
| 734 | - $vu[$num] = true; |
|
| 735 | - $s = '\u' . sprintf('%04x', $num); |
|
| 736 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - return $texte; |
|
| 731 | + $vu = []; |
|
| 732 | + while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 733 | + $num = $regs[1]; |
|
| 734 | + $vu[$num] = true; |
|
| 735 | + $s = '\u' . sprintf('%04x', $num); |
|
| 736 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + return $texte; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -748,11 +748,11 @@ discard block |
||
| 748 | 748 | * texte converti |
| 749 | 749 | **/ |
| 750 | 750 | function javascript_to_unicode($texte) { |
| 751 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 752 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 753 | - } |
|
| 751 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 752 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return $texte; |
|
| 755 | + return $texte; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /** |
@@ -764,11 +764,11 @@ discard block |
||
| 764 | 764 | * texte converti |
| 765 | 765 | **/ |
| 766 | 766 | function javascript_to_binary($texte) { |
| 767 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 768 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 769 | - } |
|
| 767 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 768 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | - return $texte; |
|
| 771 | + return $texte; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | |
@@ -786,26 +786,26 @@ discard block |
||
| 786 | 786 | * @return string |
| 787 | 787 | */ |
| 788 | 788 | function translitteration_rapide(?string $texte, string $charset = 'AUTO', string $complexe = ''): string { |
| 789 | - static $trans = []; |
|
| 790 | - if ($charset == 'AUTO') { |
|
| 791 | - $charset = $GLOBALS['meta']['charset']; |
|
| 792 | - } |
|
| 793 | - if ($texte === null || $texte === '') { |
|
| 794 | - return ''; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - $table_translit = 'translit' . $complexe; |
|
| 798 | - |
|
| 799 | - // 2. Translitterer grace a la table predefinie |
|
| 800 | - if (!isset($trans[$complexe])) { |
|
| 801 | - $trans[$complexe] = []; |
|
| 802 | - load_charset($table_translit); |
|
| 803 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 804 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 789 | + static $trans = []; |
|
| 790 | + if ($charset == 'AUTO') { |
|
| 791 | + $charset = $GLOBALS['meta']['charset']; |
|
| 792 | + } |
|
| 793 | + if ($texte === null || $texte === '') { |
|
| 794 | + return ''; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + $table_translit = 'translit' . $complexe; |
|
| 798 | + |
|
| 799 | + // 2. Translitterer grace a la table predefinie |
|
| 800 | + if (!isset($trans[$complexe])) { |
|
| 801 | + $trans[$complexe] = []; |
|
| 802 | + load_charset($table_translit); |
|
| 803 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 804 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -828,18 +828,18 @@ discard block |
||
| 828 | 828 | * @return string |
| 829 | 829 | */ |
| 830 | 830 | function translitteration(?string $texte, string $charset = 'AUTO', string $complexe = ''): string { |
| 831 | - if ($texte === null || $texte === '') { |
|
| 832 | - return ''; |
|
| 833 | - } |
|
| 831 | + if ($texte === null || $texte === '') { |
|
| 832 | + return ''; |
|
| 833 | + } |
|
| 834 | 834 | |
| 835 | - // 0. Supprimer les caracteres illegaux |
|
| 836 | - include_spip('inc/filtres'); |
|
| 837 | - $texte = corriger_caracteres($texte); |
|
| 835 | + // 0. Supprimer les caracteres illegaux |
|
| 836 | + include_spip('inc/filtres'); |
|
| 837 | + $texte = corriger_caracteres($texte); |
|
| 838 | 838 | |
| 839 | - // 1. Passer le charset et les é en utf-8 |
|
| 840 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 839 | + // 1. Passer le charset et les é en utf-8 |
|
| 840 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 841 | 841 | |
| 842 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 842 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
@@ -854,17 +854,17 @@ discard block |
||
| 854 | 854 | * @return string |
| 855 | 855 | */ |
| 856 | 856 | function translitteration_complexe(?string $texte, bool $chiffres = false): string { |
| 857 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 857 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 858 | 858 | |
| 859 | - if ($chiffres) { |
|
| 860 | - $texte = preg_replace_callback( |
|
| 861 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 862 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 863 | - $texte |
|
| 864 | - ); |
|
| 865 | - } |
|
| 859 | + if ($chiffres) { |
|
| 860 | + $texte = preg_replace_callback( |
|
| 861 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 862 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 863 | + $texte |
|
| 864 | + ); |
|
| 865 | + } |
|
| 866 | 866 | |
| 867 | - return $texte; |
|
| 867 | + return $texte; |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * @return string |
| 877 | 877 | */ |
| 878 | 878 | function translitteration_chiffree(string $car): string { |
| 879 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 879 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | * true s'il a un BOM |
| 890 | 890 | **/ |
| 891 | 891 | function bom_utf8($texte): bool { |
| 892 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 892 | + return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -906,21 +906,21 @@ discard block |
||
| 906 | 906 | * true si c'est le cas |
| 907 | 907 | **/ |
| 908 | 908 | function is_utf8($string): bool { |
| 909 | - return !strlen( |
|
| 910 | - preg_replace( |
|
| 911 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 912 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 913 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 914 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 915 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 916 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 917 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 918 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 919 | - . ',sS', |
|
| 920 | - '', |
|
| 921 | - $string |
|
| 922 | - ) |
|
| 923 | - ); |
|
| 909 | + return !strlen( |
|
| 910 | + preg_replace( |
|
| 911 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 912 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 913 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 914 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 915 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 916 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 917 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 918 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 919 | + . ',sS', |
|
| 920 | + '', |
|
| 921 | + $string |
|
| 922 | + ) |
|
| 923 | + ); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | /** |
@@ -932,13 +932,13 @@ discard block |
||
| 932 | 932 | * true si c'est le cas |
| 933 | 933 | **/ |
| 934 | 934 | function is_ascii($string): bool { |
| 935 | - return !strlen( |
|
| 936 | - preg_replace( |
|
| 937 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 938 | - '', |
|
| 939 | - $string |
|
| 940 | - ) |
|
| 941 | - ); |
|
| 935 | + return !strlen( |
|
| 936 | + preg_replace( |
|
| 937 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 938 | + '', |
|
| 939 | + $string |
|
| 940 | + ) |
|
| 941 | + ); |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
@@ -957,50 +957,50 @@ discard block |
||
| 957 | 957 | **/ |
| 958 | 958 | function transcoder_page($texte, $headers = ''): string { |
| 959 | 959 | |
| 960 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 961 | - if (is_ascii($texte)) { |
|
| 962 | - #spip_logger()->info('charset: ascii'); |
|
| 963 | - return $texte; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - if (bom_utf8($texte)) { |
|
| 967 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 968 | - $charset = 'utf-8'; |
|
| 969 | - $texte = substr($texte, 3); |
|
| 970 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 971 | - // charset precise par le contenu (xml) |
|
| 972 | - $charset = trim(strtolower($regs[1])); |
|
| 973 | - } elseif ( |
|
| 974 | - // charset precise par le contenu (html) |
|
| 975 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 976 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 977 | - |
|
| 978 | - && !str_contains($regs[2], '#') |
|
| 979 | - && ($tmp = trim(strtolower($regs[2]))) |
|
| 980 | - ) { |
|
| 981 | - $charset = $tmp; |
|
| 982 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 983 | - // charset de la reponse http |
|
| 984 | - $charset = trim(strtolower($regs[1])); |
|
| 985 | - } else { |
|
| 986 | - $charset = ''; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - // normaliser les noms du shif-jis japonais |
|
| 991 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 992 | - $charset = 'shift-jis'; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - if ($charset) { |
|
| 996 | - spip_logger()->info("charset: $charset"); |
|
| 997 | - } else { |
|
| 998 | - // valeur par defaut |
|
| 999 | - $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 1000 | - spip_logger()->info("charset probable: $charset"); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return importer_charset($texte, $charset); |
|
| 960 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 961 | + if (is_ascii($texte)) { |
|
| 962 | + #spip_logger()->info('charset: ascii'); |
|
| 963 | + return $texte; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + if (bom_utf8($texte)) { |
|
| 967 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 968 | + $charset = 'utf-8'; |
|
| 969 | + $texte = substr($texte, 3); |
|
| 970 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 971 | + // charset precise par le contenu (xml) |
|
| 972 | + $charset = trim(strtolower($regs[1])); |
|
| 973 | + } elseif ( |
|
| 974 | + // charset precise par le contenu (html) |
|
| 975 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 976 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 977 | + |
|
| 978 | + && !str_contains($regs[2], '#') |
|
| 979 | + && ($tmp = trim(strtolower($regs[2]))) |
|
| 980 | + ) { |
|
| 981 | + $charset = $tmp; |
|
| 982 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 983 | + // charset de la reponse http |
|
| 984 | + $charset = trim(strtolower($regs[1])); |
|
| 985 | + } else { |
|
| 986 | + $charset = ''; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + // normaliser les noms du shif-jis japonais |
|
| 991 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 992 | + $charset = 'shift-jis'; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + if ($charset) { |
|
| 996 | + spip_logger()->info("charset: $charset"); |
|
| 997 | + } else { |
|
| 998 | + // valeur par defaut |
|
| 999 | + $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 1000 | + spip_logger()->info("charset probable: $charset"); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return importer_charset($texte, $charset); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
@@ -1024,19 +1024,19 @@ discard block |
||
| 1024 | 1024 | * Le texte coupé |
| 1025 | 1025 | **/ |
| 1026 | 1026 | function spip_substr($c, $start = 0, $length = null) { |
| 1027 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1028 | - if ($length) { |
|
| 1029 | - return substr($c, $start, $length); |
|
| 1030 | - } else { |
|
| 1031 | - return substr($c, $start); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - if ($length) { |
|
| 1036 | - return mb_substr($c, $start, $length); |
|
| 1037 | - } else { |
|
| 1038 | - return mb_substr($c, $start); |
|
| 1039 | - } |
|
| 1027 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1028 | + if ($length) { |
|
| 1029 | + return substr($c, $start, $length); |
|
| 1030 | + } else { |
|
| 1031 | + return substr($c, $start); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + if ($length) { |
|
| 1036 | + return mb_substr($c, $start, $length); |
|
| 1037 | + } else { |
|
| 1038 | + return mb_substr($c, $start); |
|
| 1039 | + } |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1050,13 +1050,13 @@ discard block |
||
| 1050 | 1050 | * La chaîne avec une majuscule sur le premier mot |
| 1051 | 1051 | */ |
| 1052 | 1052 | function spip_ucfirst($c) { |
| 1053 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1054 | - return ucfirst($c); |
|
| 1055 | - } |
|
| 1053 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1054 | + return ucfirst($c); |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1057 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1058 | 1058 | |
| 1059 | - return $lettre1 . spip_substr($c, 1); |
|
| 1059 | + return $lettre1 . spip_substr($c, 1); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1070,11 +1070,11 @@ discard block |
||
| 1070 | 1070 | * La chaîne en minuscules |
| 1071 | 1071 | */ |
| 1072 | 1072 | function spip_strtolower($c) { |
| 1073 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1074 | - return strtolower($c); |
|
| 1075 | - } |
|
| 1073 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1074 | + return strtolower($c); |
|
| 1075 | + } |
|
| 1076 | 1076 | |
| 1077 | - return mb_strtolower($c); |
|
| 1077 | + return mb_strtolower($c); |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | /** |
@@ -1088,15 +1088,15 @@ discard block |
||
| 1088 | 1088 | * Longueur de la chaîne |
| 1089 | 1089 | */ |
| 1090 | 1090 | function spip_strlen($c) { |
| 1091 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1092 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1091 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1092 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1093 | 1093 | |
| 1094 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1095 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1096 | - return strlen($c); |
|
| 1097 | - } |
|
| 1094 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1095 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1096 | + return strlen($c); |
|
| 1097 | + } |
|
| 1098 | 1098 | |
| 1099 | - return mb_strlen($c); |
|
| 1099 | + return mb_strlen($c); |
|
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | /** |
@@ -1111,17 +1111,17 @@ discard block |
||
| 1111 | 1111 | * en unicode : 💩 |
| 1112 | 1112 | */ |
| 1113 | 1113 | function utf8_noplanes($x): string { |
| 1114 | - $regexp_utf8_4bytes = '/( |
|
| 1114 | + $regexp_utf8_4bytes = '/( |
|
| 1115 | 1115 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1116 | 1116 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1117 | 1117 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1118 | 1118 | )/xS'; |
| 1119 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1120 | - foreach ($z[0] as $k) { |
|
| 1121 | - $ku = utf_8_to_unicode($k); |
|
| 1122 | - $x = str_replace($k, $ku, $x); |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - return $x; |
|
| 1119 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1120 | + foreach ($z[0] as $k) { |
|
| 1121 | + $ku = utf_8_to_unicode($k); |
|
| 1122 | + $x = str_replace($k, $ku, $x); |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + return $x; |
|
| 1127 | 1127 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_TEST_FILE_EXISTS')) { |
| 23 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 23 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 30 | 30 | |
| 31 | 31 | if (_SPIP_LOCK_MODE == 2) { |
| 32 | - include_spip('inc/nfslock'); |
|
| 32 | + include_spip('inc/nfslock'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['liste_verrous'] = []; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * Ressource sur le fichier ouvert, sinon false. |
| 53 | 53 | **/ |
| 54 | 54 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 55 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | - // verrou |
|
| 58 | - @flock($fl, $verrou); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $fl; |
|
| 62 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | - |
|
| 66 | - return $fl; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return @fopen($fichier, $mode); |
|
| 55 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | + // verrou |
|
| 58 | + @flock($fl, $verrou); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $fl; |
|
| 62 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | + |
|
| 66 | + return $fl; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return @fopen($fichier, $mode); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * true si succès, false sinon. |
| 85 | 85 | **/ |
| 86 | 86 | function spip_fclose_unlock($handle) { |
| 87 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | - @flock($handle, LOCK_UN); |
|
| 89 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return @fclose($handle); |
|
| 87 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | + @flock($handle, LOCK_UN); |
|
| 89 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return @fclose($handle); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | * Contenu du fichier |
| 106 | 106 | **/ |
| 107 | 107 | function spip_file_get_contents($fichier) { |
| 108 | - if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | - if (function_exists('file_get_contents')) { |
|
| 110 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | - // sinon on fait un file() pour avoir le coeur net |
|
| 113 | - $contenu = @file_get_contents($fichier); |
|
| 114 | - if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | - $contenu = @file($fichier); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $contenu = @file($fichier); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $contenu = @gzfile($fichier); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 108 | + if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | + if (function_exists('file_get_contents')) { |
|
| 110 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | + // sinon on fait un file() pour avoir le coeur net |
|
| 113 | + $contenu = @file_get_contents($fichier); |
|
| 114 | + if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | + $contenu = @file($fichier); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $contenu = @file($fichier); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $contenu = @gzfile($fichier); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -146,48 +146,48 @@ discard block |
||
| 146 | 146 | * true si l'opération a réussie, false sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 149 | - $contenu = ''; |
|
| 150 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | - if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - #spip_timer('lire_fichier'); |
|
| 157 | - |
|
| 158 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | - // lire le fichier avant tout |
|
| 161 | - $contenu = spip_file_get_contents($fichier); |
|
| 162 | - |
|
| 163 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | - // et eviter un acces disque |
|
| 167 | - if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | - spip_fclose_unlock($fl); |
|
| 169 | - |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // liberer le verrou |
|
| 174 | - spip_fclose_unlock($fl); |
|
| 175 | - |
|
| 176 | - // Verifications |
|
| 177 | - $ok = true; |
|
| 178 | - if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - #spip_logger()->info("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | - if (!$ok) { |
|
| 184 | - spip_logger()->info("echec lecture $fichier"); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $ok; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 149 | + $contenu = ''; |
|
| 150 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | + if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + #spip_timer('lire_fichier'); |
|
| 157 | + |
|
| 158 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | + // lire le fichier avant tout |
|
| 161 | + $contenu = spip_file_get_contents($fichier); |
|
| 162 | + |
|
| 163 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | + // et eviter un acces disque |
|
| 167 | + if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | + spip_fclose_unlock($fl); |
|
| 169 | + |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // liberer le verrou |
|
| 174 | + spip_fclose_unlock($fl); |
|
| 175 | + |
|
| 176 | + // Verifications |
|
| 177 | + $ok = true; |
|
| 178 | + if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + #spip_logger()->info("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | + if (!$ok) { |
|
| 184 | + spip_logger()->info("echec lecture $fichier"); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $ok; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -215,92 +215,92 @@ discard block |
||
| 215 | 215 | **/ |
| 216 | 216 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 217 | 217 | |
| 218 | - #spip_timer('ecrire_fichier'); |
|
| 219 | - |
|
| 220 | - // verrouiller le fichier destination |
|
| 221 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | - // ecrire les donnees, compressees le cas echeant |
|
| 223 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | - if (str_ends_with($fichier, '.gz')) { |
|
| 226 | - $contenu = gzencode($contenu); |
|
| 227 | - } |
|
| 228 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | - // pour etre sur d'avoir une operation atomique |
|
| 230 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | - // sauf sous wintruc ou ca ne marche pas |
|
| 232 | - $ok = false; |
|
| 233 | - if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | - if (!function_exists('creer_uniqid')) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - } |
|
| 237 | - $id = creer_uniqid(); |
|
| 238 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | - $s = @fwrite($fp2, (string) $contenu, $a = strlen((string) $contenu)); |
|
| 241 | - $ok = ($s === $a); |
|
| 242 | - spip_fclose_unlock($fp2); |
|
| 243 | - spip_fclose_unlock($fp); |
|
| 244 | - $fp = null; |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - $fp = null; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - // sinon ou si methode precedente a echoueee |
|
| 266 | - // on se rabat sur la methode ancienne |
|
| 267 | - if (!$ok && !is_null($fp)) { |
|
| 268 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | - if ($truncate) { |
|
| 270 | - @ftruncate($fp, 0); |
|
| 271 | - } |
|
| 272 | - $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | - |
|
| 274 | - $ok = ($s == $a); |
|
| 275 | - spip_fclose_unlock($fp); |
|
| 276 | - } |
|
| 277 | - // on tente une dernière fois file_put_contents |
|
| 278 | - if (!$ok) { |
|
| 279 | - $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | - $ok = ($l === strlen($contenu)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // liberer le verrou et fermer le fichier |
|
| 284 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | - if ($ok) { |
|
| 286 | - if (str_contains($fichier, '.php')) { |
|
| 287 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $ok; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$ignorer_echec) { |
|
| 295 | - include_spip('inc/autoriser'); |
|
| 296 | - if (autoriser('chargerftp')) { |
|
| 297 | - raler_fichier($fichier); |
|
| 298 | - } |
|
| 299 | - spip_unlink($fichier); |
|
| 300 | - } |
|
| 301 | - spip_logger()->notice("Ecriture fichier $fichier impossible"); |
|
| 302 | - |
|
| 303 | - return false; |
|
| 218 | + #spip_timer('ecrire_fichier'); |
|
| 219 | + |
|
| 220 | + // verrouiller le fichier destination |
|
| 221 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | + // ecrire les donnees, compressees le cas echeant |
|
| 223 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | + if (str_ends_with($fichier, '.gz')) { |
|
| 226 | + $contenu = gzencode($contenu); |
|
| 227 | + } |
|
| 228 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | + // pour etre sur d'avoir une operation atomique |
|
| 230 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | + // sauf sous wintruc ou ca ne marche pas |
|
| 232 | + $ok = false; |
|
| 233 | + if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | + if (!function_exists('creer_uniqid')) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + } |
|
| 237 | + $id = creer_uniqid(); |
|
| 238 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | + $s = @fwrite($fp2, (string) $contenu, $a = strlen((string) $contenu)); |
|
| 241 | + $ok = ($s === $a); |
|
| 242 | + spip_fclose_unlock($fp2); |
|
| 243 | + spip_fclose_unlock($fp); |
|
| 244 | + $fp = null; |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + $fp = null; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + // sinon ou si methode precedente a echoueee |
|
| 266 | + // on se rabat sur la methode ancienne |
|
| 267 | + if (!$ok && !is_null($fp)) { |
|
| 268 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | + if ($truncate) { |
|
| 270 | + @ftruncate($fp, 0); |
|
| 271 | + } |
|
| 272 | + $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | + |
|
| 274 | + $ok = ($s == $a); |
|
| 275 | + spip_fclose_unlock($fp); |
|
| 276 | + } |
|
| 277 | + // on tente une dernière fois file_put_contents |
|
| 278 | + if (!$ok) { |
|
| 279 | + $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | + $ok = ($l === strlen($contenu)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // liberer le verrou et fermer le fichier |
|
| 284 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | + if ($ok) { |
|
| 286 | + if (str_contains($fichier, '.php')) { |
|
| 287 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $ok; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$ignorer_echec) { |
|
| 295 | + include_spip('inc/autoriser'); |
|
| 296 | + if (autoriser('chargerftp')) { |
|
| 297 | + raler_fichier($fichier); |
|
| 298 | + } |
|
| 299 | + spip_unlink($fichier); |
|
| 300 | + } |
|
| 301 | + spip_logger()->notice("Ecriture fichier $fichier impossible"); |
|
| 302 | + |
|
| 303 | + return false; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | * Écriture avec troncation ? |
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | - if (!str_ends_with($fichier, '.php')) { |
|
| 324 | - spip_logger()->info('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | - } |
|
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 323 | + if (!str_ends_with($fichier, '.php')) { |
|
| 324 | + spip_logger()->info('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | + } |
|
| 326 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 327 | 327 | |
| 328 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 328 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 340 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - if ( |
|
| 344 | - $force |
|
| 345 | - || !file_exists($fichier) |
|
| 346 | - || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | - ) { |
|
| 348 | - if ($use_copy) { |
|
| 349 | - @copy($fichier_tmp, $fichier); |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - @rename($fichier_tmp, $fichier); |
|
| 353 | - } |
|
| 354 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | - clearstatcache(true, $fichier); |
|
| 356 | - } |
|
| 357 | - return true; |
|
| 339 | + $fichier_tmp = $fichier . '.last'; |
|
| 340 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + if ( |
|
| 344 | + $force |
|
| 345 | + || !file_exists($fichier) |
|
| 346 | + || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | + ) { |
|
| 348 | + if ($use_copy) { |
|
| 349 | + @copy($fichier_tmp, $fichier); |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + @rename($fichier_tmp, $fichier); |
|
| 353 | + } |
|
| 354 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | + clearstatcache(true, $fichier); |
|
| 356 | + } |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -375,11 +375,11 @@ discard block |
||
| 375 | 375 | * true si l'opération a réussie, false sinon. |
| 376 | 376 | */ |
| 377 | 377 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 378 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | - $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?>' . "\n")); |
|
| 380 | - } |
|
| 378 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | + $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?>' . "\n")); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - return $res; |
|
| 382 | + return $res; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -391,25 +391,25 @@ discard block |
||
| 391 | 391 | * @uses minipres() Pour afficher le message |
| 392 | 392 | **/ |
| 393 | 393 | function raler_fichier(string $fichier): never { |
| 394 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 395 | - spip_initialisation_suite(); |
|
| 396 | - } |
|
| 397 | - include_spip('inc/minipres'); |
|
| 398 | - $dir = dirname($fichier); |
|
| 399 | - http_response_code(401); |
|
| 400 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 401 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 402 | - . " <a href='" |
|
| 403 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 404 | - . "'>" |
|
| 405 | - . _T('texte_inc_meta_2') |
|
| 406 | - . '</a> ' |
|
| 407 | - . _T( |
|
| 408 | - 'texte_inc_meta_3', |
|
| 409 | - ['repertoire' => joli_repertoire($dir)] |
|
| 410 | - ) |
|
| 411 | - . "</h4>\n"); |
|
| 412 | - exit; |
|
| 394 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 395 | + spip_initialisation_suite(); |
|
| 396 | + } |
|
| 397 | + include_spip('inc/minipres'); |
|
| 398 | + $dir = dirname($fichier); |
|
| 399 | + http_response_code(401); |
|
| 400 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 401 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 402 | + . " <a href='" |
|
| 403 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 404 | + . "'>" |
|
| 405 | + . _T('texte_inc_meta_2') |
|
| 406 | + . '</a> ' |
|
| 407 | + . _T( |
|
| 408 | + 'texte_inc_meta_3', |
|
| 409 | + ['repertoire' => joli_repertoire($dir)] |
|
| 410 | + ) |
|
| 411 | + . "</h4>\n"); |
|
| 412 | + exit; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | |
@@ -424,14 +424,14 @@ discard block |
||
| 424 | 424 | * - true si récent, false sinon |
| 425 | 425 | */ |
| 426 | 426 | function jeune_fichier($fichier, $n) { |
| 427 | - if (!file_exists($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if (!$c = @filemtime($fichier)) { |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return (time() - $n <= $c); |
|
| 427 | + if (!file_exists($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if (!$c = @filemtime($fichier)) { |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return (time() - $n <= $c); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -446,22 +446,22 @@ discard block |
||
| 446 | 446 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 447 | 447 | */ |
| 448 | 448 | function supprimer_fichier($fichier, $lock = true) { |
| 449 | - if (!@file_exists($fichier)) { |
|
| 450 | - return true; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - if ($lock) { |
|
| 454 | - // verrouiller le fichier destination |
|
| 455 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // liberer le verrou |
|
| 460 | - spip_fclose_unlock($fp); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // supprimer |
|
| 464 | - return @unlink($fichier); |
|
| 449 | + if (!@file_exists($fichier)) { |
|
| 450 | + return true; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + if ($lock) { |
|
| 454 | + // verrouiller le fichier destination |
|
| 455 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // liberer le verrou |
|
| 460 | + spip_fclose_unlock($fp); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // supprimer |
|
| 464 | + return @unlink($fichier); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -471,12 +471,12 @@ discard block |
||
| 471 | 471 | * Chemin du fichier |
| 472 | 472 | */ |
| 473 | 473 | function spip_unlink($f) { |
| 474 | - if (!is_dir($f)) { |
|
| 475 | - supprimer_fichier($f, false); |
|
| 476 | - } else { |
|
| 477 | - @unlink("$f/.ok"); |
|
| 478 | - @rmdir($f); |
|
| 479 | - } |
|
| 474 | + if (!is_dir($f)) { |
|
| 475 | + supprimer_fichier($f, false); |
|
| 476 | + } else { |
|
| 477 | + @unlink("$f/.ok"); |
|
| 478 | + @rmdir($f); |
|
| 479 | + } |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -490,26 +490,26 @@ discard block |
||
| 490 | 490 | * The absolute path of the PHP file to invalidate. |
| 491 | 491 | */ |
| 492 | 492 | function spip_clear_opcode_cache($filepath) { |
| 493 | - clearstatcache(true, $filepath); |
|
| 494 | - |
|
| 495 | - // Zend OPcache |
|
| 496 | - if (function_exists('opcache_invalidate')) { |
|
| 497 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 498 | - // si l'invalidation a echoue lever un flag |
|
| 499 | - if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 501 | - } |
|
| 502 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 504 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 505 | - } |
|
| 506 | - // APC. |
|
| 507 | - if (function_exists('apc_delete_file')) { |
|
| 508 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 509 | - // not compiled yet. |
|
| 510 | - // @see http://php.net/apc-delete-file |
|
| 511 | - @apc_delete_file($filepath); |
|
| 512 | - } |
|
| 493 | + clearstatcache(true, $filepath); |
|
| 494 | + |
|
| 495 | + // Zend OPcache |
|
| 496 | + if (function_exists('opcache_invalidate')) { |
|
| 497 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 498 | + // si l'invalidation a echoue lever un flag |
|
| 499 | + if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 501 | + } |
|
| 502 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 504 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 505 | + } |
|
| 506 | + // APC. |
|
| 507 | + if (function_exists('apc_delete_file')) { |
|
| 508 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 509 | + // not compiled yet. |
|
| 510 | + // @see http://php.net/apc-delete-file |
|
| 511 | + @apc_delete_file($filepath); |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | */ |
| 534 | 534 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 535 | - if ( |
|
| 536 | - function_exists('opcache_get_configuration') |
|
| 537 | - && @ini_get('opcache.enable') |
|
| 538 | - && @ini_get('opcache.validate_timestamps') |
|
| 539 | - && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 540 | - && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 541 | - ) { |
|
| 542 | - $wait = $duree + 1; |
|
| 543 | - if ($timestamp) { |
|
| 544 | - $wait -= (time() - $timestamp); |
|
| 545 | - if ($wait < 0) { |
|
| 546 | - $wait = 0; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - spip_logger()->notice('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's'); |
|
| 550 | - if ($wait) { |
|
| 551 | - sleep($duree + 1); |
|
| 552 | - } |
|
| 553 | - } |
|
| 535 | + if ( |
|
| 536 | + function_exists('opcache_get_configuration') |
|
| 537 | + && @ini_get('opcache.enable') |
|
| 538 | + && @ini_get('opcache.validate_timestamps') |
|
| 539 | + && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 540 | + && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 541 | + ) { |
|
| 542 | + $wait = $duree + 1; |
|
| 543 | + if ($timestamp) { |
|
| 544 | + $wait -= (time() - $timestamp); |
|
| 545 | + if ($wait < 0) { |
|
| 546 | + $wait = 0; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + spip_logger()->notice('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's'); |
|
| 550 | + if ($wait) { |
|
| 551 | + sleep($duree + 1); |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -563,26 +563,26 @@ discard block |
||
| 563 | 563 | * @return bool Suppression reussie. |
| 564 | 564 | */ |
| 565 | 565 | function supprimer_repertoire($dir) { |
| 566 | - if (!file_exists($dir)) { |
|
| 567 | - return true; |
|
| 568 | - } |
|
| 569 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 570 | - return @unlink($dir); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - foreach (scandir($dir) as $item) { |
|
| 574 | - if ($item == '.' || $item == '..') { |
|
| 575 | - continue; |
|
| 576 | - } |
|
| 577 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 578 | - @chmod($dir . '/' . $item, 0777); |
|
| 579 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 580 | - return false; |
|
| 581 | - } |
|
| 582 | - }; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - return @rmdir($dir); |
|
| 566 | + if (!file_exists($dir)) { |
|
| 567 | + return true; |
|
| 568 | + } |
|
| 569 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 570 | + return @unlink($dir); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + foreach (scandir($dir) as $item) { |
|
| 574 | + if ($item == '.' || $item == '..') { |
|
| 575 | + continue; |
|
| 576 | + } |
|
| 577 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 578 | + @chmod($dir . '/' . $item, 0777); |
|
| 579 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 582 | + }; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + return @rmdir($dir); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | |
@@ -611,58 +611,58 @@ discard block |
||
| 611 | 611 | * Chemin du répertoire créé. |
| 612 | 612 | **/ |
| 613 | 613 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false): string { |
| 614 | - static $dirs = []; |
|
| 615 | - |
|
| 616 | - $base = str_replace('//', '/', $base); |
|
| 617 | - |
|
| 618 | - # suppr le dernier caractere si c'est un / |
|
| 619 | - $base = rtrim($base, '/'); |
|
| 620 | - |
|
| 621 | - if (!strlen($subdir)) { |
|
| 622 | - $n = strrpos($base, '/'); |
|
| 623 | - if ($n === false) { |
|
| 624 | - return $nobase ? '' : ($base . '/'); |
|
| 625 | - } |
|
| 626 | - $subdir = substr($base, $n + 1); |
|
| 627 | - $base = substr($base, 0, $n + 1); |
|
| 628 | - } else { |
|
| 629 | - $base .= '/'; |
|
| 630 | - $subdir = str_replace('/', '', $subdir); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - $baseaff = $nobase ? '' : $base; |
|
| 634 | - if (isset($dirs[$base . $subdir])) { |
|
| 635 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 639 | - |
|
| 640 | - if (file_exists("$path/.ok")) { |
|
| 641 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - @mkdir($path, _SPIP_CHMOD); |
|
| 645 | - @chmod($path, _SPIP_CHMOD); |
|
| 646 | - |
|
| 647 | - if (is_dir($path) && is_writable($path)) { |
|
| 648 | - @touch("$path/.ok"); |
|
| 649 | - spip_logger()->info("creation $base$subdir/"); |
|
| 650 | - |
|
| 651 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 655 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 656 | - spip_logger()->info("echec creation $base{$subdir}"); |
|
| 657 | - if ($tantpis) { |
|
| 658 | - return ''; |
|
| 659 | - } |
|
| 660 | - // FIXME: throw an Exception… |
|
| 661 | - if (!_DIR_RESTREINT) { |
|
| 662 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 663 | - } |
|
| 664 | - $base .= $subdir; |
|
| 665 | - raler_fichier($base . '/.ok'); |
|
| 614 | + static $dirs = []; |
|
| 615 | + |
|
| 616 | + $base = str_replace('//', '/', $base); |
|
| 617 | + |
|
| 618 | + # suppr le dernier caractere si c'est un / |
|
| 619 | + $base = rtrim($base, '/'); |
|
| 620 | + |
|
| 621 | + if (!strlen($subdir)) { |
|
| 622 | + $n = strrpos($base, '/'); |
|
| 623 | + if ($n === false) { |
|
| 624 | + return $nobase ? '' : ($base . '/'); |
|
| 625 | + } |
|
| 626 | + $subdir = substr($base, $n + 1); |
|
| 627 | + $base = substr($base, 0, $n + 1); |
|
| 628 | + } else { |
|
| 629 | + $base .= '/'; |
|
| 630 | + $subdir = str_replace('/', '', $subdir); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + $baseaff = $nobase ? '' : $base; |
|
| 634 | + if (isset($dirs[$base . $subdir])) { |
|
| 635 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 639 | + |
|
| 640 | + if (file_exists("$path/.ok")) { |
|
| 641 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + @mkdir($path, _SPIP_CHMOD); |
|
| 645 | + @chmod($path, _SPIP_CHMOD); |
|
| 646 | + |
|
| 647 | + if (is_dir($path) && is_writable($path)) { |
|
| 648 | + @touch("$path/.ok"); |
|
| 649 | + spip_logger()->info("creation $base$subdir/"); |
|
| 650 | + |
|
| 651 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 655 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 656 | + spip_logger()->info("echec creation $base{$subdir}"); |
|
| 657 | + if ($tantpis) { |
|
| 658 | + return ''; |
|
| 659 | + } |
|
| 660 | + // FIXME: throw an Exception… |
|
| 661 | + if (!_DIR_RESTREINT) { |
|
| 662 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 663 | + } |
|
| 664 | + $base .= $subdir; |
|
| 665 | + raler_fichier($base . '/.ok'); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -695,55 +695,55 @@ discard block |
||
| 695 | 695 | * Chemins des fichiers trouvés. |
| 696 | 696 | **/ |
| 697 | 697 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 698 | - $nbfiles = 0; |
|
| 699 | - if ($pattern == -1) { |
|
| 700 | - $pattern = ''; |
|
| 701 | - } |
|
| 702 | - $fichiers = []; |
|
| 703 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 704 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 705 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 706 | - if ($dir == '') { |
|
| 707 | - $dir = '.'; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 711 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 712 | - if ( |
|
| 713 | - $f[0] != '.' |
|
| 714 | - && $f != 'remove.txt' |
|
| 715 | - && is_readable($f = "$dir/$f") |
|
| 716 | - ) { |
|
| 717 | - if (is_file($f)) { |
|
| 718 | - if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 719 | - $fichiers[] = $f; |
|
| 720 | - $nbfiles++; |
|
| 721 | - } |
|
| 722 | - } else { |
|
| 723 | - if (is_dir($f) && is_array($recurs)) { |
|
| 724 | - $rp = @realpath($f); |
|
| 725 | - if (!is_string($rp) || !strlen($rp)) { |
|
| 726 | - $rp = $f; |
|
| 727 | - } # realpath n'est peut etre pas autorise |
|
| 728 | - if (!isset($recurs[$rp])) { |
|
| 729 | - $recurs[$rp] = true; |
|
| 730 | - $beginning = $fichiers; |
|
| 731 | - $end = preg_files( |
|
| 732 | - "$f/", |
|
| 733 | - $pattern, |
|
| 734 | - $maxfiles - $nbfiles, |
|
| 735 | - $recurs |
|
| 736 | - ); |
|
| 737 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 738 | - $nbfiles = count($fichiers); |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - closedir($d); |
|
| 745 | - } |
|
| 746 | - sort($fichiers); |
|
| 747 | - |
|
| 748 | - return $fichiers; |
|
| 698 | + $nbfiles = 0; |
|
| 699 | + if ($pattern == -1) { |
|
| 700 | + $pattern = ''; |
|
| 701 | + } |
|
| 702 | + $fichiers = []; |
|
| 703 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 704 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 705 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 706 | + if ($dir == '') { |
|
| 707 | + $dir = '.'; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 711 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 712 | + if ( |
|
| 713 | + $f[0] != '.' |
|
| 714 | + && $f != 'remove.txt' |
|
| 715 | + && is_readable($f = "$dir/$f") |
|
| 716 | + ) { |
|
| 717 | + if (is_file($f)) { |
|
| 718 | + if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 719 | + $fichiers[] = $f; |
|
| 720 | + $nbfiles++; |
|
| 721 | + } |
|
| 722 | + } else { |
|
| 723 | + if (is_dir($f) && is_array($recurs)) { |
|
| 724 | + $rp = @realpath($f); |
|
| 725 | + if (!is_string($rp) || !strlen($rp)) { |
|
| 726 | + $rp = $f; |
|
| 727 | + } # realpath n'est peut etre pas autorise |
|
| 728 | + if (!isset($recurs[$rp])) { |
|
| 729 | + $recurs[$rp] = true; |
|
| 730 | + $beginning = $fichiers; |
|
| 731 | + $end = preg_files( |
|
| 732 | + "$f/", |
|
| 733 | + $pattern, |
|
| 734 | + $maxfiles - $nbfiles, |
|
| 735 | + $recurs |
|
| 736 | + ); |
|
| 737 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 738 | + $nbfiles = count($fichiers); |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + closedir($d); |
|
| 745 | + } |
|
| 746 | + sort($fichiers); |
|
| 747 | + |
|
| 748 | + return $fichiers; |
|
| 749 | 749 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -56,106 +56,106 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | */ |
| 58 | 58 | function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) { |
| 59 | - static $current_base = null; |
|
| 59 | + static $current_base = null; |
|
| 60 | 60 | |
| 61 | - // les anciennes fonctions modifient directement les globales |
|
| 62 | - // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | - $save = [ |
|
| 64 | - $GLOBALS['fond'] ?? null, |
|
| 65 | - $GLOBALS['contexte'] ?? null, |
|
| 66 | - $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | - $_ENV['url_propre'] ?? null, |
|
| 68 | - $GLOBALS['profondeur_url'] |
|
| 69 | - ]; |
|
| 61 | + // les anciennes fonctions modifient directement les globales |
|
| 62 | + // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | + $save = [ |
|
| 64 | + $GLOBALS['fond'] ?? null, |
|
| 65 | + $GLOBALS['contexte'] ?? null, |
|
| 66 | + $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | + $_ENV['url_propre'] ?? null, |
|
| 68 | + $GLOBALS['profondeur_url'] |
|
| 69 | + ]; |
|
| 70 | 70 | |
| 71 | - if (is_null($current_base)) { |
|
| 72 | - include_spip('inc/filtres_mini'); |
|
| 73 | - // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | - $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | - } |
|
| 76 | - if (str_starts_with($url, $current_base)) { |
|
| 77 | - $url = substr($url, strlen($current_base)); |
|
| 78 | - } |
|
| 71 | + if (is_null($current_base)) { |
|
| 72 | + include_spip('inc/filtres_mini'); |
|
| 73 | + // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | + $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | + } |
|
| 76 | + if (str_starts_with($url, $current_base)) { |
|
| 77 | + $url = substr($url, strlen($current_base)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // si on est en train d'assembler la page principale, |
|
| 81 | - // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | - // sinon extraire la bonne portion d'url |
|
| 83 | - if ($assembler) { |
|
| 84 | - if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | - $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | - } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | - $url = $_ENV['url_propre']; |
|
| 88 | - } else { |
|
| 89 | - $qs = explode('?', $url); |
|
| 90 | - // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | - $url = ltrim($qs[0], '/'); |
|
| 92 | - $url = explode('/', $url); |
|
| 93 | - while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | - array_shift($url); |
|
| 95 | - } |
|
| 96 | - $qs[0] = implode('/', $url); |
|
| 97 | - $url = implode('?', $qs); |
|
| 98 | - } |
|
| 99 | - } |
|
| 80 | + // si on est en train d'assembler la page principale, |
|
| 81 | + // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | + // sinon extraire la bonne portion d'url |
|
| 83 | + if ($assembler) { |
|
| 84 | + if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | + $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | + } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | + $url = $_ENV['url_propre']; |
|
| 88 | + } else { |
|
| 89 | + $qs = explode('?', $url); |
|
| 90 | + // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | + $url = ltrim($qs[0], '/'); |
|
| 92 | + $url = explode('/', $url); |
|
| 93 | + while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | + array_shift($url); |
|
| 95 | + } |
|
| 96 | + $qs[0] = implode('/', $url); |
|
| 97 | + $url = implode('?', $qs); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | - unset($_ENV['url_propre']); |
|
| 103 | - include_spip('inc/filtres_mini'); |
|
| 104 | - if (!str_contains($url, '://')) { |
|
| 105 | - $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | - } else { |
|
| 107 | - $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | - } |
|
| 101 | + unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | + unset($_ENV['url_propre']); |
|
| 103 | + include_spip('inc/filtres_mini'); |
|
| 104 | + if (!str_contains($url, '://')) { |
|
| 105 | + $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | + } else { |
|
| 107 | + $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - $url_redirect = ''; |
|
| 111 | - $decoder = charger_fonction_url('decoder'); |
|
| 112 | - if ($decoder) { |
|
| 113 | - $a = $decoder($url, $fond, $contexte); |
|
| 114 | - if (is_array($a)) { |
|
| 115 | - [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | - $url_redirect ??= ''; |
|
| 117 | - if ($url_redirect === $url) { |
|
| 118 | - $url_redirect = ''; |
|
| 119 | - } // securite pour eviter une redirection infinie |
|
| 120 | - if ($assembler && strlen($url_redirect)) { |
|
| 121 | - spip_logger()->info("Redirige $url vers $url_redirect"); |
|
| 122 | - include_spip('inc/headers'); |
|
| 123 | - redirige_par_entete($url_redirect, '', 301); |
|
| 124 | - } |
|
| 125 | - if (isset($nfond)) { |
|
| 126 | - $fond = $nfond; |
|
| 127 | - } else { |
|
| 128 | - if ( |
|
| 129 | - $fond == '' |
|
| 130 | - || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | - ) { |
|
| 132 | - $fond = $type; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (isset($ncontexte)) { |
|
| 136 | - $contexte = $ncontexte; |
|
| 137 | - } |
|
| 138 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | - $contexte['type'] = $type; |
|
| 140 | - } |
|
| 141 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | - $contexte['type-page'] = $type; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 110 | + $url_redirect = ''; |
|
| 111 | + $decoder = charger_fonction_url('decoder'); |
|
| 112 | + if ($decoder) { |
|
| 113 | + $a = $decoder($url, $fond, $contexte); |
|
| 114 | + if (is_array($a)) { |
|
| 115 | + [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | + $url_redirect ??= ''; |
|
| 117 | + if ($url_redirect === $url) { |
|
| 118 | + $url_redirect = ''; |
|
| 119 | + } // securite pour eviter une redirection infinie |
|
| 120 | + if ($assembler && strlen($url_redirect)) { |
|
| 121 | + spip_logger()->info("Redirige $url vers $url_redirect"); |
|
| 122 | + include_spip('inc/headers'); |
|
| 123 | + redirige_par_entete($url_redirect, '', 301); |
|
| 124 | + } |
|
| 125 | + if (isset($nfond)) { |
|
| 126 | + $fond = $nfond; |
|
| 127 | + } else { |
|
| 128 | + if ( |
|
| 129 | + $fond == '' |
|
| 130 | + || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | + ) { |
|
| 132 | + $fond = $type; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (isset($ncontexte)) { |
|
| 136 | + $contexte = $ncontexte; |
|
| 137 | + } |
|
| 138 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | + $contexte['type'] = $type; |
|
| 140 | + } |
|
| 141 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | + $contexte['type-page'] = $type; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - // retablir les globales |
|
| 148 | - [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 147 | + // retablir les globales |
|
| 148 | + [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 149 | 149 | |
| 150 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | - // d'inversion url => objet |
|
| 152 | - // maintenir pour compat ? |
|
| 153 | - #if ($assembler) { |
|
| 154 | - # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | - # unset($_ENV['url_propre']); |
|
| 156 | - #} |
|
| 150 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | + // d'inversion url => objet |
|
| 152 | + // maintenir pour compat ? |
|
| 153 | + #if ($assembler) { |
|
| 154 | + # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | + # unset($_ENV['url_propre']); |
|
| 156 | + #} |
|
| 157 | 157 | |
| 158 | - return [$fond, $contexte, $url_redirect]; |
|
| 158 | + return [$fond, $contexte, $url_redirect]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 164 | 164 | */ |
| 165 | 165 | function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array { |
| 166 | - if ($url_propre) { |
|
| 167 | - if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | - $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | - } else { |
|
| 170 | - $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | - } |
|
| 166 | + if ($url_propre) { |
|
| 167 | + if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | + $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | + } else { |
|
| 170 | + $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($urls_anciennes) { |
|
| 174 | - $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | - } |
|
| 176 | - return $urls_anciennes ?: []; |
|
| 177 | - } |
|
| 173 | + if ($urls_anciennes) { |
|
| 174 | + $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | + } |
|
| 176 | + return $urls_anciennes ?: []; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - return []; |
|
| 179 | + return []; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -184,41 +184,41 @@ discard block |
||
| 184 | 184 | * le mode 'urls-html/standard' vers les modes 'urls propres|arbos' |
| 185 | 185 | */ |
| 186 | 186 | function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array { |
| 187 | - // Migration depuis anciennes URLs ? |
|
| 188 | - // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | - if ( |
|
| 190 | - $url |
|
| 191 | - && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | - ) { |
|
| 193 | - $r = nettoyer_url_page($url, $contexte); |
|
| 194 | - if ($r) { |
|
| 195 | - [$contexte, $type, , , $suite] = $r; |
|
| 196 | - $_id = id_table_objet($type); |
|
| 197 | - $id_objet = $contexte[$_id]; |
|
| 198 | - $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | - if ( |
|
| 200 | - strlen($url_propre) |
|
| 201 | - && !strstr($url, (string) $url_propre) |
|
| 202 | - && ( |
|
| 203 | - objet_test_si_publie($type, $id_objet) |
|
| 204 | - || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | - $args = []; |
|
| 209 | - foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | - if ($fragment != "$_id=$id_objet") { |
|
| 211 | - $args[] = $fragment; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 187 | + // Migration depuis anciennes URLs ? |
|
| 188 | + // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | + if ( |
|
| 190 | + $url |
|
| 191 | + && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | + ) { |
|
| 193 | + $r = nettoyer_url_page($url, $contexte); |
|
| 194 | + if ($r) { |
|
| 195 | + [$contexte, $type, , , $suite] = $r; |
|
| 196 | + $_id = id_table_objet($type); |
|
| 197 | + $id_objet = $contexte[$_id]; |
|
| 198 | + $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | + if ( |
|
| 200 | + strlen($url_propre) |
|
| 201 | + && !strstr($url, (string) $url_propre) |
|
| 202 | + && ( |
|
| 203 | + objet_test_si_publie($type, $id_objet) |
|
| 204 | + || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | + $args = []; |
|
| 209 | + foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | + if ($fragment != "$_id=$id_objet") { |
|
| 211 | + $args[] = $fragment; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 215 | 215 | |
| 216 | - return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - /* Fin compatibilite anciennes urls */ |
|
| 221 | - return []; |
|
| 216 | + return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + /* Fin compatibilite anciennes urls */ |
|
| 221 | + return []; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -231,24 +231,24 @@ discard block |
||
| 231 | 231 | * @return string|array |
| 232 | 232 | */ |
| 233 | 233 | function urls_liste_objets($preg = true) { |
| 234 | - static $url_objets = null; |
|
| 235 | - if (is_null($url_objets)) { |
|
| 236 | - $url_objets = []; |
|
| 237 | - // recuperer les tables_objets_sql declarees |
|
| 238 | - $tables_objets = lister_tables_objets_sql(); |
|
| 239 | - foreach ($tables_objets as $t => $infos) { |
|
| 240 | - if ($infos['page']) { |
|
| 241 | - $url_objets[] = $infos['type']; |
|
| 242 | - $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | - } |
|
| 247 | - if (!$preg) { |
|
| 248 | - return $url_objets; |
|
| 249 | - } |
|
| 234 | + static $url_objets = null; |
|
| 235 | + if (is_null($url_objets)) { |
|
| 236 | + $url_objets = []; |
|
| 237 | + // recuperer les tables_objets_sql declarees |
|
| 238 | + $tables_objets = lister_tables_objets_sql(); |
|
| 239 | + foreach ($tables_objets as $t => $infos) { |
|
| 240 | + if ($infos['page']) { |
|
| 241 | + $url_objets[] = $infos['type']; |
|
| 242 | + $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | + } |
|
| 247 | + if (!$preg) { |
|
| 248 | + return $url_objets; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return implode('|', array_map('preg_quote', $url_objets)); |
|
| 251 | + return implode('|', array_map('preg_quote', $url_objets)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -262,26 +262,26 @@ discard block |
||
| 262 | 262 | * @return array |
| 263 | 263 | */ |
| 264 | 264 | function nettoyer_url_page($url, $contexte = []) { |
| 265 | - $url_objets = urls_liste_objets(); |
|
| 266 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 265 | + $url_objets = urls_liste_objets(); |
|
| 266 | + $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | + $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | - || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | - || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | - ) { |
|
| 275 | - $regs = array_pad($regs, 4, null); |
|
| 276 | - $type = objet_type($regs[1]); |
|
| 277 | - $_id = id_table_objet($type); |
|
| 278 | - $contexte[$_id] = $regs[2]; |
|
| 279 | - $suite = $regs[3]; |
|
| 270 | + if ( |
|
| 271 | + preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | + || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | + || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | + ) { |
|
| 275 | + $regs = array_pad($regs, 4, null); |
|
| 276 | + $type = objet_type($regs[1]); |
|
| 277 | + $_id = id_table_objet($type); |
|
| 278 | + $contexte[$_id] = $regs[2]; |
|
| 279 | + $suite = $regs[3]; |
|
| 280 | 280 | |
| 281 | - return [$contexte, $type, null, $type, $suite]; |
|
| 282 | - } |
|
| 281 | + return [$contexte, $type, null, $type, $suite]; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - return []; |
|
| 284 | + return []; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -299,35 +299,35 @@ discard block |
||
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | 301 | function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string { |
| 302 | - static $furls = []; |
|
| 303 | - $id = intval($id); |
|
| 304 | - if (!isset($furls[$objet])) { |
|
| 305 | - if ( |
|
| 306 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | - || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | - || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | - || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | - ) { |
|
| 311 | - $furls[$objet] = $f; |
|
| 312 | - } else { |
|
| 313 | - $furls[$objet] = ''; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - if ($furls[$objet]) { |
|
| 317 | - return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | - } |
|
| 319 | - // si pas de flag public fourni |
|
| 320 | - // le calculer en fonction de la declaration de statut |
|
| 321 | - if (is_null($public) && !$connect) { |
|
| 322 | - $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | - } |
|
| 324 | - if ($public || $connect) { |
|
| 325 | - return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | - } |
|
| 327 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | - if (!function_exists('objet_info')) { |
|
| 329 | - include_spip('inc/filtres'); |
|
| 330 | - } |
|
| 302 | + static $furls = []; |
|
| 303 | + $id = intval($id); |
|
| 304 | + if (!isset($furls[$objet])) { |
|
| 305 | + if ( |
|
| 306 | + function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | + || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | + || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | + || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | + ) { |
|
| 311 | + $furls[$objet] = $f; |
|
| 312 | + } else { |
|
| 313 | + $furls[$objet] = ''; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + if ($furls[$objet]) { |
|
| 317 | + return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | + } |
|
| 319 | + // si pas de flag public fourni |
|
| 320 | + // le calculer en fonction de la declaration de statut |
|
| 321 | + if (is_null($public) && !$connect) { |
|
| 322 | + $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | + } |
|
| 324 | + if ($public || $connect) { |
|
| 325 | + return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | + } |
|
| 327 | + $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | + if (!function_exists('objet_info')) { |
|
| 329 | + include_spip('inc/filtres'); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 332 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 333 | 333 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Notifications |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function inc_notifications_dist($quoi, $id = 0, $options = []) { |
| 34 | 34 | |
| 35 | - // charger les fichiers qui veulent ajouter des definitions |
|
| 36 | - // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 37 | - pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 35 | + // charger les fichiers qui veulent ajouter des definitions |
|
| 36 | + // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 37 | + pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 38 | 38 | |
| 39 | - if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 40 | - spip_logger('notifications')->info("$notification($quoi,$id" |
|
| 41 | - . ($options ? ',' . serialize($options) : '') |
|
| 42 | - . ')'); |
|
| 43 | - $notification($quoi, $id, $options); |
|
| 44 | - } |
|
| 39 | + if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 40 | + spip_logger('notifications')->info("$notification($quoi,$id" |
|
| 41 | + . ($options ? ',' . serialize($options) : '') |
|
| 42 | + . ')'); |
|
| 43 | + $notification($quoi, $id, $options); |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @param array $exclure |
| 56 | 56 | */ |
| 57 | 57 | function notifications_nettoyer_emails(&$emails, $exclure = []) { |
| 58 | - // filtrer et unifier |
|
| 59 | - include_spip('inc/filtres'); |
|
| 60 | - $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | - if ($exclure && count($exclure)) { |
|
| 62 | - // nettoyer les exclusions d'abord |
|
| 63 | - notifications_nettoyer_emails($exclure); |
|
| 64 | - // faire un diff |
|
| 65 | - $emails = array_diff($emails, $exclure); |
|
| 66 | - } |
|
| 58 | + // filtrer et unifier |
|
| 59 | + include_spip('inc/filtres'); |
|
| 60 | + $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | + if ($exclure && count($exclure)) { |
|
| 62 | + // nettoyer les exclusions d'abord |
|
| 63 | + notifications_nettoyer_emails($exclure); |
|
| 64 | + // faire un diff |
|
| 65 | + $emails = array_diff($emails, $exclure); |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,90 +78,90 @@ discard block |
||
| 78 | 78 | * @param string $headers |
| 79 | 79 | */ |
| 80 | 80 | function notifications_envoyer_mails($emails, $texte, $sujet = '', $from = '', $headers = '') { |
| 81 | - // rien a faire si pas de texte ! |
|
| 82 | - if (!strlen($texte)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | - if (!is_array($emails)) { |
|
| 88 | - $emails = explode(',', $emails); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - notifications_nettoyer_emails($emails); |
|
| 92 | - |
|
| 93 | - // tester si le mail est deja en html |
|
| 94 | - if ( |
|
| 95 | - str_contains($texte, '<') |
|
| 96 | - && ($ttrim = trim($texte)) |
|
| 97 | - && str_starts_with($ttrim, '<') |
|
| 98 | - && str_ends_with($ttrim, '>') |
|
| 99 | - && stripos($ttrim, '</html>') !== false |
|
| 100 | - ) { |
|
| 101 | - if (!strlen($sujet)) { |
|
| 102 | - // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | - if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 104 | - $sujet = $m[1]; |
|
| 105 | - } else { |
|
| 106 | - // fallback, on prend le body si on le trouve |
|
| 107 | - if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 108 | - $ttrim = $m[1]; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // et on extrait la premiere ligne de vrai texte... |
|
| 112 | - // nettoyer le html et les retours chariots |
|
| 113 | - $ttrim = textebrut($ttrim); |
|
| 114 | - $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | - $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | - // decouper |
|
| 117 | - $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | - // extraire la premiere ligne de texte brut |
|
| 119 | - $sujet = array_shift($ttrim); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // si besoin on ajoute le content-type dans les headers |
|
| 124 | - if (stripos($headers, 'Content-Type') === false) { |
|
| 125 | - $headers .= "Content-Type: text/html\n"; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | - // du mail qui est donc du texte |
|
| 131 | - if (!strlen($sujet)) { |
|
| 132 | - // nettoyer un peu les retours chariots |
|
| 133 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | - $texte = str_replace("\r", "\n", $texte); |
|
| 135 | - // decouper |
|
| 136 | - $texte = explode("\n", trim($texte)); |
|
| 137 | - // extraire la premiere ligne |
|
| 138 | - $sujet = array_shift($texte); |
|
| 139 | - $texte = trim(implode("\n", $texte)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | - foreach ($emails as $email) { |
|
| 144 | - // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | - // (url de suivi des notifications par exemple) |
|
| 146 | - $envoi = pipeline( |
|
| 147 | - 'notifications_envoyer_mails', |
|
| 148 | - [ |
|
| 149 | - 'email' => $email, |
|
| 150 | - 'sujet' => $sujet, |
|
| 151 | - 'texte' => $texte, |
|
| 152 | - 'from' => $from, |
|
| 153 | - 'headers' => $headers, |
|
| 154 | - ] |
|
| 155 | - ); |
|
| 156 | - $email = $envoi['email']; |
|
| 157 | - |
|
| 158 | - job_queue_add( |
|
| 159 | - 'envoyer_mail', |
|
| 160 | - ">$email : " . $envoi['sujet'], |
|
| 161 | - [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 162 | - 'inc/' |
|
| 163 | - ); |
|
| 164 | - } |
|
| 81 | + // rien a faire si pas de texte ! |
|
| 82 | + if (!strlen($texte)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | + if (!is_array($emails)) { |
|
| 88 | + $emails = explode(',', $emails); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + notifications_nettoyer_emails($emails); |
|
| 92 | + |
|
| 93 | + // tester si le mail est deja en html |
|
| 94 | + if ( |
|
| 95 | + str_contains($texte, '<') |
|
| 96 | + && ($ttrim = trim($texte)) |
|
| 97 | + && str_starts_with($ttrim, '<') |
|
| 98 | + && str_ends_with($ttrim, '>') |
|
| 99 | + && stripos($ttrim, '</html>') !== false |
|
| 100 | + ) { |
|
| 101 | + if (!strlen($sujet)) { |
|
| 102 | + // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | + if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 104 | + $sujet = $m[1]; |
|
| 105 | + } else { |
|
| 106 | + // fallback, on prend le body si on le trouve |
|
| 107 | + if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 108 | + $ttrim = $m[1]; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // et on extrait la premiere ligne de vrai texte... |
|
| 112 | + // nettoyer le html et les retours chariots |
|
| 113 | + $ttrim = textebrut($ttrim); |
|
| 114 | + $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | + $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | + // decouper |
|
| 117 | + $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | + // extraire la premiere ligne de texte brut |
|
| 119 | + $sujet = array_shift($ttrim); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // si besoin on ajoute le content-type dans les headers |
|
| 124 | + if (stripos($headers, 'Content-Type') === false) { |
|
| 125 | + $headers .= "Content-Type: text/html\n"; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | + // du mail qui est donc du texte |
|
| 131 | + if (!strlen($sujet)) { |
|
| 132 | + // nettoyer un peu les retours chariots |
|
| 133 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | + $texte = str_replace("\r", "\n", $texte); |
|
| 135 | + // decouper |
|
| 136 | + $texte = explode("\n", trim($texte)); |
|
| 137 | + // extraire la premiere ligne |
|
| 138 | + $sujet = array_shift($texte); |
|
| 139 | + $texte = trim(implode("\n", $texte)); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | + foreach ($emails as $email) { |
|
| 144 | + // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | + // (url de suivi des notifications par exemple) |
|
| 146 | + $envoi = pipeline( |
|
| 147 | + 'notifications_envoyer_mails', |
|
| 148 | + [ |
|
| 149 | + 'email' => $email, |
|
| 150 | + 'sujet' => $sujet, |
|
| 151 | + 'texte' => $texte, |
|
| 152 | + 'from' => $from, |
|
| 153 | + 'headers' => $headers, |
|
| 154 | + ] |
|
| 155 | + ); |
|
| 156 | + $email = $envoi['email']; |
|
| 157 | + |
|
| 158 | + job_queue_add( |
|
| 159 | + 'envoyer_mail', |
|
| 160 | + ">$email : " . $envoi['sujet'], |
|
| 161 | + [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 162 | + 'inc/' |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | 179 | function email_notification_objet($id_objet, $type_objet, $modele) { |
| 180 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 181 | - $id_type = id_table_objet($type_objet); |
|
| 180 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 181 | + $id_type = id_table_objet($type_objet); |
|
| 182 | 182 | |
| 183 | - return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 183 | + return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | function email_notification_article($id_article, $modele) { |
| 198 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 198 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 199 | 199 | |
| 200 | - return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 200 | + return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 201 | 201 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -50,66 +50,66 @@ discard block |
||
| 50 | 50 | * true si le cookie a été posé, false sinon. |
| 51 | 51 | **/ |
| 52 | 52 | function spip_setcookie( |
| 53 | - string $name = '', |
|
| 54 | - string $value = '', |
|
| 55 | - int|array $expires_or_options = 0, |
|
| 56 | - string $path = '', |
|
| 57 | - string $domain = '', |
|
| 58 | - bool $secure = false, |
|
| 59 | - bool $httponly = false |
|
| 53 | + string $name = '', |
|
| 54 | + string $value = '', |
|
| 55 | + int|array $expires_or_options = 0, |
|
| 56 | + string $path = '', |
|
| 57 | + string $domain = '', |
|
| 58 | + bool $secure = false, |
|
| 59 | + bool $httponly = false |
|
| 60 | 60 | ) { |
| 61 | - if (!is_array($expires_or_options)) { |
|
| 62 | - # anciens paramètres : spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $options = [ |
|
| 64 | - 'expires' => (int) $expires_or_options, |
|
| 65 | - 'path' => $path, |
|
| 66 | - 'domain' => $domain, |
|
| 67 | - 'secure' => $secure, |
|
| 68 | - 'httponly' => $httponly, |
|
| 69 | - ]; |
|
| 70 | - } else { |
|
| 71 | - $options = $expires_or_options; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // expires |
|
| 75 | - $options['expires'] ??= 0; |
|
| 76 | - if (!isset($options['path']) || $options['path'] === 'AUTO') { |
|
| 77 | - $options['path'] = defined('_COOKIE_PATH') ? constant('_COOKIE_PATH') : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 78 | - } |
|
| 79 | - if (empty($options['domain']) && defined('_COOKIE_DOMAIN') && constant('_COOKIE_DOMAIN')) { |
|
| 80 | - $options['domain'] = constant('_COOKIE_DOMAIN'); |
|
| 81 | - } |
|
| 82 | - $options['secure'] ??= false; |
|
| 83 | - $options['secure'] = ($options['secure'] ?: ($_SERVER['HTTPS'] ?? false)); |
|
| 84 | - if (defined('_COOKIE_SECURE') && constant('_COOKIE_SECURE')) { |
|
| 85 | - trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead (automatic in HTTPS).', '_COOKIE_SECURE', 'secure: true', __FUNCTION__); |
|
| 86 | - $options['secure'] = true; |
|
| 87 | - } |
|
| 88 | - $options['httponly'] ??= false; |
|
| 89 | - $options['samesite'] = ($options['samesite'] ?? 'Lax') ?: 'Lax'; |
|
| 90 | - |
|
| 91 | - /** @deprecated 5.0 Use option `'httponly' => true` */ |
|
| 92 | - if (defined('_COOKIE_SECURE_LIST')) { |
|
| 93 | - trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead.', '_COOKIE_SECURE_LIST', 'httponly: true', __FUNCTION__); |
|
| 94 | - if ( |
|
| 95 | - is_array(constant('_COOKIE_SECURE_LIST')) |
|
| 96 | - && in_array($name, constant('_COOKIE_SECURE_LIST')) |
|
| 97 | - ) { |
|
| 98 | - $options['httponly'] = true; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // in fine renommer le prefixe si besoin |
|
| 103 | - if (str_starts_with($name, 'spip_')) { |
|
| 104 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - #spip_logger('cookies')->info("cookie('$name', '$value', " . json_encode($options, true) . ")"); |
|
| 108 | - $a = @setcookie($name, $value, $options); |
|
| 109 | - |
|
| 110 | - spip_cookie_envoye(true); |
|
| 111 | - |
|
| 112 | - return $a; |
|
| 61 | + if (!is_array($expires_or_options)) { |
|
| 62 | + # anciens paramètres : spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $options = [ |
|
| 64 | + 'expires' => (int) $expires_or_options, |
|
| 65 | + 'path' => $path, |
|
| 66 | + 'domain' => $domain, |
|
| 67 | + 'secure' => $secure, |
|
| 68 | + 'httponly' => $httponly, |
|
| 69 | + ]; |
|
| 70 | + } else { |
|
| 71 | + $options = $expires_or_options; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // expires |
|
| 75 | + $options['expires'] ??= 0; |
|
| 76 | + if (!isset($options['path']) || $options['path'] === 'AUTO') { |
|
| 77 | + $options['path'] = defined('_COOKIE_PATH') ? constant('_COOKIE_PATH') : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 78 | + } |
|
| 79 | + if (empty($options['domain']) && defined('_COOKIE_DOMAIN') && constant('_COOKIE_DOMAIN')) { |
|
| 80 | + $options['domain'] = constant('_COOKIE_DOMAIN'); |
|
| 81 | + } |
|
| 82 | + $options['secure'] ??= false; |
|
| 83 | + $options['secure'] = ($options['secure'] ?: ($_SERVER['HTTPS'] ?? false)); |
|
| 84 | + if (defined('_COOKIE_SECURE') && constant('_COOKIE_SECURE')) { |
|
| 85 | + trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead (automatic in HTTPS).', '_COOKIE_SECURE', 'secure: true', __FUNCTION__); |
|
| 86 | + $options['secure'] = true; |
|
| 87 | + } |
|
| 88 | + $options['httponly'] ??= false; |
|
| 89 | + $options['samesite'] = ($options['samesite'] ?? 'Lax') ?: 'Lax'; |
|
| 90 | + |
|
| 91 | + /** @deprecated 5.0 Use option `'httponly' => true` */ |
|
| 92 | + if (defined('_COOKIE_SECURE_LIST')) { |
|
| 93 | + trigger_deprecation('spip', '5.0', 'Using "%s" constant is deprecated, use option "%s" when call "%s" instead.', '_COOKIE_SECURE_LIST', 'httponly: true', __FUNCTION__); |
|
| 94 | + if ( |
|
| 95 | + is_array(constant('_COOKIE_SECURE_LIST')) |
|
| 96 | + && in_array($name, constant('_COOKIE_SECURE_LIST')) |
|
| 97 | + ) { |
|
| 98 | + $options['httponly'] = true; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // in fine renommer le prefixe si besoin |
|
| 103 | + if (str_starts_with($name, 'spip_')) { |
|
| 104 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + #spip_logger('cookies')->info("cookie('$name', '$value', " . json_encode($options, true) . ")"); |
|
| 108 | + $a = @setcookie($name, $value, $options); |
|
| 109 | + |
|
| 110 | + spip_cookie_envoye(true); |
|
| 111 | + |
|
| 112 | + return $a; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | * @return bool |
| 126 | 126 | **/ |
| 127 | 127 | function spip_cookie_envoye($set = '') { |
| 128 | - static $envoye = false; |
|
| 129 | - if ($set) { |
|
| 130 | - $envoye = true; |
|
| 131 | - } |
|
| 128 | + static $envoye = false; |
|
| 129 | + if ($set) { |
|
| 130 | + $envoye = true; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return $envoye; |
|
| 133 | + return $envoye; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * Préfixe des cookies de SPIP |
| 150 | 150 | **/ |
| 151 | 151 | function recuperer_cookies_spip($cookie_prefix) { |
| 152 | - $prefix_long = strlen($cookie_prefix); |
|
| 153 | - |
|
| 154 | - foreach (array_keys($_COOKIE) as $name) { |
|
| 155 | - if (str_starts_with($name, 'spip_') && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 156 | - unset($_COOKIE[$name]); |
|
| 157 | - unset($GLOBALS[$name]); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - foreach ($_COOKIE as $name => $value) { |
|
| 161 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 162 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 163 | - $_COOKIE[$spipname] = $value; |
|
| 164 | - $GLOBALS[$spipname] = $value; |
|
| 165 | - } |
|
| 166 | - } |
|
| 152 | + $prefix_long = strlen($cookie_prefix); |
|
| 153 | + |
|
| 154 | + foreach (array_keys($_COOKIE) as $name) { |
|
| 155 | + if (str_starts_with($name, 'spip_') && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 156 | + unset($_COOKIE[$name]); |
|
| 157 | + unset($GLOBALS[$name]); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + foreach ($_COOKIE as $name => $value) { |
|
| 161 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 162 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 163 | + $_COOKIE[$spipname] = $value; |
|
| 164 | + $GLOBALS[$spipname] = $value; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -182,18 +182,18 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | **/ |
| 184 | 184 | function exec_test_ajax_dist() { |
| 185 | - switch (_request('js')) { |
|
| 186 | - // on est appele par <noscript> |
|
| 187 | - case -1: |
|
| 188 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 189 | - include_spip('inc/headers'); |
|
| 190 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 191 | - break; |
|
| 192 | - |
|
| 193 | - // ou par ajax |
|
| 194 | - case 1: |
|
| 195 | - default: |
|
| 196 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 197 | - break; |
|
| 198 | - } |
|
| 185 | + switch (_request('js')) { |
|
| 186 | + // on est appele par <noscript> |
|
| 187 | + case -1: |
|
| 188 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 189 | + include_spip('inc/headers'); |
|
| 190 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 191 | + break; |
|
| 192 | + |
|
| 193 | + // ou par ajax |
|
| 194 | + case 1: |
|
| 195 | + default: |
|
| 196 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 197 | + break; |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function base_repair_dist($titre = '', $reprise = '') { |
| 37 | 37 | |
| 38 | - $res = admin_repair_tables(); |
|
| 39 | - if (!$res) { |
|
| 40 | - $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 41 | - } else { |
|
| 42 | - include_spip('inc/rubriques'); |
|
| 43 | - calculer_rubriques(); |
|
| 44 | - propager_les_secteurs(); |
|
| 45 | - } |
|
| 46 | - include_spip('inc/minipres'); |
|
| 47 | - $res .= pipeline('base_admin_repair', $res); |
|
| 48 | - echo minipres( |
|
| 49 | - _T('texte_tentative_recuperation'), |
|
| 50 | - $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | - ); |
|
| 38 | + $res = admin_repair_tables(); |
|
| 39 | + if (!$res) { |
|
| 40 | + $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 41 | + } else { |
|
| 42 | + include_spip('inc/rubriques'); |
|
| 43 | + calculer_rubriques(); |
|
| 44 | + propager_les_secteurs(); |
|
| 45 | + } |
|
| 46 | + include_spip('inc/minipres'); |
|
| 47 | + $res .= pipeline('base_admin_repair', $res); |
|
| 48 | + echo minipres( |
|
| 49 | + _T('texte_tentative_recuperation'), |
|
| 50 | + $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | + ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -62,60 +62,60 @@ discard block |
||
| 62 | 62 | **/ |
| 63 | 63 | function admin_repair_tables() { |
| 64 | 64 | |
| 65 | - $repair = sql_serveur('repair', '', true); |
|
| 65 | + $repair = sql_serveur('repair', '', true); |
|
| 66 | 66 | |
| 67 | - // recreer les tables manquantes eventuelles |
|
| 68 | - include_spip('base/create'); |
|
| 69 | - creer_base(); |
|
| 70 | - $tables = sql_alltable(); |
|
| 67 | + // recreer les tables manquantes eventuelles |
|
| 68 | + include_spip('base/create'); |
|
| 69 | + creer_base(); |
|
| 70 | + $tables = sql_alltable(); |
|
| 71 | 71 | |
| 72 | - $res = ''; |
|
| 73 | - foreach ($tables as $tab) { |
|
| 74 | - $class = ''; |
|
| 75 | - $m = "<strong>$tab</strong> "; |
|
| 76 | - spip_logger()->notice("Repare $tab"); |
|
| 77 | - // supprimer la meta avant de lancer la reparation |
|
| 78 | - // car le repair peut etre long ; on ne veut pas boucler |
|
| 79 | - effacer_meta('admin_repair'); |
|
| 80 | - if ($repair) { |
|
| 81 | - $result_repair = sql_repair($tab); |
|
| 82 | - if (!$result_repair) { |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - } |
|
| 72 | + $res = ''; |
|
| 73 | + foreach ($tables as $tab) { |
|
| 74 | + $class = ''; |
|
| 75 | + $m = "<strong>$tab</strong> "; |
|
| 76 | + spip_logger()->notice("Repare $tab"); |
|
| 77 | + // supprimer la meta avant de lancer la reparation |
|
| 78 | + // car le repair peut etre long ; on ne veut pas boucler |
|
| 79 | + effacer_meta('admin_repair'); |
|
| 80 | + if ($repair) { |
|
| 81 | + $result_repair = sql_repair($tab); |
|
| 82 | + if (!$result_repair) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - // essayer de maj la table (creation de champs manquants) |
|
| 88 | - maj_tables($tab); |
|
| 87 | + // essayer de maj la table (creation de champs manquants) |
|
| 88 | + maj_tables($tab); |
|
| 89 | 89 | |
| 90 | - $count = sql_countsel($tab); |
|
| 90 | + $count = sql_countsel($tab); |
|
| 91 | 91 | |
| 92 | - if ($count > 1) { |
|
| 93 | - $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 94 | - } else { |
|
| 95 | - if ($count == 1) { |
|
| 96 | - $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 97 | - } else { |
|
| 98 | - $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 99 | - } |
|
| 100 | - } |
|
| 92 | + if ($count > 1) { |
|
| 93 | + $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 94 | + } else { |
|
| 95 | + if ($count == 1) { |
|
| 96 | + $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 97 | + } else { |
|
| 98 | + $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - if ( |
|
| 103 | - $repair |
|
| 104 | - && $result_repair |
|
| 105 | - && ($msg = implode( |
|
| 106 | - ' ', |
|
| 107 | - (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 108 | - ) . ' ') |
|
| 109 | - && !str_contains($msg, ' OK ') |
|
| 110 | - ) { |
|
| 111 | - $class = " class='notice'"; |
|
| 112 | - $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 113 | - } else { |
|
| 114 | - $m .= ' ' . _T('texte_table_ok'); |
|
| 115 | - } |
|
| 102 | + if ( |
|
| 103 | + $repair |
|
| 104 | + && $result_repair |
|
| 105 | + && ($msg = implode( |
|
| 106 | + ' ', |
|
| 107 | + (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 108 | + ) . ' ') |
|
| 109 | + && !str_contains($msg, ' OK ') |
|
| 110 | + ) { |
|
| 111 | + $class = " class='notice'"; |
|
| 112 | + $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 113 | + } else { |
|
| 114 | + $m .= ' ' . _T('texte_table_ok'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $res .= "<div$class>$m</div>"; |
|
| 118 | - } |
|
| 117 | + $res .= "<div$class>$m</div>"; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $res; |
|
| 120 | + return $res; |
|
| 121 | 121 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | **/ |
| 35 | 35 | function array_set_merge(&$table, $index, $valeur) { |
| 36 | - $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 36 | + $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -52,441 +52,441 @@ discard block |
||
| 52 | 52 | * - string (interne) si table '::md5' retourne un hash |
| 53 | 53 | */ |
| 54 | 54 | function lister_tables_objets_sql(?string $table_sql = null, $desc = []) { |
| 55 | - static $deja_la = false; |
|
| 56 | - static $infos_tables = null; |
|
| 57 | - static $md5 = null; |
|
| 58 | - static $plugin_hash = null; |
|
| 59 | - |
|
| 60 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | - |
|
| 63 | - // prealablement recuperer les tables_principales |
|
| 64 | - if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | - // pas de reentrance (cas base/serial) |
|
| 66 | - if ($deja_la) { |
|
| 67 | - spip_logger()->critical('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | - . var_export(debug_backtrace(), true)); |
|
| 69 | - |
|
| 70 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | - } |
|
| 72 | - $deja_la = true; |
|
| 73 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | - |
|
| 75 | - // recuperer les declarations explicites ancienne mode |
|
| 76 | - // qui servent a completer declarer_tables_objets_sql |
|
| 77 | - base_serial($GLOBALS['tables_principales']); |
|
| 78 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | - $infos_tables = [ |
|
| 80 | - 'spip_articles' => [ |
|
| 81 | - 'page' => 'article', |
|
| 82 | - 'texte_retour' => 'icone_retour_article', |
|
| 83 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | - 'texte_objets' => 'public:articles', |
|
| 86 | - 'texte_objet' => 'public:article', |
|
| 87 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | - 'info_1_objet' => 'info_1_article', |
|
| 90 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | - 'texte_logo_objet' => 'logo_article', |
|
| 92 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | - 'titre' => 'titre, lang', |
|
| 95 | - 'date' => 'date', |
|
| 96 | - 'principale' => 'oui', |
|
| 97 | - 'introduction_longueur' => '500', |
|
| 98 | - 'champs_editables' => [ |
|
| 99 | - 'surtitre', |
|
| 100 | - 'titre', |
|
| 101 | - 'soustitre', |
|
| 102 | - 'descriptif', |
|
| 103 | - 'nom_site', |
|
| 104 | - 'url_site', |
|
| 105 | - 'chapo', |
|
| 106 | - 'texte', |
|
| 107 | - 'ps', |
|
| 108 | - 'virtuel' |
|
| 109 | - ], |
|
| 110 | - 'champs_versionnes' => [ |
|
| 111 | - 'id_rubrique', |
|
| 112 | - 'surtitre', |
|
| 113 | - 'titre', |
|
| 114 | - 'soustitre', |
|
| 115 | - 'jointure_auteurs', |
|
| 116 | - 'descriptif', |
|
| 117 | - 'nom_site', |
|
| 118 | - 'url_site', |
|
| 119 | - 'chapo', |
|
| 120 | - 'texte', |
|
| 121 | - 'ps' |
|
| 122 | - ], |
|
| 123 | - 'field' => [ |
|
| 124 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | - 'maj' => 'TIMESTAMP', |
|
| 137 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | - ], |
|
| 151 | - 'key' => [ |
|
| 152 | - 'PRIMARY KEY' => 'id_article', |
|
| 153 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | - 'KEY id_secteur' => 'id_secteur', |
|
| 155 | - 'KEY id_trad' => 'id_trad', |
|
| 156 | - 'KEY lang' => 'lang', |
|
| 157 | - 'KEY statut' => 'statut, date', |
|
| 158 | - ], |
|
| 159 | - 'join' => [ |
|
| 160 | - 'id_article' => 'id_article', |
|
| 161 | - 'id_rubrique' => 'id_rubrique' |
|
| 162 | - ], |
|
| 163 | - 'parent' => [ |
|
| 164 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | - ], |
|
| 166 | - 'rechercher_champs' => [ |
|
| 167 | - 'surtitre' => 5, |
|
| 168 | - 'titre' => 8, |
|
| 169 | - 'soustitre' => 5, |
|
| 170 | - 'chapo' => 3, |
|
| 171 | - 'texte' => 1, |
|
| 172 | - 'ps' => 1, |
|
| 173 | - 'nom_site' => 1, |
|
| 174 | - 'url_site' => 1, |
|
| 175 | - 'descriptif' => 4 |
|
| 176 | - ], |
|
| 177 | - 'rechercher_jointures' => [ |
|
| 178 | - 'auteur' => ['nom' => 10], |
|
| 179 | - ], |
|
| 180 | - 'statut' => [ |
|
| 181 | - [ |
|
| 182 | - 'champ' => 'statut', |
|
| 183 | - 'publie' => 'publie', |
|
| 184 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | - 'post_date' => 'date', |
|
| 186 | - 'exception' => ['statut', 'tout'] |
|
| 187 | - ] |
|
| 188 | - ], |
|
| 189 | - 'statut_titres' => [ |
|
| 190 | - 'prepa' => 'info_article_redaction', |
|
| 191 | - 'prop' => 'info_article_propose', |
|
| 192 | - 'publie' => 'info_article_publie', |
|
| 193 | - 'refuse' => 'info_article_refuse', |
|
| 194 | - 'poubelle' => 'info_article_supprime' |
|
| 195 | - ], |
|
| 196 | - 'statut_textes_instituer' => [ |
|
| 197 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | - 'publie' => 'texte_statut_publie', |
|
| 200 | - 'refuse' => 'texte_statut_refuse', |
|
| 201 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | - ], |
|
| 203 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | - 'aide_changer_statut' => 'artstatut', |
|
| 205 | - 'tables_jointures' => [ |
|
| 206 | - 'profondeur' => 'rubriques', |
|
| 207 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | - ], |
|
| 209 | - ], |
|
| 210 | - 'spip_auteurs' => [ |
|
| 211 | - 'page' => 'auteur', |
|
| 212 | - 'texte_retour' => 'icone_retour', |
|
| 213 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | - 'texte_objets' => 'icone_auteurs', |
|
| 216 | - 'texte_objet' => 'public:auteur', |
|
| 217 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | - 'info_1_objet' => 'info_1_auteur', |
|
| 219 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | - 'date' => 'date', |
|
| 224 | - 'principale' => 'oui', |
|
| 225 | - 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | - 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | - 'field' => [ |
|
| 228 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | - 'maj' => 'TIMESTAMP', |
|
| 240 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | - 'alea_actuel' => 'tinytext', |
|
| 244 | - 'alea_futur' => 'tinytext', |
|
| 245 | - 'prefs' => 'text', |
|
| 246 | - 'cookie_oubli' => 'tinytext', |
|
| 247 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | - 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | - ], |
|
| 252 | - 'key' => [ |
|
| 253 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | - 'KEY login' => 'login', |
|
| 255 | - 'KEY statut' => 'statut', |
|
| 256 | - 'KEY en_ligne' => 'en_ligne', |
|
| 257 | - ], |
|
| 258 | - 'join' => [ |
|
| 259 | - 'id_auteur' => 'id_auteur', |
|
| 260 | - 'login' => 'login' |
|
| 261 | - ], |
|
| 262 | - 'rechercher_champs' => [ |
|
| 263 | - 'nom' => 5, |
|
| 264 | - 'bio' => 1, |
|
| 265 | - 'email' => 1, |
|
| 266 | - 'nom_site' => 1, |
|
| 267 | - 'url_site' => 1, |
|
| 268 | - 'login' => 1 |
|
| 269 | - ], |
|
| 270 | - // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | - // et avoir des articles publies |
|
| 272 | - 'statut' => [ |
|
| 273 | - [ |
|
| 274 | - 'champ' => 'statut', |
|
| 275 | - 'publie' => '!5poubelle', |
|
| 276 | - 'previsu' => '!5poubelle', |
|
| 277 | - 'exception' => 'statut' |
|
| 278 | - ], |
|
| 279 | - [ |
|
| 280 | - 'champ' => [ |
|
| 281 | - ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | - [ |
|
| 283 | - 'spip_articles', |
|
| 284 | - ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | - ], |
|
| 286 | - 'statut' |
|
| 287 | - ], |
|
| 288 | - 'publie' => 'publie', |
|
| 289 | - 'previsu' => '!', |
|
| 290 | - 'post_date' => 'date', |
|
| 291 | - 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | - ], |
|
| 293 | - ], |
|
| 294 | - 'statut_images' => [ |
|
| 295 | - 'auteur-6forum-16.png', |
|
| 296 | - '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | - '1comite' => 'auteur-1comite-16.png', |
|
| 298 | - '6forum' => 'auteur-6forum-16.png', |
|
| 299 | - '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | - 'nouveau' => '' |
|
| 301 | - ], |
|
| 302 | - 'statut_titres' => [ |
|
| 303 | - 'titre_image_visiteur', |
|
| 304 | - '0minirezo' => 'titre_image_administrateur', |
|
| 305 | - '1comite' => 'titre_image_redacteur_02', |
|
| 306 | - '6forum' => 'titre_image_visiteur', |
|
| 307 | - '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | - ], |
|
| 309 | - 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | - ], |
|
| 311 | - ], |
|
| 312 | - 'spip_rubriques' => [ |
|
| 313 | - 'page' => 'rubrique', |
|
| 314 | - 'url_voir' => 'rubrique', |
|
| 315 | - 'url_edit' => 'rubrique_edit', |
|
| 316 | - 'texte_retour' => 'icone_retour', |
|
| 317 | - 'texte_objets' => 'public:rubriques', |
|
| 318 | - 'texte_objet' => 'public:rubrique', |
|
| 319 | - 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | - 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | - 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | - 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | - 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | - 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | - 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | - 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | - 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | - 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | - 'titre' => 'titre, lang', |
|
| 330 | - 'date' => 'date', |
|
| 331 | - 'principale' => 'oui', |
|
| 332 | - 'introduction_longueur' => '600', |
|
| 333 | - 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | - 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | - 'field' => [ |
|
| 336 | - 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | - 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | - 'maj' => 'TIMESTAMP', |
|
| 343 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | - 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | - 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | - 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | - ], |
|
| 351 | - 'key' => [ |
|
| 352 | - 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | - 'KEY lang' => 'lang', |
|
| 354 | - 'KEY id_parent' => 'id_parent', |
|
| 355 | - ], |
|
| 356 | - 'parent' => [ |
|
| 357 | - ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | - ], |
|
| 359 | - 'rechercher_champs' => [ |
|
| 360 | - 'titre' => 8, |
|
| 361 | - 'descriptif' => 5, |
|
| 362 | - 'texte' => 1 |
|
| 363 | - ], |
|
| 364 | - 'statut' => [ |
|
| 365 | - [ |
|
| 366 | - 'champ' => 'statut', |
|
| 367 | - 'publie' => 'publie', |
|
| 368 | - 'previsu' => '!', |
|
| 369 | - 'exception' => ['statut', 'tout'] |
|
| 370 | - ], |
|
| 371 | - ], |
|
| 372 | - 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | - ], |
|
| 374 | - ], |
|
| 375 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | - ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | - ]; |
|
| 378 | - |
|
| 379 | - // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | - // initialiser la signature |
|
| 381 | - $md5 = md5(serialize($infos_tables)); |
|
| 382 | - |
|
| 383 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | - $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | - |
|
| 387 | - // completer les informations manquantes ou implicites |
|
| 388 | - $all = []; |
|
| 389 | - foreach (array_keys($infos_tables) as $t) { |
|
| 390 | - // les cles numeriques servent a declarer |
|
| 391 | - // les proprietes applicables a tous les objets |
|
| 392 | - // on les mets de cote |
|
| 393 | - if (is_numeric($t)) { |
|
| 394 | - $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | - unset($infos_tables[$t]); |
|
| 396 | - } else { |
|
| 397 | - $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // repercuter les proprietes generales communes a tous les objets |
|
| 402 | - foreach (array_keys($infos_tables) as $t) { |
|
| 403 | - foreach (array_keys($all) as $i) { |
|
| 404 | - if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | - $add = $all[$i]; |
|
| 406 | - // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | - // pour les declarations generiques avec cles numeriques |
|
| 408 | - if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | - foreach ($doublons as $d) { |
|
| 411 | - if ( |
|
| 412 | - is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | - && is_numeric($k = array_search($d, $add)) |
|
| 414 | - ) { |
|
| 415 | - unset($add[$k]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | - } else { |
|
| 421 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | - $infos_tables[$t][$i] ?? [], |
|
| 423 | - $all[$i] |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // completer les tables principales et auxiliaires |
|
| 430 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | - // pour assurer la compat en transition |
|
| 432 | - foreach ($infos_tables as $table => $infos) { |
|
| 433 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | - // qui a ete appelle avant |
|
| 436 | - $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | - // l'ajouter au tableau |
|
| 438 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | - if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | - foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | - if (isset($infos_tables[$table][$k])) { |
|
| 442 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } else { |
|
| 446 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | - } |
|
| 450 | - if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | - foreach (array_keys($mem) as $k) { |
|
| 452 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | - $mem[$k] |
|
| 456 | - ); |
|
| 457 | - } else { |
|
| 458 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // recuperer les interfaces (table_titre, table_date) |
|
| 465 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | - // dans le pipeline de declarer_tables_interfaces |
|
| 467 | - include_spip('public/interfaces'); |
|
| 468 | - foreach (array_keys($infos_tables) as $t) { |
|
| 469 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $deja_la = false; |
|
| 473 | - // signature |
|
| 474 | - $md5 = md5(serialize($infos_tables)); |
|
| 475 | - } |
|
| 476 | - if ($table_sql === '::md5') { |
|
| 477 | - return $md5; |
|
| 478 | - } |
|
| 479 | - if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | - |
|
| 483 | - return $desc; |
|
| 484 | - } |
|
| 485 | - if ($table_sql) { |
|
| 486 | - return $infos_tables[$table_sql] ?? []; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return $infos_tables; |
|
| 55 | + static $deja_la = false; |
|
| 56 | + static $infos_tables = null; |
|
| 57 | + static $md5 = null; |
|
| 58 | + static $plugin_hash = null; |
|
| 59 | + |
|
| 60 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | + |
|
| 63 | + // prealablement recuperer les tables_principales |
|
| 64 | + if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | + // pas de reentrance (cas base/serial) |
|
| 66 | + if ($deja_la) { |
|
| 67 | + spip_logger()->critical('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | + . var_export(debug_backtrace(), true)); |
|
| 69 | + |
|
| 70 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | + } |
|
| 72 | + $deja_la = true; |
|
| 73 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | + |
|
| 75 | + // recuperer les declarations explicites ancienne mode |
|
| 76 | + // qui servent a completer declarer_tables_objets_sql |
|
| 77 | + base_serial($GLOBALS['tables_principales']); |
|
| 78 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | + $infos_tables = [ |
|
| 80 | + 'spip_articles' => [ |
|
| 81 | + 'page' => 'article', |
|
| 82 | + 'texte_retour' => 'icone_retour_article', |
|
| 83 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | + 'texte_objets' => 'public:articles', |
|
| 86 | + 'texte_objet' => 'public:article', |
|
| 87 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | + 'info_1_objet' => 'info_1_article', |
|
| 90 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | + 'texte_logo_objet' => 'logo_article', |
|
| 92 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | + 'titre' => 'titre, lang', |
|
| 95 | + 'date' => 'date', |
|
| 96 | + 'principale' => 'oui', |
|
| 97 | + 'introduction_longueur' => '500', |
|
| 98 | + 'champs_editables' => [ |
|
| 99 | + 'surtitre', |
|
| 100 | + 'titre', |
|
| 101 | + 'soustitre', |
|
| 102 | + 'descriptif', |
|
| 103 | + 'nom_site', |
|
| 104 | + 'url_site', |
|
| 105 | + 'chapo', |
|
| 106 | + 'texte', |
|
| 107 | + 'ps', |
|
| 108 | + 'virtuel' |
|
| 109 | + ], |
|
| 110 | + 'champs_versionnes' => [ |
|
| 111 | + 'id_rubrique', |
|
| 112 | + 'surtitre', |
|
| 113 | + 'titre', |
|
| 114 | + 'soustitre', |
|
| 115 | + 'jointure_auteurs', |
|
| 116 | + 'descriptif', |
|
| 117 | + 'nom_site', |
|
| 118 | + 'url_site', |
|
| 119 | + 'chapo', |
|
| 120 | + 'texte', |
|
| 121 | + 'ps' |
|
| 122 | + ], |
|
| 123 | + 'field' => [ |
|
| 124 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | + 'maj' => 'TIMESTAMP', |
|
| 137 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | + ], |
|
| 151 | + 'key' => [ |
|
| 152 | + 'PRIMARY KEY' => 'id_article', |
|
| 153 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | + 'KEY id_secteur' => 'id_secteur', |
|
| 155 | + 'KEY id_trad' => 'id_trad', |
|
| 156 | + 'KEY lang' => 'lang', |
|
| 157 | + 'KEY statut' => 'statut, date', |
|
| 158 | + ], |
|
| 159 | + 'join' => [ |
|
| 160 | + 'id_article' => 'id_article', |
|
| 161 | + 'id_rubrique' => 'id_rubrique' |
|
| 162 | + ], |
|
| 163 | + 'parent' => [ |
|
| 164 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | + ], |
|
| 166 | + 'rechercher_champs' => [ |
|
| 167 | + 'surtitre' => 5, |
|
| 168 | + 'titre' => 8, |
|
| 169 | + 'soustitre' => 5, |
|
| 170 | + 'chapo' => 3, |
|
| 171 | + 'texte' => 1, |
|
| 172 | + 'ps' => 1, |
|
| 173 | + 'nom_site' => 1, |
|
| 174 | + 'url_site' => 1, |
|
| 175 | + 'descriptif' => 4 |
|
| 176 | + ], |
|
| 177 | + 'rechercher_jointures' => [ |
|
| 178 | + 'auteur' => ['nom' => 10], |
|
| 179 | + ], |
|
| 180 | + 'statut' => [ |
|
| 181 | + [ |
|
| 182 | + 'champ' => 'statut', |
|
| 183 | + 'publie' => 'publie', |
|
| 184 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | + 'post_date' => 'date', |
|
| 186 | + 'exception' => ['statut', 'tout'] |
|
| 187 | + ] |
|
| 188 | + ], |
|
| 189 | + 'statut_titres' => [ |
|
| 190 | + 'prepa' => 'info_article_redaction', |
|
| 191 | + 'prop' => 'info_article_propose', |
|
| 192 | + 'publie' => 'info_article_publie', |
|
| 193 | + 'refuse' => 'info_article_refuse', |
|
| 194 | + 'poubelle' => 'info_article_supprime' |
|
| 195 | + ], |
|
| 196 | + 'statut_textes_instituer' => [ |
|
| 197 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | + 'publie' => 'texte_statut_publie', |
|
| 200 | + 'refuse' => 'texte_statut_refuse', |
|
| 201 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | + ], |
|
| 203 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | + 'aide_changer_statut' => 'artstatut', |
|
| 205 | + 'tables_jointures' => [ |
|
| 206 | + 'profondeur' => 'rubriques', |
|
| 207 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | + ], |
|
| 209 | + ], |
|
| 210 | + 'spip_auteurs' => [ |
|
| 211 | + 'page' => 'auteur', |
|
| 212 | + 'texte_retour' => 'icone_retour', |
|
| 213 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | + 'texte_objets' => 'icone_auteurs', |
|
| 216 | + 'texte_objet' => 'public:auteur', |
|
| 217 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | + 'info_1_objet' => 'info_1_auteur', |
|
| 219 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | + 'date' => 'date', |
|
| 224 | + 'principale' => 'oui', |
|
| 225 | + 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | + 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | + 'field' => [ |
|
| 228 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | + 'maj' => 'TIMESTAMP', |
|
| 240 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | + 'alea_actuel' => 'tinytext', |
|
| 244 | + 'alea_futur' => 'tinytext', |
|
| 245 | + 'prefs' => 'text', |
|
| 246 | + 'cookie_oubli' => 'tinytext', |
|
| 247 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | + 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | + ], |
|
| 252 | + 'key' => [ |
|
| 253 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | + 'KEY login' => 'login', |
|
| 255 | + 'KEY statut' => 'statut', |
|
| 256 | + 'KEY en_ligne' => 'en_ligne', |
|
| 257 | + ], |
|
| 258 | + 'join' => [ |
|
| 259 | + 'id_auteur' => 'id_auteur', |
|
| 260 | + 'login' => 'login' |
|
| 261 | + ], |
|
| 262 | + 'rechercher_champs' => [ |
|
| 263 | + 'nom' => 5, |
|
| 264 | + 'bio' => 1, |
|
| 265 | + 'email' => 1, |
|
| 266 | + 'nom_site' => 1, |
|
| 267 | + 'url_site' => 1, |
|
| 268 | + 'login' => 1 |
|
| 269 | + ], |
|
| 270 | + // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | + // et avoir des articles publies |
|
| 272 | + 'statut' => [ |
|
| 273 | + [ |
|
| 274 | + 'champ' => 'statut', |
|
| 275 | + 'publie' => '!5poubelle', |
|
| 276 | + 'previsu' => '!5poubelle', |
|
| 277 | + 'exception' => 'statut' |
|
| 278 | + ], |
|
| 279 | + [ |
|
| 280 | + 'champ' => [ |
|
| 281 | + ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | + [ |
|
| 283 | + 'spip_articles', |
|
| 284 | + ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | + ], |
|
| 286 | + 'statut' |
|
| 287 | + ], |
|
| 288 | + 'publie' => 'publie', |
|
| 289 | + 'previsu' => '!', |
|
| 290 | + 'post_date' => 'date', |
|
| 291 | + 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | + ], |
|
| 293 | + ], |
|
| 294 | + 'statut_images' => [ |
|
| 295 | + 'auteur-6forum-16.png', |
|
| 296 | + '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | + '1comite' => 'auteur-1comite-16.png', |
|
| 298 | + '6forum' => 'auteur-6forum-16.png', |
|
| 299 | + '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | + 'nouveau' => '' |
|
| 301 | + ], |
|
| 302 | + 'statut_titres' => [ |
|
| 303 | + 'titre_image_visiteur', |
|
| 304 | + '0minirezo' => 'titre_image_administrateur', |
|
| 305 | + '1comite' => 'titre_image_redacteur_02', |
|
| 306 | + '6forum' => 'titre_image_visiteur', |
|
| 307 | + '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | + ], |
|
| 309 | + 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | + ], |
|
| 311 | + ], |
|
| 312 | + 'spip_rubriques' => [ |
|
| 313 | + 'page' => 'rubrique', |
|
| 314 | + 'url_voir' => 'rubrique', |
|
| 315 | + 'url_edit' => 'rubrique_edit', |
|
| 316 | + 'texte_retour' => 'icone_retour', |
|
| 317 | + 'texte_objets' => 'public:rubriques', |
|
| 318 | + 'texte_objet' => 'public:rubrique', |
|
| 319 | + 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | + 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | + 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | + 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | + 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | + 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | + 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | + 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | + 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | + 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | + 'titre' => 'titre, lang', |
|
| 330 | + 'date' => 'date', |
|
| 331 | + 'principale' => 'oui', |
|
| 332 | + 'introduction_longueur' => '600', |
|
| 333 | + 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | + 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | + 'field' => [ |
|
| 336 | + 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | + 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | + 'maj' => 'TIMESTAMP', |
|
| 343 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | + 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | + 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | + 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | + ], |
|
| 351 | + 'key' => [ |
|
| 352 | + 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | + 'KEY lang' => 'lang', |
|
| 354 | + 'KEY id_parent' => 'id_parent', |
|
| 355 | + ], |
|
| 356 | + 'parent' => [ |
|
| 357 | + ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | + ], |
|
| 359 | + 'rechercher_champs' => [ |
|
| 360 | + 'titre' => 8, |
|
| 361 | + 'descriptif' => 5, |
|
| 362 | + 'texte' => 1 |
|
| 363 | + ], |
|
| 364 | + 'statut' => [ |
|
| 365 | + [ |
|
| 366 | + 'champ' => 'statut', |
|
| 367 | + 'publie' => 'publie', |
|
| 368 | + 'previsu' => '!', |
|
| 369 | + 'exception' => ['statut', 'tout'] |
|
| 370 | + ], |
|
| 371 | + ], |
|
| 372 | + 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | + ], |
|
| 374 | + ], |
|
| 375 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | + ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | + ]; |
|
| 378 | + |
|
| 379 | + // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | + // initialiser la signature |
|
| 381 | + $md5 = md5(serialize($infos_tables)); |
|
| 382 | + |
|
| 383 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | + |
|
| 387 | + // completer les informations manquantes ou implicites |
|
| 388 | + $all = []; |
|
| 389 | + foreach (array_keys($infos_tables) as $t) { |
|
| 390 | + // les cles numeriques servent a declarer |
|
| 391 | + // les proprietes applicables a tous les objets |
|
| 392 | + // on les mets de cote |
|
| 393 | + if (is_numeric($t)) { |
|
| 394 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | + unset($infos_tables[$t]); |
|
| 396 | + } else { |
|
| 397 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // repercuter les proprietes generales communes a tous les objets |
|
| 402 | + foreach (array_keys($infos_tables) as $t) { |
|
| 403 | + foreach (array_keys($all) as $i) { |
|
| 404 | + if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | + $add = $all[$i]; |
|
| 406 | + // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | + // pour les declarations generiques avec cles numeriques |
|
| 408 | + if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | + foreach ($doublons as $d) { |
|
| 411 | + if ( |
|
| 412 | + is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | + && is_numeric($k = array_search($d, $add)) |
|
| 414 | + ) { |
|
| 415 | + unset($add[$k]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | + } else { |
|
| 421 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | + $infos_tables[$t][$i] ?? [], |
|
| 423 | + $all[$i] |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // completer les tables principales et auxiliaires |
|
| 430 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | + // pour assurer la compat en transition |
|
| 432 | + foreach ($infos_tables as $table => $infos) { |
|
| 433 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | + // qui a ete appelle avant |
|
| 436 | + $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | + // l'ajouter au tableau |
|
| 438 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | + if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | + foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | + if (isset($infos_tables[$table][$k])) { |
|
| 442 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } else { |
|
| 446 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | + } |
|
| 450 | + if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | + foreach (array_keys($mem) as $k) { |
|
| 452 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | + $mem[$k] |
|
| 456 | + ); |
|
| 457 | + } else { |
|
| 458 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // recuperer les interfaces (table_titre, table_date) |
|
| 465 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | + // dans le pipeline de declarer_tables_interfaces |
|
| 467 | + include_spip('public/interfaces'); |
|
| 468 | + foreach (array_keys($infos_tables) as $t) { |
|
| 469 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $deja_la = false; |
|
| 473 | + // signature |
|
| 474 | + $md5 = md5(serialize($infos_tables)); |
|
| 475 | + } |
|
| 476 | + if ($table_sql === '::md5') { |
|
| 477 | + return $md5; |
|
| 478 | + } |
|
| 479 | + if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | + |
|
| 483 | + return $desc; |
|
| 484 | + } |
|
| 485 | + if ($table_sql) { |
|
| 486 | + return $infos_tables[$table_sql] ?? []; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return $infos_tables; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -501,27 +501,27 @@ discard block |
||
| 501 | 501 | **/ |
| 502 | 502 | function base_serial(&$tables_principales) { |
| 503 | 503 | |
| 504 | - $spip_jobs = [ |
|
| 505 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | - ]; |
|
| 515 | - |
|
| 516 | - $spip_jobs_key = [ |
|
| 517 | - 'PRIMARY KEY' => 'id_job', |
|
| 518 | - 'KEY date' => 'date', |
|
| 519 | - 'KEY status' => 'status', |
|
| 520 | - ]; |
|
| 521 | - |
|
| 522 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | - $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 504 | + $spip_jobs = [ |
|
| 505 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | + ]; |
|
| 515 | + |
|
| 516 | + $spip_jobs_key = [ |
|
| 517 | + 'PRIMARY KEY' => 'id_job', |
|
| 518 | + 'KEY date' => 'date', |
|
| 519 | + 'KEY status' => 'status', |
|
| 520 | + ]; |
|
| 521 | + |
|
| 522 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | + $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,71 +533,71 @@ discard block |
||
| 533 | 533 | * @return void |
| 534 | 534 | **/ |
| 535 | 535 | function base_auxiliaires(&$tables_auxiliaires) { |
| 536 | - $spip_resultats = [ |
|
| 537 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | - 'maj' => 'TIMESTAMP' |
|
| 543 | - ]; |
|
| 544 | - |
|
| 545 | - $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | - ]; |
|
| 547 | - |
|
| 548 | - $spip_auteurs_liens = [ |
|
| 549 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | - ]; |
|
| 554 | - |
|
| 555 | - $spip_auteurs_liens_key = [ |
|
| 556 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | - 'KEY id_auteur' => 'id_auteur', |
|
| 558 | - 'KEY id_objet' => 'id_objet', |
|
| 559 | - 'KEY objet' => 'objet', |
|
| 560 | - ]; |
|
| 561 | - |
|
| 562 | - $spip_meta = [ |
|
| 563 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | - 'valeur' => "text DEFAULT ''", |
|
| 565 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | - 'maj' => 'TIMESTAMP' |
|
| 567 | - ]; |
|
| 568 | - |
|
| 569 | - $spip_meta_key = [ |
|
| 570 | - 'PRIMARY KEY' => 'nom' |
|
| 571 | - ]; |
|
| 572 | - |
|
| 573 | - $spip_jobs_liens = [ |
|
| 574 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | - ]; |
|
| 578 | - |
|
| 579 | - $spip_jobs_liens_key = [ |
|
| 580 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | - 'KEY id_job' => 'id_job' |
|
| 582 | - ]; |
|
| 583 | - |
|
| 584 | - $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | - 'field' => &$spip_auteurs_liens, |
|
| 586 | - 'key' => &$spip_auteurs_liens_key |
|
| 587 | - ]; |
|
| 588 | - |
|
| 589 | - $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | - 'field' => &$spip_meta, |
|
| 591 | - 'key' => &$spip_meta_key |
|
| 592 | - ]; |
|
| 593 | - $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | - 'field' => &$spip_resultats, |
|
| 595 | - 'key' => &$spip_resultats_key |
|
| 596 | - ]; |
|
| 597 | - $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | - 'field' => &$spip_jobs_liens, |
|
| 599 | - 'key' => &$spip_jobs_liens_key |
|
| 600 | - ]; |
|
| 536 | + $spip_resultats = [ |
|
| 537 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | + 'maj' => 'TIMESTAMP' |
|
| 543 | + ]; |
|
| 544 | + |
|
| 545 | + $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | + ]; |
|
| 547 | + |
|
| 548 | + $spip_auteurs_liens = [ |
|
| 549 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | + ]; |
|
| 554 | + |
|
| 555 | + $spip_auteurs_liens_key = [ |
|
| 556 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | + 'KEY id_auteur' => 'id_auteur', |
|
| 558 | + 'KEY id_objet' => 'id_objet', |
|
| 559 | + 'KEY objet' => 'objet', |
|
| 560 | + ]; |
|
| 561 | + |
|
| 562 | + $spip_meta = [ |
|
| 563 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | + 'valeur' => "text DEFAULT ''", |
|
| 565 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | + 'maj' => 'TIMESTAMP' |
|
| 567 | + ]; |
|
| 568 | + |
|
| 569 | + $spip_meta_key = [ |
|
| 570 | + 'PRIMARY KEY' => 'nom' |
|
| 571 | + ]; |
|
| 572 | + |
|
| 573 | + $spip_jobs_liens = [ |
|
| 574 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | + ]; |
|
| 578 | + |
|
| 579 | + $spip_jobs_liens_key = [ |
|
| 580 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | + 'KEY id_job' => 'id_job' |
|
| 582 | + ]; |
|
| 583 | + |
|
| 584 | + $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | + 'field' => &$spip_auteurs_liens, |
|
| 586 | + 'key' => &$spip_auteurs_liens_key |
|
| 587 | + ]; |
|
| 588 | + |
|
| 589 | + $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | + 'field' => &$spip_meta, |
|
| 591 | + 'key' => &$spip_meta_key |
|
| 592 | + ]; |
|
| 593 | + $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | + 'field' => &$spip_resultats, |
|
| 595 | + 'key' => &$spip_resultats_key |
|
| 596 | + ]; |
|
| 597 | + $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | + 'field' => &$spip_jobs_liens, |
|
| 599 | + 'key' => &$spip_jobs_liens_key |
|
| 600 | + ]; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | |
@@ -654,129 +654,129 @@ discard block |
||
| 654 | 654 | * @return array |
| 655 | 655 | */ |
| 656 | 656 | function renseigner_table_objet_sql($table_sql, &$infos) { |
| 657 | - if (!isset($infos['type'])) { |
|
| 658 | - // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | - // s'en servir pour extrapoler le type |
|
| 660 | - if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | - $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | - $primary = explode(',', (string) $primary); |
|
| 663 | - $primary = reset($primary); |
|
| 664 | - $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | - } else { |
|
| 666 | - $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - if (!isset($infos['type_surnoms'])) { |
|
| 670 | - $infos['type_surnoms'] = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - if (!isset($infos['table_objet'])) { |
|
| 674 | - $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | - } |
|
| 676 | - if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | - $infos['table_objet_surnoms'] = []; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - if (!isset($infos['principale'])) { |
|
| 681 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | - // et dans une boucle {principale=oui} |
|
| 686 | - $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | - |
|
| 688 | - // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | - // et dans une boucle {editable=oui} |
|
| 690 | - if (!isset($infos['editable'])) { |
|
| 691 | - $infos['editable'] = 'oui'; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | - |
|
| 696 | - // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | - // seules les exceptions sont donc a declarer |
|
| 698 | - if (!isset($infos['page'])) { |
|
| 699 | - $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - if (!isset($infos['url_voir'])) { |
|
| 703 | - $infos['url_voir'] = $infos['type']; |
|
| 704 | - } |
|
| 705 | - if (!isset($infos['url_edit'])) { |
|
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | - } |
|
| 708 | - if (!isset($infos['icone_objet'])) { |
|
| 709 | - $infos['icone_objet'] = $infos['type']; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // chaines de langue |
|
| 713 | - // par defaut : objet:icone_xxx_objet |
|
| 714 | - if (!isset($infos['texte_retour'])) { |
|
| 715 | - $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | - } |
|
| 717 | - if (!isset($infos['texte_modifier'])) { |
|
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | - } |
|
| 720 | - if (!isset($infos['texte_creer'])) { |
|
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | - } |
|
| 723 | - if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | - } |
|
| 726 | - if (!isset($infos['texte_ajouter'])) { |
|
| 727 | - // Ajouter un X |
|
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | - } |
|
| 730 | - if (!isset($infos['texte_objets'])) { |
|
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | - } |
|
| 733 | - if (!isset($infos['texte_objet'])) { |
|
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | - } |
|
| 736 | - if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | - // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | - } |
|
| 740 | - if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | - // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | - } |
|
| 744 | - if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | - // "Ce X est une traduction du X numéro :" |
|
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // objet:info_aucun_objet |
|
| 750 | - if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | - } |
|
| 753 | - // objet:info_1_objet |
|
| 754 | - if (!isset($infos['info_1_objet'])) { |
|
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | - } |
|
| 757 | - // objet:info_nb_objets |
|
| 758 | - if (!isset($infos['info_nb_objets'])) { |
|
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - if (!isset($infos['champs_editables'])) { |
|
| 763 | - $infos['champs_editables'] = []; |
|
| 764 | - } |
|
| 765 | - if (!isset($infos['champs_versionnes'])) { |
|
| 766 | - $infos['champs_versionnes'] = []; |
|
| 767 | - } |
|
| 768 | - if (!isset($infos['rechercher_champs'])) { |
|
| 769 | - $infos['rechercher_champs'] = []; |
|
| 770 | - } |
|
| 771 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | - $infos['rechercher_jointures'] = []; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if (!isset($infos['modeles'])) { |
|
| 776 | - $infos['modeles'] = [$infos['type']]; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return $infos; |
|
| 657 | + if (!isset($infos['type'])) { |
|
| 658 | + // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | + // s'en servir pour extrapoler le type |
|
| 660 | + if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | + $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | + $primary = explode(',', (string) $primary); |
|
| 663 | + $primary = reset($primary); |
|
| 664 | + $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | + } else { |
|
| 666 | + $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + if (!isset($infos['type_surnoms'])) { |
|
| 670 | + $infos['type_surnoms'] = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + if (!isset($infos['table_objet'])) { |
|
| 674 | + $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | + } |
|
| 676 | + if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | + $infos['table_objet_surnoms'] = []; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + if (!isset($infos['principale'])) { |
|
| 681 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | + // et dans une boucle {principale=oui} |
|
| 686 | + $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | + |
|
| 688 | + // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | + // et dans une boucle {editable=oui} |
|
| 690 | + if (!isset($infos['editable'])) { |
|
| 691 | + $infos['editable'] = 'oui'; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | + |
|
| 696 | + // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | + // seules les exceptions sont donc a declarer |
|
| 698 | + if (!isset($infos['page'])) { |
|
| 699 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + if (!isset($infos['url_voir'])) { |
|
| 703 | + $infos['url_voir'] = $infos['type']; |
|
| 704 | + } |
|
| 705 | + if (!isset($infos['url_edit'])) { |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | + } |
|
| 708 | + if (!isset($infos['icone_objet'])) { |
|
| 709 | + $infos['icone_objet'] = $infos['type']; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // chaines de langue |
|
| 713 | + // par defaut : objet:icone_xxx_objet |
|
| 714 | + if (!isset($infos['texte_retour'])) { |
|
| 715 | + $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | + } |
|
| 717 | + if (!isset($infos['texte_modifier'])) { |
|
| 718 | + $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | + } |
|
| 720 | + if (!isset($infos['texte_creer'])) { |
|
| 721 | + $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | + } |
|
| 723 | + if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | + } |
|
| 726 | + if (!isset($infos['texte_ajouter'])) { |
|
| 727 | + // Ajouter un X |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | + } |
|
| 730 | + if (!isset($infos['texte_objets'])) { |
|
| 731 | + $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | + } |
|
| 733 | + if (!isset($infos['texte_objet'])) { |
|
| 734 | + $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | + } |
|
| 736 | + if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | + // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | + } |
|
| 740 | + if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | + // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | + } |
|
| 744 | + if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | + // "Ce X est une traduction du X numéro :" |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // objet:info_aucun_objet |
|
| 750 | + if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | + } |
|
| 753 | + // objet:info_1_objet |
|
| 754 | + if (!isset($infos['info_1_objet'])) { |
|
| 755 | + $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | + } |
|
| 757 | + // objet:info_nb_objets |
|
| 758 | + if (!isset($infos['info_nb_objets'])) { |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + if (!isset($infos['champs_editables'])) { |
|
| 763 | + $infos['champs_editables'] = []; |
|
| 764 | + } |
|
| 765 | + if (!isset($infos['champs_versionnes'])) { |
|
| 766 | + $infos['champs_versionnes'] = []; |
|
| 767 | + } |
|
| 768 | + if (!isset($infos['rechercher_champs'])) { |
|
| 769 | + $infos['rechercher_champs'] = []; |
|
| 770 | + } |
|
| 771 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | + $infos['rechercher_jointures'] = []; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if (!isset($infos['modeles'])) { |
|
| 776 | + $infos['modeles'] = [$infos['type']]; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $infos; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -793,30 +793,30 @@ discard block |
||
| 793 | 793 | * @return array |
| 794 | 794 | */ |
| 795 | 795 | function renseigner_table_objet_interfaces($table_sql, &$infos) { |
| 796 | - if (!isset($infos['titre'])) { |
|
| 797 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | - $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | - } else { |
|
| 800 | - $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | - $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (!isset($infos['date'])) { |
|
| 805 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | - $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | - } else { |
|
| 808 | - $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | - $infos['tables_jointures'] ??= []; |
|
| 814 | - |
|
| 815 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | + $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | + } else { |
|
| 800 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (!isset($infos['date'])) { |
|
| 805 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | + $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | + } else { |
|
| 808 | + $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | + $infos['tables_jointures'] ??= []; |
|
| 814 | + |
|
| 815 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return $infos; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | * Liste et descriptions des tables principales |
| 828 | 828 | **/ |
| 829 | 829 | function lister_tables_principales() { |
| 830 | - static $done = false; |
|
| 831 | - if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | - lister_tables_objets_sql(); |
|
| 833 | - $done = true; |
|
| 834 | - } |
|
| 830 | + static $done = false; |
|
| 831 | + if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | + lister_tables_objets_sql(); |
|
| 833 | + $done = true; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - return $GLOBALS['tables_principales']; |
|
| 836 | + return $GLOBALS['tables_principales']; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -844,13 +844,13 @@ discard block |
||
| 844 | 844 | * Liste et descriptions des tables auxiliaires |
| 845 | 845 | **/ |
| 846 | 846 | function lister_tables_auxiliaires() { |
| 847 | - static $done = false; |
|
| 848 | - if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | - lister_tables_objets_sql(); |
|
| 850 | - $done = true; |
|
| 851 | - } |
|
| 847 | + static $done = false; |
|
| 848 | + if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | + lister_tables_objets_sql(); |
|
| 850 | + $done = true; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - return $GLOBALS['tables_auxiliaires']; |
|
| 853 | + return $GLOBALS['tables_auxiliaires']; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -859,44 +859,44 @@ discard block |
||
| 859 | 859 | * @return array |
| 860 | 860 | */ |
| 861 | 861 | function lister_tables_objets_surnoms() { |
| 862 | - static $surnoms = null; |
|
| 863 | - static $md5 = null; |
|
| 864 | - if ( |
|
| 865 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | - ) { |
|
| 867 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | - // declarer_table_objets_sql |
|
| 870 | - $surnoms = pipeline( |
|
| 871 | - 'declarer_tables_objets_surnoms', |
|
| 872 | - [ |
|
| 873 | - # pour les modeles |
|
| 874 | - # a enlever ? |
|
| 875 | - 'doc' => 'documents', |
|
| 876 | - 'img' => 'documents', |
|
| 877 | - 'emb' => 'documents', |
|
| 878 | - ] |
|
| 879 | - ); |
|
| 880 | - $infos_tables = lister_tables_objets_sql(); |
|
| 881 | - foreach ($infos_tables as $t => $infos) { |
|
| 882 | - // cas de base type=>table |
|
| 883 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | - // optimisations pour table_objet |
|
| 886 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | - if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return $surnoms; |
|
| 862 | + static $surnoms = null; |
|
| 863 | + static $md5 = null; |
|
| 864 | + if ( |
|
| 865 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | + ) { |
|
| 867 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | + // declarer_table_objets_sql |
|
| 870 | + $surnoms = pipeline( |
|
| 871 | + 'declarer_tables_objets_surnoms', |
|
| 872 | + [ |
|
| 873 | + # pour les modeles |
|
| 874 | + # a enlever ? |
|
| 875 | + 'doc' => 'documents', |
|
| 876 | + 'img' => 'documents', |
|
| 877 | + 'emb' => 'documents', |
|
| 878 | + ] |
|
| 879 | + ); |
|
| 880 | + $infos_tables = lister_tables_objets_sql(); |
|
| 881 | + foreach ($infos_tables as $t => $infos) { |
|
| 882 | + // cas de base type=>table |
|
| 883 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | + // optimisations pour table_objet |
|
| 886 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | + if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return $surnoms; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -905,34 +905,34 @@ discard block |
||
| 905 | 905 | * @return array |
| 906 | 906 | */ |
| 907 | 907 | function lister_types_surnoms() { |
| 908 | - static $surnoms = null; |
|
| 909 | - static $md5 = null; |
|
| 910 | - if ( |
|
| 911 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | - ) { |
|
| 913 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | - // declarer_table_objets_sql |
|
| 916 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | - $infos_tables = lister_tables_objets_sql(); |
|
| 918 | - foreach ($infos_tables as $t => $infos) { |
|
| 919 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | - // optimisations pour objet_type |
|
| 921 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | - // surnoms declares |
|
| 925 | - if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | - $surnoms[$surnom] = $infos['type']; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - return $surnoms; |
|
| 908 | + static $surnoms = null; |
|
| 909 | + static $md5 = null; |
|
| 910 | + if ( |
|
| 911 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | + ) { |
|
| 913 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | + // declarer_table_objets_sql |
|
| 916 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | + $infos_tables = lister_tables_objets_sql(); |
|
| 918 | + foreach ($infos_tables as $t => $infos) { |
|
| 919 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | + // optimisations pour objet_type |
|
| 921 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | + // surnoms declares |
|
| 925 | + if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | + $surnoms[$surnom] = $infos['type']; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + return $surnoms; |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | /** |
@@ -946,22 +946,22 @@ discard block |
||
| 946 | 946 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 947 | 947 | **/ |
| 948 | 948 | function lister_tables_spip($serveur = '') { |
| 949 | - static $tables = []; |
|
| 950 | - if (!isset($tables[$serveur])) { |
|
| 951 | - $tables[$serveur] = []; |
|
| 952 | - if (!function_exists('sql_alltable')) { |
|
| 953 | - include_spip('base/abstract_sql'); |
|
| 954 | - } |
|
| 955 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | - $spip = $connexion['prefixe'] . '_'; |
|
| 958 | - foreach ($ts as $t) { |
|
| 959 | - $t = substr((string) $t, strlen($spip)); |
|
| 960 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - return $tables[$serveur]; |
|
| 949 | + static $tables = []; |
|
| 950 | + if (!isset($tables[$serveur])) { |
|
| 951 | + $tables[$serveur] = []; |
|
| 952 | + if (!function_exists('sql_alltable')) { |
|
| 953 | + include_spip('base/abstract_sql'); |
|
| 954 | + } |
|
| 955 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | + $spip = $connexion['prefixe'] . '_'; |
|
| 958 | + foreach ($ts as $t) { |
|
| 959 | + $t = substr((string) $t, strlen($spip)); |
|
| 960 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + return $tables[$serveur]; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -976,18 +976,18 @@ discard block |
||
| 976 | 976 | * Couples (nom de la table SQL => même nom) |
| 977 | 977 | **/ |
| 978 | 978 | function lister_toutes_tables($serveur) { |
| 979 | - static $tables = []; |
|
| 980 | - if (!isset($tables[$serveur])) { |
|
| 981 | - $tables[$serveur] = []; |
|
| 982 | - if (!function_exists('sql_alltable')) { |
|
| 983 | - include_spip('base/abstract_sql'); |
|
| 984 | - } |
|
| 985 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | - foreach ($ts as $t) { |
|
| 987 | - $tables[$serveur][$t] = $t; |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - return $tables[$serveur]; |
|
| 979 | + static $tables = []; |
|
| 980 | + if (!isset($tables[$serveur])) { |
|
| 981 | + $tables[$serveur] = []; |
|
| 982 | + if (!function_exists('sql_alltable')) { |
|
| 983 | + include_spip('base/abstract_sql'); |
|
| 984 | + } |
|
| 985 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | + foreach ($ts as $t) { |
|
| 987 | + $tables[$serveur][$t] = $t; |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + return $tables[$serveur]; |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -1009,37 +1009,37 @@ discard block |
||
| 1009 | 1009 | **/ |
| 1010 | 1010 | function table_objet(string $type, string|false $serveur = ''): string { |
| 1011 | 1011 | |
| 1012 | - if ($type) { |
|
| 1013 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1014 | - } |
|
| 1015 | - if (!strlen($type)) { |
|
| 1016 | - return ''; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1020 | - if (isset($surnoms[$type])) { |
|
| 1021 | - return $surnoms[$type]; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - if ($serveur !== false) { |
|
| 1025 | - $t = lister_tables_spip($serveur); |
|
| 1026 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1027 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1028 | - if ( |
|
| 1029 | - (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1030 | - ) { |
|
| 1031 | - return $desc['id_table']; |
|
| 1032 | - } elseif ( |
|
| 1033 | - (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1034 | - ) { |
|
| 1035 | - return $desc['id_table']; |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - spip_logger()->info('table_objet(' . $type . ') calculee sans verification'); |
|
| 1039 | - #spip_logger('db')->debug(debug_backtrace()); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1012 | + if ($type) { |
|
| 1013 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1014 | + } |
|
| 1015 | + if (!strlen($type)) { |
|
| 1016 | + return ''; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1020 | + if (isset($surnoms[$type])) { |
|
| 1021 | + return $surnoms[$type]; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + if ($serveur !== false) { |
|
| 1025 | + $t = lister_tables_spip($serveur); |
|
| 1026 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1027 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1028 | + if ( |
|
| 1029 | + (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1030 | + ) { |
|
| 1031 | + return $desc['id_table']; |
|
| 1032 | + } elseif ( |
|
| 1033 | + (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1034 | + ) { |
|
| 1035 | + return $desc['id_table']; |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + spip_logger()->info('table_objet(' . $type . ') calculee sans verification'); |
|
| 1039 | + #spip_logger('db')->debug(debug_backtrace()); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | /** |
@@ -1060,33 +1060,33 @@ discard block |
||
| 1060 | 1060 | * Nom de la table SQL |
| 1061 | 1061 | **/ |
| 1062 | 1062 | function table_objet_sql(string $type, string|false $serveur = ''): string { |
| 1063 | - $nom = table_objet($type, $serveur); |
|
| 1064 | - if (!strlen($nom)) { |
|
| 1065 | - return ''; |
|
| 1066 | - } |
|
| 1067 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1068 | - // eviter de multiples inclusions |
|
| 1069 | - include_spip('public/interfaces'); |
|
| 1070 | - } |
|
| 1071 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1072 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1073 | - $nom = "spip_$nom"; |
|
| 1074 | - } else { |
|
| 1075 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1076 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1077 | - $nom = "spip_$nom"; |
|
| 1078 | - } elseif ($serveur !== false) { |
|
| 1079 | - $t = lister_tables_spip($serveur); |
|
| 1080 | - if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1081 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1082 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1083 | - return $desc['table_sql']; |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - return $nom; |
|
| 1063 | + $nom = table_objet($type, $serveur); |
|
| 1064 | + if (!strlen($nom)) { |
|
| 1065 | + return ''; |
|
| 1066 | + } |
|
| 1067 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1068 | + // eviter de multiples inclusions |
|
| 1069 | + include_spip('public/interfaces'); |
|
| 1070 | + } |
|
| 1071 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1072 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1073 | + $nom = "spip_$nom"; |
|
| 1074 | + } else { |
|
| 1075 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1076 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1077 | + $nom = "spip_$nom"; |
|
| 1078 | + } elseif ($serveur !== false) { |
|
| 1079 | + $t = lister_tables_spip($serveur); |
|
| 1080 | + if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1081 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1082 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1083 | + return $desc['table_sql']; |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + return $nom; |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /** |
@@ -1105,34 +1105,34 @@ discard block |
||
| 1105 | 1105 | * Nom de la clé primaire |
| 1106 | 1106 | **/ |
| 1107 | 1107 | function id_table_objet(string $type, string $serveur = ''): ?string { |
| 1108 | - static $trouver_table = null; |
|
| 1109 | - $type = objet_type($type, $serveur); |
|
| 1110 | - if (!$type) { |
|
| 1111 | - return null; |
|
| 1112 | - } |
|
| 1113 | - $t = table_objet($type); |
|
| 1114 | - if (!$trouver_table) { |
|
| 1115 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - $ts = lister_tables_spip($serveur); |
|
| 1119 | - if ( |
|
| 1120 | - in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1121 | - ) { |
|
| 1122 | - $desc = $trouver_table($t, $serveur); |
|
| 1123 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1124 | - return $desc['key']['PRIMARY KEY']; |
|
| 1125 | - } |
|
| 1126 | - if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1127 | - return "id_$type"; |
|
| 1128 | - } |
|
| 1129 | - // sinon renvoyer le premier champ de la table... |
|
| 1130 | - $keys = array_keys($desc['field']); |
|
| 1131 | - |
|
| 1132 | - return array_shift($keys); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - return "id_$type"; |
|
| 1108 | + static $trouver_table = null; |
|
| 1109 | + $type = objet_type($type, $serveur); |
|
| 1110 | + if (!$type) { |
|
| 1111 | + return null; |
|
| 1112 | + } |
|
| 1113 | + $t = table_objet($type); |
|
| 1114 | + if (!$trouver_table) { |
|
| 1115 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + $ts = lister_tables_spip($serveur); |
|
| 1119 | + if ( |
|
| 1120 | + in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1121 | + ) { |
|
| 1122 | + $desc = $trouver_table($t, $serveur); |
|
| 1123 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1124 | + return $desc['key']['PRIMARY KEY']; |
|
| 1125 | + } |
|
| 1126 | + if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1127 | + return "id_$type"; |
|
| 1128 | + } |
|
| 1129 | + // sinon renvoyer le premier champ de la table... |
|
| 1130 | + $keys = array_keys($desc['field']); |
|
| 1131 | + |
|
| 1132 | + return array_shift($keys); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + return "id_$type"; |
|
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | /** |
@@ -1152,60 +1152,60 @@ discard block |
||
| 1152 | 1152 | * Type de l'objet |
| 1153 | 1153 | **/ |
| 1154 | 1154 | function objet_type(string $table_objet, string|false $serveur = ''): ?string { |
| 1155 | - if (!$table_objet) { |
|
| 1156 | - return null; |
|
| 1157 | - } |
|
| 1158 | - $surnoms = lister_types_surnoms(); |
|
| 1159 | - |
|
| 1160 | - // scenario de base |
|
| 1161 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1162 | - // et la marque du pluriel |
|
| 1163 | - // on accepte id_xx en entree aussi |
|
| 1164 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1165 | - if (isset($surnoms[$type])) { |
|
| 1166 | - return $surnoms[$type]; |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - // securite : eliminer les caracteres non \w |
|
| 1170 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1171 | - |
|
| 1172 | - // si le type redonne bien la table c'est bon |
|
| 1173 | - // oui si table_objet ressemblait deja a un type |
|
| 1174 | - if ( |
|
| 1175 | - $type == $table_objet |
|
| 1176 | - || table_objet($type, $serveur) === $table_objet |
|
| 1177 | - || table_objet_sql($type, $serveur) === $table_objet |
|
| 1178 | - ) { |
|
| 1179 | - return $type; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - // si on ne veut pas chercher en base |
|
| 1183 | - if ($serveur === false) { |
|
| 1184 | - return $type; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1188 | - // car le s a la fin est incertain |
|
| 1189 | - // notamment en cas de pluriel derogatoire |
|
| 1190 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1191 | - // une declaration jeu => jeux, journal => journaux |
|
| 1192 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1193 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1194 | - $ts = lister_tables_spip($serveur); |
|
| 1195 | - $desc = false; |
|
| 1196 | - if (in_array($table_objet, $ts)) { |
|
| 1197 | - $desc = $trouver_table($table_objet); |
|
| 1198 | - } |
|
| 1199 | - if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1200 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1201 | - } |
|
| 1202 | - // si le type est declare : bingo ! |
|
| 1203 | - if ($desc && isset($desc['type'])) { |
|
| 1204 | - return $desc['type']; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - // on a fait ce qu'on a pu |
|
| 1208 | - return $type; |
|
| 1155 | + if (!$table_objet) { |
|
| 1156 | + return null; |
|
| 1157 | + } |
|
| 1158 | + $surnoms = lister_types_surnoms(); |
|
| 1159 | + |
|
| 1160 | + // scenario de base |
|
| 1161 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1162 | + // et la marque du pluriel |
|
| 1163 | + // on accepte id_xx en entree aussi |
|
| 1164 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1165 | + if (isset($surnoms[$type])) { |
|
| 1166 | + return $surnoms[$type]; |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + // securite : eliminer les caracteres non \w |
|
| 1170 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1171 | + |
|
| 1172 | + // si le type redonne bien la table c'est bon |
|
| 1173 | + // oui si table_objet ressemblait deja a un type |
|
| 1174 | + if ( |
|
| 1175 | + $type == $table_objet |
|
| 1176 | + || table_objet($type, $serveur) === $table_objet |
|
| 1177 | + || table_objet_sql($type, $serveur) === $table_objet |
|
| 1178 | + ) { |
|
| 1179 | + return $type; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + // si on ne veut pas chercher en base |
|
| 1183 | + if ($serveur === false) { |
|
| 1184 | + return $type; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1188 | + // car le s a la fin est incertain |
|
| 1189 | + // notamment en cas de pluriel derogatoire |
|
| 1190 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1191 | + // une declaration jeu => jeux, journal => journaux |
|
| 1192 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1193 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1194 | + $ts = lister_tables_spip($serveur); |
|
| 1195 | + $desc = false; |
|
| 1196 | + if (in_array($table_objet, $ts)) { |
|
| 1197 | + $desc = $trouver_table($table_objet); |
|
| 1198 | + } |
|
| 1199 | + if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1200 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1201 | + } |
|
| 1202 | + // si le type est declare : bingo ! |
|
| 1203 | + if ($desc && isset($desc['type'])) { |
|
| 1204 | + return $desc['type']; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + // on a fait ce qu'on a pu |
|
| 1208 | + return $type; |
|
| 1209 | 1209 | } |
| 1210 | 1210 | |
| 1211 | 1211 | /** |
@@ -1221,58 +1221,58 @@ discard block |
||
| 1221 | 1221 | * @return bool |
| 1222 | 1222 | */ |
| 1223 | 1223 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1224 | - // voir si une fonction est definie pour faire le boulot |
|
| 1225 | - // elle a la priorite dans ce cas |
|
| 1226 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1227 | - return $f($objet, $id_objet, $serveur); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1231 | - $id_table = $table_objet = table_objet($objet); |
|
| 1232 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1233 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1234 | - if ( |
|
| 1235 | - ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1236 | - && isset($desc['statut']) |
|
| 1237 | - && $desc['statut'] |
|
| 1238 | - ) { |
|
| 1239 | - $boucle = new Boucle(); |
|
| 1240 | - $boucle->show = $desc; |
|
| 1241 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1242 | - $boucle->id_boucle = $id_table; |
|
| 1243 | - $boucle->id_table = $id_table; |
|
| 1244 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1245 | - $boucle->sql_serveur = $serveur; |
|
| 1246 | - $boucle->select[] = $id_table_objet; |
|
| 1247 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1248 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1249 | - |
|
| 1250 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1251 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1252 | - $boucle->descr['gram'] = 'html'; |
|
| 1253 | - |
|
| 1254 | - include_spip('public/compiler'); |
|
| 1255 | - include_spip('public/composer'); |
|
| 1256 | - instituer_boucle($boucle, false, true); |
|
| 1257 | - $res = calculer_select( |
|
| 1258 | - $boucle->select, |
|
| 1259 | - $boucle->from, |
|
| 1260 | - $boucle->from_type, |
|
| 1261 | - $boucle->where, |
|
| 1262 | - $boucle->join, |
|
| 1263 | - $boucle->group, |
|
| 1264 | - $boucle->order, |
|
| 1265 | - $boucle->limit, |
|
| 1266 | - $boucle->having, |
|
| 1267 | - $table_objet, |
|
| 1268 | - $id_table, |
|
| 1269 | - $serveur |
|
| 1270 | - ); |
|
| 1271 | - return (bool) sql_fetch($res); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1275 | - return true; |
|
| 1224 | + // voir si une fonction est definie pour faire le boulot |
|
| 1225 | + // elle a la priorite dans ce cas |
|
| 1226 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1227 | + return $f($objet, $id_objet, $serveur); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1231 | + $id_table = $table_objet = table_objet($objet); |
|
| 1232 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1233 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1234 | + if ( |
|
| 1235 | + ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1236 | + && isset($desc['statut']) |
|
| 1237 | + && $desc['statut'] |
|
| 1238 | + ) { |
|
| 1239 | + $boucle = new Boucle(); |
|
| 1240 | + $boucle->show = $desc; |
|
| 1241 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1242 | + $boucle->id_boucle = $id_table; |
|
| 1243 | + $boucle->id_table = $id_table; |
|
| 1244 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1245 | + $boucle->sql_serveur = $serveur; |
|
| 1246 | + $boucle->select[] = $id_table_objet; |
|
| 1247 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1248 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1249 | + |
|
| 1250 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1251 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1252 | + $boucle->descr['gram'] = 'html'; |
|
| 1253 | + |
|
| 1254 | + include_spip('public/compiler'); |
|
| 1255 | + include_spip('public/composer'); |
|
| 1256 | + instituer_boucle($boucle, false, true); |
|
| 1257 | + $res = calculer_select( |
|
| 1258 | + $boucle->select, |
|
| 1259 | + $boucle->from, |
|
| 1260 | + $boucle->from_type, |
|
| 1261 | + $boucle->where, |
|
| 1262 | + $boucle->join, |
|
| 1263 | + $boucle->group, |
|
| 1264 | + $boucle->order, |
|
| 1265 | + $boucle->limit, |
|
| 1266 | + $boucle->having, |
|
| 1267 | + $table_objet, |
|
| 1268 | + $id_table, |
|
| 1269 | + $serveur |
|
| 1270 | + ); |
|
| 1271 | + return (bool) sql_fetch($res); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1275 | + return true; |
|
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | 1278 | |
@@ -1307,124 +1307,124 @@ discard block |
||
| 1307 | 1307 | * Retourne un tableau décrivant les parents trouvés |
| 1308 | 1308 | */ |
| 1309 | 1309 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1310 | - $parents = []; |
|
| 1311 | - |
|
| 1312 | - // Si on trouve une ou des méthodes de parent |
|
| 1313 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1314 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1315 | - include_spip('base/abstract_sql'); |
|
| 1316 | - $table_objet = table_objet_sql($objet); |
|
| 1317 | - $cle_objet = id_table_objet($objet); |
|
| 1318 | - $id_objet = (int) $id_objet; |
|
| 1319 | - |
|
| 1320 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1321 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1322 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1323 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1324 | - // de celle de l'objet source |
|
| 1325 | - $select = []; |
|
| 1326 | - if (isset($parent_methode['champ'])) { |
|
| 1327 | - $select[] = $parent_methode['champ']; |
|
| 1328 | - } |
|
| 1329 | - if (isset($parent_methode['champ_type'])) { |
|
| 1330 | - $select[] = $parent_methode['champ_type']; |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1334 | - $condition_objet_invalide = false; |
|
| 1335 | - $where = []; |
|
| 1336 | - if (!isset($parent_methode['table'])) { |
|
| 1337 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1338 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1339 | - $table = $table_objet; |
|
| 1340 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1341 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1342 | - if (isset($parent_methode['condition'])) { |
|
| 1343 | - $where[] = $parent_methode['condition']; |
|
| 1344 | - } |
|
| 1345 | - } elseif (!$parent_direct_seulement) { |
|
| 1346 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1347 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1348 | - // Si non, on peut arrêter le traitement. |
|
| 1349 | - if (isset($parent_methode['condition'])) { |
|
| 1350 | - $where = [ |
|
| 1351 | - "$cle_objet = $id_objet", |
|
| 1352 | - $parent_methode['condition'] |
|
| 1353 | - ]; |
|
| 1354 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1355 | - $condition_objet_invalide = true; |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1360 | - // la requête sur la table qui accueille le parent. |
|
| 1361 | - if (!$condition_objet_invalide) { |
|
| 1362 | - $table = $parent_methode['table']; |
|
| 1363 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1364 | - $where = []; |
|
| 1365 | - // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1366 | - // le même que celui de l'objet source. |
|
| 1367 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1368 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1369 | - : "$cle_objet = $id_objet"; |
|
| 1370 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1371 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1372 | - } |
|
| 1373 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1374 | - if (isset($parent_methode['table_condition'])) { |
|
| 1375 | - $where[] = $parent_methode['table_condition']; |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - // On lance la requête de récupération du parent |
|
| 1381 | - $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1382 | - if ( |
|
| 1383 | - !$condition_objet_invalide |
|
| 1384 | - && $where |
|
| 1385 | - && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1386 | - ) { |
|
| 1387 | - foreach ($lignes as $ligne) { |
|
| 1388 | - // Si le type est fixe |
|
| 1389 | - if (isset($parent_methode['type'])) { |
|
| 1390 | - $parent = [ |
|
| 1391 | - 'objet' => $parent_methode['type'], |
|
| 1392 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1393 | - 'champ' => $parent_methode['champ'], |
|
| 1394 | - 'table' => $table, |
|
| 1395 | - ]; |
|
| 1396 | - } |
|
| 1397 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1398 | - $parent = [ |
|
| 1399 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1400 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1401 | - 'champ' => $parent_methode['champ'], |
|
| 1402 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1403 | - 'table' => $table, |
|
| 1404 | - ]; |
|
| 1405 | - } |
|
| 1406 | - if ($is_table_lien) { |
|
| 1407 | - $parent['lien'] = $ligne; |
|
| 1408 | - } |
|
| 1409 | - $parents[] = $parent; |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - // On passe par un pipeline avant de retourner |
|
| 1416 | - $parents = pipeline( |
|
| 1417 | - 'objet_lister_parents', |
|
| 1418 | - [ |
|
| 1419 | - 'args' => [ |
|
| 1420 | - 'objet' => $objet, |
|
| 1421 | - 'id_objet' => $id_objet, |
|
| 1422 | - ], |
|
| 1423 | - 'data' => $parents, |
|
| 1424 | - ] |
|
| 1425 | - ); |
|
| 1426 | - |
|
| 1427 | - return $parents; |
|
| 1310 | + $parents = []; |
|
| 1311 | + |
|
| 1312 | + // Si on trouve une ou des méthodes de parent |
|
| 1313 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1314 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1315 | + include_spip('base/abstract_sql'); |
|
| 1316 | + $table_objet = table_objet_sql($objet); |
|
| 1317 | + $cle_objet = id_table_objet($objet); |
|
| 1318 | + $id_objet = (int) $id_objet; |
|
| 1319 | + |
|
| 1320 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1321 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1322 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1323 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1324 | + // de celle de l'objet source |
|
| 1325 | + $select = []; |
|
| 1326 | + if (isset($parent_methode['champ'])) { |
|
| 1327 | + $select[] = $parent_methode['champ']; |
|
| 1328 | + } |
|
| 1329 | + if (isset($parent_methode['champ_type'])) { |
|
| 1330 | + $select[] = $parent_methode['champ_type']; |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1334 | + $condition_objet_invalide = false; |
|
| 1335 | + $where = []; |
|
| 1336 | + if (!isset($parent_methode['table'])) { |
|
| 1337 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1338 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1339 | + $table = $table_objet; |
|
| 1340 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1341 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1342 | + if (isset($parent_methode['condition'])) { |
|
| 1343 | + $where[] = $parent_methode['condition']; |
|
| 1344 | + } |
|
| 1345 | + } elseif (!$parent_direct_seulement) { |
|
| 1346 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1347 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1348 | + // Si non, on peut arrêter le traitement. |
|
| 1349 | + if (isset($parent_methode['condition'])) { |
|
| 1350 | + $where = [ |
|
| 1351 | + "$cle_objet = $id_objet", |
|
| 1352 | + $parent_methode['condition'] |
|
| 1353 | + ]; |
|
| 1354 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1355 | + $condition_objet_invalide = true; |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1360 | + // la requête sur la table qui accueille le parent. |
|
| 1361 | + if (!$condition_objet_invalide) { |
|
| 1362 | + $table = $parent_methode['table']; |
|
| 1363 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1364 | + $where = []; |
|
| 1365 | + // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1366 | + // le même que celui de l'objet source. |
|
| 1367 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1368 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1369 | + : "$cle_objet = $id_objet"; |
|
| 1370 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1371 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1372 | + } |
|
| 1373 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1374 | + if (isset($parent_methode['table_condition'])) { |
|
| 1375 | + $where[] = $parent_methode['table_condition']; |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + // On lance la requête de récupération du parent |
|
| 1381 | + $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1382 | + if ( |
|
| 1383 | + !$condition_objet_invalide |
|
| 1384 | + && $where |
|
| 1385 | + && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1386 | + ) { |
|
| 1387 | + foreach ($lignes as $ligne) { |
|
| 1388 | + // Si le type est fixe |
|
| 1389 | + if (isset($parent_methode['type'])) { |
|
| 1390 | + $parent = [ |
|
| 1391 | + 'objet' => $parent_methode['type'], |
|
| 1392 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1393 | + 'champ' => $parent_methode['champ'], |
|
| 1394 | + 'table' => $table, |
|
| 1395 | + ]; |
|
| 1396 | + } |
|
| 1397 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1398 | + $parent = [ |
|
| 1399 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1400 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1401 | + 'champ' => $parent_methode['champ'], |
|
| 1402 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1403 | + 'table' => $table, |
|
| 1404 | + ]; |
|
| 1405 | + } |
|
| 1406 | + if ($is_table_lien) { |
|
| 1407 | + $parent['lien'] = $ligne; |
|
| 1408 | + } |
|
| 1409 | + $parents[] = $parent; |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + // On passe par un pipeline avant de retourner |
|
| 1416 | + $parents = pipeline( |
|
| 1417 | + 'objet_lister_parents', |
|
| 1418 | + [ |
|
| 1419 | + 'args' => [ |
|
| 1420 | + 'objet' => $objet, |
|
| 1421 | + 'id_objet' => $id_objet, |
|
| 1422 | + ], |
|
| 1423 | + 'data' => $parents, |
|
| 1424 | + ] |
|
| 1425 | + ); |
|
| 1426 | + |
|
| 1427 | + return $parents; |
|
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | 1430 | /** |
@@ -1436,17 +1436,17 @@ discard block |
||
| 1436 | 1436 | * @return array |
| 1437 | 1437 | */ |
| 1438 | 1438 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1439 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1439 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1440 | 1440 | |
| 1441 | - $parents_par_type = []; |
|
| 1442 | - foreach ($parents as $parent) { |
|
| 1443 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1444 | - $parents_par_type[$parent['objet']] = []; |
|
| 1445 | - } |
|
| 1446 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1447 | - } |
|
| 1441 | + $parents_par_type = []; |
|
| 1442 | + foreach ($parents as $parent) { |
|
| 1443 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1444 | + $parents_par_type[$parent['objet']] = []; |
|
| 1445 | + } |
|
| 1446 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1447 | + } |
|
| 1448 | 1448 | |
| 1449 | - return $parents_par_type; |
|
| 1449 | + return $parents_par_type; |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | |
@@ -1479,85 +1479,85 @@ discard block |
||
| 1479 | 1479 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1480 | 1480 | */ |
| 1481 | 1481 | function objet_lister_enfants($objet, $id_objet) { |
| 1482 | - $enfants = []; |
|
| 1483 | - |
|
| 1484 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1485 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1486 | - include_spip('base/abstract_sql'); |
|
| 1487 | - $id_objet = (int) $id_objet; |
|
| 1488 | - |
|
| 1489 | - // On parcourt tous les types d'enfants trouvés |
|
| 1490 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1491 | - // On construit les conditions d'identification du parent |
|
| 1492 | - $where = []; |
|
| 1493 | - // -- L'identifiant du parent |
|
| 1494 | - if (isset($_methode_parent['champ'])) { |
|
| 1495 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1496 | - } |
|
| 1497 | - // -- Si le parent est variable |
|
| 1498 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1499 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1503 | - if (!isset($_methode_parent['table'])) { |
|
| 1504 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1505 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1506 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1507 | - |
|
| 1508 | - // S'il y a une condition supplémentaire |
|
| 1509 | - if (isset($_methode_parent['condition'])) { |
|
| 1510 | - $where[] = $_methode_parent['condition']; |
|
| 1511 | - } |
|
| 1512 | - } else { |
|
| 1513 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1514 | - $table_enfant = $_methode_parent['table']; |
|
| 1515 | - $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1516 | - |
|
| 1517 | - // S'il y a une condition supplémentaire |
|
| 1518 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1519 | - $where[] = $_methode_parent['table_condition']; |
|
| 1520 | - } |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - // On lance la requête |
|
| 1524 | - $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1525 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1526 | - $enfant = [ |
|
| 1527 | - 'objet' => $objet_enfant, |
|
| 1528 | - 'id_objet' => 0, |
|
| 1529 | - 'table' => $table_enfant |
|
| 1530 | - ]; |
|
| 1531 | - if (isset($_methode_parent['champ'])) { |
|
| 1532 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1533 | - } |
|
| 1534 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1535 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1536 | - } |
|
| 1537 | - foreach ($rows as $row) { |
|
| 1538 | - $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1539 | - if ($is_table_lien) { |
|
| 1540 | - $enfant['lien'] = $row; |
|
| 1541 | - } |
|
| 1542 | - $enfants[] = $enfant; |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - // On passe par un pipeline avant de retourner |
|
| 1549 | - $enfants = pipeline( |
|
| 1550 | - 'objet_lister_enfants', |
|
| 1551 | - [ |
|
| 1552 | - 'args' => [ |
|
| 1553 | - 'objet' => $objet, |
|
| 1554 | - 'id_objet' => $id_objet, |
|
| 1555 | - ], |
|
| 1556 | - 'data' => $enfants, |
|
| 1557 | - ] |
|
| 1558 | - ); |
|
| 1559 | - |
|
| 1560 | - return $enfants; |
|
| 1482 | + $enfants = []; |
|
| 1483 | + |
|
| 1484 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1485 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1486 | + include_spip('base/abstract_sql'); |
|
| 1487 | + $id_objet = (int) $id_objet; |
|
| 1488 | + |
|
| 1489 | + // On parcourt tous les types d'enfants trouvés |
|
| 1490 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1491 | + // On construit les conditions d'identification du parent |
|
| 1492 | + $where = []; |
|
| 1493 | + // -- L'identifiant du parent |
|
| 1494 | + if (isset($_methode_parent['champ'])) { |
|
| 1495 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1496 | + } |
|
| 1497 | + // -- Si le parent est variable |
|
| 1498 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1499 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1503 | + if (!isset($_methode_parent['table'])) { |
|
| 1504 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1505 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1506 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1507 | + |
|
| 1508 | + // S'il y a une condition supplémentaire |
|
| 1509 | + if (isset($_methode_parent['condition'])) { |
|
| 1510 | + $where[] = $_methode_parent['condition']; |
|
| 1511 | + } |
|
| 1512 | + } else { |
|
| 1513 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1514 | + $table_enfant = $_methode_parent['table']; |
|
| 1515 | + $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1516 | + |
|
| 1517 | + // S'il y a une condition supplémentaire |
|
| 1518 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1519 | + $where[] = $_methode_parent['table_condition']; |
|
| 1520 | + } |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + // On lance la requête |
|
| 1524 | + $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1525 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1526 | + $enfant = [ |
|
| 1527 | + 'objet' => $objet_enfant, |
|
| 1528 | + 'id_objet' => 0, |
|
| 1529 | + 'table' => $table_enfant |
|
| 1530 | + ]; |
|
| 1531 | + if (isset($_methode_parent['champ'])) { |
|
| 1532 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1533 | + } |
|
| 1534 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1535 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1536 | + } |
|
| 1537 | + foreach ($rows as $row) { |
|
| 1538 | + $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1539 | + if ($is_table_lien) { |
|
| 1540 | + $enfant['lien'] = $row; |
|
| 1541 | + } |
|
| 1542 | + $enfants[] = $enfant; |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + // On passe par un pipeline avant de retourner |
|
| 1549 | + $enfants = pipeline( |
|
| 1550 | + 'objet_lister_enfants', |
|
| 1551 | + [ |
|
| 1552 | + 'args' => [ |
|
| 1553 | + 'objet' => $objet, |
|
| 1554 | + 'id_objet' => $id_objet, |
|
| 1555 | + ], |
|
| 1556 | + 'data' => $enfants, |
|
| 1557 | + ] |
|
| 1558 | + ); |
|
| 1559 | + |
|
| 1560 | + return $enfants; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | /** |
@@ -1569,17 +1569,17 @@ discard block |
||
| 1569 | 1569 | * @return array |
| 1570 | 1570 | */ |
| 1571 | 1571 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1572 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1572 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1573 | 1573 | |
| 1574 | - $enfants_par_type = []; |
|
| 1575 | - foreach ($enfants as $enfant) { |
|
| 1576 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1577 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1578 | - } |
|
| 1579 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1580 | - } |
|
| 1574 | + $enfants_par_type = []; |
|
| 1575 | + foreach ($enfants as $enfant) { |
|
| 1576 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1577 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1578 | + } |
|
| 1579 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1580 | + } |
|
| 1581 | 1581 | |
| 1582 | - return $enfants_par_type; |
|
| 1582 | + return $enfants_par_type; |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | /** |
@@ -1591,31 +1591,31 @@ discard block |
||
| 1591 | 1591 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1592 | 1592 | */ |
| 1593 | 1593 | function objet_type_decrire_infos_parents($objet) { |
| 1594 | - static $parents = []; |
|
| 1595 | - |
|
| 1596 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1597 | - if (!isset($parents[$objet])) { |
|
| 1598 | - $parents[$objet] = false; |
|
| 1599 | - $table = table_objet_sql($objet); |
|
| 1600 | - |
|
| 1601 | - // Si on trouve bien la description de cet objet |
|
| 1602 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1603 | - if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1604 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1605 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1606 | - // de description |
|
| 1607 | - $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1608 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1609 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1610 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1611 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1612 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1613 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1614 | - } |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - |
|
| 1618 | - return $parents[$objet]; |
|
| 1594 | + static $parents = []; |
|
| 1595 | + |
|
| 1596 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1597 | + if (!isset($parents[$objet])) { |
|
| 1598 | + $parents[$objet] = false; |
|
| 1599 | + $table = table_objet_sql($objet); |
|
| 1600 | + |
|
| 1601 | + // Si on trouve bien la description de cet objet |
|
| 1602 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1603 | + if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1604 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1605 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1606 | + // de description |
|
| 1607 | + $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1608 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1609 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1610 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1611 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1612 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1613 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1614 | + } |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + return $parents[$objet]; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | /** |
@@ -1627,36 +1627,36 @@ discard block |
||
| 1627 | 1627 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1628 | 1628 | */ |
| 1629 | 1629 | function objet_type_decrire_infos_enfants($objet) { |
| 1630 | - static $enfants = []; |
|
| 1631 | - |
|
| 1632 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1633 | - if (!isset($enfants[$objet])) { |
|
| 1634 | - $enfants[$objet] = []; |
|
| 1635 | - $tables = lister_tables_objets_sql(); |
|
| 1636 | - |
|
| 1637 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1638 | - foreach ($tables as $table => $infos) { |
|
| 1639 | - $objet_enfant = objet_type($table); |
|
| 1640 | - |
|
| 1641 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1642 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1643 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1644 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1645 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1646 | - if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1647 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1648 | - if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1649 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1650 | - } |
|
| 1651 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1652 | - elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1653 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1654 | - } |
|
| 1655 | - } |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - |
|
| 1661 | - return $enfants[$objet]; |
|
| 1630 | + static $enfants = []; |
|
| 1631 | + |
|
| 1632 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1633 | + if (!isset($enfants[$objet])) { |
|
| 1634 | + $enfants[$objet] = []; |
|
| 1635 | + $tables = lister_tables_objets_sql(); |
|
| 1636 | + |
|
| 1637 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1638 | + foreach ($tables as $table => $infos) { |
|
| 1639 | + $objet_enfant = objet_type($table); |
|
| 1640 | + |
|
| 1641 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1642 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1643 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1644 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1645 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1646 | + if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1647 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1648 | + if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1649 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1650 | + } |
|
| 1651 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1652 | + elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1653 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1654 | + } |
|
| 1655 | + } |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + |
|
| 1661 | + return $enfants[$objet]; |
|
| 1662 | 1662 | } |