PageRenderTime 34ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/modules/mod_menu/menu.php

https://github.com/joebushi/joomla
PHP | 217 lines | 121 code | 28 blank | 68 comment | 28 complexity | ddeb6ec2d6df84c6cba2a5ade75935a0 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access
  8. defined('_JEXEC') or die;
  9. jimport('joomla.base.tree');
  10. /**
  11. * @package Joomla.Administrator
  12. * @subpackage mod_menu
  13. */
  14. class JAdminCssMenu extends JTree
  15. {
  16. /**
  17. * CSS string to add to document head
  18. * @var string
  19. */
  20. protected $_css = null;
  21. function __construct()
  22. {
  23. $this->_root = new JMenuNode('ROOT');
  24. $this->_current = & $this->_root;
  25. }
  26. function addSeparator()
  27. {
  28. $this->addChild(new JMenuNode(null, null, 'separator', false));
  29. }
  30. function renderMenu($id = 'menu', $class = '')
  31. {
  32. $depth = 1;
  33. if (!empty($id)) {
  34. $id='id="'.$id.'"';
  35. }
  36. if (!empty($class)) {
  37. $class='class="'.$class.'"';
  38. }
  39. /*
  40. * Recurse through children if they exist
  41. */
  42. while ($this->_current->hasChildren())
  43. {
  44. echo "<ul ".$id." ".$class.">\n";
  45. foreach ($this->_current->getChildren() as $child)
  46. {
  47. $this->_current = & $child;
  48. $this->renderLevel($depth++);
  49. }
  50. echo "</ul>\n";
  51. }
  52. if ($this->_css) {
  53. // Add style to document head
  54. $doc = & JFactory::getDocument();
  55. $doc->addStyleDeclaration($this->_css);
  56. }
  57. }
  58. function renderLevel($depth)
  59. {
  60. /*
  61. * Build the CSS class suffix
  62. */
  63. $class = '';
  64. if ($this->_current->hasChildren()) {
  65. $class = ' class="node"';
  66. }
  67. if ($this->_current->class == 'separator') {
  68. $class = ' class="separator"';
  69. }
  70. if ($this->_current->class == 'disabled') {
  71. $class = ' class="disabled"';
  72. }
  73. /*
  74. * Print the item
  75. */
  76. echo "<li".$class.">";
  77. /*
  78. * Print a link if it exists
  79. */
  80. if ($this->_current->link != null && $this->_current->target != null) {
  81. echo "<a class=\"".$this->getIconClass($this->_current->class)."\" href=\"".$this->_current->link."\" target=\"".$this->_current->target."\" >".$this->_current->title."</a>";
  82. } elseif ($this->_current->link != null && $this->_current->target == null) {
  83. echo "<a class=\"".$this->getIconClass($this->_current->class)."\" href=\"".$this->_current->link."\">".$this->_current->title."</a>";
  84. } elseif ($this->_current->title != null) {
  85. echo "<a>".$this->_current->title."</a>\n";
  86. } else {
  87. echo "<span></span>";
  88. }
  89. /*
  90. * Recurse through children if they exist
  91. */
  92. while ($this->_current->hasChildren())
  93. {
  94. if ($this->_current->class) {
  95. echo '<ul id="menu-'.strtolower($this->_current->id).'"'.
  96. ' class="menu-component">'."\n";
  97. } else {
  98. echo '<ul>'."\n";
  99. }
  100. foreach ($this->_current->getChildren() as $child)
  101. {
  102. $this->_current = & $child;
  103. $this->renderLevel($depth++);
  104. }
  105. echo "</ul>\n";
  106. }
  107. echo "</li>\n";
  108. }
  109. /**
  110. * Method to get the CSS class name for an icon identifier or create one if
  111. * a custom image path is passed as the identifier
  112. *
  113. * @access public
  114. * @param string $identifier Icon identification string
  115. * @return string CSS class name
  116. * @since 1.5
  117. */
  118. function getIconClass($identifier)
  119. {
  120. static $classes;
  121. // Initialise the known classes array if it does not exist
  122. if (!is_array($classes)) {
  123. $classes = array();
  124. }
  125. /*
  126. * If we don't already know about the class... build it and mark it
  127. * known so we don't have to build it again
  128. */
  129. if (!isset($classes[$identifier])) {
  130. if (substr($identifier, 0, 6) == 'class:') {
  131. // We were passed a class name
  132. $class = substr($identifier, 6);
  133. $classes[$identifier] = "icon-16-$class";
  134. } else {
  135. if ($identifier == null) {
  136. return null;
  137. }
  138. // Build the CSS class for the icon
  139. $class = preg_replace('#\.[^.]*$#', '', basename($identifier));
  140. $class = preg_replace('#\.\.[^A-Za-z0-9\.\_\- ]#', '', $class);
  141. $this->_css .= "\n.icon-16-$class {\n" .
  142. "\tbackground: url($identifier) no-repeat;\n" .
  143. "}\n";
  144. $classes[$identifier] = "icon-16-$class";
  145. }
  146. }
  147. return $classes[$identifier];
  148. }
  149. }
  150. /**
  151. * @package Joomla.Administrator
  152. * @subpackage mod_menu
  153. */
  154. class JMenuNode extends JNode
  155. {
  156. /**
  157. * Node Title
  158. */
  159. public $title = null;
  160. /**
  161. * Node Id
  162. */
  163. public $id = null;
  164. /**
  165. * Node Link
  166. */
  167. public $link = null;
  168. /**
  169. * Link Target
  170. */
  171. public $target = null;
  172. /**
  173. * CSS Class for node
  174. */
  175. public $class = null;
  176. /**
  177. * Active Node?
  178. */
  179. public $active = false;
  180. public function __construct($title, $link = null, $class = null, $active = false, $target = null)
  181. {
  182. $this->title = $title;
  183. $this->link = JFilterOutput::ampReplace($link);
  184. $this->class = $class;
  185. $this->active = $active;
  186. $this->id = str_replace(" ","-",$title);
  187. $this->target = $target;
  188. }
  189. }