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
if ( !function_exists( 'jetpack_archiveorg_book_embed_to_shortcode' ) ) { require_once '/modules/shortcodes/archiveorg-book.php'; } // The content. $content = ''; // NOTICE! Understand what this does before running. $result = jetpack_archiveorg_book_embed_to_shortcode($content);
Defined (1)
The function is defined in the following location(s).
- /modules/shortcodes/archiveorg-book.php
- function jetpack_archiveorg_book_embed_to_shortcode( $content ) {
- if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/stream/' ) ) {
- return $content;
- }
- $regexp = '!<iframe\s+src=[\'"](http|https)://(www.archive|archive)\.org/stream/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)\s></iframe>!i';
- if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
- return $content;
- }
- foreach ( $matches as $match ) {
- $url = explode( '?', $match[3] );
- $id = $url[0];
- $params = $match[4];
- $params = wp_kses_hair( $params, array( 'http' ) );
- $width = isset( $params['width'] ) ? absint( $params['width']['value'] ) : 0;
- $height = isset( $params['height'] ) ? absint( $params['height']['value'] ) : 0;
- $wh = '';
- if ( $width && $height ) {
- $wh = ' width=' . $width . ' height=' . $height;
- }
- $shortcode = '[archiveorg-book ' . $id . $wh . ']';
- $content = str_replace( $match[0], $shortcode, $content );
- }
- return $content;
- }