PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/spip/ecrire/exec/menu_rubriques.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 192 lines | 135 code | 37 blank | 20 comment | 20 complexity | 8453aa6e6e428fb19fdfff0a28368536 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. include_spip('inc/texte');
  13. // http://doc.spip.org/@exec_menu_rubriques_dist
  14. function exec_menu_rubriques_dist() {
  15. global $spip_ecran;
  16. header("Cache-Control: no-cache, must-revalidate");
  17. if ($date = intval(_request('date')))
  18. header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT");
  19. $r = gen_liste_rubriques();
  20. if (!$r
  21. AND isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
  22. AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/')) {
  23. include_spip('inc/headers');
  24. header('Content-Type: text/html; charset='. $GLOBALS['meta']['charset']);
  25. http_status(304);
  26. } else {
  27. $largeur_t = ($spip_ecran == "large") ? 900 : 650;
  28. $arr_low = extraire_article(0, $GLOBALS['db_art_cache']);
  29. $total_lignes = $i = sizeof($arr_low);
  30. $ret = '';
  31. if ($i > 0) {
  32. $nb_col = min(8,ceil($total_lignes / 30));
  33. if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10);
  34. $max_lignes = ceil($total_lignes / $nb_col);
  35. $largeur = min(200, ceil($largeur_t / $nb_col));
  36. $count_lignes = 0;
  37. $style = " style='z-index: 0; vertical-align: top;'";
  38. $image = " petit-secteur";
  39. foreach( $arr_low as $id_rubrique => $titre_rubrique) {
  40. if ($count_lignes == $max_lignes) {
  41. $count_lignes = 0;
  42. $ret .= "</div></td>\n<td$style><div class='bandeau_rubriques'>";
  43. }
  44. $count_lignes ++;
  45. if (autoriser('voir','rubrique',$id_rubrique)){
  46. $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i, $largeur, $image);
  47. $i--;
  48. }
  49. }
  50. $ret = "<table><tr>\n<td$style><div class='bandeau_rubriques'>"
  51. . $ret
  52. . "\n</div></td></tr></table>\n";
  53. }
  54. include_spip('inc/actions');
  55. ajax_retour("<div>&nbsp;</div>" . $ret);
  56. }
  57. }
  58. // http://doc.spip.org/@bandeau_rubrique
  59. function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal, $largeur, $image='') {
  60. global $spip_lang_left;
  61. static $zmax = 6;
  62. $nav = "<a href='"
  63. . generer_url_ecrire('naviguer', 'id_rubrique='.$id_rubrique)
  64. . "'\nclass='bandeau_rub$image' style='width: "
  65. . $largeur
  66. . "px;'>\n&nbsp;"
  67. . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique))
  68. . "</a>\n";
  69. // Limiter volontairement le nombre de sous-menus
  70. if (!(--$zmax)) {
  71. $zmax++;
  72. return "\n<div>$nav</div>";
  73. }
  74. $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']);
  75. $i = sizeof($arr_rub);
  76. if (!$i) {
  77. $zmax++;
  78. return "\n<div>$nav</div>";
  79. }
  80. $pxdecal = max(15, ceil($largeur/5)) . 'px';
  81. $ret = http_script("// http://doc.spip.org/@bandeauHover
  82. // http://doc.spip.org/@bandeauHover
  83. function bandeauHover(r) {
  84. if (!$(r).is('.hovered'))
  85. $(r)
  86. .addClass('hovered')
  87. .children('.bandeau_rub')
  88. .css('visibility', 'visible') // bizarre
  89. .show()
  90. .end()
  91. .hover(
  92. function(){\$(this).children('.bandeau_rub').show();},
  93. function(){\$(this).children('.bandeau_rub').hide();}
  94. );
  95. };");
  96. $ret .= "<div class='pos_r' style='z-index: "
  97. . $zdecal . ";' onmouseover=\"bandeauHover(this);\">"
  98. . '<div class="brt">'
  99. . $nav
  100. . "</div>\n<div class='bandeau_rub' style='top: 14px; $spip_lang_left: "
  101. . $pxdecal
  102. . "; z-index: "
  103. . ($zdecal+1)
  104. . "'><table cellspacing='0' cellpadding='0'><tr><td valign='top'>";
  105. if ($nb_rub = count($arr_rub)) {
  106. $nb_col = min(10,max(1,ceil($nb_rub / 10)));
  107. $ret_ligne = max(4,ceil($nb_rub / $nb_col));
  108. }
  109. $count_ligne = 0;
  110. foreach( $arr_rub as $id_rub => $titre_rub) {
  111. $count_ligne ++;
  112. if ($count_ligne > $ret_ligne) {
  113. $count_ligne = 0;
  114. $ret .= "</td>";
  115. $ret .= '<td valign="top" style="border-left: 1px solid #cccccc;">';
  116. }
  117. if (autoriser('voir','rubrique',$id_rub)){
  118. $titre = supprimer_numero(typo($titre_rub));
  119. $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+$i, $largeur);
  120. $i--;
  121. }
  122. }
  123. $ret .= "</td></tr></table>\n";
  124. $ret .= "</div></div>\n";
  125. $zmax++;
  126. return $ret;
  127. }
  128. // http://doc.spip.org/@extraire_article
  129. function extraire_article($id_p, $t) {
  130. return array_key_exists($id_p, $t) ? $t[$id_p]: array();
  131. }
  132. // http://doc.spip.org/@gen_liste_rubriques
  133. function gen_liste_rubriques() {
  134. // ici, un petit fichier cache ne fait pas de mal
  135. $last = $GLOBALS['meta']["date_calcul_rubriques"];
  136. if (lire_fichier(_CACHE_RUBRIQUES, $cache)) {
  137. list($date,$GLOBALS['db_art_cache']) = @unserialize($cache);
  138. if ($date == $last) return false; // c'etait en cache :-)
  139. }
  140. // se restreindre aux rubriques utilisees recemment +secteurs
  141. $where = sql_in_select("id_rubrique", "id_rubrique", "spip_rubriques", "", "", "id_parent=0 DESC, date DESC", _CACHE_RUBRIQUES_MAX);
  142. // puis refaire la requete pour avoir l'ordre alphabetique
  143. $res = sql_select("id_rubrique, titre, id_parent", "spip_rubriques", $where, '', 'id_parent, 0+titre, titre');
  144. // il ne faut pas filtrer le autoriser voir ici
  145. // car on met le resultat en cache, commun a tout le monde
  146. $GLOBALS['db_art_cache'] = array();
  147. while ($r = sql_fetch($res)) {
  148. $t = sinon($r['titre'], _T('ecrire:info_sans_titre'));
  149. $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t));
  150. }
  151. $t = array($last ? $last : time(), $GLOBALS['db_art_cache']);
  152. ecrire_fichier(_CACHE_RUBRIQUES, serialize($t));
  153. return true;
  154. }
  155. ?>