jetpack_archiveorg_embed_to_shortcode

Compose shortcode from archive.org iframe.

Description

jetpack_archiveorg_embed_to_shortcode( (string) $content ); 

Parameters (1)

0. $content (string)
The content.

Usage

  1. if ( !function_exists( 'jetpack_archiveorg_embed_to_shortcode' ) ) { 
  2. require_once '/modules/shortcodes/archiveorg.php'; 
  3.  
  4. // The content. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_archiveorg_embed_to_shortcode($content); 
  9.  

Defined (1)

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

/modules/shortcodes/archiveorg.php  
  1. function jetpack_archiveorg_embed_to_shortcode( $content ) { 
  2. if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/embed/' ) ) { 
  3. return $content; 
  4.  
  5. $regexp = '!<iframe\s+src=[\'"]https?://archive\.org/embed/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)></iframe>!i'; 
  6.  
  7. if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) { 
  8. return $content; 
  9.  
  10. foreach ( $matches as $match ) { 
  11. $url = explode( '&', $match[1] ); 
  12. $id = 'id=' . $url[0]; 
  13.  
  14. $autoplay = ''; 
  15. $poster = ''; 
  16. for ( $ii = 1; $ii < count( $url ); $ii++ ) { 
  17. if ( 'autoplay=1' === $url[$ii] ) { 
  18. $autoplay = ' autoplay="1"'; 
  19.  
  20. $map_matches = array(); 
  21. if ( preg_match( '/^poster=(.+)$/', $url[$ii], $map_matches ) ) { 
  22. $poster = " poster=\"{$map_matches[1]}\""; 
  23.  
  24. $params = $match[2]; 
  25.  
  26. $params = wp_kses_hair( $params, array( 'http' ) ); 
  27.  
  28. $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; 
  29. $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; 
  30.  
  31. $wh = ''; 
  32. if ( $width && $height ) { 
  33. $wh = ' width=' . $width . ' height=' . $height; 
  34.  
  35. $shortcode = '[archiveorg ' . $id . $wh . $autoplay . $poster . ']'; 
  36. $content = str_replace( $match[0], $shortcode, $content ); 
  37.  
  38. return $content;