jetpack_archiveorg_book_shortcode

Convert an archive.org book shortcode into an embed code.

Description

(string) jetpack_archiveorg_book_shortcode( (array) $atts ); 

Returns (string)

The embed code for the Archive.org book

Parameters (1)

0. $atts (array)
An array of shortcode attributes.

Usage

  1. if ( !function_exists( 'jetpack_archiveorg_book_shortcode' ) ) { 
  2. require_once '/modules/shortcodes/archiveorg-book.php'; 
  3.  
  4. // An array of shortcode attributes. 
  5. $atts = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_archiveorg_book_shortcode($atts); 
  9.  

Defined (1)

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

/modules/shortcodes/archiveorg-book.php  
  1. function jetpack_archiveorg_book_shortcode( $atts ) { 
  2. global $content_width; 
  3.  
  4. if ( isset( $atts[0] ) && empty( $atts['id'] ) ) { 
  5. $atts['id'] = jetpack_shortcode_get_archiveorg_book_id( $atts ); 
  6.  
  7. $atts = shortcode_atts( array( 
  8. 'id' => '',  
  9. 'width' => 480,  
  10. 'height' => 430,  
  11. ), $atts ); 
  12.  
  13. if ( ! $atts['id'] ) { 
  14. return '<!-- error: missing archive.org book ID -->'; 
  15.  
  16. $id = $atts['id']; 
  17.  
  18. if ( ! $atts['width'] ) { 
  19. $width = absint( $content_width ); 
  20. } else { 
  21. $width = intval( $atts['width'] ); 
  22.  
  23. if ( ! $atts['height'] ) { 
  24. $height = round( ( $width / 640 ) * 360 ); 
  25. } else { 
  26. $height = intval( $atts['height'] ); 
  27.  
  28. $url = esc_url( set_url_scheme( "http://archive.org/stream/{$id}?ui=embed#mode/1up" ) ); 
  29.  
  30. $html = "<div class='embed-archiveorg-book' style='text-align:center;'><iframe src='$url' width='$width' height='$height' style='border:0;' webkitallowfullscreen='true' mozallowfullscreen='true' allowfullscreen></iframe></div>"; 
  31. return $html;