[198] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | Plugin : magusine |
---|
| 4 | Licence : GPL |
---|
| 5 | Auteurs : Stéphane Noël, Philippe Vanderlinden |
---|
| 6 | Infos : http://www.spip-contrib.net/Le-plugin-Magusine |
---|
| 7 | http://www.magunews.net/spip.php?rubrique645 |
---|
| 8 | |
---|
| 9 | $LastChangedRevision: 12345 $ |
---|
| 10 | $LastChangedBy: bubu $ |
---|
| 11 | $LastChangedDate: 2008-03-21 15:50:47 +0100 (ven, 21 mar 2008) $ |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
| 14 | function theme_actuel() { |
---|
| 15 | //print_r($GLOBALS['contexte']['id_article']); |
---|
| 16 | //echo "article -".$GLOBALS['contexte']['id_rubrique']."-"; |
---|
| 17 | if (isset($GLOBALS['contexte']['id_rubrique'])) { |
---|
| 18 | // si c'est une page rubrique, trouver le thÚme de la rubrique ou des rubriques parentes |
---|
| 19 | $theme = trouver_theme($GLOBALS['contexte']['id_rubrique']); |
---|
| 20 | $id_rubrique = $GLOBALS['contexte']['id_rubrique']; |
---|
| 21 | } else if (isset($GLOBALS['contexte']['id_article'])) { |
---|
| 22 | |
---|
| 23 | // si c'est un article, trouver sa rubrique et ensuite son thÚme, ou le thÚme des rubriques parentes |
---|
| 24 | $result = spip_query("SELECT id_rubrique FROM spip_articles WHERE id_article='".addslashes($GLOBALS['contexte']['id_article'])."'"); |
---|
| 25 | $row = spip_fetch_array($result); |
---|
| 26 | $id_rubrique = $row['id_rubrique']; |
---|
| 27 | $theme = trouver_theme_article($GLOBALS['contexte']['id_article']); |
---|
| 28 | if (!$theme) { |
---|
| 29 | $theme = trouver_theme($row['id_rubrique']); |
---|
| 30 | } |
---|
| 31 | } elseif (isset($GLOBALS['contexte']['id_mot'])) { |
---|
| 32 | // si c'est un mot, trouver le mot sinon pour son groupe |
---|
| 33 | $theme = trouver_theme_mot($GLOBALS['contexte']['id_mot']); |
---|
| 34 | if (!$theme) { |
---|
| 35 | $result = spip_query("SELECT id_groupe FROM spip_mots WHERE id_mot='".addslashes($GLOBALS['contexte']['id_mot'])."'"); |
---|
| 36 | $row = spip_fetch_array($result); |
---|
| 37 | $theme = trouver_theme_groupe($row['id_groupe']); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | } elseif (isset($GLOBALS['contexte']['id_groupe'])) { |
---|
| 41 | // si c'est un groupe, trouver son thÚme |
---|
| 42 | $theme = trouver_theme_groupe($GLOBALS['contexte']['id_groupe']); |
---|
| 43 | } else { |
---|
| 44 | // dans les autres cas, charger le thÚme par defaut |
---|
| 45 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type ='rubrique'"); |
---|
| 46 | $row = spip_fetch_array($result); |
---|
| 47 | $theme = $row['theme']; |
---|
| 48 | $id_rubrique = 0; |
---|
| 49 | } |
---|
| 50 | $theme = addslashes($theme); |
---|
| 51 | |
---|
| 52 | return $theme; |
---|
| 53 | |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | function trouver_theme_groupe($id_groupe) { |
---|
| 57 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_groupe AND type='groupe'"); |
---|
| 58 | if (spip_mysql_count($result) == 1) { |
---|
| 59 | $row = spip_fetch_array($result); |
---|
| 60 | return $row['theme']; |
---|
| 61 | } else { |
---|
| 62 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type='rubrique'"); |
---|
| 63 | $row = spip_fetch_array($result); |
---|
| 64 | return $row['theme']; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | function trouver_theme_article($id_article) { |
---|
| 69 | |
---|
| 70 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_article AND type='article'"); |
---|
| 71 | if (spip_mysql_count($result) == 1) { |
---|
| 72 | $row = spip_fetch_array($result); |
---|
| 73 | return $row['theme']; |
---|
| 74 | } else { |
---|
| 75 | return ""; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function trouver_theme_mot($id_mot) { |
---|
| 80 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_mot AND type='mot'"); |
---|
| 81 | if (spip_mysql_count($result) == 1) { |
---|
| 82 | $row = spip_fetch_array($result); |
---|
| 83 | return $row['theme']; |
---|
| 84 | } else { |
---|
| 85 | return ""; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | function trouver_theme($id_rubrique) |
---|
| 90 | { |
---|
| 91 | $id_parent = $id_rubrique; |
---|
| 92 | while($id_parent != 0) { |
---|
| 93 | // un thÚme est-il présent pour cette rubrique? |
---|
| 94 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_rubrique AND type='rubrique'"); |
---|
| 95 | if (spip_mysql_count($result) == 1) { |
---|
| 96 | $row = spip_fetch_array($result); |
---|
| 97 | return $row['theme']; |
---|
| 98 | } |
---|
| 99 | // sinon, continuer et vérifier pour le parent |
---|
| 100 | $result = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique"); |
---|
| 101 | $row = spip_fetch_array($result); |
---|
| 102 | $id_parent = $row['id_parent']; |
---|
| 103 | $id_rubrique = $id_parent; |
---|
| 104 | } |
---|
| 105 | // aucun thÚme n'a été trouvé, on prend le thÚme par défaut |
---|
| 106 | $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type='rubrique'"); |
---|
| 107 | $row = spip_fetch_array($result); |
---|
| 108 | return $row['theme']; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | ?> |
---|