function bp_get_link_details_form_status()
{
    global $bp;
    $link_status = null;
    if (!empty($_POST['link-status'])) {
        if (bp_links_is_valid_status($_POST['link-status'])) {
            $link_status = (int) $_POST['link-status'];
        }
    } else {
        $link_status = $bp->links->current_link->status;
    }
    return apply_filters('bp_get_link_details_form_status', $link_status);
}
Example #2
0
function bp_links_manage_link($args = '')
{
    global $bp;
    // init possible args
    $link_id = null;
    $user_id = null;
    $category_id = null;
    $url = null;
    $target = null;
    $rel = null;
    $name = null;
    $description = null;
    $status = null;
    $embed_data = null;
    $embed_thidx = null;
    $meta = array();
    extract($args);
    if ($link_id) {
        $link = new BP_Links_Link($link_id);
    } else {
        $link = new BP_Links_Link();
    }
    if ($user_id) {
        $link->user_id = $user_id;
    } else {
        if (empty($link->id)) {
            $link->user_id = $bp->loggedin_user->id;
        }
    }
    if (empty($link->id)) {
        $link->slug = bp_links_check_slug(sanitize_title($name));
    }
    if (bp_links_is_valid_status($status)) {
        $link->status = $status;
    }
    $link->category_id = $category_id;
    $link->url = $url;
    $link->target = $target;
    $link->rel = $rel;
    $link->name = $name;
    $link->description = $description;
    if (!empty($embed_data)) {
        try {
            // load service
            $service = BP_Links_Embed::LoadService($embed_data);
            // try to attach embed service to link
            if ($service instanceof BP_Links_Embed_Service) {
                // handle selectable image
                if ($service instanceof BP_Links_Embed_Has_Selectable_Image) {
                    if (isset($embed_thidx)) {
                        $service->image_set_selected($embed_thidx);
                    }
                }
                // attach and enable service
                $link->embed_attach($service);
                $link->embed_status_set_enabled();
            }
        } catch (BP_Links_Embed_Exception $e) {
            // epic failure
            return false;
        }
    }
    if ($link->save()) {
        // set meta data
        if (!empty($meta)) {
            // loop all meta data
            foreach ($meta as $meta_key => $meta_value) {
                // try to update each key/value
                bp_links_update_linkmeta($link->id, $meta_key, $meta_value);
            }
            // refresh meta data cache
            $link->populate_meta();
        }
        // successful save event
        do_action('bp_links_manage_link_save_success', $link, $args);
        // all done
        return $link;
    } else {
        // unsuccessful save event
        do_action('bp_links_manage_link_save_failure', $link, $args);
    }
    return false;
}