[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/modules/mod_menu/ -> menu.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: menu.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6   * @license        GNU/GPL, see LICENSE.php
   7   * Joomla! is free software. This version may have been modified pursuant to the
   8   * GNU General Public License, and as distributed it includes or is derivative
   9   * of works licensed under the GNU General Public License or other free or open
  10   * source software licenses. See COPYRIGHT.php for copyright notices and
  11   * details.
  12   */
  13  
  14  // Check to ensure this file is included in Joomla!
  15  defined('_JEXEC') or die( 'Restricted access' );
  16  
  17  jimport('joomla.base.tree');
  18  
  19  class JAdminCSSMenu extends JTree
  20  {
  21      /**
  22       * CSS string to add to document head
  23       * @var string
  24       */
  25      var $_css = null;
  26  
  27  	function __construct()
  28      {
  29          $this->_root = new JMenuNode('ROOT');
  30          $this->_current = & $this->_root;
  31      }
  32  
  33  	function addSeparator()
  34      {
  35          $this->addChild(new JMenuNode(null, null, 'separator', false));
  36      }
  37  
  38  	function renderMenu($id = 'menu', $class = '')
  39      {
  40          global $mainframe;
  41  
  42          $depth = 1;
  43  
  44          if(!empty($id)) {
  45              $id='id="'.$id.'"';
  46          }
  47  
  48          if(!empty($class)) {
  49              $class='class="'.$class.'"';
  50          }
  51  
  52          /*
  53           * Recurse through children if they exist
  54           */
  55          while ($this->_current->hasChildren())
  56          {
  57              echo "<ul ".$id." ".$class.">\n";
  58              foreach ($this->_current->getChildren() as $child)
  59              {
  60                  $this->_current = & $child;
  61                  $this->renderLevel($depth++);
  62              }
  63              echo "</ul>\n";
  64          }
  65  
  66          if ($this->_css) {
  67              // Add style to document head
  68              $doc = & JFactory::getDocument();
  69              $doc->addStyleDeclaration($this->_css);
  70          }
  71      }
  72  
  73  	function renderLevel($depth)
  74      {
  75          /*
  76           * Build the CSS class suffix
  77           */
  78          $class = '';
  79          if ($this->_current->hasChildren()) {
  80              $class = ' class="node"';
  81          }
  82  
  83          if($this->_current->class == 'separator') {
  84              $class = ' class="separator"';
  85          }
  86  
  87          if($this->_current->class == 'disabled') {
  88              $class = ' class="disabled"';
  89          }
  90  
  91  
  92          /*
  93           * Print the item
  94           */
  95          echo "<li".$class.">";
  96  
  97          /*
  98           * Print a link if it exists
  99           */
 100          if ($this->_current->link != null) {
 101              echo "<a class=\"".$this->getIconClass($this->_current->class)."\" href=\"".$this->_current->link."\">".$this->_current->title."</a>";
 102          } elseif ($this->_current->title != null) {
 103              echo "<a>".$this->_current->title."</a>\n";
 104          } else {
 105              echo "<span></span>";
 106          }
 107  
 108          /*
 109           * Recurse through children if they exist
 110           */
 111          while ($this->_current->hasChildren())
 112          {
 113              if ($this->_current->class) {
 114                  echo '<ul id="menu-'.strtolower($this->_current->id).'"'.
 115                      ' class="menu-component">'."\n";
 116              } else {
 117                  echo '<ul>'."\n";
 118              }
 119              foreach ($this->_current->getChildren() as $child)
 120              {
 121                  $this->_current = & $child;
 122                  $this->renderLevel($depth++);
 123              }
 124              echo "</ul>\n";
 125          }
 126          echo "</li>\n";
 127      }
 128  
 129      /**
 130       * Method to get the CSS class name for an icon identifier or create one if
 131       * a custom image path is passed as the identifier
 132       *
 133       * @access    public
 134       * @param    string    $identifier    Icon identification string
 135       * @return    string    CSS class name
 136       * @since    1.5
 137       */
 138  	function getIconClass($identifier)
 139      {
 140          global $mainframe;
 141  
 142          static $classes;
 143  
 144          // Initialize the known classes array if it does not exist
 145          if (!is_array($classes)) {
 146              $classes = array();
 147          }
 148  
 149          /*
 150           * If we don't already know about the class... build it and mark it
 151           * known so we don't have to build it again
 152           */
 153          if (!isset($classes[$identifier])) {
 154              if (substr($identifier, 0, 6) == 'class:') {
 155                  // We were passed a class name
 156                  $class = substr($identifier, 6);
 157                  $classes[$identifier] = "icon-16-$class";
 158              } else {
 159                  // We were passed an image path... is it a themeoffice one?
 160                  if (substr($identifier, 0, 15) == 'js/ThemeOffice/') {
 161                      // Strip the filename without extension and use that for the classname
 162                      $class = preg_replace('#\.[^.]*$#', '', basename($identifier));
 163                      $classes[$identifier] = "icon-16-$class";
 164                  } else {
 165                      if ($identifier == null) {
 166                          return null;
 167                      }
 168                      // Build the CSS class for the icon
 169                      $class = preg_replace('#\.[^.]*$#', '', basename($identifier));
 170                      $class = preg_replace( '#\.\.[^A-Za-z0-9\.\_\- ]#', '', $class);
 171  
 172                      $this->_css  .= "\n.icon-16-$class {\n" .
 173                              "\tbackground: url($identifier) no-repeat;\n" .
 174                              "}\n";
 175  
 176                      $classes[$identifier] = "icon-16-$class";
 177                  }
 178              }
 179          }
 180          return $classes[$identifier];
 181      }
 182  }
 183  
 184  class JMenuNode extends JNode
 185  {
 186      /**
 187       * Node Title
 188       */
 189      var $title = null;
 190  
 191      /**
 192       * Node Id
 193       */
 194      var $id = null;
 195  
 196  
 197      /**
 198       * Node Link
 199       */
 200      var $link = null;
 201  
 202      /**
 203       * CSS Class for node
 204       */
 205      var $class = null;
 206  
 207      /**
 208       * Active Node?
 209       */
 210      var $active = false;
 211  
 212  
 213  	function __construct($title, $link = null, $class = null, $active = false)
 214      {
 215          $this->title    = $title;
 216          $this->link        = JFilterOutput::ampReplace($link);
 217          $this->class    = $class;
 218          $this->active    = $active;
 219          $this->id        = str_replace(" ","-",$title);
 220  
 221      }
 222  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1