[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / grouper_mots.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 include_spip('inc/presentation');
16 include_spip('inc/actions');
17 include_spip('base/abstract_sql');
18
19 // http://doc.spip.org/@inc_grouper_mots_dist
20 function inc_grouper_mots_dist($id_groupe, $total) {
21 global $connect_statut, $spip_lang_right, $spip_lang;
22
23 $presenter_liste = charger_fonction('presenter_liste', 'inc');
24
25 // ceci sert a la fois:
26 // - a construire le nom du parametre d'URL indiquant la tranche
27 // - a donner un ID a la balise ou greffer le retour d'Ajax
28 // tant pour la prochaine tranche que pour le retrait de mot
29 $tmp_var = "editer_mots-$id_groupe";
30 $url = generer_url_ecrire('grouper_mots',"id_groupe=$id_groupe");
31
32 $select = 'id_mot, id_groupe, titre, descriptif, '
33 . sql_multi ("titre", $spip_lang);
34
35 $requete = array('SELECT' => $select, 'FROM' => 'spip_mots', 'WHERE' => "id_groupe=$id_groupe", 'ORDER BY' => 'multi');
36
37 $tableau = array();
38 $occurrences = calculer_liens_mots($id_groupe);
39 if ($connect_statut=="0minirezo") {
40 $styles = array(array('arial11'), array('arial1', 100), array('arial1', 130));
41 } else {
42 $styles = array(array('arial11'), array('arial1', 100));
43 }
44 return $presenter_liste($requete, 'presenter_groupe_mots_boucle', $tableau, array($occurrences, $total, $deb_aff), false, $styles, $tmp_var, '', '', $url);
45 }
46
47 // http://doc.spip.org/@afficher_groupe_mots_boucle
48 function presenter_groupe_mots_boucle($row, $own)
49 {
50 global $connect_statut;
51 $puce_statut = charger_fonction('puce_statut', 'inc');
52
53 list($occurrences, $total, $deb_aff) = $own;
54 $id_mot = $row['id_mot'];
55 $id_groupe = $row['id_groupe'];
56 $titre = typo($row['titre']);
57 $descriptif = entites_html($row['descriptif']);
58 $droit = autoriser('modifier', 'mot', $id_mot, null, array('id_groupe' => $id_groupe));
59
60 if ($droit OR $occurrences['articles'][$id_mot] > 0) {
61 $h = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=" . generer_url_retour('mots_tous') . "#editer_mots-$id_groupe");
62 if ($descriptif) $descriptif = " title=\"$descriptif\"";
63 $cle = $puce_statut($id_mot, 'publie', $id_groupe, 'mot');
64 $titre = "<a href='$h' $descriptif>$cle $titre</a>";
65 }
66 $vals = array($titre);
67
68 $texte_lie = array();
69
70 $na = isset($occurrences['articles'][$id_mot]) ? $occurrences['articles'][$id_mot] : 0;
71 if ($na == 1)
72 $texte_lie[] = _T('info_1_article');
73 else if ($na > 1)
74 $texte_lie[] = $na." "._T('info_articles_02');
75
76 $nb = isset($occurrences['breves'][$id_mot]) ? $occurrences['breves'][$id_mot] : 0;
77 if ($nb == 1)
78 $texte_lie[] = _T('info_1_breve');
79 else if ($nb > 1)
80 $texte_lie[] = $nb." "._T('info_breves_03');
81
82 $ns = isset($occurrences['syndic'][$id_mot]) ? $occurrences['syndic'][$id_mot] : 0;
83 if ($ns == 1)
84 $texte_lie[] = _T('info_1_site');
85 else if ($ns > 1)
86 $texte_lie[] = $ns." "._T('info_sites');
87
88 $nr = isset($occurrences['rubriques'][$id_mot]) ? $occurrences['rubriques'][$id_mot] : 0;
89 if ($nr == 1)
90 $texte_lie[] = _T('info_une_rubrique_02');
91 else if ($nr > 1)
92 $texte_lie[] = $nr." "._T('info_rubriques_02');
93
94 $texte_lie = pipeline('afficher_nombre_objets_associes_a',array('args'=>array('objet'=>'mot','id_objet'=>$id_mot),'data'=>$texte_lie));
95 $texte_lie = join($texte_lie,", ");
96
97 $vals[] = $texte_lie;
98
99 if ($droit) {
100 $clic = '<small>'
101 ._T('info_supprimer_mot')
102 . "&nbsp;<img style='vertical-align: bottom;' src='"
103 . chemin_image('croix-rouge.gif')
104 . "' alt='X' width='7' height='7' />"
105 . '</small>';
106
107 if ($nr OR $na OR $ns OR $nb)
108 $href = "<a href='"
109 . generer_url_ecrire("mots_tous","conf_mot=$id_mot&na=$na&nb=$nb&nr=$nr&ns=$ns&son_groupe=$id_groupe") . "#editer_mots-$id_groupe"
110 . "'>$clic</a>";
111 else {
112 $href = generer_supprimer_mot($id_mot, $id_groupe, $clic, $total, $deb_aff);
113 }
114
115 $vals[] = "<div style='text-align:right;'>$href</div>";
116 }
117
118 return $vals;
119 }
120
121 // http://doc.spip.org/@generer_supprimer_mot
122 function generer_supprimer_mot($id_mot, $id_groupe, $clic, $total, $deb_aff='')
123 {
124 $cont = ($total > 1)
125 ? ''
126 : "function(r) {jQuery('#editer_mots-$id_groupe-supprimer').css('visibility','visible');}";
127
128 return ajax_action_auteur('editer_mots', "$id_groupe,$id_mot,,,",'grouper_mots', "id_groupe=$id_groupe&$deb_aff", array($clic,''), '', $cont);
129 }
130
131 //
132 // Calculer les nombres d'elements (articles, etc.) lies a chaque mot
133 //
134
135 // http://doc.spip.org/@calculer_liens_mots
136 function calculer_liens_mots($id_groupe)
137 {
138 $aff_articles = sql_in('O.statut', ($GLOBALS['connect_statut'] =="0minirezo") ? array('prepa','prop','publie') : array('prop','publie'));
139
140 $res = sql_allfetsel("COUNT(*) as cnt, L.id_mot", "spip_mots_articles AS L LEFT JOIN spip_mots AS M ON L.id_mot=M.id_mot LEFT JOIN spip_articles AS O ON L.id_article=O.id_article", "M.id_groupe=$id_groupe AND $aff_articles", "L.id_mot");
141 $articles = array();
142 foreach($res as $row) $articles[$row['id_mot']] = $row['cnt'];
143
144 $rubriques = array();
145 $res = sql_allfetsel("COUNT(*) as cnt, L.id_mot", "spip_mots_rubriques AS L LEFT JOIN spip_mots AS M ON L.id_mot=M.id_mot", "M.id_groupe=$id_groupe", "L.id_mot");
146 foreach($res as $row) $rubriques[$row['id_mot']] = $row['cnt'];
147
148 $breves = array();
149 $res = sql_allfetsel("COUNT(*) as cnt, L.id_mot", "spip_mots_breves AS L LEFT JOIN spip_mots AS M ON L.id_mot=M.id_mot LEFT JOIN spip_breves AS O ON L.id_breve=O.id_breve", "M.id_groupe=$id_groupe AND $aff_articles", "L.id_mot");
150 foreach($res as $row) $breves[$row['id_mot']] = $row['cnt'];
151
152 $syndic = array();
153 $res = sql_allfetsel("COUNT(*) as cnt, L.id_mot", "spip_mots_syndic AS L LEFT JOIN spip_mots AS M ON L.id_mot=M.id_mot LEFT JOIN spip_syndic AS O ON L.id_syndic=O.id_syndic", "M.id_groupe=$id_groupe AND $aff_articles", "L.id_mot");
154 foreach($res as $row) $syndic[$row['id_mot']] = $row['cnt'];
155
156 return array('articles' => $articles,
157 'breves' => $breves,
158 'rubriques' => $rubriques,
159 'syndic' => $syndic);
160 }
161 ?>