source: trunk/spip/esqueleto-redcta/plugins/magusine/inc/cherche-theme.php @ 357

Last change on this file since 357 was 80, checked in by guille, 15 years ago

el plugin completo

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1<?php
2
3function theme_actuel() {
4if (isset($GLOBALS['id_rubrique'])) {
5    // si c'est une page rubrique, trouver le thÚme de la rubrique ou des rubriques parentes
6    $theme = trouver_theme($GLOBALS['id_rubrique']);
7    $id_rubrique = $GLOBALS['id_rubrique'];
8  } else if (isset($GLOBALS['id_article'])) {
9    // si c'est un article, trouver sa rubrique et ensuite son thÚme, ou le thÚme des rubriques parentes
10    $result = spip_query("SELECT id_rubrique FROM spip_articles WHERE id_article='".addslashes($GLOBALS['id_article'])."'");
11    $row = spip_fetch_array($result);
12    $id_rubrique = $row['id_rubrique'];
13    $theme = trouver_theme_article($GLOBALS['id_article']);
14    if (!$theme) {
15    $theme = trouver_theme($row['id_rubrique']);
16    }
17  } elseif (isset($GLOBALS['id_mot'])) {
18        // si c'est un mot, trouver le mot sinon pour son groupe
19        $theme = trouver_theme_mot($GLOBALS['id_mot']);
20    if (!$theme) {
21    $result = spip_query("SELECT id_groupe FROM spip_mots WHERE id_mot='".addslashes($GLOBALS['id_mot'])."'");
22    $row = spip_fetch_array($result);
23    $theme = trouver_theme_groupe($row['id_groupe']);
24    }   
25   
26  } elseif (isset($GLOBALS['id_groupe'])) {
27    // si c'est un groupe, trouver son thÚme
28    $theme = trouver_theme_groupe($GLOBALS['id_groupe']);
29  } else {
30    // dans les autres cas, charger le thÚme par defaut
31    $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type ='rubrique'");
32    $row = spip_fetch_array($result);
33    $theme = $row['theme'];
34    $id_rubrique = 0;
35  }
36  $theme = addslashes($theme);
37 
38  return $theme;
39       
40}
41
42function trouver_theme_groupe($id_groupe) {
43                $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_groupe AND type='groupe'");
44    if (spip_num_rows($result) == 1) {
45      $row = spip_fetch_array($result);
46      return $row['theme'];
47    } else {
48        $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type='rubrique'");
49                $row = spip_fetch_array($result);
50                return $row['theme'];
51    }
52}
53
54function trouver_theme_article($id_article) {
55                $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_article AND type='article'");
56    if (spip_num_rows($result) == 1) {
57      $row = spip_fetch_array($result);
58      return $row['theme'];
59    } else { 
60    return ""; 
61    }
62}
63
64function trouver_theme_mot($id_mot) {
65                $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_mot AND type='mot'");
66    if (spip_num_rows($result) == 1) {
67      $row = spip_fetch_array($result);
68      return $row['theme'];
69    } else { 
70    return ""; 
71    }
72}
73
74function trouver_theme($id_rubrique)
75        {
76  $id_parent = $id_rubrique;
77  while($id_parent != 0) {
78    // un thÚme est-il présent pour cette rubrique?
79    $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=$id_rubrique AND type='rubrique'");
80    if (spip_num_rows($result) == 1) {
81      $row = spip_fetch_array($result);
82      return $row['theme'];
83    }
84    // sinon, continuer et vérifier pour le parent
85    $result = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique");
86    $row = spip_fetch_array($result);
87    $id_parent = $row['id_parent'];
88    $id_rubrique = $id_parent;
89  }
90  // aucun thÚme n'a été trouvé, on prend le thÚme par défaut
91  $result = spip_query("SELECT theme FROM spip_arty_themeassoc WHERE id=0 AND type='rubrique'");
92  $row = spip_fetch_array($result);
93  return $row['theme'];
94}
95
96?>
Note: See TracBrowser for help on using the repository browser.