<?php

/*
 * @package WordPreciousss
 * @subpackage Precious_Parent_Theme
*/

/*register sidebar*/
	if ( function_exists('register_sidebars') )
			register_sidebars(1, array(
			'name'=>''.__('Default Sidebar', 'precious').'',
			'before_title' => '<h6>',
			'after_title' => '</h6>',
		));


/*meta widget*/
class Precious_Widget_Meta extends WP_Widget {

	function Precious_Widget_Meta() {
		$widget_ops = array('classname' => 'widget_meta', 'description' => __( 'Log in/out, admin and meta links', 'precious') );
		$this->WP_Widget('meta', __('Meta', 'precious'), $widget_ops);
	}

	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta', 'precious') : $instance['title']);

		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
?>
			<ul>
			<?php wp_register(); ?>
			<li><?php wp_loginout(); ?></li>
			<?php wp_meta(); ?>
			</ul>
<?php
		echo $after_widget;
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);

		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
		$title = strip_tags($instance['title']);
?>
			<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','precious'); ?> 
				<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>


<?php
	}
}

/*Random links widget*/
class Precious_Widget_Randomlinks extends WP_Widget {

	function Precious_Widget_Randomlinks() {
		$widget_ops = array('classname' => 'widget_randomlinks', 'description' => __( 'A list of seven random links', 'precious') );
		$this->WP_Widget('randomlinks', __('Random links', 'precious'), $widget_ops);
	}

	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Random Links', 'precious') : $instance['title']);

		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
?>
			<ul>
			<?php wp_list_bookmarks('orderby=rand&categorize=0&limit=7&title_li='); ?>
			</ul>
<?php
		echo $after_widget;
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['number'] = strip_tags($new_instance['number']);

		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
		$title = strip_tags($instance['title']);

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




<?php
	}
}

/*RSS feeds widget*/
class Precious_Widget_Feeds extends WP_Widget {

	function Precious_Widget_Feeds() {
		$widget_ops = array('classname' => 'widget_feeds', 'description' => __( 'Shows the RSS feed links for your blog', 'precious') );
		$this->WP_Widget('feedlinks', __('RSS Feeds', 'precious'), $widget_ops);
	}

	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('RSS Feeds', 'precious') : $instance['title']);


		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
?>
			<ul>
			<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('RSS Feed Posts','precious'); ?>">
				<?php precious_rssicon(__('RSS','precious')); ?> <?php _e('Posts','precious'); ?></a></li>
			<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('RSS Feed Comments','precious'); ?>">
				<?php precious_rssicon(__('RSS','precious')); ?> <?php _e('Comments','precious'); ?></a></li>
			</ul>
<?php
		echo $after_widget;
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);

		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', ) );
		$title = strip_tags($instance['title']);

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




<?php
	}
}

/*Link to home widget*/
class Precious_Widget_Home extends WP_Widget {

	function Precious_Widget_Home() {
		$widget_ops = array('classname' => 'widget_home', 'description' => __( 'Shows a link to the homepage of your blog', 'precious') );
		$this->WP_Widget('home', __('Home link', 'precious'), $widget_ops);
	}

	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Home', 'precious') : $instance['title']);

		if ( $title );
?>
		<?php if(!is_home() && !is_front_page()) { ?>
		<li id="homelink"><a href="<?php bloginfo('url'); ?>/"><?php echo $title; ?></a></li>
		<?php } ?>
<?php
		
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', ) );
		$title = strip_tags($instance['title']);

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




<?php
	}
}

/*Tagcloud widget*/
class Precious_Widget_TagCloud extends WP_Widget {

	function Precious_Widget_TagCloud() {
		$widget_ops = array('classname' => 'widget_tagcloud', 'description' => __( 'Shows a tagcloud', 'precious') );
		$this->WP_Widget('tagcloud', __('Tags', 'precious'), $widget_ops);
	}

	function widget( $args, $instance ) {
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Tags', 'precious') : $instance['title']);

		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
?>
		<?php wp_tag_cloud('smallest=0.8&largest=2&unit=em&format=list&number=45'); ?>
<?php
		echo $after_widget;
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);


		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', ) );
		$title = strip_tags($instance['title']);
		$number = strip_tags($instance['number']);

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




<?php
	}
}


// register the widgets  

function precious_widget_init() {  
	//unregister some default widgets
	unregister_widget('WP_Widget_Meta');	
	unregister_widget('WP_Widget_Tag_Cloud');	
	//register my own, my preciousss
	register_widget('Precious_Widget_Meta');  
	register_widget('Precious_Widget_Randomlinks');  
	register_widget('Precious_Widget_Feeds');  
	register_widget('Precious_Widget_Home');  
	register_widget('Precious_Widget_TagCloud');  
  }  
add_action('widgets_init', 'precious_widget_init');  






?>
