jetpack_archiveorg_embed_to_shortcode
Compose shortcode from archive.org iframe.
Description
jetpack_archiveorg_embed_to_shortcode( (string) $content );
Parameters (1)
- 0. $content (string)
- The content.
Usage
if ( !function_exists( 'jetpack_archiveorg_embed_to_shortcode' ) ) { require_once '/modules/shortcodes/archiveorg.php'; } // The content. $content = ''; // NOTICE! Understand what this does before running. $result = jetpack_archiveorg_embed_to_shortcode($content);
Defined (1)
The function is defined in the following location(s).
- /modules/shortcodes/archiveorg.php
- function jetpack_archiveorg_embed_to_shortcode( $content ) {
- if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/embed/' ) ) {
- return $content;
- }
- $regexp = '!<iframe\s+src=[\'"]https?://archive\.org/embed/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)></iframe>!i';
- if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
- return $content;
- }
- foreach ( $matches as $match ) {
- $url = explode( '&', $match[1] );
- $id = 'id=' . $url[0];
- $autoplay = '';
- $poster = '';
- for ( $ii = 1; $ii < count( $url ); $ii++ ) {
- if ( 'autoplay=1' === $url[$ii] ) {
- $autoplay = ' autoplay="1"';
- }
- $map_matches = array();
- if ( preg_match( '/^poster=(.+)$/', $url[$ii], $map_matches ) ) {
- $poster = " poster=\"{$map_matches[1]}\"";
- }
- }
- $params = $match[2];
- $params = wp_kses_hair( $params, array( 'http' ) );
- $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
- $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
- $wh = '';
- if ( $width && $height ) {
- $wh = ' width=' . $width . ' height=' . $height;
- }
- $shortcode = '[archiveorg ' . $id . $wh . $autoplay . $poster . ']';
- $content = str_replace( $match[0], $shortcode, $content );
- }
- return $content;
- }