: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! defined( 'ABSPATH' ) ) {
Most of the code is taken from class-amp-gallery-embed.php and Slider Revolution https://revolution.themepunch.com/
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-base-embed-handler.php' );
class AMP_Rev_Slider_Embed_Handler extends AMPforWP\AMPVendor\AMP_Base_Embed_Handler {
private static $script_slug = 'amp-carousel';
private static $script_src = 'https://cdn.ampproject.org/v0/amp-carousel-0.2.js';
public function register_embed() {
add_shortcode( 'rev_slider', array( $this, 'shortcode' ) );
public function unregister_embed() {
remove_shortcode( 'rev_slider' );
public function get_scripts() {
if ( ! $this->did_convert_elements ) {
return array( self::$script_slug => self::$script_src );
public function shortcode( $args, $mid_content = null ) {
global $post,$revSliderVersion;
extract(shortcode_atts(array('alias' => ''), $args, 'rev_slider'));
extract(shortcode_atts(array('settings' => ''), $args, 'rev_slider'));
extract(shortcode_atts(array('order' => ''), $args, 'rev_slider'));
if( !empty($revSliderVersion) && 6 > $revSliderVersion ){
if($settings !== '') $settings = json_decode(str_replace(array('({', '})', "'"), array('[', ']', '"'), $settings) ,true);
if($order !== '') $order = explode(',', $order);
$sliderAlias = ($alias != '') ? $alias : RevSliderFunctions::getVal($args,0);
$gal_ids = RevSliderFunctionsWP::check_for_shortcodes($mid_content);
if(!empty($gal_ids)){ //add a gallery based slider
$slider = RevSliderOutput::putSlider($sliderAlias, '', $gal_ids);
$slider = RevSliderOutput::putSlider($sliderAlias, '', array(), $settings, $order);
$content = ob_get_contents();
$slides = $slider->getSlidesForOutput(true,'',$gal_ids);
foreach ($slides as $slide) {
$bgtype = $slide->getParam('background_type', 'image');
$img_data = wp_get_attachment_metadata( $slide->getImageID() );
if($bgtype == 'external'){
$url = esc_url($slide->getParam('slide_bg_external', ''));
$imgalt = esc_attr($slide->getParam('alt_attr', ''));
$img_title = esc_attr($slide->getParam('title_attr', ''));
$img_w = $slide->getParam('ext_width', '1920');
$img_h = $slide->getParam('ext_height', '1080');
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($img_w),
'height' => intval($img_h),
'bgtype' => esc_attr($bgtype)
}elseif( $bgtype == 'image'){
$img_data = wp_get_attachment_metadata( $slide->getImageID() );
$url = $slide->getImageUrl();
$attachment_id = $slide->getImageID();
if(isset($img_data['width'])){
$width = $img_data['width'];
if(isset($img_data['height'])){
$height = $img_data['height'];
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($width),
'height' => intval($height),
'bgtype' => esc_attr($bgtype)
}elseif( $bgtype == 'youtube' ){
$youtube_id = $slide->getParam('slide_bg_youtube', '');
$cover_img = $slide->getImageUrl();
$urls[] = apply_filters('amp_gallery_image_params', array(
'bgtype' => esc_attr($bgtype),
'cover_img' => $cover_img
elseif ( defined('RS_REVISION') && 6.0 <= RS_REVISION ) {
extract(shortcode_atts(array('alias' => ''), $args, 'rev_slider'));
extract(shortcode_atts(array('settings' => ''), $args, 'rev_slider'));
extract(shortcode_atts(array('order' => ''), $args, 'rev_slider'));
extract(shortcode_atts(array('usage' => ''), $args, 'rev_slider'));
$output = new RevSliderOutput();
$slider_alias = ($alias != '') ? $alias : $output->get_val($args, 0); //backwards compatibility
$output->set_custom_order($order);
$output->set_custom_settings($settings);
$gallery_ids = $output->check_for_shortcodes($mid_content); //check for example on gallery shortcode and do stuff
if($gallery_ids !== false) $output->set_gallery_ids($gallery_ids);
$slider = $output->add_slider_to_stage($slider_alias, $usage);
$content = ob_get_contents();
$slides = $slider->get_slides_for_output(true,'',$gallery_ids);
foreach ($slides as $slide) {
$bgtype = $slide->get_param(array('bg', 'type'),'');
$layers = $slide->getLayers();
$image_id = $slide->image_id;
$url = $slide->image_url;
$img_data = wp_get_attachment_metadata( $image_id );
if( $bgtype == 'image' && !empty($layers) ){
if(isset($img_data['width'])){
$width = $img_data['width'];
if(isset($img_data['height'])){
$height = $img_data['height'];
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($width),
'height' => intval($height),
'bgtype' => esc_attr($bgtype)
}elseif(!empty($layers)){
foreach ($layers as $key => $layer) {
if($layer['type'] == 'text'){
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($width),
'height' => intval($height),
'bgtype' => esc_attr($bgtype)
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($width),
'height' => intval($height),
'bgtype' => esc_attr($bgtype)
}elseif($bgtype == 'external' || !empty($layers)){
$url = esc_url($slide->get_param(array('bg','externalSrc'), ''));
$imgalt = esc_attr($slide->get_param('alt_attr', ''));
$img_title = esc_attr($slide->get_param('title_attr', ''));
$img_w = $slide->get_param('ext_width', '1920');
$img_h = $slide->get_param('ext_height', '1080');
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($img_w),
'height' => intval($img_h),
'bgtype' => esc_attr($bgtype)
foreach ($layers as $key => $layer) {
if($layer['type'] == 'video'){
$video_url = esc_attr($layer['media']['mp4Url']);;
$video_url = str_replace('http:','https:',$video_url);
$cover_img = esc_attr($layer['media']['posterUrl']);
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($video_url),
'bgtype' => esc_attr($layer['type']),
'cover_img' => esc_url($cover_img)
}elseif( $bgtype == 'image' || !empty($layers) ){
if(isset($img_data['width'])){
$width = $img_data['width'];
if(isset($img_data['height'])){
$height = $img_data['height'];
$urls[] = apply_filters('amp_gallery_image_params', array(
'width' => intval($width),
'height' => intval($height),
'bgtype' => esc_attr($bgtype)
foreach ($layers as $key => $layer) {
if($layer['type'] == 'video'){
$video_url = esc_attr($layer['media']['mp4Url']);;
$video_url = str_replace('http:','https:',$video_url);
$cover_img = esc_attr($layer['media']['posterUrl']);
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($video_url),
'bgtype' => esc_attr($layer['type']),
'cover_img' => esc_url($cover_img)
}elseif( $bgtype == 'youtube' || !empty($layers) ){
$youtube_id = $slide->get_param(array('bg','youtube'), '');
$cover_img = $slide->get_param(array('bg','image'), '');
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_attr($youtube_id),
'bgtype' => esc_attr($bgtype),
'cover_img' => esc_attr($cover_img)
foreach ($layers as $key => $layer) {
if($layer['type'] == 'video'){
$video_url = esc_attr($layer['media']['mp4Url']);;
$video_url = str_replace('http:','https:',$video_url);
$cover_img = esc_attr($layer['media']['posterUrl']);
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($video_url),
'bgtype' => esc_attr($layer['type']),
'cover_img' => esc_url($cover_img)
}elseif( $bgtype == 'vimeo' || !empty($layers) ){
$vimeo_id = $slide->get_param(array('bg','vimeo'), '');
$cover_img = $slide->get_param(array('bg','image'), '');
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_attr($vimeo_id),
'bgtype' => esc_attr($bgtype),
'cover_img' => esc_attr($cover_img)
foreach ($layers as $key => $layer) {
if($layer['type'] == 'video'){
$video_url = esc_attr($layer['media']['mp4Url']);;
$video_url = str_replace('http:','https:',$video_url);
$cover_img = esc_attr($layer['media']['posterUrl']);
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($video_url),
'bgtype' => esc_attr($layer['type']),
'cover_img' => esc_url($cover_img)
}elseif($bgtype == 'html5' || !empty($layers)){
$html5_url = $slide->get_param(array('bg','mpeg'), '');
$html5_url = str_replace('http:','https:',$html5_url);
$cover_img = $slide->get_param(array('bg','image'), '');
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($html5_url),
'bgtype' => esc_attr($bgtype),
'cover_img' => esc_url($cover_img)
foreach ($layers as $key => $layer) {
if($layer['type'] == 'video'){
$video_url = esc_attr($layer['media']['mp4Url']);;
$video_url = str_replace('http:','https:',$video_url);
$cover_img = esc_attr($layer['media']['posterUrl']);
$urls[] = apply_filters('amp_gallery_image_params', array(
'url' => esc_url($video_url),
'bgtype' => esc_attr($layer['type']),
'cover_img' => esc_url($cover_img)
foreach ($urls as $k => $v) {
$new_urls[implode($v)] = $v;
$new_urls = array_values($new_urls);
return $this->render( array(
public function render( $args ) {
global $redux_builder_amp,$carousel_markup_all;
$this->did_convert_elements = true;
$args = wp_parse_args( $args, array(
if ( empty( $args['images'] ) ) {
$carousel_markup = $amp_image_lightbox = '';
$carousel_markup_all = array(
'main-html'=>'{{with_carousel}}
'image-with-caption-html'=>'<figure><div class="ampforwp-gallery-item amp-carousel-container">{{main_images}} </div><figcaption {{openbrack}}class{{closebrack}}="expanded? \'expanded\' : \'\'" on="tap:AMP.setState({expanded: !expanded})" tabindex="0" role="button" >{{main_images_caption}}<span {{openbrack}}text{{closebrack}}="expanded ? \'less\' : \'more\'">more</span> </figcaption></figure>',
'image-without-caption-html' =>'<div class="ampforwp-gallery-item amp-carousel-container">{{main_images}} </div>',
'gallery_css' => '.cls-btn{background:#0d0d0d;border:none;position: absolute;right: 10px;}
.cls-btn:after{content:"X";display:inline-block;color:#fff;font-size:20px;padding:20px;}',
'main-html'=>'{{with_carousel}}
{{with_carousel_thumbnail}}
'image-with-caption-html'=>'<figure><div class="ampforwp-gallery-item amp-carousel-container">{{main_images}} </div><figcaption {{openbrack}}class{{closebrack}}="expanded? \'expanded\' : \'\'" on="tap:AMP.setState({expanded: !expanded})" tabindex="0" role="button" >{{main_images_caption}}<span {{openbrack}}text{{closebrack}}="expanded ? \'less\' : \'more\'">more</span> </figcaption></figure>',
'image-without-caption-html' =>'<div class="ampforwp-gallery-item amp-carousel-container">{{main_images}} </div>',
'carousel_with_thumbnail_html'=>'<button on="tap:carousel-with-carousel-preview-{{unique_id}}.goToSlide(index={{unique_index}})" class="amp-carousel-slide amp-scrollable-carousel-slide">{{thumbnail}}</button>',
.cls-btn{background:#0d0d0d;border:none;position: absolute;right: 10px;}
.cls-btn:after{content:"X";display:inline-block;color:#fff;font-size:20px;padding:20px;}
.carousel-preview button{padding:0;}
.carousel-preview amp-img{height:40px;width:60px;position:relative;}
.carousel-preview {width: 100%;display: inline-block;text-align: center;margin: 20px 0px;}
'main-html'=>'<div class="gal_w">{{with_images}}</div>
'image-with-caption-html'=>'',
'image-without-caption-html' =>'{{main_images}}',
.gal_w{display:inline-block;width:100%}
.gal_w amp-img{background:#f1f1f1;height:134px;width:150px;position: relative;float:left;margin:10px;}
.cls-btn{background:#0d0d0d;border:none;position: absolute;right: 10px;}
.cls-btn:after{content:"X";display:inline-block;color:#fff;font-size:20px;padding:20px;}
$carousel_markup_all = apply_filters("ampforwp_manage_gallery_markup", $carousel_markup_all);
$markup = $carousel_markup_all[1];
if( isset($redux_builder_amp['ampforwp-gallery-design-type']) && isset($carousel_markup_all[$redux_builder_amp['ampforwp-gallery-design-type'] ] ) ){
$markup = $carousel_markup_all[$redux_builder_amp['ampforwp-gallery-design-type']];
foreach ( $args['images'] as $key => $image ) {
if($image['bgtype'] =="image" || $image['bgtype'] =="external" ){
'width' => $image['width'],
'height' => $image['height'],
'class' => 'amp-carousel-img',
}elseif( $image['bgtype'] =="youtube"){
'data-videoid'=> $image['url'],
'width' => $image['width'],
'height' => $image['height'],
'class' => 'amp-carousel-img',
'data-param-playlist'=> $image['url'],
'data-param-modestbranding'=> '1',
$tag_type = 'amp-youtube';
}elseif( $image['bgtype'] =="vimeo"){
'data-videoid'=> $image['url'],
'width' => $image['width'],
'height' => $image['height'],
'class' => 'amp-carousel-img',
}elseif( $image['bgtype'] =="html5"){
'width' => $image['width'],
'height' => $image['height'],
'class' => 'amp-carousel-img',
'poster' => $image['cover_img'],
elseif( $image['bgtype'] =="video"){
'width' => $image['width'],
'height' => $image['height'],
'class' => 'amp-carousel-img',
'poster' => $image['cover_img'],
if( 3 == ampforwp_get_setting('ampforwp-gallery-design-type') || true == ampforwp_get_setting('ampforwp-gallery-lightbox') ){
$design3_additional_attr = array('on'=> 'tap:gallery-lightbox', 'role'=>'button',
if( is_array($amp_img_arr) && !empty($amp_img_arr) ){
$amp_img_arr = array_merge($amp_img_arr, $design3_additional_attr);
$amp_image_lightbox = '<amp-image-lightbox id="gallery-lightbox" layout="nodisplay">
<div on="tap:gallery-lightbox.close" role="button"
<button class="cls-btn" on="tap:gallery-lightbox.close"
role="button" tabindex="0"></button>
$amp_images[$key] = AMP_HTML_Utils::build_tag(
$upload_dir = wp_upload_dir();
$upload_url = $upload_dir['baseurl'];
if( $tag_type == 'amp-img'){
if ( false === strpos( $image['url'], $upload_url ) ) {
$smallimage = $image['url'];
$thumb_url = ampforwp_aq_resize( $image['url'], 120, 60, true, false ); //resize & crop the image
$smallimage = $thumb_url[0];
$smallwidth = $thumb_url[1];
$smallheight = $thumb_url[2];
$smallimage = $image['url'];
$smallwidth = $image['width'];
$smallheight = $image['height'];
}elseif( $tag_type == 'amp-youtube'){
$smallimage = $image['cover_img'];
$amp_images_small[$key] = AMP_HTML_Utils::build_tag(