
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

add_action( 'widgets_init', 'presso_widgets_init_custom_banner' );
if ( ! function_exists( 'presso_widgets_init_custom_banner' ) ) {
	function presso_widgets_init_custom_banner() {
		register_widget( 'Presso__widget_custom_banner' );
	}
}

if ( ! class_exists( 'Presso__widget_custom_banner' ) ) {
	class Presso__widget_custom_banner extends WP_Widget {
		private $default = array(
			'supertitle' => '',
			'title' => '',
			'subtitle' => '',
			'imgurl' => '',
			'linkurl' => '',
			'buttontext' => '',
		);

		public function __construct() {
			// widget actual processes
			parent::__construct(
		 		'vw_widget_custom_banner', // Base ID
				PRESSO_THEME_NAME.': Custom Banner', // Name
				array( 'description' => esc_html__( "Display a custom banner", 'presso' ) ) // Args
			);
		}

		function widget( $args, $instance ) {
			extract($args);

			$instance['supertitle'] = apply_filters( 'wpml_translate_single_string', $instance['supertitle'], 'Widgets', $this->id.'_supertitle' );
			$instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
			$instance['subtitle'] = apply_filters( 'wpml_translate_single_string', $instance['subtitle'], 'Widgets', $this->id.'_subtitle' );
			$instance['buttontext'] = apply_filters( 'wpml_translate_single_string', $instance['buttontext'], 'Widgets', $this->id.'_buttontext' );

			$instance = wp_parse_args( (array) $instance, $this->default );

			echo wp_kses_post( $before_widget );

			?>
				<div class="vw-custom-banner" style="background-image: url( <?php echo esc_url( $instance['imgurl'] ); ?>);">
					<div class="vw-custom-banner__inner">

						<?php if ( ! empty( $instance['supertitle'] ) ) : ?>
						<h6 class="vw-custom-banner__supertitle"><?php echo esc_html( $instance['supertitle'] ); ?></h6>
						<?php endif; ?>

						<?php if ( ! empty( $instance['title'] ) ) : ?>
						<h3 class="vw-custom-banner__title"><?php echo esc_html( apply_filters( 'widget_title', wp_kses_data( $instance['title'] ), $instance, $this->id_base) ); ?></h3>
						<?php endif; ?>
						
						<?php if ( ! empty( $instance['subtitle'] ) ) : ?>
						<div class="vw-custom-banner__subtitle"><?php echo esc_html( $instance['subtitle'] ); ?></div>
						<?php endif; ?>
						
						<?php if ( ! empty( $instance['linkurl'] ) ) : ?>
						<a class="vw-custom-banner__button vw-button vw-button--small vw-button--accent" href="<?php echo esc_url( $instance['linkurl'] ); ?>" class="vw-custom-banner__button"><?php echo esc_html( $instance['buttontext'] ); ?></a>
						<?php endif; ?>

					</div>
				</div>
			<?php

			echo wp_kses_post( $after_widget );
		}

		function update( $new_instance, $old_instance ) {
			$instance = $old_instance;
			$new_instance = wp_parse_args( (array) $new_instance, $this->default );
			$instance['supertitle'] = sanitize_text_field( $new_instance['supertitle'] );
			$instance['title'] = sanitize_text_field( $new_instance['title'] );
			$instance['subtitle'] = sanitize_text_field( $new_instance['subtitle'] );
			$instance['imgurl'] = esc_url( $new_instance['imgurl'] );
			$instance['linkurl'] = esc_url( $new_instance['linkurl'] );
			$instance['buttontext'] = sanitize_text_field( $new_instance['buttontext'] );

			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_supertitle', $instance['supertitle'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_title', $instance['title'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_subtitle', $instance['subtitle'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_buttontext', $instance['buttontext'] );

			return $instance;
		}

		function form( $instance ) {
			$instance = wp_parse_args( (array) $instance, $this->default );

			$supertitle = $instance['supertitle'];
			$title = $instance['title'];
			$subtitle = $instance['subtitle'];
			$imgurl = $instance['imgurl'];
			$linkurl = $instance['linkurl'];
			$buttontext = $instance['buttontext'];
			?>

			<!-- supertitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>"><?php esc_html_e( 'Super-title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('supertitle') ); ?>" type="text" value="<?php echo esc_attr($supertitle); ?>" />
			</p>

			<!-- title -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e( 'Title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
			</p>

			<!-- subtitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>"><?php esc_html_e( 'Subtitle:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('subtitle') ); ?>" type="text" value="<?php echo esc_attr($subtitle); ?>" />
			</p>

			<!-- imgurl -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('imgurl') ); ?>"><?php esc_html_e( 'Image Url:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('imgurl') ); ?>" name="<?php echo esc_attr( $this->get_field_name('imgurl') ); ?>" type="text" value="<?php echo esc_attr($imgurl); ?>" />
			</p>

			<!-- linkurl -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('linkurl') ); ?>"><?php esc_html_e( 'Link Url:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('linkurl') ); ?>" name="<?php echo esc_attr( $this->get_field_name('linkurl') ); ?>" type="text" value="<?php echo esc_attr($linkurl); ?>" />
			</p>

			<!-- buttontext -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('buttontext') ); ?>"><?php esc_html_e( 'Button Label:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('buttontext') ); ?>" name="<?php echo esc_attr( $this->get_field_name('buttontext') ); ?>" type="text" value="<?php echo esc_attr($buttontext); ?>" />
			</p>


			<?php
		}
	}
}