jetpack_dailymotion_embed_reversal

Dailymotion Embed Reversal (with new iframe code as of 17.09.2014).

Description

jetpack_dailymotion_embed_reversal( $content ); 

Converts a generic HTML embed code from Dailymotion into an oEmbeddable URL.

Parameters (1)

0. $content
The content.

Usage

  1. if ( !function_exists( 'jetpack_dailymotion_embed_reversal' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/dailymotion.php'; 
  3.  
  4. // The content. 
  5. $content = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_dailymotion_embed_reversal($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/shortcodes/dailymotion.php  
  1. function jetpack_dailymotion_embed_reversal( $content ) { 
  2. if ( false === stripos( $content, 'dailymotion.com/embed' ) ) { 
  3. return $content; 
  4.  
  5. /** Sample embed code as of Sep 17th 2014: 
  6.   
  7. <iframe frameborder="0" width="480" height="270" src="//www.dailymotion.com/embed/video/x25x71x" allowfullscreen></iframe><br /><a href="http://www.dailymotion.com/video/x25x71x_dog-with-legs-in-casts-learns-how-to-enter-the-front-door_animals" target="_blank">Dog with legs in casts learns how to enter the...</a> <i>by <a href="http://www.dailymotion.com/videobash" target="_blank">videobash</a></i> 
  8. */ 
  9. $regexes = array(); 
  10.  
  11. // I'm Konstantin and I love regex. 
  12. $regexes[] = '#<iframe[^>]+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/([^"\'/]++) "[^>]*+>\s*+</iframe>\s*+(?:<br\s*+/>)?\s*+ 
  13. (?: <a[^>]+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "[^>]*+>.+?</a>\s*+ )? 
  14. (?: <i>.*?<a[^>]+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "[^>]*+>.+?</a>\s*+</i> )?#ix'; 
  15.  
  16. $regexes[] = '#<iframe(?:[^&]|&(?!gt;))+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/([^"\'/]++) "(?:[^&]|&(?!gt;))*+>\s*+</iframe>\s*+(?:<br\s*+/>)?\s*+ 
  17. (?: <a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+>.+?</a>\s*+ )? 
  18. (?: <i>.*?<a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+>.+?</a>\s*+</i> )?#ix'; 
  19.  
  20. foreach ( $regexes as $regex ) { 
  21. if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) { 
  22. continue; 
  23.  
  24. foreach ( $matches as $match ) { 
  25. $url = esc_url( sprintf( 'https://dailymotion.com/video/%s', $match[1] ) ); 
  26. $replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) ); 
  27. $content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content ); 
  28.  
  29. /** This action is documented in modules/shortcodes/youtube.php */ 
  30. do_action( 'jetpack_embed_to_shortcode', 'dailymotion', $url ); 
  31.  
  32. return $content;