function _render_friends($scope) {
	$section = ($scope == 'internal') ? 'friends' : 'friends_ext';
	$section_singular = $this->section_singular_names[$section];
	$page = (int)@$_REQUEST['friend_page'];
	$friend_state =& $this->state[$section];

	// paging controls
	$total_friends = Relation::count_relations($this->user->user_id, $scope);
	$total_pages = (int)ceil((float)$total_friends / $this->friends_per_page);
	if ($page > $total_pages) $page = $total_pages;
	if ($page < 1) $page = 1;
	$paging = "Show page: ";
	for ($i = 1; $i < $total_pages+1; ++$i) {
	  if ($i == $page) {
	    $paging .= "$i ";
	  } else {
	    $paging .= "<a href=\"javascript:badge.reload_section('badge_$section', '$this->url/$this->badge_tag/$section?friend_page=$i');\">$i</a> ";
	  }
	}
	$first_friend = ($page-1)*$this->friends_per_page + 1;
	$last_friend = min($first_friend + $this->friends_per_page - 1, $total_friends);
	$paging .= "(showing $first_friend-$last_friend of $total_friends friends)";

	// 'showing XXX' link
	$showing = $this->make_showing_link($friend_state, $section, "friend_page=$page");

	// facewall display
	$facewall = "";
	foreach (Relation::get_all_relations($this->user->user_id, 0, FALSE, $this->friends_per_page, $page, 'created', 'desc', $scope) as $rel) {
	    $facewall .= '<div id="'.$section_singular.'_'.($scope == 'internal' ? $rel['user_id'] : md5($rel['user_id'])).'">'.$this->render_friend_image($rel, $scope).'</div>';
	}

	// outer template
	return <<<ENS
<p>$showing</p>

<!--<p>How many items to show at once: <select id="item_count" onchange="badge.update()">
<option value="5">5</option>
<option value="10">10</option>
<option value="15" selected="selected">15</option>
<option value="20">20</option>
</select></p>-->

<div>
$facewall
<div style="clear: both"></div>
</div>

<p>$paging</p>
ENS;
    }
function peopleaggregator_getUserRelations($args)
{
    $login = $args['login'];
    $page = $args['page'];
    $perpage = $args['resultsPerPage'];
    //	$detail = $args['detailLevel'];
    $imageSize = $args['profileImageSize'];
    if (preg_match("/^(\\d+)x(\\d+)\$/", $imageSize, $m)) {
        $imageWidth = (int) $m[1];
        $imageHeight = (int) $m[2];
    } else {
        $imageWidth = $imageHeight = 0;
    }
    // look up user ID
    $user = new User();
    $user->load($login);
    $total = Relation::count_relations($user->user_id);
    $total_pages = api_n_pages($total, $perpage);
    $relations_out = array();
    foreach (Relation::get_all_relations($user->user_id, 0, FALSE, $perpage, $page) as $rel) {
        $rel_out = array('id' => 'user:'******'user_id'], 'login' => $rel['login_name'], 'relation' => $rel['relation_type'], 'url' => PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $rel['user_id']);
        $img_info = api_resize_user_image($rel['picture'], $imageWidth, $imageHeight);
        if ($img_info) {
            $rel_out['image'] = $img_info;
        }
        $relations_out[] = $rel_out;
    }
    if (sizeof($relations_out)) {
        $first = ($page - 1) * $perpage + 1;
        $msg = "Retrieved relations {$first}-" . ($first + sizeof($relations_out)) . " of {$total} for user {$user->login_name}.";
    } else {
        $msg = "Retrieved zero relations.";
        if ($page > $total_pages) {
            $msg .= "  Try specifying a page number between 1 and {$total_pages}.";
        }
    }
    return array('success' => TRUE, 'msg' => $msg, 'login' => $user->login_name, 'totalPages' => $total_pages, 'resultsPerPage' => $perpage, 'totalResults' => $total, 'page' => $page, 'relations' => $relations_out);
}