<?php
/*
Plugin Name: StudioPress eNews and Updates
Description: This plugin/widget allows you to place an eNews and Updates widget in your sidebar.
Author: Nathan Rice
Author URI: http://www.nathanrice.net/
Version: 1.0
*/

add_action('widgets_init', create_function('', "register_widget('eNews_Updates');"));
class eNews_Updates extends WP_Widget {

	function eNews_Updates() {
		$widget_ops = array( 'classname' => 'enews-widget', 'description' => 'Displays eNews &amp; Updates signup form' );
		$control_ops = array( 'width' => 200, 'height' => 250, 'id_base' => 'enews' );
		$this->WP_Widget( 'enews', 'eNews and Updates', $widget_ops, $control_ops );
	}

	function widget($args, $instance) {
		extract($args);
		
		echo $before_widget.'<div class="enews">';
		
			if (!empty($instance['title']))
				echo $before_title . $instance['title'] . $after_title;
			
			echo wpautop($instance['text']);
			
			if(!empty($instance['id'])) { ?>
			<form id="subscribe" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo $instance['id']; ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"><input type="text" value="Enter your email address..." id="subbox" onfocus="if (this.value == 'Enter your email address...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter your email address...';}" name="email"/><input type="hidden" value="<?php echo $instance['id']; ?>" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="GO" id="subbutton" /></form>
			<?php }
				
		echo '</div>'.$after_widget;
	}

	function update($new_instance, $old_instance) {
		return $new_instance;
	}

	function form($instance) { ?>
		<p>
		<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e("Title"); ?>:</label><br />
		<input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:95%;" />
		</p>
		
		<p>
		<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text To Show'); ?>:</label><br />
		<textarea id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" style="width: 95%;" rows="6"><?php echo $instance['text']; ?></textarea>
		</p>
		
		<p>
		<label for="<?php echo $this->get_field_id('id'); ?>"><?php _e("Google/Feedburner ID"); ?>:</label>
		<input id="<?php echo $this->get_field_id('id'); ?>" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $instance['id']; ?>" style="width:95%;" />
		</p>
		
	<?php 
	}
}
?>