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