You are here

public function HeartbeatActivity::hasAccess in Heartbeat 7

hasAccess().

Parameters

Object $account: The User object to check access for.

HeartbeatStream $heartbeatStream: Optional heartbeat stream object where the account object is the viewer.

File

includes/heartbeatactivity.inc, line 225
HeartbeatActivity object Defines one heartbeat activity object.

Class

HeartbeatActivity
Class defines an activity message object

Code

public function hasAccess($account, $heartbeatStream = NULL) {

  // Case user1 is not related to userA and userB. UserA and UserB are related.
  // user1 views site activity.
  if (isset($heartbeatStream)) {
    $account = $heartbeatStream
      ->getViewer();
  }
  else {
    $heartbeatStream = heartbeat_stream('singleactivity');
  }
  $access_activity_profiles = user_access('access heartbeat activity profiles', $account);
  $access_profiles = user_access('access user profiles', $account);

  // Remove messages set private by site administrator
  // and remove messages set private by user profile setting.
  if ($this
    ->isPrivate() && $account->uid != $this->actor->uid) {
    $heartbeatStream
      ->addError('Activity message #' . $this->uaid . ' is filtered from display because it is a private message.');
    return FALSE;
  }

  // Replace user links with their name if no access.
  if ($access_activity_profiles) {
    if (!$access_profiles) {

      // TODO Think of a superb way to divide message templates into parts, bound to properties.
      // For now, let's try to keep the problem to a minimum.
      // Do some tricks to try and solve the problem of profile access from generated links.
      if (isset($this->variables['!username'])) {
        $this->message = str_replace($this->variables['!username'], $this->actor->name, $this->message);
      }
      elseif (isset($this->variables['!user'])) {
        $this->message = str_replace($this->variables['!user'], $this->actor->name, $this->message);
      }
      else {
        $link = l($this->actor->name, 'user/' . $this->actor->uid);
        $this->message = preg_replace("|{$link}|", $this->actor->name, $this->message);
      }
    }
  }
  return TRUE;
}