Move Tag Cloud widget to WP_Widget, see #8441

git-svn-id: http://svn.automattic.com/wordpress/trunk@11094 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-04-27 09:28:57 +00:00
parent 7ee6f89719
commit e1dbca4f8a

View File

@ -331,7 +331,10 @@ class WP_Widget_Calendar extends WP_Widget {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
?> ?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> <p><label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
</label></p>
<?php <?php
} }
} }
@ -376,9 +379,16 @@ class WP_Widget_Text extends WP_Widget {
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
$text = format_to_edit($instance['text']); $text = format_to_edit($instance['text']);
?> ?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> <p><label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
</label></p>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea> <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
<p><label for="<?php echo $this->get_field_id('filter'); ?>"><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked($instance['filter']); ?> />&nbsp;<?php _e('Automatically add paragraphs.') ?></label></p>
<p><label for="<?php echo $this->get_field_id('filter'); ?>">
<input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked($instance['filter']); ?> />&nbsp;<?php _e('Automatically add paragraphs.') ?>
</label></p>
<?php <?php
} }
} }
@ -458,29 +468,25 @@ class WP_Widget_Categories extends WP_Widget {
$hierarchical = (bool) $instance['hierarchical']; $hierarchical = (bool) $instance['hierarchical'];
$dropdown = (bool) $instance['dropdown']; $dropdown = (bool) $instance['dropdown'];
?> ?>
<p> <p><label for="<?php echo $this->get_field_id('title'); ?>">
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e( 'Title:' ); ?> <?php _e( 'Title:' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label> </label></p>
</p>
<p> <p><label for="<?php echo $this->get_field_id('dropdown'); ?>">
<label for="<?php echo $this->get_field_id('dropdown'); ?>">
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> /> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
<?php _e( 'Show as dropdown' ); ?> <?php _e( 'Show as dropdown' ); ?>
</label> </label><br />
<br />
<label for="<?php echo $this->get_field_id('count'); ?>"> <label for="<?php echo $this->get_field_id('count'); ?>">
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> /> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
<?php _e( 'Show post counts' ); ?> <?php _e( 'Show post counts' ); ?>
</label> </label><br />
<br />
<label for="<?php echo $this->get_field_id('hierarchical'); ?>"> <label for="<?php echo $this->get_field_id('hierarchical'); ?>">
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> /> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
<?php _e( 'Show hierarchy' ); ?> <?php _e( 'Show hierarchy' ); ?>
</label> </label></p>
</p>
<?php <?php
} }
@ -859,49 +865,40 @@ function wp_widget_rss_form( $args, $inputs = null ) {
if ( $inputs['url'] ) : if ( $inputs['url'] ) :
?> ?>
<p> <p><label for="rss-url-<?php echo $number; ?>">
<label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?> <?php _e('Enter the RSS feed URL here:'); ?>
<input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /> <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" />
</label> </label></p>
</p>
<?php endif; if ( $inputs['title'] ) : ?> <?php endif; if ( $inputs['title'] ) : ?>
<p> <p><label for="rss-title-<?php echo $number; ?>">
<label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?> <?php _e('Give the feed a title (optional):'); ?>
<input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /> <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
</label> </label></p>
</p>
<?php endif; if ( $inputs['items'] ) : ?> <?php endif; if ( $inputs['items'] ) : ?>
<p> <p><label for="rss-items-<?php echo $number; ?>">
<label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?> <?php _e('How many items would you like to display?'); ?>
<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]"> <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
<?php <?php
for ( $i = 1; $i <= 20; ++$i ) for ( $i = 1; $i <= 20; ++$i )
echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>"; echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
?> ?>
</select> </select>
</label> </label></p>
</p>
<?php endif; if ( $inputs['show_summary'] ) : ?> <?php endif; if ( $inputs['show_summary'] ) : ?>
<p> <p><label for="rss-show-summary-<?php echo $number; ?>">
<label for="rss-show-summary-<?php echo $number; ?>">
<input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/> <input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
<?php _e('Display item content?'); ?> <?php _e('Display item content?'); ?>
</label> </label></p>
</p>
<?php endif; if ( $inputs['show_author'] ) : ?> <?php endif; if ( $inputs['show_author'] ) : ?>
<p> <p><label for="rss-show-author-<?php echo $number; ?>">
<label for="rss-show-author-<?php echo $number; ?>">
<input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/> <input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
<?php _e('Display item author if available?'); ?> <?php _e('Display item author if available?'); ?>
</label> </label></p>
</p>
<?php endif; if ( $inputs['show_date'] ) : ?> <?php endif; if ( $inputs['show_date'] ) : ?>
<p> <p><label for="rss-show-date-<?php echo $number; ?>">
<label for="rss-show-date-<?php echo $number; ?>">
<input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/> <input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
<?php _e('Display item date?'); ?> <?php _e('Display item date?'); ?>
</label> </label></p>
</p>
<?php <?php
endif; endif;
foreach ( array_keys($default_inputs) as $input ) : foreach ( array_keys($default_inputs) as $input ) :
@ -956,19 +953,21 @@ function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
} }
/** /**
* Display tag cloud widget. * Tag cloud widget class
* *
* @since 2.3.0 * @since 2.8.0
*
* @param array $args Widget arguments.
*/ */
function wp_widget_tag_cloud($args) { class WP_Widget_Tag_Cloud extends WP_Widget {
function WP_Widget_Tag_Cloud() {
$widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
$this->WP_Widget('tag_cloud', __('Tag Cloud'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args); extract($args);
$options = get_option('widget_tag_cloud'); $title = empty($instance['title']) ? __('Tags') : apply_filters('widget_title', $instance['title']);
$title = empty($options['title']) ? __('Tags') : apply_filters('widget_title', $options['title']);
echo $before_widget; echo $before_widget;
echo $before_title . $title . $after_title; echo $before_title . $title . $after_title;
@ -976,33 +975,20 @@ function wp_widget_tag_cloud($args) {
echo $after_widget; echo $after_widget;
} }
/** function update( $new_instance, $old_instance ) {
* Manage WordPress Tag Cloud widget options. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
* return $instance;
* Displays management form for changing the tag cloud widget title.
*
* @since 2.3.0
*/
function wp_widget_tag_cloud_control() {
$options = $newoptions = get_option('widget_tag_cloud');
if ( isset($_POST['tag-cloud-submit']) ) {
$newoptions['title'] = strip_tags(stripslashes($_POST['tag-cloud-title']));
} }
if ( $options != $newoptions ) { function form( $instance ) {
$options = $newoptions;
update_option('widget_tag_cloud', $options);
}
$title = attribute_escape( $options['title'] );
?> ?>
<p><label for="tag-cloud-title"> <p><label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Title:') ?> <input type="text" class="widefat" id="tag-cloud-title" name="tag-cloud-title" value="<?php echo $title ?>" /></label> <?php _e('Title:') ?>
</p> <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo attribute_escape( $instance['title'] ); ?>" />
<input type="hidden" name="tag-cloud-submit" id="tag-cloud-submit" value="1" /> </label></p>
<?php <?php
} }
}
/** /**
* Register all of the default WordPress widgets on startup. * Register all of the default WordPress widgets on startup.
@ -1038,9 +1024,7 @@ function wp_widgets_init() {
register_widget('WP_Widget_RSS'); register_widget('WP_Widget_RSS');
$widget_ops = array('classname' => 'widget_tag_cloud', 'description' => __( "Your most used tags in cloud format") ); register_widget('WP_Widget_Tag_Cloud');
wp_register_sidebar_widget('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud', $widget_ops);
wp_register_widget_control('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud_control' );
do_action('widgets_init'); do_action('widgets_init');
} }