<?php
/**
 * Postmag widget Social
 * @package Postmagthemes
 * @subpackage Postmag
 */
if ( ! class_exists( 'Postmag_Social_Widget' ) ) :
	class Postmag_Social_Widget extends WP_Widget{  // this whole class is to make one widget called Cutome Recentpost
		function __construct() {
			parent::__construct(
				'custome_social_widget', // Base ID
				__( 'Built - Social Link', 'postmag' ), // Name
				array( 'description' => __( 'Displays your Social link', 'postmag' ) )
			);
		}
		private function defaults(){
			$defaults = array(
				'socialpagename1' 	=> __( 'facebook', 'postmag' ),
				'sociallink1' 		=> __( '#', 'postmag' ),
				'socialpagename2' 	=> __( 'twitter', 'postmag' ),
				'sociallink2' 		=> __( '#', 'postmag' ),
				'socialpagename3' 	=> __( 'google-plus', 'postmag' ),
				'sociallink3' 		=> __( '#', 'postmag' ),
			);
			return $defaults;
		}
		public function form( $instance) {
			$instance = wp_parse_args( (array) $instance, $this->defaults() );
			$socialpagename1 = $instance[ 'socialpagename1' ];
			$sociallink1 = $instance[ 'sociallink1' ];
			$socialpagename2 = $instance[ 'socialpagename2' ];
			$sociallink2 = $instance[ 'sociallink2' ];
			$socialpagename3 = $instance[ 'socialpagename3' ];
			$sociallink3 = $instance[ 'sociallink3' ];
			?>
			<!-- CODE FOR CHOOSING Social link  -->
			<label><?php esc_attr_e( '1. Social page Name:', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'socialpagename1' ) );?>" name = "<?php echo esc_attr( $this -> get_field_name( 'socialpagename1' ) );?>" type = "text" value = "<?php echo esc_html( $socialpagename1 );?>" size = "15" />
			<label><?php esc_attr_e( 'Social page Link', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'sociallink1' ) ); ?>" name = "<?php echo esc_attr( $this -> get_field_name( 'sociallink1' ) ); ?>" type = "text" value = "<?php echo esc_url( $sociallink1 );?>" size = "30" />
			<br />
			<label> <?php esc_attr_e( '2. Social page Name:', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'socialpagename2' ) );?>" name = "<?php echo esc_attr( $this -> get_field_name( 'socialpagename2' ) ); ?>" type = "text" value = "<?php echo esc_html( $socialpagename2 );?>" size = "15" />
			<label><?php esc_attr_e( ' Social page Link', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'sociallink2' ) ); ?>" name = "<?php echo esc_attr( $this -> get_field_name( 'sociallink2' ) );?>" type = "text" value = "<?php echo esc_url( $sociallink2 );?>" size = "30" />
			<br />
			<label><?php esc_attr_e( '3. Social page Name:', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'socialpagename3' ) ); ?>" name = "<?php echo esc_attr( $this -> get_field_name( 'socialpagename3' ) );?>" type = "text" value = "<?php echo esc_html( $socialpagename3 );?>" size = "15" />
			<label><?php esc_attr_e( 'Social page Link ', 'postmag' ) ?></label>
			<input id = "<?php echo esc_attr( $this -> get_field_id( 'sociallink3' ) ); ?>" name = "<?php echo esc_attr( $this -> get_field_name( 'sociallink3' ) );?>" type = "text" value = "<?php echo esc_url( $sociallink3 );?>" size = "30" />
			<?php
		}
		public function update( $new_instance, $old_instance) {
			$instance = $old_instance;
			$instance[ 'socialpagename1' ] = sanitize_text_field( $new_instance[ 'socialpagename1' ] );
			$instance[ 'sociallink1' ] = esc_url_raw( $new_instance[ 'sociallink1' ] );
			$instance[ 'socialpagename2' ] = sanitize_text_field( $new_instance[ 'socialpagename2' ] );
			$instance[ 'sociallink2' ] = esc_url_raw( $new_instance[ 'sociallink2' ] );
			$instance[ 'socialpagename3' ] = sanitize_text_field( $new_instance[ 'socialpagename3' ] );
			$instance[ 'sociallink3' ] = esc_url_raw( $new_instance[ 'sociallink3' ] );
			return $instance;
		}
		public function widget( $args, $instance) {
			$instance = wp_parse_args( (array) $instance, $this->defaults() );
			$socialpagename1 = $instance[ 'socialpagename1' ];
			$sociallink1 =  $instance[ 'sociallink1' ];
			$socialpagename2 = $instance[ 'socialpagename2' ];
			$sociallink2 = $instance[ 'sociallink2' ];
			$socialpagename3 = $instance[ 'socialpagename3' ];
			$sociallink3 = $instance[ 'sociallink3' ];
			echo $args['before_widget'];
			$this->getRealtyListings( $socialpagename1,$sociallink1,$socialpagename2,$sociallink2,$socialpagename3,$sociallink3 );
			echo $args['after_widget'];

		}
		private function getRealtyListings( $socialpagename1,$sociallink1,$socialpagename2,$sociallink2,$socialpagename3,$sociallink3 ) {
			?>
			<div class = "myrow4">
			<a href = "<?php echo esc_url( $sociallink1 ); ?>" target="_blank" class = "fa socialwidget fa-<?php echo esc_attr( $socialpagename1 ); ?>" ></a>
			<a href = "<?php echo esc_url( $sociallink2 ); ?>" target="_blank" class = "fa socialwidget fa-<?php echo esc_attr( $socialpagename2 ); ?>" ></a>
			<a href = "<?php echo esc_url( $sociallink3 ); ?>" target="_blank" class = "fa socialwidget fa-<?php echo esc_attr( $socialpagename3 ); ?>" ></a>
			</div>
			<?php
		}
	} //end class social_Widget USED
endif;
