Ejemplo n.º 1
0
/**
 * Replaces plain-text links to YouTube videos with YouTube embeds.
 *
 * @param string $content HTML content
 * @return string The content with embeds instead of URLs
 */
function youtube_link($content)
{
    return jetpack_preg_replace_callback_outside_tags('!(?:\\n|\\A)https?://(?:www\\.)?(?:youtube.com/(?:v/|playlist|watch[/\\#?])|youtu\\.be/)[^\\s]+?(?:\\n|\\Z)!i', 'youtube_link_callback', $content, 'youtube.com/');
}
Ejemplo n.º 2
0
/**
 * Replaces shortcodes and plain-text URLs to Vimeo videos with Vimeo embeds.
 * Covers shortcode usage [vimeo 1234] | [vimeo https://vimeo.com/1234] | [vimeo http://vimeo.com/1234]
 * Or plain text URLs https://vimeo.com/1234 | vimeo.com/1234 | //vimeo.com/1234
 * Links are left intact.
 *
 * @since 3.7.0
 * @since 3.9.5 One regular expression matches shortcodes and plain URLs.
 *
 * @param string $content HTML content
 * @return string The content with embeds instead of URLs
 */
function vimeo_link($content)
{
    /**
     *  [vimeo 12345]
     *  [vimeo http://vimeo.com/12345]
     */
    $shortcode = "(?:\\[vimeo\\s+[^0-9]*)([0-9]+)(?:\\])";
    /**
     *  http://vimeo.com/12345
     *  https://vimeo.com/12345
     *  //vimeo.com/12345
     *  vimeo.com/some/descender/12345
     *
     *  Should not capture inside HTML attributes
     *  [Not] <a href="vimeo.com/12345">Cool Video</a>
     *  [Not] <a href="https://vimeo.com/12345">vimeo.com/12345</a>
     *
     *  Could erroneously capture:
     *  <a href="some.link/maybe/even/vimeo">This video (vimeo.com/12345) is teh cat's meow!</a>
     */
    $plain_url = "(?:[^'\">]?\\/?(?:https?:\\/\\/)?vimeo\\.com[^0-9]+)([0-9]+)(?:[^'\"0-9<]|\$)";
    return jetpack_preg_replace_callback_outside_tags(sprintf('#%s|%s#i', $shortcode, $plain_url), 'vimeo_link_callback', $content, 'vimeo');
}