node_access
modules/node/node.module, строка 2752
- Версии
- 5
node_access($op, $node = NULL)
- 6
node_access($op, $node, $account = NULL)
Устанавливает может ли текущий пользователь выполнять заданные действия на определённом ноде.
Параметры
$op
Действие выполняющиеся на ноде. Возможные значения:
'view'
'update'
'delete'
'create'
$node
нод объект (или массив нода) на котором действие выполняется, или тип нода (напр. 'forum'
) для операции 'create'
.
Возвращаемое значение
TRUE
, если действие может выполняться.
Связанные темы
Код
<?php
function node_access($op, $node = NULL) {
global $user;
if (!$node || !in_array($op, array('view', 'update', 'delete', 'create'), TRUE)) {
// If there was no node to check against, or the $op was not one of the
// supported ones, we return access denied.
return FALSE;
}
// Convert the node to an object if necessary:
if ($op != 'create') {
$node = (object)$node;
}
// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
return FALSE;
}
if (user_access('administer nodes')) {
return TRUE;
}
if (!user_access('access content')) {
return FALSE;
}
// Can't use node_invoke(), because the access hook takes the $op parameter
// before the $node parameter.
$module = node_get_types('module', $node);
if ($module == 'node') {
$module = 'node_content'; // Avoid function name collisions.
}
$access = module_invoke($module, 'access', $op, $node);
if (!is_null($access)) {
return $access;
}
// If the module did not override the access rights, use those set in the
// node_access table.
if ($op != 'create' && $node->nid && $node->status) {
$grants = array();
foreach (node_access_grants($op) as $realm => $gids) {
foreach ($gids as $gid) {
$grants[] = "(gid = $gid AND realm = '$realm')";
}
}
$grants_sql = '';
if (count($grants)) {
$grants_sql = 'AND ('. implode(' OR ', $grants) .')';
}
$sql = "SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) $grants_sql AND grant_$op >= 1";
$result = db_query($sql, $node->nid);
return (db_result($result));
}
// Let authors view their own nodes.
if ($op == 'view' && $user->uid == $node->uid && $user->uid != 0) {
return TRUE;
}
return FALSE;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии