jetpack_archiveorg_book_embed_to_shortcode

Compose shortcode from archive.org book iframe.

Description

jetpack_archiveorg_book_embed_to_shortcode( (string) $content ); 

Parameters (1)

0. $content (string)
The content.

Usage

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

Defined (1)

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

/modules/shortcodes/archiveorg-book.php  
  1. function jetpack_archiveorg_book_embed_to_shortcode( $content ) { 
  2. if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/stream/' ) ) { 
  3. return $content; 
  4.  
  5. $regexp = '!<iframe\s+src=[\'"](http|https)://(www.archive|archive)\.org/stream/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)\s></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[3] ); 
  12. $id = $url[0]; 
  13.  
  14. $params = $match[4]; 
  15.  
  16. $params = wp_kses_hair( $params, array( 'http' ) ); 
  17.  
  18. $width = isset( $params['width'] ) ? absint( $params['width']['value'] ) : 0; 
  19. $height = isset( $params['height'] ) ? absint( $params['height']['value'] ) : 0; 
  20.  
  21. $wh = ''; 
  22. if ( $width && $height ) { 
  23. $wh = ' width=' . $width . ' height=' . $height; 
  24.  
  25. $shortcode = '[archiveorg-book ' . $id . $wh . ']'; 
  26. $content = str_replace( $match[0], $shortcode, $content ); 
  27.  
  28. return $content;