You are here

function scald_actions in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 scald.module \scald_actions()

Determine the Scald Actions Bitstring for a given Atom for a given User.

Parameters

$atom: A Scald Atom

$account: A Drupal user account Defaults to the current $user

Return value

A Scald Actions Bitstring FALSE if the Atom is invalid

3 calls to scald_actions()
scald_action_permitted in ./scald.module
Determines if a given User can act on a given Atom in a given way.
scald_prerender in ./scald.module
Prepare a Scald Atom for rendering
scald_render in ./scald.module
Render a Scald Atom

File

./scald.module, line 1989

Code

function scald_actions($atom, $account = NULL) {
  global $user;

  // Argument validation
  if (is_null($account)) {
    $account = $user;
  }

  // Default to Anonymous perms if no action bitstring is set.  Also handle the
  //  special subcase of the Anonymous user.
  //
  // NOTE: This is necessary because $user is *not* the result of a user_load()
  //  and so defaults must be defined at first use. Testing for the member's
  //  existance and then modifying the $user object directly (as appropriate)
  //  ensures that the cost of a query is saved the next time an access check is
  //  executed for the current user during this session.
  if (!isset($account->scald_actions)) {

    // Note that db_result() will conveniently fail to FALSE which will prohibit
    //  the user from completing *any* Actions.  Since the Admin interface only
    //  shows Roles which have the "use scald" permission (and therefore the
    //  {scald_role_actions} table only contains Roles which have that
    //  permission), checking for said permission is not necessary (thus saving
    //  a fairly expensive check).
    $account->scald_actions = db_result(db_query("\n      SELECT\n        actions\n      FROM\n        {scald_role_actions}\n      WHERE\n        rid = %d", DRUPAL_ANONYMOUS_RID));
    if ($account->uid == $user->uid) {
      $user->scald_actions = $account->scald_actions;
    }
  }

  // NOTE: Not using scald_is_fetched here because Action validation can (and
  //  should) be done prior to fetching.  However, it is assumed that this $atom
  //  is *at least* the result of a scald_is_registered() call.
  if (!is_object($atom) || !isset($atom->actions)) {
    return FALSE;
  }

  // The Account in question belongs to the Scald Publisher of this Atom
  if ($atom->publisher == $account->uid) {
    $account->scald_actions = $account->scald_actions | variable_get('scald_actions_publisher', 0);
  }

  // Check for the "admin bit" being set in *either* the Atom or the User Action
  //  bitstring and if it is set, OR the two rather than ANDing them.
  return $atom->actions & SCALD_ACTIONS_ADMIN_BIT || $account->scald_actions & SCALD_ACTIONS_ADMIN_BIT ? $atom->actions | $account->scald_actions : $atom->actions & $account->scald_actions;
}