Exemplo n.º 1
0
 /**
  * Render category to html
  *
  * @param Mage_Catalog_Model_Category $category
  * @param int Nesting level number
  * @param boolean Whether ot not this item is last, affects list item class
  * @param boolean Whether ot not this item is first, affects list item class
  * @param boolean Whether ot not this item is outermost, affects list item class
  * @param string Extra class of outermost list items
  * @param string If specified wraps children list in div with this class
  * @param boolean Whether ot not to add on* attributes to list item
  * @return string
  */
 protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false, $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
 {
     if (!$category->getIsActive()) {
         return '';
     }
     $html = array();
     // get all children
     $children = $category->getChildren();
     $childrenCount = $children->count();
     $hasChildren = $children && $childrenCount;
     // select active children
     $activeChildren = array();
     foreach ($children as $child) {
         if ($child->getIsActive()) {
             $activeChildren[] = $child;
         }
     }
     $activeChildrenCount = count($activeChildren);
     $hasActiveChildren = $activeChildrenCount > 0;
     // prepare list item html classes
     $classes = array();
     $classes[] = 'level' . $level;
     $classes[] = 'nav-' . $this->_getItemPosition($level);
     if ($this->_navigation_place == self::MENU_BAR) {
         if ($this->isCategoryActive($category)) {
             $classes[] = 'active';
         }
     }
     $linkClass = '';
     if ($isOutermost && $outermostItemClass) {
         $classes[] = $outermostItemClass;
         $linkClass = ' class="' . $outermostItemClass . '"';
     }
     if ($isFirst) {
         $classes[] = 'first';
     }
     if ($isLast) {
         $classes[] = 'last';
     }
     if ($hasActiveChildren) {
         $classes[] = 'parent';
     }
     // prepare list item attributes
     $attributes = array();
     if (count($classes) > 0) {
         $attributes['class'] = implode(' ', $classes);
     }
     switch ($this->getTypeNavigation()) {
         case GoMage_Navigation_Model_Layer::FILTER_TYPE_DROPDOWN:
             if ($this->getIsAjax()) {
                 $attributes['onchange'] = "setNavigationUrl(this.value); return false;";
             } else {
                 $attributes['onchange'] = "window.location=this.value";
             }
             $curent_id = 0;
             if (Mage::registry('current_category')) {
                 $curent_id = Mage::registry('current_category')->getId();
             }
             if ($category->getLevel() == $this->_root_level) {
                 $htmlSel = '<li><select';
                 foreach ($attributes as $attrName => $attrValue) {
                     $htmlSel .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
                 }
                 $htmlSel .= '>';
                 $html[] = $htmlSel;
                 $option_value = $this->getIsAjax() ? $this->getAjaxUrl($category) : $this->getCategoryUrl($category);
                 $html[] = '<option class="gan-dropdown-top" value="' . $option_value . '">' . (str_repeat('&nbsp;&nbsp;', $category->getLevel() - $this->_root_level) . $category->getName()) . '</option>';
             }
             $option_selected = $curent_id == $category->getId() ? 'selected="selected"' : '';
             $option_value = $this->getIsAjax() ? $this->getAjaxUrl($category) : $this->getCategoryUrl($category);
             $html[] = '<option ' . $option_selected . ' value="' . $option_value . '">' . (str_repeat('&nbsp;&nbsp;', $category->getLevel() - $this->_root_level) . $category->getName()) . '</option>';
             // render children
             $htmlChildren = '';
             $j = 0;
             foreach ($activeChildren as $child) {
                 $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                 $j++;
             }
             if (!empty($htmlChildren)) {
                 $html[] = $htmlChildren;
             }
             if ($category->getLevel() == $this->_root_level) {
                 $html[] = '</select></li>';
             }
             break;
         case GoMage_Navigation_Model_Layer::FILTER_TYPE_PLAIN:
             $linkClass = '';
             if ($isOutermost && $outermostItemClass) {
                 $linkClass = $outermostItemClass;
             }
             if ($this->getIsActiveAjaxCategory($category) || $this->isCategoryActive($category)) {
                 $linkClass .= ' active';
             }
             $linkClass = ' class="' . $linkClass . '" ';
             if ($category->getLevel() == $this->_root_level) {
                 if ($hasActiveChildren && !$noEventAttributes) {
                     $attributes['onmouseover'] = 'toggleMenu(this,1)';
                     $attributes['onmouseout'] = 'toggleMenu(this,0)';
                 }
                 $htmlLi = '<li';
                 foreach ($attributes as $attrName => $attrValue) {
                     $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
                 }
                 $htmlLi .= '>';
                 $html[] = $htmlLi;
                 $htmlA = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass;
                 if ($this->getIsAjax()) {
                     $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
                 }
                 $htmlA .= '>';
                 $html[] = $htmlA;
                 $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
                 $html[] = '</a>';
                 if ($hasActiveChildren) {
                     if ($this->_navigation_place == self::MENU_BAR) {
                         $_width = $category->getData('navigation_pw_width');
                     } else {
                         $_width = $category->getData('navigation_pw_side_width');
                     }
                     $gan_plain_style = ($this->_navigation_place == self::MENU_BAR ? 'background-color: ' . $this->getColumnColor() . ';' : '') . ($_width ? 'width: ' . $_width . 'px;' : '');
                     if ($gan_plain_style) {
                         $gan_plain_style = 'style="' . $gan_plain_style . '"';
                     }
                     $html[] = '<div ' . $gan_plain_style . ' class="gan-plain" >';
                     if (!($this->_navigation_place == self::MENU_BAR)) {
                         $html[] = '<span class="gan-plain-border"></span>';
                     }
                     $_add_style = '';
                     if ($this->_navigation_place == self::MENU_BAR) {
                         $navigation_image = $category->getData('navigation_image');
                         $navigation_image_position = $category->getData('navigation_image_position');
                         if ($navigation_image) {
                             $navigation_image = $this->getResizedImage($navigation_image, $category->getData('navigation_image_width'), $category->getData('navigation_image_height'));
                         }
                         if ($navigation_image) {
                             $_add_image_style = '';
                             if ($category->getData('navigation_image_width')) {
                                 $_add_image_style = 'width:' . $category->getData('navigation_image_width') . 'px;';
                             }
                             if ($category->getData('navigation_image_height')) {
                                 $_add_image_style .= 'height:' . $category->getData('navigation_image_height') . 'px;';
                             }
                             if ($_add_image_style) {
                                 $_add_image_style = 'style="' . $_add_image_style . '"';
                             }
                             $this->_plain_image = '<div class="' . GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::getPositionClass($navigation_image_position) . '">';
                             $this->_plain_image .= '<img ' . $_add_image_style . ' src="' . Mage::getBaseUrl('media') . "catalog/product/cache/cat_resized/" . $navigation_image . '" alt="' . $this->escapeHtml($category->getName()) . '" />';
                             $this->_plain_image .= '</div>';
                             $imageObj = new Varien_Image(Mage::getBaseDir('media') . DS . "catalog" . DS . "product" . DS . "cache" . DS . "cat_resized" . DS . $navigation_image);
                             switch ($navigation_image_position) {
                                 case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::RIGHT:
                                     $_add_style = ' style="margin-right: ' . ((int) ($category->getData('navigation_image_width') ? $category->getData('navigation_image_width') : $imageObj->getOriginalWidth()) + 10) . 'px;" ';
                                     $html[] = $this->_plain_image;
                                     $this->_plain_image = '';
                                     break;
                                 case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::TOP:
                                     $html[] = $this->_plain_image;
                                     $this->_plain_image = '';
                                     break;
                                 case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::BOTTOM:
                                     break;
                                 default:
                                 case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::LEFT:
                                     $_add_style = ' style="margin-left: ' . ((int) ($category->getData('navigation_image_width') ? $category->getData('navigation_image_width') : $imageObj->getOriginalWidth()) + 10) . 'px;" ';
                                     $html[] = $this->_plain_image;
                                     $this->_plain_image = '';
                                     break;
                             }
                         }
                     }
                     $html[] = '<div ' . $_add_style . ' class="gan-plain-items">';
                     $activeChildren = $this->sort_category($activeChildren);
                 }
             } else {
                 $_cat_column = null;
                 if ($category->getLevel() == $this->_root_level + 1) {
                     if ($this->_navigation_place == self::MENU_BAR) {
                         $_cat_column = $category->getData('navigation_column') ? $category->getData('navigation_column') : 1;
                     } else {
                         $_cat_column = $category->getData('navigation_column_side') ? $category->getData('navigation_column_side') : 1;
                     }
                 }
                 if ($this->_childs_count == 1 || $_cat_column && $_cat_column != $this->_current_column) {
                     $this->_current_column = $_cat_column;
                     $_with_percent = floor(100 / $this->_columns);
                     if ($this->_childs_count != 1) {
                         $html[] = '</ul>';
                     }
                     $html[] = '<ul style="width:' . $_with_percent . '%;" class="gan-plain-item">';
                 }
                 $html[] = '<li' . ($category->getLevel() == $this->_root_level + 1 ? ' class="gan-plain-item-bold" ' : '') . '>';
                 $htmlA = '<a style="padding-left: ' . 10 * ($category->getLevel() - ($this->_root_level + 1)) . 'px;" href="' . $this->getCategoryUrl($category) . '"' . $linkClass;
                 if ($this->getIsAjax()) {
                     $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
                 }
                 $htmlA .= '>';
                 $html[] = $htmlA;
                 $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
                 $html[] = '</a>';
                 $html[] = '</li>';
             }
             // render children
             $htmlChildren = '';
             $j = 0;
             foreach ($activeChildren as $child) {
                 $this->_childs_count++;
                 $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                 $j++;
             }
             if (!empty($htmlChildren)) {
                 $html[] = $htmlChildren;
             }
             if ($category->getLevel() == $this->_root_level) {
                 if ($hasActiveChildren) {
                     $html[] = '</ul>';
                     $html[] = '</div>';
                     //gan-plain-items
                     if ($this->_plain_image) {
                         $html[] = $this->_plain_image;
                         $this->_plain_image = '';
                     }
                     $html[] = '</div>';
                     //gan-plain
                 }
                 $html[] = '</li>';
             }
             break;
         case GoMage_Navigation_Model_Layer::FILTER_TYPE_FOLDING:
             $htmlLi = '<li';
             foreach ($attributes as $attrName => $attrValue) {
                 $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
             }
             $htmlLi .= '>';
             $html[] = $htmlLi;
             $htmlA = '<a href="' . $this->getCategoryUrl($category) . '"';
             $htmlA .= ' style="padding-left: ' . 10 * ($category->getLevel() - $this->_root_level) . 'px;" ';
             if ($this->getIsAjax()) {
                 $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
             }
             if ($this->getIsActiveAjaxCategory($category) || $this->isCategoryActive($category)) {
                 $htmlA .= ' class="active" ';
             }
             $htmlA .= '>';
             $html[] = $htmlA;
             $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
             $html[] = '</a>';
             // render children
             $htmlChildren = '';
             $j = 0;
             foreach ($activeChildren as $child) {
                 $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                 $j++;
             }
             if (!empty($htmlChildren)) {
                 $html[] = $htmlChildren;
             }
             $html[] = '</li>';
             break;
         case GoMage_Navigation_Model_Layer::FILTER_TYPE_IMAGE:
             $htmlLi = '<li';
             foreach ($attributes as $attrName => $attrValue) {
                 $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
             }
             $htmlLi .= '>';
             $html[] = $htmlLi;
             $htmlA = '<a href="' . $this->getCategoryUrl($category) . '"';
             if ($this->getIsAjax()) {
                 $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
             }
             if ($this->getIsActiveAjaxCategory($category) || $this->isCategoryActive($category)) {
                 $htmlA .= ' class="active" ';
             }
             $htmlA .= '>';
             $html[] = $htmlA;
             $image_url = $category->getData('filter_image');
             if ($image_url) {
                 $image_url = Mage::getBaseUrl('media') . '/catalog/category/' . $image_url;
                 if ($image_width = $this->getImageWidth()) {
                     $image_width = 'width="' . $image_width . '"';
                 } else {
                     $image_width = '';
                 }
                 if ($image_height = $this->getImageHeight()) {
                     $image_height = 'height="' . $image_height . '"';
                 } else {
                     $image_height = '';
                 }
                 $html[] = '<img ' . $image_width . ' ' . $image_height . ' title="' . $category->getName() . '" src="' . $image_url . '" alt="' . $category->getName() . '" />';
             }
             if ($this->canShowLabels()) {
                 $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
             }
             $html[] = '</a>';
             $html[] = '</li>';
             break;
         case GoMage_Navigation_Model_Layer::FILTER_TYPE_DEFAULT_PRO:
             if ($hasActiveChildren && !$noEventAttributes) {
                 $attributes['onmouseover'] = 'toggleMenu(this,1)';
                 $attributes['onmouseout'] = 'toggleMenu(this,0)';
             }
             // assemble list item with attributes
             $htmlLi = '<li';
             foreach ($attributes as $attrName => $attrValue) {
                 $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
             }
             $htmlLi .= '>';
             $html[] = $htmlLi;
             $htmlA = '<a href="' . $this->getCategoryUrl($category) . '"';
             if ($this->getIsAjax()) {
                 $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
             }
             if ($this->isCategoryActive($category)) {
                 $htmlA .= ' class="active" ';
             }
             $htmlA .= '>';
             $html[] = $htmlA;
             $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
             $html[] = '</a>';
             // render children
             $htmlChildren = '';
             $j = 0;
             foreach ($activeChildren as $child) {
                 $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                 $j++;
             }
             if (!empty($htmlChildren)) {
                 if ($childrenWrapClass) {
                     $html[] = '<div class="' . $childrenWrapClass . '">';
                 }
                 $html[] = '<ul class="level' . $level . '">';
                 $html[] = $htmlChildren;
                 $html[] = '</ul>';
                 if ($childrenWrapClass) {
                     $html[] = '</div>';
                 }
             }
             $html[] = '</li>';
             break;
         default:
             if ($this->_navigation_place == self::MENU_BAR) {
                 if ($hasActiveChildren && !$noEventAttributes) {
                     $attributes['onmouseover'] = 'toggleMenu(this,1)';
                     $attributes['onmouseout'] = 'toggleMenu(this,0)';
                 }
                 // assemble list item with attributes
                 $htmlLi = '<li';
                 foreach ($attributes as $attrName => $attrValue) {
                     $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
                 }
                 $htmlLi .= '>';
                 $html[] = $htmlLi;
                 $html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>';
                 $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
                 $html[] = '</a>';
                 // render children
                 $htmlChildren = '';
                 $j = 0;
                 foreach ($activeChildren as $child) {
                     $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                     $j++;
                 }
                 if (!empty($htmlChildren)) {
                     ////  if ($childrenWrapClass) {
                     $html[] = '<div class="children_class">';
                     // }
                     $html[] = '<ul class="level' . $level . '">';
                     $html[] = $htmlChildren;
                     $html[] = '</ul>';
                     //  if ($childrenWrapClass) {
                     $html[] = '</div>';
                     //   }
                 }
                 $html[] = '</li>';
             } else {
                 $htmlLi = '<li';
                 foreach ($attributes as $attrName => $attrValue) {
                     $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
                 }
                 $htmlLi .= '>';
                 $html[] = $htmlLi;
                 $htmlA = '<a href="' . $this->getCategoryUrl($category) . '"';
                 $htmlA .= ' style="padding-left: ' . 10 * ($category->getLevel() - $this->_root_level) . 'px;" ';
                 if ($this->getIsAjax()) {
                     $htmlA .= ' onclick="setNavigationUrl(\'' . $this->getAjaxUrl($category) . '\'); return false;" ';
                 }
                 if ($this->getIsActiveAjaxCategory($category) || $this->isCategoryActive($category)) {
                     $htmlA .= ' class="active" ';
                 }
                 $htmlA .= '>';
                 $html[] = $htmlA;
                 $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
                 $html[] = '</a>';
                 // render children
                 $htmlChildren = '';
                 $j = 0;
                 if ($this->getIsActiveAjaxCategory($category) || $this->getIsShowAllSubcategories()) {
                     foreach ($activeChildren as $child) {
                         $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
                         $j++;
                     }
                 }
                 if (!empty($htmlChildren)) {
                     if ($childrenWrapClass) {
                         $html[] = '<div class="' . $childrenWrapClass . '">';
                     }
                     $html[] = '<ul class="level' . $level . '">';
                     $html[] = $htmlChildren;
                     $html[] = '</ul>';
                     if ($childrenWrapClass) {
                         $html[] = '</div>';
                     }
                 }
                 $html[] = '</li>';
             }
     }
     $html = implode("\n", $html);
     return $html;
 }
