[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / ecrire / exec / menu_rubriques.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
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/texte');
16
17 // http://doc.spip.org/@exec_menu_rubriques_dist
18 function exec_menu_rubriques_dist() {
19 global $spip_ecran;
20
21 header("Cache-Control: no-cache, must-revalidate");
22
23 if ($date = intval(_request('date')))
24 header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT");
25
26 $r = gen_liste_rubriques();
27 if (!$r
28 AND isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
29 AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/')) {
30 include_spip('inc/headers');
31 header('Content-Type: text/html; charset='. $GLOBALS['meta']['charset']);
32 http_status(304);
33 } else {
34
35 $largeur_t = ($spip_ecran == "large") ? 900 : 650;
36
37 $arr_low = extraire_article(0, $GLOBALS['db_art_cache']);
38
39 $total_lignes = $i = sizeof($arr_low);
40 $ret = '';
41
42 if ($i > 0) {
43 $nb_col = min(8,ceil($total_lignes / 30));
44 if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10);
45 $max_lignes = ceil($total_lignes / $nb_col);
46 $largeur = min(200, ceil($largeur_t / $nb_col));
47 $count_lignes = 0;
48 $style = " style='z-index: 0; vertical-align: top;'";
49 $image = " petit-secteur";
50 foreach( $arr_low as $id_rubrique => $titre_rubrique) {
51 if ($count_lignes == $max_lignes) {
52 $count_lignes = 0;
53
54 $ret .= "</div></td>\n<td$style><div class='bandeau_rubriques'>";
55 }
56 $count_lignes ++;
57 if (autoriser('voir','rubrique',$id_rubrique)){
58 $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i, $largeur, $image);
59 $i--;
60 }
61 }
62
63 $ret = "<table><tr>\n<td$style><div class='bandeau_rubriques'>"
64 . $ret
65 . "\n</div></td></tr></table>\n";
66 }
67
68 include_spip('inc/actions');
69 ajax_retour("<div>&nbsp;</div>" . $ret);
70 }
71 }
72
73
74 // http://doc.spip.org/@bandeau_rubrique
75 function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal, $largeur, $image='') {
76
77 global $spip_lang_left;
78
79 static $zmax = 6;
80
81 $nav = "<a href='"
82 . generer_url_ecrire('naviguer', 'id_rubrique='.$id_rubrique)
83 . "'\nclass='bandeau_rub$image' style='width: "
84 . $largeur
85 . "px;'>\n&nbsp;"
86 . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique))
87 . "</a>\n";
88
89 // Limiter volontairement le nombre de sous-menus
90 if (!(--$zmax)) {
91 $zmax++;
92 return "\n<div>$nav</div>";
93 }
94
95 $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']);
96 $i = sizeof($arr_rub);
97 if (!$i) {
98 $zmax++;
99 return "\n<div>$nav</div>";
100 }
101
102 $pxdecal = max(15, ceil($largeur/5)) . 'px';
103
104 $ret = http_script("// http://doc.spip.org/@bandeauHover
105 // http://doc.spip.org/@bandeauHover
106 function bandeauHover(r) {
107 if (!$(r).is('.hovered'))
108 $(r)
109 .addClass('hovered')
110 .children('.bandeau_rub')
111 .css('visibility', 'visible') // bizarre
112 .show()
113 .end()
114 .hover(
115 function(){\$(this).children('.bandeau_rub').show();},
116 function(){\$(this).children('.bandeau_rub').hide();}
117 );
118 };");
119
120 $ret .= "<div class='pos_r' style='z-index: "
121 . $zdecal . ";' onmouseover=\"bandeauHover(this);\">"
122 . '<div class="brt">'
123 . $nav
124 . "</div>\n<div class='bandeau_rub' style='top: 14px; $spip_lang_left: "
125 . $pxdecal
126 . "; z-index: "
127 . ($zdecal+1)
128 . "'><table cellspacing='0' cellpadding='0'><tr><td valign='top'>";
129
130 if ($nb_rub = count($arr_rub)) {
131 $nb_col = min(10,max(1,ceil($nb_rub / 10)));
132 $ret_ligne = max(4,ceil($nb_rub / $nb_col));
133 }
134 $count_ligne = 0;
135 foreach( $arr_rub as $id_rub => $titre_rub) {
136 $count_ligne ++;
137
138 if ($count_ligne > $ret_ligne) {
139 $count_ligne = 0;
140 $ret .= "</td>";
141 $ret .= '<td valign="top" style="border-left: 1px solid #cccccc;">';
142
143 }
144 if (autoriser('voir','rubrique',$id_rub)){
145 $titre = supprimer_numero(typo($titre_rub));
146 $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+$i, $largeur);
147 $i--;
148 }
149 }
150 $ret .= "</td></tr></table>\n";
151 $ret .= "</div></div>\n";
152
153 $zmax++;
154 return $ret;
155 }
156
157
158 // http://doc.spip.org/@extraire_article
159 function extraire_article($id_p, $t) {
160 return array_key_exists($id_p, $t) ? $t[$id_p]: array();
161 }
162
163 // http://doc.spip.org/@gen_liste_rubriques
164 function gen_liste_rubriques() {
165
166 // ici, un petit fichier cache ne fait pas de mal
167 $last = $GLOBALS['meta']["date_calcul_rubriques"];
168 if (lire_fichier(_CACHE_RUBRIQUES, $cache)) {
169 list($date,$GLOBALS['db_art_cache']) = @unserialize($cache);
170 if ($date == $last) return false; // c'etait en cache :-)
171 }
172 // se restreindre aux rubriques utilisees recemment +secteurs
173
174 $where = sql_in_select("id_rubrique", "id_rubrique", "spip_rubriques", "", "", "id_parent=0 DESC, date DESC", _CACHE_RUBRIQUES_MAX);
175
176 // puis refaire la requete pour avoir l'ordre alphabetique
177
178 $res = sql_select("id_rubrique, titre, id_parent", "spip_rubriques", $where, '', 'id_parent, 0+titre, titre');
179
180 // il ne faut pas filtrer le autoriser voir ici
181 // car on met le resultat en cache, commun a tout le monde
182 $GLOBALS['db_art_cache'] = array();
183 while ($r = sql_fetch($res)) {
184 $t = sinon($r['titre'], _T('ecrire:info_sans_titre'));
185 $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t));
186 }
187
188 $t = array($last ? $last : time(), $GLOBALS['db_art_cache']);
189 ecrire_fichier(_CACHE_RUBRIQUES, serialize($t));
190 return true;
191 }
192 ?>