| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2011 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 $items; |
|---|
| 17 | private $id; |
|---|
| 18 | public $title; |
|---|
| 19 | public $separator; |
|---|
| 20 | |
|---|
| 21 | public function __construct($id,$title,$separator='') |
|---|
| 22 | { |
|---|
| 23 | $this->id = $id; |
|---|
| 24 | $this->title = $title; |
|---|
| 25 | $this->separator = $separator; |
|---|
| 26 | $this->items = array(); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | public function getID() |
|---|
| 30 | { |
|---|
| 31 | return $this->id; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public function getTitle() |
|---|
| 35 | { |
|---|
| 36 | return $this->title; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | public function getSeparator() |
|---|
| 40 | { |
|---|
| 41 | return $this->separator; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public function getItems() |
|---|
| 45 | { |
|---|
| 46 | return $this->items; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public function addItem($title,$url,$img,$active,$show=true,$id=null,$class=null) |
|---|
| 50 | { |
|---|
| 51 | if($show) { |
|---|
| 52 | $this->items[] = $this->itemDef($title,$url,$img,$active,$id,$class); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null) |
|---|
| 57 | { |
|---|
| 58 | if ($show) { |
|---|
| 59 | array_unshift($this->items,$this->itemDef($title,$url,$img,$active,$id,$class)); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | protected function itemDef($title,$url,$img,$active,$id=null,$class=null) |
|---|
| 64 | { |
|---|
| 65 | if (is_array($url)) { |
|---|
| 66 | $link = $url[0]; |
|---|
| 67 | $ahtml = (!empty($url[1])) ? ' '.$url[1] : ''; |
|---|
| 68 | } else { |
|---|
| 69 | $link = $url; |
|---|
| 70 | $ahtml = ''; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return array( |
|---|
| 74 | 'title' => $title, |
|---|
| 75 | 'link' => $link, |
|---|
| 76 | 'ahtml' => $ahtml, |
|---|
| 77 | 'img' => dc_admin_icon_url($img), |
|---|
| 78 | 'active' => (boolean) $active, |
|---|
| 79 | 'id' => $id, |
|---|
| 80 | 'class' => $class |
|---|
| 81 | ); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | @deprecated Use Template engine instead |
|---|
| 86 | */ |
|---|
| 87 | public function draw() |
|---|
| 88 | { |
|---|
| 89 | if (count($this->items) == 0) { |
|---|
| 90 | return ''; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | $res = |
|---|
| 94 | '<div id="'.$this->id.'">'. |
|---|
| 95 | ($this->title ? '<h3>'.$this->title.'</h3>' : ''). |
|---|
| 96 | '<ul>'."\n"; |
|---|
| 97 | |
|---|
| 98 | for ($i=0; $i<count($this->items); $i++) |
|---|
| 99 | { |
|---|
| 100 | if ($i+1 < count($this->items) && $this->separator != '') { |
|---|
| 101 | $res .= preg_replace('|</li>$|',$this->separator.'</li>',$this->drawItem($this->items[$i])); |
|---|
| 102 | $res .= "\n"; |
|---|
| 103 | } else { |
|---|
| 104 | $res .= $this->drawItem($this->items[$i])."\n"; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | $res .= '</ul></div>'."\n"; |
|---|
| 109 | |
|---|
| 110 | return $res; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | @deprecated Use Template engine instead |
|---|
| 115 | */ |
|---|
| 116 | protected function drawItem($item) |
|---|
| 117 | { |
|---|
| 118 | return |
|---|
| 119 | '<li'.(($item['active'] || $item['class']) ? ' class="'.(($item['active']) ? 'active ' : '').(($item['class']) ? $item['class'] : '').'"' : ''). |
|---|
| 120 | (($item['id']) ? ' id="'.$item['id'].'"' : ''). |
|---|
| 121 | (($item['img']) ? ' style="background-image: url('.$item['img'].');"' : ''). |
|---|
| 122 | '>'. |
|---|
| 123 | |
|---|
| 124 | '<a href="'.$item['link'].'"'.$item['ahtml'].'>'.$item['title'].'</a></li>'."\n"; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | ?> |
|---|