class.menu.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. /*
  23. Classe Menu
  24. */
  25. class menu
  26. {
  27. function menu($id,$imgSpace='',$itemSpace='')
  28. {
  29. $this->id = $id;
  30. $this->imgSpace = $imgSpace;
  31. $this->itemSpace = $itemSpace;
  32. $this->items = array();
  33. }
  34. function addItem($title,$url,$img,$active,$show=true,$id=NULL)
  35. {
  36. if($show)
  37. {
  38. if (is_array($url)) {
  39. $link = $url[0];
  40. $ahtml = (!empty($url[1])) ? ' '.$url[1] : '';
  41. } else {
  42. $link = $url;
  43. $ahtml = '';
  44. }
  45. $this->items[] =
  46. '<li'.(($active) ? ' class="actif"' : '').
  47. (($id) ? ' id="'.$id.'"' : '').
  48. '>'.
  49. (($img) ? '<img src="'.$img.'" alt="" />'.$this->imgSpace : '').
  50. '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n";
  51. }
  52. }
  53. function draw()
  54. {
  55. $res = '<ul id="'.$this->id.'">'."\n";
  56. if (count($this->items) > 0) {
  57. for ($i=0; $i<count($this->items); $i++)
  58. {
  59. if ($i+1 < count($this->items) && $this->itemSpace != '') {
  60. $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->items[$i]);
  61. $res .= "\n";
  62. } else {
  63. $res .= $this->items[$i]."\n";
  64. }
  65. }
  66. } else {
  67. $res .= '<li>&nbsp;</li>';
  68. }
  69. $res .= '</ul>'."\n";
  70. return $res;
  71. }
  72. }
  73. ?>