[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/exec/ -> menu_rubriques.php (source)

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


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics