AVH Extended Categories Widgets - Version 2.0

Version Description

Download this release

Release Info

Developer petervanderdoes
Plugin Icon wp plugin AVH Extended Categories Widgets
Version 2.0
Comparing to
See all releases

Code changes from version 1.5.1 to 2.0

2.8/avh-ec.client.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Include all the classes we use.
3
+ require (dirname( __FILE__ ) . '/class/avh-ec.core.php');
4
+ require (dirname( __FILE__ ) . '/class/avh-ec.widgets.php');
5
+
6
+ /**
7
+ * Initialize the plugin
8
+ *
9
+ */
10
+ function avhextendedcategories_init ()
11
+ {
12
+ add_action( 'widgets_init', 'avhextendedcategories_widgets_init' );
13
+
14
+ } // End avhamazon_init()
15
+
16
+
17
+ /**
18
+ * Register the widget
19
+ *
20
+ * @WordPress Action widgets_init
21
+ * @since 3.0
22
+ *
23
+ */
24
+ function avhextendedcategories_widgets_init ()
25
+ {
26
+ register_widget( 'WP_Widget_AVH_ExtendedCategories_Normal' );
27
+ register_widget( 'WP_Widget_AVH_ExtendendCategories_Top' );
28
+ }
29
+
30
+ add_action( 'plugins_loaded', 'avhextendedcategories_init' );
31
+ ?>
2.8/class/avh-ec.core.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class AVHExtendendCategoriesCore
3
+ {
4
+ var $version;
5
+ var $comment;
6
+
7
+ /**
8
+ * PHP5 constructor
9
+ *
10
+ */
11
+ function __construct ()
12
+ {
13
+ $this->version = '2.0';
14
+ $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
15
+ }
16
+
17
+ /**
18
+ * PHP4 Constructor
19
+ *
20
+ * @return AVHExtendendCategoriesCore
21
+ */
22
+ function AVHExtendendCategoriesCore ()
23
+ {
24
+ $this->__construct();
25
+ }
26
+
27
+ /**
28
+ * Singleton method
29
+ *
30
+ * @return object
31
+ */
32
+ function getInstance ()
33
+ {
34
+ static $_instance;
35
+ if ( $_instance === null ) {
36
+ $_instance = & new self( );
37
+ }
38
+ return $_instance;
39
+ }
40
+
41
+ /**
42
+ * Used in forms to set the checked option.
43
+ *
44
+ * @param mixed $checked
45
+ * @param mixed_type $current
46
+ * @return string
47
+ *
48
+ * @since 2.0
49
+ */
50
+ function isChecked ( $checked, $current )
51
+ {
52
+ if ( $checked == $current ) {
53
+ return (' checked="checked"');
54
+ }
55
+ return ('');
56
+ }
57
+ }
58
+ ?>
2.8/class/avh-ec.widgets.php ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Widget Class for displaying categories. Extended version of the dfeault categories.
4
+ *
5
+ */
6
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
7
+ {
8
+ var $core;
9
+
10
+ /**
11
+ * PHP 5 Constructor
12
+ *
13
+ */
14
+ function __construct ()
15
+ {
16
+ $this->core = & AVHExtendendCategoriesCore::getInstance();
17
+
18
+ //Convert the old option widget_extended_categories to widget_extended-categories
19
+ $old = get_option( 'widget_extended_categories' );
20
+ if ( ! (false === $old) ) {
21
+ update_option( 'widget_extended-categories', $old );
22
+ delete_option( 'widget_extended_categories' );
23
+ }
24
+ $widget_ops = array ('description' => __( "An extended version of the default Categories widget." ) );
25
+ WP_Widget::__construct( 'extended-categories', __( 'AVH Extended Categories' ), $widget_ops );
26
+ }
27
+
28
+ function WP_Widget_AVH_ExtendedCategories_Normal ()
29
+ {
30
+ $this->__construct();
31
+ }
32
+
33
+ /**
34
+ * Display the widget
35
+ *
36
+ * @param unknown_type $args
37
+ * @param unknown_type $instance
38
+ */
39
+ function widget ( $args, $instance )
40
+ {
41
+ extract( $args );
42
+
43
+ $c = $instance['count'] ? '1' : '0';
44
+ $h = $instance['hierarchical'] ? '1' : '0';
45
+ $d = $instance['depth'] ? $instance['depth'] : - 1;
46
+ $e = $instance['hide_empty'] ? '1' : '0';
47
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
48
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
49
+ $r = $instance['rssfeed'] ? 'RSS' : '';
50
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
51
+ if ( empty( $r ) ) {
52
+ $i = '';
53
+ }
54
+ if ( ! empty( $i ) ) {
55
+ if ( ! file_exists( ABSPATH . '/' . $i ) ) {
56
+ $i = '';
57
+ }
58
+ }
59
+ if ( empty( $d ) ) {
60
+ $d = - 1;
61
+ }
62
+
63
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'] );
64
+ $style = empty( $instance['style'] ) ? 'list' : $instance['style'];
65
+ if ( $instance['post_category'] ) {
66
+ $post_category = unserialize( $instance['post_category'] );
67
+ $included_cats = implode( ",", $post_category );
68
+ }
69
+ $cat_args = array ('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => __( 'Select Category' ), 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number );
70
+ echo $before_widget;
71
+ echo $this->core->comment;
72
+ echo $before_title . $title . $after_title;
73
+ echo '<ul>';
74
+
75
+ if ( $style == 'list' ) {
76
+ wp_list_categories( $cat_args );
77
+ } else {
78
+ wp_dropdown_categories( $cat_args );
79
+ echo '<script type=\'text/javascript\'>' . "\n";
80
+ echo '/* <![CDATA[ */' . "\n";
81
+ echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
82
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
83
+ echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
84
+ echo ' location.href = "' . get_option( 'home' ) . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
85
+ echo ' }' . "\n";
86
+ echo ' }' . "\n";
87
+ echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
88
+ echo '/* ]]> */' . "\n";
89
+ echo '</script>' . "\n";
90
+ }
91
+ echo '</ul>';
92
+ echo $after_widget;
93
+ }
94
+
95
+ /**
96
+ * When Widget Control Form Is Posted
97
+ *
98
+ * @param unknown_type $new_instance
99
+ * @param unknown_type $old_instance
100
+ * @return unknown
101
+ */
102
+ function update ( $new_instance, $old_instance )
103
+ {
104
+ // update the instance's settings
105
+ if ( ! isset( $new_instance['submit'] ) ) {
106
+ return false;
107
+ }
108
+
109
+ $instance = $old_instance;
110
+
111
+ $instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) );
112
+ $instance['count'] = $new_instance['count'] ? 1 : 0;
113
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? 1 : 0;
114
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? 1 : 0;
115
+ $instance['sort_column'] = strip_tags( stripslashes( $new_instance['sort_column'] ) );
116
+ $instance['sort_order'] = strip_tags( stripslashes( $new_instance['sort_order'] ) );
117
+ $instance['style'] = strip_tags( stripslashes( $new_instance['style'] ) );
118
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? 1 : 0;
119
+ $instance['rssimage'] = strip_tags( stripslashes( $new_instance['rssimage'] ) );
120
+ if ( array_key_exists( 'all', $new_instance['post_category'] ) ) {
121
+ $instance['post_category'] = false;
122
+ } else {
123
+ $instance['post_category'] = serialize( $new_instance['post_category'] );
124
+ }
125
+ $instance['depth'] = ( int ) $new_instance['depth'];
126
+ if ( $instance['depth'] < 0 || 11 < $instance['depth'] ) {
127
+ $instance['depth'] = 0;
128
+ }
129
+ return $instance;
130
+ }
131
+
132
+ /**
133
+ * Display Widget Control Form
134
+ *
135
+ * @param unknown_type $instance
136
+ */
137
+ function form ( $instance )
138
+ {
139
+ // displays the widget admin form
140
+ $instance = wp_parse_args( ( array ) $instance, array ('title' => '', 'rssimage' => '', 'depth' => 0 ) );
141
+
142
+ // Prepare data for display
143
+ $title = esc_attr( $instance['title'] );
144
+ $count = ( bool ) $instance['count'];
145
+ $hierarchical = ( bool ) $instance['hierarchical'];
146
+ $depth = ( int ) $instance['depth'];
147
+ $hide_empty = ( bool ) $instance['hide_empty'];
148
+ $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
149
+ $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
150
+ $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
151
+ $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
152
+ $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
153
+ $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
154
+ $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
155
+ $rssfeed = ( bool ) $instance['rssfeed'];
156
+ $rssimage = esc_attr( $instance['rssimage'] );
157
+ $selected_cats = ($instance['post_category'] != '') ? unserialize( $instance['post_category'] ) : false;
158
+
159
+ if ( $depth < 0 || 11 < $depth ) {
160
+ $depth = 0;
161
+ }
162
+ echo '<p>';
163
+ echo '<label for="' . $this->get_field_id( 'title' ) . '">';
164
+ _e( 'Title:' );
165
+ echo '<input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" /> ';
166
+ echo '</label>';
167
+ echo '</p>';
168
+
169
+ echo '<p>';
170
+
171
+ echo '<label for="' . $this->get_field_id( 'count' ) . '">';
172
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'count' ) . '" name="' . $this->get_field_name( 'count' ) . '" ' . $this->core->isChecked( true, $count ) . ' /> ';
173
+ _e( 'Show post counts' );
174
+ echo '</label>';
175
+ echo '<br />';
176
+
177
+ echo '<label for="' . $this->get_field_id( 'hierachical' ) . '">';
178
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'hierachical' ) . '" name="' . $this->get_field_name( 'hierarchical' ) . '" ' . $this->core->isChecked( true, $hierarchical ) . ' /> ';
179
+ _e( 'Show hierarchy' );
180
+ echo '</label>';
181
+ echo '<br />';
182
+
183
+ echo '<label for="' . $this->get_field_id( 'depth' ) . '">';
184
+ _e( 'How many levels to show' );
185
+ echo '</label>';
186
+ echo '<select id="' . $this->get_field_id( 'depth' ) . '" name="' . $this->get_field_name( 'depth' ) . '"> ';
187
+ echo '<option value="0" ' . (0 == $depth ? "selected='selected'" : '') . '>' . __( 'All Levels' ) . '</option>';
188
+ echo '<option value="1" ' . (1 == $depth ? "selected='selected'" : '') . '>' . __( 'Toplevel only' ) . '</option>';
189
+ for ( $i = 2; $i <= 11; $i ++ ) {
190
+ echo '<option value="' . $i . '" ' . ($i == $depth ? "selected='selected'" : '') . '>' . __( 'Child ' ) . ($i - 1) . '</option>';
191
+ }
192
+ echo '</select>';
193
+ echo '<br />';
194
+
195
+ echo '<label for="' . $this->get_field_id( 'hide_empty' ) . '">';
196
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'hide_empty' ) . '" name="' . $this->get_field_name( 'hide_empty' ) . '" ' . $this->core->isChecked( true, $hide_empty ) . '/> ';
197
+ _e( 'Hide empty categories' );
198
+ echo '</label>';
199
+ echo '<br />';
200
+ echo '</p>';
201
+
202
+ echo '<p>';
203
+ echo '<label for="' . $this->get_field_id( 'sort_column' ) . '">';
204
+ _e( 'Sort by ' );
205
+ echo '<select id="' . $this->get_field_id( 'sort_column' ) . '" name="' . $this->get_field_name( 'sort_column' ) . '"> ';
206
+ echo '<option value="ID" ' . $sort_id . '>' . __( 'ID' ) . '</option>';
207
+ echo '<option value="name" ' . $sort_name . '>' . __( 'Name' ) . '</option>';
208
+ echo '<option value="count" ' . $sort_count . '>' . __( 'Count' ) . '</option>';
209
+ echo '</select>';
210
+ echo '</label>';
211
+ echo '<br />';
212
+
213
+ echo '<label for="' . $this->get_field_id( 'sort_order' ) . '">';
214
+ _e( 'Sort order ' );
215
+ echo '<select id="' . $this->get_field_id( 'sort_order' ) . '" name="' . $this->get_field_name( 'sort_order' ) . '"> ';
216
+ echo '<option value="asc" ' . $sort_order_a . '>' . __( 'Ascending' ) . '</option>';
217
+ echo '<option value="desc" ' . $sort_order_d . '>' . __( 'Descending' ) . '</option>';
218
+ echo '</select>';
219
+ echo '</label>';
220
+ echo '<br />';
221
+
222
+ echo '<label for="' . $this->get_field_id( 'style' ) . '">';
223
+ _e( 'Display style ' );
224
+ echo '<select id="' . $this->get_field_id( 'style' ) . '" name="' . $this->get_field_name( 'style' ) . '"> ';
225
+ echo '<option value="list" ' . $style_list . '>' . __( 'List' ) . '</option>';
226
+ echo '<option value="drop" ' . $style_drop . '>' . __( 'Drop down' ) . '</option>';
227
+ echo '</select>';
228
+ echo '</label>';
229
+ echo '<br />';
230
+ echo '</p>';
231
+
232
+ echo '<p>';
233
+
234
+ echo '<label for="' . $this->get_field_id( 'rssfeed' ) . '">';
235
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'rssfeed' ) . '" name="' . $this->get_field_name( 'rssfeed' ) . '" ' . $this->core->isChecked( true, $rssfeed ) . '/> ';
236
+ _e( 'Show RSS Feed' );
237
+ echo '</label>';
238
+ echo '<br />';
239
+
240
+ echo '<label for="">';
241
+ _e( 'Full path to RSS image:' );
242
+ echo '<input class="widefat" id="' . $this->get_field_id( 'rssimage' ) . '" name="' . $this->get_field_name( 'rssimage' ) . '" type="text" value="' . $rssimage . '" />';
243
+ echo '</label>';
244
+ echo '</p>';
245
+
246
+ echo '<p>';
247
+ echo '<b>' . __( 'Include these categories' ) . '</b><hr />';
248
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
249
+ echo '<li id="' . $this->get_field_id( 'category--1' ) . '" class="popular-category">';
250
+ echo '<label for="' . $this->get_field_id( 'post_category' ) . '" class="selectit">';
251
+ echo '<input value="all" id="' . $this->get_field_id( 'post_category' ) . '" name="' . $this->get_field_name( 'post_category' ) . '[all]" type="checkbox" ' . $this->core->isChecked( false, $selected_cats ) . '> ';
252
+ _e( 'Include All Categories' );
253
+ echo '</label>';
254
+ echo '</li>';
255
+ $this->avh_wp_category_checklist( 0, 0, $selected_cats, false, $this->number );
256
+ echo '</ul>';
257
+ echo '</p>';
258
+
259
+ echo '<input type="hidden" id="' . $this->get_field_id( 'submit' ) . '" name="' . $this->get_field_name( 'submit' ) . '" value="1" />';
260
+ }
261
+
262
+ /**
263
+ * Creates the categories checklist
264
+ *
265
+ * @param int $post_id
266
+ * @param int $descendants_and_self
267
+ * @param array $selected_cats
268
+ * @param array $popular_cats
269
+ * @param int $number
270
+ */
271
+ function avh_wp_category_checklist ( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $number )
272
+ {
273
+ $walker = new AVH_Walker_Category_Checklist( );
274
+ $walker->number = $number;
275
+ $walker->input_id = $this->get_field_id( 'post_category' );
276
+ $walker->input_name = $this->get_field_name( 'post_category' );
277
+ $walker->li_id = $this->get_field_id( 'category--1' );
278
+
279
+ $descendants_and_self = ( int ) $descendants_and_self;
280
+
281
+ $args = array ();
282
+ if ( is_array( $selected_cats ) )
283
+ $args['selected_cats'] = $selected_cats;
284
+ elseif ( $post_id )
285
+ $args['selected_cats'] = wp_get_post_categories( $post_id );
286
+ else
287
+ $args['selected_cats'] = array ();
288
+
289
+ if ( is_array( $popular_cats ) )
290
+ $args['popular_cats'] = $popular_cats;
291
+ else
292
+ $args['popular_cats'] = get_terms( 'category', array ('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
293
+
294
+ if ( $descendants_and_self ) {
295
+ $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
296
+ $self = get_category( $descendants_and_self );
297
+ array_unshift( $categories, $self );
298
+ } else {
299
+ $categories = get_categories( 'get=all' );
300
+ }
301
+
302
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
303
+ $checked_categories = array ();
304
+ for ( $i = 0; isset( $categories[$i] ); $i ++ ) {
305
+ if ( in_array( $categories[$i]->term_id, $args['selected_cats'] ) ) {
306
+ $checked_categories[] = $categories[$i];
307
+ unset( $categories[$i] );
308
+ }
309
+ }
310
+
311
+ // Put checked cats on top
312
+ echo call_user_func_array( array (&$walker, 'walk' ), array ($checked_categories, 0, $args ) );
313
+ // Then the rest of them
314
+ echo call_user_func_array( array (&$walker, 'walk' ), array ($categories, 0, $args ) );
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Widget Class for displaying the top categories
320
+ *
321
+ */
322
+ class WP_Widget_AVH_ExtendendCategories_Top extends WP_Widget
323
+ {
324
+ var $core;
325
+
326
+ /**
327
+ * PHP 5 Constructor
328
+ *
329
+ */
330
+ function __construct ()
331
+ {
332
+ $this->core = & AVHExtendendCategoriesCore::getInstance();
333
+
334
+ $widget_ops = array ('description' => __( "Shows the top categories." ) );
335
+ WP_Widget::__construct( false, __( 'AVH Extended Categories Top' ), $widget_ops );
336
+ }
337
+
338
+ function WP_Widget_AVH_ExtendedCategories_Top ()
339
+ {
340
+ $this->__construct();
341
+ }
342
+
343
+ /** Echo the widget content.
344
+ *
345
+ * Subclasses should over-ride this function to generate their widget code.
346
+ *
347
+ * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
348
+ * @param array $instance The settings for the particular instance of the widget
349
+ */
350
+ function widget ( $args, $instance )
351
+ {
352
+
353
+ extract( $args );
354
+
355
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'] );
356
+ $style = empty( $instance['style'] ) ? 'list' : $instance['style'];
357
+ if ( ! $a = ( int ) $instance['amount'] ) {
358
+ $a = 5;
359
+ } elseif ( $a < 1 ) {
360
+ $a = 1;
361
+ }
362
+ $c = $instance['count'] ? '1' : '0';
363
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
364
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
365
+ $r = $instance['rssfeed'] ? 'RSS' : '';
366
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
367
+ if ( empty( $r ) ) {
368
+ $i = '';
369
+ }
370
+ if ( ! empty( $i ) ) {
371
+ if ( ! file_exists( ABSPATH . '/' . $i ) ) {
372
+ $i = '';
373
+ }
374
+ }
375
+
376
+ $top_cats = get_terms( 'category', array ('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => false ) );
377
+ $included_cats = implode( ",", $top_cats );
378
+
379
+ $cat_args = array ('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'hide_empty' => 0, 'hierarchical' => 0, 'depth' => - 1, 'title_li' => '', 'show_option_none' => __( 'Select Category' ), 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number );
380
+ echo $before_widget;
381
+ echo $this->core->comment;
382
+ echo $before_title . $title . $after_title;
383
+ echo '<ul>';
384
+
385
+ if ( $style == 'list' ) {
386
+ wp_list_categories( $cat_args );
387
+ } else {
388
+ wp_dropdown_categories( $cat_args );
389
+ echo '<script type=\'text/javascript\'>' . "\n";
390
+ echo '/* <![CDATA[ */' . "\n";
391
+ echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
392
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
393
+ echo ' if ( ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
394
+ echo ' location.href = "' . get_option( 'home' ) . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
395
+ echo ' }' . "\n";
396
+ echo ' }' . "\n";
397
+ echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
398
+ echo '/* ]]> */' . "\n";
399
+ echo '</script>' . "\n";
400
+ }
401
+ echo '</ul>';
402
+ echo $after_widget;
403
+ }
404
+
405
+ /** Update a particular instance.
406
+ *
407
+ * This function should check that $new_instance is set correctly.
408
+ * The newly calculated value of $instance should be returned.
409
+ * If "false" is returned, the instance won't be saved/updated.
410
+ *
411
+ * @param array $new_instance New settings for this instance as input by the user via form()
412
+ * @param array $old_instance Old settings for this instance
413
+ * @return array Settings to save or bool false to cancel saving
414
+ */
415
+ function update ( $new_instance, $old_instance )
416
+ {
417
+ // update the instance's settings
418
+ if ( ! isset( $new_instance['submit'] ) ) {
419
+ return false;
420
+ }
421
+
422
+ $instance = $old_instance;
423
+
424
+ $instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) );
425
+ $instance['amount'] = ( int ) $new_instance['amount'];
426
+ $instance['count'] = $new_instance['count'] ? 1 : 0;
427
+ $instance['sort_column'] = strip_tags( stripslashes( $new_instance['sort_column'] ) );
428
+ $instance['sort_order'] = strip_tags( stripslashes( $new_instance['sort_order'] ) );
429
+ $instance['style'] = strip_tags( stripslashes( $new_instance['style'] ) );
430
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? 1 : 0;
431
+ $instance['rssimage'] = strip_tags( stripslashes( $new_instance['rssimage'] ) );
432
+
433
+ return $instance;
434
+ }
435
+
436
+ /** Echo the settings update form
437
+ *
438
+ * @param array $instance Current settings
439
+ */
440
+ function form ( $instance )
441
+ {
442
+ // displays the widget admin form
443
+ $instance = wp_parse_args( ( array ) $instance, array ('title' => '', 'rssimage' => '' ) );
444
+
445
+ // Prepare data for display
446
+ $title = esc_attr( $instance['title'] );
447
+ if ( ! $amount = ( int ) $instance['amount'] ) {
448
+ $amount = 5;
449
+ }
450
+ $count = ( bool ) $instance['count'];
451
+ $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
452
+ $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
453
+ $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
454
+ $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
455
+ $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
456
+ $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
457
+ $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
458
+ $rssfeed = ( bool ) $instance['rssfeed'];
459
+ $rssimage = esc_attr( $instance['rssimage'] );
460
+
461
+ if ( $amount < 1 ) {
462
+ $amount = 1;
463
+ }
464
+ echo '<p>';
465
+ echo '<label for="' . $this->get_field_id( 'title' ) . '">';
466
+ _e( 'Title:' );
467
+ echo '<input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" /> ';
468
+ echo '</label>';
469
+ echo '</p>';
470
+
471
+ echo '<p>';
472
+ echo '<label for="' . $this->get_field_id( 'amount' ) . '">';
473
+ _e( 'How many categories to show' );
474
+ echo '</label>';
475
+ echo '<input class="widefat" id="' . $this->get_field_id( 'amount' ) . '" name="' . $this->get_field_name( 'amount' ) . '" type="text" value="' . $amount . '" /> ';
476
+ echo '</select>';
477
+ echo '</p>';
478
+
479
+ echo '<p>';
480
+ echo '<label for="' . $this->get_field_id( 'count' ) . '">';
481
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'count' ) . '" name="' . $this->get_field_name( 'count' ) . '" ' . $this->core->isChecked( true, $count ) . ' /> ';
482
+ _e( 'Show post counts' );
483
+ echo '</label>';
484
+ echo '<br />';
485
+
486
+ echo '<label for="' . $this->get_field_id( 'sort_column' ) . '">';
487
+ _e( 'Sort by ' );
488
+ echo '<select id="' . $this->get_field_id( 'sort_column' ) . '" name="' . $this->get_field_name( 'sort_column' ) . '"> ';
489
+ echo '<option value="ID" ' . $sort_id . '>' . __( 'ID' ) . '</option>';
490
+ echo '<option value="name" ' . $sort_name . '>' . __( 'Name' ) . '</option>';
491
+ echo '<option value="count" ' . $sort_count . '>' . __( 'Count' ) . '</option>';
492
+ echo '</select>';
493
+ echo '</label>';
494
+ echo '<br />';
495
+
496
+ echo '<label for="' . $this->get_field_id( 'sort_order' ) . '">';
497
+ _e( 'Sort order ' );
498
+ echo '<select id="' . $this->get_field_id( 'sort_order' ) . '" name="' . $this->get_field_name( 'sort_order' ) . '"> ';
499
+ echo '<option value="asc" ' . $sort_order_a . '>' . __( 'Ascending' ) . '</option>';
500
+ echo '<option value="desc" ' . $sort_order_d . '>' . __( 'Descending' ) . '</option>';
501
+ echo '</select>';
502
+ echo '</label>';
503
+ echo '<br />';
504
+
505
+ echo '<label for="' . $this->get_field_id( 'style' ) . '">';
506
+ _e( 'Display style ' );
507
+ echo '<select id="' . $this->get_field_id( 'style' ) . '" name="' . $this->get_field_name( 'style' ) . '"> ';
508
+ echo '<option value="list" ' . $style_list . '>' . __( 'List' ) . '</option>';
509
+ echo '<option value="drop" ' . $style_drop . '>' . __( 'Drop down' ) . '</option>';
510
+ echo '</select>';
511
+ echo '</label>';
512
+ echo '<br />';
513
+ echo '</p>';
514
+
515
+ echo '<p>';
516
+
517
+ echo '<label for="' . $this->get_field_id( 'rssfeed' ) . '">';
518
+ echo '<input class="checkbox" type="checkbox" id="' . $this->get_field_id( 'rssfeed' ) . '" name="' . $this->get_field_name( 'rssfeed' ) . '" ' . $this->core->isChecked( true, $rssfeed ) . '/> ';
519
+ _e( 'Show RSS Feed' );
520
+ echo '</label>';
521
+ echo '<br />';
522
+
523
+ echo '<label for="">';
524
+ _e( 'Full path to RSS image:' );
525
+ echo '<input class="widefat" id="' . $this->get_field_id( 'rssimage' ) . '" name="' . $this->get_field_name( 'rssimage' ) . '" type="text" value="' . $rssimage . '" />';
526
+ echo '</label>';
527
+ echo '</p>';
528
+
529
+ echo '<input type="hidden" id="' . $this->get_field_id( 'submit' ) . '" name="' . $this->get_field_name( 'submit' ) . '" value="1" />';
530
+ }
531
+
532
+ }
533
+ /**
534
+ * Class that will display the categories
535
+ *
536
+ */
537
+ class AVH_Walker_Category_Checklist extends Walker
538
+ {
539
+ var $tree_type = 'category';
540
+ var $db_fields = array ('parent' => 'parent', 'id' => 'term_id' ); //TODO: decouple this
541
+ var $number;
542
+ var $input_id;
543
+ var $input_name;
544
+ var $li_id;
545
+
546
+ function start_lvl ( &$output, $depth, $args )
547
+ {
548
+ $indent = str_repeat( "\t", $depth );
549
+ $output .= "$indent<ul class='children'>\n";
550
+ }
551
+
552
+ function end_lvl ( &$output, $depth, $args )
553
+ {
554
+ $indent = str_repeat( "\t", $depth );
555
+ $output .= "$indent</ul>\n";
556
+ }
557
+
558
+ function start_el ( &$output, $category, $depth, $args )
559
+ {
560
+ extract( $args );
561
+ $this->input_id = $this->input_id . '-' . $category->term_id;
562
+ $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
563
+ $output .= "\n<li id='$this->li_id'$class>" . '<label for="' . $this->input_id . '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $this->input_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "") . '/> ' . wp_specialchars( apply_filters( 'the_category', $category->name ) ) . '</label>';
564
+ }
565
+
566
+ function end_el ( &$output, $category, $depth, $args )
567
+ {
568
+ $output .= "</li>\n";
569
+ }
570
+ }
571
+ ?>
readme.txt CHANGED
@@ -1,25 +1,44 @@
1
  === Extended Categories Widget ===
2
  Contributors: petervanderdoes
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
- Tags: extended, categories, widget
5
  Requires at least: 2.3
6
- Tested up to: 2.7.1
7
- Stable tag: 1.5.1
8
 
9
- Replacement of the category widget to allow for greater customization of the category widget.
10
 
11
  == Description ==
12
 
13
- Replacement of the category widget to allow for greater customization of the category widget. The following options have been implemented:
14
 
15
- * Display as List or Dropdown
16
- * Show number of posts (Count) after the category
17
- * Hide empty categories
 
 
 
 
 
 
 
18
  * Show categories hierarchical.
 
 
 
 
 
 
 
 
 
 
 
 
19
  * Sort by ID, Name,Count.
20
  * Sort ascending or descending.
21
  * Show RSS link after the category as text or image.
22
- * Select which categories to show. (Requires WordPress 2.5.1 or higher)
23
 
24
  == Installation ==
25
 
@@ -29,7 +48,7 @@ The Extended Categories Widget can be installed in 3 easy steps:
29
 
30
  1. Activate the plugin
31
 
32
- 1. Go to the Presentation->Widgets page and drag the widget into the sidebar of your choice. Configuration of the widget is done like all other widgets.
33
 
34
 
35
  == Frequently Asked Questions ==
@@ -37,10 +56,20 @@ The Extended Categories Widget can be installed in 3 easy steps:
37
  = What about support? =
38
  I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.
39
 
 
 
 
 
 
 
40
  == Screenshots ==
41
  None
42
 
43
  == Arbitrary section ==
 
 
 
 
44
  * Version 1.5.1
45
  * Bugfix: Compatibility issue with the plugin wp-security-scan
46
  * Version 1.5
1
  === Extended Categories Widget ===
2
  Contributors: petervanderdoes
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
+ Tags: extended, categories, widget, top categories
5
  Requires at least: 2.3
6
+ Tested up to: 2.8
7
+ Stable tag: 2.0
8
 
9
+ The AVH Extended Categories Widget gives you two widgets for displaying categories. One is a replacement of the default category widget to allow for greater customization. The second is a Top Categories widget.
10
 
11
  == Description ==
12
 
13
+ The AVH Extended Categories Widget gives you two widgets for displaying categories.
14
 
15
+ 1. Replacement of the default category widget to allow for greater customization.
16
+
17
+ 1. A top categories widget. Shows the top X categories. This requires WordPress 2.8 or higher.
18
+
19
+ The replacement widget gives you the following customizable options:
20
+
21
+ * Title of the widget.
22
+ * Display as List or Dropdown.
23
+ * Show number of posts (Count) after the category.
24
+ * Hide empty categories.
25
  * Show categories hierarchical.
26
+ * Show categories up to a certain depth. (Requires WordPress 2.8 or higher).
27
+ * Sort by ID, Name,Count.
28
+ * Sort ascending or descending.
29
+ * Show RSS link after the category as text or image.
30
+ * Select which categories to show. (Requires WordPress 2.5.1 or higher).
31
+
32
+ The Top Categories widget gives you the following customizable options:
33
+
34
+ * Title of the widget.
35
+ * How many categories to show.
36
+ * Display as List or Dropdown.
37
+ * Show number of posts (Count) after the category.
38
  * Sort by ID, Name,Count.
39
  * Sort ascending or descending.
40
  * Show RSS link after the category as text or image.
41
+ * Select which categories to show. (Requires WordPress 2.5.1 or higher).
42
 
43
  == Installation ==
44
 
48
 
49
  1. Activate the plugin
50
 
51
+ 1. Go to the Presentation/Appearance->Widgets page and drag the widget into the sidebar of your choice. Configuration of the widget is done like all other widgets.
52
 
53
 
54
  == Frequently Asked Questions ==
56
  = What about support? =
57
  I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.
58
 
59
+ = Depth selection =
60
+ Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.
61
+
62
+ Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:
63
+ You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.
64
+
65
  == Screenshots ==
66
  None
67
 
68
  == Arbitrary section ==
69
+ * Version 2.0
70
+ * Updated for WordPress 2.8. Unlimited amount of Extended Categories widgets is now possible.
71
+ * In WordPress 2.8 you have the options to select depth when showing hierarchy. See FAQ for more information.
72
+ * With WordPress 2.8 there is a new widget, AVH Extended Categories Top. This will show the top categories based on amount of posts.
73
  * Version 1.5.1
74
  * Bugfix: Compatibility issue with the plugin wp-security-scan
75
  * Version 1.5
widget-pre2.8.php ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function widget_extended_categories_init() {
4
+ // Widgets exists?
5
+ if (! function_exists ( 'wp_register_sidebar_widget' ) || ! function_exists ( 'wp_register_widget_control' )) {
6
+ return;
7
+ }
8
+
9
+ function widget_extended_categories($args, $number = 1) {
10
+ $version = '2.0';
11
+ // Check for version
12
+ require (ABSPATH . WPINC . '/version.php');
13
+ if ( version_compare($wp_version, '2.5.1', '<') ) {
14
+ $avh_extcat_canselectcats=false;
15
+ } else {
16
+ $avh_extcat_canselectcats=true;
17
+ }
18
+ extract ( $args );
19
+ $options = get_option ( 'widget_extended_categories' );
20
+ $c = $options [$number]['count'] ? '1' : '0';
21
+ $h = $options [$number]['hierarchical'] ? '1' : '0';
22
+ $e = $options [$number]['hide_empty'] ? '1' : '0';
23
+ $s = $options [$number]['sort_column'] ? $options [$number]['sort_column'] : 'name';
24
+ $o = $options [$number]['sort_order'] ? $options [$number]['sort_order'] : 'asc';
25
+ $r = $options [$number]['rssfeed'] ? 'RSS' : '';
26
+ $i = $options [$number]['rssimage'] ? $options [$number]['rssimage'] : '';
27
+ if (empty($r)) {
28
+ $i='';
29
+ }
30
+ if (!empty($i)){
31
+ if (! file_exists(ABSPATH . '/'. $i)) {
32
+ $i='';
33
+ }
34
+ }
35
+ $title = empty ( $options [$number]['title'] ) ? __ ( 'Categories' ) : attribute_escape($options [$number]['title']);
36
+ $style = empty ( $options [$number]['style'] ) ? 'list' : $options [$number]['style'];
37
+ if ($avh_extcat_canselectcats) {
38
+ if ($options [$number]['post_category']) {
39
+ $post_category = unserialize ( $options [$number]['post_category'] );
40
+ $included_cats = implode ( ",", $post_category );
41
+ }
42
+ $cat_args = array (
43
+ 'include' => $included_cats,
44
+ 'orderby' => $s,
45
+ 'order' => $o,
46
+ 'show_count' => $c,
47
+ 'hide_empty' => $e,
48
+ 'hierarchical' => $h,
49
+ 'title_li' => '',
50
+ 'show_option_none' => __ ( 'Select Category' ),
51
+ 'feed' => $r,
52
+ 'feed_image' => $i,
53
+ 'name' => 'ec-cat-'.$number,
54
+ 'depth' => 2, );
55
+ } else {
56
+ $cat_args = array (
57
+ 'orderby' => $s,
58
+ 'order' => $o,
59
+ 'show_count' => $c,
60
+ 'hide_empty' => $e,
61
+ 'hierarchical' => $h,
62
+ 'title_li' => '',
63
+ 'show_option_none' => __ ( 'Select Category' ),
64
+ 'feed' => $r,
65
+ 'feed_image' => $i,
66
+ 'name' => 'ec-cat-'.$number);
67
+ }
68
+ echo $before_widget;
69
+ echo '<!-- AVH Extended Categories version ' . $version .' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
70
+ echo $before_title . $title . $after_title;
71
+ echo '<ul>';
72
+
73
+ if ($style == 'list') {
74
+ wp_list_categories ( $cat_args );
75
+ } else {
76
+ wp_dropdown_categories ( $cat_args );
77
+ ?>
78
+ <script lang='javascript'><!--
79
+ var ec_dropdown_<?php echo ($number); ?> = document.getElementById('ec-cat-<?php echo ($number); ?>');
80
+ function ec_onCatChange_<?php echo ($number); ?>() {
81
+ if ( ec_dropdown_<?php echo ($number); ?>.options[ec_dropdown_<?php echo ($number); ?>.selectedIndex].value > 0 ) {
82
+ location.href = "<?php echo get_option ( 'home' ); ?>/?cat="+ec_dropdown_<?php echo ($number); ?>.options[ec_dropdown_<?php echo ($number); ?>.selectedIndex].value;
83
+ }
84
+ }
85
+ ec_dropdown_<?php echo ($number); ?>.onchange = ec_onCatChange_<?php echo ($number); ?>;
86
+ --></script>
87
+ <?php
88
+ }
89
+ echo '</ul>';
90
+ echo $after_widget;
91
+ }
92
+
93
+ function widget_extended_categories_control($number = 1) {
94
+ // Check for version
95
+ require (ABSPATH . WPINC . '/version.php');
96
+ if ( version_compare($wp_version, '2.5.1', '<') ) {
97
+ $avh_extcat_canselectcats=false;
98
+ } else {
99
+ $avh_extcat_canselectcats=true;
100
+ }
101
+ // Get actual options
102
+ $options = $newoptions = get_option ( 'widget_extended_categories' );
103
+ if (! is_array ( $options )) {
104
+ $options = $newoptions = array ( );
105
+ }
106
+ // Post to new options array
107
+
108
+ if ($_POST ['categories-submit-' . $number]) {
109
+ $newoptions [$number]['title'] = strip_tags ( stripslashes ( $_POST ['categories-title-' . $number] ) );
110
+ $newoptions [$number]['count'] = isset ( $_POST ['categories-count-' . $number] );
111
+ $newoptions [$number]['hierarchical'] = isset ( $_POST ['categories-hierarchical-' . $number] );
112
+ $newoptions [$number]['hide_empty'] = isset ( $_POST ['categories-hide_empty-' . $number] );
113
+ $newoptions [$number]['sort_column'] = strip_tags ( stripslashes ( $_POST ['categories-sort_column-' . $number] ) );
114
+ $newoptions [$number]['sort_order'] = strip_tags ( stripslashes ( $_POST ['categories-sort_order-' . $number] ) );
115
+ $newoptions [$number]['style'] = strip_tags ( stripslashes ( $_POST ['categories-style-' . $number] ) );
116
+ $newoptions [$number]['rssfeed'] = isset ( $_POST ['categories-rssfeed-' . $number] );
117
+ $newoptions [$number]['rssimage'] = attribute_escape ( $_POST ['categories-rssimage-' . $number] );
118
+ if ($avh_extcat_canselectcats) {
119
+ if (in_array ( '-1', $_POST ['post_category-' . $number], true )) {
120
+ $newoptions [$number]['post_category'] = false;
121
+ } else {
122
+ $newoptions [$number]['post_category'] = serialize ( $_POST ['post_category-' . $number] );
123
+ }
124
+ }
125
+
126
+ }
127
+
128
+ // Update if new options
129
+ if ($options != $newoptions) {
130
+ $options = $newoptions;
131
+ update_option ( 'widget_extended_categories', $options );
132
+ }
133
+
134
+ // Prepare data for display
135
+ $title = htmlspecialchars ( $options [$number]['title'], ENT_QUOTES );
136
+ $count = $options [$number]['count'] ? 'checked="checked"' : '';
137
+ $hierarchical = $options [$number]['hierarchical'] ? 'checked="checked"' : '';
138
+ $hide_empty = $options [$number]['hide_empty'] ? 'checked="checked"' : '';
139
+ $sort_id = ($options [$number]['sort_column'] == 'ID') ? ' SELECTED' : '';
140
+ $sort_name = ($options [$number]['sort_column'] == 'name') ? ' SELECTED' : '';
141
+ $sort_count = ($options [$number]['sort_column'] == 'count') ? ' SELECTED' : '';
142
+ $sort_order_a = ($options [$number]['sort_order'] == 'asc') ? ' SELECTED' : '';
143
+ $sort_order_d = ($options [$number]['sort_order'] == 'desc') ? ' SELECTED' : '';
144
+ $style_list = ($options [$number]['style'] == 'list') ? ' SELECTED' : '';
145
+ $style_drop = ($options [$number]['style'] == 'drop') ? ' SELECTED' : '';
146
+ $rssfeed = $options [$number]['rssfeed'] ? 'checked="checked"' : '';
147
+ $rssimage = htmlspecialchars ( $options [$number]['rssimage'], ENT_QUOTES );
148
+ if ($avh_extcat_canselectcats) {
149
+ $selected_cats = ($options [$number]['post_category'] != '') ? unserialize ( $options [$number]['post_category'] ) : false;
150
+ }
151
+ ?>
152
+ <div>
153
+ <label for="categories-title-<?php echo $number; ?>"><?php _e ( 'Title:' ); ?>
154
+ <input style="width: 250px;" id="categories-title-<?php echo $number; ?>" name="categories-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
155
+ </label>
156
+
157
+ <label for="categories-count-<?php echo $number; ?>" style="line-height: 35px; display: block;">Show post counts
158
+ <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count-<?php echo $number; ?>" name="categories-count-<?php echo $number; ?>" />
159
+ </label>
160
+
161
+ <label for="categories-hierarchical" style="line-height: 35px; display: block;">Show hierarchy
162
+ <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical-<?php echo $number; ?>" name="categories-hierarchical-<?php echo $number; ?>" />
163
+ </label>
164
+
165
+ <label for="categories-hide_empty-<?php echo $number; ?>" style="line-height: 35px; display: block;">Hide empty categories
166
+ <input class="checkbox" type="checkbox" <?php echo $hide_empty; ?> id="categories-hide_empty-<?php echo $number; ?>" name="categories-hide_empty-<?php echo $number; ?>" />
167
+ </label>
168
+
169
+ <label for="categories-sort_column-<?php echo $number; ?>" style="line-height: 35px; display: block;">Sort by
170
+ <select id="categories-sort_column-<?php echo $number; ?>" name="categories-sort_column-<?php echo $number; ?>">
171
+ <option value="ID" <?php echo $sort_id?>>ID</option>
172
+ <option value="name" <?php echo $sort_name?>>Name</option>
173
+ <option value="count" <?php echo $sort_count?>>Count</option>
174
+ </select>
175
+ </label>
176
+
177
+ <label for="categories-sort_order-<?php echo $number; ?>" style="line-height: 35px; display: block;">Sort order
178
+ <select id="categories-sort_order-<?php echo $number; ?>" name="categories-sort_order-<?php echo $number; ?>">
179
+ <option value="asc" <?php echo $sort_order_a?>>Ascending</option>
180
+ <option value="desc" <?php echo $sort_order_d?>>Descending</option>
181
+ </select>
182
+ </label>
183
+
184
+ <label for="categories-style-<?php echo $number; ?>" style="line-height: 35px; display: block;">Display style
185
+ <select id="categories-style-<?php echo $number; ?>" name="categories-style-<?php echo $number; ?>">
186
+ <option value='list' <?php echo $style_list; ?>>List</option>
187
+ <option value='drop' <?php echo $style_drop; ?>>Drop down</option>
188
+ </select>
189
+ </label>
190
+
191
+ <label for="categories-rssfeed-<?php echo $number; ?>" style="line-height: 35px; display: block;">Show RSS Feed
192
+ <input class="checkbox" type="checkbox" <?php echo $rssfeed; ?> id="categories-rssfeed-<?php echo $number; ?>" name="categories-rssfeed-<?php echo $number; ?>" />
193
+ </label>
194
+
195
+ <label for="categories-rssimage-<?php echo $number; ?>"><?php _e ( 'Full path to RSS image:' ); ?>
196
+ <input style="width: 250px;" id="categories-rssimage-<?php echo $number; ?>" name="categories-rssimage-<?php echo $number; ?>" type="text" value="<?php echo $rssimage; ?>" />
197
+ </label>
198
+
199
+ <?php
200
+ if ($avh_extcat_canselectcats) {
201
+ echo ' <b>Include these categories</b><hr />';
202
+ echo ' <ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
203
+ echo ' <li id="category--1-'.$number.'" class="popular-category">';
204
+ echo ' <label for="in-category--1-'.$number.'" class="selectit">';
205
+ echo ' <input value="-1" name="post_category-'.$number.'[]" id="in-category--1-'.$number.'" type="checkbox"';
206
+ if (!$selected_cats) { echo 'checked'; }
207
+ echo '> Include All Categories';
208
+ echo ' </label>';
209
+ echo ' </li>';
210
+ avh_wp_category_checklist(0,0,$selected_cats,false,$number);
211
+ echo ' </ul>';
212
+ }
213
+ ?>
214
+
215
+ <input type="hidden" id="categories-submit-<?php echo $number; ?>" name="categories-submit-<?php echo $number; ?>" value="1" /></div>
216
+ <?php
217
+ }
218
+ /**
219
+ * Called after the widget_extended_categories_page form has been submitted.
220
+ * Set the amount of widgets wanted and register the widgets
221
+ *
222
+ */
223
+ function widget_extended_categories_setup() {
224
+ $options = $newoptions = get_option('widget_extended_categories');
225
+ if ( isset($_POST['extended_categories-number-submit']) ) {
226
+ $number = (int) $_POST['extended_categories-number'];
227
+ if ( $number > 9 ) $number = 9;
228
+ if ( $number < 1 ) $number = 1;
229
+ $newoptions['number'] = $number;
230
+ }
231
+ if ( $options != $newoptions ) {
232
+ $options = $newoptions;
233
+ update_option('widget_extended_categories', $options);
234
+ widget_extended_categories_register($options['number']);
235
+ }
236
+ }
237
+ /**
238
+ * How many Wish List widgets are wanted.
239
+ *
240
+ */
241
+ function widget_extended_categories_page() {
242
+ $options = get_option('widget_extended_categories');
243
+ ?>
244
+ <div class="wrap">
245
+ <form method="post">
246
+ <h2><?php _e('AVH Extended Categories Widgets', 'avhextendedcategories'); ?></h2>
247
+ <p style="line-height: 30px;"><?php _e('How many wishlist widgets would you like?', 'avhextendedcategories'); ?>
248
+ <select id="extended_categories-number" name="extended_categories-number" value="<?php echo $options['number']; ?>">
249
+ <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?>
250
+ </select>
251
+ <span class="submit"><input type="submit" name="extended_categories-number-submit" id="extended_categories-number-submit" value="<?php echo attribute_escape(__('Save', 'avhextendedcategories')); ?>" /></span></p>
252
+ </form>
253
+ </div>
254
+ <?php
255
+ }
256
+ function widget_extended_categories_register() {
257
+ $options = get_option( 'widget_extended_categories' );
258
+
259
+ $number = ( int ) $options['number'];
260
+ if ( $number < 1 ) $number = 1;
261
+ if ( $number > 9 ) $number = 9;
262
+ for ( $i = 1; $i <= 9; $i ++ ) {
263
+ $id = "extended-categories-$i";
264
+ $name = sprintf( __('Extended Categories %d'), $i );
265
+ wp_register_sidebar_widget( $id, $name, $i <= $number ? 'widget_extended_categories' : /* unregister */ '', array ( 'classname'=>'widget_extended_categories_init'), $i );
266
+ wp_register_widget_control( $id, $name, $i <= $number ? 'widget_extended_categories_control' : /* unregister */ '', array ( 'width'=>300, 'height'=>270), $i );
267
+ }
268
+ add_action('sidebar_admin_setup', 'widget_extended_categories_setup');
269
+ add_action('sidebar_admin_page', 'widget_extended_categories_page');
270
+ }
271
+
272
+ // Launch Widgets
273
+ widget_extended_categories_register ();
274
+ }
275
+ add_action ( 'plugins_loaded', 'widget_extended_categories_init' );
276
+
277
+ /**
278
+ * As the original wp_category_checklist doesn't support multiple lists on the same page I needed to duplicate the functions
279
+ * use by the wp_category_checklist function
280
+ *
281
+ */
282
+ /**
283
+ * Class that will display the categories
284
+ *
285
+ */
286
+ class AVH_Walker_Category_Checklist extends Walker {
287
+ var $tree_type = 'category';
288
+ var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
289
+ var $number;
290
+
291
+ function start_lvl(&$output, $depth, $args) {
292
+ $indent = str_repeat("\t", $depth);
293
+ $output .= "$indent<ul class='children'>\n";
294
+ }
295
+
296
+ function end_lvl(&$output, $depth, $args) {
297
+ $indent = str_repeat("\t", $depth);
298
+ $output .= "$indent</ul>\n";
299
+ }
300
+
301
+ function start_el(&$output, $category, $depth, $args) {
302
+ extract($args);
303
+
304
+ $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
305
+ $output .= "\n<li id='category-$category->term_id-$this->number'$class>" . '<label for="in-category-' . $category->term_id . '-' .$this->number. '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category-' . $this->number . '[]" id="in-category-' . $category->term_id . '-'.$this->number.'"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . wp_specialchars( apply_filters('the_category', $category->name )) . '</label>';
306
+ }
307
+
308
+ function end_el(&$output, $category, $depth, $args) {
309
+ $output .= "</li>\n";
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Creates the categories checklist
315
+ *
316
+ * @param int $post_id
317
+ * @param int $descendants_and_self
318
+ * @param array $selected_cats
319
+ * @param array $popular_cats
320
+ * @param int $number
321
+ */
322
+ function avh_wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $number ) {
323
+ $walker = new AVH_Walker_Category_Checklist;
324
+ $walker->number = $number;
325
+
326
+ $descendants_and_self = (int) $descendants_and_self;
327
+
328
+ $args = array();
329
+ if ( is_array( $selected_cats ) )
330
+ $args['selected_cats'] = $selected_cats;
331
+ elseif ( $post_id )
332
+ $args['selected_cats'] = wp_get_post_categories($post_id);
333
+ else
334
+ $args['selected_cats'] = array();
335
+
336
+ if ( is_array( $popular_cats ) )
337
+ $args['popular_cats'] = $popular_cats;
338
+ else
339
+ $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
340
+
341
+ if ( $descendants_and_self ) {
342
+ $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
343
+ $self = get_category( $descendants_and_self );
344
+ array_unshift( $categories, $self );
345
+ } else {
346
+ $categories = get_categories('get=all');
347
+ }
348
+
349
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
350
+ $checked_categories = array();
351
+ for ( $i = 0; isset($categories[$i]); $i++ ) {
352
+ if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
353
+ $checked_categories[] = $categories[$i];
354
+ unset($categories[$i]);
355
+ }
356
+ }
357
+
358
+ // Put checked cats on top
359
+ echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
360
+ // Then the rest of them
361
+ echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
362
+ }
363
+
364
+ ?>
widget_extended_categories.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Extended Category Widget
4
  Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  Description: Replacement of the category widget to allow for greater customization of the category widget.
6
- Version: 1.5.1
7
  Author: Peter van der Does
8
  Author URI: http://blog.avirtualhome.com/
9
 
@@ -24,364 +24,12 @@ along with this program; if not, write to the Free Software
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
- function widget_extended_categories_init() {
28
- // Widgets exists?
29
- if (! function_exists ( 'wp_register_sidebar_widget' ) || ! function_exists ( 'wp_register_widget_control' )) {
30
- return;
31
- }
32
-
33
- function widget_extended_categories($args, $number = 1) {
34
- $version = '1.5.1';
35
- // Check for version
36
- require (ABSPATH . WPINC . '/version.php');
37
- if ( version_compare($wp_version, '2.5.1', '<') ) {
38
- $avh_extcat_canselectcats=false;
39
- } else {
40
- $avh_extcat_canselectcats=true;
41
- }
42
- extract ( $args );
43
- $options = get_option ( 'widget_extended_categories' );
44
- $c = $options [$number]['count'] ? '1' : '0';
45
- $h = $options [$number]['hierarchical'] ? '1' : '0';
46
- $e = $options [$number]['hide_empty'] ? '1' : '0';
47
- $s = $options [$number]['sort_column'] ? $options [$number]['sort_column'] : 'name';
48
- $o = $options [$number]['sort_order'] ? $options [$number]['sort_order'] : 'asc';
49
- $r = $options [$number]['rssfeed'] ? 'RSS' : '';
50
- $i = $options [$number]['rssimage'] ? $options [$number]['rssimage'] : '';
51
- if (empty($r)) {
52
- $i='';
53
- }
54
- if (!empty($i)){
55
- if (! file_exists(ABSPATH . '/'. $i)) {
56
- $i='';
57
- }
58
- }
59
- $title = empty ( $options [$number]['title'] ) ? __ ( 'Categories' ) : attribute_escape($options [$number]['title']);
60
- $style = empty ( $options [$number]['style'] ) ? 'list' : $options [$number]['style'];
61
- if ($avh_extcat_canselectcats) {
62
- if ($options [$number]['post_category']) {
63
- $post_category = unserialize ( $options [$number]['post_category'] );
64
- $included_cats = implode ( ",", $post_category );
65
- }
66
- $cat_args = array (
67
- 'include' => $included_cats,
68
- 'orderby' => $s,
69
- 'order' => $o,
70
- 'show_count' => $c,
71
- 'hide_empty' => $e,
72
- 'hierarchical' => $h,
73
- 'title_li' => '',
74
- 'show_option_none' => __ ( 'Select Category' ),
75
- 'feed' => $r,
76
- 'feed_image' => $i,
77
- 'name' => 'ec-cat-'.$number );
78
- } else {
79
- $cat_args = array (
80
- 'orderby' => $s,
81
- 'order' => $o,
82
- 'show_count' => $c,
83
- 'hide_empty' => $e,
84
- 'hierarchical' => $h,
85
- 'title_li' => '',
86
- 'show_option_none' => __ ( 'Select Category' ),
87
- 'feed' => $r,
88
- 'feed_image' => $i,
89
- 'name' => 'ec-cat-'.$number);
90
- }
91
- echo $before_widget;
92
- echo '<!-- AVH Extended Categories version ' . $version .' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
93
- echo $before_title . $title . $after_title;
94
- echo '<ul>';
95
-
96
- if ($style == 'list') {
97
- wp_list_categories ( $cat_args );
98
- } else {
99
- wp_dropdown_categories ( $cat_args );
100
- ?>
101
- <script lang='javascript'><!--
102
- var ec_dropdown_<?php echo ($number); ?> = document.getElementById('ec-cat-<?php echo ($number); ?>');
103
- function ec_onCatChange_<?php echo ($number); ?>() {
104
- if ( ec_dropdown_<?php echo ($number); ?>.options[ec_dropdown_<?php echo ($number); ?>.selectedIndex].value > 0 ) {
105
- location.href = "<?php echo get_option ( 'home' ); ?>/?cat="+ec_dropdown_<?php echo ($number); ?>.options[ec_dropdown_<?php echo ($number); ?>.selectedIndex].value;
106
- }
107
- }
108
- ec_dropdown_<?php echo ($number); ?>.onchange = ec_onCatChange_<?php echo ($number); ?>;
109
- --></script>
110
- <?php
111
- }
112
- echo '</ul>';
113
- echo $after_widget;
114
- }
115
-
116
- function widget_extended_categories_control($number = 1) {
117
- // Check for version
118
- require (ABSPATH . WPINC . '/version.php');
119
- if ( version_compare($wp_version, '2.5.1', '<') ) {
120
- $avh_extcat_canselectcats=false;
121
- } else {
122
- $avh_extcat_canselectcats=true;
123
- }
124
- // Get actual options
125
- $options = $newoptions = get_option ( 'widget_extended_categories' );
126
- if (! is_array ( $options )) {
127
- $options = $newoptions = array ( );
128
- }
129
- // Post to new options array
130
-
131
- if ($_POST ['categories-submit-' . $number]) {
132
- $newoptions [$number]['title'] = strip_tags ( stripslashes ( $_POST ['categories-title-' . $number] ) );
133
- $newoptions [$number]['count'] = isset ( $_POST ['categories-count-' . $number] );
134
- $newoptions [$number]['hierarchical'] = isset ( $_POST ['categories-hierarchical-' . $number] );
135
- $newoptions [$number]['hide_empty'] = isset ( $_POST ['categories-hide_empty-' . $number] );
136
- $newoptions [$number]['sort_column'] = strip_tags ( stripslashes ( $_POST ['categories-sort_column-' . $number] ) );
137
- $newoptions [$number]['sort_order'] = strip_tags ( stripslashes ( $_POST ['categories-sort_order-' . $number] ) );
138
- $newoptions [$number]['style'] = strip_tags ( stripslashes ( $_POST ['categories-style-' . $number] ) );
139
- $newoptions [$number]['rssfeed'] = isset ( $_POST ['categories-rssfeed-' . $number] );
140
- $newoptions [$number]['rssimage'] = attribute_escape ( $_POST ['categories-rssimage-' . $number] );
141
- if ($avh_extcat_canselectcats) {
142
- if (in_array ( '-1', $_POST ['post_category-' . $number], true )) {
143
- $newoptions [$number]['post_category'] = false;
144
- } else {
145
- $newoptions [$number]['post_category'] = serialize ( $_POST ['post_category-' . $number] );
146
- }
147
- }
148
-
149
- }
150
-
151
- // Update if new options
152
- if ($options != $newoptions) {
153
- $options = $newoptions;
154
- update_option ( 'widget_extended_categories', $options );
155
- }
156
-
157
- // Prepare data for display
158
- $title = htmlspecialchars ( $options [$number]['title'], ENT_QUOTES );
159
- $count = $options [$number]['count'] ? 'checked="checked"' : '';
160
- $hierarchical = $options [$number]['hierarchical'] ? 'checked="checked"' : '';
161
- $hide_empty = $options [$number]['hide_empty'] ? 'checked="checked"' : '';
162
- $sort_id = ($options [$number]['sort_column'] == 'ID') ? ' SELECTED' : '';
163
- $sort_name = ($options [$number]['sort_column'] == 'name') ? ' SELECTED' : '';
164
- $sort_count = ($options [$number]['sort_column'] == 'count') ? ' SELECTED' : '';
165
- $sort_order_a = ($options [$number]['sort_order'] == 'asc') ? ' SELECTED' : '';
166
- $sort_order_d = ($options [$number]['sort_order'] == 'desc') ? ' SELECTED' : '';
167
- $style_list = ($options [$number]['style'] == 'list') ? ' SELECTED' : '';
168
- $style_drop = ($options [$number]['style'] == 'drop') ? ' SELECTED' : '';
169
- $rssfeed = $options [$number]['rssfeed'] ? 'checked="checked"' : '';
170
- $rssimage = htmlspecialchars ( $options [$number]['rssimage'], ENT_QUOTES );
171
- if ($avh_extcat_canselectcats) {
172
- $selected_cats = ($options [$number]['post_category'] != '') ? unserialize ( $options [$number]['post_category'] ) : false;
173
- }
174
- ?>
175
- <div>
176
- <label for="categories-title-<?php echo $number; ?>"><?php _e ( 'Title:' ); ?>
177
- <input style="width: 250px;" id="categories-title-<?php echo $number; ?>" name="categories-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
178
- </label>
179
-
180
- <label for="categories-count-<?php echo $number; ?>" style="line-height: 35px; display: block;">Show post counts
181
- <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count-<?php echo $number; ?>" name="categories-count-<?php echo $number; ?>" />
182
- </label>
183
-
184
- <label for="categories-hierarchical" style="line-height: 35px; display: block;">Show hierarchy
185
- <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical-<?php echo $number; ?>" name="categories-hierarchical-<?php echo $number; ?>" />
186
- </label>
187
-
188
- <label for="categories-hide_empty-<?php echo $number; ?>" style="line-height: 35px; display: block;">Hide empty categories
189
- <input class="checkbox" type="checkbox" <?php echo $hide_empty; ?> id="categories-hide_empty-<?php echo $number; ?>" name="categories-hide_empty-<?php echo $number; ?>" />
190
- </label>
191
-
192
- <label for="categories-sort_column-<?php echo $number; ?>" style="line-height: 35px; display: block;">Sort by
193
- <select id="categories-sort_column-<?php echo $number; ?>" name="categories-sort_column-<?php echo $number; ?>">
194
- <option value="ID" <?php echo $sort_id?>>ID</option>
195
- <option value="name" <?php echo $sort_name?>>Name</option>
196
- <option value="count" <?php echo $sort_count?>>Count</option>
197
- </select>
198
- </label>
199
-
200
- <label for="categories-sort_order-<?php echo $number; ?>" style="line-height: 35px; display: block;">Sort order
201
- <select id="categories-sort_order-<?php echo $number; ?>" name="categories-sort_order-<?php echo $number; ?>">
202
- <option value="asc" <?php echo $sort_order_a?>>Ascending</option>
203
- <option value="desc" <?php echo $sort_order_d?>>Descending</option>
204
- </select>
205
- </label>
206
-
207
- <label for="categories-style-<?php echo $number; ?>" style="line-height: 35px; display: block;">Display style
208
- <select id="categories-style-<?php echo $number; ?>" name="categories-style-<?php echo $number; ?>">
209
- <option value='list' <?php echo $style_list; ?>>List</option>
210
- <option value='drop' <?php echo $style_drop; ?>>Drop down</option>
211
- </select>
212
- </label>
213
-
214
- <label for="categories-rssfeed-<?php echo $number; ?>" style="line-height: 35px; display: block;">Show RSS Feed
215
- <input class="checkbox" type="checkbox" <?php echo $rssfeed; ?> id="categories-rssfeed-<?php echo $number; ?>" name="categories-rssfeed-<?php echo $number; ?>" />
216
- </label>
217
-
218
- <label for="categories-rssimage-<?php echo $number; ?>"><?php _e ( 'Full path to RSS image:' ); ?>
219
- <input style="width: 250px;" id="categories-rssimage-<?php echo $number; ?>" name="categories-rssimage-<?php echo $number; ?>" type="text" value="<?php echo $rssimage; ?>" />
220
- </label>
221
-
222
- <?php
223
- if ($avh_extcat_canselectcats) {
224
- echo ' <b>Include these categories</b><hr />';
225
- echo ' <ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
226
- echo ' <li id="category--1-'.$number.'" class="popular-category">';
227
- echo ' <label for="in-category--1-'.$number.'" class="selectit">';
228
- echo ' <input value="-1" name="post_category-'.$number.'[]" id="in-category--1-'.$number.'" type="checkbox"';
229
- if (!$selected_cats) { echo 'checked'; }
230
- echo '> Include All Categories';
231
- echo ' </label>';
232
- echo ' </li>';
233
- avh_wp_category_checklist(0,0,$selected_cats,false,$number);
234
- echo ' </ul>';
235
- }
236
- ?>
237
-
238
- <input type="hidden" id="categories-submit-<?php echo $number; ?>" name="categories-submit-<?php echo $number; ?>" value="1" /></div>
239
- <?php
240
- }
241
- /**
242
- * Called after the widget_extended_categories_page form has been submitted.
243
- * Set the amount of widgets wanted and register the widgets
244
- *
245
- */
246
- function widget_extended_categories_setup() {
247
- $options = $newoptions = get_option('widget_extended_categories');
248
- if ( isset($_POST['extended_categories-number-submit']) ) {
249
- $number = (int) $_POST['extended_categories-number'];
250
- if ( $number > 9 ) $number = 9;
251
- if ( $number < 1 ) $number = 1;
252
- $newoptions['number'] = $number;
253
- }
254
- if ( $options != $newoptions ) {
255
- $options = $newoptions;
256
- update_option('widget_extended_categories', $options);
257
- widget_extended_categories_register($options['number']);
258
- }
259
- }
260
- /**
261
- * How many Wish List widgets are wanted.
262
- *
263
- */
264
- function widget_extended_categories_page() {
265
- $options = get_option('widget_extended_categories');
266
- ?>
267
- <div class="wrap">
268
- <form method="post">
269
- <h2><?php _e('AVH Extended Categories Widgets', 'avhextendedcategories'); ?></h2>
270
- <p style="line-height: 30px;"><?php _e('How many wishlist widgets would you like?', 'avhextendedcategories'); ?>
271
- <select id="extended_categories-number" name="extended_categories-number" value="<?php echo $options['number']; ?>">
272
- <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?>
273
- </select>
274
- <span class="submit"><input type="submit" name="extended_categories-number-submit" id="extended_categories-number-submit" value="<?php echo attribute_escape(__('Save', 'avhextendedcategories')); ?>" /></span></p>
275
- </form>
276
- </div>
277
- <?php
278
- }
279
- function widget_extended_categories_register() {
280
- $options = get_option( 'widget_extended_categories' );
281
-
282
- $number = ( int ) $options['number'];
283
- if ( $number < 1 ) $number = 1;
284
- if ( $number > 9 ) $number = 9;
285
- for ( $i = 1; $i <= 9; $i ++ ) {
286
- $id = "extended-categories-$i";
287
- $name = sprintf( __('Extended Categories %d'), $i );
288
- wp_register_sidebar_widget( $id, $name, $i <= $number ? 'widget_extended_categories' : /* unregister */ '', array ( 'classname'=>'widget_extended_categories_init'), $i );
289
- wp_register_widget_control( $id, $name, $i <= $number ? 'widget_extended_categories_control' : /* unregister */ '', array ( 'width'=>300, 'height'=>270), $i );
290
- }
291
- add_action('sidebar_admin_setup', 'widget_extended_categories_setup');
292
- add_action('sidebar_admin_page', 'widget_extended_categories_page');
293
- }
294
-
295
- // Launch Widgets
296
- widget_extended_categories_register ();
297
- }
298
- add_action ( 'plugins_loaded', 'widget_extended_categories_init' );
299
 
300
- /**
301
- * As the original wp_category_checklist doesn't support multiple lists on the same page I needed to duplicate the functions
302
- * use by the wp_category_checklist function
303
- *
304
- */
305
- /**
306
- * Class that will display the categories
307
- *
308
- */
309
- class AVH_Walker_Category_Checklist extends Walker {
310
- var $tree_type = 'category';
311
- var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
312
- var $number;
313
-
314
- function start_lvl(&$output, $depth, $args) {
315
- $indent = str_repeat("\t", $depth);
316
- $output .= "$indent<ul class='children'>\n";
317
- }
318
-
319
- function end_lvl(&$output, $depth, $args) {
320
- $indent = str_repeat("\t", $depth);
321
- $output .= "$indent</ul>\n";
322
- }
323
-
324
- function start_el(&$output, $category, $depth, $args) {
325
- extract($args);
326
-
327
- $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
328
- $output .= "\n<li id='category-$category->term_id-$this->number'$class>" . '<label for="in-category-' . $category->term_id . '-' .$this->number. '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category-' . $this->number . '[]" id="in-category-' . $category->term_id . '-'.$this->number.'"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . wp_specialchars( apply_filters('the_category', $category->name )) . '</label>';
329
- }
330
-
331
- function end_el(&$output, $category, $depth, $args) {
332
- $output .= "</li>\n";
333
- }
334
  }
335
-
336
- /**
337
- * Creates the categories checklist
338
- *
339
- * @param int $post_id
340
- * @param int $descendants_and_self
341
- * @param array $selected_cats
342
- * @param array $popular_cats
343
- * @param int $number
344
- */
345
- function avh_wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $number ) {
346
- $walker = new AVH_Walker_Category_Checklist;
347
- $walker->number = $number;
348
-
349
- $descendants_and_self = (int) $descendants_and_self;
350
-
351
- $args = array();
352
- if ( is_array( $selected_cats ) )
353
- $args['selected_cats'] = $selected_cats;
354
- elseif ( $post_id )
355
- $args['selected_cats'] = wp_get_post_categories($post_id);
356
- else
357
- $args['selected_cats'] = array();
358
-
359
- if ( is_array( $popular_cats ) )
360
- $args['popular_cats'] = $popular_cats;
361
- else
362
- $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
363
-
364
- if ( $descendants_and_self ) {
365
- $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
366
- $self = get_category( $descendants_and_self );
367
- array_unshift( $categories, $self );
368
- } else {
369
- $categories = get_categories('get=all');
370
- }
371
-
372
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
373
- $checked_categories = array();
374
- for ( $i = 0; isset($categories[$i]); $i++ ) {
375
- if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
376
- $checked_categories[] = $categories[$i];
377
- unset($categories[$i]);
378
- }
379
- }
380
-
381
- // Put checked cats on top
382
- echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
383
- // Then the rest of them
384
- echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
385
- }
386
-
387
- ?>
3
  Plugin Name: Extended Category Widget
4
  Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  Description: Replacement of the category widget to allow for greater customization of the category widget.
6
+ Version: 2.0
7
  Author: Peter van der Does
8
  Author URI: http://blog.avirtualhome.com/
9
 
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
+ // Include WordPress version
28
+ require (ABSPATH . WPINC . '/version.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ if ( ( float ) $wp_version >= 2.8 ) {
31
+ require (dirname ( __FILE__ ) . '/2.8/avh-ec.client.php');
32
+ } else {
33
+ require_once 'widget-pre2.8.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
+ ?>