All pastes #335837 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-02-01 17:12 UTC
rendered paste body
function _menu_access($item, $map, $direction = MENU_INCOMING) {
  $path = '';
  if ($item->replacements) {
    $replacements = unserialize($item->replacements);
    $path_map = ($direction == MENU_INCOMING) ? $map : explode('/', $item->path);
    foreach ($replacements as $index => $function) {
      // Create a real path.
      if ($direction == MENU_OUTGOING) {
        if ($return = $function(MENU_OUTGOING, !empty($map[$index]) ? $map[$index] : '')) {
          $path_map[$index] = $return;
        }
      }
      // We now have a real path regardless of direction, map it.
      $return = $function(MENU_INCOMING, !empty($path_map[$index]) ? $path_map[$index] : '');
      if ($return === FALSE) {
        return array(FALSE, FALSE, '');
      }
      $map[$index] = $return;
    }
    if ($direction == MENU_OUTGOING ) {
      $path = implode('/', $path_map);
    }
  }
  $callback = $item->access_callback;
  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);
}