Exemplo n.º 2
0
 public function renderPlainImage($navigation_image, $category, $first_level)
 {
     if ($first_level) {
         $image_position = $this->_plain_root_cat->getData('navigation_pw_fl_ipos');
         $width = $this->_plain_root_cat->getData('navigation_pw_fl_iwidth');
         $height = $this->_plain_root_cat->getData('navigation_pw_fl_iheight');
     } else {
         $image_position = $this->_plain_root_cat->getData('navigation_pw_sl_ipos');
         $width = $this->_plain_root_cat->getData('navigation_pw_sl_iwidth');
         $height = $this->_plain_root_cat->getData('navigation_pw_sl_iheight');
     }
     $plain_image = '';
     $navigation_image = $this->getResizedImage($navigation_image, $width, $height);
     if ($navigation_image) {
         $_add_image_style = '';
         if ($width) {
             $_add_image_style = 'width:' . $width . 'px;';
         }
         if ($height) {
             $_add_image_style .= 'height:' . $height . 'px;';
         }
         if ($_add_image_style) {
             $_add_image_style = 'style="' . $_add_image_style . '"';
         }
         $plain_image .= '<img class="' . GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::getPositionClass($image_position) . '" ' . $_add_image_style . ' src="' . $navigation_image . '" alt="' . $this->escapeHtml($category->getName()) . '" />';
     }
     return $plain_image;
 }