PageRenderTime 82ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/aamenu/code/trunk/administrator/modules/mod_aamenu/menu.php

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