]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-includes / widgets.php
1 <?php
2
3 /* Global Variables */
4
5 global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_styles, $wp_registered_widget_defaults;
6
7 $wp_registered_sidebars = array();
8 $wp_registered_widgets = array();
9 $wp_registered_widget_controls = array();
10 $wp_registered_widget_styles = array();
11 $wp_register_widget_defaults = false;
12
13 /* Template tags & API functions */
14
15 function register_sidebars($number = 1, $args = array()) {
16         $number = (int) $number;
17
18         if ( is_string($args) )
19                 parse_str($args, $args);
20
21         $i = 1;
22
23         while ( $i <= $number ) {
24                 $_args = $args;
25                 if ( $number > 1 ) {
26                         $_args['name'] = isset($args['name']) ? $args['name'] : sprintf(__('Sidebar %d'), $i);
27                 } else {
28                         $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
29                 }
30                 $_args['id'] = isset($args['id']) ? $args['id'] : "sidebar-$i";
31                 register_sidebar($_args);
32                 ++$i;
33         }
34 }
35
36 function register_sidebar($args = array()) {
37         global $wp_registered_sidebars;
38
39         if ( is_string($args) )
40                 parse_str($args, $args);
41
42         $i = count($wp_registered_sidebars) + 1;
43
44         $defaults = array(
45                 'name' => sprintf(__('Sidebar %d'), $i ),
46                 'id' => "sidebar-$i",
47                 'before_widget' => '<li id="%1$s" class="widget %2$s">',
48                 'after_widget' => "</li>\n",
49                 'before_title' => '<h2 class="widgettitle">',
50                 'after_title' => "</h2>\n",
51         );
52
53         $sidebar = array_merge($defaults, $args);
54
55         $wp_registered_sidebars[$sidebar['id']] = $sidebar;
56
57         return $sidebar['id'];
58 }
59
60 function unregister_sidebar( $name ) {
61         global $wp_registered_sidebars;
62
63         if ( isset( $wp_registered_sidebars[$name] ) )
64                 unset( $wp_registered_sidebars[$name] );
65 }
66
67 function register_sidebar_widget($name, $output_callback, $classname = '') {
68         // Compat
69         if ( is_array($name) ) {
70                 if ( count($name) == 3 )
71                         $name = sprintf($name[0], $name[2]);
72                 else
73                         $name = $name[0];
74         }
75
76         $id = sanitize_title($name);
77         $options = array();
78         if ( !empty($classname) && is_string($classname) )
79                 $options['classname'] = $classname;
80         $params = array_slice(func_get_args(), 2);
81         $args = array($id, $name, $output_callback, $options);
82         if ( !empty($params) )
83                 $args = array_merge($args, $params);
84
85         call_user_func_array('wp_register_sidebar_widget', $args);
86 }
87
88 function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) {
89
90         global $wp_registered_widgets, $wp_register_widget_defaults;
91
92         $id = sanitize_title($id);
93
94         if ( empty($output_callback) ) {
95                 unset($wp_registered_widgets[$id]);
96                 return;
97         }
98
99         $defaults = array('classname' => $output_callback);
100         $options = wp_parse_args($options, $defaults);
101         $widget = array(
102                 'name' => $name,
103                 'id' => $id,
104                 'callback' => $output_callback,
105                 'params' => array_slice(func_get_args(), 4)
106         );
107         $widget = array_merge($widget, $options);
108
109         if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || !$wp_register_widget_defaults) )
110                 $wp_registered_widgets[$id] = $widget;
111 }
112
113 function unregister_sidebar_widget($id) {
114         return wp_unregister_sidebar_widget($id);
115 }
116
117 function wp_unregister_sidebar_widget($id) {
118         wp_register_sidebar_widget($id, '', '');
119         wp_unregister_widget_control($id);
120 }
121
122 function register_widget_control($name, $control_callback, $width = '', $height = '') {
123         // Compat
124         if ( is_array($name) ) {
125                 if ( count($name) == 3 )
126                         $name = sprintf($name[0], $name[2]);
127                 else
128                         $name = $name[0];
129         }
130
131         $id = sanitize_title($name);
132         $options = array();
133         if ( !empty($width) )
134                 $options['width'] = $width;
135         if ( !empty($height) )
136                 $options['height'] = $height;
137         $params = array_slice(func_get_args(), 4);
138         $args = array($id, $name, $control_callback, $options);
139         if ( !empty($params) )
140                 $args = array_merge($args, $params);
141
142         call_user_func_array('wp_register_widget_control', $args);
143 }
144
145 function wp_register_widget_control($id, $name, $control_callback, $options = array()) {
146         global $wp_registered_widget_controls, $wp_register_widget_defaults;
147
148         $id = sanitize_title($id);
149
150         if ( empty($control_callback) ) {
151                 unset($wp_registered_widget_controls[$id]);
152                 return;
153         }
154
155         if ( isset($wp_registered_widget_controls[$id]) && $wp_register_widget_defaults )
156                 return;
157
158         $defaults = array('width' => 300, 'height' => 200);
159         $options = wp_parse_args($options, $defaults);
160         $options['width'] = (int) $options['width'];
161         $options['height'] = (int) $options['height'];
162         $options['width'] = $options['width'] > 90 ? $options['width'] + 60 : 360;
163         $options['height'] = $options['height'] > 60 ? $options['height'] + 40 : 240;
164
165         $widget = array(
166                 'name' => $name,
167                 'id' => $id,
168                 'callback' => $control_callback,
169                 'params' => array_slice(func_get_args(), 4)
170         );
171         $widget = array_merge($widget, $options);
172
173         $wp_registered_widget_controls[$id] = $widget;
174 }
175
176 function unregister_widget_control($id) {
177         return wp_unregister_widget_control($id);
178 }
179
180 function wp_unregister_widget_control($id) {
181         return wp_register_widget_control($id, '', '');
182 }
183
184 function dynamic_sidebar($index = 1) {
185         global $wp_registered_sidebars, $wp_registered_widgets;
186
187         if ( is_int($index) ) {
188                 $index = "sidebar-$index";
189         } else {
190                 $index = sanitize_title($index);
191                 foreach ( $wp_registered_sidebars as $key => $value ) {
192                         if ( sanitize_title($value['name']) == $index ) {
193                                 $index = $key;
194                                 break;
195                         }
196                 }
197         }
198
199         $sidebars_widgets = wp_get_sidebars_widgets();
200
201         if ( empty($wp_registered_sidebars[$index]) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
202                 return false;
203
204         $sidebar = $wp_registered_sidebars[$index];
205
206         $did_one = false;
207         foreach ( $sidebars_widgets[$index] as $id ) {
208                 $callback = $wp_registered_widgets[$id]['callback'];
209
210                 $params = array_merge(array($sidebar), (array) $wp_registered_widgets[$id]['params']);
211
212                 // Substitute HTML id and class attributes into before_widget
213                 $classname_ = '';
214                 foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
215                         if ( is_string($cn) )
216                                 $classname_ .= '_' . $cn;
217                         elseif ( is_object($cn) )
218                                 $classname_ .= '_' . get_class($cn);
219                 }
220                 $classname_ = ltrim($classname_, '_');
221                 $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
222
223                 if ( is_callable($callback) ) {
224                         call_user_func_array($callback, $params);
225                         $did_one = true;
226                 }
227         }
228
229         return $did_one;
230 }
231
232 function is_active_widget($callback) {
233         global $wp_registered_widgets;
234
235         $sidebars_widgets = wp_get_sidebars_widgets(false);
236
237         if ( is_array($sidebars_widgets) ) foreach ( $sidebars_widgets as $sidebar => $widgets )
238                 if ( is_array($widgets) ) foreach ( $widgets as $widget )
239                         if ( $wp_registered_widgets[$widget]['callback'] == $callback )
240                                 return true;
241
242         return false;
243 }
244
245 function is_dynamic_sidebar() {
246         global $wp_registered_widgets, $wp_registered_sidebars;
247         $sidebars_widgets = get_option('sidebars_widgets');
248         foreach ( $wp_registered_sidebars as $index => $sidebar ) {
249                 if ( count($sidebars_widgets[$index]) ) {
250                         foreach ( $sidebars_widgets[$index] as $widget )
251                                 if ( array_key_exists($widget, $wp_registered_widgets) )
252                                         return true;
253                 }
254         }
255         return false;
256 }
257
258 /* Internal Functions */
259
260 function wp_get_sidebars_widgets($update = true) {
261         global $wp_registered_widgets, $wp_registered_sidebars;
262
263         $sidebars_widgets = get_option('sidebars_widgets');
264         $_sidebars_widgets = array();
265
266         if ( !isset($sidebars_widgets['array_version']) )
267                 $sidebars_widgets['array_version'] = 1;
268
269         switch ( $sidebars_widgets['array_version'] ) {
270                 case 1 :
271                         foreach ( $sidebars_widgets as $index => $sidebar )
272                         if ( is_array($sidebar) )
273                         foreach ( $sidebar as $i => $name ) {
274                                 $id = strtolower($name);
275                                 if ( isset($wp_registered_widgets[$id]) ) {
276                                         $_sidebars_widgets[$index][$i] = $id;
277                                         continue;
278                                 }
279                                 $id = sanitize_title($name);
280                                 if ( isset($wp_registered_widgets[$id]) ) {
281                                         $_sidebars_widgets[$index][$i] = $id;
282                                         continue;
283                                 }
284                                 unset($_sidebars_widgets[$index][$i]);
285                         }
286                         $_sidebars_widgets['array_version'] = 2;
287                         $sidebars_widgets = $_sidebars_widgets;
288                         unset($_sidebars_widgets);
289
290                 case 2 :
291                         $sidebars = array_keys( $wp_registered_sidebars );
292                         if ( !empty( $sidebars ) ) {
293                                 // Move the known-good ones first
294                                 foreach ( $sidebars as $id ) {
295                                         if ( array_key_exists( $id, $sidebars_widgets ) ) {
296                                                 $_sidebars_widgets[$id] = $sidebars_widgets[$id];
297                                                 unset($sidebars_widgets[$id], $sidebars[$id]);
298                                         }
299                                 }
300
301                                 // Assign to each unmatched registered sidebar the first available orphan
302                                 unset( $sidebars_widgets[ 'array_version' ] );
303                                 while ( ( $sidebar = array_shift( $sidebars ) ) && $widgets = array_shift( $sidebars_widgets ) )
304                                         $_sidebars_widgets[ $sidebar ] = $widgets;
305
306                                 $_sidebars_widgets['array_version'] = 3;
307                                 $sidebars_widgets = $_sidebars_widgets;
308                                 unset($_sidebars_widgets);
309                         }
310
311                         if ( $update )
312                                 update_option('sidebars_widgets', $sidebars_widgets);
313         }
314
315         unset($sidebars_widgets['array_version']);
316
317         return $sidebars_widgets;
318 }
319
320 function wp_set_sidebars_widgets( $sidebars_widgets ) {
321         update_option( 'sidebars_widgets', $sidebars_widgets );
322 }
323
324 function wp_get_widget_defaults() {
325         global $wp_registered_sidebars;
326
327         $defaults = array();
328
329         foreach ( $wp_registered_sidebars as $index => $sidebar )
330                 $defaults[$index] = array();
331
332         return $defaults;
333 }
334
335 /* Default Widgets */
336
337 function wp_widget_pages( $args ) {
338         extract( $args );
339         $options = get_option( 'widget_pages' );
340
341         $title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title'];
342         $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
343         $exclude = empty( $options['exclude'] ) ? '' : $options['exclude'];
344
345         if ( $sortby == 'menu_order' ) {
346                 $sortby = 'menu_order, post_title';
347         }
348
349         $out = wp_list_pages( array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) );
350
351         if ( !empty( $out ) ) {
352 ?>
353         <?php echo $before_widget; ?>
354                 <?php echo $before_title . $title . $after_title; ?>
355                 <ul>
356                         <?php echo $out; ?>
357                 </ul>
358         <?php echo $after_widget; ?>
359 <?php
360         }
361 }
362
363 function wp_widget_pages_control() {
364         $options = $newoptions = get_option('widget_pages');
365         if ( $_POST['pages-submit'] ) {
366                 $newoptions['title'] = strip_tags(stripslashes($_POST['pages-title']));
367
368                 $sortby = stripslashes( $_POST['pages-sortby'] );
369
370                 if ( in_array( $sortby, array( 'post_title', 'menu_order', 'ID' ) ) ) {
371                         $newoptions['sortby'] = $sortby;
372                 } else {
373                         $newoptions['sortby'] = 'menu_order';
374                 }
375
376                 $newoptions['exclude'] = strip_tags( stripslashes( $_POST['pages-exclude'] ) );
377         }
378         if ( $options != $newoptions ) {
379                 $options = $newoptions;
380                 update_option('widget_pages', $options);
381         }
382         $title = attribute_escape($options['title']);
383         $exclude = attribute_escape( $options['exclude'] );
384 ?>
385                         <p><label for="pages-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="pages-title" name="pages-title" type="text" value="<?php echo $title; ?>" /></label></p>
386                         <p><label for="pages-sortby"><?php _e( 'Sort by:' ); ?>
387                                 <select name="pages-sortby" id="pages-sortby">
388                                         <option value="post_title"<?php selected( $options['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
389                                         <option value="menu_order"<?php selected( $options['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
390                                         <option value="ID"<?php selected( $options['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
391                                 </select></label></p>
392                         <p><label for="pages-exclude"><?php _e( 'Exclude:' ); ?> <input type="text" value="<?php echo $exclude; ?>" name="pages-exclude" id="pages-exclude" style="width: 180px;" /></label><br />
393                         <small><?php _e( 'Page IDs, separated by commas.' ); ?></small></p>
394                         <input type="hidden" id="pages-submit" name="pages-submit" value="1" />
395 <?php
396 }
397
398 function wp_widget_links($args) {
399         extract($args, EXTR_SKIP);
400         wp_list_bookmarks(array(
401                 'title_before' => $before_title, 'title_after' => $after_title,
402                 'category_before' => $before_widget, 'category_after' => $after_widget,
403                 'show_images' => true, 'class' => 'linkcat widget'
404         ));
405 }
406
407 function wp_widget_search($args) {
408         extract($args);
409 ?>
410                 <?php echo $before_widget; ?>
411                         <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
412                         <div>
413                         <input type="text" name="s" id="s" size="15" /><br />
414                         <input type="submit" value="<?php echo attribute_escape(__('Search')); ?>" />
415                         </div>
416                         </form>
417                 <?php echo $after_widget; ?>
418 <?php
419 }
420
421 function wp_widget_archives($args) {
422         extract($args);
423         $options = get_option('widget_archives');
424         $c = $options['count'] ? '1' : '0';
425         $d = $options['dropdown'] ? '1' : '0';
426         $title = empty($options['title']) ? __('Archives') : $options['title'];
427
428         echo $before_widget;
429         echo $before_title . $title . $after_title;
430
431         if($d) {
432 ?>
433                 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c"); ?> </select>
434 <?php
435         } else {
436 ?>
437                 <ul>
438                 <?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
439                 </ul>
440 <?php
441         }
442
443         echo $after_widget;
444 }
445
446 function wp_widget_archives_control() {
447         $options = $newoptions = get_option('widget_archives');
448         if ( $_POST["archives-submit"] ) {
449                 $newoptions['count'] = isset($_POST['archives-count']);
450                 $newoptions['dropdown'] = isset($_POST['archives-dropdown']);
451                 $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"]));
452         }
453         if ( $options != $newoptions ) {
454                 $options = $newoptions;
455                 update_option('widget_archives', $options);
456         }
457         $count = $options['count'] ? 'checked="checked"' : '';
458         $dropdown = $options['dropdown'] ? 'checked="checked"' : '';
459         $title = attribute_escape($options['title']);
460 ?>
461                         <p><label for="archives-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p>
462                         <p style="text-align:right;margin-right:40px;"><label for="archives-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /></label></p>
463                         <p style="text-align:right;margin-right:40px;"><label for="archives-dropdown"><?php _e('Display as a drop down'); ?> <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /></label></p>
464                         <input type="hidden" id="archives-submit" name="archives-submit" value="1" />
465 <?php
466 }
467
468 function wp_widget_meta($args) {
469         extract($args);
470         $options = get_option('widget_meta');
471         $title = empty($options['title']) ? __('Meta') : $options['title'];
472 ?>
473                 <?php echo $before_widget; ?>
474                         <?php echo $before_title . $title . $after_title; ?>
475                         <ul>
476                         <?php wp_register(); ?>
477                         <li><?php wp_loginout(); ?></li>
478                         <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
479                         <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
480                         <li><a href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
481                         <?php wp_meta(); ?>
482                         </ul>
483                 <?php echo $after_widget; ?>
484 <?php
485 }
486 function wp_widget_meta_control() {
487         $options = $newoptions = get_option('widget_meta');
488         if ( $_POST["meta-submit"] ) {
489                 $newoptions['title'] = strip_tags(stripslashes($_POST["meta-title"]));
490         }
491         if ( $options != $newoptions ) {
492                 $options = $newoptions;
493                 update_option('widget_meta', $options);
494         }
495         $title = attribute_escape($options['title']);
496 ?>
497                         <p><label for="meta-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="meta-title" name="meta-title" type="text" value="<?php echo $title; ?>" /></label></p>
498                         <input type="hidden" id="meta-submit" name="meta-submit" value="1" />
499 <?php
500 }
501
502 function wp_widget_calendar($args) {
503         extract($args);
504         $options = get_option('widget_calendar');
505         $title = $options['title'];
506         if ( empty($title) )
507                 $title = '&nbsp;';
508         echo $before_widget . $before_title . $title . $after_title;
509         echo '<div id="calendar_wrap">';
510         get_calendar();
511         echo '</div>';
512         echo $after_widget;
513 }
514 function wp_widget_calendar_control() {
515         $options = $newoptions = get_option('widget_calendar');
516         if ( $_POST["calendar-submit"] ) {
517                 $newoptions['title'] = strip_tags(stripslashes($_POST["calendar-title"]));
518         }
519         if ( $options != $newoptions ) {
520                 $options = $newoptions;
521                 update_option('widget_calendar', $options);
522         }
523         $title = attribute_escape($options['title']);
524 ?>
525                         <p><label for="calendar-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="calendar-title" name="calendar-title" type="text" value="<?php echo $title; ?>" /></label></p>
526                         <input type="hidden" id="calendar-submit" name="calendar-submit" value="1" />
527 <?php
528 }
529
530 function wp_widget_text($args, $number = 1) {
531         extract($args);
532         $options = get_option('widget_text');
533         $title = $options[$number]['title'];
534         $text = apply_filters( 'widget_text', $options[$number]['text'] );
535 ?>
536                 <?php echo $before_widget; ?>
537                         <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
538                         <div class="textwidget"><?php echo $text; ?></div>
539                 <?php echo $after_widget; ?>
540 <?php
541 }
542
543 function wp_widget_text_control($number) {
544         $options = $newoptions = get_option('widget_text');
545         if ( !is_array($options) )
546                 $options = $newoptions = array();
547         if ( $_POST["text-submit-$number"] ) {
548                 $newoptions[$number]['title'] = strip_tags(stripslashes($_POST["text-title-$number"]));
549                 $newoptions[$number]['text'] = stripslashes($_POST["text-text-$number"]);
550                 if ( !current_user_can('unfiltered_html') )
551                         $newoptions[$number]['text'] = stripslashes(wp_filter_post_kses($newoptions[$number]['text']));
552         }
553         if ( $options != $newoptions ) {
554                 $options = $newoptions;
555                 update_option('widget_text', $options);
556         }
557         $title = attribute_escape($options[$number]['title']);
558         $text = format_to_edit($options[$number]['text']);
559 ?>
560                         <input style="width: 450px;" id="text-title-<?php echo $number; ?>" name="text-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
561                         <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo $number; ?>" name="text-text-<?php echo $number; ?>"><?php echo $text; ?></textarea>
562                         <input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" />
563 <?php
564 }
565
566 function wp_widget_text_setup() {
567         $options = $newoptions = get_option('widget_text');
568         if ( isset($_POST['text-number-submit']) ) {
569                 $number = (int) $_POST['text-number'];
570                 if ( $number > 9 ) $number = 9;
571                 if ( $number < 1 ) $number = 1;
572                 $newoptions['number'] = $number;
573         }
574         if ( $options != $newoptions ) {
575                 $options = $newoptions;
576                 update_option('widget_text', $options);
577                 wp_widget_text_register($options['number']);
578         }
579 }
580
581 function wp_widget_text_page() {
582         $options = $newoptions = get_option('widget_text');
583 ?>
584         <div class="wrap">
585                 <form method="POST">
586                         <h2><?php _e('Text Widgets'); ?></h2>
587                         <p style="line-height: 30px;"><?php _e('How many text widgets would you like?'); ?>
588                         <select id="text-number" name="text-number" value="<?php echo $options['number']; ?>">
589 <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?>
590                         </select>
591                         <span class="submit"><input type="submit" name="text-number-submit" id="text-number-submit" value="<?php echo attribute_escape(__('Save')); ?>" /></span></p>
592                 </form>
593         </div>
594 <?php
595 }
596
597 function wp_widget_text_register() {
598         $options = get_option('widget_text');
599         $number = $options['number'];
600         if ( $number < 1 ) $number = 1;
601         if ( $number > 9 ) $number = 9;
602         $dims = array('width' => 460, 'height' => 350);
603         $class = array('classname' => 'widget_text');
604         for ($i = 1; $i <= 9; $i++) {
605                 $name = sprintf(__('Text %d'), $i);
606                 $id = "text-$i"; // Never never never translate an id
607                 wp_register_sidebar_widget($id, $name, $i <= $number ? 'wp_widget_text' : /* unregister */ '', $class, $i);
608                 wp_register_widget_control($id, $name, $i <= $number ? 'wp_widget_text_control' : /* unregister */ '', $dims, $i);
609         }
610         add_action('sidebar_admin_setup', 'wp_widget_text_setup');
611         add_action('sidebar_admin_page', 'wp_widget_text_page');
612 }
613
614 function wp_widget_categories($args, $number = 1) {
615         extract($args);
616         $options = get_option('widget_categories');
617
618         $c = $options[$number]['count'] ? '1' : '0';
619         $h = $options[$number]['hierarchical'] ? '1' : '0';
620         $d = $options[$number]['dropdown'] ? '1' : '0';
621
622         $title = empty($options[$number]['title']) ? __('Categories') : $options[$number]['title'];
623
624         echo $before_widget;
625         echo $before_title . $title . $after_title;
626
627         $cat_args = "orderby=name&show_count={$c}&hierarchical={$h}";
628
629         if ( $d ) {
630                 wp_dropdown_categories($cat_args . '&show_option_none= ' . __('Select Category'));
631 ?>
632
633 <script lang='javascript'><!--
634     var dropdown = document.getElementById("cat");
635     function onCatChange() {
636                 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
637                         location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
638                 }
639     }
640     dropdown.onchange = onCatChange;
641 --></script>
642
643 <?php
644         } else {
645 ?>
646                 <ul>
647                 <?php wp_list_categories($cat_args . '&title_li='); ?>
648                 </ul>
649 <?php
650         }
651
652         echo $after_widget;
653 }
654
655 function wp_widget_categories_control( $number ) {
656         $options = $newoptions = get_option('widget_categories');
657
658         if ( !is_array( $options ) ) {
659                 $options = $newoptions = get_option( 'widget_categories' );
660         }
661
662         if ( $_POST['categories-submit-' . $number] ) {
663                 $newoptions[$number]['count'] = isset($_POST['categories-count-' . $number]);
664                 $newoptions[$number]['hierarchical'] = isset($_POST['categories-hierarchical-' . $number]);
665                 $newoptions[$number]['dropdown'] = isset($_POST['categories-dropdown-' . $number]);
666                 $newoptions[$number]['title'] = strip_tags(stripslashes($_POST['categories-title-' . $number]));
667         }
668
669         if ( $options != $newoptions ) {
670                 $options = $newoptions;
671                 update_option('widget_categories', $options);
672         }
673
674         $title = attribute_escape( $options[$number]['title'] );
675 ?>
676                         <p><label for="categories-title-<?php echo $number; ?>">
677                                 <?php _e( 'Title:' ); ?> <input style="width:300px" id="categories-title-<?php echo $number; ?>" name="categories-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
678                         </label></p>
679
680                         <p><label for="categories-dropdown-<?php echo $number; ?>">
681                                 <input type="checkbox" class="checkbox" id="categories-dropdown-<?php echo $number; ?>" name="categories-dropdown-<?php echo $number; ?>"<?php echo $options[$number]['dropdown'] ? ' checked="checked"' : ''; ?> /> <?php _e( 'Show as dropdown' ); ?>
682                         </label></p>
683
684                         <p><label for="categories-count-<?php echo $number; ?>">
685                                 <input type="checkbox" class="checkbox" id="categories-count-<?php echo $number; ?>" name="categories-count-<?php echo $number; ?>"<?php echo $options[$number]['count'] ? ' checked="checked"' : ''; ?> /> <?php _e( 'Show post counts' ); ?>
686                         </label></p>
687
688                         <p><label for="categories-hierarchical-<?php echo $number; ?>">
689                                 <input type="checkbox" class="checkbox" id="categories-hierarchical-<?php echo $number; ?>" name="categories-hierarchical-<?php echo $number; ?>"<?php echo $options[$number]['hierarchical'] ? ' checked="checked"' : ''; ?> /> <?php _e( 'Show hierarchy' ); ?>
690                         </label></p>
691
692                         <input type="hidden" id="categories-submit-<?php echo $number; ?>" name="categories-submit-<?php echo $number; ?>" value="1" />
693 <?php
694 }
695
696 function wp_widget_categories_setup() {
697         $options = $newoptions = get_option( 'widget_categories' );
698
699         if ( isset( $_POST['categories-number-submit'] ) ) {
700                 $number = (int) $_POST['categories-number'];
701
702                 if ( $number > 9 ) {
703                         $number = 9;
704                 } elseif ( $number < 1 ) {
705                         $number = 1;
706                 }
707
708                 $newoptions['number'] = $number;
709         }
710
711         if ( $newoptions != $options ) {
712                 $options = $newoptions;
713                 update_option( 'widget_categories', $options );
714                 wp_widget_categories_register( $options['number'] );
715         }
716 }
717
718 function wp_widget_categories_page() {
719         $options = get_option( 'widget_categories' );
720 ?>
721         <div class="wrap">
722                 <form method="post">
723                         <h2><?php _e( 'Categories Widgets' ); ?></h2>
724                         <p style="line-height: 30px;"><?php _e( 'How many categories widgets would you like?' ); ?>
725                                 <select id="categories-number" name="categories-number" value="<?php echo attribute_escape( $options['number'] ); ?>">
726                                         <?php
727                                                 for ( $i = 1; $i < 10; $i++ ) {
728                                                         echo '<option value="' . $i . '"' . ( $i == $options['number'] ? ' selected="selected"' : '' ) . '>' . $i . "</option>\n";
729                                                 }
730                                         ?>
731                                 </select>
732                                 <span class="submit">
733                                         <input type="submit" value="<?php echo attribute_escape( __( 'Save' ) ); ?>" id="categories-number-submit" name="categories-number-submit" />
734                                 </span>
735                         </p>
736                 </form>
737         </div>
738 <?php
739 }
740
741 function wp_widget_categories_upgrade() {
742         $options = get_option( 'widget_categories' );
743
744         $newoptions = array( 'number' => 1, 1 => $options );
745
746         update_option( 'widget_categories', $newoptions );
747
748         $sidebars_widgets = get_option( 'sidebars_widgets' );
749         if ( is_array( $sidebars_widgets ) ) {
750                 foreach ( $sidebars_widgets as $sidebar => $widgets ) {
751                         if ( is_array( $widgets ) ) {
752                                 foreach ( $widgets as $widget )
753                                         $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget;
754                         } else {
755                                 $new_widgets[$sidebar] = $widgets;
756                         }
757                 }
758                 if ( $new_widgets != $sidebars_widgets )
759                         update_option( 'sidebars_widgets', $new_widgets );
760         }
761
762         if ( isset( $_POST['categories-submit'] ) ) {
763                 $_POST['categories-submit-1'] = $_POST['categories-submit'];
764                 $_POST['categories-count-1'] = $_POST['categories-count'];
765                 $_POST['categories-hierarchical-1'] = $_POST['categories-hierarchical'];
766                 $_POST['categories-dropdown-1'] = $_POST['categories-dropdown'];
767                 $_POST['categories-title-1'] = $_POST['categories-title'];
768                 foreach ( $_POST as $k => $v )
769                         if ( substr($k, -5) == 'order' )
770                                 $_POST[$k] = str_replace('categories', 'categories-1', $v);
771         }
772
773         return $newoptions;
774 }
775
776 function wp_widget_categories_register() {
777         $options = get_option( 'widget_categories' );
778         if ( !isset($options['number']) )
779                 $options = wp_widget_categories_upgrade();
780         $number = (int) $options['number'];
781
782         if ( $number > 9 ) {
783                 $number = 9;
784         } elseif ( $number < 1 ) {
785                 $number = 1;
786         }
787
788         $dims = array( 'width' => 350, 'height' => 170 );
789         $class = array( 'classname' => 'widget_categories' );
790
791         for ( $i = 1; $i <= 9; $i++ ) {
792                 $name = sprintf( __( 'Categories %d' ), $i );
793                 $id = 'categories-' . $i;
794
795                 $widget_callback = ( $i <= $number ) ? 'wp_widget_categories' : '';
796                 $control_callback = ( $i <= $number ) ? 'wp_widget_categories_control' : '';
797
798                 wp_register_sidebar_widget( $id, $name, $widget_callback, $class, $i );
799                 wp_register_widget_control( $id, $name, $control_callback, $dims, $i );
800         }
801
802         add_action( 'sidebar_admin_setup', 'wp_widget_categories_setup' );
803         add_action( 'sidebar_admin_page', 'wp_widget_categories_page' );
804 }
805
806 function wp_widget_recent_entries($args) {
807         if ( $output = wp_cache_get('widget_recent_entries') )
808                 return print($output);
809
810         ob_start();
811         extract($args);
812         $options = get_option('widget_recent_entries');
813         $title = empty($options['title']) ? __('Recent Posts') : $options['title'];
814         if ( !$number = (int) $options['number'] )
815                 $number = 10;
816         else if ( $number < 1 )
817                 $number = 1;
818         else if ( $number > 15 )
819                 $number = 15;
820
821         $r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0&post_status=publish");
822         if ($r->have_posts()) :
823 ?>
824                 <?php echo $before_widget; ?>
825                         <?php echo $before_title . $title . $after_title; ?>
826                         <ul>
827                         <?php  while ($r->have_posts()) : $r->the_post(); ?>
828                         <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
829                         <?php endwhile; ?>
830                         </ul>
831                 <?php echo $after_widget; ?>
832 <?php
833         endif;
834         wp_cache_add('widget_recent_entries', ob_get_flush());
835 }
836
837 function wp_flush_widget_recent_entries() {
838         wp_cache_delete('widget_recent_entries');
839 }
840
841 add_action('save_post', 'wp_flush_widget_recent_entries');
842 add_action('deleted_post', 'wp_flush_widget_recent_entries');
843
844 function wp_widget_recent_entries_control() {
845         $options = $newoptions = get_option('widget_recent_entries');
846         if ( $_POST["recent-entries-submit"] ) {
847                 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-entries-title"]));
848                 $newoptions['number'] = (int) $_POST["recent-entries-number"];
849         }
850         if ( $options != $newoptions ) {
851                 $options = $newoptions;
852                 update_option('widget_recent_entries', $options);
853                 wp_flush_widget_recent_entries();
854         }
855         $title = attribute_escape($options['title']);
856         if ( !$number = (int) $options['number'] )
857                 $number = 5;
858 ?>
859                         <p><label for="recent-entries-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="recent-entries-title" name="recent-entries-title" type="text" value="<?php echo $title; ?>" /></label></p>
860                         <p><label for="recent-entries-number"><?php _e('Number of posts to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-entries-number" name="recent-entries-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p>
861                         <input type="hidden" id="recent-entries-submit" name="recent-entries-submit" value="1" />
862 <?php
863 }
864
865 function wp_widget_recent_comments($args) {
866         global $wpdb, $comments, $comment;
867         extract($args, EXTR_SKIP);
868         $options = get_option('widget_recent_comments');
869         $title = empty($options['title']) ? __('Recent Comments') : $options['title'];
870         if ( !$number = (int) $options['number'] )
871                 $number = 5;
872         else if ( $number < 1 )
873                 $number = 1;
874         else if ( $number > 15 )
875                 $number = 15;
876
877         if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
878                 $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
879                 wp_cache_add( 'recent_comments', $comments, 'widget' );
880         }
881 ?>
882
883                 <?php echo $before_widget; ?>
884                         <?php echo $before_title . $title . $after_title; ?>
885                         <ul id="recentcomments"><?php
886                         if ( $comments ) : foreach ($comments as $comment) :
887                         echo  '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
888                         endforeach; endif;?></ul>
889                 <?php echo $after_widget; ?>
890 <?php
891 }
892
893 function wp_delete_recent_comments_cache() {
894         wp_cache_delete( 'recent_comments', 'widget' );
895 }
896 add_action( 'comment_post', 'wp_delete_recent_comments_cache' );
897 add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' );
898
899 function wp_widget_recent_comments_control() {
900         $options = $newoptions = get_option('widget_recent_comments');
901         if ( $_POST["recent-comments-submit"] ) {
902                 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"]));
903                 $newoptions['number'] = (int) $_POST["recent-comments-number"];
904         }
905         if ( $options != $newoptions ) {
906                 $options = $newoptions;
907                 update_option('widget_recent_comments', $options);
908                 wp_delete_recent_comments_cache();
909         }
910         $title = attribute_escape($options['title']);
911         if ( !$number = (int) $options['number'] )
912                 $number = 5;
913 ?>
914                         <p><label for="recent-comments-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="recent-comments-title" name="recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>
915                         <p><label for="recent-comments-number"><?php _e('Number of comments to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-comments-number" name="recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p>
916                         <input type="hidden" id="recent-comments-submit" name="recent-comments-submit" value="1" />
917 <?php
918 }
919
920 function wp_widget_recent_comments_style() {
921 ?>
922 <style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style>
923 <?php
924 }
925
926 function wp_widget_recent_comments_register() {
927         $dims = array('width' => 320, 'height' => 90);
928         $class = array('classname' => 'widget_recent_comments');
929         wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $class);
930         wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control', $dims);
931
932         if ( is_active_widget('wp_widget_recent_comments') )
933                 add_action('wp_head', 'wp_widget_recent_comments_style');
934 }
935
936 function wp_widget_rss($args, $number = 1) {
937         require_once(ABSPATH . WPINC . '/rss.php');
938         extract($args);
939         $options = get_option('widget_rss');
940         if ( isset($options['error']) && $options['error'] )
941                 return;
942         $num_items = (int) $options[$number]['items'];
943         $show_summary = $options[$number]['show_summary'];
944         if ( empty($num_items) || $num_items < 1 || $num_items > 10 ) $num_items = 10;
945         $url = $options[$number]['url'];
946         while ( strstr($url, 'http') != $url )
947                 $url = substr($url, 1);
948         if ( empty($url) )
949                 return;
950         $rss = fetch_rss($url);
951         $link = clean_url(strip_tags($rss->channel['link']));
952         while ( strstr($link, 'http') != $link )
953                 $link = substr($link, 1);
954         $desc = attribute_escape(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES)));
955         $title = $options[$number]['title'];
956         if ( empty($title) )
957                 $title = htmlentities(strip_tags($rss->channel['title']));
958         if ( empty($title) )
959                 $title = $desc;
960         if ( empty($title) )
961                 $title = __('Unknown Feed');
962         $url = clean_url(strip_tags($url));
963         if ( file_exists(dirname(__FILE__) . '/rss.png') )
964                 $icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png';
965         else
966                 $icon = get_option('siteurl').'/wp-includes/images/rss.png';
967         $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
968 ?>
969                 <?php echo $before_widget; ?>
970                         <?php $title ? print($before_title . $title . $after_title) : null; ?>
971 <?php
972         if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
973                 $rss->items = array_slice($rss->items, 0, $num_items);
974                 echo '<ul>';
975                 foreach ($rss->items as $item ) {
976                         while ( strstr($item['link'], 'http') != $item['link'] )
977                                 $item['link'] = substr($item['link'], 1);
978                         $link = clean_url(strip_tags($item['link']));
979                         $title = attribute_escape(strip_tags($item['title']));
980                         if ( empty($title) )
981                                 $title = __('Untitled');
982                         $desc = '';
983                         if ( $show_summary ) {
984                                 $summary = '<div class="rssSummary">' . $item['description'] . '</div>';
985                         } else {
986                                 if ( isset( $item['description'] ) && is_string( $item['description'] ) )
987                                         $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
988                                 $summary = '';
989                         }
990                         echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>$summary</li>";
991                 }
992                 echo '</ul>';
993         } else {
994                 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
995         }
996
997         echo $after_widget;
998 }
999
1000 function wp_widget_rss_control($number) {
1001         $options = $newoptions = get_option('widget_rss');
1002         if ( $_POST["rss-submit-$number"] ) {
1003                 $newoptions[$number]['items'] = (int) $_POST["rss-items-$number"];
1004                 $url = sanitize_url(strip_tags(stripslashes($_POST["rss-url-$number"])));
1005                 $newoptions[$number]['title'] = trim(strip_tags(stripslashes($_POST["rss-title-$number"])));
1006                 if ( $url !== $options[$number]['url'] ) {
1007                         require_once(ABSPATH . WPINC . '/rss.php');
1008                         $rss = fetch_rss($url);
1009                         if ( is_object($rss) ) {
1010                                 $newoptions[$number]['url'] = $url;
1011                                 $newoptions[$number]['error'] = false;
1012                         } else {
1013                                 $newoptions[$number]['error'] = true;
1014                                 $newoptions[$number]['url'] = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1);
1015                                 $error = sprintf(__('Error in RSS %1$d: %2$s'), $number, $newoptions[$number]['error']);
1016                         }
1017                 }
1018         }
1019         if ( $options != $newoptions ) {
1020                 $options = $newoptions;
1021                 update_option('widget_rss', $options);
1022         }
1023         $url = attribute_escape($options[$number]['url']);
1024         $items = (int) $options[$number]['items'];
1025         $title = attribute_escape($options[$number]['title']);
1026         if ( empty($items) || $items < 1 ) $items = 10;
1027 ?>
1028                         <p style="text-align:center;"><?php _e('Enter the RSS feed URL here:'); ?></p>
1029                         <input style="width: 400px;" id="rss-url-<?php echo "$number"; ?>" name="rss-url-<?php echo "$number"; ?>" type="text" value="<?php echo $url; ?>" />
1030                         <p style="text-align:center;"><?php _e('Give the feed a title (optional):'); ?></p>
1031                         <input style="width: 400px;" id="rss-title-<?php echo "$number"; ?>" name="rss-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" />
1032                         <p style="text-align:center; line-height: 30px;"><?php _e('How many items would you like to display?'); ?> <select id="rss-items-<?php echo $number; ?>" name="rss-items-<?php echo $number; ?>"><?php for ( $i = 1; $i <= 10; ++$i ) echo "<option value='$i' ".($items==$i ? "selected='selected'" : '').">$i</option>"; ?></select></p>
1033                         <input type="hidden" id="rss-submit-<?php echo "$number"; ?>" name="rss-submit-<?php echo "$number"; ?>" value="1" />
1034 <?php
1035 }
1036
1037 function wp_widget_rss_setup() {
1038         $options = $newoptions = get_option('widget_rss');
1039         if ( isset($_POST['rss-number-submit']) ) {
1040                 $number = (int) $_POST['rss-number'];
1041                 if ( $number > 9 ) $number = 9;
1042                 if ( $number < 1 ) $number = 1;
1043                 $newoptions['number'] = $number;
1044         }
1045         if ( $options != $newoptions ) {
1046                 $options = $newoptions;
1047                 update_option('widget_rss', $options);
1048                 wp_widget_rss_register($options['number']);
1049         }
1050 }
1051
1052 function wp_widget_rss_page() {
1053         $options = $newoptions = get_option('widget_rss');
1054 ?>
1055         <div class="wrap">
1056                 <form method="POST">
1057                         <h2><?php _e('RSS Feed Widgets'); ?></h2>
1058                         <p style="line-height: 30px;"><?php _e('How many RSS widgets would you like?'); ?>
1059                         <select id="rss-number" name="rss-number" value="<?php echo $options['number']; ?>">
1060 <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?>
1061                         </select>
1062                         <span class="submit"><input type="submit" name="rss-number-submit" id="rss-number-submit" value="<?php echo attribute_escape(__('Save')); ?>" /></span></p>
1063                 </form>
1064         </div>
1065 <?php
1066 }
1067
1068 function wp_widget_rss_register() {
1069         $options = get_option('widget_rss');
1070         $number = $options['number'];
1071         if ( $number < 1 ) $number = 1;
1072         if ( $number > 9 ) $number = 9;
1073         $dims = array('width' => 410, 'height' => 200);
1074         $class = array('classname' => 'widget_rss');
1075         for ($i = 1; $i <= 9; $i++) {
1076                 $name = sprintf(__('RSS %d'), $i);
1077                 $id = "rss-$i"; // Never never never translate an id
1078                 wp_register_sidebar_widget($id, $name, $i <= $number ? 'wp_widget_rss' : /* unregister */ '', $class, $i);
1079                 wp_register_widget_control($id, $name, $i <= $number ? 'wp_widget_rss_control' : /* unregister */ '', $dims, $i);
1080         }
1081         add_action('sidebar_admin_setup', 'wp_widget_rss_setup');
1082         add_action('sidebar_admin_page', 'wp_widget_rss_page');
1083 }
1084
1085 function wp_widget_tag_cloud($args) {
1086         extract($args);
1087         $options = get_option('widget_tag_cloud');
1088         $title = empty($options['title']) ? __('Tags') : $options['title'];
1089
1090         echo $before_widget;
1091         echo $before_title . $title . $after_title;
1092         wp_tag_cloud();
1093         echo $after_widget;
1094 }
1095
1096 function wp_widget_tag_cloud_control() {
1097         $options = $newoptions = get_option('widget_tag_cloud');
1098
1099         if ( $_POST['tag-cloud-submit'] ) {
1100                 $newoptions['title'] = strip_tags(stripslashes($_POST['tag-cloud-title']));
1101         }
1102
1103         if ( $options != $newoptions ) {
1104                 $options = $newoptions;
1105                 update_option('widget_tag_cloud', $options);
1106         }
1107
1108         $title = attribute_escape( $options['title'] );
1109 ?>
1110         <p><label for="tag-cloud-title">
1111         <?php _e('Title:') ?> <input type="text" style="width:300px" id="tag-cloud-title" name="tag-cloud-title" value="<?php echo $title ?>" /></label>
1112         </p>
1113         <input type="hidden" name="tag-cloud-submit" id="tag-cloud-submit" value="1" />
1114 <?php
1115 }
1116
1117 function wp_widgets_init() {
1118         if ( !is_blog_installed() )
1119                 return;
1120
1121         $GLOBALS['wp_register_widget_defaults'] = true;
1122
1123         $dims90 = array( 'height' => 90, 'width' => 300 );
1124         $dims100 = array( 'height' => 100, 'width' => 300 );
1125         $dims150 = array( 'height' => 150, 'width' => 300 );
1126
1127         $class = array('classname' => 'widget_pages');
1128         wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $class);
1129         wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control', $dims150);
1130
1131         $class['classname'] = 'widget_calendar';
1132         wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $class);
1133         wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control', $dims90);
1134
1135         $class['classname'] = 'widget_archives';
1136         wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $class);
1137         wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control', $dims100);
1138
1139         $class['classname'] = 'widget_links';
1140         wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $class);
1141
1142         $class['classname'] = 'widget_meta';
1143         wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $class);
1144         wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control', $dims90);
1145
1146         $class['classname'] = 'widget_search';
1147         wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $class);
1148
1149         $class['classname'] = 'widget_recent_entries';
1150         wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $class);
1151         wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control', $dims90);
1152
1153         $class['classname'] = 'widget_tag_cloud';
1154         wp_register_sidebar_widget('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud', $class);
1155         wp_register_widget_control('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud_control', 'width=300&height=160');
1156
1157         wp_widget_categories_register();
1158         wp_widget_text_register();
1159         wp_widget_rss_register();
1160         wp_widget_recent_comments_register();
1161
1162         $GLOBALS['wp_register_widget_defaults'] = false;
1163
1164         do_action('widgets_init');
1165 }
1166
1167 add_action('init', 'wp_widgets_init', 1);
1168
1169 ?>