wp/wp-includes/default-widgets.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    11  *
    11  *
    12  * @since 2.8.0
    12  * @since 2.8.0
    13  */
    13  */
    14 class WP_Widget_Pages extends WP_Widget {
    14 class WP_Widget_Pages extends WP_Widget {
    15 
    15 
    16 	function __construct() {
    16 	public function __construct() {
    17 		$widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') );
    17 		$widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A list of your site’s Pages.') );
    18 		parent::__construct('pages', __('Pages'), $widget_ops);
    18 		parent::__construct('pages', __('Pages'), $widget_ops);
    19 	}
    19 	}
    20 
    20 
    21 	function widget( $args, $instance ) {
    21 	public function widget( $args, $instance ) {
    22 		extract( $args );
    22 
    23 
    23 		/**
    24 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
    24 		 * Filter the widget title.
       
    25 		 *
       
    26 		 * @since 2.6.0
       
    27 		 *
       
    28 		 * @param string $title    The widget title. Default 'Pages'.
       
    29 		 * @param array  $instance An array of the widget's settings.
       
    30 		 * @param mixed  $id_base  The widget ID.
       
    31 		 */
       
    32 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
       
    33 
    25 		$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    34 		$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    26 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    35 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    27 
    36 
    28 		if ( $sortby == 'menu_order' )
    37 		if ( $sortby == 'menu_order' )
    29 			$sortby = 'menu_order, post_title';
    38 			$sortby = 'menu_order, post_title';
    30 
    39 
    31 		$out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) );
    40 		/**
    32 
    41 		 * Filter the arguments for the Pages widget.
    33 		if ( !empty( $out ) ) {
    42 		 *
    34 			echo $before_widget;
    43 		 * @since 2.8.0
    35 			if ( $title)
    44 		 *
    36 				echo $before_title . $title . $after_title;
    45 		 * @see wp_list_pages()
       
    46 		 *
       
    47 		 * @param array $args An array of arguments to retrieve the pages list.
       
    48 		 */
       
    49 		$out = wp_list_pages( apply_filters( 'widget_pages_args', array(
       
    50 			'title_li'    => '',
       
    51 			'echo'        => 0,
       
    52 			'sort_column' => $sortby,
       
    53 			'exclude'     => $exclude
       
    54 		) ) );
       
    55 
       
    56 		if ( ! empty( $out ) ) {
       
    57 			echo $args['before_widget'];
       
    58 			if ( $title ) {
       
    59 				echo $args['before_title'] . $title . $args['after_title'];
       
    60 			}
    37 		?>
    61 		?>
    38 		<ul>
    62 		<ul>
    39 			<?php echo $out; ?>
    63 			<?php echo $out; ?>
    40 		</ul>
    64 		</ul>
    41 		<?php
    65 		<?php
    42 			echo $after_widget;
    66 			echo $args['after_widget'];
    43 		}
    67 		}
    44 	}
    68 	}
    45 
    69 
    46 	function update( $new_instance, $old_instance ) {
    70 	public function update( $new_instance, $old_instance ) {
    47 		$instance = $old_instance;
    71 		$instance = $old_instance;
    48 		$instance['title'] = strip_tags($new_instance['title']);
    72 		$instance['title'] = strip_tags($new_instance['title']);
    49 		if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
    73 		if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
    50 			$instance['sortby'] = $new_instance['sortby'];
    74 			$instance['sortby'] = $new_instance['sortby'];
    51 		} else {
    75 		} else {
    55 		$instance['exclude'] = strip_tags( $new_instance['exclude'] );
    79 		$instance['exclude'] = strip_tags( $new_instance['exclude'] );
    56 
    80 
    57 		return $instance;
    81 		return $instance;
    58 	}
    82 	}
    59 
    83 
    60 	function form( $instance ) {
    84 	public function form( $instance ) {
    61 		//Defaults
    85 		//Defaults
    62 		$instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
    86 		$instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
    63 		$title = esc_attr( $instance['title'] );
    87 		$title = esc_attr( $instance['title'] );
    64 		$exclude = esc_attr( $instance['exclude'] );
    88 		$exclude = esc_attr( $instance['exclude'] );
    65 	?>
    89 	?>
    87  *
   111  *
    88  * @since 2.8.0
   112  * @since 2.8.0
    89  */
   113  */
    90 class WP_Widget_Links extends WP_Widget {
   114 class WP_Widget_Links extends WP_Widget {
    91 
   115 
    92 	function __construct() {
   116 	public function __construct() {
    93 		$widget_ops = array('description' => __( "Your blogroll" ) );
   117 		$widget_ops = array('description' => __( "Your blogroll" ) );
    94 		parent::__construct('links', __('Links'), $widget_ops);
   118 		parent::__construct('links', __('Links'), $widget_ops);
    95 	}
   119 	}
    96 
   120 
    97 	function widget( $args, $instance ) {
   121 	public function widget( $args, $instance ) {
    98 		extract($args, EXTR_SKIP);
       
    99 
   122 
   100 		$show_description = isset($instance['description']) ? $instance['description'] : false;
   123 		$show_description = isset($instance['description']) ? $instance['description'] : false;
   101 		$show_name = isset($instance['name']) ? $instance['name'] : false;
   124 		$show_name = isset($instance['name']) ? $instance['name'] : false;
   102 		$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
   125 		$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
   103 		$show_images = isset($instance['images']) ? $instance['images'] : true;
   126 		$show_images = isset($instance['images']) ? $instance['images'] : true;
   104 		$category = isset($instance['category']) ? $instance['category'] : false;
   127 		$category = isset($instance['category']) ? $instance['category'] : false;
   105 		$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
   128 		$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
   106 		$order = $orderby == 'rating' ? 'DESC' : 'ASC';
   129 		$order = $orderby == 'rating' ? 'DESC' : 'ASC';
   107 		$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
   130 		$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
   108 
   131 
   109 		$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
   132 		$before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
   110 		wp_list_bookmarks(apply_filters('widget_links_args', array(
   133 
   111 			'title_before' => $before_title, 'title_after' => $after_title,
   134 		/**
   112 			'category_before' => $before_widget, 'category_after' => $after_widget,
   135 		 * Filter the arguments for the Links widget.
       
   136 		 *
       
   137 		 * @since 2.6.0
       
   138 		 *
       
   139 		 * @see wp_list_bookmarks()
       
   140 		 *
       
   141 		 * @param array $args An array of arguments to retrieve the links list.
       
   142 		 */
       
   143 		wp_list_bookmarks( apply_filters( 'widget_links_args', array(
       
   144 			'title_before' => $args['before_title'], 'title_after' => $args['after_title'],
       
   145 			'category_before' => $before_widget, 'category_after' => $args['after_widget'],
   113 			'show_images' => $show_images, 'show_description' => $show_description,
   146 			'show_images' => $show_images, 'show_description' => $show_description,
   114 			'show_name' => $show_name, 'show_rating' => $show_rating,
   147 			'show_name' => $show_name, 'show_rating' => $show_rating,
   115 			'category' => $category, 'class' => 'linkcat widget',
   148 			'category' => $category, 'class' => 'linkcat widget',
   116 			'orderby' => $orderby, 'order' => $order,
   149 			'orderby' => $orderby, 'order' => $order,
   117 			'limit' => $limit,
   150 			'limit' => $limit,
   118 		)));
   151 		) ) );
   119 	}
   152 	}
   120 
   153 
   121 	function update( $new_instance, $old_instance ) {
   154 	public function update( $new_instance, $old_instance ) {
   122 		$new_instance = (array) $new_instance;
   155 		$new_instance = (array) $new_instance;
   123 		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
   156 		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
   124 		foreach ( $instance as $field => $val ) {
   157 		foreach ( $instance as $field => $val ) {
   125 			if ( isset($new_instance[$field]) )
   158 			if ( isset($new_instance[$field]) )
   126 				$instance[$field] = 1;
   159 				$instance[$field] = 1;
   134 		$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
   167 		$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
   135 
   168 
   136 		return $instance;
   169 		return $instance;
   137 	}
   170 	}
   138 
   171 
   139 	function form( $instance ) {
   172 	public function form( $instance ) {
   140 
   173 
   141 		//Defaults
   174 		//Defaults
   142 		$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
   175 		$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
   143 		$link_cats = get_terms( 'link_category' );
   176 		$link_cats = get_terms( 'link_category' );
   144 		if ( ! $limit = intval( $instance['limit'] ) )
   177 		if ( ! $limit = intval( $instance['limit'] ) )
   187  *
   220  *
   188  * @since 2.8.0
   221  * @since 2.8.0
   189  */
   222  */
   190 class WP_Widget_Search extends WP_Widget {
   223 class WP_Widget_Search extends WP_Widget {
   191 
   224 
   192 	function __construct() {
   225 	public function __construct() {
   193 		$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
   226 		$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );
   194 		parent::__construct('search', __('Search'), $widget_ops);
   227 		parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
   195 	}
   228 	}
   196 
   229 
   197 	function widget( $args, $instance ) {
   230 	public function widget( $args, $instance ) {
   198 		extract($args);
   231 
       
   232 		/** This filter is documented in wp-includes/default-widgets.php */
   199 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   233 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   200 
   234 
   201 		echo $before_widget;
   235 		echo $args['before_widget'];
   202 		if ( $title )
   236 		if ( $title ) {
   203 			echo $before_title . $title . $after_title;
   237 			echo $args['before_title'] . $title . $args['after_title'];
       
   238 		}
   204 
   239 
   205 		// Use current theme search form if it exists
   240 		// Use current theme search form if it exists
   206 		get_search_form();
   241 		get_search_form();
   207 
   242 
   208 		echo $after_widget;
   243 		echo $args['after_widget'];
   209 	}
   244 	}
   210 
   245 
   211 	function form( $instance ) {
   246 	public function form( $instance ) {
   212 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   247 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   213 		$title = $instance['title'];
   248 		$title = $instance['title'];
   214 ?>
   249 ?>
   215 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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>
   250 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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>
   216 <?php
   251 <?php
   217 	}
   252 	}
   218 
   253 
   219 	function update( $new_instance, $old_instance ) {
   254 	public function update( $new_instance, $old_instance ) {
   220 		$instance = $old_instance;
   255 		$instance = $old_instance;
   221 		$new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
   256 		$new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
   222 		$instance['title'] = strip_tags($new_instance['title']);
   257 		$instance['title'] = strip_tags($new_instance['title']);
   223 		return $instance;
   258 		return $instance;
   224 	}
   259 	}
   230  *
   265  *
   231  * @since 2.8.0
   266  * @since 2.8.0
   232  */
   267  */
   233 class WP_Widget_Archives extends WP_Widget {
   268 class WP_Widget_Archives extends WP_Widget {
   234 
   269 
   235 	function __construct() {
   270 	public function __construct() {
   236 		$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s posts') );
   271 		$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s Posts.') );
   237 		parent::__construct('archives', __('Archives'), $widget_ops);
   272 		parent::__construct('archives', __('Archives'), $widget_ops);
   238 	}
   273 	}
   239 
   274 
   240 	function widget( $args, $instance ) {
   275 	public function widget( $args, $instance ) {
   241 		extract($args);
       
   242 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   276 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   243 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   277 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   244 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
   278 
   245 
   279 		/** This filter is documented in wp-includes/default-widgets.php */
   246 		echo $before_widget;
   280 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
   247 		if ( $title )
   281 
   248 			echo $before_title . $title . $after_title;
   282 		echo $args['before_widget'];
       
   283 		if ( $title ) {
       
   284 			echo $args['before_title'] . $title . $args['after_title'];
       
   285 		}
   249 
   286 
   250 		if ( $d ) {
   287 		if ( $d ) {
   251 ?>
   288 			$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
   252 		<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
   289 ?>
       
   290 		<label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
       
   291 		<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
       
   292 			<?php
       
   293 			/**
       
   294 			 * Filter the arguments for the Archives widget drop-down.
       
   295 			 *
       
   296 			 * @since 2.8.0
       
   297 			 *
       
   298 			 * @see wp_get_archives()
       
   299 			 *
       
   300 			 * @param array $args An array of Archives widget drop-down arguments.
       
   301 			 */
       
   302 			$dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
       
   303 				'type'            => 'monthly',
       
   304 				'format'          => 'option',
       
   305 				'show_post_count' => $c
       
   306 			) );
       
   307 
       
   308 			switch ( $dropdown_args['type'] ) {
       
   309 				case 'yearly':
       
   310 					$label = __( 'Select Year' );
       
   311 					break;
       
   312 				case 'monthly':
       
   313 					$label = __( 'Select Month' );
       
   314 					break;
       
   315 				case 'daily':
       
   316 					$label = __( 'Select Day' );
       
   317 					break;
       
   318 				case 'weekly':
       
   319 					$label = __( 'Select Week' );
       
   320 					break;
       
   321 				default:
       
   322 					$label = __( 'Select Post' );
       
   323 					break;
       
   324 			}
       
   325 			?>
       
   326 
       
   327 			<option value=""><?php echo esc_attr( $label ); ?></option>
       
   328 			<?php wp_get_archives( $dropdown_args ); ?>
       
   329 
       
   330 		</select>
   253 <?php
   331 <?php
   254 		} else {
   332 		} else {
   255 ?>
   333 ?>
   256 		<ul>
   334 		<ul>
   257 		<?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
   335 <?php
       
   336 		/**
       
   337 		 * Filter the arguments for the Archives widget.
       
   338 		 *
       
   339 		 * @since 2.8.0
       
   340 		 *
       
   341 		 * @see wp_get_archives()
       
   342 		 *
       
   343 		 * @param array $args An array of Archives option arguments.
       
   344 		 */
       
   345 		wp_get_archives( apply_filters( 'widget_archives_args', array(
       
   346 			'type'            => 'monthly',
       
   347 			'show_post_count' => $c
       
   348 		) ) );
       
   349 ?>
   258 		</ul>
   350 		</ul>
   259 <?php
   351 <?php
   260 		}
   352 		}
   261 
   353 
   262 		echo $after_widget;
   354 		echo $args['after_widget'];
   263 	}
   355 	}
   264 
   356 
   265 	function update( $new_instance, $old_instance ) {
   357 	public function update( $new_instance, $old_instance ) {
   266 		$instance = $old_instance;
   358 		$instance = $old_instance;
   267 		$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
   359 		$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
   268 		$instance['title'] = strip_tags($new_instance['title']);
   360 		$instance['title'] = strip_tags($new_instance['title']);
   269 		$instance['count'] = $new_instance['count'] ? 1 : 0;
   361 		$instance['count'] = $new_instance['count'] ? 1 : 0;
   270 		$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
   362 		$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
   271 
   363 
   272 		return $instance;
   364 		return $instance;
   273 	}
   365 	}
   274 
   366 
   275 	function form( $instance ) {
   367 	public function form( $instance ) {
   276 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
   368 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
   277 		$title = strip_tags($instance['title']);
   369 		$title = strip_tags($instance['title']);
   278 		$count = $instance['count'] ? 'checked="checked"' : '';
   370 		$count = $instance['count'] ? 'checked="checked"' : '';
   279 		$dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
   371 		$dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
   280 ?>
   372 ?>
   295  *
   387  *
   296  * @since 2.8.0
   388  * @since 2.8.0
   297  */
   389  */
   298 class WP_Widget_Meta extends WP_Widget {
   390 class WP_Widget_Meta extends WP_Widget {
   299 
   391 
   300 	function __construct() {
   392 	public function __construct() {
   301 		$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
   393 		$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, &amp; WordPress.org links.") );
   302 		parent::__construct('meta', __('Meta'), $widget_ops);
   394 		parent::__construct('meta', __('Meta'), $widget_ops);
   303 	}
   395 	}
   304 
   396 
   305 	function widget( $args, $instance ) {
   397 	public function widget( $args, $instance ) {
   306 		extract($args);
   398 
   307 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
   399 		/** This filter is documented in wp-includes/default-widgets.php */
   308 
   400 		$title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
   309 		echo $before_widget;
   401 
   310 		if ( $title )
   402 		echo $args['before_widget'];
   311 			echo $before_title . $title . $after_title;
   403 		if ( $title ) {
       
   404 			echo $args['before_title'] . $title . $args['after_title'];
       
   405 		}
   312 ?>
   406 ?>
   313 			<ul>
   407 			<ul>
   314 			<?php wp_register(); ?>
   408 			<?php wp_register(); ?>
   315 			<li><?php wp_loginout(); ?></li>
   409 			<li><?php wp_loginout(); ?></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>
   410 			<li><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Entries <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>
   411 			<li><a href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   318 			<?php echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
   412 <?php
   319 				esc_url( __( 'http://wordpress.org/' ) ),
   413 			/**
       
   414 			 * Filter the "Powered by WordPress" text in the Meta widget.
       
   415 			 *
       
   416 			 * @since 3.6.0
       
   417 			 *
       
   418 			 * @param string $title_text Default title text for the WordPress.org link.
       
   419 			 */
       
   420 			echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
       
   421 				esc_url( __( 'https://wordpress.org/' ) ),
   320 				esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
   422 				esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
   321 				_x( 'WordPress.org', 'meta widget link text' )
   423 				_x( 'WordPress.org', 'meta widget link text' )
   322 			) ); ?>
   424 			) );
   323 			<?php wp_meta(); ?>
   425 
       
   426 			wp_meta();
       
   427 ?>
   324 			</ul>
   428 			</ul>
   325 <?php
   429 <?php
   326 		echo $after_widget;
   430 		echo $args['after_widget'];
   327 	}
   431 	}
   328 
   432 
   329 	function update( $new_instance, $old_instance ) {
   433 	public function update( $new_instance, $old_instance ) {
   330 		$instance = $old_instance;
   434 		$instance = $old_instance;
   331 		$instance['title'] = strip_tags($new_instance['title']);
   435 		$instance['title'] = strip_tags($new_instance['title']);
   332 
   436 
   333 		return $instance;
   437 		return $instance;
   334 	}
   438 	}
   335 
   439 
   336 	function form( $instance ) {
   440 	public function form( $instance ) {
   337 		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
   441 		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
   338 		$title = strip_tags($instance['title']);
   442 		$title = strip_tags($instance['title']);
   339 ?>
   443 ?>
   340 			<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>
   444 			<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>
   341 <?php
   445 <?php
   347  *
   451  *
   348  * @since 2.8.0
   452  * @since 2.8.0
   349  */
   453  */
   350 class WP_Widget_Calendar extends WP_Widget {
   454 class WP_Widget_Calendar extends WP_Widget {
   351 
   455 
   352 	function __construct() {
   456 	public function __construct() {
   353 		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s posts') );
   457 		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s Posts.') );
   354 		parent::__construct('calendar', __('Calendar'), $widget_ops);
   458 		parent::__construct('calendar', __('Calendar'), $widget_ops);
   355 	}
   459 	}
   356 
   460 
   357 	function widget( $args, $instance ) {
   461 	public function widget( $args, $instance ) {
   358 		extract($args);
   462 
   359 		$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
   463 		/** This filter is documented in wp-includes/default-widgets.php */
   360 		echo $before_widget;
   464 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   361 		if ( $title )
   465 
   362 			echo $before_title . $title . $after_title;
   466 		echo $args['before_widget'];
       
   467 		if ( $title ) {
       
   468 			echo $args['before_title'] . $title . $args['after_title'];
       
   469 		}
   363 		echo '<div id="calendar_wrap">';
   470 		echo '<div id="calendar_wrap">';
   364 		get_calendar();
   471 		get_calendar();
   365 		echo '</div>';
   472 		echo '</div>';
   366 		echo $after_widget;
   473 		echo $args['after_widget'];
   367 	}
   474 	}
   368 
   475 
   369 	function update( $new_instance, $old_instance ) {
   476 	public function update( $new_instance, $old_instance ) {
   370 		$instance = $old_instance;
   477 		$instance = $old_instance;
   371 		$instance['title'] = strip_tags($new_instance['title']);
   478 		$instance['title'] = strip_tags($new_instance['title']);
   372 
   479 
   373 		return $instance;
   480 		return $instance;
   374 	}
   481 	}
   375 
   482 
   376 	function form( $instance ) {
   483 	public function form( $instance ) {
   377 		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
   484 		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
   378 		$title = strip_tags($instance['title']);
   485 		$title = strip_tags($instance['title']);
   379 ?>
   486 ?>
   380 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   487 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   381 		<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>
   488 		<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>
   388  *
   495  *
   389  * @since 2.8.0
   496  * @since 2.8.0
   390  */
   497  */
   391 class WP_Widget_Text extends WP_Widget {
   498 class WP_Widget_Text extends WP_Widget {
   392 
   499 
   393 	function __construct() {
   500 	public function __construct() {
   394 		$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
   501 		$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.'));
   395 		$control_ops = array('width' => 400, 'height' => 350);
   502 		$control_ops = array('width' => 400, 'height' => 350);
   396 		parent::__construct('text', __('Text'), $widget_ops, $control_ops);
   503 		parent::__construct('text', __('Text'), $widget_ops, $control_ops);
   397 	}
   504 	}
   398 
   505 
   399 	function widget( $args, $instance ) {
   506 	public function widget( $args, $instance ) {
   400 		extract($args);
   507 
       
   508 		/** This filter is documented in wp-includes/default-widgets.php */
   401 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
   509 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
       
   510 
       
   511 		/**
       
   512 		 * Filter the content of the Text widget.
       
   513 		 *
       
   514 		 * @since 2.3.0
       
   515 		 *
       
   516 		 * @param string    $widget_text The widget content.
       
   517 		 * @param WP_Widget $instance    WP_Widget instance.
       
   518 		 */
   402 		$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
   519 		$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
   403 		echo $before_widget;
   520 		echo $args['before_widget'];
   404 		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
   521 		if ( ! empty( $title ) ) {
       
   522 			echo $args['before_title'] . $title . $args['after_title'];
       
   523 		} ?>
   405 			<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
   524 			<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
   406 		<?php
   525 		<?php
   407 		echo $after_widget;
   526 		echo $args['after_widget'];
   408 	}
   527 	}
   409 
   528 
   410 	function update( $new_instance, $old_instance ) {
   529 	public function update( $new_instance, $old_instance ) {
   411 		$instance = $old_instance;
   530 		$instance = $old_instance;
   412 		$instance['title'] = strip_tags($new_instance['title']);
   531 		$instance['title'] = strip_tags($new_instance['title']);
   413 		if ( current_user_can('unfiltered_html') )
   532 		if ( current_user_can('unfiltered_html') )
   414 			$instance['text'] =  $new_instance['text'];
   533 			$instance['text'] =  $new_instance['text'];
   415 		else
   534 		else
   416 			$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
   535 			$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
   417 		$instance['filter'] = isset($new_instance['filter']);
   536 		$instance['filter'] = ! empty( $new_instance['filter'] );
   418 		return $instance;
   537 		return $instance;
   419 	}
   538 	}
   420 
   539 
   421 	function form( $instance ) {
   540 	public function form( $instance ) {
   422 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
   541 		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
   423 		$title = strip_tags($instance['title']);
   542 		$title = strip_tags($instance['title']);
   424 		$text = esc_textarea($instance['text']);
   543 		$text = esc_textarea($instance['text']);
   425 ?>
   544 ?>
   426 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   545 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   438  *
   557  *
   439  * @since 2.8.0
   558  * @since 2.8.0
   440  */
   559  */
   441 class WP_Widget_Categories extends WP_Widget {
   560 class WP_Widget_Categories extends WP_Widget {
   442 
   561 
   443 	function __construct() {
   562 	public function __construct() {
   444 		$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
   563 		$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) );
   445 		parent::__construct('categories', __('Categories'), $widget_ops);
   564 		parent::__construct('categories', __('Categories'), $widget_ops);
   446 	}
   565 	}
   447 
   566 
   448 	function widget( $args, $instance ) {
   567 	public function widget( $args, $instance ) {
   449 		extract( $args );
   568 
   450 
   569 		/** This filter is documented in wp-includes/default-widgets.php */
   451 		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
   570 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
       
   571 
   452 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   572 		$c = ! empty( $instance['count'] ) ? '1' : '0';
   453 		$h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
   573 		$h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
   454 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   574 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
   455 
   575 
   456 		echo $before_widget;
   576 		echo $args['before_widget'];
   457 		if ( $title )
   577 		if ( $title ) {
   458 			echo $before_title . $title . $after_title;
   578 			echo $args['before_title'] . $title . $args['after_title'];
   459 
   579 		}
   460 		$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
   580 
       
   581 		$cat_args = array(
       
   582 			'orderby'      => 'name',
       
   583 			'show_count'   => $c,
       
   584 			'hierarchical' => $h
       
   585 		);
   461 
   586 
   462 		if ( $d ) {
   587 		if ( $d ) {
   463 			$cat_args['show_option_none'] = __('Select Category');
   588 			static $first_dropdown = true;
   464 			wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
   589 
       
   590 			$dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
       
   591 			$first_dropdown = false;
       
   592 
       
   593 			echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
       
   594 
       
   595 			$cat_args['show_option_none'] = __( 'Select Category' );
       
   596 			$cat_args['id'] = $dropdown_id;
       
   597 
       
   598 			/**
       
   599 			 * Filter the arguments for the Categories widget drop-down.
       
   600 			 *
       
   601 			 * @since 2.8.0
       
   602 			 *
       
   603 			 * @see wp_dropdown_categories()
       
   604 			 *
       
   605 			 * @param array $cat_args An array of Categories widget drop-down arguments.
       
   606 			 */
       
   607 			wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
   465 ?>
   608 ?>
   466 
   609 
   467 <script type='text/javascript'>
   610 <script type='text/javascript'>
   468 /* <![CDATA[ */
   611 /* <![CDATA[ */
   469 	var dropdown = document.getElementById("cat");
   612 (function() {
       
   613 	var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
   470 	function onCatChange() {
   614 	function onCatChange() {
   471 		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
   615 		if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
   472 			location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
   616 			location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
   473 		}
   617 		}
   474 	}
   618 	}
   475 	dropdown.onchange = onCatChange;
   619 	dropdown.onchange = onCatChange;
       
   620 })();
   476 /* ]]> */
   621 /* ]]> */
   477 </script>
   622 </script>
   478 
   623 
   479 <?php
   624 <?php
   480 		} else {
   625 		} else {
   481 ?>
   626 ?>
   482 		<ul>
   627 		<ul>
   483 <?php
   628 <?php
   484 		$cat_args['title_li'] = '';
   629 		$cat_args['title_li'] = '';
   485 		wp_list_categories(apply_filters('widget_categories_args', $cat_args));
   630 
       
   631 		/**
       
   632 		 * Filter the arguments for the Categories widget.
       
   633 		 *
       
   634 		 * @since 2.8.0
       
   635 		 *
       
   636 		 * @param array $cat_args An array of Categories widget options.
       
   637 		 */
       
   638 		wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
   486 ?>
   639 ?>
   487 		</ul>
   640 		</ul>
   488 <?php
   641 <?php
   489 		}
   642 		}
   490 
   643 
   491 		echo $after_widget;
   644 		echo $args['after_widget'];
   492 	}
   645 	}
   493 
   646 
   494 	function update( $new_instance, $old_instance ) {
   647 	public function update( $new_instance, $old_instance ) {
   495 		$instance = $old_instance;
   648 		$instance = $old_instance;
   496 		$instance['title'] = strip_tags($new_instance['title']);
   649 		$instance['title'] = strip_tags($new_instance['title']);
   497 		$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
   650 		$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
   498 		$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
   651 		$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
   499 		$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
   652 		$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
   500 
   653 
   501 		return $instance;
   654 		return $instance;
   502 	}
   655 	}
   503 
   656 
   504 	function form( $instance ) {
   657 	public function form( $instance ) {
   505 		//Defaults
   658 		//Defaults
   506 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   659 		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
   507 		$title = esc_attr( $instance['title'] );
   660 		$title = esc_attr( $instance['title'] );
   508 		$count = isset($instance['count']) ? (bool) $instance['count'] :false;
   661 		$count = isset($instance['count']) ? (bool) $instance['count'] :false;
   509 		$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
   662 		$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
   530  *
   683  *
   531  * @since 2.8.0
   684  * @since 2.8.0
   532  */
   685  */
   533 class WP_Widget_Recent_Posts extends WP_Widget {
   686 class WP_Widget_Recent_Posts extends WP_Widget {
   534 
   687 
   535 	function __construct() {
   688 	public function __construct() {
   536 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
   689 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site&#8217;s most recent Posts.") );
   537 		parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
   690 		parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
   538 		$this->alt_option_name = 'widget_recent_entries';
   691 		$this->alt_option_name = 'widget_recent_entries';
   539 
   692 
   540 		add_action( 'save_post', array($this, 'flush_widget_cache') );
   693 		add_action( 'save_post', array($this, 'flush_widget_cache') );
   541 		add_action( 'deleted_post', array($this, 'flush_widget_cache') );
   694 		add_action( 'deleted_post', array($this, 'flush_widget_cache') );
   542 		add_action( 'switch_theme', array($this, 'flush_widget_cache') );
   695 		add_action( 'switch_theme', array($this, 'flush_widget_cache') );
   543 	}
   696 	}
   544 
   697 
   545 	function widget($args, $instance) {
   698 	public function widget($args, $instance) {
   546 		$cache = wp_cache_get('widget_recent_posts', 'widget');
   699 		$cache = array();
   547 
   700 		if ( ! $this->is_preview() ) {
   548 		if ( !is_array($cache) )
   701 			$cache = wp_cache_get( 'widget_recent_posts', 'widget' );
       
   702 		}
       
   703 
       
   704 		if ( ! is_array( $cache ) ) {
   549 			$cache = array();
   705 			$cache = array();
   550 
   706 		}
   551 		if ( ! isset( $args['widget_id'] ) )
   707 
       
   708 		if ( ! isset( $args['widget_id'] ) ) {
   552 			$args['widget_id'] = $this->id;
   709 			$args['widget_id'] = $this->id;
       
   710 		}
   553 
   711 
   554 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
   712 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
   555 			echo $cache[ $args['widget_id'] ];
   713 			echo $cache[ $args['widget_id'] ];
   556 			return;
   714 			return;
   557 		}
   715 		}
   558 
   716 
   559 		ob_start();
   717 		ob_start();
   560 		extract($args);
       
   561 
   718 
   562 		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
   719 		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
       
   720 
       
   721 		/** This filter is documented in wp-includes/default-widgets.php */
   563 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
   722 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
   564 		$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 10;
   723 
       
   724 		$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
   565 		if ( ! $number )
   725 		if ( ! $number )
   566  			$number = 10;
   726 			$number = 5;
   567 		$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
   727 		$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
   568 
   728 
   569 		$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 ) ) );
   729 		/**
       
   730 		 * Filter the arguments for the Recent Posts widget.
       
   731 		 *
       
   732 		 * @since 3.4.0
       
   733 		 *
       
   734 		 * @see WP_Query::get_posts()
       
   735 		 *
       
   736 		 * @param array $args An array of arguments used to retrieve the recent posts.
       
   737 		 */
       
   738 		$r = new WP_Query( apply_filters( 'widget_posts_args', array(
       
   739 			'posts_per_page'      => $number,
       
   740 			'no_found_rows'       => true,
       
   741 			'post_status'         => 'publish',
       
   742 			'ignore_sticky_posts' => true
       
   743 		) ) );
       
   744 
   570 		if ($r->have_posts()) :
   745 		if ($r->have_posts()) :
   571 ?>
   746 ?>
   572 		<?php echo $before_widget; ?>
   747 		<?php echo $args['before_widget']; ?>
   573 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   748 		<?php if ( $title ) {
       
   749 			echo $args['before_title'] . $title . $args['after_title'];
       
   750 		} ?>
   574 		<ul>
   751 		<ul>
   575 		<?php while ( $r->have_posts() ) : $r->the_post(); ?>
   752 		<?php while ( $r->have_posts() ) : $r->the_post(); ?>
   576 			<li>
   753 			<li>
   577 				<a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
   754 				<a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
   578 			<?php if ( $show_date ) : ?>
   755 			<?php if ( $show_date ) : ?>
   579 				<span class="post-date"><?php echo get_the_date(); ?></span>
   756 				<span class="post-date"><?php echo get_the_date(); ?></span>
   580 			<?php endif; ?>
   757 			<?php endif; ?>
   581 			</li>
   758 			</li>
   582 		<?php endwhile; ?>
   759 		<?php endwhile; ?>
   583 		</ul>
   760 		</ul>
   584 		<?php echo $after_widget; ?>
   761 		<?php echo $args['after_widget']; ?>
   585 <?php
   762 <?php
   586 		// Reset the global $the_post as this query will have stomped on it
   763 		// Reset the global $the_post as this query will have stomped on it
   587 		wp_reset_postdata();
   764 		wp_reset_postdata();
   588 
   765 
   589 		endif;
   766 		endif;
   590 
   767 
   591 		$cache[$args['widget_id']] = ob_get_flush();
   768 		if ( ! $this->is_preview() ) {
   592 		wp_cache_set('widget_recent_posts', $cache, 'widget');
   769 			$cache[ $args['widget_id'] ] = ob_get_flush();
   593 	}
   770 			wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
   594 
   771 		} else {
   595 	function update( $new_instance, $old_instance ) {
   772 			ob_end_flush();
       
   773 		}
       
   774 	}
       
   775 
       
   776 	public function update( $new_instance, $old_instance ) {
   596 		$instance = $old_instance;
   777 		$instance = $old_instance;
   597 		$instance['title'] = strip_tags($new_instance['title']);
   778 		$instance['title'] = strip_tags($new_instance['title']);
   598 		$instance['number'] = (int) $new_instance['number'];
   779 		$instance['number'] = (int) $new_instance['number'];
   599 		$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
   780 		$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
   600 		$this->flush_widget_cache();
   781 		$this->flush_widget_cache();
   604 			delete_option('widget_recent_entries');
   785 			delete_option('widget_recent_entries');
   605 
   786 
   606 		return $instance;
   787 		return $instance;
   607 	}
   788 	}
   608 
   789 
   609 	function flush_widget_cache() {
   790 	public function flush_widget_cache() {
   610 		wp_cache_delete('widget_recent_posts', 'widget');
   791 		wp_cache_delete('widget_recent_posts', 'widget');
   611 	}
   792 	}
   612 
   793 
   613 	function form( $instance ) {
   794 	public function form( $instance ) {
   614 		$title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   795 		$title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   615 		$number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
   796 		$number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
   616 		$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
   797 		$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
   617 ?>
   798 ?>
   618 		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   799 		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   632  *
   813  *
   633  * @since 2.8.0
   814  * @since 2.8.0
   634  */
   815  */
   635 class WP_Widget_Recent_Comments extends WP_Widget {
   816 class WP_Widget_Recent_Comments extends WP_Widget {
   636 
   817 
   637 	function __construct() {
   818 	public function __construct() {
   638 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
   819 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site&#8217;s most recent comments.' ) );
   639 		parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
   820 		parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
   640 		$this->alt_option_name = 'widget_recent_comments';
   821 		$this->alt_option_name = 'widget_recent_comments';
   641 
   822 
   642 		if ( is_active_widget(false, false, $this->id_base) )
   823 		if ( is_active_widget(false, false, $this->id_base) )
   643 			add_action( 'wp_head', array($this, 'recent_comments_style') );
   824 			add_action( 'wp_head', array($this, 'recent_comments_style') );
   645 		add_action( 'comment_post', array($this, 'flush_widget_cache') );
   826 		add_action( 'comment_post', array($this, 'flush_widget_cache') );
   646 		add_action( 'edit_comment', array($this, 'flush_widget_cache') );
   827 		add_action( 'edit_comment', array($this, 'flush_widget_cache') );
   647 		add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
   828 		add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
   648 	}
   829 	}
   649 
   830 
   650 	function recent_comments_style() {
   831 	public function recent_comments_style() {
       
   832 
       
   833 		/**
       
   834 		 * Filter the Recent Comments default widget styles.
       
   835 		 *
       
   836 		 * @since 3.1.0
       
   837 		 *
       
   838 		 * @param bool   $active  Whether the widget is active. Default true.
       
   839 		 * @param string $id_base The widget ID.
       
   840 		 */
   651 		if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
   841 		if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
   652 			|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
   842 			|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
   653 			return;
   843 			return;
   654 		?>
   844 		?>
   655 	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
   845 	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
   656 <?php
   846 <?php
   657 	}
   847 	}
   658 
   848 
   659 	function flush_widget_cache() {
   849 	public function flush_widget_cache() {
   660 		wp_cache_delete('widget_recent_comments', 'widget');
   850 		wp_cache_delete('widget_recent_comments', 'widget');
   661 	}
   851 	}
   662 
   852 
   663 	function widget( $args, $instance ) {
   853 	public function widget( $args, $instance ) {
   664 		global $comments, $comment;
   854 		global $comments, $comment;
   665 
   855 
   666 		$cache = wp_cache_get('widget_recent_comments', 'widget');
   856 		$cache = array();
   667 
   857 		if ( ! $this->is_preview() ) {
   668 		if ( ! is_array( $cache ) )
   858 			$cache = wp_cache_get('widget_recent_comments', 'widget');
       
   859 		}
       
   860 		if ( ! is_array( $cache ) ) {
   669 			$cache = array();
   861 			$cache = array();
       
   862 		}
   670 
   863 
   671 		if ( ! isset( $args['widget_id'] ) )
   864 		if ( ! isset( $args['widget_id'] ) )
   672 			$args['widget_id'] = $this->id;
   865 			$args['widget_id'] = $this->id;
   673 
   866 
   674 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
   867 		if ( isset( $cache[ $args['widget_id'] ] ) ) {
   675 			echo $cache[ $args['widget_id'] ];
   868 			echo $cache[ $args['widget_id'] ];
   676 			return;
   869 			return;
   677 		}
   870 		}
   678 
   871 
   679  		extract($args, EXTR_SKIP);
   872 		$output = '';
   680  		$output = '';
       
   681 
   873 
   682 		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
   874 		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
       
   875 
       
   876 		/** This filter is documented in wp-includes/default-widgets.php */
   683 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
   877 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
       
   878 
   684 		$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
   879 		$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
   685 		if ( ! $number )
   880 		if ( ! $number )
   686  			$number = 5;
   881 			$number = 5;
   687 
   882 
   688 		$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
   883 		/**
   689 		$output .= $before_widget;
   884 		 * Filter the arguments for the Recent Comments widget.
   690 		if ( $title )
   885 		 *
   691 			$output .= $before_title . $title . $after_title;
   886 		 * @since 3.4.0
       
   887 		 *
       
   888 		 * @see WP_Comment_Query::query() for information on accepted arguments.
       
   889 		 *
       
   890 		 * @param array $comment_args An array of arguments used to retrieve the recent comments.
       
   891 		 */
       
   892 		$comments = get_comments( apply_filters( 'widget_comments_args', array(
       
   893 			'number'      => $number,
       
   894 			'status'      => 'approve',
       
   895 			'post_status' => 'publish'
       
   896 		) ) );
       
   897 
       
   898 		$output .= $args['before_widget'];
       
   899 		if ( $title ) {
       
   900 			$output .= $args['before_title'] . $title . $args['after_title'];
       
   901 		}
   692 
   902 
   693 		$output .= '<ul id="recentcomments">';
   903 		$output .= '<ul id="recentcomments">';
   694 		if ( $comments ) {
   904 		if ( $comments ) {
   695 			// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
   905 			// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
   696 			$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
   906 			$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
   697 			_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
   907 			_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
   698 
   908 
   699 			foreach ( (array) $comments as $comment) {
   909 			foreach ( (array) $comments as $comment) {
   700 				$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>';
   910 				$output .= '<li class="recentcomments">';
       
   911 				/* translators: comments widget: 1: comment author, 2: post link */
       
   912 				$output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
       
   913 					'<span class="comment-author-link">' . get_comment_author_link() . '</span>',
       
   914 					'<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
       
   915 				);
       
   916 				$output .= '</li>';
   701 			}
   917 			}
   702  		}
   918 		}
   703 		$output .= '</ul>';
   919 		$output .= '</ul>';
   704 		$output .= $after_widget;
   920 		$output .= $args['after_widget'];
   705 
   921 
   706 		echo $output;
   922 		echo $output;
   707 		$cache[$args['widget_id']] = $output;
   923 
   708 		wp_cache_set('widget_recent_comments', $cache, 'widget');
   924 		if ( ! $this->is_preview() ) {
   709 	}
   925 			$cache[ $args['widget_id'] ] = $output;
   710 
   926 			wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
   711 	function update( $new_instance, $old_instance ) {
   927 		}
       
   928 	}
       
   929 
       
   930 	public function update( $new_instance, $old_instance ) {
   712 		$instance = $old_instance;
   931 		$instance = $old_instance;
   713 		$instance['title'] = strip_tags($new_instance['title']);
   932 		$instance['title'] = strip_tags($new_instance['title']);
   714 		$instance['number'] = absint( $new_instance['number'] );
   933 		$instance['number'] = absint( $new_instance['number'] );
   715 		$this->flush_widget_cache();
   934 		$this->flush_widget_cache();
   716 
   935 
   719 			delete_option('widget_recent_comments');
   938 			delete_option('widget_recent_comments');
   720 
   939 
   721 		return $instance;
   940 		return $instance;
   722 	}
   941 	}
   723 
   942 
   724 	function form( $instance ) {
   943 	public function form( $instance ) {
   725 		$title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   944 		$title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   726 		$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
   945 		$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
   727 ?>
   946 ?>
   728 		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   947 		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   729 		<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>
   948 		<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>
   739  *
   958  *
   740  * @since 2.8.0
   959  * @since 2.8.0
   741  */
   960  */
   742 class WP_Widget_RSS extends WP_Widget {
   961 class WP_Widget_RSS extends WP_Widget {
   743 
   962 
   744 	function __construct() {
   963 	public function __construct() {
   745 		$widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
   964 		$widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
   746 		$control_ops = array( 'width' => 400, 'height' => 200 );
   965 		$control_ops = array( 'width' => 400, 'height' => 200 );
   747 		parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
   966 		parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
   748 	}
   967 	}
   749 
   968 
   750 	function widget($args, $instance) {
   969 	public function widget($args, $instance) {
   751 
   970 
   752 		if ( isset($instance['error']) && $instance['error'] )
   971 		if ( isset($instance['error']) && $instance['error'] )
   753 			return;
   972 			return;
   754 
       
   755 		extract($args, EXTR_SKIP);
       
   756 
   973 
   757 		$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
   974 		$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
   758 		while ( stristr($url, 'http') != $url )
   975 		while ( stristr($url, 'http') != $url )
   759 			$url = substr($url, 1);
   976 			$url = substr($url, 1);
   760 
   977 
   780 		}
   997 		}
   781 
   998 
   782 		if ( empty($title) )
   999 		if ( empty($title) )
   783 			$title = empty($desc) ? __('Unknown Feed') : $desc;
  1000 			$title = empty($desc) ? __('Unknown Feed') : $desc;
   784 
  1001 
   785 		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
  1002 		/** This filter is documented in wp-includes/default-widgets.php */
       
  1003 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
       
  1004 
   786 		$url = esc_url(strip_tags($url));
  1005 		$url = esc_url(strip_tags($url));
   787 		$icon = includes_url('images/rss.png');
  1006 		$icon = includes_url('images/rss.png');
   788 		if ( $title )
  1007 		if ( $title )
   789 			$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>";
  1008 			$title = "<a class='rsswidget' href='$url'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link'>$title</a>";
   790 
  1009 
   791 		echo $before_widget;
  1010 		echo $args['before_widget'];
   792 		if ( $title )
  1011 		if ( $title ) {
   793 			echo $before_title . $title . $after_title;
  1012 			echo $args['before_title'] . $title . $args['after_title'];
       
  1013 		}
   794 		wp_widget_rss_output( $rss, $instance );
  1014 		wp_widget_rss_output( $rss, $instance );
   795 		echo $after_widget;
  1015 		echo $args['after_widget'];
   796 
  1016 
   797 		if ( ! is_wp_error($rss) )
  1017 		if ( ! is_wp_error($rss) )
   798 			$rss->__destruct();
  1018 			$rss->__destruct();
   799 		unset($rss);
  1019 		unset($rss);
   800 	}
  1020 	}
   801 
  1021 
   802 	function update($new_instance, $old_instance) {
  1022 	public function update($new_instance, $old_instance) {
   803 		$testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
  1023 		$testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
   804 		return wp_widget_rss_process( $new_instance, $testurl );
  1024 		return wp_widget_rss_process( $new_instance, $testurl );
   805 	}
  1025 	}
   806 
  1026 
   807 	function form($instance) {
  1027 	public function form($instance) {
   808 
  1028 
   809 		if ( empty($instance) )
  1029 		if ( empty($instance) )
   810 			$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
  1030 			$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
   811 		$instance['number'] = $this->number;
  1031 		$instance['number'] = $this->number;
   812 
  1032 
   836 		if ( is_admin() || current_user_can('manage_options') )
  1056 		if ( is_admin() || current_user_can('manage_options') )
   837 			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
  1057 			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
   838 		return;
  1058 		return;
   839 	}
  1059 	}
   840 
  1060 
   841 	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
  1061 	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
   842 	$args = wp_parse_args( $args, $default_args );
  1062 	$args = wp_parse_args( $args, $default_args );
   843 	extract( $args, EXTR_SKIP );
  1063 
   844 
  1064 	$items = (int) $args['items'];
   845 	$items = (int) $items;
       
   846 	if ( $items < 1 || 20 < $items )
  1065 	if ( $items < 1 || 20 < $items )
   847 		$items = 10;
  1066 		$items = 10;
   848 	$show_summary  = (int) $show_summary;
  1067 	$show_summary  = (int) $args['show_summary'];
   849 	$show_author   = (int) $show_author;
  1068 	$show_author   = (int) $args['show_author'];
   850 	$show_date     = (int) $show_date;
  1069 	$show_date     = (int) $args['show_date'];
   851 
  1070 
   852 	if ( !$rss->get_item_quantity() ) {
  1071 	if ( !$rss->get_item_quantity() ) {
   853 		echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
  1072 		echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
   854 		$rss->__destruct();
  1073 		$rss->__destruct();
   855 		unset($rss);
  1074 		unset($rss);
   856 		return;
  1075 		return;
   857 	}
  1076 	}
   858 
  1077 
   859 	echo '<ul>';
  1078 	echo '<ul>';
   860 	foreach ( $rss->get_items(0, $items) as $item ) {
  1079 	foreach ( $rss->get_items( 0, $items ) as $item ) {
   861 		$link = $item->get_link();
  1080 		$link = $item->get_link();
   862 		while ( stristr($link, 'http') != $link )
  1081 		while ( stristr( $link, 'http' ) != $link ) {
   863 			$link = substr($link, 1);
  1082 			$link = substr( $link, 1 );
   864 		$link = esc_url(strip_tags($link));
  1083 		}
   865 		$title = esc_attr(strip_tags($item->get_title()));
  1084 		$link = esc_url( strip_tags( $link ) );
   866 		if ( empty($title) )
  1085 
   867 			$title = __('Untitled');
  1086 		$title = esc_html( trim( strip_tags( $item->get_title() ) ) );
   868 
  1087 		if ( empty( $title ) ) {
   869 		$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
  1088 			$title = __( 'Untitled' );
   870 		$excerpt = wp_html_excerpt( $desc, 360 );
  1089 		}
   871 
  1090 
   872 		// Append ellipsis. Change existing [...] to [&hellip;].
  1091 		$desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
   873 		if ( '[...]' == substr( $excerpt, -5 ) )
  1092 		$desc = esc_attr( wp_trim_words( $desc, 55, ' [&hellip;]' ) );
   874 			$excerpt = substr( $excerpt, 0, -5 ) . '[&hellip;]';
  1093 
   875 		elseif ( '[&hellip;]' != substr( $excerpt, -10 ) && $desc != $excerpt )
  1094 		$summary = '';
   876 			$excerpt .= ' [&hellip;]';
       
   877 
       
   878 		$excerpt = esc_html( $excerpt );
       
   879 
       
   880 		if ( $show_summary ) {
  1095 		if ( $show_summary ) {
   881 			$summary = "<div class='rssSummary'>$excerpt</div>";
  1096 			$summary = $desc;
   882 		} else {
  1097 
   883 			$summary = '';
  1098 			// Change existing [...] to [&hellip;].
       
  1099 			if ( '[...]' == substr( $summary, -5 ) ) {
       
  1100 				$summary = substr( $summary, 0, -5 ) . '[&hellip;]';
       
  1101 			}
       
  1102 
       
  1103 			$summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
   884 		}
  1104 		}
   885 
  1105 
   886 		$date = '';
  1106 		$date = '';
   887 		if ( $show_date ) {
  1107 		if ( $show_date ) {
   888 			$date = $item->get_date( 'U' );
  1108 			$date = $item->get_date( 'U' );
   901 			}
  1121 			}
   902 		}
  1122 		}
   903 
  1123 
   904 		if ( $link == '' ) {
  1124 		if ( $link == '' ) {
   905 			echo "<li>$title{$date}{$summary}{$author}</li>";
  1125 			echo "<li>$title{$date}{$summary}{$author}</li>";
       
  1126 		} elseif ( $show_summary ) {
       
  1127 			echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";
   906 		} else {
  1128 		} else {
   907 			echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
  1129 			echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";
   908 		}
  1130 		}
   909 	}
  1131 	}
   910 	echo '</ul>';
  1132 	echo '</ul>';
   911 	$rss->__destruct();
  1133 	$rss->__destruct();
   912 	unset($rss);
  1134 	unset($rss);
   923  *
  1145  *
   924  * @param array|string $args Values for input fields.
  1146  * @param array|string $args Values for input fields.
   925  * @param array $inputs Override default display options.
  1147  * @param array $inputs Override default display options.
   926  */
  1148  */
   927 function wp_widget_rss_form( $args, $inputs = null ) {
  1149 function wp_widget_rss_form( $args, $inputs = null ) {
   928 
       
   929 	$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
  1150 	$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
   930 	$inputs = wp_parse_args( $inputs, $default_inputs );
  1151 	$inputs = wp_parse_args( $inputs, $default_inputs );
   931 	extract( $args );
  1152 
   932 	extract( $inputs, EXTR_SKIP );
  1153 	$args['number'] = esc_attr( $args['number'] );
   933 
  1154 	$args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
   934 	$number = esc_attr( $number );
  1155 	$args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
   935 	$title  = esc_attr( $title );
  1156 	$args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
   936 	$url    = esc_url( $url );
  1157 
   937 	$items  = (int) $items;
  1158 	if ( $args['items'] < 1 || 20 < $args['items'] ) {
   938 	if ( $items < 1 || 20 < $items )
  1159 		$args['items'] = 10;
   939 		$items  = 10;
  1160 	}
   940 	$show_summary   = (int) $show_summary;
  1161 
   941 	$show_author    = (int) $show_author;
  1162 	$args['show_summary']   = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
   942 	$show_date      = (int) $show_date;
  1163 	$args['show_author']    = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
   943 
  1164 	$args['show_date']      = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
   944 	if ( !empty($error) )
  1165 
   945 		echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
  1166 	if ( ! empty( $args['error'] ) ) {
       
  1167 		echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
       
  1168 	}
   946 
  1169 
   947 	if ( $inputs['url'] ) :
  1170 	if ( $inputs['url'] ) :
   948 ?>
  1171 ?>
   949 	<p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
  1172 	<p><label for="rss-url-<?php echo $args['number']; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>
   950 	<input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
  1173 	<input class="widefat" id="rss-url-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][url]" type="text" value="<?php echo $args['url']; ?>" /></p>
   951 <?php endif; if ( $inputs['title'] ) : ?>
  1174 <?php endif; if ( $inputs['title'] ) : ?>
   952 	<p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
  1175 	<p><label for="rss-title-<?php echo $args['number']; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>
   953 	<input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
  1176 	<input class="widefat" id="rss-title-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][title]" type="text" value="<?php echo $args['title']; ?>" /></p>
   954 <?php endif; if ( $inputs['items'] ) : ?>
  1177 <?php endif; if ( $inputs['items'] ) : ?>
   955 	<p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
  1178 	<p><label for="rss-items-<?php echo $args['number']; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>
   956 	<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
  1179 	<select id="rss-items-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][items]">
   957 <?php
  1180 <?php
   958 		for ( $i = 1; $i <= 20; ++$i )
  1181 		for ( $i = 1; $i <= 20; ++$i ) {
   959 			echo "<option value='$i' " . selected( $items, $i, false ) . ">$i</option>";
  1182 			echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";
       
  1183 		}
   960 ?>
  1184 ?>
   961 	</select></p>
  1185 	</select></p>
   962 <?php endif; if ( $inputs['show_summary'] ) : ?>
  1186 <?php endif; if ( $inputs['show_summary'] ) : ?>
   963 	<p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
  1187 	<p><input id="rss-show-summary-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> />
   964 	<label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
  1188 	<label for="rss-show-summary-<?php echo $args['number']; ?>"><?php _e( 'Display item content?' ); ?></label></p>
   965 <?php endif; if ( $inputs['show_author'] ) : ?>
  1189 <?php endif; if ( $inputs['show_author'] ) : ?>
   966 	<p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
  1190 	<p><input id="rss-show-author-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> />
   967 	<label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
  1191 	<label for="rss-show-author-<?php echo $args['number']; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>
   968 <?php endif; if ( $inputs['show_date'] ) : ?>
  1192 <?php endif; if ( $inputs['show_date'] ) : ?>
   969 	<p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
  1193 	<p><input id="rss-show-date-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>
   970 	<label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
  1194 	<label for="rss-show-date-<?php echo $args['number']; ?>"><?php _e( 'Display item date?' ); ?></label></p>
   971 <?php
  1195 <?php
   972 	endif;
  1196 	endif;
   973 	foreach ( array_keys($default_inputs) as $input ) :
  1197 	foreach ( array_keys($default_inputs) as $input ) :
   974 		if ( 'hidden' === $inputs[$input] ) :
  1198 		if ( 'hidden' === $inputs[$input] ) :
   975 			$id = str_replace( '_', '-', $input );
  1199 			$id = str_replace( '_', '-', $input );
   976 ?>
  1200 ?>
   977 	<input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
  1201 	<input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][<?php echo $input; ?>]" value="<?php echo $args[ $input ]; ?>" />
   978 <?php
  1202 <?php
   979 		endif;
  1203 		endif;
   980 	endforeach;
  1204 	endforeach;
   981 }
  1205 }
   982 
  1206 
  1030  *
  1254  *
  1031  * @since 2.8.0
  1255  * @since 2.8.0
  1032  */
  1256  */
  1033 class WP_Widget_Tag_Cloud extends WP_Widget {
  1257 class WP_Widget_Tag_Cloud extends WP_Widget {
  1034 
  1258 
  1035 	function __construct() {
  1259 	public function __construct() {
  1036 		$widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
  1260 		$widget_ops = array( 'description' => __( "A cloud of your most used tags.") );
  1037 		parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  1261 		parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  1038 	}
  1262 	}
  1039 
  1263 
  1040 	function widget( $args, $instance ) {
  1264 	public function widget( $args, $instance ) {
  1041 		extract($args);
       
  1042 		$current_taxonomy = $this->_get_current_taxonomy($instance);
  1265 		$current_taxonomy = $this->_get_current_taxonomy($instance);
  1043 		if ( !empty($instance['title']) ) {
  1266 		if ( !empty($instance['title']) ) {
  1044 			$title = $instance['title'];
  1267 			$title = $instance['title'];
  1045 		} else {
  1268 		} else {
  1046 			if ( 'post_tag' == $current_taxonomy ) {
  1269 			if ( 'post_tag' == $current_taxonomy ) {
  1048 			} else {
  1271 			} else {
  1049 				$tax = get_taxonomy($current_taxonomy);
  1272 				$tax = get_taxonomy($current_taxonomy);
  1050 				$title = $tax->labels->name;
  1273 				$title = $tax->labels->name;
  1051 			}
  1274 			}
  1052 		}
  1275 		}
  1053 		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
  1276 
  1054 
  1277 		/** This filter is documented in wp-includes/default-widgets.php */
  1055 		echo $before_widget;
  1278 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  1056 		if ( $title )
  1279 
  1057 			echo $before_title . $title . $after_title;
  1280 		echo $args['before_widget'];
       
  1281 		if ( $title ) {
       
  1282 			echo $args['before_title'] . $title . $args['after_title'];
       
  1283 		}
  1058 		echo '<div class="tagcloud">';
  1284 		echo '<div class="tagcloud">';
  1059 		wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
  1285 
       
  1286 		/**
       
  1287 		 * Filter the taxonomy used in the Tag Cloud widget.
       
  1288 		 *
       
  1289 		 * @since 2.8.0
       
  1290 		 * @since 3.0.0 Added taxonomy drop-down.
       
  1291 		 *
       
  1292 		 * @see wp_tag_cloud()
       
  1293 		 *
       
  1294 		 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
       
  1295 		 */
       
  1296 		wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
       
  1297 			'taxonomy' => $current_taxonomy
       
  1298 		) ) );
       
  1299 
  1060 		echo "</div>\n";
  1300 		echo "</div>\n";
  1061 		echo $after_widget;
  1301 		echo $args['after_widget'];
  1062 	}
  1302 	}
  1063 
  1303 
  1064 	function update( $new_instance, $old_instance ) {
  1304 	public function update( $new_instance, $old_instance ) {
       
  1305 		$instance = array();
  1065 		$instance['title'] = strip_tags(stripslashes($new_instance['title']));
  1306 		$instance['title'] = strip_tags(stripslashes($new_instance['title']));
  1066 		$instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  1307 		$instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  1067 		return $instance;
  1308 		return $instance;
  1068 	}
  1309 	}
  1069 
  1310 
  1070 	function form( $instance ) {
  1311 	public function form( $instance ) {
  1071 		$current_taxonomy = $this->_get_current_taxonomy($instance);
  1312 		$current_taxonomy = $this->_get_current_taxonomy($instance);
  1072 ?>
  1313 ?>
  1073 	<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1314 	<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1074 	<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>
  1315 	<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>
  1075 	<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
  1316 	<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
  1082 		<option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
  1323 		<option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
  1083 	<?php endforeach; ?>
  1324 	<?php endforeach; ?>
  1084 	</select></p><?php
  1325 	</select></p><?php
  1085 	}
  1326 	}
  1086 
  1327 
  1087 	function _get_current_taxonomy($instance) {
  1328 	public function _get_current_taxonomy($instance) {
  1088 		if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
  1329 		if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
  1089 			return $instance['taxonomy'];
  1330 			return $instance['taxonomy'];
  1090 
  1331 
  1091 		return 'post_tag';
  1332 		return 'post_tag';
  1092 	}
  1333 	}
  1097  *
  1338  *
  1098  * @since 3.0.0
  1339  * @since 3.0.0
  1099  */
  1340  */
  1100  class WP_Nav_Menu_Widget extends WP_Widget {
  1341  class WP_Nav_Menu_Widget extends WP_Widget {
  1101 
  1342 
  1102 	function __construct() {
  1343 	public function __construct() {
  1103 		$widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
  1344 		$widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
  1104 		parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
  1345 		parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
  1105 	}
  1346 	}
  1106 
  1347 
  1107 	function widget($args, $instance) {
  1348 	public function widget($args, $instance) {
  1108 		// Get menu
  1349 		// Get menu
  1109 		$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
  1350 		$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
  1110 
  1351 
  1111 		if ( !$nav_menu )
  1352 		if ( !$nav_menu )
  1112 			return;
  1353 			return;
  1113 
  1354 
       
  1355 		/** This filter is documented in wp-includes/default-widgets.php */
  1114 		$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  1356 		$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  1115 
  1357 
  1116 		echo $args['before_widget'];
  1358 		echo $args['before_widget'];
  1117 
  1359 
  1118 		if ( !empty($instance['title']) )
  1360 		if ( !empty($instance['title']) )
  1119 			echo $args['before_title'] . $instance['title'] . $args['after_title'];
  1361 			echo $args['before_title'] . $instance['title'] . $args['after_title'];
  1120 
  1362 
  1121 		wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
  1363 		$nav_menu_args = array(
       
  1364 			'fallback_cb' => '',
       
  1365 			'menu'        => $nav_menu
       
  1366 		);
       
  1367 
       
  1368 		/**
       
  1369 		 * Filter the arguments for the Custom Menu widget.
       
  1370 		 *
       
  1371 		 * @since 4.2.0
       
  1372 		 *
       
  1373 		 * @param array    $nav_menu_args {
       
  1374 		 *     An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
       
  1375 		 *
       
  1376 		 *     @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
       
  1377 		 *     @type mixed         $menu        Menu ID, slug, or name.
       
  1378 		 * }
       
  1379 		 * @param stdClass $nav_menu      Nav menu object for the current menu.
       
  1380 		 * @param array    $args          Display arguments for the current widget.
       
  1381 		 */
       
  1382 		wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) );
  1122 
  1383 
  1123 		echo $args['after_widget'];
  1384 		echo $args['after_widget'];
  1124 	}
  1385 	}
  1125 
  1386 
  1126 	function update( $new_instance, $old_instance ) {
  1387 	public function update( $new_instance, $old_instance ) {
  1127 		$instance['title'] = strip_tags( stripslashes($new_instance['title']) );
  1388 		$instance = array();
  1128 		$instance['nav_menu'] = (int) $new_instance['nav_menu'];
  1389 		if ( ! empty( $new_instance['title'] ) ) {
       
  1390 			$instance['title'] = strip_tags( stripslashes($new_instance['title']) );
       
  1391 		}
       
  1392 		if ( ! empty( $new_instance['nav_menu'] ) ) {
       
  1393 			$instance['nav_menu'] = (int) $new_instance['nav_menu'];
       
  1394 		}
  1129 		return $instance;
  1395 		return $instance;
  1130 	}
  1396 	}
  1131 
  1397 
  1132 	function form( $instance ) {
  1398 	public function form( $instance ) {
  1133 		$title = isset( $instance['title'] ) ? $instance['title'] : '';
  1399 		$title = isset( $instance['title'] ) ? $instance['title'] : '';
  1134 		$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
  1400 		$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
  1135 
  1401 
  1136 		// Get menus
  1402 		// Get menus
  1137 		$menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
  1403 		$menus = wp_get_nav_menus();
  1138 
  1404 
  1139 		// If no menus exists, direct the user to go and create some.
  1405 		// If no menus exists, direct the user to go and create some.
  1140 		if ( !$menus ) {
  1406 		if ( !$menus ) {
  1141 			echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
  1407 			echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
  1142 			return;
  1408 			return;
  1147 			<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; ?>" />
  1413 			<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; ?>" />
  1148 		</p>
  1414 		</p>
  1149 		<p>
  1415 		<p>
  1150 			<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1416 			<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1151 			<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  1417 			<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
       
  1418 				<option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
  1152 		<?php
  1419 		<?php
  1153 			foreach ( $menus as $menu ) {
  1420 			foreach ( $menus as $menu ) {
  1154 				echo '<option value="' . $menu->term_id . '"'
  1421 				echo '<option value="' . $menu->term_id . '"'
  1155 					. selected( $nav_menu, $menu->term_id, false )
  1422 					. selected( $nav_menu, $menu->term_id, false )
  1156 					. '>'. $menu->name . '</option>';
  1423 					. '>'. esc_html( $menu->name ) . '</option>';
  1157 			}
  1424 			}
  1158 		?>
  1425 		?>
  1159 			</select>
  1426 			</select>
  1160 		</p>
  1427 		</p>
  1161 		<?php
  1428 		<?php
  1199 
  1466 
  1200 	register_widget('WP_Widget_Tag_Cloud');
  1467 	register_widget('WP_Widget_Tag_Cloud');
  1201 
  1468 
  1202 	register_widget('WP_Nav_Menu_Widget');
  1469 	register_widget('WP_Nav_Menu_Widget');
  1203 
  1470 
  1204 	do_action('widgets_init');
  1471 	/**
       
  1472 	 * Fires after all default WordPress widgets have been registered.
       
  1473 	 *
       
  1474 	 * @since 2.2.0
       
  1475 	 */
       
  1476 	do_action( 'widgets_init' );
  1205 }
  1477 }
  1206 
  1478 
  1207 add_action('init', 'wp_widgets_init', 1);
  1479 add_action('init', 'wp_widgets_init', 1);