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