<?php

class Intense_Overlay extends Intense_Shortcode {

	function __construct() {
        parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'Overlay', 'intense' );
		$this->description = __( 'The overlay shortcode is used to add an overlay that will show when the user hovers over the image. You can add your own content to show as part of the overlay. Some examples of content you could add include: icons, buttons, text, etc.', 'intense' );
		$this->category = __( 'Layout', 'intense' );
		$this->show_preview = false;		
		$this->vc_map_content = 'textarea';
		$this->is_container = true;
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		$output = '';

		$id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

		$subtleheight = '';

		if ( !empty( $subtleeffect ) ) {
            intense_load_subtle_effect_CSS( $subtleeffect );
            intense_add_script( 'intense.subtle.effect' );
        }

        if ( !empty( $split_title ) ) {
       		$split_title = explode(' ', $title, 3);        
    	} else {
    		$split_title = array();
    		$split_title[0] = $title;
    	}

    	if ( is_numeric( $link ) ) {
            $link = get_permalink( $link );
        }

        $atts['class'] = 'subtle-effect-img';
		if ( !empty( $atts['image_size'] ) ) $atts['size'] = $atts['image_size'];
		$image_shortcode = intense_run_shortcode( 'intense_image', $atts );

		if ( !empty( $link ) ) $output .= '<a href="' . $link . '">';
		$output .= '<div class="intense overlay subtle-effect' . ( !empty( $class ) ? ' ' . $class : '' ) . '">';
		$output .= "<figure class='intense effect-" . $subtleeffect . "' style='" . ( !empty( $subtleheight ) ? $subtleheight . ';' : '' ) . ( !empty( $link ) ? 'cursor:pointer;' : 'cursor: default;' ) . "'>";		
		$output .= $image_shortcode;
		$output .= '<figcaption class="subtle-effect-caption">';
		$output .= '<h2>' . ( !empty( $split_title[0] ) ? esc_html( $split_title[0] ) : '' ) . "<span>" . ( !empty( $split_title[1] ) ? ' ' . esc_html( $split_title[1] ) : '' ) . "</span>" . ( !empty( $split_title[2] ) ? ' ' . esc_html( $split_title[2] ) : '' ) . '</h2>';
		$output .= '<p>';
		$output .= do_shortcode( $content );
		$output .= '</p>';
		$output .= '</figcaption>';
		$output .= '</figure>';
		$output .= '</div>';
		if ( !empty( $link ) ) $output .= '</a>';

		return $output;
	}
}
