/** * Adds a URL format and oEmbed provider URL pair. * * @since 2.9.0 * @see nxt_oEmbed * * @uses _nxt_oembed_get_object() * * @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards. * @param string $provider The URL to the oEmbed provider. * @param boolean $regex Whether the $format parameter is in a regex format. */ function nxt_oembed_add_provider($format, $provider, $regex = false) { require_once ABSPATH . nxtINC . '/class-oembed.php'; $oembed = _nxt_oembed_get_object(); $oembed->providers[$format] = array($provider, $regex); }
/** * The {@link do_shortcode()} callback function. * * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. * Next, checks the URL against the regex of registered {@link nxt_oEmbed} providers if oEmbed discovery is false. * If none of the regex matches and it's enabled, then the URL will be passed to {@link BP_Embed::parse_oembed()} for oEmbed parsing. * * @uses nxt_parse_args() * @uses nxt_embed_defaults() * @uses current_user_can() * @uses _nxt_oembed_get_object() * @uses nxt_Embed::maybe_make_link() * * @param array $attr Shortcode attributes. * @param string $url The URL attempting to be embeded. * @return string The embed HTML on success, otherwise the original URL. */ function shortcode($attr, $url = '') { if (empty($url)) { return ''; } $rawattr = $attr; $attr = nxt_parse_args($attr, nxt_embed_defaults()); // kses converts & into & and we need to undo this // See http://core.trac.nxtclass.org/ticket/11311 $url = str_replace('&', '&', $url); // Look for known internal handlers ksort($this->handlers); foreach ($this->handlers as $priority => $handlers) { foreach ($handlers as $hid => $handler) { if (preg_match($handler['regex'], $url, $matches) && is_callable($handler['callback'])) { if (false !== ($return = call_user_func($handler['callback'], $matches, $attr, $url, $rawattr))) { return apply_filters('embed_handler_html', $return, $url, $attr); } } } } // Get object ID $id = apply_filters('embed_post_id', 0); // Is oEmbed discovery on? $attr['discover'] = apply_filters('bp_embed_oembed_discover', false) && current_user_can('unfiltered_html'); // Set up a new nxt oEmbed object to check URL with registered oEmbed providers require_once ABSPATH . nxtINC . '/class-oembed.php'; $oembed_obj = _nxt_oembed_get_object(); // If oEmbed discovery is true, skip oEmbed provider check $is_oembed_link = false; if (!$attr['discover']) { foreach ((array) $oembed_obj->providers as $provider_matchmask => $provider) { $regex = ($is_regex = $provider[1]) ? $provider_matchmask : '#' . str_replace('___wildcard___', '(.+)', preg_quote(str_replace('*', '___wildcard___', $provider_matchmask), '#')) . '#i'; if (preg_match($regex, $url)) { $is_oembed_link = true; } } // If url doesn't match a nxt oEmbed provider, stop parsing if (!$is_oembed_link) { return $this->maybe_make_link($url); } } return $this->parse_oembed($id, $url, $attr, $rawattr); }