views_node_access.module in Views node access 7
Same filename and directory in other branches
Views node access - hook implementations and access function for views hook_menu.
File
views_node_access.moduleView source
<?php
/**
* @file
* Views node access - hook implementations and access function for views hook_menu.
*/
/**
* Implements hook_views_api().
*/
function views_node_access_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'views_node_access'),
);
}
/**
* Node type access function for views hook menu.
*/
function views_node_access_check_node_type($types = array(), array $pre_callback = array()) {
$access = TRUE;
if (!empty($pre_callback)) {
$function_name = array_shift($pre_callback);
if (function_exists($function_name)) {
$access = call_user_func_array($function_name, $pre_callback);
}
}
if (!$access) {
return $access;
}
if (arg(0) != 'node' || !is_numeric(arg(1))) {
return FALSE;
}
$node = node_load(arg(1));
if (in_array($node->type, $types)) {
return TRUE;
}
return FALSE;
}
/**
* Current user access function for views hook menu.
*/
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;
}
Functions
Name | Description |
---|---|
views_node_access_check_node_type | Node type access function for views hook menu. |
views_node_access_current_user | Current user access function for views hook menu. |
views_node_access_views_api | Implements hook_views_api(). |