web/wp-includes/default-widgets.php
changeset 194 32102edaa81b
parent 144 df0ebfb22f63
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 
       
     3 /**
     2 /**
     4  * Default Widgets
     3  * Default Widgets
     5  *
     4  *
     6  * @package WordPress
     5  * @package WordPress
     7  * @subpackage Widgets
     6  * @subpackage Widgets
    12  *
    11  *
    13  * @since 2.8.0
    12  * @since 2.8.0
    14  */
    13  */
    15 class WP_Widget_Pages extends WP_Widget {
    14 class WP_Widget_Pages extends WP_Widget {
    16 
    15 
    17 	function WP_Widget_Pages() {
    16 	function __construct() {
    18 		$widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your blog&#8217;s WordPress Pages') );
    17 		$widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site&#8217;s WordPress Pages') );
    19 		$this->WP_Widget('pages', __('Pages'), $widget_ops);
    18 		parent::__construct('pages', __('Pages'), $widget_ops);
    20 	}
    19 	}
    21 
    20 
    22 	function widget( $args, $instance ) {
    21 	function widget( $args, $instance ) {
    23 		extract( $args );
    22 		extract( $args );
    24 
    23 
    25 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title']);
    24 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
    26 		$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    25 		$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    27 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    26 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    28 
    27 
    29 		if ( $sortby == 'menu_order' )
    28 		if ( $sortby == 'menu_order' )
    30 			$sortby = 'menu_order, post_title';
    29 			$sortby = 'menu_order, post_title';
    88  *
    87  *
    89  * @since 2.8.0
    88  * @since 2.8.0
    90  */
    89  */
    91 class WP_Widget_Links extends WP_Widget {
    90 class WP_Widget_Links extends WP_Widget {
    92 
    91 
    93 	function WP_Widget_Links() {
    92 	function __construct() {
    94 		$widget_ops = array('description' => __( "Your blogroll" ) );
    93 		$widget_ops = array('description' => __( "Your blogroll" ) );
    95 		$this->WP_Widget('links', __('Links'), $widget_ops);
    94 		parent::__construct('links', __('Links'), $widget_ops);
    96 	}
    95 	}
    97 
    96 
    98 	function widget( $args, $instance ) {
    97 	function widget( $args, $instance ) {
    99 		extract($args, EXTR_SKIP);
    98 		extract($args, EXTR_SKIP);
   100 
    99 
   101 		$show_description = isset($instance['description']) ? $instance['description'] : false;
   100 		$show_description = isset($instance['description']) ? $instance['description'] : false;
   102 		$show_name = isset($instance['name']) ? $instance['name'] : false;
   101 		$show_name = isset($instance['name']) ? $instance['name'] : false;
   103 		$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
   102 		$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
   104 		$show_images = isset($instance['images']) ? $instance['images'] : true;
   103 		$show_images = isset($instance['images']) ? $instance['images'] : true;
   105 		$category = isset($instance['category']) ? $instance['category'] : false;
   104 		$category = isset($instance['category']) ? $instance['category'] : false;
   106 
   105 		$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
   107 		if ( is_admin() && !$category ) {
   106 		$order = $orderby == 'rating' ? 'DESC' : 'ASC';
   108 			// Display All Links widget as such in the widgets screen
   107 		$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
   109 			echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget;
       
   110 			return;
       
   111 		}
       
   112 
   108 
   113 		$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
   109 		$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
   114 		wp_list_bookmarks(apply_filters('widget_links_args', array(
   110 		wp_list_bookmarks(apply_filters('widget_links_args', array(
   115 			'title_before' => $before_title, 'title_after' => $after_title,
   111 			'title_before' => $before_title, 'title_after' => $after_title,
   116 			'category_before' => $before_widget, 'category_after' => $after_widget,
   112 			'category_before' => $before_widget, 'category_after' => $after_widget,
   117 			'show_images' => $show_images, 'show_description' => $show_description,
   113 			'show_images' => $show_images, 'show_description' => $show_description,
   118 			'show_name' => $show_name, 'show_rating' => $show_rating,
   114 			'show_name' => $show_name, 'show_rating' => $show_rating,
   119 			'category' => $category, 'class' => 'linkcat widget'
   115 			'category' => $category, 'class' => 'linkcat widget',
       
   116 			'orderby' => $orderby, 'order' => $order,
       
   117 			'limit' => $limit,
   120 		)));
   118 		)));
   121 	}
   119 	}
   122 
   120 
   123 	function update( $new_instance, $old_instance ) {
   121 	function update( $new_instance, $old_instance ) {
   124 		$new_instance = (array) $new_instance;
   122 		$new_instance = (array) $new_instance;
   125 		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
   123 		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
   126 		foreach ( $instance as $field => $val ) {
   124 		foreach ( $instance as $field => $val ) {
   127 			if ( isset($new_instance[$field]) )
   125 			if ( isset($new_instance[$field]) )
   128 				$instance[$field] = 1;
   126 				$instance[$field] = 1;
   129 		}
   127 		}
   130 		$instance['category'] = intval($new_instance['category']);
   128 
       
   129 		$instance['orderby'] = 'name';
       
   130 		if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
       
   131 			$instance['orderby'] = $new_instance['orderby'];
       
   132 
       
   133 		$instance['category'] = intval( $new_instance['category'] );
       
   134 		$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
   131 
   135 
   132 		return $instance;
   136 		return $instance;
   133 	}
   137 	}
   134 
   138 
   135 	function form( $instance ) {
   139 	function form( $instance ) {
   136 
   140 
   137 		//Defaults
   141 		//Defaults
   138 		$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
   142 		$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
   139 		$link_cats = get_terms( 'link_category');
   143 		$link_cats = get_terms( 'link_category' );
       
   144 		if ( ! $limit = intval( $instance['limit'] ) )
       
   145 			$limit = -1;
   140 ?>
   146 ?>
   141 		<p>
   147 		<p>
   142 		<label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
   148 		<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
   143 		<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
   149 		<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
   144 		<option value=""><?php _e('All Links'); ?></option>
   150 		<option value=""><?php _ex('All Links', 'links widget'); ?></option>
   145 		<?php
   151 		<?php
   146 		foreach ( $link_cats as $link_cat ) {
   152 		foreach ( $link_cats as $link_cat ) {
   147 			echo '<option value="' . intval($link_cat->term_id) . '"'
   153 			echo '<option value="' . intval($link_cat->term_id) . '"'
   148 				. ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
   154 				. ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
   149 				. '>' . $link_cat->name . "</option>\n";
   155 				. '>' . $link_cat->name . "</option>\n";
   150 		}
   156 		}
   151 		?>
   157 		?>
   152 		</select></p>
   158 		</select>
       
   159 		<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
       
   160 		<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
       
   161 			<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
       
   162 			<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
       
   163 			<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
       
   164 			<option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _e( 'Random' ); ?></option>
       
   165 		</select>
       
   166 		</p>
   153 		<p>
   167 		<p>
   154 		<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
   168 		<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
   155 		<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
   169 		<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
   156 		<input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
   170 		<input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
   157 		<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
   171 		<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
   158 		<input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
   172 		<input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
   159 		<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
   173 		<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
   160 		<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
   174 		<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
   161 		<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
   175 		<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
   162 		</p>
   176 		</p>
       
   177 		<p>
       
   178 		<label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
       
   179 		<input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
       
   180 		</p>
   163 <?php
   181 <?php
   164 	}
   182 	}
   165 }
   183 }
   166 
   184 
   167 /**
   185 /**
   169  *
   187  *
   170  * @since 2.8.0
   188  * @since 2.8.0
   171  */
   189  */
   172 class WP_Widget_Search extends WP_Widget {
   190 class WP_Widget_Search extends WP_Widget {
   173 
   191 
   174 	function WP_Widget_Search() {
   192 	function __construct() {
   175 		$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
   193 		$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
   176 		$this->WP_Widget('search', __('Search'), $widget_ops);
   194 		parent::__construct('search', __('Search'), $widget_ops);
   177 	}
   195 	}
   178 
   196 
   179 	function widget( $args, $instance ) {
   197 	function widget( $args, $instance ) {
   180 		extract($args);
   198 		extract($args);
   181 		$title = apply_filters('widget_title', $instance['title']);
   199 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   182 
   200 
   183 		echo $before_widget;
   201 		echo $before_widget;
   184 		if ( $title )
   202 		if ( $title )
   185 			echo $before_title . $title . $after_title;
   203 			echo $before_title . $title . $after_title;
   186 
   204 
   212  *
   230  *
   213  * @since 2.8.0
   231  * @since 2.8.0
   214  */
   232  */
   215 class WP_Widget_Archives extends WP_Widget {
   233 class WP_Widget_Archives extends WP_Widget {
   216 
   234 
   217 	function WP_Widget_Archives() {
   235 	function __construct() {
   218 		$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your blog&#8217;s posts') );
   236 		$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s posts') );
   219 		$this->WP_Widget('archives', __('Archives'), $widget_ops);
   237 		parent::__construct('archives', __('Archives'), $widget_ops);
   220 	}
   238 	}
   221 
   239 
   222 	function widget( $args, $instance ) {
   240 	function widget( $args, $instance ) {
   223 		extract($args);
   241 		extract($args);
   224 		$c = $instance['count'] ? '1' : '0';
   242 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   225 		$d = $instance['dropdown'] ? '1' : '0';
   243 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   226 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title']);
   244 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
   227 
   245 
   228 		echo $before_widget;
   246 		echo $before_widget;
   229 		if ( $title )
   247 		if ( $title )
   230 			echo $before_title . $title . $after_title;
   248 			echo $before_title . $title . $after_title;
   231 
   249 
   260 		$count = $instance['count'] ? 'checked="checked"' : '';
   278 		$count = $instance['count'] ? 'checked="checked"' : '';
   261 		$dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
   279 		$dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
   262 ?>
   280 ?>
   263 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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 esc_attr($title); ?>" /></p>
   281 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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 esc_attr($title); ?>" /></p>
   264 		<p>
   282 		<p>
       
   283 			<input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
       
   284 			<br/>
   265 			<input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
   285 			<input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
   266 			<br />
       
   267 			<input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as a drop down'); ?></label>
       
   268 		</p>
   286 		</p>
   269 <?php
   287 <?php
   270 	}
   288 	}
   271 }
   289 }
   272 
   290 
   277  *
   295  *
   278  * @since 2.8.0
   296  * @since 2.8.0
   279  */
   297  */
   280 class WP_Widget_Meta extends WP_Widget {
   298 class WP_Widget_Meta extends WP_Widget {
   281 
   299 
   282 	function WP_Widget_Meta() {
   300 	function __construct() {
   283 		$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
   301 		$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
   284 		$this->WP_Widget('meta', __('Meta'), $widget_ops);
   302 		parent::__construct('meta', __('Meta'), $widget_ops);
   285 	}
   303 	}
   286 
   304 
   287 	function widget( $args, $instance ) {
   305 	function widget( $args, $instance ) {
   288 		extract($args);
   306 		extract($args);
   289 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title']);
   307 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
   290 
   308 
   291 		echo $before_widget;
   309 		echo $before_widget;
   292 		if ( $title )
   310 		if ( $title )
   293 			echo $before_title . $title . $after_title;
   311 			echo $before_title . $title . $after_title;
   294 ?>
   312 ?>
   295 			<ul>
   313 			<ul>
   296 			<?php wp_register(); ?>
   314 			<?php wp_register(); ?>
   297 			<li><?php wp_loginout(); ?></li>
   315 			<li><?php wp_loginout(); ?></li>
   298 			<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   316 			<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   299 			<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   317 			<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   300 			<li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
   318 			<li><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>"><?php
       
   319 			/* translators: meta widget link text */
       
   320 			_e( 'WordPress.org' );
       
   321 			?></a></li>
   301 			<?php wp_meta(); ?>
   322 			<?php wp_meta(); ?>
   302 			</ul>
   323 			</ul>
   303 <?php
   324 <?php
   304 		echo $after_widget;
   325 		echo $after_widget;
   305 	}
   326 	}
   325  *
   346  *
   326  * @since 2.8.0
   347  * @since 2.8.0
   327  */
   348  */
   328 class WP_Widget_Calendar extends WP_Widget {
   349 class WP_Widget_Calendar extends WP_Widget {
   329 
   350 
   330 	function WP_Widget_Calendar() {
   351 	function __construct() {
   331 		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your blog&#8217;s posts') );
   352 		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s posts') );
   332 		$this->WP_Widget('calendar', __('Calendar'), $widget_ops);
   353 		parent::__construct('calendar', __('Calendar'), $widget_ops);
   333 	}
   354 	}
   334 
   355 
   335 	function widget( $args, $instance ) {
   356 	function widget( $args, $instance ) {
   336 		extract($args);
   357 		extract($args);
   337 		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
   358 		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
   338 		echo $before_widget;
   359 		echo $before_widget;
   339 		if ( $title )
   360 		if ( $title )
   340 			echo $before_title . $title . $after_title;
   361 			echo $before_title . $title . $after_title;
   341 		echo '<div id="calendar_wrap">';
   362 		echo '<div id="calendar_wrap">';
   342 		get_calendar();
   363 		get_calendar();
   366  *
   387  *
   367  * @since 2.8.0
   388  * @since 2.8.0
   368  */
   389  */
   369 class WP_Widget_Text extends WP_Widget {
   390 class WP_Widget_Text extends WP_Widget {
   370 
   391 
   371 	function WP_Widget_Text() {
   392 	function __construct() {
   372 		$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
   393 		$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
   373 		$control_ops = array('width' => 400, 'height' => 350);
   394 		$control_ops = array('width' => 400, 'height' => 350);
   374 		$this->WP_Widget('text', __('Text'), $widget_ops, $control_ops);
   395 		parent::__construct('text', __('Text'), $widget_ops, $control_ops);
   375 	}
   396 	}
   376 
   397 
   377 	function widget( $args, $instance ) {
   398 	function widget( $args, $instance ) {
   378 		extract($args);
   399 		extract($args);
   379 		$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
   400 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   380 		$text = apply_filters( 'widget_text', $instance['text'] );
   401 		$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
   381 		echo $before_widget;
   402 		echo $before_widget;
   382 		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
   403 		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
   383 			<div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
   404 			<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
   384 		<?php
   405 		<?php
   385 		echo $after_widget;
   406 		echo $after_widget;
   386 	}
   407 	}
   387 
   408 
   388 	function update( $new_instance, $old_instance ) {
   409 	function update( $new_instance, $old_instance ) {
   389 		$instance = $old_instance;
   410 		$instance = $old_instance;
   390 		$instance['title'] = strip_tags($new_instance['title']);
   411 		$instance['title'] = strip_tags($new_instance['title']);
   391 		if ( current_user_can('unfiltered_html') )
   412 		if ( current_user_can('unfiltered_html') )
   392 			$instance['text'] =  $new_instance['text'];
   413 			$instance['text'] =  $new_instance['text'];
   393 		else
   414 		else
   394 			$instance['text'] = wp_filter_post_kses( $new_instance['text'] );
   415 			$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
   395 		$instance['filter'] = isset($new_instance['filter']);
   416 		$instance['filter'] = isset($new_instance['filter']);
   396 		return $instance;
   417 		return $instance;
   397 	}
   418 	}
   398 
   419 
   399 	function form( $instance ) {
   420 	function form( $instance ) {
   400 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
   421 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
   401 		$title = strip_tags($instance['title']);
   422 		$title = strip_tags($instance['title']);
   402 		$text = format_to_edit($instance['text']);
   423 		$text = esc_textarea($instance['text']);
   403 ?>
   424 ?>
   404 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   425 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   405 		<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); ?>" /></p>
   426 		<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); ?>" /></p>
   406 
   427 
   407 		<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
   428 		<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
   408 
   429 
   409 		<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked($instance['filter']); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs.'); ?></label></p>
   430 		<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
   410 <?php
   431 <?php
   411 	}
   432 	}
   412 }
   433 }
   413 
   434 
   414 /**
   435 /**
   416  *
   437  *
   417  * @since 2.8.0
   438  * @since 2.8.0
   418  */
   439  */
   419 class WP_Widget_Categories extends WP_Widget {
   440 class WP_Widget_Categories extends WP_Widget {
   420 
   441 
   421 	function WP_Widget_Categories() {
   442 	function __construct() {
   422 		$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
   443 		$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
   423 		$this->WP_Widget('categories', __('Categories'), $widget_ops);
   444 		parent::__construct('categories', __('Categories'), $widget_ops);
   424 	}
   445 	}
   425 
   446 
   426 	function widget( $args, $instance ) {
   447 	function widget( $args, $instance ) {
   427 		extract( $args );
   448 		extract( $args );
   428 
   449 
   429 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title']);
   450 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
   430 		$c = $instance['count'] ? '1' : '0';
   451 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   431 		$h = $instance['hierarchical'] ? '1' : '0';
   452 		$h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
   432 		$d = $instance['dropdown'] ? '1' : '0';
   453 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   433 
   454 
   434 		echo $before_widget;
   455 		echo $before_widget;
   435 		if ( $title )
   456 		if ( $title )
   436 			echo $before_title . $title . $after_title;
   457 			echo $before_title . $title . $after_title;
   437 
   458 
   445 <script type='text/javascript'>
   466 <script type='text/javascript'>
   446 /* <![CDATA[ */
   467 /* <![CDATA[ */
   447 	var dropdown = document.getElementById("cat");
   468 	var dropdown = document.getElementById("cat");
   448 	function onCatChange() {
   469 	function onCatChange() {
   449 		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
   470 		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
   450 			location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
   471 			location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
   451 		}
   472 		}
   452 	}
   473 	}
   453 	dropdown.onchange = onCatChange;
   474 	dropdown.onchange = onCatChange;
   454 /* ]]> */
   475 /* ]]> */
   455 </script>
   476 </script>
   470 	}
   491 	}
   471 
   492 
   472 	function update( $new_instance, $old_instance ) {
   493 	function update( $new_instance, $old_instance ) {
   473 		$instance = $old_instance;
   494 		$instance = $old_instance;
   474 		$instance['title'] = strip_tags($new_instance['title']);
   495 		$instance['title'] = strip_tags($new_instance['title']);
   475 		$instance['count'] = $new_instance['count'] ? 1 : 0;
   496 		$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
   476 		$instance['hierarchical'] = $new_instance['hierarchical'] ? 1 : 0;
   497 		$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
   477 		$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
   498 		$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
   478 
   499 
   479 		return $instance;
   500 		return $instance;
   480 	}
   501 	}
   481 
   502 
   482 	function form( $instance ) {
   503 	function form( $instance ) {
   483 		//Defaults
   504 		//Defaults
   484 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   505 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   485 		$title = esc_attr( $instance['title'] );
   506 		$title = esc_attr( $instance['title'] );
   486 		$count = (bool) $instance['count'];
   507 		$count = isset($instance['count']) ? (bool) $instance['count'] :false;
   487 		$hierarchical = (bool) $instance['hierarchical'];
   508 		$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
   488 		$dropdown = (bool) $instance['dropdown'];
   509 		$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
   489 ?>
   510 ?>
   490 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
   511 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
   491 		<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>
   512 		<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>
   492 
   513 
   493 		<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
   514 		<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
   494 		<label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Show as dropdown' ); ?></label><br />
   515 		<label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
   495 
   516 
   496 		<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
   517 		<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
   497 		<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
   518 		<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
   498 
   519 
   499 		<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
   520 		<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
   508  *
   529  *
   509  * @since 2.8.0
   530  * @since 2.8.0
   510  */
   531  */
   511 class WP_Widget_Recent_Posts extends WP_Widget {
   532 class WP_Widget_Recent_Posts extends WP_Widget {
   512 
   533 
   513 	function WP_Widget_Recent_Posts() {
   534 	function __construct() {
   514 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") );
   535 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
   515 		$this->WP_Widget('recent-posts', __('Recent Posts'), $widget_ops);
   536 		parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
   516 		$this->alt_option_name = 'widget_recent_entries';
   537 		$this->alt_option_name = 'widget_recent_entries';
   517 
   538 
   518 		add_action( 'save_post', array(&$this, 'flush_widget_cache') );
   539 		add_action( 'save_post', array(&$this, 'flush_widget_cache') );
   519 		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
   540 		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
   520 		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
   541 		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
   524 		$cache = wp_cache_get('widget_recent_posts', 'widget');
   545 		$cache = wp_cache_get('widget_recent_posts', 'widget');
   525 
   546 
   526 		if ( !is_array($cache) )
   547 		if ( !is_array($cache) )
   527 			$cache = array();
   548 			$cache = array();
   528 
   549 
   529 		if ( isset($cache[$args['widget_id']]) ) {
   550 		if ( ! isset( $args['widget_id'] ) )
   530 			echo $cache[$args['widget_id']];
   551 			$args['widget_id'] = $this->id;
       
   552 
       
   553 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
       
   554 			echo $cache[ $args['widget_id'] ];
   531 			return;
   555 			return;
   532 		}
   556 		}
   533 
   557 
   534 		ob_start();
   558 		ob_start();
   535 		extract($args);
   559 		extract($args);
   536 
   560 
   537 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title']);
   561 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
   538 		if ( !$number = (int) $instance['number'] )
   562 		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
   539 			$number = 10;
   563  			$number = 10;
   540 		else if ( $number < 1 )
   564 
   541 			$number = 1;
   565 		$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
   542 		else if ( $number > 15 )
       
   543 			$number = 15;
       
   544 
       
   545 		$r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
       
   546 		if ($r->have_posts()) :
   566 		if ($r->have_posts()) :
   547 ?>
   567 ?>
   548 		<?php echo $before_widget; ?>
   568 		<?php echo $before_widget; ?>
   549 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   569 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   550 		<ul>
   570 		<ul>
   551 		<?php  while ($r->have_posts()) : $r->the_post(); ?>
   571 		<?php  while ($r->have_posts()) : $r->the_post(); ?>
   552 		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
   572 		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
   553 		<?php endwhile; ?>
   573 		<?php endwhile; ?>
   554 		</ul>
   574 		</ul>
   555 		<?php echo $after_widget; ?>
   575 		<?php echo $after_widget; ?>
   556 <?php
   576 <?php
   557 			wp_reset_query();  // Restore global post data stomped by the_post().
   577 		// Reset the global $the_post as this query will have stomped on it
       
   578 		wp_reset_postdata();
       
   579 
   558 		endif;
   580 		endif;
   559 
   581 
   560 		$cache[$args['widget_id']] = ob_get_flush();
   582 		$cache[$args['widget_id']] = ob_get_flush();
   561 		wp_cache_add('widget_recent_posts', $cache, 'widget');
   583 		wp_cache_set('widget_recent_posts', $cache, 'widget');
   562 	}
   584 	}
   563 
   585 
   564 	function update( $new_instance, $old_instance ) {
   586 	function update( $new_instance, $old_instance ) {
   565 		$instance = $old_instance;
   587 		$instance = $old_instance;
   566 		$instance['title'] = strip_tags($new_instance['title']);
   588 		$instance['title'] = strip_tags($new_instance['title']);
   577 	function flush_widget_cache() {
   599 	function flush_widget_cache() {
   578 		wp_cache_delete('widget_recent_posts', 'widget');
   600 		wp_cache_delete('widget_recent_posts', 'widget');
   579 	}
   601 	}
   580 
   602 
   581 	function form( $instance ) {
   603 	function form( $instance ) {
   582 		$title = esc_attr($instance['title']);
   604 		$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
   583 		if ( !$number = (int) $instance['number'] )
   605 		$number = isset($instance['number']) ? absint($instance['number']) : 5;
   584 			$number = 5;
       
   585 ?>
   606 ?>
   586 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   607 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   587 		<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>
   608 		<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>
   588 
   609 
   589 		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
   610 		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
   590 		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /><br />
   611 		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
   591 		<small><?php _e('(at most 15)'); ?></small></p>
       
   592 <?php
   612 <?php
   593 	}
   613 	}
   594 }
   614 }
   595 
   615 
   596 /**
   616 /**
   598  *
   618  *
   599  * @since 2.8.0
   619  * @since 2.8.0
   600  */
   620  */
   601 class WP_Widget_Recent_Comments extends WP_Widget {
   621 class WP_Widget_Recent_Comments extends WP_Widget {
   602 
   622 
   603 	function WP_Widget_Recent_Comments() {
   623 	function __construct() {
   604 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
   624 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
   605 		$this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops);
   625 		parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
   606 		$this->alt_option_name = 'widget_recent_comments';
   626 		$this->alt_option_name = 'widget_recent_comments';
   607 
   627 
   608 		if ( is_active_widget(false, false, $this->id_base) )
   628 		if ( is_active_widget(false, false, $this->id_base) )
   609 			add_action( 'wp_head', array(&$this, 'recent_comments_style') );
   629 			add_action( 'wp_head', array(&$this, 'recent_comments_style') );
   610 
   630 
   611 		add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
   631 		add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
   612 		add_action( 'wp_set_comment_status', array(&$this, 'flush_widget_cache') );
   632 		add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
   613 	}
   633 	}
   614 
   634 
   615 	function recent_comments_style() { ?>
   635 	function recent_comments_style() {
       
   636 		if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
       
   637 			|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
       
   638 			return;
       
   639 		?>
   616 	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
   640 	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
   617 <?php
   641 <?php
   618 	}
   642 	}
   619 
   643 
   620 	function flush_widget_cache() {
   644 	function flush_widget_cache() {
   621 		wp_cache_delete('recent_comments', 'widget');
   645 		wp_cache_delete('widget_recent_comments', 'widget');
   622 	}
   646 	}
   623 
   647 
   624 	function widget( $args, $instance ) {
   648 	function widget( $args, $instance ) {
   625 		global $wpdb, $comments, $comment;
   649 		global $comments, $comment;
   626 
   650 
   627 		extract($args, EXTR_SKIP);
   651 		$cache = wp_cache_get('widget_recent_comments', 'widget');
   628 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
   652 
   629 		if ( !$number = (int) $instance['number'] )
   653 		if ( ! is_array( $cache ) )
   630 			$number = 5;
   654 			$cache = array();
   631 		else if ( $number < 1 )
   655 
   632 			$number = 1;
   656 		if ( ! isset( $args['widget_id'] ) )
   633 		else if ( $number > 15 )
   657 			$args['widget_id'] = $this->id;
   634 			$number = 15;
   658 
   635 
   659 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
   636 		if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
   660 			echo $cache[ $args['widget_id'] ];
   637 			$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15");
   661 			return;
   638 			wp_cache_add( 'recent_comments', $comments, 'widget' );
   662 		}
   639 		}
   663 
   640 
   664  		extract($args, EXTR_SKIP);
   641 		$comments = array_slice( (array) $comments, 0, $number );
   665  		$output = '';
   642 ?>
   666 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Recent Comments' ) : $instance['title'], $instance, $this->id_base );
   643 		<?php echo $before_widget; ?>
   667 
   644 			<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   668 		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
   645 			<ul id="recentcomments"><?php
   669  			$number = 5;
   646 			if ( $comments ) : foreach ( (array) $comments as $comment) :
   670 
   647 			echo  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
   671 		$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
   648 			endforeach; endif;?></ul>
   672 		$output .= $before_widget;
   649 		<?php echo $after_widget; ?>
   673 		if ( $title )
   650 <?php
   674 			$output .= $before_title . $title . $after_title;
       
   675 
       
   676 		$output .= '<ul id="recentcomments">';
       
   677 		if ( $comments ) {
       
   678 			foreach ( (array) $comments as $comment) {
       
   679 				$output .=  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
       
   680 			}
       
   681  		}
       
   682 		$output .= '</ul>';
       
   683 		$output .= $after_widget;
       
   684 
       
   685 		echo $output;
       
   686 		$cache[$args['widget_id']] = $output;
       
   687 		wp_cache_set('widget_recent_comments', $cache, 'widget');
   651 	}
   688 	}
   652 
   689 
   653 	function update( $new_instance, $old_instance ) {
   690 	function update( $new_instance, $old_instance ) {
   654 		$instance = $old_instance;
   691 		$instance = $old_instance;
   655 		$instance['title'] = strip_tags($new_instance['title']);
   692 		$instance['title'] = strip_tags($new_instance['title']);
   656 		$instance['number'] = (int) $new_instance['number'];
   693 		$instance['number'] = absint( $new_instance['number'] );
   657 		$this->flush_widget_cache();
   694 		$this->flush_widget_cache();
   658 
   695 
   659 		$alloptions = wp_cache_get( 'alloptions', 'options' );
   696 		$alloptions = wp_cache_get( 'alloptions', 'options' );
   660 		if ( isset($alloptions['widget_recent_comments']) )
   697 		if ( isset($alloptions['widget_recent_comments']) )
   661 			delete_option('widget_recent_comments');
   698 			delete_option('widget_recent_comments');
   669 ?>
   706 ?>
   670 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   707 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   671 		<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>
   708 		<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>
   672 
   709 
   673 		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
   710 		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
   674 		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /><br />
   711 		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
   675 		<small><?php _e('(at most 15)'); ?></small></p>
       
   676 <?php
   712 <?php
   677 	}
   713 	}
   678 }
   714 }
   679 
   715 
   680 /**
   716 /**
   681  * RSS widget class
   717  * RSS widget class
   682  *
   718  *
   683  * @since 2.8.0
   719  * @since 2.8.0
   684  */
   720  */
   685 class WP_Widget_RSS_Sam extends WP_Widget {
   721 class WP_Widget_RSS extends WP_Widget {
   686 
   722 
   687 	function WP_Widget_RSS_Sam() {
   723 	function __construct() {
   688 		$widget_ops = array( 'description' => __('Entries from any RSS Custom / SAM') );
   724 		$widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
   689 		$control_ops = array( 'width' => 400, 'height' => 200 );
   725 		$control_ops = array( 'width' => 400, 'height' => 200 );
   690 		$this->WP_Widget( 'rss', __('RSS'), $widget_ops, $control_ops );
   726 		parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
   691 	}
   727 	}
   692 
   728 
   693 	function widget($args, $instance) {
   729 	function widget($args, $instance) {
   694 
   730 
   695 		if ( isset($instance['error']) && $instance['error'] )
   731 		if ( isset($instance['error']) && $instance['error'] )
   696 			return;
   732 			return;
   697 
   733 
   698 		extract($args, EXTR_SKIP);
   734 		extract($args, EXTR_SKIP);
   699 
   735 
   700 		$url = $instance['url'];
   736 		$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
   701 		while ( stristr($url, 'http') != $url )
   737 		while ( stristr($url, 'http') != $url )
   702 			$url = substr($url, 1);
   738 			$url = substr($url, 1);
   703 
   739 
   704 		if ( empty($url) )
   740 		if ( empty($url) )
       
   741 			return;
       
   742 
       
   743 		// self-url destruction sequence
       
   744 		if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
   705 			return;
   745 			return;
   706 
   746 
   707 		$rss = fetch_feed($url);
   747 		$rss = fetch_feed($url);
   708 		$title = $instance['title'];
   748 		$title = $instance['title'];
   709 		$desc = '';
   749 		$desc = '';
   719 		}
   759 		}
   720 
   760 
   721 		if ( empty($title) )
   761 		if ( empty($title) )
   722 			$title = empty($desc) ? __('Unknown Feed') : $desc;
   762 			$title = empty($desc) ? __('Unknown Feed') : $desc;
   723 
   763 
   724 		$title = apply_filters('widget_title', $title );
   764 		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
   725 		$url = esc_url(strip_tags($url));
   765 		$url = esc_url(strip_tags($url));
   726 		$icon = includes_url('images/rss.png');
   766 		$icon = includes_url('images/rss.png');
   727 		if ( $title )
   767 		if ( $title )
   728 			$title = "$title";
   768 			$title = "<a class='rsswidget' href='$url' title='" . esc_attr__( 'Syndicate this content' ) ."'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
   729 
   769 
   730 		echo $before_widget;
   770 		echo $before_widget;
   731 		if ( $title )
   771 		if ( $title )
   732 			echo $before_title . $title . $after_title;
   772 			echo $before_title . $title . $after_title;
   733 		wp_widget_rss_output( $rss, $instance );
   773 		wp_widget_rss_output( $rss, $instance );
   734 		echo $after_widget;
   774 		echo $after_widget;
       
   775 
       
   776 		if ( ! is_wp_error($rss) )
       
   777 			$rss->__destruct();
       
   778 		unset($rss);
   735 	}
   779 	}
   736 
   780 
   737 	function update($new_instance, $old_instance) {
   781 	function update($new_instance, $old_instance) {
   738 		$testurl = $new_instance['url'] != $old_instance['url'];
   782 		$testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
   739 		return wp_widget_rss_process( $new_instance, $testurl );
       
   740 	}
       
   741 
       
   742 	function form($instance) {
       
   743 
       
   744 		if ( empty($instance) )
       
   745 			$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
       
   746 		$instance['number'] = $this->number;
       
   747 
       
   748 		wp_widget_rss_form( $instance );
       
   749 	}
       
   750 }
       
   751 
       
   752 
       
   753 /**
       
   754  * RSS widget class
       
   755  *
       
   756  * @since 2.8.0
       
   757  */
       
   758 class WP_Widget_RSS extends WP_Widget {
       
   759 
       
   760 	function WP_Widget_RSS() {
       
   761 		$widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
       
   762 		$control_ops = array( 'width' => 400, 'height' => 200 );
       
   763 		$this->WP_Widget( 'rss', __('RSS'), $widget_ops, $control_ops );
       
   764 	}
       
   765 
       
   766 	function widget($args, $instance) {
       
   767 
       
   768 		if ( isset($instance['error']) && $instance['error'] )
       
   769 			return;
       
   770 
       
   771 		extract($args, EXTR_SKIP);
       
   772 
       
   773 		$url = $instance['url'];
       
   774 		while ( stristr($url, 'http') != $url )
       
   775 			$url = substr($url, 1);
       
   776 
       
   777 		if ( empty($url) )
       
   778 			return;
       
   779 
       
   780 		$rss = fetch_feed($url);
       
   781 		$title = $instance['title'];
       
   782 		$desc = '';
       
   783 		$link = '';
       
   784 
       
   785 		if ( ! is_wp_error($rss) ) {
       
   786 			$desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
       
   787 			if ( empty($title) )
       
   788 				$title = esc_html(strip_tags($rss->get_title()));
       
   789 			$link = esc_url(strip_tags($rss->get_permalink()));
       
   790 			while ( stristr($link, 'http') != $link )
       
   791 				$link = substr($link, 1);
       
   792 		}
       
   793 
       
   794 		if ( empty($title) )
       
   795 			$title = empty($desc) ? __('Unknown Feed') : $desc;
       
   796 
       
   797 		$title = apply_filters('widget_title', $title );
       
   798 		$url = esc_url(strip_tags($url));
       
   799 		$icon = includes_url('images/rss.png');
       
   800 		if ( $title )
       
   801 			$title = "<a class='rsswidget' target='_blank' href='$url' title='" . esc_attr(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
       
   802 
       
   803 		echo $before_widget;
       
   804 		if ( $title )
       
   805 			echo $before_title . $title . $after_title;
       
   806 		wp_widget_rss_output( $rss, $instance );
       
   807 		echo $after_widget;
       
   808 	}
       
   809 
       
   810 	function update($new_instance, $old_instance) {
       
   811 		$testurl = $new_instance['url'] != $old_instance['url'];
       
   812 		return wp_widget_rss_process( $new_instance, $testurl );
   783 		return wp_widget_rss_process( $new_instance, $testurl );
   813 	}
   784 	}
   814 
   785 
   815 	function form($instance) {
   786 	function form($instance) {
   816 
   787 
   841 	}
   812 	}
   842 
   813 
   843 	if ( is_wp_error($rss) ) {
   814 	if ( is_wp_error($rss) ) {
   844 		if ( is_admin() || current_user_can('manage_options') )
   815 		if ( is_admin() || current_user_can('manage_options') )
   845 			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
   816 			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
   846 
       
   847 		return;
   817 		return;
   848 	}
   818 	}
   849 
   819 
   850 	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
   820 	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
   851 	$args = wp_parse_args( $args, $default_args );
   821 	$args = wp_parse_args( $args, $default_args );
   858 	$show_author   = (int) $show_author;
   828 	$show_author   = (int) $show_author;
   859 	$show_date     = (int) $show_date;
   829 	$show_date     = (int) $show_date;
   860 
   830 
   861 	if ( !$rss->get_item_quantity() ) {
   831 	if ( !$rss->get_item_quantity() ) {
   862 		echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
   832 		echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
       
   833 		$rss->__destruct();
       
   834 		unset($rss);
   863 		return;
   835 		return;
   864 	}
   836 	}
   865 
   837 
   866 	echo '<ul>';
   838 	echo '<ul>';
   867 	foreach ( $rss->get_items(0, $items) as $item ) {
   839 	foreach ( $rss->get_items(0, $items) as $item ) {
   871 		$link = esc_url(strip_tags($link));
   843 		$link = esc_url(strip_tags($link));
   872 		$title = esc_attr(strip_tags($item->get_title()));
   844 		$title = esc_attr(strip_tags($item->get_title()));
   873 		if ( empty($title) )
   845 		if ( empty($title) )
   874 			$title = __('Untitled');
   846 			$title = __('Untitled');
   875 
   847 
   876 		$desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset')))));
   848 		$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
   877 		$desc = wp_html_excerpt( $desc, 360 ) . ' [&hellip;]';
   849 		$desc = wp_html_excerpt( $desc, 360 );
       
   850 
       
   851 		// Append ellipsis. Change existing [...] to [&hellip;].
       
   852 		if ( '[...]' == substr( $desc, -5 ) )
       
   853 			$desc = substr( $desc, 0, -5 ) . '[&hellip;]';
       
   854 		elseif ( '[&hellip;]' != substr( $desc, -10 ) )
       
   855 			$desc .= ' [&hellip;]';
       
   856 
   878 		$desc = esc_html( $desc );
   857 		$desc = esc_html( $desc );
   879 
   858 
   880 		if ( $show_summary ) {
   859 		if ( $show_summary ) {
   881 			$summary = "<div class='rssSummary'>$desc</div>";
   860 			$summary = "<div class='rssSummary'>$desc</div>";
   882 		} else {
   861 		} else {
   883 			$summary = '';
   862 			$summary = '';
   884 		}
   863 		}
   885 
   864 
   886 		$date = '';
   865 		$date = '';
   887 		if ( $show_date ) {
   866 		if ( $show_date ) {
   888 			$date = $item->get_date();
   867 			$date = $item->get_date( 'U' );
   889 
   868 
   890 			if ( $date ) {
   869 			if ( $date ) {
   891 				if ( $date_stamp = strtotime( $date ) )
   870 				$date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
   892 					$date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
       
   893 				else
       
   894 					$date = '';
       
   895 			}
   871 			}
   896 		}
   872 		}
   897 
   873 
   898 		$author = '';
   874 		$author = '';
   899 		if ( $show_author ) {
   875 		if ( $show_author ) {
   905 		}
   881 		}
   906 
   882 
   907 		if ( $link == '' ) {
   883 		if ( $link == '' ) {
   908 			echo "<li>$title{$date}{$summary}{$author}</li>";
   884 			echo "<li>$title{$date}{$summary}{$author}</li>";
   909 		} else {
   885 		} else {
   910 			echo "<li><a class='rsswidget' href='$link' title='$desc' target='_blank'>$title</a>{$date}{$summary}{$author}</li>";
   886 			echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
   911 		}
   887 		}
   912 	}
   888 	}
   913 	echo '</ul>';
   889 	echo '</ul>';
   914 }
   890 	$rss->__destruct();
   915 
   891 	unset($rss);
   916 
   892 }
   917 
   893 
   918 /**
   894 /**
   919  * Display RSS widget options form.
   895  * Display RSS widget options form.
   920  *
   896  *
   921  * The options for what fields are displayed for the RSS form are all booleans
   897  * The options for what fields are displayed for the RSS form are all booleans
  1003 	$items = (int) $widget_rss['items'];
   979 	$items = (int) $widget_rss['items'];
  1004 	if ( $items < 1 || 20 < $items )
   980 	if ( $items < 1 || 20 < $items )
  1005 		$items = 10;
   981 		$items = 10;
  1006 	$url           = esc_url_raw(strip_tags( $widget_rss['url'] ));
   982 	$url           = esc_url_raw(strip_tags( $widget_rss['url'] ));
  1007 	$title         = trim(strip_tags( $widget_rss['title'] ));
   983 	$title         = trim(strip_tags( $widget_rss['title'] ));
  1008 	$show_summary  = (int) $widget_rss['show_summary'];
   984 	$show_summary  = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
  1009 	$show_author   = (int) $widget_rss['show_author'];
   985 	$show_author   = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
  1010 	$show_date     = (int) $widget_rss['show_date'];
   986 	$show_date     = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;
  1011 
   987 
  1012 	if ( $check_feed ) {
   988 	if ( $check_feed ) {
  1013 		$rss = fetch_feed($url);
   989 		$rss = fetch_feed($url);
  1014 		$error = false;
   990 		$error = false;
  1015 		$link = '';
   991 		$link = '';
  1017 			$error = $rss->get_error_message();
   993 			$error = $rss->get_error_message();
  1018 		} else {
   994 		} else {
  1019 			$link = esc_url(strip_tags($rss->get_permalink()));
   995 			$link = esc_url(strip_tags($rss->get_permalink()));
  1020 			while ( stristr($link, 'http') != $link )
   996 			while ( stristr($link, 'http') != $link )
  1021 				$link = substr($link, 1);
   997 				$link = substr($link, 1);
       
   998 
       
   999 			$rss->__destruct();
       
  1000 			unset($rss);
  1022 		}
  1001 		}
  1023 	}
  1002 	}
  1024 
  1003 
  1025 	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
  1004 	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
  1026 }
  1005 }
  1030  *
  1009  *
  1031  * @since 2.8.0
  1010  * @since 2.8.0
  1032  */
  1011  */
  1033 class WP_Widget_Tag_Cloud extends WP_Widget {
  1012 class WP_Widget_Tag_Cloud extends WP_Widget {
  1034 
  1013 
  1035 	function WP_Widget_Tag_Cloud() {
  1014 	function __construct() {
  1036 		$widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
  1015 		$widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
  1037 		$this->WP_Widget('tag_cloud', __('Tag Cloud'), $widget_ops);
  1016 		parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  1038 	}
  1017 	}
  1039 
  1018 
  1040 	function widget( $args, $instance ) {
  1019 	function widget( $args, $instance ) {
  1041 		extract($args);
  1020 		extract($args);
  1042 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Tags') : $instance['title']);
  1021 		$current_taxonomy = $this->_get_current_taxonomy($instance);
       
  1022 		if ( !empty($instance['title']) ) {
       
  1023 			$title = $instance['title'];
       
  1024 		} else {
       
  1025 			if ( 'post_tag' == $current_taxonomy ) {
       
  1026 				$title = __('Tags');
       
  1027 			} else {
       
  1028 				$tax = get_taxonomy($current_taxonomy);
       
  1029 				$title = $tax->labels->name;
       
  1030 			}
       
  1031 		}
       
  1032 		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
  1043 
  1033 
  1044 		echo $before_widget;
  1034 		echo $before_widget;
  1045 		if ( $title )
  1035 		if ( $title )
  1046 			echo $before_title . $title . $after_title;
  1036 			echo $before_title . $title . $after_title;
  1047 		echo '<div>';
  1037 		echo '<div class="tagcloud">';
  1048 		wp_tag_cloud(apply_filters('widget_tag_cloud_args', array()));
  1038 		wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
  1049 		echo "</div>\n";
  1039 		echo "</div>\n";
  1050 		echo $after_widget;
  1040 		echo $after_widget;
  1051 	}
  1041 	}
  1052 
  1042 
  1053 	function update( $new_instance, $old_instance ) {
  1043 	function update( $new_instance, $old_instance ) {
  1054 		$instance['title'] = strip_tags(stripslashes($new_instance['title']));
  1044 		$instance['title'] = strip_tags(stripslashes($new_instance['title']));
       
  1045 		$instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  1055 		return $instance;
  1046 		return $instance;
  1056 	}
  1047 	}
  1057 
  1048 
  1058 	function form( $instance ) {
  1049 	function form( $instance ) {
       
  1050 		$current_taxonomy = $this->_get_current_taxonomy($instance);
  1059 ?>
  1051 ?>
  1060 	<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1052 	<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1061 	<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
  1053 	<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
  1062 <?php
  1054 	<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
       
  1055 	<select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
       
  1056 	<?php foreach ( get_taxonomies() as $taxonomy ) :
       
  1057 				$tax = get_taxonomy($taxonomy);
       
  1058 				if ( !$tax->show_tagcloud || empty($tax->labels->name) )
       
  1059 					continue;
       
  1060 	?>
       
  1061 		<option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
       
  1062 	<?php endforeach; ?>
       
  1063 	</select></p><?php
       
  1064 	}
       
  1065 
       
  1066 	function _get_current_taxonomy($instance) {
       
  1067 		if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
       
  1068 			return $instance['taxonomy'];
       
  1069 
       
  1070 		return 'post_tag';
       
  1071 	}
       
  1072 }
       
  1073 
       
  1074 /**
       
  1075  * Navigation Menu widget class
       
  1076  *
       
  1077  * @since 3.0.0
       
  1078  */
       
  1079  class WP_Nav_Menu_Widget extends WP_Widget {
       
  1080 
       
  1081 	function __construct() {
       
  1082 		$widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
       
  1083 		parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
       
  1084 	}
       
  1085 
       
  1086 	function widget($args, $instance) {
       
  1087 		// Get menu
       
  1088 		$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
       
  1089 
       
  1090 		if ( !$nav_menu )
       
  1091 			return;
       
  1092 
       
  1093 		$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
       
  1094 
       
  1095 		echo $args['before_widget'];
       
  1096 
       
  1097 		if ( !empty($instance['title']) )
       
  1098 			echo $args['before_title'] . $instance['title'] . $args['after_title'];
       
  1099 
       
  1100 		wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
       
  1101 
       
  1102 		echo $args['after_widget'];
       
  1103 	}
       
  1104 
       
  1105 	function update( $new_instance, $old_instance ) {
       
  1106 		$instance['title'] = strip_tags( stripslashes($new_instance['title']) );
       
  1107 		$instance['nav_menu'] = (int) $new_instance['nav_menu'];
       
  1108 		return $instance;
       
  1109 	}
       
  1110 
       
  1111 	function form( $instance ) {
       
  1112 		$title = isset( $instance['title'] ) ? $instance['title'] : '';
       
  1113 		$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
       
  1114 
       
  1115 		// Get menus
       
  1116 		$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
       
  1117 
       
  1118 		// If no menus exists, direct the user to go and create some.
       
  1119 		if ( !$menus ) {
       
  1120 			echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
       
  1121 			return;
       
  1122 		}
       
  1123 		?>
       
  1124 		<p>
       
  1125 			<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
       
  1126 			<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
       
  1127 		</p>
       
  1128 		<p>
       
  1129 			<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
       
  1130 			<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
       
  1131 		<?php
       
  1132 			foreach ( $menus as $menu ) {
       
  1133 				$selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
       
  1134 				echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
       
  1135 			}
       
  1136 		?>
       
  1137 			</select>
       
  1138 		</p>
       
  1139 		<?php
  1063 	}
  1140 	}
  1064 }
  1141 }
  1065 
  1142 
  1066 /**
  1143 /**
  1067  * Register all of the default WordPress widgets on startup.
  1144  * Register all of the default WordPress widgets on startup.
  1094 	register_widget('WP_Widget_Recent_Posts');
  1171 	register_widget('WP_Widget_Recent_Posts');
  1095 
  1172 
  1096 	register_widget('WP_Widget_Recent_Comments');
  1173 	register_widget('WP_Widget_Recent_Comments');
  1097 
  1174 
  1098 	register_widget('WP_Widget_RSS');
  1175 	register_widget('WP_Widget_RSS');
  1099 	
  1176 
  1100 	register_widget('WP_Widget_RSS_Sam');
       
  1101 	
       
  1102 	register_widget('WP_Widget_Tag_Cloud');
  1177 	register_widget('WP_Widget_Tag_Cloud');
  1103 
  1178 
       
  1179 	register_widget('WP_Nav_Menu_Widget');
       
  1180 
  1104 	do_action('widgets_init');
  1181 	do_action('widgets_init');
  1105 }
  1182 }
  1106 
  1183 
  1107 add_action('init', 'wp_widgets_init', 1);
  1184 add_action('init', 'wp_widgets_init', 1);