function _user_relationship_blocks_view in User Relationships 5.2
Same name and namespace in other branches
- 6 user_relationship_blocks/user_relationship_blocks.module \_user_relationship_blocks_view()
helper function user_relationship_blocks_block delegates to when $op == 'view'
1 call to _user_relationship_blocks_view()
- user_relationship_blocks_block in plugins/
user_relationship_blocks/ user_relationship_blocks.module - Implementation for hook_block
File
- plugins/
user_relationship_blocks/ user_relationship_blocks.module, line 157
Code
function _user_relationship_blocks_view($block_type, $rtid, $extra) {
global $user;
if (($block_type == UR_BLOCK_MY || $block_type == 'pending') && !$user->uid) {
return;
}
// determine which user's relationships to display
if (!($account = module_invoke_all('user_relationship_blocks', 'display', $block_type, $rtid, $extra))) {
if (($block_type == 'pending' || $block_type == UR_BLOCK_MY) && $user->uid) {
$account =& $user;
}
else {
// TODO: using the URL arguments like this is bad. find a better way
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
$account = user_load(array(
'uid' => $node->uid,
));
}
else {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$account = user_load(array(
'uid' => arg(1),
));
}
}
}
}
$function = "_user_relationship_blocks_view_{$block_type}";
if (function_exists($function)) {
return $function($account, $block_type, $rtid, $extra);
}
// select the appropriate set of relationships based on admin's configuration settings
switch (variable_get("user_relationships_block_{$block_type}_t_{$rtid}_sort", 'newest')) {
case 'newest':
$order = 'updated_at DESC';
break;
case 'oldest':
$order = 'updated_at ASC';
break;
case 'random':
$order = 'RAND()';
break;
}
$limit = variable_get("user_relationships_block_{$block_type}_t_{$rtid}_size", UR_BLOCK_DEFAULT_SIZE);
$key = $extra ? $extra == 'you_to_them' ? 'requester_id' : 'requestee_id' : 'user';
$args = array(
$key => $account->uid,
'approved' => TRUE,
);
if ($rtid != UR_BLOCK_ALL_TYPES) {
$args['rtid'] = $rtid;
}
$relationships = user_relationships_load($args, FALSE, 'rid', $order, $limit);
// get the content of the block
return theme('user_relationship_block', $account, $relationships, $block_type, $rtid, $extra);
}