Make WordPress Core

Ticket #17276: default-widgets.php

File default-widgets.php, 46.6 KB (added by squeeky, 13 years ago)

modified version of wp-includes/default-widgets.php

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