function smartyUrl($parameters, $smarty)
{
if (!isset($parameters['context'])) {
// Extract the variables named in $paramList, and remove them
// from the parameters array. Variables remaining in params will be
// passed along to Request::url as extra parameters.
$context = array();
$application = PKPApplication::getApplication();
$contextList = $application->getContextList();
foreach ($contextList as $contextName) {
if (isset($parameters[$contextName])) {
$context[$contextName] = $parameters[$contextName];
unset($parameters[$contextName]);
} else {
$context[$contextName] = null;
}
}
$parameters['context'] = $context;
}
// Extract the reserved variables named in $paramList, and remove them
// from the parameters array. Variables remaining in parameters will be passed
// along to Request::url as extra parameters.
$paramList = array('params', 'router', 'context', 'page', 'component', 'op', 'path', 'anchor', 'escape');
foreach ($paramList as $parameter) {
if (isset($parameters[$parameter])) {
${$parameter} = $parameters[$parameter];
unset($parameters[$parameter]);
} else {
${$parameter} = null;
}
}
// Merge parameters specified in the {url paramName=paramValue} format with
// those optionally supplied in {url params=$someAssociativeArray} format
$parameters = array_merge($parameters, (array) $params);
// Set the default router
if (is_null($router)) {
if (is_a($this->_request->getRouter(), 'PKPComponentRouter')) {
$router = ROUTE_COMPONENT;
} else {
$router = ROUTE_PAGE;
}
}
// Check the router
$dispatcher = PKPApplication::getDispatcher();
$routerShortcuts = array_keys($dispatcher->getRouterNames());
assert(in_array($router, $routerShortcuts));
// Identify the handler
switch ($router) {
case ROUTE_PAGE:
$handler = $page;
break;
case ROUTE_COMPONENT:
$handler = $component;
break;
default:
// Unknown router type
assert(false);
}
// Let the dispatcher create the url
return $dispatcher->url($this->_request, $router, $context, $handler, $op, $path, $parameters, $anchor, !isset($escape) || $escape);
}