<?php
/**
 * Adodis Blog package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

/**
 * @param	array	A named array
 * @return	array
 */
function AdodisBlogBuildRoute(&$query)
{
	$segments 		= array();

	if (isset($query['task'])) {
		$segments[] = $query['task'];
		unset($query['task']);
	}
	if (isset($query['id'])) {
		$segments[] = $query['id'];
		unset($query['id']);
	}

	return $segments;
}

/**
 * @param	array	A named array
 * @param	array
 *
 * Formats:
 *
 * index.php?/banners/task/id/Itemid
 *
 * index.php?/banners/id/Itemid
 */
function AdodisBlogParseRoute($segments)
{
	$vars 					= array();

	// view is always the first element of the array
	$count 					= count($segments);

	if ($count)
	{
		$count--;
		$segment 			= array_shift($segments);
		if (is_numeric($segment)) {
			$vars['id'] 	= $segment;
		} else {
			$vars['task'] 	= $segment;
		}
	}

	if ($count)
	{
		$count--;
		$segment 			= array_shift($segments) ;
		if (is_numeric($segment)) {
			$vars['id'] 	= $segment;
		}
	}

	return $vars;
}
