You are here

function user_relationship_blocks_block_view in User Relationships 7

helper function user_relationship_blocks_block delegates to when $op == 'view'

File

user_relationship_blocks/user_relationship_blocks.module, line 183
User Relationship Blocks implementation @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217

Code

function user_relationship_blocks_block_view($delta) {
  global $user;

  //pad array with nulls before calling list() to avoid php notices
  $exploded = explode(UR_BLOCK_SEPARATOR, $delta);
  while (count($exploded) < 3) {
    $exploded[] = NULL;
  }
  list($block_type, $rtid, $extra) = $exploded;
  $is_my_block = $block_type == UR_BLOCK_MY || in_array($block_type, array(
    'pending',
  ));
  if ($is_my_block && !$user->uid) {
    return;
  }
  $settings = user_relationship_blocks_block_save($delta);
  $settings->rtid = $rtid;
  $settings->block_type = $block_type;

  // determine which user's relationships to display
  if ($is_my_block) {

    // Only allow access if the user has permissions to view his own
    // relationships.
    if (user_relationships_ui_check_access('view', $user, user_relationships_type_load($rtid))) {
      $account = $user;
    }
  }
  elseif ($uid = _user_relationship_blocks_get_uid($delta)) {
    $account_loaded = user_load($uid);
    if ($account_loaded && user_relationships_ui_check_access('view', $account_loaded, user_relationships_type_load($rtid))) {
      $account = $account_loaded;
    }
  }
  if (!empty($account)) {
    $add_to_string = in_array($block_type, array(
      'pending',
      'actions',
    )) ? "_{$block_type}" : '';
    return array(
      'subject' => theme('user_relationship_block_subject', array(
        'bid' => $delta,
        'account' => $account,
        'rtid' => $rtid,
        'extra' => $extra,
      )),
      'content' => theme("user_relationships{$add_to_string}_block", array(
        'account' => $account,
        'settings' => $settings,
        'extra' => $extra,
      )),
    );
  }
}