function flickr_geo_permissions_photos_where($owner_id, $viewer_id = 0)
{
    if ($owner_id == $viewer_id) {
        return '';
    }
    $perms_map = flickr_geo_permissions_map('string keys');
    if ($viewer_id == 0) {
        $perms = array($perms_map['public']);
    } else {
        if ($contact = flickr_contacts_get_contact($owner_id, $viewer_id)) {
            $rel_map = flickr_contacts_relationship_map();
            $str_rel = $rel_map[$contact['rel']];
            $perms = array($perms_map['public'], $perms_map['contacts']);
            if ($str_rel == 'friends') {
                $perms[] = $perms_map['friends'];
                $perms[] = $perms_map['friends and family'];
            } else {
                if ($str_rel == 'family') {
                    $perms[] = $perms_map['family'];
                    $perms[] = $perms_map['friends and family'];
                } else {
                }
            }
        } else {
            $perms = array($perms_map['public']);
        }
    }
    return $perms;
}
function flickr_contacts_calculate_relationship(&$contact)
{
    $friend = $contact['friend'];
    $family = $contact['family'];
    $map = flickr_contacts_relationship_map('string keys');
    $rel = 0;
    if ($family && $friend) {
        $rel = $map['friends and family'];
    } else {
        if ($family) {
            $rel = $map['family'];
        } else {
            if ($friend) {
                $rel = $map['friends'];
            } else {
                $rel = $map['contact'];
            }
        }
    }
    # echo "{$contact_username} ({$flickr_contact['user_id']}) fr:{$friend} fa:{$family} rel:{$rel}\n";
    return $rel;
}