Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.menu.php

    r3075 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcMenu 
    1515{ 
    16      private $id; 
    17      public $title; 
     16    private $id; 
     17    public $title; 
    1818 
    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      } 
     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    } 
    2727 
    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      } 
     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    } 
    3939 
    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      } 
     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    } 
    5151 
    52      public function draw() 
    53      { 
    54           if (count($this->items) + count($this->pinned) == 0) { 
    55                return ''; 
    56           } 
     52    public function draw() 
     53    { 
     54        if (count($this->items) + count($this->pinned) == 0) { 
     55            return ''; 
     56        } 
    5757 
    58           $res = 
    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"; 
    6262 
    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        } 
    7372 
    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        } 
    8785 
    88           $res .= '</ul></div>'."\n"; 
     86        $res .= '</ul></div>' . "\n"; 
    8987 
    90           return $res; 
    91      } 
     88        return $res; 
     89    } 
    9290 
    93      protected function itemDef($title,$url,$img,$active,$id=null,$class=null) 
    94      { 
    95           if (is_array($url)) { 
    96                $link = $url[0]; 
    97                $ahtml = (!empty($url[1])) ? ' '.$url[1] : ''; 
    98           } else { 
    99                $link = $url; 
    100                $ahtml = ''; 
    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        } 
    102100 
    103           $img = dc_admin_icon_url($img); 
     101        $img = dc_admin_icon_url($img); 
    104102 
    105           return 
    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            '>' . 
    110108 
    111           '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n"; 
    112      } 
     109            '<a href="' . $link . '"' . $ahtml . '>' . $title . '</a></li>' . "\n"; 
     110    } 
    113111} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map