/** * 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_links_auto_embed_panel($embed_service = null, $display = false) { // inline style for display (or not) $attr_display = $display === true ? null : ' style="display: none;"'; // render the markup ?> <span id="link-url-embed-clear"<?php echo $attr_display; ?> > <a href="#clear"><?php _e('Clear', 'buddypress-links'); ?> </a> </span> <input type="submit" id="link-url-embed-fetch" name="link-url-embed-fetch" value="<?php _e('Fetch Page Details', 'buddypress-links'); ?> "> <div id="link-url-embed" <?php echo $attr_display; ?> > <?php bp_links_auto_embed_panel_content($embed_service); ?> </div><?php // spit out nonce field wp_nonce_field('bp_links_save_link-auto-embed', '_wpnonce-link-auto-embed'); }