jetpack_lytro_shortcode_handler

Lytro.com Shortcode.

Description

(string) jetpack_lytro_shortcode_handler( (array) $atts ); 

Allows embedding Lytro living pictures using [lytro photo="200"] or [lytro photo="http://www.lytro.com/..."]. Additional attributes like show_border, show_arrow, etc have priority over the ones supplied in the URL.

Returns (string)

Embed HTML or a

Parameters (1)

0. $atts (array)
Shortcode attributes

Usage

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

Defined (1)

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

/modules/shortcodes/lytro.php  
  1. function jetpack_lytro_shortcode_handler( $atts ) { 
  2. $defaults = array(); 
  3. $attributes = jetpack_lytro_shortcode_attributes(); 
  4. foreach ( $attributes as $key => $attribute ) { 
  5. if ( isset( $attribute['default'] ) ) { 
  6. $defaults[$key] = $attribute['default']; 
  7.  
  8. $atts = shortcode_atts( $defaults, $atts ); 
  9.  
  10. // There has to at least be a photo attribute. 
  11. if ( empty( $atts['photo'] ) ) { 
  12. return '<!-- Lytro Shortcode Error: No Photo ID/URL -->'; 
  13.  
  14. // The photo attribute might be a URL 
  15. if ( ! is_numeric( $atts['photo'] ) ) { 
  16. $atts = array_merge( $atts, jetpack_lytro_shortcode_url_to_atts( $atts['photo'] ) ); 
  17.  
  18. // Validate all attributes by callable function or regular expression. 
  19. foreach ( $atts as $key => $value ) { 
  20. $attribute = $attributes[$key]; 
  21. if ( isset( $attribute['validate'] ) ) { 
  22. $validate = $attribute['validate']; 
  23. $valid = is_callable( $validate ) ? call_user_func( $validate, $value ) : preg_match( $validate, $value ); 
  24. if ( ! $valid ) { 
  25. $atts[$key] = $defaults[$key]; 
  26.  
  27. // The photo attribute might have changed, make sure it's still valid. 
  28. if ( ! is_numeric( $atts['photo'] ) || ! $atts['photo'] ) { 
  29. return '<!-- Lytro Shortcode Error: Invalid Photo ID/URL -->'; 
  30.  
  31. // Build a query which is then appended to the iframe src. 
  32. $query_args = array(); 
  33. foreach ( $atts as $key => $value ) { 
  34. $attribute = $attributes[$key]; 
  35. if ( isset( $attribute['query_arg'] ) && ! empty( $attribute['query_arg'] ) && ! empty( $value ) ) { 
  36. $query_args[$attribute['query_arg']] = $value; 
  37.  
  38. if ( ! empty( $atts['username'] ) ) { 
  39. $src = sprintf( 'https://pictures.lytro.com/%s/pictures/%d/embed', $atts['username'], $atts['photo'] ); 
  40. } else { 
  41. $src = sprintf( 'https://pictures.lytro.com/pictures/%d/embed', $atts['photo'] ); 
  42.  
  43. // Add query args and build the iframe. 
  44. $src = add_query_arg( $query_args, $src ); 
  45.  
  46. return '<iframe width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '" src="' . esc_url( $src ) . '" frameborder="0" allowfullscreen scrolling="no"></iframe>';