@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -54,64 +54,64 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = array(), $postdate = false) { |
| 57 | - $neuf = false; |
|
| 57 | + $neuf = false; |
|
| 58 | 58 | |
| 59 | - // Compat avec l'ancienne signature |
|
| 60 | - if (is_string($infos)) { |
|
| 61 | - $infos = array('statut_ancien' => $infos); |
|
| 62 | - } |
|
| 63 | - if (!isset($infos['statut_ancien'])) { |
|
| 64 | - $infos['statut_ancien'] = ''; |
|
| 65 | - } |
|
| 59 | + // Compat avec l'ancienne signature |
|
| 60 | + if (is_string($infos)) { |
|
| 61 | + $infos = array('statut_ancien' => $infos); |
|
| 62 | + } |
|
| 63 | + if (!isset($infos['statut_ancien'])) { |
|
| 64 | + $infos['statut_ancien'] = ''; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // On recherche quels statuts tester |
|
| 68 | - if ( |
|
| 69 | - isset($infos['objet']) |
|
| 70 | - and include_spip('inc/filtres') |
|
| 71 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | - and is_array($declaration_statut) |
|
| 73 | - ) { |
|
| 74 | - foreach ($declaration_statut as $champ_statut) { |
|
| 75 | - if ($champ_statut['champ'] == 'statut') { |
|
| 76 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | - break; // stop on a trouvé le bon champ |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $statuts_publies = array('publie'); |
|
| 83 | - } |
|
| 67 | + // On recherche quels statuts tester |
|
| 68 | + if ( |
|
| 69 | + isset($infos['objet']) |
|
| 70 | + and include_spip('inc/filtres') |
|
| 71 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | + and is_array($declaration_statut) |
|
| 73 | + ) { |
|
| 74 | + foreach ($declaration_statut as $champ_statut) { |
|
| 75 | + if ($champ_statut['champ'] == 'statut') { |
|
| 76 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | + break; // stop on a trouvé le bon champ |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $statuts_publies = array('publie'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if (isset($modifs['statut']) |
|
| 87 | - or isset($modifs['id_rubrique']) |
|
| 88 | - or ($postdate and strtotime($postdate) > time()) |
|
| 89 | - ) { |
|
| 90 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 91 | - } |
|
| 92 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 93 | - if ($postdate) { |
|
| 94 | - calculer_prochain_postdate(true); |
|
| 95 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 96 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 97 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 98 | - } |
|
| 99 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 100 | - if ($postdate) { |
|
| 101 | - calculer_prochain_postdate(true); |
|
| 102 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 103 | - } else { |
|
| 104 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 109 | - { |
|
| 110 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $langues = calculer_langues_utilisees(); |
|
| 114 | - ecrire_meta('langues_utilisees', $langues); |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if (isset($modifs['statut']) |
|
| 87 | + or isset($modifs['id_rubrique']) |
|
| 88 | + or ($postdate and strtotime($postdate) > time()) |
|
| 89 | + ) { |
|
| 90 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 91 | + } |
|
| 92 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 93 | + if ($postdate) { |
|
| 94 | + calculer_prochain_postdate(true); |
|
| 95 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 96 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 97 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 98 | + } |
|
| 99 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 100 | + if ($postdate) { |
|
| 101 | + calculer_prochain_postdate(true); |
|
| 102 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 103 | + } else { |
|
| 104 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 109 | + { |
|
| 110 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $langues = calculer_langues_utilisees(); |
|
| 114 | + ecrire_meta('langues_utilisees', $langues); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * true si le statut change effectivement |
| 130 | 130 | */ |
| 131 | 131 | function publier_branche_rubrique($id_rubrique) { |
| 132 | - $id_pred = $id_rubrique; |
|
| 133 | - while (true) { |
|
| 134 | - sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 135 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 136 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 137 | - if (!$id_parent) { |
|
| 138 | - break; |
|
| 139 | - } |
|
| 140 | - $id_rubrique = $id_parent; |
|
| 141 | - } |
|
| 132 | + $id_pred = $id_rubrique; |
|
| 133 | + while (true) { |
|
| 134 | + sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 135 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 136 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 137 | + if (!$id_parent) { |
|
| 138 | + break; |
|
| 139 | + } |
|
| 140 | + $id_rubrique = $id_parent; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 144 | - return $id_pred != $id_rubrique; |
|
| 144 | + return $id_pred != $id_rubrique; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -159,21 +159,21 @@ discard block |
||
| 159 | 159 | * true si le statut change effectivement |
| 160 | 160 | */ |
| 161 | 161 | function depublier_branche_rubrique_if($id_rubrique) { |
| 162 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 162 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 163 | 163 | |
| 164 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 165 | - $id_pred = $id_rubrique; |
|
| 166 | - while ($id_pred) { |
|
| 164 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 165 | + $id_pred = $id_rubrique; |
|
| 166 | + while ($id_pred) { |
|
| 167 | 167 | |
| 168 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 169 | - return $id_pred != $id_rubrique; |
|
| 170 | - } |
|
| 171 | - // passer au parent si on a depublie |
|
| 172 | - $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 173 | - $id_pred = $r['id_parent']; |
|
| 174 | - } |
|
| 168 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 169 | + return $id_pred != $id_rubrique; |
|
| 170 | + } |
|
| 171 | + // passer au parent si on a depublie |
|
| 172 | + $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 173 | + $id_pred = $r['id_parent']; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - return $id_pred != $id_rubrique; |
|
| 176 | + return $id_pred != $id_rubrique; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -190,57 +190,57 @@ discard block |
||
| 190 | 190 | * true si la rubrique a été dépubliée |
| 191 | 191 | */ |
| 192 | 192 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 193 | - if (is_null($date)) { |
|
| 194 | - $date = date('Y-m-d H:i:s'); |
|
| 195 | - } |
|
| 196 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 197 | - " AND date <= " . sql_quote($date) : ''; |
|
| 198 | - |
|
| 199 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // verifier qu'elle existe et est bien publiee |
|
| 204 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 205 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 210 | - // Le type de l'objet est au pluriel |
|
| 211 | - $compte = array( |
|
| 212 | - 'articles' => sql_countsel("spip_articles", |
|
| 213 | - "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 214 | - 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 215 | - 'documents' => sql_countsel( |
|
| 216 | - "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", |
|
| 217 | - "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ") |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 221 | - $compte = pipeline('objet_compte_enfants', |
|
| 222 | - array( |
|
| 223 | - 'args' => array( |
|
| 224 | - 'objet' => 'rubrique', |
|
| 225 | - 'id_objet' => $id_rubrique, |
|
| 226 | - 'statut' => 'publie', |
|
| 227 | - 'date' => $date |
|
| 228 | - ), |
|
| 229 | - 'data' => $compte |
|
| 230 | - ) |
|
| 231 | - ); |
|
| 232 | - |
|
| 233 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 234 | - foreach ($compte as $objet => $n) { |
|
| 235 | - if ($n) { |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 193 | + if (is_null($date)) { |
|
| 194 | + $date = date('Y-m-d H:i:s'); |
|
| 195 | + } |
|
| 196 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 197 | + " AND date <= " . sql_quote($date) : ''; |
|
| 198 | + |
|
| 199 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // verifier qu'elle existe et est bien publiee |
|
| 204 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 205 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 210 | + // Le type de l'objet est au pluriel |
|
| 211 | + $compte = array( |
|
| 212 | + 'articles' => sql_countsel("spip_articles", |
|
| 213 | + "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 214 | + 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 215 | + 'documents' => sql_countsel( |
|
| 216 | + "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", |
|
| 217 | + "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ") |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 221 | + $compte = pipeline('objet_compte_enfants', |
|
| 222 | + array( |
|
| 223 | + 'args' => array( |
|
| 224 | + 'objet' => 'rubrique', |
|
| 225 | + 'id_objet' => $id_rubrique, |
|
| 226 | + 'statut' => 'publie', |
|
| 227 | + 'date' => $date |
|
| 228 | + ), |
|
| 229 | + 'data' => $compte |
|
| 230 | + ) |
|
| 231 | + ); |
|
| 232 | + |
|
| 233 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 234 | + foreach ($compte as $objet => $n) { |
|
| 235 | + if ($n) { |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 241 | 241 | |
| 242 | 242 | # spip_log("depublier_rubrique $id_pred"); |
| 243 | - return true; |
|
| 243 | + return true; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -263,18 +263,18 @@ discard block |
||
| 263 | 263 | **/ |
| 264 | 264 | function calculer_rubriques() { |
| 265 | 265 | |
| 266 | - calculer_rubriques_publiees(); |
|
| 266 | + calculer_rubriques_publiees(); |
|
| 267 | 267 | |
| 268 | - // Apres chaque (de)publication |
|
| 269 | - // recalculer les langues utilisees sur le site |
|
| 270 | - $langues = calculer_langues_utilisees(); |
|
| 271 | - ecrire_meta('langues_utilisees', $langues); |
|
| 268 | + // Apres chaque (de)publication |
|
| 269 | + // recalculer les langues utilisees sur le site |
|
| 270 | + $langues = calculer_langues_utilisees(); |
|
| 271 | + ecrire_meta('langues_utilisees', $langues); |
|
| 272 | 272 | |
| 273 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 274 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 273 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 274 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 275 | 275 | |
| 276 | - // on calcule la date du prochain article post-date |
|
| 277 | - calculer_prochain_postdate(); |
|
| 276 | + // on calcule la date du prochain article post-date |
|
| 277 | + calculer_prochain_postdate(); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
@@ -291,51 +291,51 @@ discard block |
||
| 291 | 291 | **/ |
| 292 | 292 | function calculer_rubriques_publiees() { |
| 293 | 293 | |
| 294 | - // Mettre les compteurs a zero |
|
| 295 | - sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 296 | - |
|
| 297 | - // |
|
| 298 | - // Publier et dater les rubriques qui ont un article publie |
|
| 299 | - // |
|
| 300 | - |
|
| 301 | - // Afficher les articles post-dates ? |
|
| 302 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 303 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 304 | - |
|
| 305 | - $r = sql_select( |
|
| 306 | - "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 307 | - "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 308 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 309 | - while ($row = sql_fetch($r)) { |
|
| 310 | - sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 311 | - "id_rubrique=" . intval($row['id'])); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 315 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 316 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 317 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 318 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 319 | - pipeline('calculer_rubriques', null); |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 323 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 324 | - do { |
|
| 325 | - $continuer = false; |
|
| 326 | - $r = sql_select( |
|
| 327 | - "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 328 | - "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 329 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 330 | - while ($row = sql_fetch($r)) { |
|
| 331 | - sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 332 | - "id_rubrique=" . intval($row['id'])); |
|
| 333 | - $continuer = true; |
|
| 334 | - } |
|
| 335 | - } while ($continuer); |
|
| 336 | - |
|
| 337 | - // Enregistrement des modifs |
|
| 338 | - sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 294 | + // Mettre les compteurs a zero |
|
| 295 | + sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 296 | + |
|
| 297 | + // |
|
| 298 | + // Publier et dater les rubriques qui ont un article publie |
|
| 299 | + // |
|
| 300 | + |
|
| 301 | + // Afficher les articles post-dates ? |
|
| 302 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 303 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 304 | + |
|
| 305 | + $r = sql_select( |
|
| 306 | + "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 307 | + "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 308 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 309 | + while ($row = sql_fetch($r)) { |
|
| 310 | + sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 311 | + "id_rubrique=" . intval($row['id'])); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 315 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 316 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 317 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 318 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 319 | + pipeline('calculer_rubriques', null); |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 323 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 324 | + do { |
|
| 325 | + $continuer = false; |
|
| 326 | + $r = sql_select( |
|
| 327 | + "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 328 | + "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 329 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 330 | + while ($row = sql_fetch($r)) { |
|
| 331 | + sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 332 | + "id_rubrique=" . intval($row['id'])); |
|
| 333 | + $continuer = true; |
|
| 334 | + } |
|
| 335 | + } while ($continuer); |
|
| 336 | + |
|
| 337 | + // Enregistrement des modifs |
|
| 338 | + sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -350,99 +350,99 @@ discard block |
||
| 350 | 350 | * @return void |
| 351 | 351 | **/ |
| 352 | 352 | function propager_les_secteurs() { |
| 353 | - // Profondeur 0 |
|
| 354 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 355 | - // et fixer les id_secteur des rubriques racines |
|
| 356 | - sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 357 | - // Toute rubrique non racine est de profondeur >0 |
|
| 358 | - sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 359 | - |
|
| 360 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 361 | - $maxiter = sql_countsel("spip_rubriques"); |
|
| 362 | - |
|
| 363 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 364 | - // on fait profondeur par profondeur |
|
| 365 | - |
|
| 366 | - $prof = 0; |
|
| 367 | - do { |
|
| 368 | - $continuer = false; |
|
| 369 | - |
|
| 370 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 371 | - // on fixe le profondeur $prof+1 |
|
| 372 | - |
|
| 373 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 374 | - // on teste A.profondeur > $prof+1 car : |
|
| 375 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 376 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 377 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 378 | - $maxiter2 = $maxiter; |
|
| 379 | - while ($maxiter2-- |
|
| 380 | - and $rows = sql_allfetsel( |
|
| 381 | - "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 382 | - "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 383 | - "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 384 | - "", "R.id_secteur", "0,100")) { |
|
| 385 | - |
|
| 386 | - $id_secteur = null; |
|
| 387 | - $ids = array(); |
|
| 388 | - while ($row = array_shift($rows)) { |
|
| 389 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 390 | - if (count($ids)) { |
|
| 391 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 392 | - sql_in('id_rubrique', $ids)); |
|
| 393 | - } |
|
| 394 | - $id_secteur = $row['id_secteur']; |
|
| 395 | - $ids = array(); |
|
| 396 | - } |
|
| 397 | - $ids[] = $row['id']; |
|
| 398 | - } |
|
| 399 | - if (count($ids)) { |
|
| 400 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 401 | - sql_in('id_rubrique', $ids)); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 407 | - $maxiter2 = $maxiter; |
|
| 408 | - while ($maxiter2-- |
|
| 409 | - and $rows = sql_allfetsel( |
|
| 410 | - "id_rubrique as id", |
|
| 411 | - "spip_rubriques", |
|
| 412 | - "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 413 | - "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 414 | - $rows = array_column($rows, 'id'); |
|
| 415 | - sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 419 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 420 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 421 | - // on arrete les frais |
|
| 422 | - if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 423 | - $prof++; |
|
| 424 | - $continuer = true; |
|
| 425 | - } |
|
| 426 | - } while ($continuer and $maxiter--); |
|
| 427 | - |
|
| 428 | - // loger si la table des rubriques semble foireuse |
|
| 429 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 430 | - if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 431 | - spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 432 | - _LOG_CRITIQUE); |
|
| 433 | - sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // reparer les articles |
|
| 437 | - $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 438 | - "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 439 | - |
|
| 440 | - while ($row = sql_fetch($r)) { |
|
| 441 | - sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 445 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 353 | + // Profondeur 0 |
|
| 354 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 355 | + // et fixer les id_secteur des rubriques racines |
|
| 356 | + sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 357 | + // Toute rubrique non racine est de profondeur >0 |
|
| 358 | + sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 359 | + |
|
| 360 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 361 | + $maxiter = sql_countsel("spip_rubriques"); |
|
| 362 | + |
|
| 363 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 364 | + // on fait profondeur par profondeur |
|
| 365 | + |
|
| 366 | + $prof = 0; |
|
| 367 | + do { |
|
| 368 | + $continuer = false; |
|
| 369 | + |
|
| 370 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 371 | + // on fixe le profondeur $prof+1 |
|
| 372 | + |
|
| 373 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 374 | + // on teste A.profondeur > $prof+1 car : |
|
| 375 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 376 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 377 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 378 | + $maxiter2 = $maxiter; |
|
| 379 | + while ($maxiter2-- |
|
| 380 | + and $rows = sql_allfetsel( |
|
| 381 | + "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 382 | + "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 383 | + "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 384 | + "", "R.id_secteur", "0,100")) { |
|
| 385 | + |
|
| 386 | + $id_secteur = null; |
|
| 387 | + $ids = array(); |
|
| 388 | + while ($row = array_shift($rows)) { |
|
| 389 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 390 | + if (count($ids)) { |
|
| 391 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 392 | + sql_in('id_rubrique', $ids)); |
|
| 393 | + } |
|
| 394 | + $id_secteur = $row['id_secteur']; |
|
| 395 | + $ids = array(); |
|
| 396 | + } |
|
| 397 | + $ids[] = $row['id']; |
|
| 398 | + } |
|
| 399 | + if (count($ids)) { |
|
| 400 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 401 | + sql_in('id_rubrique', $ids)); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 407 | + $maxiter2 = $maxiter; |
|
| 408 | + while ($maxiter2-- |
|
| 409 | + and $rows = sql_allfetsel( |
|
| 410 | + "id_rubrique as id", |
|
| 411 | + "spip_rubriques", |
|
| 412 | + "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 413 | + "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 414 | + $rows = array_column($rows, 'id'); |
|
| 415 | + sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 419 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 420 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 421 | + // on arrete les frais |
|
| 422 | + if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 423 | + $prof++; |
|
| 424 | + $continuer = true; |
|
| 425 | + } |
|
| 426 | + } while ($continuer and $maxiter--); |
|
| 427 | + |
|
| 428 | + // loger si la table des rubriques semble foireuse |
|
| 429 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 430 | + if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 431 | + spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 432 | + _LOG_CRITIQUE); |
|
| 433 | + sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // reparer les articles |
|
| 437 | + $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 438 | + "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 439 | + |
|
| 440 | + while ($row = sql_fetch($r)) { |
|
| 441 | + sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 445 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -457,17 +457,17 @@ discard block |
||
| 457 | 457 | * true si un changement a eu lieu |
| 458 | 458 | **/ |
| 459 | 459 | function calculer_langues_rubriques_etape() { |
| 460 | - $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 461 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 460 | + $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 461 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 462 | 462 | |
| 463 | - $t = false; |
|
| 464 | - while ($row = sql_fetch($s)) { |
|
| 465 | - $id_rubrique = $row['id_rubrique']; |
|
| 466 | - $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 467 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 468 | - } |
|
| 463 | + $t = false; |
|
| 464 | + while ($row = sql_fetch($s)) { |
|
| 465 | + $id_rubrique = $row['id_rubrique']; |
|
| 466 | + $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 467 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - return $t; |
|
| 470 | + return $t; |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -487,30 +487,30 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function calculer_langues_rubriques() { |
| 489 | 489 | |
| 490 | - // rubriques (recursivite) |
|
| 491 | - sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 492 | - "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 493 | - while (calculer_langues_rubriques_etape()) { |
|
| 494 | - ; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // articles |
|
| 498 | - $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 499 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 500 | - while ($row = sql_fetch($s)) { |
|
| 501 | - $id_article = $row['id_article']; |
|
| 502 | - sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 503 | - "id_article=" . intval($id_article)); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 507 | - |
|
| 508 | - $langues = calculer_langues_utilisees(); |
|
| 509 | - ecrire_meta('langues_utilisees', $langues); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 513 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 490 | + // rubriques (recursivite) |
|
| 491 | + sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 492 | + "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 493 | + while (calculer_langues_rubriques_etape()) { |
|
| 494 | + ; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // articles |
|
| 498 | + $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 499 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 500 | + while ($row = sql_fetch($s)) { |
|
| 501 | + $id_article = $row['id_article']; |
|
| 502 | + sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 503 | + "id_article=" . intval($id_article)); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 507 | + |
|
| 508 | + $langues = calculer_langues_utilisees(); |
|
| 509 | + ecrire_meta('langues_utilisees', $langues); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 513 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | |
@@ -527,79 +527,79 @@ discard block |
||
| 527 | 527 | * Liste des langues utilisées séparées par des virgules |
| 528 | 528 | **/ |
| 529 | 529 | function calculer_langues_utilisees($serveur = '') { |
| 530 | - include_spip('public/interfaces'); |
|
| 531 | - include_spip('public/compiler'); |
|
| 532 | - include_spip('public/composer'); |
|
| 533 | - include_spip('public/phraser_html'); |
|
| 534 | - $langues = array(); |
|
| 535 | - |
|
| 536 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 537 | - |
|
| 538 | - include_spip('base/objets'); |
|
| 539 | - $tables = lister_tables_objets_sql(); |
|
| 540 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 541 | - |
|
| 542 | - foreach (array_keys($tables) as $t) { |
|
| 543 | - $desc = $trouver_table($t, $serveur); |
|
| 544 | - // c'est une table avec des langues |
|
| 545 | - if ($desc['exist'] |
|
| 546 | - and isset($desc['field']['lang']) |
|
| 547 | - and isset($desc['field']['langue_choisie']) |
|
| 548 | - ) { |
|
| 549 | - |
|
| 550 | - $boucle = new Boucle(); |
|
| 551 | - $boucle->show = $desc; |
|
| 552 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 553 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 554 | - $boucle->id_table = $desc['table_objet']; |
|
| 555 | - $boucle->primary = $desc['key']["PRIMARY KEY"] ?? ''; |
|
| 556 | - $boucle->sql_serveur = $serveur; |
|
| 557 | - $boucle->select[] = "DISTINCT lang"; |
|
| 558 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 559 | - $boucle->separateur[] = ','; |
|
| 560 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 561 | - $boucle->iterateur = 'sql'; |
|
| 562 | - |
|
| 563 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 564 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 565 | - $boucle->descr['gram'] = 'html'; |
|
| 566 | - |
|
| 567 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 568 | - |
|
| 569 | - if (isset($desc['statut']) |
|
| 570 | - and $desc['statut'] |
|
| 571 | - ) { |
|
| 572 | - $boucles = array( |
|
| 573 | - 'calculer_langues_utilisees' => $boucle, |
|
| 574 | - ); |
|
| 575 | - // generer un nom de fonction "anonyme" unique |
|
| 576 | - do { |
|
| 577 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 578 | - } while (function_exists($functionname)); |
|
| 579 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 580 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 581 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 582 | - $res = ''; |
|
| 583 | - eval($code); |
|
| 584 | - $res = explode(',', $res); |
|
| 585 | - foreach ($res as $lang) { |
|
| 586 | - $langues[$lang] = 1; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 590 | - while ($row = sql_fetch($res)) { |
|
| 591 | - $langues[$row['lang']] = 1; |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - $langues = array_filter(array_keys($langues)); |
|
| 598 | - sort($langues); |
|
| 599 | - $langues = join(',', $langues); |
|
| 600 | - spip_log("langues utilisees: $langues"); |
|
| 601 | - |
|
| 602 | - return $langues; |
|
| 530 | + include_spip('public/interfaces'); |
|
| 531 | + include_spip('public/compiler'); |
|
| 532 | + include_spip('public/composer'); |
|
| 533 | + include_spip('public/phraser_html'); |
|
| 534 | + $langues = array(); |
|
| 535 | + |
|
| 536 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 537 | + |
|
| 538 | + include_spip('base/objets'); |
|
| 539 | + $tables = lister_tables_objets_sql(); |
|
| 540 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 541 | + |
|
| 542 | + foreach (array_keys($tables) as $t) { |
|
| 543 | + $desc = $trouver_table($t, $serveur); |
|
| 544 | + // c'est une table avec des langues |
|
| 545 | + if ($desc['exist'] |
|
| 546 | + and isset($desc['field']['lang']) |
|
| 547 | + and isset($desc['field']['langue_choisie']) |
|
| 548 | + ) { |
|
| 549 | + |
|
| 550 | + $boucle = new Boucle(); |
|
| 551 | + $boucle->show = $desc; |
|
| 552 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 553 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 554 | + $boucle->id_table = $desc['table_objet']; |
|
| 555 | + $boucle->primary = $desc['key']["PRIMARY KEY"] ?? ''; |
|
| 556 | + $boucle->sql_serveur = $serveur; |
|
| 557 | + $boucle->select[] = "DISTINCT lang"; |
|
| 558 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 559 | + $boucle->separateur[] = ','; |
|
| 560 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 561 | + $boucle->iterateur = 'sql'; |
|
| 562 | + |
|
| 563 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 564 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 565 | + $boucle->descr['gram'] = 'html'; |
|
| 566 | + |
|
| 567 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 568 | + |
|
| 569 | + if (isset($desc['statut']) |
|
| 570 | + and $desc['statut'] |
|
| 571 | + ) { |
|
| 572 | + $boucles = array( |
|
| 573 | + 'calculer_langues_utilisees' => $boucle, |
|
| 574 | + ); |
|
| 575 | + // generer un nom de fonction "anonyme" unique |
|
| 576 | + do { |
|
| 577 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 578 | + } while (function_exists($functionname)); |
|
| 579 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 580 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 581 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 582 | + $res = ''; |
|
| 583 | + eval($code); |
|
| 584 | + $res = explode(',', $res); |
|
| 585 | + foreach ($res as $lang) { |
|
| 586 | + $langues[$lang] = 1; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 590 | + while ($row = sql_fetch($res)) { |
|
| 591 | + $langues[$row['lang']] = 1; |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + $langues = array_filter(array_keys($langues)); |
|
| 598 | + sort($langues); |
|
| 599 | + $langues = join(',', $langues); |
|
| 600 | + spip_log("langues utilisees: $langues"); |
|
| 601 | + |
|
| 602 | + return $langues; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -616,9 +616,9 @@ discard block |
||
| 616 | 616 | * incluant les rubriques noeuds et toutes leurs descendances |
| 617 | 617 | */ |
| 618 | 618 | function calcul_branche_in($id) { |
| 619 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 619 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 620 | 620 | |
| 621 | - return $calcul_branche_in($id); |
|
| 621 | + return $calcul_branche_in($id); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -636,9 +636,9 @@ discard block |
||
| 636 | 636 | * incluant les rubriques transmises et toutes leurs parentées |
| 637 | 637 | */ |
| 638 | 638 | function calcul_hierarchie_in($id, $tout = true) { |
| 639 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 639 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 640 | 640 | |
| 641 | - return $calcul_hierarchie_in($id, $tout); |
|
| 641 | + return $calcul_hierarchie_in($id, $tout); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | |
@@ -659,38 +659,38 @@ discard block |
||
| 659 | 659 | * incluant les rubriques noeuds et toutes leurs descendances |
| 660 | 660 | */ |
| 661 | 661 | function inc_calcul_branche_in_dist($id) { |
| 662 | - static $b = array(); |
|
| 663 | - |
|
| 664 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 665 | - if (!is_array($id)) { |
|
| 666 | - $id = explode(',', $id); |
|
| 667 | - } |
|
| 668 | - $id = join(',', array_map('intval', $id)); |
|
| 669 | - if (isset($b[$id])) { |
|
| 670 | - return $b[$id]; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - // Notre branche commence par la rubrique de depart |
|
| 674 | - $branche = $r = $id; |
|
| 675 | - |
|
| 676 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 677 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 678 | - $maxiter = 10000; |
|
| 679 | - while ($maxiter-- and $filles = sql_allfetsel( |
|
| 680 | - 'id_rubrique', |
|
| 681 | - 'spip_rubriques', |
|
| 682 | - sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 683 | - )) { |
|
| 684 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 685 | - $branche .= ',' . $r; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 689 | - if (strlen($branche) < 10000) { |
|
| 690 | - $b[$id] = $branche; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $branche; |
|
| 662 | + static $b = array(); |
|
| 663 | + |
|
| 664 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 665 | + if (!is_array($id)) { |
|
| 666 | + $id = explode(',', $id); |
|
| 667 | + } |
|
| 668 | + $id = join(',', array_map('intval', $id)); |
|
| 669 | + if (isset($b[$id])) { |
|
| 670 | + return $b[$id]; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + // Notre branche commence par la rubrique de depart |
|
| 674 | + $branche = $r = $id; |
|
| 675 | + |
|
| 676 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 677 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 678 | + $maxiter = 10000; |
|
| 679 | + while ($maxiter-- and $filles = sql_allfetsel( |
|
| 680 | + 'id_rubrique', |
|
| 681 | + 'spip_rubriques', |
|
| 682 | + sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 683 | + )) { |
|
| 684 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 685 | + $branche .= ',' . $r; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 689 | + if (strlen($branche) < 10000) { |
|
| 690 | + $b[$id] = $branche; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $branche; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | |
@@ -712,43 +712,43 @@ discard block |
||
| 712 | 712 | * incluant les rubriques transmises et toutes leurs parentées |
| 713 | 713 | */ |
| 714 | 714 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 715 | - static $b = array(); |
|
| 716 | - |
|
| 717 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 718 | - if (!is_array($id)) { |
|
| 719 | - $id = explode(',', $id); |
|
| 720 | - } |
|
| 721 | - $id = join(',', array_map('intval', $id)); |
|
| 722 | - |
|
| 723 | - if (isset($b[$id])) { |
|
| 724 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 725 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - $hier = ""; |
|
| 729 | - |
|
| 730 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 731 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 732 | - $ids_nouveaux_parents = $id; |
|
| 733 | - $maxiter = 10000; |
|
| 734 | - while ($maxiter-- and $parents = sql_allfetsel( |
|
| 735 | - 'id_parent', |
|
| 736 | - 'spip_rubriques', |
|
| 737 | - sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 738 | - )) { |
|
| 739 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 740 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 744 | - if (strlen($hier) < 10000) { |
|
| 745 | - $b[$id] = $hier; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 749 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 750 | - |
|
| 751 | - return $hier; |
|
| 715 | + static $b = array(); |
|
| 716 | + |
|
| 717 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 718 | + if (!is_array($id)) { |
|
| 719 | + $id = explode(',', $id); |
|
| 720 | + } |
|
| 721 | + $id = join(',', array_map('intval', $id)); |
|
| 722 | + |
|
| 723 | + if (isset($b[$id])) { |
|
| 724 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 725 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + $hier = ""; |
|
| 729 | + |
|
| 730 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 731 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 732 | + $ids_nouveaux_parents = $id; |
|
| 733 | + $maxiter = 10000; |
|
| 734 | + while ($maxiter-- and $parents = sql_allfetsel( |
|
| 735 | + 'id_parent', |
|
| 736 | + 'spip_rubriques', |
|
| 737 | + sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 738 | + )) { |
|
| 739 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 740 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 744 | + if (strlen($hier) < 10000) { |
|
| 745 | + $b[$id] = $hier; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 749 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 750 | + |
|
| 751 | + return $hier; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -766,38 +766,38 @@ discard block |
||
| 766 | 766 | * @return void |
| 767 | 767 | **/ |
| 768 | 768 | function calculer_prochain_postdate($check = false) { |
| 769 | - include_spip('base/abstract_sql'); |
|
| 770 | - if ($check) { |
|
| 771 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 772 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 773 | - |
|
| 774 | - $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 775 | - "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 776 | - "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 777 | - while ($row = sql_fetch($r)) { |
|
| 778 | - publier_branche_rubrique($row['id']); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 785 | - "1"); |
|
| 786 | - |
|
| 787 | - if ($t) { |
|
| 788 | - $t = $t['date']; |
|
| 789 | - if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 790 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 791 | - ) { |
|
| 792 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 793 | - ecrire_meta('derniere_modif', time()); |
|
| 794 | - } |
|
| 795 | - } else { |
|
| 796 | - effacer_meta('date_prochain_postdate'); |
|
| 797 | - ecrire_meta('derniere_modif', time()); |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - spip_log("prochain postdate: $t"); |
|
| 769 | + include_spip('base/abstract_sql'); |
|
| 770 | + if ($check) { |
|
| 771 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 772 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 773 | + |
|
| 774 | + $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 775 | + "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 776 | + "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 777 | + while ($row = sql_fetch($r)) { |
|
| 778 | + publier_branche_rubrique($row['id']); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 785 | + "1"); |
|
| 786 | + |
|
| 787 | + if ($t) { |
|
| 788 | + $t = $t['date']; |
|
| 789 | + if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 790 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 791 | + ) { |
|
| 792 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 793 | + ecrire_meta('derniere_modif', time()); |
|
| 794 | + } |
|
| 795 | + } else { |
|
| 796 | + effacer_meta('date_prochain_postdate'); |
|
| 797 | + ecrire_meta('derniere_modif', time()); |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + spip_log("prochain postdate: $t"); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -822,42 +822,42 @@ discard block |
||
| 822 | 822 | */ |
| 823 | 823 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 824 | 824 | |
| 825 | - // eclater l'arborescence demandee |
|
| 826 | - // echapper les </multi> et autres balises fermantes html |
|
| 827 | - $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 828 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 829 | - include_spip('base/abstract_sql'); |
|
| 830 | - foreach ($arbo as $titre) { |
|
| 831 | - // retablir les </multi> et autres balises fermantes html |
|
| 832 | - $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 833 | - $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 834 | - "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 835 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 836 | - if ($r !== null) { |
|
| 837 | - $id_parent = $r; |
|
| 838 | - } else { |
|
| 839 | - $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 840 | - 'titre' => $titre, |
|
| 841 | - 'id_parent' => $id_parent, |
|
| 842 | - 'statut' => 'prepa' |
|
| 843 | - ), $desc = array(), $serveur); |
|
| 844 | - if ($id_parent > 0) { |
|
| 845 | - $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 846 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 847 | - $id_secteur = $data['id_secteur']; |
|
| 848 | - $lang = $data['lang']; |
|
| 849 | - } else { |
|
| 850 | - $id_secteur = $id_rubrique; |
|
| 851 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 855 | - "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 856 | - |
|
| 857 | - // pour la recursion |
|
| 858 | - $id_parent = $id_rubrique; |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return intval($id_parent); |
|
| 825 | + // eclater l'arborescence demandee |
|
| 826 | + // echapper les </multi> et autres balises fermantes html |
|
| 827 | + $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 828 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 829 | + include_spip('base/abstract_sql'); |
|
| 830 | + foreach ($arbo as $titre) { |
|
| 831 | + // retablir les </multi> et autres balises fermantes html |
|
| 832 | + $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 833 | + $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 834 | + "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 835 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 836 | + if ($r !== null) { |
|
| 837 | + $id_parent = $r; |
|
| 838 | + } else { |
|
| 839 | + $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 840 | + 'titre' => $titre, |
|
| 841 | + 'id_parent' => $id_parent, |
|
| 842 | + 'statut' => 'prepa' |
|
| 843 | + ), $desc = array(), $serveur); |
|
| 844 | + if ($id_parent > 0) { |
|
| 845 | + $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 846 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 847 | + $id_secteur = $data['id_secteur']; |
|
| 848 | + $lang = $data['lang']; |
|
| 849 | + } else { |
|
| 850 | + $id_secteur = $id_rubrique; |
|
| 851 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 855 | + "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 856 | + |
|
| 857 | + // pour la recursion |
|
| 858 | + $id_parent = $id_rubrique; |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return intval($id_parent); |
|
| 863 | 863 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * @return void |
| 33 | 33 | **/ |
| 34 | 34 | function array_set_merge(&$table, $index, $valeur) { |
| 35 | - if (!isset($table[$index])) { |
|
| 36 | - $table[$index] = $valeur; |
|
| 37 | - } else { |
|
| 38 | - $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | - } |
|
| 35 | + if (!isset($table[$index])) { |
|
| 36 | + $table[$index] = $valeur; |
|
| 37 | + } else { |
|
| 38 | + $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -53,439 +53,439 @@ discard block |
||
| 53 | 53 | * @return array|bool |
| 54 | 54 | */ |
| 55 | 55 | function lister_tables_objets_sql($table_sql = null, $desc = array()) { |
| 56 | - static $deja_la = false; |
|
| 57 | - static $infos_tables = null; |
|
| 58 | - static $md5 = null; |
|
| 59 | - static $plugin_hash = null; |
|
| 60 | - |
|
| 61 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | - |
|
| 64 | - // prealablement recuperer les tables_principales |
|
| 65 | - if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | - // pas de reentrance (cas base/serial) |
|
| 67 | - if ($deja_la) { |
|
| 68 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | - |
|
| 71 | - return ($table_sql === '::md5' ? $md5 : array()); |
|
| 72 | - } |
|
| 73 | - $deja_la = true; |
|
| 74 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | - |
|
| 76 | - // recuperer les declarations explicites ancienne mode |
|
| 77 | - // qui servent a completer declarer_tables_objets_sql |
|
| 78 | - base_serial($GLOBALS['tables_principales']); |
|
| 79 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | - $infos_tables = array( |
|
| 81 | - 'spip_articles' => array( |
|
| 82 | - 'page' => 'article', |
|
| 83 | - 'texte_retour' => 'icone_retour_article', |
|
| 84 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | - 'texte_objets' => 'public:articles', |
|
| 87 | - 'texte_objet' => 'public:article', |
|
| 88 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | - 'info_1_objet' => 'info_1_article', |
|
| 91 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | - 'texte_logo_objet' => 'logo_article', |
|
| 93 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | - 'titre' => 'titre, lang', |
|
| 96 | - 'date' => 'date', |
|
| 97 | - 'principale' => 'oui', |
|
| 98 | - 'introduction_longueur' => '500', |
|
| 99 | - 'champs_editables' => array( |
|
| 100 | - 'surtitre', |
|
| 101 | - 'titre', |
|
| 102 | - 'soustitre', |
|
| 103 | - 'descriptif', |
|
| 104 | - 'nom_site', |
|
| 105 | - 'url_site', |
|
| 106 | - 'chapo', |
|
| 107 | - 'texte', |
|
| 108 | - 'ps', |
|
| 109 | - 'virtuel' |
|
| 110 | - ), |
|
| 111 | - 'champs_versionnes' => array( |
|
| 112 | - 'id_rubrique', |
|
| 113 | - 'surtitre', |
|
| 114 | - 'titre', |
|
| 115 | - 'soustitre', |
|
| 116 | - 'jointure_auteurs', |
|
| 117 | - 'descriptif', |
|
| 118 | - 'nom_site', |
|
| 119 | - 'url_site', |
|
| 120 | - 'chapo', |
|
| 121 | - 'texte', |
|
| 122 | - 'ps' |
|
| 123 | - ), |
|
| 124 | - 'field' => array( |
|
| 125 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | - 'maj' => 'TIMESTAMP', |
|
| 138 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | - ), |
|
| 152 | - 'key' => array( |
|
| 153 | - 'PRIMARY KEY' => 'id_article', |
|
| 154 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | - 'KEY id_secteur' => 'id_secteur', |
|
| 156 | - 'KEY id_trad' => 'id_trad', |
|
| 157 | - 'KEY lang' => 'lang', |
|
| 158 | - 'KEY statut' => 'statut, date', |
|
| 159 | - ), |
|
| 160 | - 'join' => array( |
|
| 161 | - 'id_article' => 'id_article', |
|
| 162 | - 'id_rubrique' => 'id_rubrique' |
|
| 163 | - ), |
|
| 164 | - 'parent' => [ |
|
| 165 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | - ], |
|
| 167 | - 'rechercher_champs' => array( |
|
| 168 | - 'surtitre' => 5, |
|
| 169 | - 'titre' => 8, |
|
| 170 | - 'soustitre' => 5, |
|
| 171 | - 'chapo' => 3, |
|
| 172 | - 'texte' => 1, |
|
| 173 | - 'ps' => 1, |
|
| 174 | - 'nom_site' => 1, |
|
| 175 | - 'url_site' => 1, |
|
| 176 | - 'descriptif' => 4 |
|
| 177 | - ), |
|
| 178 | - 'rechercher_jointures' => array( |
|
| 179 | - 'auteur' => array('nom' => 10), |
|
| 180 | - ), |
|
| 181 | - 'statut' => array( |
|
| 182 | - array( |
|
| 183 | - 'champ' => 'statut', |
|
| 184 | - 'publie' => 'publie', |
|
| 185 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | - 'post_date' => 'date', |
|
| 187 | - 'exception' => array('statut', 'tout') |
|
| 188 | - ) |
|
| 189 | - ), |
|
| 190 | - 'statut_titres' => array( |
|
| 191 | - 'prepa' => 'info_article_redaction', |
|
| 192 | - 'prop' => 'info_article_propose', |
|
| 193 | - 'publie' => 'info_article_publie', |
|
| 194 | - 'refuse' => 'info_article_refuse', |
|
| 195 | - 'poubelle' => 'info_article_supprime' |
|
| 196 | - ), |
|
| 197 | - 'statut_textes_instituer' => array( |
|
| 198 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | - 'publie' => 'texte_statut_publie', |
|
| 201 | - 'refuse' => 'texte_statut_refuse', |
|
| 202 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | - ), |
|
| 204 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | - 'aide_changer_statut' => 'artstatut', |
|
| 206 | - 'tables_jointures' => array( |
|
| 207 | - 'profondeur' => 'rubriques', |
|
| 208 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | - ), |
|
| 210 | - ), |
|
| 211 | - 'spip_auteurs' => array( |
|
| 212 | - 'page' => 'auteur', |
|
| 213 | - 'texte_retour' => 'icone_retour', |
|
| 214 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | - 'texte_objets' => 'icone_auteurs', |
|
| 217 | - 'texte_objet' => 'public:auteur', |
|
| 218 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | - 'info_1_objet' => 'info_1_auteur', |
|
| 220 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | - 'date' => 'date', |
|
| 225 | - 'principale' => 'oui', |
|
| 226 | - 'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'), |
|
| 227 | - 'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'), |
|
| 228 | - 'field' => array( |
|
| 229 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | - 'maj' => 'TIMESTAMP', |
|
| 241 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | - 'alea_actuel' => 'tinytext', |
|
| 245 | - 'alea_futur' => 'tinytext', |
|
| 246 | - 'prefs' => 'text', |
|
| 247 | - 'cookie_oubli' => 'tinytext', |
|
| 248 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 251 | - ), |
|
| 252 | - 'key' => array( |
|
| 253 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | - 'KEY login' => 'login', |
|
| 255 | - 'KEY statut' => 'statut', |
|
| 256 | - 'KEY en_ligne' => 'en_ligne', |
|
| 257 | - ), |
|
| 258 | - 'join' => array( |
|
| 259 | - 'id_auteur' => 'id_auteur', |
|
| 260 | - 'login' => 'login' |
|
| 261 | - ), |
|
| 262 | - 'rechercher_champs' => array( |
|
| 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' => array( |
|
| 273 | - array( |
|
| 274 | - 'champ' => 'statut', |
|
| 275 | - 'publie' => '!5poubelle', |
|
| 276 | - 'previsu' => '!5poubelle', |
|
| 277 | - 'exception' => 'statut' |
|
| 278 | - ), |
|
| 279 | - array( |
|
| 280 | - 'champ' => array( |
|
| 281 | - array('spip_auteurs_liens', 'id_auteur'), |
|
| 282 | - array( |
|
| 283 | - 'spip_articles', |
|
| 284 | - array('id_objet', 'id_article', 'objet', 'article') |
|
| 285 | - ), |
|
| 286 | - 'statut' |
|
| 287 | - ), |
|
| 288 | - 'publie' => 'publie', |
|
| 289 | - 'previsu' => '!', |
|
| 290 | - 'post_date' => 'date', |
|
| 291 | - 'exception' => array('statut', 'lien', 'tout') |
|
| 292 | - ), |
|
| 293 | - ), |
|
| 294 | - 'statut_images' => array( |
|
| 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' => array( |
|
| 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' => array(#'auteurs_liens' // declaration generique plus bas |
|
| 310 | - ), |
|
| 311 | - ), |
|
| 312 | - 'spip_rubriques' => array( |
|
| 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' => array('titre', 'texte', 'descriptif', 'extra'), |
|
| 334 | - 'champs_versionnes' => array('titre', 'descriptif', 'texte'), |
|
| 335 | - 'field' => array( |
|
| 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' => array( |
|
| 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' => array( |
|
| 360 | - 'titre' => 8, |
|
| 361 | - 'descriptif' => 5, |
|
| 362 | - 'texte' => 1 |
|
| 363 | - ), |
|
| 364 | - 'statut' => array( |
|
| 365 | - array( |
|
| 366 | - 'champ' => 'statut', |
|
| 367 | - 'publie' => 'publie', |
|
| 368 | - 'previsu' => '!', |
|
| 369 | - 'exception' => array('statut', 'tout') |
|
| 370 | - ), |
|
| 371 | - ), |
|
| 372 | - 'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | - ), |
|
| 374 | - ), |
|
| 375 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | - array('tables_jointures' => array('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 = array(); |
|
| 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 ($all as $i => $v) { |
|
| 404 | - if (in_array($i, array('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' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) { |
|
| 409 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | - foreach ($doublons as $d) { |
|
| 411 | - if (is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 412 | - and is_numeric($k = array_search($d, $add)) |
|
| 413 | - ) { |
|
| 414 | - unset($add[$k]); |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add); |
|
| 419 | - } else { |
|
| 420 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 421 | - isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), |
|
| 422 | - $all[$i] |
|
| 423 | - ); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // completer les tables principales et auxiliaires |
|
| 429 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 430 | - // pour assurer la compat en transition |
|
| 431 | - foreach ($infos_tables as $table => $infos) { |
|
| 432 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 433 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 434 | - // qui a ete appelle avant |
|
| 435 | - $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array()); |
|
| 436 | - // l'ajouter au tableau |
|
| 437 | - $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
|
| 438 | - if (isset($infos['field']) and isset($infos['key'])) { |
|
| 439 | - foreach (array('field', 'key', 'join') as $k) { |
|
| 440 | - if (isset($infos_tables[$table][$k])) { |
|
| 441 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } else { |
|
| 445 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 446 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 447 | - $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
|
| 448 | - } |
|
| 449 | - if (count($mem)) { |
|
| 450 | - foreach (array_keys($mem) as $k) { |
|
| 451 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 452 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 453 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 454 | - $mem[$k] |
|
| 455 | - ); |
|
| 456 | - } else { |
|
| 457 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // recuperer les interfaces (table_titre, table_date) |
|
| 464 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 465 | - // dans le pipeline de declarer_tables_interfaces |
|
| 466 | - include_spip('public/interfaces'); |
|
| 467 | - foreach (array_keys($infos_tables) as $t) { |
|
| 468 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $deja_la = false; |
|
| 472 | - // signature |
|
| 473 | - $md5 = md5(serialize($infos_tables)); |
|
| 474 | - } |
|
| 475 | - if ($table_sql === '::md5') { |
|
| 476 | - return $md5; |
|
| 477 | - } |
|
| 478 | - if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 479 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 480 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 481 | - |
|
| 482 | - return $desc; |
|
| 483 | - } |
|
| 484 | - if ($table_sql) { |
|
| 485 | - return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array(); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - return $infos_tables; |
|
| 56 | + static $deja_la = false; |
|
| 57 | + static $infos_tables = null; |
|
| 58 | + static $md5 = null; |
|
| 59 | + static $plugin_hash = null; |
|
| 60 | + |
|
| 61 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | + |
|
| 64 | + // prealablement recuperer les tables_principales |
|
| 65 | + if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | + // pas de reentrance (cas base/serial) |
|
| 67 | + if ($deja_la) { |
|
| 68 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | + |
|
| 71 | + return ($table_sql === '::md5' ? $md5 : array()); |
|
| 72 | + } |
|
| 73 | + $deja_la = true; |
|
| 74 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | + |
|
| 76 | + // recuperer les declarations explicites ancienne mode |
|
| 77 | + // qui servent a completer declarer_tables_objets_sql |
|
| 78 | + base_serial($GLOBALS['tables_principales']); |
|
| 79 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | + $infos_tables = array( |
|
| 81 | + 'spip_articles' => array( |
|
| 82 | + 'page' => 'article', |
|
| 83 | + 'texte_retour' => 'icone_retour_article', |
|
| 84 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | + 'texte_objets' => 'public:articles', |
|
| 87 | + 'texte_objet' => 'public:article', |
|
| 88 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | + 'info_1_objet' => 'info_1_article', |
|
| 91 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | + 'texte_logo_objet' => 'logo_article', |
|
| 93 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | + 'titre' => 'titre, lang', |
|
| 96 | + 'date' => 'date', |
|
| 97 | + 'principale' => 'oui', |
|
| 98 | + 'introduction_longueur' => '500', |
|
| 99 | + 'champs_editables' => array( |
|
| 100 | + 'surtitre', |
|
| 101 | + 'titre', |
|
| 102 | + 'soustitre', |
|
| 103 | + 'descriptif', |
|
| 104 | + 'nom_site', |
|
| 105 | + 'url_site', |
|
| 106 | + 'chapo', |
|
| 107 | + 'texte', |
|
| 108 | + 'ps', |
|
| 109 | + 'virtuel' |
|
| 110 | + ), |
|
| 111 | + 'champs_versionnes' => array( |
|
| 112 | + 'id_rubrique', |
|
| 113 | + 'surtitre', |
|
| 114 | + 'titre', |
|
| 115 | + 'soustitre', |
|
| 116 | + 'jointure_auteurs', |
|
| 117 | + 'descriptif', |
|
| 118 | + 'nom_site', |
|
| 119 | + 'url_site', |
|
| 120 | + 'chapo', |
|
| 121 | + 'texte', |
|
| 122 | + 'ps' |
|
| 123 | + ), |
|
| 124 | + 'field' => array( |
|
| 125 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | + 'maj' => 'TIMESTAMP', |
|
| 138 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | + ), |
|
| 152 | + 'key' => array( |
|
| 153 | + 'PRIMARY KEY' => 'id_article', |
|
| 154 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | + 'KEY id_secteur' => 'id_secteur', |
|
| 156 | + 'KEY id_trad' => 'id_trad', |
|
| 157 | + 'KEY lang' => 'lang', |
|
| 158 | + 'KEY statut' => 'statut, date', |
|
| 159 | + ), |
|
| 160 | + 'join' => array( |
|
| 161 | + 'id_article' => 'id_article', |
|
| 162 | + 'id_rubrique' => 'id_rubrique' |
|
| 163 | + ), |
|
| 164 | + 'parent' => [ |
|
| 165 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | + ], |
|
| 167 | + 'rechercher_champs' => array( |
|
| 168 | + 'surtitre' => 5, |
|
| 169 | + 'titre' => 8, |
|
| 170 | + 'soustitre' => 5, |
|
| 171 | + 'chapo' => 3, |
|
| 172 | + 'texte' => 1, |
|
| 173 | + 'ps' => 1, |
|
| 174 | + 'nom_site' => 1, |
|
| 175 | + 'url_site' => 1, |
|
| 176 | + 'descriptif' => 4 |
|
| 177 | + ), |
|
| 178 | + 'rechercher_jointures' => array( |
|
| 179 | + 'auteur' => array('nom' => 10), |
|
| 180 | + ), |
|
| 181 | + 'statut' => array( |
|
| 182 | + array( |
|
| 183 | + 'champ' => 'statut', |
|
| 184 | + 'publie' => 'publie', |
|
| 185 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | + 'post_date' => 'date', |
|
| 187 | + 'exception' => array('statut', 'tout') |
|
| 188 | + ) |
|
| 189 | + ), |
|
| 190 | + 'statut_titres' => array( |
|
| 191 | + 'prepa' => 'info_article_redaction', |
|
| 192 | + 'prop' => 'info_article_propose', |
|
| 193 | + 'publie' => 'info_article_publie', |
|
| 194 | + 'refuse' => 'info_article_refuse', |
|
| 195 | + 'poubelle' => 'info_article_supprime' |
|
| 196 | + ), |
|
| 197 | + 'statut_textes_instituer' => array( |
|
| 198 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | + 'publie' => 'texte_statut_publie', |
|
| 201 | + 'refuse' => 'texte_statut_refuse', |
|
| 202 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | + ), |
|
| 204 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | + 'aide_changer_statut' => 'artstatut', |
|
| 206 | + 'tables_jointures' => array( |
|
| 207 | + 'profondeur' => 'rubriques', |
|
| 208 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | + ), |
|
| 210 | + ), |
|
| 211 | + 'spip_auteurs' => array( |
|
| 212 | + 'page' => 'auteur', |
|
| 213 | + 'texte_retour' => 'icone_retour', |
|
| 214 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | + 'texte_objets' => 'icone_auteurs', |
|
| 217 | + 'texte_objet' => 'public:auteur', |
|
| 218 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | + 'info_1_objet' => 'info_1_auteur', |
|
| 220 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | + 'date' => 'date', |
|
| 225 | + 'principale' => 'oui', |
|
| 226 | + 'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'), |
|
| 227 | + 'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'), |
|
| 228 | + 'field' => array( |
|
| 229 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | + 'maj' => 'TIMESTAMP', |
|
| 241 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | + 'alea_actuel' => 'tinytext', |
|
| 245 | + 'alea_futur' => 'tinytext', |
|
| 246 | + 'prefs' => 'text', |
|
| 247 | + 'cookie_oubli' => 'tinytext', |
|
| 248 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 251 | + ), |
|
| 252 | + 'key' => array( |
|
| 253 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | + 'KEY login' => 'login', |
|
| 255 | + 'KEY statut' => 'statut', |
|
| 256 | + 'KEY en_ligne' => 'en_ligne', |
|
| 257 | + ), |
|
| 258 | + 'join' => array( |
|
| 259 | + 'id_auteur' => 'id_auteur', |
|
| 260 | + 'login' => 'login' |
|
| 261 | + ), |
|
| 262 | + 'rechercher_champs' => array( |
|
| 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' => array( |
|
| 273 | + array( |
|
| 274 | + 'champ' => 'statut', |
|
| 275 | + 'publie' => '!5poubelle', |
|
| 276 | + 'previsu' => '!5poubelle', |
|
| 277 | + 'exception' => 'statut' |
|
| 278 | + ), |
|
| 279 | + array( |
|
| 280 | + 'champ' => array( |
|
| 281 | + array('spip_auteurs_liens', 'id_auteur'), |
|
| 282 | + array( |
|
| 283 | + 'spip_articles', |
|
| 284 | + array('id_objet', 'id_article', 'objet', 'article') |
|
| 285 | + ), |
|
| 286 | + 'statut' |
|
| 287 | + ), |
|
| 288 | + 'publie' => 'publie', |
|
| 289 | + 'previsu' => '!', |
|
| 290 | + 'post_date' => 'date', |
|
| 291 | + 'exception' => array('statut', 'lien', 'tout') |
|
| 292 | + ), |
|
| 293 | + ), |
|
| 294 | + 'statut_images' => array( |
|
| 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' => array( |
|
| 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' => array(#'auteurs_liens' // declaration generique plus bas |
|
| 310 | + ), |
|
| 311 | + ), |
|
| 312 | + 'spip_rubriques' => array( |
|
| 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' => array('titre', 'texte', 'descriptif', 'extra'), |
|
| 334 | + 'champs_versionnes' => array('titre', 'descriptif', 'texte'), |
|
| 335 | + 'field' => array( |
|
| 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' => array( |
|
| 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' => array( |
|
| 360 | + 'titre' => 8, |
|
| 361 | + 'descriptif' => 5, |
|
| 362 | + 'texte' => 1 |
|
| 363 | + ), |
|
| 364 | + 'statut' => array( |
|
| 365 | + array( |
|
| 366 | + 'champ' => 'statut', |
|
| 367 | + 'publie' => 'publie', |
|
| 368 | + 'previsu' => '!', |
|
| 369 | + 'exception' => array('statut', 'tout') |
|
| 370 | + ), |
|
| 371 | + ), |
|
| 372 | + 'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | + ), |
|
| 374 | + ), |
|
| 375 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | + array('tables_jointures' => array('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 = array(); |
|
| 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 ($all as $i => $v) { |
|
| 404 | + if (in_array($i, array('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' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) { |
|
| 409 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | + foreach ($doublons as $d) { |
|
| 411 | + if (is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 412 | + and is_numeric($k = array_search($d, $add)) |
|
| 413 | + ) { |
|
| 414 | + unset($add[$k]); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add); |
|
| 419 | + } else { |
|
| 420 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 421 | + isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), |
|
| 422 | + $all[$i] |
|
| 423 | + ); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // completer les tables principales et auxiliaires |
|
| 429 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 430 | + // pour assurer la compat en transition |
|
| 431 | + foreach ($infos_tables as $table => $infos) { |
|
| 432 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 433 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 434 | + // qui a ete appelle avant |
|
| 435 | + $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array()); |
|
| 436 | + // l'ajouter au tableau |
|
| 437 | + $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
|
| 438 | + if (isset($infos['field']) and isset($infos['key'])) { |
|
| 439 | + foreach (array('field', 'key', 'join') as $k) { |
|
| 440 | + if (isset($infos_tables[$table][$k])) { |
|
| 441 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } else { |
|
| 445 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 446 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 447 | + $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
|
| 448 | + } |
|
| 449 | + if (count($mem)) { |
|
| 450 | + foreach (array_keys($mem) as $k) { |
|
| 451 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 452 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 453 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 454 | + $mem[$k] |
|
| 455 | + ); |
|
| 456 | + } else { |
|
| 457 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // recuperer les interfaces (table_titre, table_date) |
|
| 464 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 465 | + // dans le pipeline de declarer_tables_interfaces |
|
| 466 | + include_spip('public/interfaces'); |
|
| 467 | + foreach (array_keys($infos_tables) as $t) { |
|
| 468 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $deja_la = false; |
|
| 472 | + // signature |
|
| 473 | + $md5 = md5(serialize($infos_tables)); |
|
| 474 | + } |
|
| 475 | + if ($table_sql === '::md5') { |
|
| 476 | + return $md5; |
|
| 477 | + } |
|
| 478 | + if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 479 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 480 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 481 | + |
|
| 482 | + return $desc; |
|
| 483 | + } |
|
| 484 | + if ($table_sql) { |
|
| 485 | + return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array(); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + return $infos_tables; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -500,27 +500,27 @@ discard block |
||
| 500 | 500 | **/ |
| 501 | 501 | function base_serial(&$tables_principales) { |
| 502 | 502 | |
| 503 | - $spip_jobs = array( |
|
| 504 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 505 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 506 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 507 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 508 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 509 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 510 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 511 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 512 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 513 | - ); |
|
| 514 | - |
|
| 515 | - $spip_jobs_key = array( |
|
| 516 | - 'PRIMARY KEY' => 'id_job', |
|
| 517 | - 'KEY date' => 'date', |
|
| 518 | - 'KEY status' => 'status', |
|
| 519 | - ); |
|
| 520 | - |
|
| 521 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 522 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 523 | - $tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key); |
|
| 503 | + $spip_jobs = array( |
|
| 504 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 505 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 506 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 507 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 508 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 509 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 510 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 511 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 512 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 513 | + ); |
|
| 514 | + |
|
| 515 | + $spip_jobs_key = array( |
|
| 516 | + 'PRIMARY KEY' => 'id_job', |
|
| 517 | + 'KEY date' => 'date', |
|
| 518 | + 'KEY status' => 'status', |
|
| 519 | + ); |
|
| 520 | + |
|
| 521 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 522 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 523 | + $tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
@@ -532,71 +532,71 @@ discard block |
||
| 532 | 532 | * @return void |
| 533 | 533 | **/ |
| 534 | 534 | function base_auxiliaires(&$tables_auxiliaires) { |
| 535 | - $spip_resultats = array( |
|
| 536 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 537 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 538 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 539 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 540 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 541 | - 'maj' => 'TIMESTAMP' |
|
| 542 | - ); |
|
| 543 | - |
|
| 544 | - $spip_resultats_key = array(// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 545 | - ); |
|
| 546 | - |
|
| 547 | - $spip_auteurs_liens = array( |
|
| 548 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 549 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 551 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 552 | - ); |
|
| 553 | - |
|
| 554 | - $spip_auteurs_liens_key = array( |
|
| 555 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 556 | - 'KEY id_auteur' => 'id_auteur', |
|
| 557 | - 'KEY id_objet' => 'id_objet', |
|
| 558 | - 'KEY objet' => 'objet', |
|
| 559 | - ); |
|
| 560 | - |
|
| 561 | - $spip_meta = array( |
|
| 562 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 563 | - 'valeur' => "text DEFAULT ''", |
|
| 564 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 565 | - 'maj' => 'TIMESTAMP' |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - $spip_meta_key = array( |
|
| 569 | - 'PRIMARY KEY' => 'nom' |
|
| 570 | - ); |
|
| 571 | - |
|
| 572 | - $spip_jobs_liens = array( |
|
| 573 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 574 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 576 | - ); |
|
| 577 | - |
|
| 578 | - $spip_jobs_liens_key = array( |
|
| 579 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 580 | - 'KEY id_job' => 'id_job' |
|
| 581 | - ); |
|
| 582 | - |
|
| 583 | - $tables_auxiliaires['spip_auteurs_liens'] = array( |
|
| 584 | - 'field' => &$spip_auteurs_liens, |
|
| 585 | - 'key' => &$spip_auteurs_liens_key |
|
| 586 | - ); |
|
| 587 | - |
|
| 588 | - $tables_auxiliaires['spip_meta'] = array( |
|
| 589 | - 'field' => &$spip_meta, |
|
| 590 | - 'key' => &$spip_meta_key |
|
| 591 | - ); |
|
| 592 | - $tables_auxiliaires['spip_resultats'] = array( |
|
| 593 | - 'field' => &$spip_resultats, |
|
| 594 | - 'key' => &$spip_resultats_key |
|
| 595 | - ); |
|
| 596 | - $tables_auxiliaires['spip_jobs_liens'] = array( |
|
| 597 | - 'field' => &$spip_jobs_liens, |
|
| 598 | - 'key' => &$spip_jobs_liens_key |
|
| 599 | - ); |
|
| 535 | + $spip_resultats = array( |
|
| 536 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 537 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 538 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 539 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 540 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 541 | + 'maj' => 'TIMESTAMP' |
|
| 542 | + ); |
|
| 543 | + |
|
| 544 | + $spip_resultats_key = array(// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 545 | + ); |
|
| 546 | + |
|
| 547 | + $spip_auteurs_liens = array( |
|
| 548 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 549 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 551 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 552 | + ); |
|
| 553 | + |
|
| 554 | + $spip_auteurs_liens_key = array( |
|
| 555 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 556 | + 'KEY id_auteur' => 'id_auteur', |
|
| 557 | + 'KEY id_objet' => 'id_objet', |
|
| 558 | + 'KEY objet' => 'objet', |
|
| 559 | + ); |
|
| 560 | + |
|
| 561 | + $spip_meta = array( |
|
| 562 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 563 | + 'valeur' => "text DEFAULT ''", |
|
| 564 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 565 | + 'maj' => 'TIMESTAMP' |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + $spip_meta_key = array( |
|
| 569 | + 'PRIMARY KEY' => 'nom' |
|
| 570 | + ); |
|
| 571 | + |
|
| 572 | + $spip_jobs_liens = array( |
|
| 573 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 574 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 576 | + ); |
|
| 577 | + |
|
| 578 | + $spip_jobs_liens_key = array( |
|
| 579 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 580 | + 'KEY id_job' => 'id_job' |
|
| 581 | + ); |
|
| 582 | + |
|
| 583 | + $tables_auxiliaires['spip_auteurs_liens'] = array( |
|
| 584 | + 'field' => &$spip_auteurs_liens, |
|
| 585 | + 'key' => &$spip_auteurs_liens_key |
|
| 586 | + ); |
|
| 587 | + |
|
| 588 | + $tables_auxiliaires['spip_meta'] = array( |
|
| 589 | + 'field' => &$spip_meta, |
|
| 590 | + 'key' => &$spip_meta_key |
|
| 591 | + ); |
|
| 592 | + $tables_auxiliaires['spip_resultats'] = array( |
|
| 593 | + 'field' => &$spip_resultats, |
|
| 594 | + 'key' => &$spip_resultats_key |
|
| 595 | + ); |
|
| 596 | + $tables_auxiliaires['spip_jobs_liens'] = array( |
|
| 597 | + 'field' => &$spip_jobs_liens, |
|
| 598 | + 'key' => &$spip_jobs_liens_key |
|
| 599 | + ); |
|
| 600 | 600 | |
| 601 | 601 | } |
| 602 | 602 | |
@@ -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(',', $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'] = array(); |
|
| 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'] = array(); |
|
| 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'] and $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'] and $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'] = array(); |
|
| 764 | - } |
|
| 765 | - if (!isset($infos['champs_versionnes'])) { |
|
| 766 | - $infos['champs_versionnes'] = array(); |
|
| 767 | - } |
|
| 768 | - if (!isset($infos['rechercher_champs'])) { |
|
| 769 | - $infos['rechercher_champs'] = array(); |
|
| 770 | - } |
|
| 771 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | - $infos['rechercher_jointures'] = array(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if (!isset($infos['modeles'])) { |
|
| 776 | - $infos['modeles'] = array($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(',', $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'] = array(); |
|
| 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'] = array(); |
|
| 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'] and $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'] and $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'] = array(); |
|
| 764 | + } |
|
| 765 | + if (!isset($infos['champs_versionnes'])) { |
|
| 766 | + $infos['champs_versionnes'] = array(); |
|
| 767 | + } |
|
| 768 | + if (!isset($infos['rechercher_champs'])) { |
|
| 769 | + $infos['rechercher_champs'] = array(); |
|
| 770 | + } |
|
| 771 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | + $infos['rechercher_jointures'] = array(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if (!isset($infos['modeles'])) { |
|
| 776 | + $infos['modeles'] = array($infos['type']); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $infos; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -793,32 +793,32 @@ 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']) and 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']) and 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 | - if (!isset($infos['statut'])) { |
|
| 812 | - $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : ''; |
|
| 813 | - } |
|
| 814 | - if (!isset($infos['tables_jointures'])) { |
|
| 815 | - $infos['tables_jointures'] = array(); |
|
| 816 | - } |
|
| 817 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) and 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']) and 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 | + if (!isset($infos['statut'])) { |
|
| 812 | + $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : ''; |
|
| 813 | + } |
|
| 814 | + if (!isset($infos['tables_jointures'])) { |
|
| 815 | + $infos['tables_jointures'] = array(); |
|
| 816 | + } |
|
| 817 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + return $infos; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -829,13 +829,13 @@ discard block |
||
| 829 | 829 | * Liste et descriptions des tables principales |
| 830 | 830 | **/ |
| 831 | 831 | function lister_tables_principales() { |
| 832 | - static $done = false; |
|
| 833 | - if (!$done or !count($GLOBALS['tables_principales'])) { |
|
| 834 | - lister_tables_objets_sql(); |
|
| 835 | - $done = true; |
|
| 836 | - } |
|
| 832 | + static $done = false; |
|
| 833 | + if (!$done or !count($GLOBALS['tables_principales'])) { |
|
| 834 | + lister_tables_objets_sql(); |
|
| 835 | + $done = true; |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - return $GLOBALS['tables_principales']; |
|
| 838 | + return $GLOBALS['tables_principales']; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -846,13 +846,13 @@ discard block |
||
| 846 | 846 | * Liste et descriptions des tables auxiliaires |
| 847 | 847 | **/ |
| 848 | 848 | function lister_tables_auxiliaires() { |
| 849 | - static $done = false; |
|
| 850 | - if (!$done or !count($GLOBALS['tables_auxiliaires'])) { |
|
| 851 | - lister_tables_objets_sql(); |
|
| 852 | - $done = true; |
|
| 853 | - } |
|
| 849 | + static $done = false; |
|
| 850 | + if (!$done or !count($GLOBALS['tables_auxiliaires'])) { |
|
| 851 | + lister_tables_objets_sql(); |
|
| 852 | + $done = true; |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | - return $GLOBALS['tables_auxiliaires']; |
|
| 855 | + return $GLOBALS['tables_auxiliaires']; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -861,44 +861,44 @@ discard block |
||
| 861 | 861 | * @return array |
| 862 | 862 | */ |
| 863 | 863 | function lister_tables_objets_surnoms() { |
| 864 | - static $surnoms = null; |
|
| 865 | - static $md5 = null; |
|
| 866 | - if (!$surnoms |
|
| 867 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 868 | - ) { |
|
| 869 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 870 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 871 | - // declarer_table_objets_sql |
|
| 872 | - $surnoms = pipeline( |
|
| 873 | - 'declarer_tables_objets_surnoms', |
|
| 874 | - array( |
|
| 875 | - # pour les modeles |
|
| 876 | - # a enlever ? |
|
| 877 | - 'doc' => 'documents', |
|
| 878 | - 'img' => 'documents', |
|
| 879 | - 'emb' => 'documents', |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 882 | - $infos_tables = lister_tables_objets_sql(); |
|
| 883 | - foreach ($infos_tables as $t => $infos) { |
|
| 884 | - // cas de base type=>table |
|
| 885 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 886 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 887 | - // optimisations pour table_objet |
|
| 888 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 889 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 890 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 891 | - if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 892 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 893 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - return $surnoms; |
|
| 864 | + static $surnoms = null; |
|
| 865 | + static $md5 = null; |
|
| 866 | + if (!$surnoms |
|
| 867 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 868 | + ) { |
|
| 869 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 870 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 871 | + // declarer_table_objets_sql |
|
| 872 | + $surnoms = pipeline( |
|
| 873 | + 'declarer_tables_objets_surnoms', |
|
| 874 | + array( |
|
| 875 | + # pour les modeles |
|
| 876 | + # a enlever ? |
|
| 877 | + 'doc' => 'documents', |
|
| 878 | + 'img' => 'documents', |
|
| 879 | + 'emb' => 'documents', |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | + $infos_tables = lister_tables_objets_sql(); |
|
| 883 | + foreach ($infos_tables as $t => $infos) { |
|
| 884 | + // cas de base type=>table |
|
| 885 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 886 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 887 | + // optimisations pour table_objet |
|
| 888 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 889 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 890 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 891 | + if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 892 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 893 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + return $surnoms; |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -907,34 +907,34 @@ discard block |
||
| 907 | 907 | * @return array |
| 908 | 908 | */ |
| 909 | 909 | function lister_types_surnoms() { |
| 910 | - static $surnoms = null; |
|
| 911 | - static $md5 = null; |
|
| 912 | - if (!$surnoms |
|
| 913 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 914 | - ) { |
|
| 915 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 916 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 917 | - // declarer_table_objets_sql |
|
| 918 | - $surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site')); |
|
| 919 | - $infos_tables = lister_tables_objets_sql(); |
|
| 920 | - foreach ($infos_tables as $t => $infos) { |
|
| 921 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 922 | - // optimisations pour objet_type |
|
| 923 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 924 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 925 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 926 | - // surnoms declares |
|
| 927 | - if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 928 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 929 | - $surnoms[$surnom] = $infos['type']; |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - return $surnoms; |
|
| 910 | + static $surnoms = null; |
|
| 911 | + static $md5 = null; |
|
| 912 | + if (!$surnoms |
|
| 913 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 914 | + ) { |
|
| 915 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 916 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 917 | + // declarer_table_objets_sql |
|
| 918 | + $surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site')); |
|
| 919 | + $infos_tables = lister_tables_objets_sql(); |
|
| 920 | + foreach ($infos_tables as $t => $infos) { |
|
| 921 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 922 | + // optimisations pour objet_type |
|
| 923 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 924 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 925 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 926 | + // surnoms declares |
|
| 927 | + if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 928 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 929 | + $surnoms[$surnom] = $infos['type']; |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + return $surnoms; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -948,22 +948,22 @@ discard block |
||
| 948 | 948 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 949 | 949 | **/ |
| 950 | 950 | function lister_tables_spip($serveur = '') { |
| 951 | - static $tables = array(); |
|
| 952 | - if (!isset($tables[$serveur])) { |
|
| 953 | - $tables[$serveur] = array(); |
|
| 954 | - if (!function_exists('sql_alltable')) { |
|
| 955 | - include_spip('base/abstract_sql'); |
|
| 956 | - } |
|
| 957 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 958 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 959 | - $spip = $connexion['prefixe'] . '_'; |
|
| 960 | - foreach ($ts as $t) { |
|
| 961 | - $t = substr($t, strlen($spip)); |
|
| 962 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - return $tables[$serveur]; |
|
| 951 | + static $tables = array(); |
|
| 952 | + if (!isset($tables[$serveur])) { |
|
| 953 | + $tables[$serveur] = array(); |
|
| 954 | + if (!function_exists('sql_alltable')) { |
|
| 955 | + include_spip('base/abstract_sql'); |
|
| 956 | + } |
|
| 957 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 958 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 959 | + $spip = $connexion['prefixe'] . '_'; |
|
| 960 | + foreach ($ts as $t) { |
|
| 961 | + $t = substr($t, strlen($spip)); |
|
| 962 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + return $tables[$serveur]; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | |
@@ -978,17 +978,17 @@ discard block |
||
| 978 | 978 | * Couples (nom de la table SQL => même nom) |
| 979 | 979 | **/ |
| 980 | 980 | function lister_toutes_tables($serveur){ |
| 981 | - static $tables = array(); |
|
| 982 | - if (!isset($tables[$serveur])){ |
|
| 983 | - $tables[$serveur] = array(); |
|
| 984 | - if (!function_exists("sql_alltable")) |
|
| 985 | - include_spip("base/abstract_sql"); |
|
| 986 | - $ts = sql_alltable('%',$serveur); // toutes les tables |
|
| 987 | - foreach ($ts as $t){ |
|
| 988 | - $tables[$serveur][$t] = $t; |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - return $tables[$serveur]; |
|
| 981 | + static $tables = array(); |
|
| 982 | + if (!isset($tables[$serveur])){ |
|
| 983 | + $tables[$serveur] = array(); |
|
| 984 | + if (!function_exists("sql_alltable")) |
|
| 985 | + include_spip("base/abstract_sql"); |
|
| 986 | + $ts = sql_alltable('%',$serveur); // toutes les tables |
|
| 987 | + foreach ($ts as $t){ |
|
| 988 | + $tables[$serveur][$t] = $t; |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + return $tables[$serveur]; |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -1008,34 +1008,34 @@ discard block |
||
| 1008 | 1008 | * Nom de l'objet |
| 1009 | 1009 | **/ |
| 1010 | 1010 | function table_objet($type, $serveur = '') { |
| 1011 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1012 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | - if (!$type) { |
|
| 1014 | - return; |
|
| 1015 | - } |
|
| 1016 | - if (isset($surnoms[$type])) { |
|
| 1017 | - return $surnoms[$type]; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - if ($serveur !== false) { |
|
| 1021 | - $t = lister_tables_spip($serveur); |
|
| 1022 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1023 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1024 | - if ((isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1025 | - and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1026 | - ) { |
|
| 1027 | - return $desc['id_table']; |
|
| 1028 | - } elseif ((isset($t[$type]) or in_array($type, $t)) |
|
| 1029 | - and ($desc = $trouver_table($type, $serveur)) |
|
| 1030 | - ) { |
|
| 1031 | - return $desc['id_table']; |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1035 | - #spip_log(debug_backtrace(),'db'); |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1011 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1012 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | + if (!$type) { |
|
| 1014 | + return; |
|
| 1015 | + } |
|
| 1016 | + if (isset($surnoms[$type])) { |
|
| 1017 | + return $surnoms[$type]; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + if ($serveur !== false) { |
|
| 1021 | + $t = lister_tables_spip($serveur); |
|
| 1022 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1023 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1024 | + if ((isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1025 | + and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1026 | + ) { |
|
| 1027 | + return $desc['id_table']; |
|
| 1028 | + } elseif ((isset($t[$type]) or in_array($type, $t)) |
|
| 1029 | + and ($desc = $trouver_table($type, $serveur)) |
|
| 1030 | + ) { |
|
| 1031 | + return $desc['id_table']; |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1035 | + #spip_log(debug_backtrace(),'db'); |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1056,30 +1056,30 @@ discard block |
||
| 1056 | 1056 | **/ |
| 1057 | 1057 | function table_objet_sql($type, $serveur = '') { |
| 1058 | 1058 | |
| 1059 | - $nom = table_objet($type, $serveur); |
|
| 1060 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1061 | - // eviter de multiples inclusions |
|
| 1062 | - include_spip('public/interfaces'); |
|
| 1063 | - } |
|
| 1064 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1065 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1066 | - $nom = "spip_$nom"; |
|
| 1067 | - } else { |
|
| 1068 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1069 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1070 | - $nom = "spip_$nom"; |
|
| 1071 | - } elseif ($serveur !== false) { |
|
| 1072 | - $t = lister_tables_spip($serveur); |
|
| 1073 | - if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1074 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1075 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1076 | - return $desc['table_sql']; |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $nom; |
|
| 1059 | + $nom = table_objet($type, $serveur); |
|
| 1060 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1061 | + // eviter de multiples inclusions |
|
| 1062 | + include_spip('public/interfaces'); |
|
| 1063 | + } |
|
| 1064 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1065 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1066 | + $nom = "spip_$nom"; |
|
| 1067 | + } else { |
|
| 1068 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1069 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1070 | + $nom = "spip_$nom"; |
|
| 1071 | + } elseif ($serveur !== false) { |
|
| 1072 | + $t = lister_tables_spip($serveur); |
|
| 1073 | + if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1074 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1075 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1076 | + return $desc['table_sql']; |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $nom; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1098,35 +1098,35 @@ discard block |
||
| 1098 | 1098 | * Nom de la clé primaire |
| 1099 | 1099 | **/ |
| 1100 | 1100 | function id_table_objet($type, $serveur = '') { |
| 1101 | - static $trouver_table = null; |
|
| 1102 | - $type = objet_type($type, $serveur); |
|
| 1103 | - if (!$type) { |
|
| 1104 | - return; |
|
| 1105 | - } |
|
| 1106 | - $t = table_objet($type); |
|
| 1107 | - if (!$trouver_table) { |
|
| 1108 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - $ts = lister_tables_spip($serveur); |
|
| 1112 | - if ( |
|
| 1113 | - in_array($t, $ts) |
|
| 1114 | - or in_array($t, lister_toutes_tables($serveur)) |
|
| 1115 | - ){ |
|
| 1116 | - $desc = $trouver_table($t, $serveur); |
|
| 1117 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1118 | - return $desc['key']['PRIMARY KEY']; |
|
| 1119 | - } |
|
| 1120 | - if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1121 | - return "id_$type"; |
|
| 1122 | - } |
|
| 1123 | - // sinon renvoyer le premier champ de la table... |
|
| 1124 | - $keys = array_keys($desc['field']); |
|
| 1125 | - |
|
| 1126 | - return array_shift($keys); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - return "id_$type"; |
|
| 1101 | + static $trouver_table = null; |
|
| 1102 | + $type = objet_type($type, $serveur); |
|
| 1103 | + if (!$type) { |
|
| 1104 | + return; |
|
| 1105 | + } |
|
| 1106 | + $t = table_objet($type); |
|
| 1107 | + if (!$trouver_table) { |
|
| 1108 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + $ts = lister_tables_spip($serveur); |
|
| 1112 | + if ( |
|
| 1113 | + in_array($t, $ts) |
|
| 1114 | + or in_array($t, lister_toutes_tables($serveur)) |
|
| 1115 | + ){ |
|
| 1116 | + $desc = $trouver_table($t, $serveur); |
|
| 1117 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1118 | + return $desc['key']['PRIMARY KEY']; |
|
| 1119 | + } |
|
| 1120 | + if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1121 | + return "id_$type"; |
|
| 1122 | + } |
|
| 1123 | + // sinon renvoyer le premier champ de la table... |
|
| 1124 | + $keys = array_keys($desc['field']); |
|
| 1125 | + |
|
| 1126 | + return array_shift($keys); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + return "id_$type"; |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | /** |
@@ -1145,59 +1145,59 @@ discard block |
||
| 1145 | 1145 | * Type de l'objet |
| 1146 | 1146 | **/ |
| 1147 | 1147 | function objet_type($table_objet, $serveur = '') { |
| 1148 | - if (!$table_objet) { |
|
| 1149 | - return; |
|
| 1150 | - } |
|
| 1151 | - $surnoms = lister_types_surnoms(); |
|
| 1152 | - |
|
| 1153 | - // scenario de base |
|
| 1154 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1155 | - // et la marque du pluriel |
|
| 1156 | - // on accepte id_xx en entree aussi |
|
| 1157 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1158 | - if (isset($surnoms[$type])) { |
|
| 1159 | - return $surnoms[$type]; |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - // securite : eliminer les caracteres non \w |
|
| 1163 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1164 | - |
|
| 1165 | - // si le type redonne bien la table c'est bon |
|
| 1166 | - // oui si table_objet ressemblait deja a un type |
|
| 1167 | - if ($type == $table_objet |
|
| 1168 | - or (table_objet($type, $serveur) == $table_objet) |
|
| 1169 | - or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1170 | - ) { |
|
| 1171 | - return $type; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // si on ne veut pas chercher en base |
|
| 1175 | - if ($serveur === false) { |
|
| 1176 | - return $type; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1180 | - // car le s a la fin est incertain |
|
| 1181 | - // notamment en cas de pluriel derogatoire |
|
| 1182 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1183 | - // une declaration jeu => jeux, journal => journaux |
|
| 1184 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1185 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1186 | - $ts = lister_tables_spip($serveur); |
|
| 1187 | - $desc = false; |
|
| 1188 | - if (in_array($table_objet, $ts)) { |
|
| 1189 | - $desc = $trouver_table($table_objet); |
|
| 1190 | - } |
|
| 1191 | - if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1192 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1193 | - } |
|
| 1194 | - // si le type est declare : bingo ! |
|
| 1195 | - if ($desc and isset($desc['type'])) { |
|
| 1196 | - return $desc['type']; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - // on a fait ce qu'on a pu |
|
| 1200 | - return $type; |
|
| 1148 | + if (!$table_objet) { |
|
| 1149 | + return; |
|
| 1150 | + } |
|
| 1151 | + $surnoms = lister_types_surnoms(); |
|
| 1152 | + |
|
| 1153 | + // scenario de base |
|
| 1154 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1155 | + // et la marque du pluriel |
|
| 1156 | + // on accepte id_xx en entree aussi |
|
| 1157 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1158 | + if (isset($surnoms[$type])) { |
|
| 1159 | + return $surnoms[$type]; |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + // securite : eliminer les caracteres non \w |
|
| 1163 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1164 | + |
|
| 1165 | + // si le type redonne bien la table c'est bon |
|
| 1166 | + // oui si table_objet ressemblait deja a un type |
|
| 1167 | + if ($type == $table_objet |
|
| 1168 | + or (table_objet($type, $serveur) == $table_objet) |
|
| 1169 | + or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1170 | + ) { |
|
| 1171 | + return $type; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // si on ne veut pas chercher en base |
|
| 1175 | + if ($serveur === false) { |
|
| 1176 | + return $type; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1180 | + // car le s a la fin est incertain |
|
| 1181 | + // notamment en cas de pluriel derogatoire |
|
| 1182 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1183 | + // une declaration jeu => jeux, journal => journaux |
|
| 1184 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1185 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1186 | + $ts = lister_tables_spip($serveur); |
|
| 1187 | + $desc = false; |
|
| 1188 | + if (in_array($table_objet, $ts)) { |
|
| 1189 | + $desc = $trouver_table($table_objet); |
|
| 1190 | + } |
|
| 1191 | + if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1192 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1193 | + } |
|
| 1194 | + // si le type est declare : bingo ! |
|
| 1195 | + if ($desc and isset($desc['type'])) { |
|
| 1196 | + return $desc['type']; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + // on a fait ce qu'on a pu |
|
| 1200 | + return $type; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | /** |
@@ -1213,61 +1213,61 @@ discard block |
||
| 1213 | 1213 | * @return bool |
| 1214 | 1214 | */ |
| 1215 | 1215 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1216 | - // voir si une fonction est definie pour faire le boulot |
|
| 1217 | - // elle a la priorite dans ce cas |
|
| 1218 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1219 | - return $f($objet, $id_objet, $serveur); |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1223 | - $id_table = $table_objet = table_objet($objet); |
|
| 1224 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1225 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1226 | - if ($desc = $trouver_table($table_objet, $serveur) |
|
| 1227 | - and isset($desc['statut']) |
|
| 1228 | - and $desc['statut'] |
|
| 1229 | - ) { |
|
| 1230 | - $boucle = new Boucle(); |
|
| 1231 | - $boucle->show = $desc; |
|
| 1232 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1233 | - $boucle->id_boucle = $id_table; |
|
| 1234 | - $boucle->id_table = $id_table; |
|
| 1235 | - $boucle->primary = $desc['key']["PRIMARY KEY"] ?? ''; |
|
| 1236 | - $boucle->sql_serveur = $serveur; |
|
| 1237 | - $boucle->select[] = $id_table_objet; |
|
| 1238 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1239 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1240 | - |
|
| 1241 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1242 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1243 | - $boucle->descr['gram'] = 'html'; |
|
| 1244 | - |
|
| 1245 | - include_spip('public/compiler'); |
|
| 1246 | - include_spip('public/composer'); |
|
| 1247 | - instituer_boucle($boucle, false, true); |
|
| 1248 | - $res = calculer_select( |
|
| 1249 | - $boucle->select, |
|
| 1250 | - $boucle->from, |
|
| 1251 | - $boucle->from_type, |
|
| 1252 | - $boucle->where, |
|
| 1253 | - $boucle->join, |
|
| 1254 | - $boucle->group, |
|
| 1255 | - $boucle->order, |
|
| 1256 | - $boucle->limit, |
|
| 1257 | - $boucle->having, |
|
| 1258 | - $table_objet, |
|
| 1259 | - $id_table, |
|
| 1260 | - $serveur |
|
| 1261 | - ); |
|
| 1262 | - if (sql_fetch($res)) { |
|
| 1263 | - return true; |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - return false; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1270 | - return true; |
|
| 1216 | + // voir si une fonction est definie pour faire le boulot |
|
| 1217 | + // elle a la priorite dans ce cas |
|
| 1218 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1219 | + return $f($objet, $id_objet, $serveur); |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1223 | + $id_table = $table_objet = table_objet($objet); |
|
| 1224 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1225 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1226 | + if ($desc = $trouver_table($table_objet, $serveur) |
|
| 1227 | + and isset($desc['statut']) |
|
| 1228 | + and $desc['statut'] |
|
| 1229 | + ) { |
|
| 1230 | + $boucle = new Boucle(); |
|
| 1231 | + $boucle->show = $desc; |
|
| 1232 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1233 | + $boucle->id_boucle = $id_table; |
|
| 1234 | + $boucle->id_table = $id_table; |
|
| 1235 | + $boucle->primary = $desc['key']["PRIMARY KEY"] ?? ''; |
|
| 1236 | + $boucle->sql_serveur = $serveur; |
|
| 1237 | + $boucle->select[] = $id_table_objet; |
|
| 1238 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1239 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1240 | + |
|
| 1241 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1242 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1243 | + $boucle->descr['gram'] = 'html'; |
|
| 1244 | + |
|
| 1245 | + include_spip('public/compiler'); |
|
| 1246 | + include_spip('public/composer'); |
|
| 1247 | + instituer_boucle($boucle, false, true); |
|
| 1248 | + $res = calculer_select( |
|
| 1249 | + $boucle->select, |
|
| 1250 | + $boucle->from, |
|
| 1251 | + $boucle->from_type, |
|
| 1252 | + $boucle->where, |
|
| 1253 | + $boucle->join, |
|
| 1254 | + $boucle->group, |
|
| 1255 | + $boucle->order, |
|
| 1256 | + $boucle->limit, |
|
| 1257 | + $boucle->having, |
|
| 1258 | + $table_objet, |
|
| 1259 | + $id_table, |
|
| 1260 | + $serveur |
|
| 1261 | + ); |
|
| 1262 | + if (sql_fetch($res)) { |
|
| 1263 | + return true; |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + return false; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1270 | + return true; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | |
@@ -1302,125 +1302,125 @@ discard block |
||
| 1302 | 1302 | * Retourne un tableau décrivant les parents trouvés |
| 1303 | 1303 | */ |
| 1304 | 1304 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1305 | - $parents = []; |
|
| 1306 | - |
|
| 1307 | - // Si on trouve une ou des méthodes de parent |
|
| 1308 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1309 | - |
|
| 1310 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1311 | - include_spip('base/abstract_sql'); |
|
| 1312 | - $table_objet = table_objet_sql($objet); |
|
| 1313 | - $cle_objet = id_table_objet($objet); |
|
| 1314 | - $id_objet = intval($id_objet); |
|
| 1315 | - |
|
| 1316 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1317 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1318 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1319 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1320 | - // de celle de l'objet source |
|
| 1321 | - $select = array(); |
|
| 1322 | - if (isset($parent_methode['champ'])) { |
|
| 1323 | - $select[] = $parent_methode['champ']; |
|
| 1324 | - } |
|
| 1325 | - if (isset($parent_methode['champ_type'])) { |
|
| 1326 | - $select[] = $parent_methode['champ_type']; |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1330 | - $condition_objet_invalide = false; |
|
| 1331 | - $where = array(); |
|
| 1332 | - if (!isset($parent_methode['table'])) { |
|
| 1333 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1334 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1335 | - $table = $table_objet; |
|
| 1336 | - $where = array("$cle_objet = $id_objet"); |
|
| 1337 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1338 | - if (isset($parent_methode['condition'])) { |
|
| 1339 | - $where[] = $parent_methode['condition']; |
|
| 1340 | - } |
|
| 1341 | - } elseif (!$parent_direct_seulement) { |
|
| 1342 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1343 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1344 | - // Si non, on peut arrêter le traitement. |
|
| 1345 | - if (isset($parent_methode['condition'])) { |
|
| 1346 | - $where = array( |
|
| 1347 | - "$cle_objet = $id_objet", |
|
| 1348 | - $parent_methode['condition'] |
|
| 1349 | - ); |
|
| 1350 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1351 | - $condition_objet_invalide = true; |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1356 | - // la requête sur la table qui accueille le parent. |
|
| 1357 | - if (!$condition_objet_invalide) { |
|
| 1358 | - $table = $parent_methode['table']; |
|
| 1359 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1360 | - $where = array(); |
|
| 1361 | - // -- 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 |
|
| 1362 | - // le même que celui de l'objet source. |
|
| 1363 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1364 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1365 | - : "${cle_objet} = $id_objet"; |
|
| 1366 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1367 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1368 | - } |
|
| 1369 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1370 | - if (isset($parent_methode['table_condition'])) { |
|
| 1371 | - $where[] = $parent_methode['table_condition']; |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - // On lance la requête de récupération du parent |
|
| 1377 | - $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1378 | - if ( |
|
| 1379 | - !$condition_objet_invalide |
|
| 1380 | - and $where |
|
| 1381 | - and ($lignes = sql_allfetsel( $is_table_lien ? '*' : $select, $table, $where)) |
|
| 1382 | - ) { |
|
| 1383 | - foreach ($lignes as $ligne) { |
|
| 1384 | - // Si le type est fixe |
|
| 1385 | - if (isset($parent_methode['type'])) { |
|
| 1386 | - $parent = array( |
|
| 1387 | - 'objet' => $parent_methode['type'], |
|
| 1388 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1389 | - 'champ' => $parent_methode['champ'], |
|
| 1390 | - 'table' => $table, |
|
| 1391 | - ); |
|
| 1392 | - } |
|
| 1393 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1394 | - $parent = array( |
|
| 1395 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1396 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1397 | - 'champ' => $parent_methode['champ'], |
|
| 1398 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1399 | - 'table' => $table, |
|
| 1400 | - ); |
|
| 1401 | - } |
|
| 1402 | - if ($is_table_lien) { |
|
| 1403 | - $parent['lien'] = $ligne; |
|
| 1404 | - } |
|
| 1405 | - $parents[] = $parent; |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - // On passe par un pipeline avant de retourner |
|
| 1412 | - $parents = pipeline( |
|
| 1413 | - 'objet_lister_parents', |
|
| 1414 | - array( |
|
| 1415 | - 'args' => array( |
|
| 1416 | - 'objet' => $objet, |
|
| 1417 | - 'id_objet' => $id_objet, |
|
| 1418 | - ), |
|
| 1419 | - 'data' => $parents, |
|
| 1420 | - ) |
|
| 1421 | - ); |
|
| 1422 | - |
|
| 1423 | - return $parents; |
|
| 1305 | + $parents = []; |
|
| 1306 | + |
|
| 1307 | + // Si on trouve une ou des méthodes de parent |
|
| 1308 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1309 | + |
|
| 1310 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1311 | + include_spip('base/abstract_sql'); |
|
| 1312 | + $table_objet = table_objet_sql($objet); |
|
| 1313 | + $cle_objet = id_table_objet($objet); |
|
| 1314 | + $id_objet = intval($id_objet); |
|
| 1315 | + |
|
| 1316 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1317 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1318 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1319 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1320 | + // de celle de l'objet source |
|
| 1321 | + $select = array(); |
|
| 1322 | + if (isset($parent_methode['champ'])) { |
|
| 1323 | + $select[] = $parent_methode['champ']; |
|
| 1324 | + } |
|
| 1325 | + if (isset($parent_methode['champ_type'])) { |
|
| 1326 | + $select[] = $parent_methode['champ_type']; |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1330 | + $condition_objet_invalide = false; |
|
| 1331 | + $where = array(); |
|
| 1332 | + if (!isset($parent_methode['table'])) { |
|
| 1333 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1334 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1335 | + $table = $table_objet; |
|
| 1336 | + $where = array("$cle_objet = $id_objet"); |
|
| 1337 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1338 | + if (isset($parent_methode['condition'])) { |
|
| 1339 | + $where[] = $parent_methode['condition']; |
|
| 1340 | + } |
|
| 1341 | + } elseif (!$parent_direct_seulement) { |
|
| 1342 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1343 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1344 | + // Si non, on peut arrêter le traitement. |
|
| 1345 | + if (isset($parent_methode['condition'])) { |
|
| 1346 | + $where = array( |
|
| 1347 | + "$cle_objet = $id_objet", |
|
| 1348 | + $parent_methode['condition'] |
|
| 1349 | + ); |
|
| 1350 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1351 | + $condition_objet_invalide = true; |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1356 | + // la requête sur la table qui accueille le parent. |
|
| 1357 | + if (!$condition_objet_invalide) { |
|
| 1358 | + $table = $parent_methode['table']; |
|
| 1359 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1360 | + $where = array(); |
|
| 1361 | + // -- 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 |
|
| 1362 | + // le même que celui de l'objet source. |
|
| 1363 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1364 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1365 | + : "${cle_objet} = $id_objet"; |
|
| 1366 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1367 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1368 | + } |
|
| 1369 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1370 | + if (isset($parent_methode['table_condition'])) { |
|
| 1371 | + $where[] = $parent_methode['table_condition']; |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + // On lance la requête de récupération du parent |
|
| 1377 | + $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1378 | + if ( |
|
| 1379 | + !$condition_objet_invalide |
|
| 1380 | + and $where |
|
| 1381 | + and ($lignes = sql_allfetsel( $is_table_lien ? '*' : $select, $table, $where)) |
|
| 1382 | + ) { |
|
| 1383 | + foreach ($lignes as $ligne) { |
|
| 1384 | + // Si le type est fixe |
|
| 1385 | + if (isset($parent_methode['type'])) { |
|
| 1386 | + $parent = array( |
|
| 1387 | + 'objet' => $parent_methode['type'], |
|
| 1388 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1389 | + 'champ' => $parent_methode['champ'], |
|
| 1390 | + 'table' => $table, |
|
| 1391 | + ); |
|
| 1392 | + } |
|
| 1393 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1394 | + $parent = array( |
|
| 1395 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1396 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1397 | + 'champ' => $parent_methode['champ'], |
|
| 1398 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1399 | + 'table' => $table, |
|
| 1400 | + ); |
|
| 1401 | + } |
|
| 1402 | + if ($is_table_lien) { |
|
| 1403 | + $parent['lien'] = $ligne; |
|
| 1404 | + } |
|
| 1405 | + $parents[] = $parent; |
|
| 1406 | + } |
|
| 1407 | + } |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + // On passe par un pipeline avant de retourner |
|
| 1412 | + $parents = pipeline( |
|
| 1413 | + 'objet_lister_parents', |
|
| 1414 | + array( |
|
| 1415 | + 'args' => array( |
|
| 1416 | + 'objet' => $objet, |
|
| 1417 | + 'id_objet' => $id_objet, |
|
| 1418 | + ), |
|
| 1419 | + 'data' => $parents, |
|
| 1420 | + ) |
|
| 1421 | + ); |
|
| 1422 | + |
|
| 1423 | + return $parents; |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | /** |
@@ -1432,17 +1432,17 @@ discard block |
||
| 1432 | 1432 | * @return array |
| 1433 | 1433 | */ |
| 1434 | 1434 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1435 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1435 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1436 | 1436 | |
| 1437 | - $parents_par_type = []; |
|
| 1438 | - foreach ($parents as $parent) { |
|
| 1439 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1440 | - $parents_par_type[$parent['objet']] = []; |
|
| 1441 | - } |
|
| 1442 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1443 | - } |
|
| 1437 | + $parents_par_type = []; |
|
| 1438 | + foreach ($parents as $parent) { |
|
| 1439 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1440 | + $parents_par_type[$parent['objet']] = []; |
|
| 1441 | + } |
|
| 1442 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - return $parents_par_type; |
|
| 1445 | + return $parents_par_type; |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | |
@@ -1475,87 +1475,87 @@ discard block |
||
| 1475 | 1475 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1476 | 1476 | */ |
| 1477 | 1477 | function objet_lister_enfants($objet, $id_objet) { |
| 1478 | - $enfants = array(); |
|
| 1478 | + $enfants = array(); |
|
| 1479 | 1479 | |
| 1480 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1481 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1482 | - include_spip('base/abstract_sql'); |
|
| 1483 | - $id_objet = intval($id_objet); |
|
| 1480 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1481 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1482 | + include_spip('base/abstract_sql'); |
|
| 1483 | + $id_objet = intval($id_objet); |
|
| 1484 | 1484 | |
| 1485 | - // On parcourt tous les types d'enfants trouvés |
|
| 1486 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1487 | - // On construit les conditions d'identification du parent |
|
| 1488 | - $where = array(); |
|
| 1489 | - // -- L'identifiant du parent |
|
| 1490 | - if (isset($_methode_parent['champ'])) { |
|
| 1491 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1492 | - } |
|
| 1493 | - // -- Si le parent est variable |
|
| 1494 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1495 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1499 | - if (!isset($_methode_parent['table'])) { |
|
| 1500 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1501 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1502 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1503 | - |
|
| 1504 | - // S'il y a une condition supplémentaire |
|
| 1505 | - if (isset($_methode_parent['condition'])) { |
|
| 1506 | - $where[] = $_methode_parent['condition']; |
|
| 1507 | - } |
|
| 1508 | - } else { |
|
| 1509 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1510 | - $table_enfant = $_methode_parent['table']; |
|
| 1511 | - $cle_objet_enfant = isset($_methode_parent['source_champ']) |
|
| 1512 | - ? $_methode_parent['source_champ'] |
|
| 1513 | - : id_table_objet($objet_enfant); |
|
| 1514 | - |
|
| 1515 | - // S'il y a une condition supplémentaire |
|
| 1516 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | - $where[] = $_methode_parent['table_condition']; |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - // On lance la requête |
|
| 1522 | - $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1523 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | - $enfant = [ |
|
| 1525 | - 'objet' => $objet_enfant, |
|
| 1526 | - 'id_objet' => 0, |
|
| 1527 | - 'table' => $table_enfant |
|
| 1528 | - ]; |
|
| 1529 | - if (isset($_methode_parent['champ'])) { |
|
| 1530 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | - } |
|
| 1532 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | - } |
|
| 1535 | - foreach ($rows as $row) { |
|
| 1536 | - $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1537 | - if ($is_table_lien) { |
|
| 1538 | - $enfant['lien'] = $row; |
|
| 1539 | - } |
|
| 1540 | - $enfants[] = $enfant; |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // On passe par un pipeline avant de retourner |
|
| 1547 | - $enfants = pipeline( |
|
| 1548 | - 'objet_lister_enfants', |
|
| 1549 | - array( |
|
| 1550 | - 'args' => array( |
|
| 1551 | - 'objet' => $objet, |
|
| 1552 | - 'id_objet' => $id_objet, |
|
| 1553 | - ), |
|
| 1554 | - 'data' => $enfants, |
|
| 1555 | - ) |
|
| 1556 | - ); |
|
| 1557 | - |
|
| 1558 | - return $enfants; |
|
| 1485 | + // On parcourt tous les types d'enfants trouvés |
|
| 1486 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1487 | + // On construit les conditions d'identification du parent |
|
| 1488 | + $where = array(); |
|
| 1489 | + // -- L'identifiant du parent |
|
| 1490 | + if (isset($_methode_parent['champ'])) { |
|
| 1491 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1492 | + } |
|
| 1493 | + // -- Si le parent est variable |
|
| 1494 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1495 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1499 | + if (!isset($_methode_parent['table'])) { |
|
| 1500 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1501 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1502 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1503 | + |
|
| 1504 | + // S'il y a une condition supplémentaire |
|
| 1505 | + if (isset($_methode_parent['condition'])) { |
|
| 1506 | + $where[] = $_methode_parent['condition']; |
|
| 1507 | + } |
|
| 1508 | + } else { |
|
| 1509 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1510 | + $table_enfant = $_methode_parent['table']; |
|
| 1511 | + $cle_objet_enfant = isset($_methode_parent['source_champ']) |
|
| 1512 | + ? $_methode_parent['source_champ'] |
|
| 1513 | + : id_table_objet($objet_enfant); |
|
| 1514 | + |
|
| 1515 | + // S'il y a une condition supplémentaire |
|
| 1516 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | + $where[] = $_methode_parent['table_condition']; |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + // On lance la requête |
|
| 1522 | + $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1523 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | + $enfant = [ |
|
| 1525 | + 'objet' => $objet_enfant, |
|
| 1526 | + 'id_objet' => 0, |
|
| 1527 | + 'table' => $table_enfant |
|
| 1528 | + ]; |
|
| 1529 | + if (isset($_methode_parent['champ'])) { |
|
| 1530 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | + } |
|
| 1532 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | + } |
|
| 1535 | + foreach ($rows as $row) { |
|
| 1536 | + $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1537 | + if ($is_table_lien) { |
|
| 1538 | + $enfant['lien'] = $row; |
|
| 1539 | + } |
|
| 1540 | + $enfants[] = $enfant; |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // On passe par un pipeline avant de retourner |
|
| 1547 | + $enfants = pipeline( |
|
| 1548 | + 'objet_lister_enfants', |
|
| 1549 | + array( |
|
| 1550 | + 'args' => array( |
|
| 1551 | + 'objet' => $objet, |
|
| 1552 | + 'id_objet' => $id_objet, |
|
| 1553 | + ), |
|
| 1554 | + 'data' => $enfants, |
|
| 1555 | + ) |
|
| 1556 | + ); |
|
| 1557 | + |
|
| 1558 | + return $enfants; |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1567,17 +1567,17 @@ discard block |
||
| 1567 | 1567 | * @return array |
| 1568 | 1568 | */ |
| 1569 | 1569 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1570 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1570 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1571 | 1571 | |
| 1572 | - $enfants_par_type = []; |
|
| 1573 | - foreach ($enfants as $enfant) { |
|
| 1574 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | - } |
|
| 1577 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | - } |
|
| 1572 | + $enfants_par_type = []; |
|
| 1573 | + foreach ($enfants as $enfant) { |
|
| 1574 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | + } |
|
| 1577 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | + } |
|
| 1579 | 1579 | |
| 1580 | - return $enfants_par_type; |
|
| 1580 | + return $enfants_par_type; |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
@@ -1589,35 +1589,35 @@ discard block |
||
| 1589 | 1589 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1590 | 1590 | */ |
| 1591 | 1591 | function objet_type_decrire_infos_parents($objet) { |
| 1592 | - static $parents = array(); |
|
| 1592 | + static $parents = array(); |
|
| 1593 | 1593 | |
| 1594 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | - if (!isset($parents[$objet])) { |
|
| 1596 | - $parents[$objet] = false; |
|
| 1597 | - $table = table_objet_sql($objet); |
|
| 1594 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | + if (!isset($parents[$objet])) { |
|
| 1596 | + $parents[$objet] = false; |
|
| 1597 | + $table = table_objet_sql($objet); |
|
| 1598 | 1598 | |
| 1599 | - // Si on trouve bien la description de cet objet |
|
| 1600 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | - if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1602 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | - // de description |
|
| 1605 | - if (!isset($infos['parent'][0])) { |
|
| 1606 | - $parents[$objet] = array($infos['parent']); |
|
| 1607 | - } else { |
|
| 1608 | - $parents[$objet] = $infos['parent']; |
|
| 1609 | - } |
|
| 1610 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1611 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1612 | - $parents[$objet] = array(array('type' => 'rubrique', 'champ' => 'id_rubrique')); |
|
| 1613 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1614 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1615 | - $parents[$objet] = array(array('type' => $objet, 'champ' => 'id_parent')); |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - } |
|
| 1599 | + // Si on trouve bien la description de cet objet |
|
| 1600 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | + if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1602 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | + // de description |
|
| 1605 | + if (!isset($infos['parent'][0])) { |
|
| 1606 | + $parents[$objet] = array($infos['parent']); |
|
| 1607 | + } else { |
|
| 1608 | + $parents[$objet] = $infos['parent']; |
|
| 1609 | + } |
|
| 1610 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1611 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1612 | + $parents[$objet] = array(array('type' => 'rubrique', 'champ' => 'id_rubrique')); |
|
| 1613 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1614 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1615 | + $parents[$objet] = array(array('type' => $objet, 'champ' => 'id_parent')); |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | + } |
|
| 1619 | 1619 | |
| 1620 | - return $parents[$objet]; |
|
| 1620 | + return $parents[$objet]; |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | /** |
@@ -1629,36 +1629,36 @@ discard block |
||
| 1629 | 1629 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1630 | 1630 | */ |
| 1631 | 1631 | function objet_type_decrire_infos_enfants($objet) { |
| 1632 | - static $enfants = array(); |
|
| 1632 | + static $enfants = array(); |
|
| 1633 | 1633 | |
| 1634 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1635 | - if (!isset($enfants[$objet])) { |
|
| 1636 | - $enfants[$objet] = array(); |
|
| 1637 | - $tables = lister_tables_objets_sql(); |
|
| 1634 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1635 | + if (!isset($enfants[$objet])) { |
|
| 1636 | + $enfants[$objet] = array(); |
|
| 1637 | + $tables = lister_tables_objets_sql(); |
|
| 1638 | 1638 | |
| 1639 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1640 | - foreach ($tables as $table => $infos) { |
|
| 1641 | - $objet_enfant = objet_type($table); |
|
| 1639 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1640 | + foreach ($tables as $table => $infos) { |
|
| 1641 | + $objet_enfant = objet_type($table); |
|
| 1642 | 1642 | |
| 1643 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1644 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1645 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1646 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1647 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1648 | - if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1649 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1650 | - if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1651 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | - } |
|
| 1653 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1654 | - elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1655 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - } |
|
| 1661 | - } |
|
| 1643 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1644 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1645 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1646 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1647 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1648 | + if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1649 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1650 | + if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1651 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | + } |
|
| 1653 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1654 | + elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1655 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + } |
|
| 1661 | + } |
|
| 1662 | 1662 | |
| 1663 | - return $enfants[$objet]; |
|
| 1663 | + return $enfants[$objet]; |
|
| 1664 | 1664 | } |