<?php
/*
Plugin Name: Vidall Widgets
Plugin URI: http://vidall.co.uk
Description: A plugin for various widgets
Version: 1.0
Author: Vidall
Author URI: http://vidall.co.uk
License: GPL2
*/


class ventoux_address_widget extends WP_Widget {

// constructor
    function ventoux_address_widget() {
        parent::WP_Widget(false, $name = __('Ventoux address widget', 'ventoux') );
    }

	// widget form creation
function form($instance) {

// Check values
if( $instance) {
     $title = esc_attr($instance['title']);
     $text = esc_attr($instance['text']);
     $text2 = esc_attr($instance['text2']);
     $text3 = esc_attr($instance['text3']);
     $text4 = esc_attr($instance['text4']);
     $text5 = esc_attr($instance['text5']);

     $textarea = esc_textarea($instance['textarea']);
} else {
     $title = '';
     $text = '';
     $text2 = '';
     $text3 = '';
     $textarea = '';
}
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Address line 1:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo $text; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text2'); ?>"><?php _e('Address line 2:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text2'); ?>" name="<?php echo $this->get_field_name('text2'); ?>" type="text2" value="<?php echo $text2; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text3'); ?>"><?php _e('Address line 3:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text3'); ?>" name="<?php echo $this->get_field_name('text3'); ?>" type="text3" value="<?php echo $text3; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text4'); ?>"><?php _e('Phone number:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text4'); ?>" name="<?php echo $this->get_field_name('text4'); ?>" type="text4" value="<?php echo $text4; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text5'); ?>"><?php _e('Mobile phone number:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text5'); ?>" name="<?php echo $this->get_field_name('text5'); ?>" type="text5" value="<?php echo $text5; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Extra text:', 'wp_widget_plugin'); ?></label>
<textarea class="widefat" id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>"><?php echo $textarea; ?></textarea>
</p>
<?php
}



	// update widget
function update($new_instance, $old_instance) {
      $instance = $old_instance;
      // Fields
      $instance['title'] = strip_tags($new_instance['title']);
      $instance['text'] = strip_tags($new_instance['text']);
      $instance['text2'] = strip_tags($new_instance['text2']);
      $instance['text3'] = strip_tags($new_instance['text3']);
      $instance['text4'] = strip_tags($new_instance['text4']);
      $instance['text5'] = strip_tags($new_instance['text5']);
      $instance['textarea'] = strip_tags($new_instance['textarea']);
     return $instance;
}

	// display widget
function widget($args, $instance) {
   extract( $args );
   // these are the widget options
   $title = apply_filters('widget_title', $instance['title']);
   $text = $instance['text'];
   $text2 = $instance['text2'];
   $text3 = $instance['text3'];
   $text4 = $instance['text4'];
   $text5 = $instance['text5'];
   $textarea = $instance['textarea'];
   echo $before_widget;
   // Display the widget
   echo '<div class="widget-text wp_widget_plugin_box vf-address-background">';

   // Check if title is set
   if ( $title ) {
    echo '<h5>' . $title . '</h5>';
   }

   // Check if text is set
   if( $text ) {
    echo '<ul class="wp_widget_plugin_text"><li><i class="icons icon_pin"></i>  '.$text.'</li>';
   }
   // Check if text is set
   if( $text2 ) {
    echo '<li>'.$text2.'</li>';
   }
   // Check if text is set
   if( $text3 ) {
    echo '<li> '.$text3.'</li>';
   }
     // Check if text is set
   if( $text4 ) {
    echo '<li><i class="icons icon_phone"></i>  '.$text4.'</li>';
   }
     // Check if text is set
   if( $text5 ) {
    echo '<li><i class="icons icon_mobile"></i>  '.$text5.'</li></ul>';
   }
   // Check if textarea is set
   if( $textarea ) {
     echo '<p class="wp_widget_plugin_textarea">'.$textarea.'</p>';
   }
   echo '</div>';
   echo $after_widget;
}
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("ventoux_address_widget");'));





class ventoux_image_widget extends WP_Widget
{

  public function __construct()
  {
    parent::__construct(
      'ventoux-image-widget',
      'Ventoux image widget',
      array(
        'description' => 'Image widget'
      )
    );
  }

  public function widget( $args, $instance ){
    extract( $args );
    // basic output just for this example
    echo $before_widget;
    echo '
      <img src="'.esc_url($instance['image_uri']).'" />
    ';
    echo $after_widget;
  }

  public function form( $instance )
  {
    // removed the for loop, you can create new instances of the widget instead
    ?>
    <p>
      <label for="<?php echo $this->get_field_id('text'); ?>">Text</label><br />
      <input type="text" name="<?php echo $this->get_field_name('text'); ?>" id="<?php echo $this->get_field_id('text'); ?>" value="<?php echo $instance['text']; ?>" class="widefat" />
    </p>
    <p>
      <label for="<?php echo $this->get_field_id('image_uri'); ?>">Image</label><br />
      <input type="text" class="img" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $instance['image_uri']; ?>" />
      <input type="button" class="select-img" value="Select Image" />
    </p>
    <?php
  }


} 
// end class

// init the widget
add_action( 'widgets_init', create_function('', 'return register_widget("ventoux_image_widget");') );

// queue up the necessary js
function ventoux_image_widget_enqueue()
{
  $screen = get_current_screen();
  if ('widgets' == $screen->id) {
    wp_enqueue_style('thickbox');
  wp_enqueue_script('media-upload');
  wp_enqueue_script('thickbox');
  // moved the js to an external file, you may want to change the path
  wp_enqueue_script('ventoux', '/wp-content/plugins/vidall_widgets/uploader.js', null, null, true);
}
  }
  
add_action('admin_enqueue_scripts', 'ventoux_image_widget_enqueue');