Changeset 3730:5c45a5df9a59 for inc/admin/class.dc.menu.php
- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/class.dc.menu.php
r3075 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcMenu 15 15 { 16 17 16 private $id; 17 public $title; 18 18 19 public function __construct($id,$title,$itemSpace='')20 21 $this->id= $id;22 $this->title= $title;23 24 $this->pinned= array();25 $this->items= array();26 19 public function __construct($id, $title, $itemSpace = '') 20 { 21 $this->id = $id; 22 $this->title = $title; 23 $this->itemSpace = $itemSpace; 24 $this->pinned = array(); 25 $this->items = array(); 26 } 27 27 28 public function addItem($title,$url,$img,$active,$show=true,$id=null,$class=null,$pinned=false)29 30 if($show) {31 $item = $this->itemDef($title,$url,$img,$active,$id,$class);32 33 34 35 36 37 38 28 public function addItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false) 29 { 30 if ($show) { 31 $item = $this->itemDef($title, $url, $img, $active, $id, $class); 32 if ($pinned) { 33 $this->pinned[] = $item; 34 } else { 35 $this->items[$title] = $item; 36 } 37 } 38 } 39 39 40 public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null,$pinned=false)41 42 43 $item = $this->itemDef($title,$url,$img,$active,$id,$class);44 45 array_unshift($this->pinned,$item);46 47 48 49 50 40 public function prependItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false) 41 { 42 if ($show) { 43 $item = $this->itemDef($title, $url, $img, $active, $id, $class); 44 if ($pinned) { 45 array_unshift($this->pinned, $item); 46 } else { 47 $this->items[$title] = $item; 48 } 49 } 50 } 51 51 52 53 54 55 56 52 public function draw() 53 { 54 if (count($this->items) + count($this->pinned) == 0) { 55 return ''; 56 } 57 57 58 59 '<div id="'.$this->id.'">'.60 ($this->title ? '<h3>'.$this->title.'</h3>' : '').61 '<ul>'."\n";58 $res = 59 '<div id="' . $this->id . '">' . 60 ($this->title ? '<h3>' . $this->title . '</h3>' : '') . 61 '<ul>' . "\n"; 62 62 63 // 1. Display pinned items (unsorted) 64 for ($i=0; $i<count($this->pinned); $i++) 65 { 66 if ($i+1 < count($this->pinned) && $this->itemSpace != '') { 67 $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->pinned[$i]); 68 $res .= "\n"; 69 } else { 70 $res .= $this->pinned[$i]."\n"; 71 } 72 } 63 // 1. Display pinned items (unsorted) 64 for ($i = 0; $i < count($this->pinned); $i++) { 65 if ($i + 1 < count($this->pinned) && $this->itemSpace != '') { 66 $res .= preg_replace('|</li>$|', $this->itemSpace . '</li>', $this->pinned[$i]); 67 $res .= "\n"; 68 } else { 69 $res .= $this->pinned[$i] . "\n"; 70 } 71 } 73 72 74 // 2. Display unpinned itmes (sorted) 75 $i = 0; 76 dcUtils::lexicalKeySort($this->items); 77 foreach ($this->items as $title => $item) 78 { 79 if ($i+1 < count($this->items) && $this->itemSpace != '') { 80 $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$item); 81 $res .= "\n"; 82 } else { 83 $res .= $item."\n"; 84 } 85 $i++; 86 } 73 // 2. Display unpinned itmes (sorted) 74 $i = 0; 75 dcUtils::lexicalKeySort($this->items); 76 foreach ($this->items as $title => $item) { 77 if ($i + 1 < count($this->items) && $this->itemSpace != '') { 78 $res .= preg_replace('|</li>$|', $this->itemSpace . '</li>', $item); 79 $res .= "\n"; 80 } else { 81 $res .= $item . "\n"; 82 } 83 $i++; 84 } 87 85 88 $res .= '</ul></div>'."\n";86 $res .= '</ul></div>' . "\n"; 89 87 90 91 88 return $res; 89 } 92 90 93 protected function itemDef($title,$url,$img,$active,$id=null,$class=null)94 95 96 $link= $url[0];97 $ahtml = (!empty($url[1])) ? ' '.$url[1] : '';98 99 $link= $url;100 101 91 protected function itemDef($title, $url, $img, $active, $id = null, $class = null) 92 { 93 if (is_array($url)) { 94 $link = $url[0]; 95 $ahtml = (!empty($url[1])) ? ' ' . $url[1] : ''; 96 } else { 97 $link = $url; 98 $ahtml = ''; 99 } 102 100 103 101 $img = dc_admin_icon_url($img); 104 102 105 106 '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : '').107 (($id) ? ' id="'.$id.'"' : '').108 (($img) ? ' style="background-image: url('.$img.');"' : '').109 '>'.103 return 104 '<li' . (($active || $class) ? ' class="' . (($active) ? 'active ' : '') . (($class) ? $class : '') . '"' : '') . 105 (($id) ? ' id="' . $id . '"' : '') . 106 (($img) ? ' style="background-image: url(' . $img . ');"' : '') . 107 '>' . 110 108 111 '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n";112 109 '<a href="' . $link . '"' . $ahtml . '>' . $title . '</a></li>' . "\n"; 110 } 113 111 }
Note: See TracChangeset
for help on using the changeset viewer.