Dotclear

Changeset 1064:0c887ef58692


Ignore:
Timestamp:
12/13/12 08:48:15 (13 years ago)
Author:
JcDenis
Branch:
twig
Message:
  • dcMenu is now "Twig compliant"
Location:
inc/admin
Files:
3 edited

Legend:

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

    r1061 r1064  
    117117     { 
    118118          return array( 
    119                '__'           => new Twig_Function_Function("__", array('is_safe' => array('html'))), 
    120                'page_menu' => new Twig_Function_Method($this, 'pageMenu', array('is_safe' => array('html'))) 
     119               '__'           => new Twig_Function_Function("__", array('is_safe' => array('html'))) 
     120               //,'page_menu' => new Twig_Function_Method($this, 'pageMenu', array('is_safe' => array('html'))) 
    121121          ); 
    122122     } 
     
    134134          $this->getCurrentBlog(); 
    135135          $this->getCurrentUser(); 
     136          $this->getMenus(); 
    136137           
    137138          # Additional globals 
     
    200201     { 
    201202          $this->protected_globals['page_title'] = $title; 
    202      } 
    203       
    204      /** 
    205      pageMenu 
    206      */ 
    207      public function pageMenu() 
    208      { 
    209           $menu =& $GLOBALS['_menu']; 
    210           foreach ($menu as $k => $v) { 
    211                echo $menu[$k]->draw(); 
    212           } 
    213203     } 
    214204      
     
    308298               ); 
    309299     } 
     300      
     301     protected function getMenus() 
     302     { 
     303          global $_menu; 
     304           
     305          $this->protected_globals['menus'] = array(); 
     306           
     307          if (!isset($_menu)) { 
     308               return; 
     309          } 
     310           
     311          foreach($_menu as $m) { 
     312               $this->protected_globals['menus'][] = array( 
     313                    'id'           => $m->getID(), 
     314                    'title'        => $m->getTitle(), 
     315                    'separator'    => $m->getSeparator(), 
     316                    'items'        => $m->getItems() 
     317               ); 
     318          } 
     319     } 
    310320} 
    311321?> 
  • inc/admin/class.dc.menu.php

    r691 r1064  
    1414class dcMenu 
    1515{ 
     16     private $items; 
    1617     private $id; 
    1718     public $title; 
     19     public $separator; 
    1820      
    19      public function __construct($id,$title,$itemSpace='') 
     21     public function __construct($id,$title,$separator='') 
    2022     { 
    2123          $this->id = $id; 
    2224          $this->title = $title; 
    23           $this->itemSpace = $itemSpace; 
     25          $this->separator = $separator; 
    2426          $this->items = array(); 
     27     } 
     28      
     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; 
    2547     } 
    2648      
     
    3961     } 
    4062      
     63     protected function itemDef($title,$url,$img,$active,$id=null,$class=null) 
     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          } 
     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     */ 
    4187     public function draw() 
    4288     { 
     
    5298          for ($i=0; $i<count($this->items); $i++) 
    5399          { 
    54                if ($i+1 < count($this->items) && $this->itemSpace != '') { 
    55                     $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->items[$i]); 
     100               if ($i+1 < count($this->items) && $this->separator != '') { 
     101                    $res .= preg_replace('|</li>$|',$this->separator.'</li>',$this->drawItem($this->items[$i])); 
    56102                    $res .= "\n"; 
    57103               } else { 
    58                     $res .= $this->items[$i]."\n"; 
     104                    $res .= $this->drawItem($this->items[$i])."\n"; 
    59105               } 
    60106          } 
     
    65111     } 
    66112      
    67      protected function itemDef($title,$url,$img,$active,$id=null,$class=null) 
     113     /** 
     114     @deprecated Use Template engine instead 
     115     */ 
     116     protected function drawItem($item) 
    68117     { 
    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            
    79118          return 
    80           '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : ''). 
    81           (($id) ? ' id="'.$id.'"' : ''). 
    82           (($img) ? ' style="background-image: url('.$img.');"' : ''). 
     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'].');"' : ''). 
    83122          '>'. 
    84123           
    85           '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n"; 
     124          '<a href="'.$item['link'].'"'.$item['ahtml'].'>'.$item['title'].'</a></li>'."\n"; 
    86125     } 
    87126} 
  • inc/admin/default-templates/layout.html.twig

    r1060 r1064  
    6868          </div> 
    6969          <div id="main-menu"> 
    70                {{ page_menu() }} 
     70               {% block menus %} 
     71               {% for menu in menus %} 
     72               {% if menu.items is not empty %} 
     73               <div id="{{menu.id}}"> 
     74                    {% if menu.title is not empty %}<h3>{{menu.title}}</h3>{% endif %} 
     75                    <ul> 
     76                    {% for item in menu.items %} 
     77                    {% spaceless %} 
     78                    <li {% if item.active or item.class is not empty %} class="{% if item.active %}active {% endif %}{{item.class}}"{% endif %} 
     79                    {% if item.id is not empty %}id="{{item.id}}" {% endif %} 
     80                    {% if item.img is not empty %} style="background-image: url({{item.img}});"{% endif %} 
     81                    ><a href="{{item.link}}"{{item.ahtml}}>{{item.title}}</a> 
     82                    {% if loop.last %}{{menu.separator}}{% endif %}</li> 
     83                    {% endspaceless %} 
     84                    {% endfor %} 
     85                    </ul> 
     86               </div> 
     87               {% endif %} 
     88               {% endfor %} 
     89               {% endblock %} 
    7190          </div> 
    7291          <div id="footer"> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map