| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear |
|---|
| 7 | # Licensed under the GPL version 2.0 license. |
|---|
| 8 | # See LICENSE file or |
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 10 | # |
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
|---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
|---|
| 13 | |
|---|
| 14 | class dcMenu |
|---|
| 15 | { |
|---|
| 16 | private $id; |
|---|
| 17 | public $title; |
|---|
| 18 | |
|---|
| 19 | public function __construct($id,$title,$itemSpace='') |
|---|
| 20 | { |
|---|
| 21 | $this->id = $id; |
|---|
| 22 | $this->title = $title; |
|---|
| 23 | $this->itemSpace = $itemSpace; |
|---|
| 24 | $this->items = array(); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | public function addItem($title,$url,$img,$active,$show=true,$id=null) |
|---|
| 28 | { |
|---|
| 29 | if($show) { |
|---|
| 30 | $this->items[] = $this->itemDef($title,$url,$img,$active,$id); |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public function prependItem($title,$url,$img,$active,$show=true,$id=null) |
|---|
| 35 | { |
|---|
| 36 | if ($show) { |
|---|
| 37 | array_unshift($this->items,$this->itemDef($title,$url,$img,$active,$id)); |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public function draw() |
|---|
| 42 | { |
|---|
| 43 | if (count($this->items) == 0) { |
|---|
| 44 | return ''; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | $res = |
|---|
| 48 | '<div id="'.$this->id.'">'. |
|---|
| 49 | ($this->title ? '<h3>'.$this->title.'</h3>' : ''). |
|---|
| 50 | '<ul>'."\n"; |
|---|
| 51 | |
|---|
| 52 | for ($i=0; $i<count($this->items); $i++) |
|---|
| 53 | { |
|---|
| 54 | if ($i+1 < count($this->items) && $this->itemSpace != '') { |
|---|
| 55 | $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->items[$i]); |
|---|
| 56 | $res .= "\n"; |
|---|
| 57 | } else { |
|---|
| 58 | $res .= $this->items[$i]."\n"; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | $res .= '</ul></div>'."\n"; |
|---|
| 63 | |
|---|
| 64 | return $res; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | protected function itemDef($title,$url,$img,$active,$id=null) |
|---|
| 68 | { |
|---|
| 69 | if (is_array($url)) { |
|---|
| 70 | $link = $url[0]; |
|---|
| 71 | $ahtml = (!empty($url[1])) ? ' '.$url[1] : ''; |
|---|
| 72 | } else { |
|---|
| 73 | $link = $url; |
|---|
| 74 | $ahtml = ''; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | return |
|---|
| 78 | '<li'.(($active) ? ' class="active"' : ''). |
|---|
| 79 | (($id) ? ' id="'.$id.'"' : ''). |
|---|
| 80 | (($img) ? ' style="background-image: url('.$img.');"' : ''). |
|---|
| 81 | '>'. |
|---|
| 82 | |
|---|
| 83 | '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n"; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | ?> |
|---|