~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-includes/default-widgets.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

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