| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2013 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,$class=null) | 
|---|
| 28 | { | 
|---|
| 29 | if($show) { | 
|---|
| 30 | $this->items[] = $this->itemDef($title,$url,$img,$active,$id,$class); | 
|---|
| 31 | } | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null) | 
|---|
| 35 | { | 
|---|
| 36 | if ($show) { | 
|---|
| 37 | array_unshift($this->items,$this->itemDef($title,$url,$img,$active,$id,$class)); | 
|---|
| 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,$class=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 | $img = dc_admin_icon_url($img); | 
|---|
| 78 |  | 
|---|
| 79 | return | 
|---|
| 80 | '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : ''). | 
|---|
| 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 | ?> | 
|---|