
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

defined( 'PRESSO_CONST_BACKSTRETCH_OPT_FADE' ) || define( 'PRESSO_CONST_BACKSTRETCH_OPT_FADE', 400 );
defined( 'PRESSO_CONST_BACKSTRETCH_OPT_DURATION' ) || define( 'PRESSO_CONST_BACKSTRETCH_OPT_DURATION', 5000 );

/* -----------------------------------------------------------------------------
 * BackStretch
 * -------------------------------------------------------------------------- */
add_filter( 'presso_filter_localize_main_js', 'presso_backstretch_localize' );
if ( ! function_exists( 'presso_backstretch_localize' ) ) {
	function presso_backstretch_localize( $data ) {
		if ( ! presso_has_title_bg() ) {
			return $data;
		}
		
		$data['vw_backstretch_opt_transition'] = 'fade';
		$data['vw_backstretch_opt_animation'] = null;
		$data['vw_backstretch_opt_fade'] = PRESSO_CONST_BACKSTRETCH_OPT_FADE;
		$data['vw_backstretch_opt_duration'] = PRESSO_CONST_BACKSTRETCH_OPT_DURATION;

		if ( ! is_attachment() && have_posts() ) { the_post();
			wp_enqueue_script( 'vegas' );

			global $post;
			$attachments = array();
			$image_urls = array();
			$image_captions = array();
			$image_locations = array();

			/**
			 * Get image IDs
			 */
			if ( has_post_format( 'gallery' ) ) {
				$layout = get_post_meta( get_the_id(), 'vw_gallery_layout', true );

				if ( 'slider' == $layout ) {
					$attachments = get_post_meta( get_the_id(), 'vw_gallery_images', true );
				}
			}

			if ( empty( $attachments ) ) {
				if ( is_single() || is_page() ) {
					$attachments[] = presso_get_featured_image_id( $post->ID );
					
				} elseif( presso_is_woocommerce() ) {
					$attachments[] = presso_get_featured_image_id( presso_get_shop_page_id() );
					
				}
			}

			/**
			 * Get image information
			 */
			foreach ( $attachments as $attachment_ID ) {
				
				// Get image url
				$full_image_url = wp_get_attachment_image_src( $attachment_ID, 'full' );
				if ( $full_image_url ) $image_urls[] = esc_url( $full_image_url[0] );

				// Get caption
				$attachment = get_post( $attachment_ID );
				if ( ! empty( $attachment ) && ! empty( $attachment->post_excerpt ) ) {
					$image_captions[] = esc_html( $attachment->post_excerpt );
				} else {
					$image_captions[] = '';
				}

				// Get location
				ob_start();
				presso_the_location_link( $attachment_ID );

				$location_html = ob_get_clean();
				if ( $location_html ) {
					$image_locations[] = $location_html;

				} else {
					$image_locations[] = '';

				}
			}

			if ( ! empty( $image_urls ) ) {
				$data['vw_backstretch_images'] = $image_urls;
				$data['vw_backstretch_captions'] = $image_captions;
				$data['vw_backstretch_locations'] = $image_locations;
			}


			// Get video url
			if ( is_page() || ( is_single() && ! has_post_format( 'gallery' ) ) ) {
				$attr_id = get_post_meta( get_the_ID(), 'vw_featured_video', true );
				$video_url = wp_get_attachment_url( $attr_id );

				if ( ! empty( $video_url ) ) {
					$data['vw_backstretch_video'] = $video_url;
				}
			}

			rewind_posts();
		}

		return $data;
	}
}