<?php
add_action('widgets_init','tigu_banner125x125_load_widgets');


function tigu_banner125x125_load_widgets(){
		register_widget("Tigu_banner125x125_Widget");
}

class Tigu_banner125x125_Widget extends WP_widget{
	
	function Tigu_banner125x125_Widget(){
		$widget_ops = array('classname' => 'tigu_banner125x125_widget', 'description' => 'Four Banners 125x125 for your sidebar widget');

		$control_ops = array('id_base' => 'tigu_banner125x125_widget');

		$this->WP_Widget('tigu_banner125x125_widget', 'GAMELEON: 125x125 banners', $widget_ops, $control_ops);
		
	}
	
	function widget($args,$instance){
		extract($args);
        $show_home = isset($instance['show_home']) ? 'true' : 'false';
        $show_page = isset($instance['show_page']) ? 'true' : 'false';
        $show_single = isset($instance['show_single']) ? 'true' : 'false';
		$link1 = $instance['link1'];
		$image1 = $instance['image1'];
		$code1 = $instance['code1'];
		
		$link2 = $instance['link2'];
		$image2 = $instance['image2'];
		$code2 = $instance['code2'];
		
		$link3 = $instance['link3'];
		$image3 = $instance['image3'];
		$code3 = $instance['code3'];
		
		$link4 = $instance['link4'];
		$image4 = $instance['image4'];
		$code4 = $instance['code4'];

		$alt1 = $instance['alt1'];
		$alt2 = $instance['alt2'];
		$alt3 = $instance['alt3'];
		$alt4 = $instance['alt4'];
        if ( ( is_home() && $show_home == 'false')  ||  ( is_page() && $show_page == 'false' ) || ( is_single() && $show_single == 'false' )){
        } else {
        echo $before_widget;
		
		?>
        <div class="banner125x125-sidebar">
		<?php
		if($link1 || $image1 || $code1){
		if($image1) {	
		?>	
			<div class="banner125x125"><a href="<?php echo $link1; ?>"><img src="<?php echo $image1; ?>" alt="<?php echo $alt1; ?>" /></a></div>
		<?php
		}
		else {
		?>
			<div class="banner125x125"><?php echo stripslashes($code1); ?></div>
		<?php }} ?>
		
		
		<?php
		if($link2 || $image2 || $code2){
		if($image2) {	
		?>				
			<div class="banner125x125 right"><a href="<?php echo $link2; ?>"><img src="<?php echo $image2; ?>" alt="<?php echo $alt2; ?>" /></a></div>
		<?php
		}
		else {
		?>
			<div class="banner125x125 right"><?php echo stripslashes($code2); ?></div>
		<?php }} ?>
		
		<?php
		if($link3 || $image3 || $code3){
		if($image3) {	
		?>				
			<div class="banner125x125"><a href="<?php echo $link3; ?>"><img src="<?php echo $image3; ?>" alt="<?php echo $alt3; ?>" /></a></div>
		<?php
		}
		else {
		?>
			<div class="banner125x125"><?php echo stripslashes($code3); ?></div>
		<?php }} ?>
		
		<?php
		if($link4 || $image4 || $code4){
		if($image4) {	
		?>				
			<div class="banner125x125 right"><a href="<?php echo $link4; ?>"><img src="<?php echo $image4; ?>" alt="<?php echo $alt4; ?>" /></a></div>
		<?php
		}
		else {
		?>
			<div class="banner125x125 right"><?php echo stripslashes($code4); ?></div>
		<?php }} ?>
		
		</div>
		
		
		<?php
		echo $after_widget;
	}
	}
	function update($new_instance, $old_instance){
		$instance = $old_instance;
		
		$instance['show_home'] = $new_instance['show_home'];
		$instance['show_page'] = $new_instance['show_page'];
		$instance['show_single'] = $new_instance['show_single'];
		$instance['link1'] = $new_instance['link1'];
		$instance['image1'] = $new_instance['image1'];
		$instance['code1'] = $new_instance['code1'];
		
		$instance['link2'] = $new_instance['link2'];
		$instance['image2'] = $new_instance['image2'];
		$instance['code2'] = $new_instance['code2'];
		
		$instance['link3'] = $new_instance['link3'];
		$instance['image3'] = $new_instance['image3'];
		$instance['code3'] = $new_instance['code3'];
		
		$instance['link4'] = $new_instance['link4'];
		$instance['image4'] = $new_instance['image4'];
		$instance['code4'] = $new_instance['code4'];

		$instance['alt1'] = $new_instance['alt1'];
		$instance['alt2'] = $new_instance['alt2'];
		$instance['alt3'] = $new_instance['alt3'];
		$instance['alt4'] = $new_instance['alt4'];
		
		return $instance;
	}
	
