Drupal API

node_access

  • Drupal 5
  • Drupal 6
Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

modules/node/node.module, строка 1992

Версии
5
node_access($op, $node = NULL)
6
node_access($op, $node, $account = NULL)

Устанавливает, может ли текущий пользователь выполнять заданные действия над определённой нодой.

Параметры

$op Действие, выполняющееся над нодой. Возможные значения:

  • 'view'
  • 'update'
  • 'delete'
  • 'create'
$node Объект ноды (или массив ноды), над которой выполняется действие, или тип ноды (напр., 'forum') для операции 'create'.

$account Необязательный аргумент. Объект пользователя, представляющий пользователя, от имени которого совершается действие. Определяет доступ для пользователя, отличного от текущего.

Возвращаемое значение

TRUE, если действие может выполняться.

Связанные темы

▸ 18 функции вызывают node_access()

▾ 18 функции вызывают node_access()

blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Коллбэк Blogging API. Модифицирует указанную ноду блога.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Коллбэк Blogging API. Вставляет новую запись блога как ноду.
blogapi_mt_publish_post in modules/blogapi/blogapi.module
Коллбэк Blogging API. Публикует данную ноду.
book_link in modules/book/book.module
Реализация hook_link().
node_add in modules/node/node.pages.inc
Выводит форму подтверждения ноды или ряд ссылок на такие формы.
node_delete in modules/node/node.module
Удаляет ноду.
node_form in modules/node/node.pages.inc
Генерирует нод, добавляет/редактирует массив формы.
node_preview in modules/node/node.pages.inc
Generate a node preview.
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
template_preprocess_forums in modules/forum/forum.module
Process variables for forums.tpl.php
translation_nodeapi in modules/translation/translation.module
Implementation of hook_nodeapi().
translation_node_overview in modules/translation/translation.pages.inc
Overview page for a node's translations.
upload_file_download in modules/upload/upload.module
Implementation of hook_file_download().
_blogapi_get_node_types in modules/blogapi/blogapi.module
_book_outline_access in modules/book/book.module
Menu item access callback - determine if the outline tab is accessible.
_node_add_access in modules/node/node.module
_node_revision_access in modules/node/node.module
_translation_tab_access in modules/translation/translation.module
Menu access callback.

Код

<?php
function node_access($op, $node, $account = 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 no user object is supplied, the access check is for the current user.
  if (empty($account)) {
    $account = $user;
  }
  // If the node is in a restricted format, disallow editing.
  if ($op == 'update' && !filter_access($node->format)) {
    return FALSE;
  }
  if (user_access('administer nodes', $account)) {
    return TRUE;
  }
  if (!user_access('access content', $account)) {
    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, $account);
  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, $account) 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' && $account->uid == $node->uid && $account->uid != 0) {
    return TRUE;
  }
  return FALSE;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему

Что такое OpenID?
  • Регистрация
  • Забыли пароль?

Документация

  • Drupal 6
  • Константы
  • Файлы
  • Функции
  • Глобальные переменные
  • Разделы