<?php
/**
 * Widget Name: AIO Banner
 *
 * @package All In One Custom Post
 * @since All In One Custom Post 1.0.0 
 */

if ( ! class_exists( 'vr_widget_banner' ) ) {
	class vr_widget_banner extends WP_Widget {

		// Widget Construct
		public function __construct() {
			parent::__construct(
				false,
				_x( 'AIO Banner' , 'backend', PLUGIN_NAME),
				array(
					'description' => _x( 'Display banner.', 'backend', PLUGIN_NAME),
					'classname'   => 'aio-widget-banner',
				)
			);
		}

		// Widget Init
		public function widget( $args, $instance ) {
						
			$title		= empty( $instance['title'] ) ? '' : $instance['title'];
			$module		= empty( $instance['module'] ) ? '' : $instance['module'];
			$header		= empty( $instance['header'] ) ? '' : $instance['header'];
			$content	= empty( $instance['content'] ) ? '' : $instance['content'];
			$button		= empty( $instance['button'] ) ? '' : $instance['button'];
			$animation	= empty( $instance['animation'] ) ? '' : $instance['animation'];
			$ani		= '';

			if ( $animation != '' ) { $animation = 'data-animation="' . $animation . '"'; $ani = 'fx-start'; }

			echo $args['before_widget'];
			if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; }
			?>
		
				<?php if ( $module == 'left' ) : ?>
			
					<article class="banner-left clearfix <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
						<div class="banner-head">
							<h2><?php echo wp_filter_kses( $header ); ?></h2>
							<?php if ( $content != '' ) : ?>
								<p><?php echo wp_filter_kses( $content ); ?></p>
							<?php endif; ?>
						</div>
						<div class="banner-foot">
							<?php echo do_shortcode( $button ); ?>
						</div>
					</article>
					
				<?php else : ?>
				
					<article class="banner-center clearfix <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
						<div class="banner-inner">
							<h2><?php echo wp_filter_kses( $header ); ?></h2>
							<div class="line-center"></div>
							<?php if ( $content != '' ) : ?>
								<p><?php echo wp_filter_kses( $content ); ?></p>
							<?php endif; ?>
							<?php echo do_shortcode( $button ); ?>
						</div>
					</article>
			
				<?php endif; ?>
		
			<?php
			echo $args['after_widget'];
		}

		// Form Update
		public function update( $new_instance, $old_instance ) {
			$instance = array();

			$instance['title'] 		= wp_strip_all_tags( $new_instance['title'] );
			$instance['module'] 	= esc_attr( $new_instance['module'] );
			$instance['header'] 	= wp_filter_kses( $new_instance['header'] );
			$instance['content'] 	= wp_filter_kses( $new_instance['content'] );
			$instance['button'] 	= $new_instance['button'];
			$instance['animation'] 	= esc_attr( $new_instance['animation'] );

			return $instance;
		}

		// Widget Form
		public function form( $instance ) {

			$title		= empty( $instance['title'] ) ? '' : $instance['title'];
			$module		= empty( $instance['module'] ) ? 'center' : $instance['module'];
			$header		= empty( $instance['header'] ) ? '' : $instance['header'];
			$content	= empty( $instance['content'] ) ? '' : $instance['content'];
			$button		= empty( $instance['button'] ) ? '' : $instance['button'];
			$animation	= empty( $instance['animation'] ) ? '' : $instance['animation'];
			
			?>

			<p>
				<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget Title :', PLUGIN_NAME ); ?></label>
				<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" style="width:100%;" type="text" />
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'header' ); ?>"><?php _e( 'Caption :', PLUGIN_NAME ); ?></label>
				<textarea id="<?php echo $this->get_field_id( 'header' ); ?>" name="<?php echo $this->get_field_name( 'header' ); ?>" style="width:100%;" rows="6"><?php echo wp_filter_kses( $header ); ?></textarea>
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'content' ); ?>"><?php _e( 'Content :', PLUGIN_NAME ); ?></label>
				<textarea id="<?php echo $this->get_field_id( 'content' ); ?>" name="<?php echo $this->get_field_name( 'content' ); ?>" style="width:100%;" rows="6"><?php echo wp_filter_kses( $content ); ?></textarea>
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button :', PLUGIN_NAME ); ?></label>
				<textarea id="<?php echo $this->get_field_id( 'button' ); ?>" name="<?php echo $this->get_field_name( 'button' ); ?>" style="width:100%;" rows="6"><?php echo $button; ?></textarea>
				<small>Note: add button shortcode [shortcode_button module="main" size="big" title="More" url="#" icon="fa-plus"].</small>
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'module' ); ?>"><?php _e( 'Module :', PLUGIN_NAME ); ?></label>
				<select id="<?php echo $this->get_field_id( 'module' ); ?>" name="<?php echo $this->get_field_name( 'module' ); ?>" style="width:100%;">
					<option value="left" <?php if ( $module == 'left' ) { echo 'selected="selected"'; } ?>>Left</option>
					<option value="center" <?php if ( $module == 'center' ) { echo 'selected="selected"'; } ?>>Center</option>
				</select>
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'animation' ); ?>"><?php _e( 'Animation :', PLUGIN_NAME ); ?></label>
				<select id="<?php echo $this->get_field_id( 'animation' ); ?>" name="<?php echo $this->get_field_name( 'animation' ); ?>" style="width:100%;">
					<option value="" <?php if ( $animation == '' ) { echo 'selected="selected"'; } ?>>None</option>
					<option value="fadeIn" <?php if ( $animation == 'fadeIn' ) { echo 'selected="selected"'; } ?>>fadeIn</option>
					<option value="fadeInUp" <?php if ( $animation == 'fadeInUp' ) { echo 'selected="selected"'; } ?>>fadeInUp</option>
					<option value="fadeInDown" <?php if ( $animation == 'fadeInDown' ) { echo 'selected="selected"'; } ?>>fadeInDown</option>
					<option value="fadeInLeft" <?php if ( $animation == 'fadeInLeft' ) { echo 'selected="selected"'; } ?>>fadeInLeft</option>
					<option value="fadeInRight" <?php if ( $animation == 'fadeInRight' ) { echo 'selected="selected"'; } ?>>fadeInRight</option>
					<option value="rotateFromLeft" <?php if ( $animation == 'rotateFromLeft' ) { echo 'selected="selected"'; } ?>>rotateFromLeft</option>
					<option value="rotateFromRight" <?php if ( $animation == 'rotateFromRight' ) { echo 'selected="selected"'; } ?>>rotateFromRight</option>
					<option value="flipInX" <?php if ( $animation == 'flipInX' ) { echo 'selected="selected"'; } ?>>flipInX</option>
					<option value="flipOutX" <?php if ( $animation == 'flipOutX' ) { echo 'selected="selected"'; } ?>>flipOutX</option>
					<option value="flipInY" <?php if ( $animation == 'flipInY' ) { echo 'selected="selected"'; } ?>>flipInY</option>
					<option value="flipOutY" <?php if ( $animation == 'flipOutY' ) { echo 'selected="selected"'; } ?>>flipOutY</option>
					<option value="bounceIn" <?php if ( $animation == 'bounceIn' ) { echo 'selected="selected"'; } ?>>zoomIn</option>
					<option value="bounceInUp" <?php if ( $animation == 'bounceInUp' ) { echo 'selected="selected"'; } ?>>bounceInUp</option>
					<option value="bounceInDown" <?php if ( $animation == 'bounceInDown' ) { echo 'selected="selected"'; } ?>>bounceInDown</option>
					<option value="bounceInLeft" <?php if ( $animation == 'bounceInLeft' ) { echo 'selected="selected"'; } ?>>bounceInLeft</option>
					<option value="bounceInRight" <?php if ( $animation == 'bounceInRight' ) { echo 'selected="selected"'; } ?>>bounceInRight</option>
				</select>
			</p>

			<?php
		}

	}
	add_action( 'widgets_init', create_function( '', 'register_widget( "vr_widget_banner" );' ) );
}