function bp_get_link_details_form_embed_service()
{
    global $bp;
    if (!empty($_POST['link-url-embed-data'])) {
        try {
            // load service
            $service = BP_Links_Embed::LoadService(trim($_POST['link-url-embed-data']));
            // valid service?
            if ($service instanceof BP_Links_Embed_Service) {
                return $service;
            }
        } catch (BP_Links_Embed_Exception $e) {
            return false;
        }
    } elseif (bp_links_current_link_embed_enabled()) {
        return bp_links_current_link_embed_service();
    }
    return false;
}
 function embed()
 {
     if (!$this->_embed_service_obj instanceof BP_Links_Embed_Service && empty($this->embed_data) === false) {
         // handle backwards compatibility with deprecated storage method (arrays)
         switch ((string) $this->embed_service) {
             case self::EMBED_SERVICE_PICAPP:
                 $embed_data = unserialize($this->embed_data);
                 if (!empty($embed_data)) {
                     $this->_embed_service_obj = new BP_Links_Embed_Service_PicApp();
                     $this->_embed_service_obj->from_deprecated_data($embed_data);
                 }
                 break;
             case self::EMBED_SERVICE_FOTOGLIF:
                 $embed_data = unserialize($this->embed_data);
                 if (!empty($embed_data)) {
                     $this->_embed_service_obj = new BP_Links_Embed_Service_Fotoglif();
                     $this->_embed_service_obj->from_deprecated_data($embed_data);
                 }
                 break;
             default:
                 $this->_embed_service_obj = BP_Links_Embed::LoadService($this->embed_data);
         }
     }
     return $this->_embed_service_obj;
 }
 function embed()
 {
     if (!$this->_embed_service_obj instanceof BP_Links_Embed_Service && empty($this->embed_data) === false) {
         // handle backwards compatibility with deprecated storage method (arrays)
         $this->_embed_service_obj = BP_Links_Embed::LoadService($this->embed_data);
     }
     return $this->_embed_service_obj;
 }
Example #4
0
function bp_get_links_auto_embed_panel_from_data($embed_data = null)
{
    if (!empty($embed_data)) {
        $service = BP_Links_Embed::LoadService($embed_data);
        return bp_get_links_auto_embed_panel($service, true);
    } else {
        return bp_get_links_auto_embed_panel();
    }
}
Example #5
0
function bp_links_auto_embed_panel_from_data($embed_data = null)
{
    // page fetching enabled?
    if (true === BP_LINKS_CREATE_PAGE_FETCH) {
        // yep, spit out embed panel if applicable
        if (!empty($embed_data)) {
            $service = BP_Links_Embed::LoadService($embed_data);
            bp_links_auto_embed_panel($service, true);
        } else {
            bp_links_auto_embed_panel();
        }
    }
}
Example #6
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;
}