You are here

function plus1_vote_access in Plus 1 6.2

Check that an item being voted upon is a valid vote.

Parameters

$type: Type of target (currently only node is supported).

$id: Identifier within the type (in this case nid).

$account: The user trying to cast the vote.

Return value

boolean to allow vote.

3 calls to plus1_vote_access()
plus1_block_view in ./plus1.module
Function for plus1_block(op = 'view').
plus1_nodeapi in ./plus1.module
Implements hook_nodeapi().
plus1_vote in ./plus1.module
Page callback.

File

./plus1.module, line 228
A simple +1 voting widget module.

Code

function plus1_vote_access($op, $node, $account = NULL) {
  global $user;
  if (!$node || !in_array($op, array(
    'view',
    '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;
  }

  // If no user object is supplied, the access check is for the current user.
  if (empty($account)) {
    $account = $user;
  }
  $vote_allow = TRUE;
  foreach (module_implements('plus1_access') as $module) {
    $status = module_invoke($module, 'plus1_access', $node, 'view', $user);
    if ($status === PLUS1_ACCESS_ALLOW) {
      break;
    }
    elseif ($status === PLUS1_ACCESS_DENY) {
      $vote_allow = FALSE;
      break;
    }
  }
  return $vote_allow;
}