Ejemplo n.º 1
0
function jshoppingParseRoute($segments)
{
    $vars = array();
    initLoadJoomshoppingLanguageFile();
    $reservedFirstAlias = JSFactory::getReservedFirstAlias();
    $menu = JFactory::getApplication()->getMenu();
    $menuItem = $menu->getActive();
    JPluginHelper::importPlugin('jshoppingrouter');
    $dispatcher = JDispatcher::getInstance();
    $dispatcher->trigger('onBeforeParseRoute', array(&$vars, &$segments));
    $segments[0] = getSeoSegment($segments[0]);
    if (isset($segments[1])) {
        $segments[1] = getSeoSegment($segments[1]);
    } else {
        $segments[1] = "";
    }
    if (!isset($menuItem->query['controller']) && isset($menuItem->query['view'])) {
        $menuItem->query['controller'] = $menuItem->query['view'];
    }
    if (isset($menuItem->query['controller'])) {
        if ($menuItem->query['controller'] == "cart") {
            $vars['controller'] = "cart";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "wishlist") {
            $vars['controller'] = "wishlist";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "search") {
            $vars['controller'] = "search";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "user" && $menuItem->query['task'] == "") {
            $vars['controller'] = "user";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "checkout") {
            $vars['controller'] = "checkout";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "vendor" && $menuItem->query['task'] == "") {
            $vars['controller'] = "vendor";
            $vars['task'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "content" && $menuItem->query['task'] == "view") {
            $vars['controller'] = "content";
            $vars['page'] = $segments[0];
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($menuItem->query['controller'] == "category" && $menuItem->query['category_id'] && $segments[1] == "") {
            $prodalias = JSFactory::getAliasProduct();
            $product_id = array_search($segments[0], $prodalias, true);
            if (!$product_id) {
                JError::raiseError(404, _JSHOP_PAGE_NOT_FOUND);
            }
            $vars['controller'] = "product";
            $vars['task'] = "view";
            $vars['category_id'] = $menuItem->query['category_id'];
            $vars['product_id'] = $product_id;
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
    }
    if ($segments[0] && !in_array($segments[0], $reservedFirstAlias)) {
        $catalias = JSFactory::getAliasCategory();
        $category_id = array_search($segments[0], $catalias, true);
        if ($category_id && $segments[1] == "") {
            $vars['controller'] = "category";
            $vars['task'] = "view";
            $vars['category_id'] = $category_id;
            $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
            return $vars;
        }
        if ($category_id && $segments[1] != "") {
            $prodalias = JSFactory::getAliasProduct();
            $product_id = array_search($segments[1], $prodalias, true);
            if (!$product_id) {
                JError::raiseError(404, _JSHOP_PAGE_NOT_FOUND);
            }
            if ($category_id && $product_id) {
                $vars['controller'] = "product";
                $vars['task'] = "view";
                $vars['category_id'] = $category_id;
                $vars['product_id'] = $product_id;
                $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
                return $vars;
            }
        }
        if (!$category_id && $segments[1] == "") {
            $manalias = JSFactory::getAliasManufacturer();
            $manufacturer_id = array_search($segments[0], $manalias, true);
            if ($manufacturer_id) {
                $vars['controller'] = "manufacturer";
                $vars['task'] = "view";
                $vars['manufacturer_id'] = $manufacturer_id;
                $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
                return $vars;
            }
        }
        JError::raiseError(404, _JSHOP_PAGE_NOT_FOUND);
    } else {
        $vars['controller'] = $segments[0];
        $vars['task'] = $segments[1];
        if ($vars['controller'] == "category" && $vars['task'] == "view") {
            $vars['category_id'] = $segments[2];
        }
        if ($vars['controller'] == "product" && $vars['task'] == "view") {
            $vars['category_id'] = $segments[2];
            $vars['product_id'] = $segments[3];
        }
        if ($vars['controller'] == "product" && $vars['task'] == "ajax_attrib_select_and_price") {
            $vars['product_id'] = $segments[2];
        }
        if ($vars['controller'] == "manufacturer" && isset($segments[2])) {
            $vars['manufacturer_id'] = $segments[2];
        }
        if ($vars['controller'] == "content") {
            $vars['page'] = $segments[2];
        }
    }
    $dispatcher->trigger('onAfterParseRoute', array(&$vars, &$segments));
    return $vars;
}