function _menu_access($item, $map, $direction = MENU_INCOMING) {
$path = '';
// Check if there are dynamic arguments in the path that need to be calculated.
if ($item->replacements) {
$replacements = unserialize($item->replacements);
$path_map = ($direction == MENU_INCOMING) ? $map : explode('/', $item->path);
foreach ($replacements as $index => $function) {
// Translate place-holders into real values; for example, translate [user_current] to 5.
if ($direction == MENU_OUTGOING) {
if ($return = $function(MENU_OUTGOING, !empty($map[$index]) ? $map[$index] : '')) {
$path_map[$index] = $return;
}
}
// Map replacement value to callback function.
$return = $function(MENU_INCOMING, !empty($path_map[$index]) ? $path_map[$index] : '');
// If callback returned an error, trigger 404.
if ($return === FALSE) {
return array(FALSE, FALSE, '');
}
$map[$index] = $return;
}
if ($direction == MENU_OUTGOING ) {
$path = implode('/', $path_map);
}
}
$callback = $item->access_callback;
// Check for TRUE and FALSE.
if (is_numeric($callback)) {
return array($callback, $map, $path);
}
$arguments = menu_unserialize($item->access_arguments, $map);
// As call_user_func_array is quite slow and user_access is a very common
// callback, it is worth making a special case for it.
if ($callback == 'user_access') {
$access = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]);
return array($access, $map, $path);
}
return array(call_user_func_array($callback, $arguments), $map, $path);
}