Пример #1
0
function virtuemartParseRoute($segments)
{
    $vars = array();
    $helper = vmrouterHelper::getInstance();
    if ($helper->router_disabled) {
        $total = count($segments);
        for ($i = 0; $i < $total; $i = $i + 2) {
            $vars[$segments[$i]] = $segments[$i + 1];
        }
        return $vars;
    }
    if (empty($segments)) {
        return $vars;
    }
    //$lang = $helper->lang ;
    // revert '-' (Joomla change - to :) //
    foreach ($segments as &$value) {
        $value = str_replace(':', '-', $value);
    }
    // $splitted = explode(',',$segments[0],2);
    $splitted = explode(',', end($segments), 2);
    if ($helper->compareKey($splitted[0], 'results')) {
        // array_shift($segments);
        array_pop($segments);
        $results = explode('-', $splitted[1], 2);
        //Pagination has changed, removed the -1 note by Max Milbers NOTE: Works on j1.5, but NOT j1.7
        // limitstart is swapped by joomla to start ! See includes/route.php
        if ($start = $results[0] - 1) {
            $vars['limitstart'] = $start;
        } else {
            $vars['limitstart'] = 0;
        }
        $vars['limit'] = $results[1] - $results[0] + 1;
    } else {
        $vars['limitstart'] = 0;
        if (vmrouterHelper::$limit === null) {
            vmrouterHelper::$limit = VmConfig::get('list_limit', 20);
        }
        $vars['limit'] = vmrouterHelper::$limit;
    }
    if (empty($segments)) {
        $vars['view'] = 'category';
        $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
        return $vars;
    }
    // $orderby = explode(',',$segments[0],2);
    $orderby = explode(',', end($segments), 2);
    if ($helper->compareKey($orderby[0], 'by')) {
        $vars['orderby'] = $helper->getOrderingKey($orderby[1]);
        // array_shift($segments);
        array_pop($segments);
        if (empty($segments)) {
            $vars['view'] = 'category';
            $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
            return $vars;
        }
    }
    if ($helper->compareKey(end($segments), 'orderDesc')) {
        $vars['order'] = 'DESC';
        array_pop($segments);
        if (empty($segments)) {
            $vars['view'] = 'category';
            $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
            return $vars;
        }
    }
    if ($segments[0] == 'product') {
        $vars['view'] = 'product';
        $vars['task'] = $segments[1];
        $vars['tmpl'] = 'component';
        return $vars;
    }
    if ($segments[0] == 'checkout') {
        $vars['view'] = 'cart';
        $vars['task'] = $segments[0];
        return $vars;
    }
    if ($helper->compareKey($segments[0], 'manufacturer')) {
        if (!empty($segments[1])) {
            array_shift($segments);
            $vars['virtuemart_manufacturer_id'] = $helper->getManufacturerId($segments[0]);
        }
        array_shift($segments);
        // OSP 2012-02-29 removed search malforms SEF path and search is performed
        // $vars['search'] = 'true';
        if (empty($segments)) {
            $vars['view'] = 'category';
            $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
            return $vars;
        }
    }
    /* added in vm208 */
    // if no joomla link: vendor/vendorname/layout
    // if joomla link joomlalink/vendorname/layout
    if ($helper->compareKey($segments[0], 'vendor')) {
        $vars['virtuemart_vendor_id'] = $helper->getVendorId($segments[1]);
        // OSP 2012-02-29 removed search malforms SEF path and search is performed
        // $vars['search'] = 'true';
        // this can never happen
        if (empty($segments)) {
            $vars['view'] = 'vendor';
            $vars['virtuemart_vendor_id'] = $helper->activeMenu->virtuemart_vendor_id;
            return $vars;
        }
    }
    if ($helper->compareKey($segments[0], 'search')) {
        $vars['search'] = 'true';
        array_shift($segments);
        if (!empty($segments)) {
            $vars['keyword'] = array_shift($segments);
        }
        $vars['view'] = 'category';
        $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
        if (empty($segments)) {
            return $vars;
        }
    }
    if (end($segments) == 'modal') {
        $vars['tmpl'] = 'component';
        array_pop($segments);
    }
    if ($helper->compareKey(end($segments), 'askquestion')) {
        $vars = (array) $helper->activeMenu;
        $vars['task'] = 'askquestion';
        array_pop($segments);
    } elseif ($helper->compareKey(end($segments), 'recommend')) {
        $vars = (array) $helper->activeMenu;
        $vars['task'] = 'recommend';
        array_pop($segments);
    } elseif ($helper->compareKey(end($segments), 'notify')) {
        $vars = (array) $helper->activeMenu;
        $vars['layout'] = 'notify';
        array_pop($segments);
    }
    if (empty($segments)) {
        return $vars;
    }
    // View is first segment now
    $view = $segments[0];
    if ($helper->compareKey($view, 'orders') || $helper->activeMenu->view == 'orders') {
        $vars['view'] = 'orders';
        if ($helper->compareKey($view, 'orders')) {
            array_shift($segments);
        }
        if (empty($segments)) {
            $vars['layout'] = 'list';
        } else {
            if ($helper->compareKey($segments[0], 'list')) {
                $vars['layout'] = 'list';
                array_shift($segments);
            }
        }
        if (!empty($segments)) {
            if ($segments[0] == 'number') {
                $vars['order_number'] = $segments[1];
            } else {
                $vars['virtuemart_order_id'] = $segments[1];
            }
            $vars['layout'] = 'details';
        }
        return $vars;
    } else {
        if ($helper->compareKey($view, 'user') || $helper->activeMenu->view == 'user') {
            $vars['view'] = 'user';
            if ($helper->compareKey($view, 'user')) {
                array_shift($segments);
            }
            if (!empty($segments)) {
                if ($helper->compareKey($segments[0], 'editaddresscartBT')) {
                    $vars['addrtype'] = 'BT';
                    $vars['task'] = 'editaddresscart';
                } elseif ($helper->compareKey($segments[0], 'editaddresscartST')) {
                    $vars['addrtype'] = 'ST';
                    $vars['task'] = 'editaddresscart';
                } elseif ($helper->compareKey($segments[0], 'editaddresscheckoutBT')) {
                    $vars['addrtype'] = 'BT';
                    $vars['task'] = 'editaddresscheckout';
                } elseif ($helper->compareKey($segments[0], 'editaddresscheckoutST')) {
                    $vars['addrtype'] = 'ST';
                    $vars['task'] = 'editaddresscheckout';
                } elseif ($helper->compareKey($segments[0], 'editaddressST')) {
                    $vars['addrtype'] = 'ST';
                    $vars['task'] = 'editaddressST';
                } elseif ($helper->compareKey($segments[0], 'editaddressBT')) {
                    $vars['addrtype'] = 'BT';
                    $vars['task'] = 'edit';
                    $vars['layout'] = 'edit';
                    //I think that should be the layout, not the task
                } elseif ($helper->compareKey($segments[0], 'edit')) {
                    $vars['layout'] = 'edit';
                    //uncomment and lets test
                } else {
                    $vars['task'] = $segments[0];
                }
            }
            return $vars;
        } else {
            if ($helper->compareKey($view, 'vendor') || $helper->activeMenu->view == 'vendor') {
                /* vm208 */
                $vars['view'] = 'vendor';
                if ($helper->compareKey($view, 'vendor')) {
                    array_shift($segments);
                    if (empty($segments)) {
                        return $vars;
                    }
                }
                //$vars['virtuemart_vendor_id'] = array_shift($segments);//// already done
                //array_shift($segments);
                $vars['virtuemart_vendor_id'] = $helper->getVendorId($segments[0]);
                array_shift($segments);
                if (!empty($segments)) {
                    if ($helper->compareKey($segments[0], 'contact')) {
                        $vars['layout'] = 'contact';
                    } elseif ($helper->compareKey($segments[0], 'tos')) {
                        $vars['layout'] = 'tos';
                    } elseif ($helper->compareKey($segments[0], 'details')) {
                        $vars['layout'] = 'details';
                    }
                } else {
                    $vars['layout'] = 'details';
                }
                return $vars;
            } elseif ($helper->compareKey($segments[0], 'pluginresponse')) {
                $vars['view'] = 'pluginresponse';
                array_shift($segments);
                if (!empty($segments)) {
                    $vars['task'] = $segments[0];
                    array_shift($segments);
                }
                if (isset($segments[0]) && $segments[0] == 'modal') {
                    $vars['tmpl'] = 'component';
                    array_shift($segments);
                }
                return $vars;
            } else {
                if ($helper->compareKey($view, 'cart') || $helper->activeMenu->view == 'cart') {
                    $vars['view'] = 'cart';
                    if ($helper->compareKey($view, 'cart')) {
                        array_shift($segments);
                        if (empty($segments)) {
                            return $vars;
                        }
                    }
                    if ($helper->compareKey($segments[0], 'edit_shipment')) {
                        $vars['task'] = 'edit_shipment';
                    } elseif ($helper->compareKey($segments[0], 'editpayment')) {
                        $vars['task'] = 'editpayment';
                    } elseif ($helper->compareKey($segments[0], 'delete')) {
                        $vars['task'] = 'delete';
                    } elseif ($helper->compareKey($segments[0], 'checkout')) {
                        $vars['task'] = 'checkout';
                    } else {
                        $vars['task'] = $segments[0];
                    }
                    return $vars;
                } else {
                    if ($helper->compareKey($view, 'manufacturers') || $helper->activeMenu->view == 'manufacturer') {
                        $vars['view'] = 'manufacturer';
                        if ($helper->compareKey($view, 'manufacturers')) {
                            array_shift($segments);
                        }
                        if (!empty($segments)) {
                            $vars['virtuemart_manufacturer_id'] = $helper->getManufacturerId($segments[0]);
                            array_shift($segments);
                        }
                        if (isset($segments[0]) && $segments[0] == 'modal') {
                            $vars['tmpl'] = 'component';
                            array_shift($segments);
                        }
                        // if (isset($helper->activeMenu->virtuemart_manufacturer_id))
                        // $vars['virtuemart_manufacturer_id'] = $helper->activeMenu->virtuemart_manufacturer_id ;
                        vmdebug('my parsed URL vars', $vars);
                        return $vars;
                    }
                }
            }
        }
    }
    /*
     * seo_sufix must never be used in category or router can't find it
     * eg. suffix as "-suffix", a category with "name-suffix" get always a false return
     * Trick : YOu can simply use "-p","-x","-" or ".htm" for better seo result if it's never in the product/category name !
     */
    /*	if (substr(end($segments ), -(int)$helper->seo_sufix_size ) == $helper->seo_sufix ) {
    			vmdebug('$segments productdetail',$segments,end($segments ));*/
    $last_elem = end($segments);
    $slast_elem = prev($segments);
    if (substr($last_elem, -(int) $helper->seo_sufix_size) == $helper->seo_sufix || $last_elem == 'notify' && substr($slast_elem, -(int) $helper->seo_sufix_size) == $helper->seo_sufix) {
        $vars['view'] = 'productdetails';
        if ($last_elem == 'notify') {
            $vars['layout'] = 'notify';
            array_pop($segments);
        }
        if (!$helper->use_id) {
            $product = $helper->getProductId($segments, $helper->activeMenu->virtuemart_category_id);
            $vars['virtuemart_product_id'] = $product['virtuemart_product_id'];
            $vars['virtuemart_category_id'] = $product['virtuemart_category_id'];
            //vmdebug('View productdetails, using case !$helper->use_id',$vars,$helper->activeMenu);
        } elseif (isset($segments[1])) {
            $vars['virtuemart_product_id'] = $segments[0];
            $vars['virtuemart_category_id'] = $segments[1];
            //vmdebug('View productdetails, using case isset($segments[1]',$vars);
        } else {
            $vars['virtuemart_product_id'] = $segments[0];
            $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
            //vmdebug('View productdetails, using case "else", which uses $helper->activeMenu->virtuemart_category_id ',$vars);
        }
    } elseif (!$helper->use_id && $helper->activeMenu->view == 'category') {
        $vars['virtuemart_category_id'] = $helper->getCategoryId(end($segments), $helper->activeMenu->virtuemart_category_id);
        $vars['view'] = 'category';
    } elseif (isset($segments[0]) && ctype_digit($segments[0]) || $helper->activeMenu->virtuemart_category_id > 0) {
        $vars['virtuemart_category_id'] = $segments[0];
        $vars['view'] = 'category';
    } elseif ($helper->activeMenu->virtuemart_category_id > 0 && $vars['view'] != 'productdetails') {
        $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id;
        $vars['view'] = 'category';
    } elseif ($id = $helper->getCategoryId(end($segments), $helper->activeMenu->virtuemart_category_id)) {
        // find corresponding category . If not, segment 0 must be a view
        $vars['virtuemart_category_id'] = $id;
        $vars['view'] = 'category';
    } else {
        $vars['view'] = $segments[0];
        if (isset($segments[1])) {
            $vars['task'] = $segments[1];
        }
    }
    //vmdebug('Router vars',$vars);
    return $vars;
}
Пример #2
0
                $limitstart = 0;
                shAddToGETVarsList('limitstart', $limitstart);
                shRemoveFromGETVarsList('limitstart');
            }
        }
        ShlSystem_Log::debug('sh404sef', 'Inside com_virtuemart.php, building url from menu item route');
        $title = array($item->route);
    }
}
if (empty($title)) {
    ShlSystem_Log::debug('sh404sef', 'Loading component own router.php file from inside com_virtuemart.php');
    $functionName = ucfirst(str_replace('com_', '', $option)) . 'BuildRoute';
    if (!function_exists($functionName)) {
        include JPATH_ROOT . '/components/' . $option . '/router.php';
    }
    $helper = vmrouterHelper::getInstance($originalVars);
    $menuItem = $helper->menuVmitems;
    $shopName = empty($menuItem) ? 'vm' : $menuItem[0]->alias;
    // check for shop root url, else normal routing
    if (!empty($originalVars['view']) && $originalVars['view'] == 'virtuemart') {
        // if VM is homepage, then that's fine
        if (!shIsAnyHomepage($string)) {
            // else use menu item alias as slug
            $title[] = $shopName;
            unset($originalVars['view']);
        }
    } else {
        // various checks as VM2 seem to produce funky non-sef urls
        if (!empty($originalVars['view']) && $originalVars['view'] == 'productdetails') {
            if (empty($originalVars['virtuemart_product_id'])) {
                // request for product details, but product id is 0