[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
[3] | 27 | public function addItem($title,$url,$img,$active,$show=true,$id=null,$class=null) |
---|
[0] | 28 | { |
---|
| 29 | if($show) { |
---|
[3] | 30 | $this->items[] = $this->itemDef($title,$url,$img,$active,$id,$class); |
---|
[0] | 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
[3] | 34 | public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null) |
---|
[0] | 35 | { |
---|
| 36 | if ($show) { |
---|
[3] | 37 | array_unshift($this->items,$this->itemDef($title,$url,$img,$active,$id,$class)); |
---|
[0] | 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 | |
---|
[3] | 67 | protected function itemDef($title,$url,$img,$active,$id=null,$class=null) |
---|
[0] | 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 | |
---|
[691] | 77 | $img = dc_admin_icon_url($img); |
---|
| 78 | |
---|
[0] | 79 | return |
---|
[3] | 80 | '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : ''). |
---|
[0] | 81 | (($id) ? ' id="'.$id.'"' : ''). |
---|
| 82 | (($img) ? ' style="background-image: url('.$img.');"' : ''). |
---|
| 83 | '>'. |
---|
| 84 | |
---|
| 85 | '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n"; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | ?> |
---|