<?php

class Intense_Timeline_Event extends Intense_Shortcode {

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

		global $intense_visions_options;

		$this->title = __( 'Timeline Event', 'intense' );
		$this->category = __( 'Layout', 'intense' );
		$this->show_preview = true;
		$this->hidden = true;
		$this->parent = 'intense_timeline';
		$this->is_container = true;

		// 'use_content' => 0, //options: 1,0 - will use inner content instead of using this layout
	}

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

		$output = '';
		global $currentYear;
		global $showyear;
		global $event_number;
		global $intense_visions_options;
		global $previous_featured;

		$radius = '';
	    if ( isset( $event_border_radius ) ) {
	        $radius = ' border-radius:' . $event_border_radius . ' !important;';
	    }

		if ( isset( $images ) && strpos( $images, "," ) > 0 ) {
			$slider = "[intense_slider]";
			$images = preg_split("/[,]/", $images);

			foreach ( $images as $image ) {
				$slider .= "[intense_slide][intense_image imageid='" . trim( $image ) . "' border_radius='" . $image_border_radius . "' size='" . $image_size . "'][/intense_slide]";
			}

			$slider .= "[/intense_slider]";

			$image = do_shortcode( $slider );
		} elseif ( isset( $images ) ) {
			$image = do_shortcode( "[intense_image imageid='" . trim( $images ) . "' border_radius='" . $image_border_radius . "' size='" . $image_size . "']" );
		} else {
			$image = '';
		}

		if ( !empty( $animation_type ) ) {
			$animation_wrapper_start = intense_get_animation_wrapper_start( $animation_type, $animation_trigger, $animation_scroll_percent, $animation_delay );
			$animation_wrapper_end = intense_get_animation_wrapper_end();
		} else {
			$animation_wrapper_start = null; 
			$animation_wrapper_end = null;
		}

		$eventYear = date( 'Y', strtotime( $date ) );
		$colorset = "color" . rand();
		$featured_class = ( $featured ? 'featured ' : '' );

		$output .= $animation_wrapper_start;

		if ( $previous_featured && $event_number % 2 != 0 && !$featured ) {
			$output .= "<li class='intense event' style='visibility: hidden;'></li>";
			$event_number++;
		}

		if ( $featured ) {
			$previous_featured = 1;
		} else {
			$previous_featured = 0;
		}

		if ( ( $currentYear == '' || $currentYear != $eventYear ) ) {
			$currentYear = $eventYear;

			if ( $showyear ) {
				$output .= "<li class='intense intense_post year'>" . $currentYear . "</li>";
			}

			if ( $showyear || $event_number == 0 ) {
				if ( !$showyear ) {
					$output .= "<li></li>";
				}
				$output .= "<li class='intense intense_post " . $colorset . " event offset-first $featured_class" . ( is_rtl() ? "rtl " : "" ) . "'>";
			} else {
				$output .= "<li class='intense intense_post " . $colorset . " event $featured_class'>";
			}

			$output .= "<style>." . $colorset . " { background: " . $color . " !important; " . $radius . " } ." . $colorset . ":hover { background: " . intense_adjust_color_brightness( $color, -20 ) . " !important; }</style>";
		} else {
			$output .= "<li class='intense intense_post " . $colorset . " event $featured_class'>";			
			$output .= "<style>." . $colorset . " { background: " . $color . " !important; " . $radius . " } ." . $colorset . ":hover { background: " . intense_adjust_color_brightness( $color, -20 ) . " !important; }</style>";
		}

		if ($type == 'blog_post') {
			if ( $use_content ) {
				$output .= trim( do_shortcode( $content ) );
			} else {
				$post_shortcode = "[intense_row padding_top='5']";
				$post_shortcode .= "[intense_column size='6']<div class='title'><h3 class='title'>" . $title . "</h3></div>[/intense_column][intense_column size='6']<div class='date'>" . date( 'F j, Y', strtotime( $date ) ) . "</div>[/intense_column]";
				$post_shortcode .= "[/intense_row]";
				$post_shortcode .= "<div>";
				$post_shortcode .= $image;
				$post_shortcode .= "</div>";
				$post_shortcode .= "<div class='content'>" . trim( do_shortcode( $content ) ) . "</div><div style='height:25px;'><a class='pull-right' href='" . $readmore . "' target='" . $readmore_target . "'>" . $readmore_text . "</a></div>";	
				$output .= do_shortcode( $post_shortcode );	
			}	
		}

		if ($type == 'custom') {
			$output .= trim( do_shortcode( $content ) );
		}

		if ( $type == 'slider' ) {
			if ( $title != '' ) {
				$title_shortcode = "[intense_row padding_top='5']";
				$title_shortcode .= "[intense_column size='12']<div class='title'><h3>" . $title . "</h3></div>[/intense_column]";
				$title_shortcode .= "[/intense_row]";
				$output .= do_shortcode( $title_shortcode );
			}

			$output .= "<div>";
			$output .= $image;
			$output .= "</div>";
		}

		$output .= "</li>";
		$output .= $animation_wrapper_end;

		$event_number++;

		return $output;

		return $output;
	}
}
