[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/extinc/ -> class.menu.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # Version: MPL 1.1/GPL 2.0/LGPL 2.1
   6  #
   7  # The contents of this file are subject to the Mozilla Public License Version
   8  # 1.1 (the "License"); you may not use this file except in compliance with
   9  # the License. You may obtain a copy of the License at
  10  # http://www.mozilla.org/MPL/
  11  #
  12  # Software distributed under the License is distributed on an "AS IS" basis,
  13  # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14  # for the specific language governing rights and limitations under the
  15  # License.
  16  #
  17  # The Original Code is DotClear Weblog.
  18  #
  19  # The Initial Developer of the Original Code is
  20  # Olivier Meunier.
  21  # Portions created by the Initial Developer are Copyright (C) 2003
  22  # the Initial Developer. All Rights Reserved.
  23  #
  24  # Contributor(s):
  25  #  Loïc d'Anterroches - Add accesskey and first/last class support
  26  #
  27  # Alternatively, the contents of this file may be used under the terms of
  28  # either the GNU General Public License Version 2 or later (the "GPL"), or
  29  # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30  # in which case the provisions of the GPL or the LGPL are applicable instead
  31  # of those above. If you wish to allow use of your version of this file only
  32  # under the terms of either the GPL or the LGPL, and not to allow others to
  33  # use your version of this file under the terms of the MPL, indicate your
  34  # decision by deleting the provisions above and replace them with the notice
  35  # and other provisions required by the GPL or the LGPL. If you do not delete
  36  # the provisions above, a recipient may use your version of this file under
  37  # the terms of any one of the MPL, the GPL or the LGPL.
  38  #
  39  # ***** END LICENSE BLOCK ***** */
  40  
  41  /**
  42   * Classe Menu
  43   */
  44  
  45  class menu
  46  {
  47      /**
  48       * Constructor
  49       *
  50       * @param string Id of the menu
  51       * @param string Character to put after the image tag of the menu item
  52       * @param string Character to put just before the </li> in the list
  53       */
  54      function menu($id, $imgSpace='', $itemSpace='')
  55      {
  56          $this->id = $id;
  57          $this->imgSpace = $imgSpace;
  58          $this->itemSpace = $itemSpace;
  59          $this->items = array();
  60      }
  61      
  62      /**
  63       * Add a new item to the menu
  64       *
  65       * @param string Title of the menu link
  66       * @param string Url for the link
  67       * @param string Url of the link image
  68       * @param bool Active to get the "active" class set
  69       * @param bool Show the item (true)
  70       * @param string Accesskey for the item ('')
  71       */
  72      function addItem($title, $url, $img, $active, $show=true, $accesskey='')
  73      {
  74          if($show) {
  75              if (is_array($url)) {
  76                  $link = $url[0];
  77                  $ahtml = (!empty($url[1])) ? ' '.$url[1] : '';
  78              } else {
  79                  $link = $url;
  80                  $ahtml = '';
  81              }
  82              if (strlen($accesskey) == 1) {
  83                  $title2 = preg_replace('/('.$accesskey.')/i', '<u>\1</u>', $title, 1);
  84                  if ($title2 == $title) {
  85                      $title = $title.' <span class="accesskey">['.$accesskey.']</span>';
  86                  } else {
  87                      $title = $title2;
  88                  }
  89                  $ahtml = ' accesskey="'.$accesskey.'"';
  90              }
  91              $this->items[] =
  92                  '<li'.(($active) ? ' class="active"' : ' class=""').'>'.
  93                  (($img) ? '<img src="'.$img.'" alt="" />'.$this->imgSpace : '').
  94                  '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n";
  95          }
  96      }
  97  
  98      /**
  99       * Returns the HTML code of the menu.
 100       *
 101       * @return string HTML code
 102       */
 103      function draw()
 104      {
 105          $res = '<ul id="'.$this->id.'">'."\n";
 106          $count = count($this->items);
 107          if ($count > 0) {
 108              for ($i=0; $i<$count; $i++) {
 109                  if (0 == $i) {
 110                      $this->items[$i] = preg_replace('|class="active"|', 'class="active first"', $this->items[$i]);
 111                      $this->items[$i] = preg_replace('|class=""|', 'class="first"', $this->items[$i]);
 112                  }
 113                  if ($i+1 == $count) {
 114                      $this->items[$i] = preg_replace('|class="active"|', 'class="active last"', $this->items[$i]);
 115                      $this->items[$i] = preg_replace('|class=""|', 'class="last"', $this->items[$i]);
 116                  }
 117                  if ($i+1 < $count && $this->itemSpace != '') {
 118                      $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->items[$i]);
 119                      $res .= "\n";
 120                  } else {
 121                      $res .= $this->items[$i]."\n";
 122                  }
 123              }
 124          } else {
 125              $res .= '<li>&nbsp;</li>';
 126          }
 127          
 128          $res .= '</ul>'."\n";
 129          $res = preg_replace('|class=""|', '', $res);
 130          
 131          return $res;
 132      }
 133  }
 134  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics