<?
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.url2.php
 * Type:     function
 * Name:     link
 * Purpose:  zwraca sformatowany url na potrzeby naszamedycyna.pl
 * -------------------------------------------------------------
 */
function smarty_function_url2($params, &$smarty)
{
    if(!isset($params['action'])) {
        return URL_MAIN;
    }

    $url = URL_MAIN;
    if($url[strlen($url) - 1] == '/' && $params['action'][0] == '/') {
        $url = substr($url, 0, -1);
    } else {
        if($url[strlen($url) - 1] != '/' && $params['action'][0] != '/') {
            $url .= '/';
        }
    }

    if($params['action'][strlen($params['action']) - 1] == '/') {
       $params['action'] = substr($params['action'], 0, -1);
    }

    $url .= $params['action'];
    unset($params['action']);

    if(!empty ($params)) {
        foreach($params as $k => $v) {
            $url .= '/' . $k . '/' . $v;
        }
    }

    return $url;

}
?>