	function form($instance){
		$defaults = array(
        'show_home' => 'on',
        'show_page' => 'on',
        'show_single' => 'on',
        'link1' => '', 
        'link2' => '',
        'link3' => '',
        'link4' => '',
        'code1' => '',
        'code2' => '',
        'code3' => '',
        'code4' => '',
        'image1' => '', 
        'image2' => '',
        'image3' => '',
        'image4' => '',
        'alt1' => 'banner',
        'alt2' => 'banner',
        'alt3' => 'banner',
        'alt4' => 'banner'
);
		$instance = wp_parse_args((array) $instance, $defaults); ?>
		<h3><u>Banner Add 1</u></h3>
		<h4>USING IMAGE</h4>
	<p>
			<label for="<?php echo $this->get_field_id('image1'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image1'); ?>" name="<?php echo $this->get_field_name('image1'); ?>" value="<?php echo $instance['image1']; ?>" />
		</p>

		<p>
			<label for="<?php echo $this->get_field_id('link1'); ?>">Target Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link1'); ?>" name="<?php echo $this->get_field_name('link1'); ?>" value="<?php echo $instance['link1']; ?>" />
		</p>
		  <p>
			<label for="<?php echo $this->get_field_id('alt1'); ?>">Image <em>alt</em> attribute:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('alt1'); ?>" name="<?php echo $this->get_field_name('alt1'); ?>" value="<?php echo $instance['alt1']; ?>" />
         An imagine element must have an <em>alt</em> attribute, useful for markup validation.
	    </p>

			<h4 style='margin-top: 40px;'>OR USING CUSTOM CODE</h4>
		<p>
			<textarea class="widefat" rows="5" cols="10" id="<?php echo $this->get_field_id('code1'); ?>" name="<?php echo $this->get_field_name('code1'); ?>"><?php echo $instance['code1']; ?></textarea>
		</p>
		
		<h3><u>Banner Add 2</u></h3>
		<h4>USING IMAGE</h4>
	<p>
			<label for="<?php echo $this->get_field_id('image2'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image2'); ?>" name="<?php echo $this->get_field_name('image2'); ?>" value="<?php echo $instance['image2']; ?>" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('link2'); ?>">Target Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link2'); ?>" name="<?php echo $this->get_field_name('link2'); ?>" value="<?php echo $instance['link2']; ?>" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('alt2'); ?>">Image <em>alt</em> attribute:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('alt2'); ?>" name="<?php echo $this->get_field_name('alt2'); ?>" value="<?php echo $instance['alt2']; ?>" />
         An imagine element must have an <em>alt</em> attribute, useful for markup validation.
	    </p>
		<h4 style='margin-top: 40px;'>OR USING CUSTOM CODE</h4>
		<p>
			<textarea class="widefat" rows="5" cols="10" id="<?php echo $this->get_field_id('code2'); ?>" name="<?php echo $this->get_field_name('code2'); ?>"><?php echo $instance['code2']; ?></textarea>
		</p>
		
		<h3><u>Banner Add 3</u></h3>
		<h4>USING IMAGE</h4>
		<p>
			<label for="<?php echo $this->get_field_id('image3'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image3'); ?>" name="<?php echo $this->get_field_name('image3'); ?>" value="<?php echo $instance['image3']; ?>" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('link3'); ?>">Target Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link3'); ?>" name="<?php echo $this->get_field_name('link3'); ?>" value="<?php echo $instance['link3']; ?>" />
		</p>
			<p>
			<label for="<?php echo $this->get_field_id('alt3'); ?>">Image <em>alt</em> attribute:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('alt3'); ?>" name="<?php echo $this->get_field_name('alt3'); ?>" value="<?php echo $instance['alt3']; ?>" />
         An imagine element must have an <em>alt</em> attribute, useful for markup validation.
	    </p>

			<h4 style='margin-top: 40px;'>OR USING CUSTOM CODE</h4>
		<p>
			<textarea class="widefat" rows="5" cols="10" id="<?php echo $this->get_field_id('code3'); ?>" name="<?php echo $this->get_field_name('code3'); ?>"><?php echo $instance['code3']; ?></textarea>
		</p>
		
		<h3><u>Banner Add 4</u></h3>
		<h4>USING IMAGE</h4>
		<p>
			<label for="<?php echo $this->get_field_id('image4'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image4'); ?>" name="<?php echo $this->get_field_name('image4'); ?>" value="<?php echo $instance['image4']; ?>" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('link4'); ?>">Target Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link4'); ?>" name="<?php echo $this->get_field_name('link4'); ?>" value="<?php echo $instance['link4']; ?>" />
		</p>
		
			<p>
			<label for="<?php echo $this->get_field_id('alt4'); ?>">Image <em>alt</em> attribute:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('alt4'); ?>" name="<?php echo $this->get_field_name('alt4'); ?>" value="<?php echo $instance['alt4']; ?>" />
         An imagine element must have an <em>alt</em> attribute, useful for markup validation.
	    </p>
			<h4 style='margin-top: 40px;'>OR USING CUSTOM CODE</h4>
		<p>
			<textarea class="widefat" rows="5" cols="10" id="<?php echo $this->get_field_id('code4'); ?>" name="<?php echo $this->get_field_name('code4'); ?>"><?php echo $instance['code4']; ?></textarea>
		</p>
		         <p>
         <input class="checkbox" type="checkbox" <?php checked($instance['show_home'], 'on'); ?> id="<?php echo $this->get_field_id('show_home'); ?>" name="<?php echo $this->get_field_name('show_home'); ?>" />
         <label for="<?php echo $this->get_field_id('show_home'); ?>">Show on Home Page?</label>
         </p>
         <p>
         <input class="checkbox" type="checkbox" <?php checked($instance['show_page'], 'on'); ?> id="<?php echo $this->get_field_id('show_page'); ?>" name="<?php echo $this->get_field_name('show_page'); ?>" />
         <label for="<?php echo $this->get_field_id('show_page'); ?>">Show on Single Page?</label>
        </p>
   <p>
         <input class="checkbox" type="checkbox" <?php checked($instance['show_single'], 'on'); ?> id="<?php echo $this->get_field_id('show_single'); ?>" name="<?php echo $this->get_field_name('show_single'); ?>" />
         <label for="<?php echo $this->get_field_id('show_single'); ?>">Show on Single Post?</label>
        </p>
		<?php

	}
}
?>