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 afficher_selecteur($args, $afficher_ajouter_rubrique=true, $afficher_ajouter_article=true) |
---|
15 | { |
---|
16 | $retour = charger_structure(); |
---|
17 | $arbo = $retour[0]; |
---|
18 | $articles = $retour[1]; |
---|
19 | echo "<ul class=\"selecteur\">"; |
---|
20 | foreach($arbo as $id => $section) { |
---|
21 | echo "<li class=\"section\">"; |
---|
22 | if ($afficher_ajouter_rubrique) { |
---|
23 | echo '<a href="'.generer_url(array_merge($args, array("id_rubrique" => $id))).'" class="ajouter"><img src="'._DIR_PLUGIN_ARTY.'images/ajouter.gif" alt="+" /></a>'; |
---|
24 | } |
---|
25 | echo '<img class="fleche" onclick="deplier_contenu(this);" src="'._DIR_PLUGIN_ARTY.'images/deplierhaut.gif" alt=">" />'; |
---|
26 | echo '<span class="titre_section">'.$section["titre"].'</span>'; |
---|
27 | echo afficher_enfants($section["enfants"], $articles, $args, $afficher_ajouter_rubrique, $afficher_ajouter_article); |
---|
28 | if($afficher_ajouter_article) { |
---|
29 | echo selec_afficher_article($id, $articles, $args, $afficher_ajouter_rubrique, $afficher_ajouter_article); |
---|
30 | } |
---|
31 | echo "</li>"; |
---|
32 | } |
---|
33 | echo "</ul>"; |
---|
34 | } |
---|
35 | |
---|
36 | function charger_structure(){ |
---|
37 | //rubriques |
---|
38 | $arbo = array(); |
---|
39 | |
---|
40 | $result = spip_query("SELECT id_rubrique, titre FROM spip_rubriques WHERE id_parent=0"); |
---|
41 | while ($row = spip_fetch_array($result)) { |
---|
42 | $arbo[$row['id_rubrique']] = array("titre" => $row['titre']); |
---|
43 | $arbo[$row['id_rubrique']]["enfants"] = rubriques_enfants($row['id_rubrique']); |
---|
44 | } |
---|
45 | |
---|
46 | //articles |
---|
47 | $articles = array(); |
---|
48 | |
---|
49 | $result = spip_query("SELECT id_article, titre, id_rubrique FROM spip_articles WHERE statut='publie'"); |
---|
50 | while ($row = spip_fetch_array($result)) { |
---|
51 | $articles[$row['id_article']] = array("titre" => $row['titre'], "id_rubrique" => $row['id_rubrique']); |
---|
52 | } |
---|
53 | |
---|
54 | return array($arbo, $articles); |
---|
55 | } |
---|
56 | |
---|
57 | function rubriques_enfants($id_parent){ |
---|
58 | $return = array(); |
---|
59 | $result = spip_query("SELECT id_rubrique, titre FROM spip_rubriques WHERE id_parent=".$id_parent); |
---|
60 | while ($rub = spip_fetch_array($result)){ |
---|
61 | $return[$rub['id_rubrique']]["titre"] = ($rub['titre']); |
---|
62 | $return[$rub['id_rubrique']]["enfants"] = rubriques_enfants($rub['id_rubrique']); |
---|
63 | } |
---|
64 | return $return; |
---|
65 | } |
---|
66 | |
---|
67 | function afficher_enfants($arbo, $articles, $args, $afficher_ajouter_rubrique=true, $afficher_ajouter_article=true) { |
---|
68 | $html = ""; |
---|
69 | foreach($arbo as $id => $rub){ |
---|
70 | $html .= "<li class=\"rubrique\">"; |
---|
71 | if ($afficher_ajouter_rubrique) { |
---|
72 | $html .= "<a href=\"".generer_url(array_merge($args, array("id_rubrique" => $id)))."\" class=\"ajouter\"><img src=\""._DIR_PLUGIN_ARTY."images/ajouter.gif\" alt=\"+\" /></a>"; |
---|
73 | } |
---|
74 | $html .= '<img class="fleche" onclick="deplier_contenu(this);" src="'._DIR_PLUGIN_ARTY.'images/deplierhaut.gif" alt=">" />'; |
---|
75 | $html .= "<span class=\"titre_rubrique\">".raccourcir_titre($rub["titre"], 45)."</span>"; |
---|
76 | $html .= afficher_enfants($rub["enfants"], $articles, $args, $afficher_ajouter_rubrique, $afficher_ajouter_article); |
---|
77 | if ($afficher_ajouter_article) { |
---|
78 | $html .= selec_afficher_article($id, $articles, $args, $afficher_ajouter_rubrique, $afficher_ajouter_article); |
---|
79 | } |
---|
80 | $html .= "</li>"; |
---|
81 | } |
---|
82 | if ($html != "") { |
---|
83 | $html = "<ul style=\"display:none;\">".$html."</ul>"; |
---|
84 | } |
---|
85 | return $html; |
---|
86 | } |
---|
87 | |
---|
88 | function selec_afficher_article($id_rubrique, $articles, $args, $afficher_ajouter_rubrique=true, $afficher_ajouter_article=true){ |
---|
89 | $html = ""; |
---|
90 | foreach($articles as $id => $article){ |
---|
91 | if ($article["id_rubrique"] == $id_rubrique) { |
---|
92 | $html .= "<li class=\"article\">"; |
---|
93 | if ($afficher_ajouter_article) { |
---|
94 | $html .= "<a href=\"".generer_url(array_merge($args, array("id_article" => $id)))."\" class=\"ajouter\"><img src=\""._DIR_PLUGIN_ARTY."images/ajouter.gif\" alt=\"+\" /></a>"; |
---|
95 | } |
---|
96 | $html .= "<span class=\"titre_article\">".raccourcir_titre($article["titre"], 45)."</span>"; |
---|
97 | $html .= "</li>"; |
---|
98 | } |
---|
99 | } |
---|
100 | if ($html != "") { |
---|
101 | $html = "<ul style=\"display:none;\">".$html."</ul>"; |
---|
102 | } |
---|
103 | return $html; |
---|
104 | } |
---|
105 | |
---|
106 | function generer_url($args) |
---|
107 | { |
---|
108 | $segments = array(); |
---|
109 | $ancre = ""; |
---|
110 | $script = ""; |
---|
111 | foreach ($args as $param => $value) { |
---|
112 | if ($param == "#") { |
---|
113 | $ancre = "#".$value; |
---|
114 | } elseif ($param == "exec") { |
---|
115 | $script = $value; |
---|
116 | } else { |
---|
117 | $segments[] = $param."=".$value; |
---|
118 | } |
---|
119 | } |
---|
120 | $args = implode("&", $segments).$ancre; |
---|
121 | $url = generer_url_ecrire($script, $args); |
---|
122 | return $url; |
---|
123 | } |
---|
124 | |
---|
125 | function raccourcir_titre($titre, $max){ |
---|
126 | if (strlen($titre) > $max) { |
---|
127 | return substr($titre, 0, $max)."..."; |
---|
128 | } else { |
---|
129 | return $titre; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | function afficher_selecteur_mots($args) |
---|
134 | { |
---|
135 | $groupes = charger_structure_mots(); |
---|
136 | echo "<ul class=\"selecteur\">"; |
---|
137 | foreach($groupes as $id => $groupe) { |
---|
138 | echo "<li class=\"groupe\">"; |
---|
139 | echo '<a href="'.generer_url(array_merge($args, array("id_groupe" => $id))).'" class="ajouter"><img src="'._DIR_PLUGIN_ARTY.'images/ajouter.gif" alt="+" /></a>'; |
---|
140 | echo '<img class="fleche" onclick="deplier_contenu(this);" src="'._DIR_PLUGIN_ARTY.'images/deplierhaut.gif" alt=">" />'; |
---|
141 | echo '<span class="titre_groupe">'.$groupe["titre"].'</span>'; |
---|
142 | echo afficher_mots($groupe['mots'], $args); |
---|
143 | echo "</li>"; |
---|
144 | } |
---|
145 | echo "</ul>"; |
---|
146 | } |
---|
147 | |
---|
148 | function charger_structure_mots(){ |
---|
149 | //groupes de mots |
---|
150 | $groupes = array(); |
---|
151 | $result = spip_query("SELECT id_groupe, titre FROM spip_groupes_mots"); |
---|
152 | while ($row = spip_fetch_array($result)) { |
---|
153 | $result2 = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe=".$row['id_groupe']); |
---|
154 | $mots = array(); |
---|
155 | while ($row2 = spip_fetch_array($result2)) { |
---|
156 | $mots[$row2['id_mot']] = $row2['titre']; |
---|
157 | } |
---|
158 | $groupes[$row['id_groupe']] = array( |
---|
159 | 'titre' => $row['titre'], |
---|
160 | 'mots' => $mots, |
---|
161 | ); |
---|
162 | |
---|
163 | } |
---|
164 | |
---|
165 | return $groupes; |
---|
166 | } |
---|
167 | |
---|
168 | function afficher_mots($mots, $args){ |
---|
169 | $html = ""; |
---|
170 | foreach($mots as $id => $mot){ |
---|
171 | $html .= "<li class=\"mot\">"; |
---|
172 | $html .= "<a href=\"".generer_url(array_merge($args, array("id_mot" => $id)))."\" class=\"ajouter\"><img src=\""._DIR_PLUGIN_ARTY."images/ajouter.gif\" alt=\"+\" /></a>"; |
---|
173 | $html .= "<span class=\"titre_mot\">".raccourcir_titre($mot, 45)."</span>"; |
---|
174 | $html .= "</li>"; |
---|
175 | } |
---|
176 | if ($html != "") { |
---|
177 | $html = "<ul style=\"display:none;\">".$html."</ul>"; |
---|
178 | } |
---|
179 | return $html; |
---|
180 | } |
---|
181 | |
---|
182 | ?> |
---|