本文整理汇总了PHP中node_access函数的典型用法代码示例。如果您正苦于以下问题:PHP node_access函数的具体用法?PHP node_access怎么用?PHP node_access使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了node_access函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _groupadmin_user_has_role
/**
* Test if user has the specified groupadmin role, or return array of all roles.
*/
function _groupadmin_user_has_role($group_node = null, $user = null, $role = null)
{
// All posssible roles in order of decreasing access.
$all_roles = array('manager', 'admins', 'members', 'visitors');
// If no group was specified, return array of all possible roles.
if (!$group_node) {
return $all_roles;
}
// Check for explicit permission.
if (_groupadmin_user_access($role)) {
return TRUE;
}
// Test status...
switch ($role) {
case 'manager':
$has_role = $user->uid == $group_node->uid;
break;
case 'admins':
$has_role = og_is_group_admin($group_node, $user);
break;
case 'members':
$has_role = _groupadmin_is_group_member($group_node->nid, $user->uid);
break;
case 'visitors':
$has_role = node_access('view', $group_node, $user);
break;
default:
$has_role = FALSE;
}
return $has_role;
}
示例2: mooc_foundation_access_preprocess_page
/**
* Implements template_preprocess_page.
*/
function mooc_foundation_access_preprocess_page(&$variables)
{
// speedreader is enabled
if (module_exists('speedreader')) {
$variables['speedreader'] = TRUE;
}
// mespeak is enabled
if (module_exists('mespeak')) {
$variables['mespeak'] = TRUE;
}
// support for add child page shortcut
$node = menu_get_object();
if ($node && user_access('access printer-friendly version')) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Print'), 'book/export/html/' . arg(1));
}
$child_type = variable_get('book_child_type', 'book');
if ($node && !empty($node->book) && (user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && isset($node->book['depth']) && $node->book['depth'] < MENU_MAX_DEPTH) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Add child page'), 'node/add/' . str_replace('_', '-', $child_type), array('query' => array('parent' => $node->book['mlid'])));
}
if (user_access('access contextual links')) {
$variables['tabs_extras'][0][] = '<li class="cis_accessibility_check"></li>';
}
}
示例3: _nodereferrer_create_add_reference_form_submit
/**
* Submit the form to add to an existing node
*/
function _nodereferrer_create_add_reference_form_submit($form, &$form_state)
{
if ($form_state['clicked_button']['#name'] != 'add') {
drupal_set_message(t('The operation was cancelled'));
drupal_goto('node/' . arg(1));
return;
}
$append_node = node_load($form_state['values']['referrence']);
$current_node = node_load(arg(1));
// Make sure the user is allowed to do this.
if (!node_access('update', $current_node)) {
drupal_set_message(t('You do not have rights to update this node'));
drupal_goto('node/' . arg(1));
return;
}
$field_name = $current_node->reference_fields[arg(3)]['field_name'];
$field_array =& $current_node->{$field_name};
$multiple = $current_node->reference_fields[arg(3)]['multiple'] == 1;
if ($field_array[0]['nid'] === null || !$multiple) {
$field_array[0]['nid'] = $append_node->nid;
} else {
$field_array[] = array('nid' => $append_node->nid);
}
// Save, and ensure the changes are noticed
node_save($current_node);
cache_clear_all();
drupal_set_message(t('The node was added'));
drupal_goto('node/' . arg(1));
}
示例4: mooc_foundation_access_preprocess_page
/**
* Implements template_preprocess_page.
*/
function mooc_foundation_access_preprocess_page(&$variables)
{
// speedreader is enabled
if (module_exists('speedreader')) {
$variables['speedreader'] = TRUE;
}
// mespeak is enabled
if (module_exists('mespeak')) {
$variables['mespeak'] = TRUE;
}
// support for add child page shortcut
$node = menu_get_object();
if ($node && user_access('access printer-friendly version')) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Print'), 'book/export/html/' . arg(1));
}
$child_type = variable_get('book_child_type', 'book');
if ($node && !empty($node->book) && (user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && isset($node->book['depth']) && $node->book['depth'] < MENU_MAX_DEPTH) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Add child page'), 'node/add/' . str_replace('_', '-', $child_type), array('query' => array('parent' => $node->book['mlid'])));
}
if (user_access('access contextual links')) {
$variables['tabs_extras'][0][] = '<li class="cis_accessibility_check"></li>';
}
// remove the prefix that provides a link to the home page
// as MOOC is the thing that currently provides support directly for this
// and slightly overrides the behavior
$keys = array_keys($variables['page']['header']);
$keyname = array_shift($keys);
unset($variables['page']['header'][$keyname]['#prefix']);
}
示例5: hook_publishcontent_unpublish_access
/**
* Allow other modules the ability to modify access to the unpublish controls.
*
* Modules may implement this hook if they want to have a say in whether or not
* a given user has access to perform unpublish action on a node.
*
* @param node $node
* A node object being checked
* @param user $account
* The user wanting to unpublish the node.
*
* @return bool|NULL
* TRUE - if the user should access return TRUE
* FALSE - if the user definetley should not access return FALSE
* NULL - This module wan't change the outcome. It is typically
* better to return NULL than FALSE. If no module returns TRUE
* then the user will be denied access. If one module returns
* FALSE then the user will denied even if another module returns
* TRUE.
*/
function hook_publishcontent_unpublish_access($node, $account)
{
$access = $node->status && (user_access('administer nodes') || user_access('unpublish any content') || user_access('unpublish own content') && $user->uid == $node->uid || user_access('unpublish editable content') && node_access('update', $node) || user_access('unpublish own ' . check_plain($node->type) . ' content', $user) && $user->uid == $node->uid || user_access('unpublish any ' . check_plain($node->type) . ' content') || user_access('unpublish editable ' . check_plain($node->type) . ' content') && node_access('update', $node));
if ($access) {
return TRUE;
}
}
示例6: _nodereferrer_create_get_referrers
/**
* Helper function : given a node, return the list of referrers the
* current user is allowed to create as an array defining :
*
* 'name' : Name of the referrer field
* 'field' : Details of the referer field
* 'referrence' : Detail of the reference field
*
*/
function _nodereferrer_create_get_referrers($node)
{
$list = array();
if (!variable_get('nodereferrer_create_show_on_nodereferrer', 1)) {
return $list;
}
$type = content_types($node->type);
foreach ($type['fields'] as $name => $field) {
if ($field['type'] != 'nodereferrer' || !is_array($field['referrer_types'])) {
continue;
}
foreach (array_filter($field['referrer_types']) as $reftype) {
if (!node_access('create', $reftype)) {
continue;
}
$with_field = array();
foreach (array_filter($field['referrer_fields']) as $reffield) {
$cf = content_fields($reffield, $reftype);
if ($cf) {
$with_field[$reftype][] = $cf;
}
}
if (count($with_field) == 0) {
continue;
}
$list[] = array('name' => substr($name, strlen('field_')), 'field' => $field, 'referrence' => $with_field);
}
}
return $list;
}
示例7: canEdit
private function canEdit()
{
$node = $this->getNode();
if ($node) {
return node_access('update', $node);
} else {
return node_access('create', $node);
}
}
示例8: have_access
/**
* Check view and edit permissions.
*
* @param $op
* The type of operation. Either 'view' or 'edit'.
*/
function have_access($op)
{
global $user;
$db = DBConnection::instance();
$field_id = (int) _post('fid');
if (!$field_id) {
$field_id = (int) _get('fid');
}
$field = (object) $db->dq("SELECT entity_id, entity_type, delta FROM {mytinytodo_fields} WHERE id = ?", $field_id)->fetch_assoc();
$field_info = field_info_field_by_id($field->delta);
if ($field->entity_type == 'node') {
if (!($node = node_load($field->entity_id))) {
return false;
}
$node_access = $op == 'edit' ? 'update' : $op;
if (node_access($node_access, $node, $user) && field_access($op, $field_info, $field->entity_type, $node, $user)) {
return true;
}
} else {
if ($field->entity_type == 'user') {
if (!($account = user_load($field->entity_id))) {
return false;
}
if (field_access($op, $field_info, $field->entity_type, $account, $user)) {
return true;
}
} else {
if ($field->entity_type == 'comment') {
if (!($comment = comment_load($field->entity_id))) {
return false;
}
if ($op == 'view' && !user_access('access comments')) {
return false;
} else {
if ($op == 'edit' && !comment_access($op, $comment)) {
return false;
}
}
if (field_access($op, $field_info, $field->entity_type, $comment, $user)) {
return true;
}
} else {
if (module_exists('entity')) {
if (!($entity = entity_load($field_id))) {
return false;
}
$entity_access = $op == 'edit' ? 'update' : $op;
if (entity_access($entity_access, $field->entity_type, $entity, $user) && field_access($op, $field_info, $field->entity_type, $entity, $user)) {
return true;
}
}
}
}
}
return false;
}
示例9: hook_workbench_block
/**
* Return Workbench status information in a block.
*
* To reduce clutter, modules are encouraged to use this hook
* to provide debugging and other relevant information.
*
* @return
* An array of message strings to print. The preferred format
* is a one line string in the format Title: <em>Message</em>.
* @see workbench_block_view().
*/
function hook_workbench_block()
{
// Add editing information to this page (if it's a node).
if ($node = menu_get_object()) {
if (node_access('update', $node)) {
return array(t('My Module: <em>You may not edit this content.</em>'));
} else {
return array(t('My Module: <em>You may edit this content.</em>'));
}
}
}
示例10: hook_publishcontent_unpublish_access
/**
* Allow other modules the ability to modify access to the unpublish controls.
*
* Modules may implement this hook if they want to have a say in whether or not
* a given user has access to perform unpublish action on a node.
*
* @param node $node
* A node object being checked
* @param user $account
* The user wanting to unpublish the node.
*
* @return bool|NULL
* PUBLISHCONTENT_ACCESS_ALLOW - if the user can unpublish the node.
* PUBLISHCONTENT_ACCESS_DENY - if the user definetley cannot unpublish.
* PUBLISHCONTENT_ACCESS_IGNORE - This module wan't change the outcome.
* It is typically better to return IGNORE than DENY. If no module returns
* ALLOW then the user will be denied access. If one module returns
* DENY then the user will denied even if another module returns
* ALLOW.
*/
function hook_publishcontent_unpublish_access($node, $account)
{
$access = $node->status && (user_access('administer nodes') || user_access('unpublish any content') || user_access('unpublish own content') && $user->uid == $node->uid || user_access('unpublish editable content') && node_access('update', $node) || user_access('unpublish own ' . check_plain($node->type) . ' content', $user) && $user->uid == $node->uid || user_access('unpublish any ' . check_plain($node->type) . ' content') || user_access('unpublish editable ' . check_plain($node->type) . ' content') && node_access('update', $node));
if ($access) {
// The user is allowed to unpublish the node according to this hook.
// If another hook denys access they will be denied.
return PUBLISHCONTENT_ACCESS_ALLOW;
}
// This function does not believe they can publish but is
// not explicitly denying access to publish. If no other hooks
// allow it then the user will be denied.
return PUBLISHCONTENT_ACCESS_IGNORE;
}
示例11: setNodeValue
public static function setNodeValue()
{
// Gather URL parameters.
$nid = isset($_GET['nid']) ? intval($_GET['nid']) : null;
$field = isset($_GET['f']) ? $_GET['f'] : null;
$value = isset($_GET['v']) ? $_GET['v'] : null;
// Validate parameters and coerce types as needed.
switch ($field) {
case 'sharing':
switch ($value) {
case 'public':
$value = 1;
break;
case 'private':
$value = 0;
break;
default:
$value = null;
break;
}
break;
default:
$field = null;
break;
}
if (!isset($nid) || !isset($field) || !isset($value)) {
throw new Exception(t('Invalid method parameters.'));
}
// Load the node and perform update access check.
require_once DRUPAL_ROOT . '/includes/common.inc';
module_load_include('module', 'node');
module_load_include('inc', 'field', 'field.attach');
module_load_include('module', 'user');
$node = node_load($nid);
if (!node_access('update', $node)) {
throw new Exception('User does not have access to nid ' . $nid, 403);
}
// Set the appropriate node fields.
switch ($field) {
case 'sharing':
$node->status = $value;
break;
}
// Save the node.
node_save($node);
die('ok');
}
示例12: getReferencableEntities
/**
* Implements EntityReferenceHandler::getReferencableEntities().
*/
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0)
{
$gid = oa_core_get_space_context();
$space = node_load($gid);
$type = variable_get_value('oa_worktracker_assigned_to_users');
if ($type === OA_WORKTRACKER_ASSIGN_TO_INHERITED_USERS && !module_exists('oa_subspaces')) {
$type = OA_WORKTRACKER_ASSIGN_TO_ONLY_LOCAL_USERS;
}
$uids = array();
switch ($type) {
case OA_WORKTRACKER_ASSIGN_TO_INHERITED_USERS:
$uids = og_subgroups_get_users_group('node', $space);
$uids = $uids['user'];
$inherited = _og_subgroups_get_inherited_users('node', $gid);
foreach ($inherited as $inherited_uid => $data) {
$uids[] = $inherited_uid;
}
break;
case OA_WORKTRACKER_ASSIGN_TO_ONLY_LOCAL_USERS:
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'og_membership')->propertyCondition('group_type', 'node', '=')->propertyCondition('gid', $gid, '=')->propertyCondition('entity_type', 'user', '=')->propertyCondition('state', OG_STATE_ACTIVE, '=');
$result = $query->execute();
if (!empty($result['og_membership'])) {
$og_memberships = og_membership_load_multiple(array_keys($result['og_membership']));
foreach ($og_memberships as $og_membership) {
$uids[] = $og_membership->etid;
}
}
break;
case OA_WORKTRACKER_ASSIGN_TO_ANY_USERS:
$query = db_select('users', 'u')->fields('u', array('uid'))->condition('status', 1);
$uids = $query->execute()->fetchCol();
break;
}
$options = array('user' => array());
if (!empty($uids)) {
// Get the user label and make sure that the user can access the space.
$users = user_load_multiple($uids);
foreach ($users as $uid => $account) {
if (node_access('view', $space, $account)) {
$options['user'][$uid] = check_plain($this->getLabel($account));
}
}
asort($options['user']);
}
return $options;
}
开发者ID:cesardmoro,项目名称:openatrium-2-quickstart,代码行数:50,代码来源:OaWorkTracker_SelectionHandler_Assigned.class.php
示例13: mooc_foundation_access_preprocess_page
/**
* Implements template_preprocess_page.
*/
function mooc_foundation_access_preprocess_page(&$variables)
{
// speedreader is enabled
if (module_exists('speedreader')) {
$variables['speedreader'] = TRUE;
}
// drop some tabs that don't seem to go away on their own
if (isset($variables['tabs']['#primary']) && !empty($variables['tabs']['#primary'])) {
foreach ($variables['tabs']['#primary'] as $key => $value) {
if (in_array($value['#link']['path'], array('node/%/display', 'node/%/outline', 'node/%/log'))) {
unset($variables['tabs']['#primary'][$key]);
}
}
// fornow drop secondary entirely for nodes
if (arg(0) == 'node' && isset($variables['tabs']['#secondary'])) {
unset($variables['tabs']['#secondary']);
}
}
$child_type = variable_get('book_child_type', 'book');
$node = menu_get_object();
if ($node && !empty($node->book) && (user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && isset($node->book['depth']) && $node->book['depth'] < MENU_MAX_DEPTH) {
$variables['tabs_extras'][200][] = '<div class="divider"></div>';
$variables['tabs_extras'][200][] = '<span class="nolink cis-lmsless-text">' . t('Operations') . '</strong>';
$variables['tabs_extras'][200][] = l(t('Edit child outline'), 'node/' . $node->book['nid'] . '/outline/children');
$variables['tabs_extras'][200][] = l(t('Edit course outline'), 'admin/content/book/' . $node->book['bid']);
}
// support hiding the accessibility check UI which is poorly located
if ($node && user_access('view accessibility tests')) {
$variables['tabs_extras'][200][] = '<span class="cis_accessibility_check"></span>';
}
// remove the prefix that provides a link to the home page
// as MOOC is the thing that currently provides support directly for this
// and slightly overrides the behavior
$keys = array_keys($variables['page']['header']);
$keyname = array_shift($keys);
unset($variables['page']['header'][$keyname]['#prefix']);
// Remove title from a page when a gitbook markdown filter is present.
if (isset($variables['page']['content']['system_main']['nodes'])) {
foreach ($variables['page']['content']['system_main']['nodes'] as $node) {
if (isset($node['body']['#object'])) {
if ($node['body']['#object']->body['und'][0]['format'] == "git_book_markdown") {
$variables['title'] = "";
}
}
}
}
}
示例14: hook_message_access_alter
/**
* Allow modules to alter access granted to a message entity.
* @param $access
* Boolean specifying whether the specifified account has the specified access.
* @param context
* Array containing relevant information for determining access to
* the message entity. Keys are op, entity, entity_type, and account.
*/
function hook_message_access_alter(&$access, $context)
{
// We're only interested in the 'view' operation.
if ($context['op'] != 'view') {
return;
}
$message = $context['entity'];
// Verify view access to nodes referenced in the message.
if (isset($message->field_target_nodes)) {
foreach ($message->field_target_nodes[LANGUAGE_NONE] as $key => $value) {
$node = node_load($value['target_id']);
if (!node_access('view', $node, $context['account'])) {
// If the user cannot view any nodes in the message,
// deny access to the entire message;
$access = FALSE;
return;
}
}
}
}
示例15: _nodereferrer_create_add_form_submit
/**
* Submit the form to add to an existing node
*/
function _nodereferrer_create_add_form_submit($form, &$form_state)
{
if ($form_state['clicked_button']['#name'] != 'add') {
drupal_set_message(t('The operation was cancelled'));
drupal_goto('node/' . arg(1));
}
$append_node = node_load($form_state['values']['referrence']);
// Make sure the user is allowed to do this
if (!node_access('update', $append_node)) {
drupal_set_message(t('You do not have rights to update this node'));
drupal_goto('node/' . arg(1));
return;
}
$current_node = node_load(arg(1));
$field = $current_node->referrers[arg(3)]['referrence'][arg(4)][arg(5)]['field_name'];
array_push($append_node->{$field}, array('nid' => $current_node->nid));
// Save, and ensure the changes are noticed
node_save($append_node);
cache_clear_all();
drupal_set_message(t('The node was added'));
drupal_goto('node/' . arg(1));
}