googleapps_shortcode

Parse shortcode attributes and output a Google Docs embed.

Description

(string) googleapps_shortcode( (array) $atts ); 

Returns (string)

Parameters (1)

0. $atts (array)
The atts.

Usage

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

Defined (1)

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

/modules/shortcodes/googleapps.php  
  1. function googleapps_shortcode( $atts ) { 
  2. global $content_width; 
  3.  
  4. $attr = shortcode_atts( 
  5. array( 
  6. 'width' => '100%',  
  7. 'height' => '560',  
  8. 'domain' => 'docs',  
  9. 'dir' => 'document',  
  10. 'query' => '',  
  11. 'src' => '',  
  12. ), $atts 
  13. ); 
  14.  
  15. if ( isset( $content_width ) && is_numeric( $attr['width'] ) && $attr['width'] > $content_width ) { 
  16. $attr['width'] = $content_width; 
  17.  
  18. if ( isset( $content_width ) && '560' === $attr['height'] ) { 
  19. $attr['height'] = $content_height = floor( $content_width * 3 / 4 ); 
  20.  
  21. if ( isset( $atts[0] ) && $atts[0] ) { 
  22. $attr['src'] = $atts[0]; 
  23.  
  24. if ( $attr['src'] && preg_match( '!https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/([-\w\./]+)\?([^"]+)!', $attr['src'], $matches ) ) { 
  25. $attr['domain'] = $matches[1]; 
  26. $attr['dir'] = $matches[2]; 
  27. parse_str( htmlspecialchars_decode( $matches[3] ), $query_ar ); 
  28. $query_ar['chrome'] = 'false'; 
  29. $query_ar['embedded'] = 'true'; 
  30. $attr['query'] = http_build_query( $query_ar ); 
  31.  
  32. if ( ! googleapps_validate_domain_and_dir( $attr['domain'], $attr['dir'] ) ) { 
  33. return '<!-- Unsupported URL -->'; 
  34.  
  35. $attr['query'] = $attr['dir'] . '?' . $attr['query']; 
  36.  
  37. /** This action is documented in modules/widgets/social-media-icons.php */ 
  38. do_action( 'jetpack_bump_stats_extras', 'embeds', googleapps_service_name( $attr['domain'], $attr['dir'] ) ); 
  39.  
  40. return sprintf( 
  41. '<iframe src="%s" frameborder="0" width="%s" height="%s" marginheight="0" marginwidth="0"></iframe>',  
  42. esc_url( 'https://' . $attr['domain'] . '.google.com/' . $attr['query'] ),  
  43. esc_attr( $attr['width'] ),  
  44. esc_attr( $attr['height'] ) 
  45. );