<?php
/**
 * FW Food menu 5.1.1
 * @copyright (C) 2020 Fastw3b
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.fastw3b.net/ Official website
 **/

defined( '_JEXEC' ) or die( 'Restricted access' );

function fwFoodMenuBuildRoute(&$query) {
    $segments = array();

    if (!empty($query['Itemid'])) {
        $menu = JMenu::getInstance('site');
        $item = $menu->getItems('id', $query['Itemid'], true);
        if ($item) {
		 	if (!empty($query['view'])) {
				if ($query['view'] != $item->query['view']) {
					$segments[] = $query['view'];
				}
				unset($query['view']);
			}
			if (!empty($query['id'])) {
				$segments[] = $query['id'];
				unset($query['id']);
			}
		}
	} else {
		if (!empty($query['view'])) {
			$segments[] = $query['view'];
			unset($query['view']);
		}
		if (!empty($query['id'])) {
			$segments[] = $query['id'];
			unset($query['id']);
		}
	}

	return $segments;
}
function fwFoodMenuParseRoute(&$segments) {
    $vars = array();
	if (count($segments) == 2 and $segments[0] == 'item') {
		$vars['view'] = 'item';
		$vars['id'] = $segments[1];
		$segments = array();
	}
/*print_r($segments); print_r($vars); die();*/
	return $vars;
}
