function api_flickr_favorites_add()
{
    $flickr_user = api_utils_flickr_ensure_token_perms($GLOBALS['cfg']['user'], 'write');
    $photo_id = post_int64("photo_id");
    if (!$photo_id) {
        api_output_error(999, "Missing photo ID");
    }
    # just silently ignore things that have already been faved
    if (!flickr_faves_is_faved_by_user($GLOBALS['cfg']['user'], $photo_id)) {
        $method = 'flickr.favorites.add';
        $args = array('photo_id' => $photo_id, 'auth_token' => $flickr_user['auth_token']);
        $rsp = flickr_api_call($method, $args);
        if (!$rsp['ok'] && $rsp['error_code'] != 3) {
            api_output_error(999, $rsp['error']);
        }
    }
    $out = array('photo_id' => $photo_id);
    api_output_ok($out);
}
function flickr_photos_permissions_can_view_photo(&$photo, $viewer_id = 0, $more = array())
{
    if ($viewer_id && $photo['user_id'] == $viewer_id) {
        return 1;
    }
    $perms_map = flickr_photos_permissions_map();
    $perms = $perms_map[$photo['perms']];
    if (!$viewer_id && $perms == 'public') {
        return 1;
    }
    if ($perms == 'public') {
        return 1;
    }
    if ($contact = flickr_contacts_get_contact($photo['user_id'], $viewer_id)) {
        $rel_map = flickr_contacts_relationship_map();
        $str_rel = $rel_map[$contact['rel']];
        if ($perms == 'friends' || $perms == 'family') {
            return $str_rel == $perms ? 1 : 0;
        }
        if ($perms == 'friends and family') {
            return in_array($str_rel, array('friends', 'family')) ? 1 : 0;
        }
    }
    # Note: this is predicated on the assumption that the user
    # actually has permissions to view the photo otherwise the
    # backup/import code would not have downloaded the photo; the
    # problem is not a flickr permissions issue but due to the
    # fact that the photo owner is not a registered parallel-flickr
    # user and hence their contact list is not present.
    # (20120607/straup)
    if ($viewer_id && isset($more['allow_if_is_faved'])) {
        loadlib("flickr_faves");
        $viewer = users_get_by_id($viewer_id);
        if (flickr_faves_is_faved_by_user($viewer, $photo['id'])) {
            return 1;
        }
    }
    return 0;
}