3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/texte');
17 // http://doc.spip.org/@exec_menu_rubriques_dist
18 function exec_menu_rubriques_dist() {
21 header("Cache-Control: no-cache, must-revalidate");
23 if ($date = intval(_request('date')))
24 header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT");
26 $r = gen_liste_rubriques();
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']);
35 $largeur_t = ($spip_ecran == "large") ?
900 : 650;
37 $arr_low = extraire_article(0, $GLOBALS['db_art_cache']);
39 $total_lignes = $i = sizeof($arr_low);
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));
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) {
54 $ret .= "</div></td>\n<td$style><div class='bandeau_rubriques'>";
57 if (autoriser('voir','rubrique',$id_rubrique)){
58 $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i, $largeur, $image);
63 $ret = "<table><tr>\n<td$style><div class='bandeau_rubriques'>"
65 . "\n</div></td></tr></table>\n";
68 include_spip('inc/actions');
69 ajax_retour("<div> </div>" . $ret);
74 // http://doc.spip.org/@bandeau_rubrique
75 function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal, $largeur, $image='') {
77 global $spip_lang_left;
82 . generer_url_ecrire('naviguer', 'id_rubrique='.$id_rubrique)
83 . "'\nclass='bandeau_rub$image' style='width: "
86 . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique))
89 // Limiter volontairement le nombre de sous-menus
92 return "\n<div>$nav</div>";
95 $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']);
96 $i = sizeof($arr_rub);
99 return "\n<div>$nav</div>";
102 $pxdecal = max(15, ceil($largeur/5)) . 'px';
104 $ret = http_script("// http://doc.spip.org/@bandeauHover
105 // http://doc.spip.org/@bandeauHover
106 function bandeauHover(r) {
107 if (!$(r).is('.hovered'))
110 .children('.bandeau_rub')
111 .css('visibility', 'visible') // bizarre
115 function(){\$(this).children('.bandeau_rub').show();},
116 function(){\$(this).children('.bandeau_rub').hide();}
120 $ret .= "<div class='pos_r' style='z-index: "
121 . $zdecal . ";' onmouseover=\"bandeauHover(this);\">"
122 . '<div class="brt">'
124 . "</div>\n<div class='bandeau_rub' style='top: 14px; $spip_lang_left: "
128 . "'><table cellspacing='0' cellpadding='0'><tr><td valign='top'>";
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));
135 foreach( $arr_rub as $id_rub => $titre_rub) {
138 if ($count_ligne > $ret_ligne) {
141 $ret .= '<td valign="top" style="border-left: 1px solid #cccccc;">';
144 if (autoriser('voir','rubrique',$id_rub)){
145 $titre = supprimer_numero(typo($titre_rub));
146 $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+
$i, $largeur);
150 $ret .= "</td></tr></table>\n";
151 $ret .= "</div></div>\n";
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();
163 // http://doc.spip.org/@gen_liste_rubriques
164 function gen_liste_rubriques() {
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 :-)
172 // se restreindre aux rubriques utilisees recemment +secteurs
174 $where = sql_in_select("id_rubrique", "id_rubrique", "spip_rubriques", "", "", "id_parent=0 DESC, date DESC", _CACHE_RUBRIQUES_MAX
);
176 // puis refaire la requete pour avoir l'ordre alphabetique
178 $res = sql_select("id_rubrique, titre, id_parent", "spip_rubriques", $where, '', 'id_parent, 0+titre, titre');
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));
188 $t = array($last ?
$last : time(), $GLOBALS['db_art_cache']);
189 ecrire_fichier(_CACHE_RUBRIQUES
, serialize($t));