googleapps_embed_to_shortcode

Reverse iframe embed to shortcode mapping HTML attributes to shortcode attributes.

Description

googleapps_embed_to_shortcode( (string) $content ); 

Parameters (1)

0. $content (string)
The content.

Usage

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

Defined (1)

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

/modules/shortcodes/googleapps.php  
  1. function googleapps_embed_to_shortcode( $content ) { 
  2. if ( ! is_string( $content ) || false === stripos( $content, '<iframe' ) && false === stripos( $content, '.google.com' ) ) { 
  3. return $content; 
  4.  
  5. $regexp = '#<iframe((?:\s+\w+="[^"]*")*?)\s*src="https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/(?!maps)([-\w\./]+)(?:\?)?([^"]+)?"\s*((?:\s+\w+="[^"]*")*?)>.*?</iframe>#i'; 
  6. $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); 
  7. $regexp_squot = str_replace( '"', "'", $regexp ); 
  8. $regexp_ent_squot = str_replace( '"', "'", $regexp_ent ); 
  9. $regexp_noquot = '!<iframe(.*?)src=https://(docs|drive)\.google\.com/[-\.\w/]*?(viewer)\?(.*?)>(.*?)</iframe>!'; 
  10. $regexp_ent_noquot = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp_noquot, ENT_NOQUOTES ) ); 
  11.  
  12. foreach ( array( 'regexp', 'regexp_ent', 'regexp_squot', 'regexp_ent_squot', 'regexp_noquot', 'regexp_ent_noquot' ) as $reg ) { 
  13. if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { 
  14. continue; 
  15.  
  16. foreach ( $matches as $match ) { 
  17. $params = $match[1] . $match[5]; 
  18. if ( in_array( $reg, array( 'regexp_ent', 'regexp_ent_squot' ) ) ) { 
  19. $params = html_entity_decode( $params ); 
  20.  
  21. $params = wp_kses_hair( $params, array( 'http' ) ); 
  22.  
  23. $width = $height = 0; 
  24. if ( isset( $params['width'] ) ) { 
  25. $width = (int) $params['width']['value']; 
  26.  
  27. if ( isset( $params['height'] ) ) { 
  28. $height = (int) $params['height']['value']; 
  29.  
  30. // allow the user to specify width greater than 200 inside text widgets 
  31. if ( $width > 400 && isset( $_POST['widget-text'] ) ) { 
  32. $width = 200; 
  33. $height = 200; 
  34.  
  35. $attributes = ''; 
  36. if ( isset( $params['width'] ) && '100%' == $params['width']['value'] ) { 
  37. $width = '100%'; 
  38.  
  39. if ( $width ) { 
  40. $attributes = ' width="' . $width . '"'; 
  41.  
  42. if ( $height ) { 
  43. $attributes .= ' height="' . $height . '"'; 
  44.  
  45. $domain = 'spreadsheets'; 
  46. if ( in_array( $match[2], array( 'docs', 'drive', 'www', 'calendar' ) ) ) { 
  47. $domain = $match[2]; 
  48.  
  49. // Make sure this is actually something that the shortcode supports. If it's not, leave the HTML alone. 
  50. if ( ! googleapps_validate_domain_and_dir( $domain, $match[3] ) ) { 
  51. continue; 
  52.  
  53. /** This action is documented in modules/widgets/social-media-icons.php */ 
  54. do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', googleapps_service_name( $domain, $match[3] ) ); 
  55.  
  56. $content = str_replace( $match[0], '[googleapps domain="' . $domain . '" dir="' . $match[3] . '" query="' . esc_attr( $match[4] ) . '"' . $attributes . ' /]', $content ); 
  57.  
  58. return $content;