示例#1
0
 /**
  * Parse the categories of a tree for display
  *
  * @access public
  * @param array $tree
  * @param int $endLevel
  * @return mixed
  */
 public static function parseTree($tree, $startLevel = 1, $endLevel = 99)
 {
     $current_category_id = modMageBridgeMenuHelper::getCurrentCategoryId();
     $current_category_path = modMageBridgeMenuHelper::getCurrentCategoryPath();
     if (is_array($tree) && count($tree) > 0) {
         foreach ($tree as $index => $item) {
             $item['path'] = explode('/', $item['path']);
             if (empty($item)) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove disabled categories
             if ($item['is_active'] != 1) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove categories that should not be in the menu
             if (isset($item['include_in_menu']) && $item['include_in_menu'] != 1) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove items from the wrong start-level
             if ($startLevel > 0 && $item['level'] < $startLevel && !in_array($current_category_id, $item['path'])) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove items from the wrong end-level
             if ($item['level'] > $endLevel) {
                 unset($tree[$index]);
                 continue;
             }
             // Handle HTML-entities in the title
             if (isset($item['name'])) {
                 $item['name'] = htmlspecialchars($item['name']);
             }
             // Parse the children-tree
             if (!empty($item['children'])) {
                 $item['children'] = modMageBridgeMenuHelper::parseTree($item['children'], $startLevel, $endLevel);
             } else {
                 $item['children'] = array();
             }
             // Translate the URL into Joomla! SEF URL
             if (empty($item['url'])) {
                 $item['url'] = '';
             } else {
                 $item['url'] = MageBridgeUrlHelper::route($item['url']);
             }
             $tree[$index] = $item;
         }
     }
     return $tree;
 }
/**
 * Joomla! module MageBridge: Catalog Menu
 *
 * @author	Yireo (info@yireo.com)
 * @package   MageBridge
 * @copyright Copyright 2015
 * @license   GNU Public License
 * @link	  http://www.yireo.com
 */
// No direct access
defined('_JEXEC') or die('Restricted access');
// Import the MageBridge autoloader
require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php';
require_once dirname(__FILE__) . '/helper.php';
// Read the parameters
$root = $params->get('root', 0);
$levels = $params->get('levels', 2);
$startLevel = $params->get('startlevel', 1);
if ($startLevel < 1) {
    $startLevel = 1;
}
$endLevel = $startLevel + $levels - 1;
$layout = $params->get('layout', 'default');
// Call the helper
$catalog_tree = modMageBridgeMenuHelper::build($params);
// Load the catalog-tree
$rootLevel = !empty($catalog_tree['level']) ? $catalog_tree['level'] : 0;
$catalog_tree = modMageBridgeMenuHelper::setRoot($catalog_tree, $root);
$catalog_tree = modMageBridgeMenuHelper::parseTree($catalog_tree, $rootLevel + $startLevel, $rootLevel + $endLevel);
// Show the template
require JModuleHelper::getLayoutPath('mod_magebridge_menu', $layout);
 public function parseTree($tree, $endLevel = 99)
 {
     if (is_array($tree) && count($tree) > 0) {
         foreach ($tree as $index => $item) {
             if (empty($item)) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove disabled categories
             if ($item['is_active'] != 1) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove categories that should not be in the menu
             if (isset($item['include_in_menu']) && $item['include_in_menu'] != 1) {
                 unset($tree[$index]);
                 continue;
             }
             // Remove items from the wrong level
             if ($item['level'] >= $endLevel) {
                 unset($tree[$index]);
                 continue;
             }
             // Handle HTML-entities in the title
             if (isset($item['name'])) {
                 $item['name'] = htmlspecialchars($item['name']);
             }
             // Parse the children-tree
             if (!empty($item['children'])) {
                 $item['children'] = modMageBridgeMenuHelper::parseTree($item['children'], $endLevel);
             } else {
                 $item['children'] = array();
             }
             // Translate the URL into Joomla! SEF URL
             if (empty($item['url'])) {
                 $item['url'] = '';
             } else {
                 $item['url'] = MageBridgeUrlHelper::route($item['url']);
             }
             $tree[$index] = $item;
         }
     }
     return $tree;
 }
<?php

/**
 * Joomla! module MageBridge: Catalog Menu
 *
 * @author Yireo (info@yireo.com)
 * @package MageBridge
 * @copyright Copyright 2012
 * @license GNU Public License
 * @link http://www.yireo.com
 */
// No direct access
defined('_JEXEC') or die('Restricted access');
// Import the MageBridge autoloader
require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php';
require_once dirname(__FILE__) . '/helper.php';
// Read the parameters
$root = $params->get('root', 0);
$levels = $params->get('levels', 2);
// Call the helper
$catalog_tree = modMageBridgeMenuHelper::build($params);
// Determine the appropriate settings
$catalog_tree = modMageBridgeMenuHelper::setRoot($catalog_tree, $root);
if (!empty($catalog_tree[0]['level'])) {
    $levels = $catalog_tree[0]['level'] + $levels;
}
$catalog_tree = modMageBridgeMenuHelper::parseTree($catalog_tree, $levels);
require JModuleHelper::getLayoutPath('mod_magebridge_menu');