source: trunk/spip/esqueleto-redcta/plugins/magusine/inc/arty_selecteur.php @ 80

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

el plugin completo

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