You are here

function views_node_access_current_user in Views node access 7

Same name and namespace in other branches
  1. 6 views_node_access.module \views_node_access_current_user()

Current user access function for views hook menu.

1 string reference to 'views_node_access_current_user'
views_node_access_plugin_access_current_user::get_access_callback in ./views_node_access_plugin_access_current_user.inc
Determine the access callback and arguments.

File

./views_node_access.module, line 48
Views node access - hook implementations and access function for views hook_menu.

Code

function views_node_access_current_user() {
  global $user;
  if (!isset($user->uid) || !($user->uid > 0)) {
    return FALSE;
  }
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    return arg(1) == $user->uid;
  }
  if (arg(0) == 'admin') {

    // return true for administration paths, if not this breaks menu system
    return TRUE;
  }
  $view_user = NULL;
  foreach (range(1, 3) as $i) {
    $view_user = menu_get_object('user', $i);
    if (!empty($view_user)) {
      return $view_user->uid == $user->uid;
    }
  }
  foreach (range(1, 3) as $i) {
    $view_user = menu_get_object('user_uid_optional', $i);
    if (!empty($view_user)) {
      return $view_user->uid == $user->uid;
    }
  }

  /* @todo look for node creator?
    foreach (range(1, 3) as $i) {
      $node = menu_get_object('node', $i);
      if (!empty($node)) {
        return $node->uid;
      }
    }
    */
  return FALSE;
}