Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Catalog_Block_Seo_Sitemap_Tree_Pager
  • Mage_Page_Block_Html
  • Mage_Page_Block_Html_Breadcrumbs
  • Mage_Page_Block_Html_Footer
  • Mage_Page_Block_Html_Head
  • Mage_Page_Block_Html_Header
  • Mage_Page_Block_Html_Notices
  • Mage_Page_Block_Html_Pager
  • Mage_Page_Block_Html_Topmenu
  • Mage_Page_Block_Html_Welcome
  • Mage_Page_Block_Html_Wrapper
  • Mage_Page_Block_Js_Cookie
  • Mage_Page_Block_Redirect
  • Mage_Page_Helper_Data
  • Mage_Page_Helper_Html
  • Mage_Page_Helper_Layout
  • Mage_Page_Model_Config
  • Mage_Page_Model_Source_Layout
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Page
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Top menu block
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Page
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Page_Block_Html_Topmenu extends Mage_Core_Block_Template
 35: {
 36:     /**
 37:      * Top menu data tree
 38:      *
 39:      * @var Varien_Data_Tree_Node
 40:      */
 41:     protected $_menu;
 42: 
 43:     /**
 44:      * Init top menu tree structure
 45:      */
 46:     public function _construct()
 47:     {
 48:         $this->_menu = new Varien_Data_Tree_Node(array(), 'root', new Varien_Data_Tree());
 49:     }
 50: 
 51:     /**
 52:      * Get top menu html
 53:      *
 54:      * @param string $outermostClass
 55:      * @param string $childrenWrapClass
 56:      * @return string
 57:      */
 58:     public function getHtml($outermostClass = '', $childrenWrapClass = '')
 59:     {
 60:         Mage::dispatchEvent('page_block_html_topmenu_gethtml_before', array(
 61:             'menu' => $this->_menu
 62:         ));
 63: 
 64:         $this->_menu->setOutermostClass($outermostClass);
 65:         $this->_menu->setChildrenWrapClass($childrenWrapClass);
 66: 
 67:         $html = $this->_getHtml($this->_menu, $childrenWrapClass);
 68: 
 69:         Mage::dispatchEvent('page_block_html_topmenu_gethtml_after', array(
 70:             'menu' => $this->_menu,
 71:             'html' => $html
 72:         ));
 73: 
 74:         return $html;
 75:     }
 76: 
 77:     /**
 78:      * Recursively generates top menu html from data that is specified in $menuTree
 79:      *
 80:      * @param Varien_Data_Tree_Node $menuTree
 81:      * @param string $childrenWrapClass
 82:      * @return string
 83:      */
 84:     protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass)
 85:     {
 86:         $html = '';
 87: 
 88:         $children = $menuTree->getChildren();
 89:         $parentLevel = $menuTree->getLevel();
 90:         $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;
 91: 
 92:         $counter = 1;
 93:         $childrenCount = $children->count();
 94: 
 95:         $parentPositionClass = $menuTree->getPositionClass();
 96:         $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
 97: 
 98:         foreach ($children as $child) {
 99: 
100:             $child->setLevel($childLevel);
101:             $child->setIsFirst($counter == 1);
102:             $child->setIsLast($counter == $childrenCount);
103:             $child->setPositionClass($itemPositionClassPrefix . $counter);
104: 
105:             $outermostClassCode = '';
106:             $outermostClass = $menuTree->getOutermostClass();
107: 
108:             if ($childLevel == 0 && $outermostClass) {
109:                 $outermostClassCode = ' class="' . $outermostClass . '" ';
110:                 $child->setClass($outermostClass);
111:             }
112: 
113:             $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
114:             $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
115:                 . $this->escapeHtml($child->getName()) . '</span></a>';
116: 
117:             if ($child->hasChildren()) {
118:                 if (!empty($childrenWrapClass)) {
119:                     $html .= '<div class="' . $childrenWrapClass . '">';
120:                 }
121:                 $html .= '<ul class="level' . $childLevel . '">';
122:                 $html .= $this->_getHtml($child, $childrenWrapClass);
123:                 $html .= '</ul>';
124: 
125:                 if (!empty($childrenWrapClass)) {
126:                     $html .= '</div>';
127:                 }
128:             }
129:             $html .= '</li>';
130: 
131:             $counter++;
132:         }
133: 
134:         return $html;
135:     }
136: 
137:     /**
138:      * Generates string with all attributes that should be present in menu item element
139:      *
140:      * @param Varien_Data_Tree_Node $item
141:      * @return string
142:      */
143:     protected function _getRenderedMenuItemAttributes(Varien_Data_Tree_Node $item)
144:     {
145:         $html = '';
146:         $attributes = $this->_getMenuItemAttributes($item);
147: 
148:         foreach ($attributes as $attributeName => $attributeValue) {
149:             $html .= ' ' . $attributeName . '="' . str_replace('"', '\"', $attributeValue) . '"';
150:         }
151: 
152:         return $html;
153:     }
154: 
155:     /**
156:      * Returns array of menu item's attributes
157:      *
158:      * @param Varien_Data_Tree_Node $item
159:      * @return array
160:      */
161:     protected function _getMenuItemAttributes(Varien_Data_Tree_Node $item)
162:     {
163:         $menuItemClasses = $this->_getMenuItemClasses($item);
164:         $attributes = array(
165:             'class' => implode(' ', $menuItemClasses)
166:         );
167: 
168:         return $attributes;
169:     }
170: 
171:     /**
172:      * Returns array of menu item's classes
173:      *
174:      * @param Varien_Data_Tree_Node $item
175:      * @return array
176:      */
177:     protected function _getMenuItemClasses(Varien_Data_Tree_Node $item)
178:     {
179:         $classes = array();
180: 
181:         $classes[] = 'level' . $item->getLevel();
182:         $classes[] = $item->getPositionClass();
183: 
184:         if ($item->getIsFirst()) {
185:             $classes[] = 'first';
186:         }
187: 
188:         if ($item->getIsActive()) {
189:             $classes[] = 'active';
190:         }
191: 
192:         if ($item->getIsLast()) {
193:             $classes[] = 'last';
194:         }
195: 
196:         if ($item->getClass()) {
197:             $classes[] = $item->getClass();
198:         }
199: 
200:         if ($item->hasChildren()) {
201:             $classes[] = 'parent';
202:         }
203: 
204:         return $classes;
205:     }
206: }
207: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0