Dotclear

source: inc/admin/class.dc.menu.php @ 2593:6741802596a0

Revision 2593:6741802596a0, 2.7 KB checked in by Dsls, 12 years ago (diff)

Fusion avec default

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[691]6# Copyright (c) 2003-2011 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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcMenu
15{
[1064]16     private $items;
[0]17     private $id;
18     public $title;
[1064]19     public $separator;
[1179]20     
[1064]21     public function __construct($id,$title,$separator='')
[0]22     {
23          $this->id = $id;
24          $this->title = $title;
[1064]25          $this->separator = $separator;
[0]26          $this->items = array();
27     }
[1179]28     
[1064]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     
[3]49     public function addItem($title,$url,$img,$active,$show=true,$id=null,$class=null)
[0]50     {
51          if($show) {
[3]52               $this->items[] = $this->itemDef($title,$url,$img,$active,$id,$class);
[0]53          }
54     }
[1179]55     
[3]56     public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null)
[0]57     {
58          if ($show) {
[3]59               array_unshift($this->items,$this->itemDef($title,$url,$img,$active,$id,$class));
[0]60          }
61     }
[1179]62     
[3]63     protected function itemDef($title,$url,$img,$active,$id=null,$class=null)
[0]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          }
[1064]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     */
[1179]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          {
[1064]100               if ($i+1 < count($this->items) && $this->separator != '') {
101                    $res .= preg_replace('|</li>$|',$this->separator.'</li>',$this->drawItem($this->items[$i]));
[1179]102                    $res .= "\n";
103               } else {
[1064]104                    $res .= $this->drawItem($this->items[$i])."\n";
[1179]105               }
106          }
107         
108          $res .= '</ul></div>'."\n";
109         
110          return $res;
111     }
112     
[1064]113     /**
114     @deprecated Use Template engine instead
115     */
116     protected function drawItem($item)
[1179]117     {
[0]118          return
[1064]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'].');"' : '').
[0]122          '>'.
[1179]123         
[1064]124          '<a href="'.$item['link'].'"'.$item['ahtml'].'>'.$item['title'].'</a></li>'."\n";
[0]125     }
126}
[1179]127?>
Note: See TracBrowser for help on using the repository browser.

Sites map