]*>(.*)<\/h[3,4,5,6]>/sU',
'
$1
',
$content
);
return $content;
}
function ampforwp_fbia_address_tag($content){
$content = preg_replace(
'/]*>(.*)<\/address>/sU',
'$1
',
$content
);
return $content;
}
function ampforwp_fbia_filter_dom($content){
$DOMDocument = ampforwp_fbia_get_content_DOM($content);
$DOMDocument = apply_filters("ampforwp_fbia_content_dom", $DOMDocument);
$content = ampforwp_fbia_get_content_from_DOM($DOMDocument);
return $content;
}
function ampforwp_ia_modify_gutenburg_gallery($content){
$allMatches = preg_replace_callback('/(.*?)<\/ul>/', function($matches) {
return ''.$matches[3].'';
}, $content);
$fbiagallery = preg_replace_callback('/
<\/figure><\/li>/', function($match) {
return '
';
}, $allMatches);
return $fbiagallery;
}
function ampforwp_gallery_shortcode_markup_modify( $output, $attr, $instance ){
global $wp;
$post = get_post(ampforwp_get_the_ID());
if ( is_feed() && isset($wp->query_vars['feed']) && 'instant_articles' == $wp->query_vars['feed'] ) {
$atts = shortcode_atts( array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post ? $post->ID : 0,
'itemtag' => 'figure',
'icontag' => 'div',
'captiontag' => 'figcaption',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => ''
), $attr, 'gallery' );
if ( ! empty( $atts['include'] ) ) {
$_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( ! empty( $atts['exclude'] ) ) {
$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
} else {
$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
}
if ( empty( $attachments ) ) {
return '';
}
// Build the gallery html output
$output = "";
// Iterate over the available images
$i = 0;
foreach ( $attachments as $id => $attachment ) {
$attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "gallery-$id" ) : '';
$image_output = wp_get_attachment_image( $id, "full", false, $attr );
$image_meta = wp_get_attachment_metadata( $id );
$orientation = '';
if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
}
$output .= "";
$output .= $image_output;
if ( trim($attachment->post_excerpt) ) {
// $output .= "
//
// " . wptexturize($attachment->post_excerpt) . "
// ";
}
$output .= "";
}
$output .= "";
return $output;
}
return $output;
}
function ampforwp_fbia_get_content_DOM($content){
$libxml_previous_state = libxml_use_internal_errors( true );
$DOMDocument = new DOMDocument( '1.0', get_option( 'blog_charset' ) );
// DOMDocument isn’t handling encodings too well, so let’s help it a little
if ( function_exists( 'mb_convert_encoding' ) ) {
$content = mb_convert_encoding( $content, 'HTML-ENTITIES', get_option( 'blog_charset' ) );
}
$result = $DOMDocument->loadHTML( '' . utf8_decode( $content ) . '' );
libxml_clear_errors();
libxml_use_internal_errors( $libxml_previous_state );
return $DOMDocument;
}
function ampforwp_fbia_get_content_from_DOM($DOMDocument){
$body = $DOMDocument->getElementsByTagName( 'body' )->item( 0 );
$filtered_content = '';
foreach ( $body->childNodes as $node ) {
if ( method_exists( $DOMDocument, 'saveHTML' ) && version_compare(phpversion(), '5.3.6', '>=') ) {
$filtered_content .= $DOMDocument->saveHTML( $node );// Requires PHP 5.3.6
} else {
$temp_content = $DOMDocument->saveXML( $node );
$iframe_pattern = "#