/** * Display auto-embed panel on the create/admin form */ function bp_links_ajax_link_auto_embed_url() { check_ajax_referer('bp_links_save_link-auto-embed'); try { // try to load a service $embed_service = BP_Links_Embed::FromUrl($_POST['url']); // did we get a rich media service? if ($embed_service instanceof BP_Links_Embed_From_Url) { // capture embed panel content ob_start(); bp_links_auto_embed_panel_content($embed_service); // output response bp_links_ajax_response_string(1, $embed_service->title(), $embed_service->description(), ob_get_clean()); } // NOT rich media, fall back to page parser $page_parser = BP_Links_Embed_Page_Parser::GetInstance(); if ($page_parser->from_url($_POST['url'])) { $page_title = $page_parser->title(); $page_desc = $page_parser->description(); if (!empty($page_title) || !empty($page_desc)) { // output response bp_links_ajax_response_string(2, $page_title, $page_desc); } } } catch (BP_Links_Embed_User_Exception $e) { bp_links_ajax_response_string(-1, esc_html($e->getMessage())); } catch (Exception $e) { // fall through to generic error for all other exceptions // TODO comment out this debug line before tagging a version // bp_links_ajax_response_string( -1, esc_html( $e->getMessage() ) ); } // if all else fails, just spit out generic warning message bp_links_ajax_response_string(-2, __('Auto-fill not available for this URL.', 'buddypress-links')); }
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; }
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(); } }
/** * Get singleton instance * * @return BP_Links_Embed */ public static final function GetInstance() { if (empty(self::$instance)) { self::$instance = new BP_Links_Embed(); // register natively supported services self::$instance->register_service(new BP_Links_Embed_Service_YouTube()); self::$instance->register_service(new BP_Links_Embed_Service_Flickr()); self::$instance->register_service(new BP_Links_Embed_Service_MetaCafe()); self::$instance->register_service(new BP_Links_Embed_Service_WebPage(true)); } return self::$instance; }
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(); } } }
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; }