Make WordPress Core

Changeset 11094


Ignore:
Timestamp:
04/27/2009 09:28:57 AM (17 years ago)
Author:
azaozz
Message:

Move Tag Cloud widget to WP_Widget, see #8441

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-widgets.php

    r11093 r11094  
    332332                $title = strip_tags($instance['title']);
    333333?>
    334                         <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>
     334                <p><label for="<?php echo $this->get_field_id('title'); ?>">
     335                <?php _e('Title:'); ?>
     336                <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); ?>" />
     337                </label></p>
    335338<?php
    336339        }
    … …  
    377380                $text = format_to_edit($instance['text']);
    378381?>
    379                         <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>
    380                         <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>
    381                         <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>
     382                <p><label for="<?php echo $this->get_field_id('title'); ?>">
     383                <?php _e('Title:'); ?>
     384                <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); ?>" />
     385                </label></p>
     386
     387                <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>
     388
     389                <p><label for="<?php echo $this->get_field_id('filter'); ?>">
     390                <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.') ?>
     391                </label></p>
    382392<?php
    383393        }
    … …  
    430440?>
    431441                <ul>
    432                 <?php
    433                         $cat_args['title_li'] = '';
    434                         wp_list_categories($cat_args);
    435                 ?>
     442<?php
     443                $cat_args['title_li'] = '';
     444                wp_list_categories($cat_args);
     445?>
    436446                </ul>
    437447<?php
    … …  
    459469                $dropdown = (bool) $instance['dropdown'];
    460470?>
    461                         <p>
    462                                 <label for="<?php echo $this->get_field_id('title'); ?>">
    463                                         <?php _e( 'Title:' ); ?>
    464                                         <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; ?>" />
    465                                 </label>
    466                         </p>
    467 
    468                         <p>
    469                                 <label for="<?php echo $this->get_field_id('dropdown'); ?>">
    470                                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
    471                                         <?php _e( 'Show as dropdown' ); ?>
    472                                 </label>
    473                                 <br />
    474                                 <label for="<?php echo $this->get_field_id('count'); ?>">
    475                                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
    476                                         <?php _e( 'Show post counts' ); ?>
    477                                 </label>
    478                                 <br />
    479                                 <label for="<?php echo $this->get_field_id('hierarchical'); ?>">
    480                                         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
    481                                         <?php _e( 'Show hierarchy' ); ?>
    482                                 </label>
    483                         </p>
     471                <p><label for="<?php echo $this->get_field_id('title'); ?>">
     472                <?php _e( 'Title:' ); ?>
     473                <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; ?>" />
     474                </label></p>
     475
     476                <p><label for="<?php echo $this->get_field_id('dropdown'); ?>">
     477                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
     478                <?php _e( 'Show as dropdown' ); ?>
     479                </label><br />
     480
     481                <label for="<?php echo $this->get_field_id('count'); ?>">
     482                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
     483                <?php _e( 'Show post counts' ); ?>
     484                </label><br />
     485
     486                <label for="<?php echo $this->get_field_id('hierarchical'); ?>">
     487                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
     488                <?php _e( 'Show hierarchy' ); ?>
     489                </label></p>
    484490<?php
    485491        }
    … …  
    527533                if ($r->have_posts()) :
    528534?>
    529                         <?php echo $before_widget; ?>
    530                         <?php echo $before_title . $title . $after_title; ?>
    531                         <ul>
    532                         <?php  while ($r->have_posts()) : $r->the_post(); ?>
    533                         <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
    534                         <?php endwhile; ?>
    535                         </ul>
    536                         <?php echo $after_widget; ?>
     535                <?php echo $before_widget; ?>
     536                <?php echo $before_title . $title . $after_title; ?>
     537                <ul>
     538                <?php  while ($r->have_posts()) : $r->the_post(); ?>
     539                <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
     540                <?php endwhile; ?>
     541                </ul>
     542                <?php echo $after_widget; ?>
    537543<?php
    538544                        wp_reset_query();  // Restore global post data stomped by the_post().
    … …  
    565571                        $number = 5;
    566572?>
    567         <p><label for="<?php echo $this->get_field_id('title'); ?>">
    568         <?php _e('Title:'); ?>
    569         <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></p>
    570 
    571         <p><label for="<?php echo $this->get_field_id('number'); ?>">
    572         <?php _e('Number of posts to show:'); ?>
    573         <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" /></label>
    574         <br /><small><?php _e('(at most 15)'); ?></small></p>
     573                <p><label for="<?php echo $this->get_field_id('title'); ?>">
     574                <?php _e('Title:'); ?>
     575                <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></p>
     576
     577                <p><label for="<?php echo $this->get_field_id('number'); ?>">
     578                <?php _e('Number of posts to show:'); ?>
     579                <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" /></label>
     580                <br /><small><?php _e('(at most 15)'); ?></small></p>
    575581<?php
    576582        }
    … …  
    652658                        $number = 5;
    653659?>
    654         <p><label for="<?php echo $this->get_field_id('title'); ?>">
    655         <?php _e('Title:'); ?>
    656         <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></p>
    657 
    658         <p><label for="<?php echo $this->get_field_id('number'); ?>">
    659         <?php _e('Number of comments to show:'); ?>
    660         <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" /></label>
    661         <br /><small><?php _e('(at most 15)'); ?></small></p>
     660                <p><label for="<?php echo $this->get_field_id('title'); ?>">
     661                <?php _e('Title:'); ?>
     662                <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></p>
     663
     664                <p><label for="<?php echo $this->get_field_id('number'); ?>">
     665                <?php _e('Number of comments to show:'); ?>
     666                <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" /></label>
     667                <br /><small><?php _e('(at most 15)'); ?></small></p>
    662668<?php
    663669        }
    … …  
    860866        if ( $inputs['url'] ) :
    861867?>
    862         <p>
    863                 <label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?>
    864                         <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" />
    865                 </label>
    866         </p>
     868        <p><label for="rss-url-<?php echo $number; ?>">
     869        <?php _e('Enter the RSS feed URL here:'); ?>
     870        <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" />
     871        </label></p>
    867872<?php endif; if ( $inputs['title'] ) : ?>
    868         <p>
    869                 <label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?>
    870                         <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
    871                 </label>
    872         </p>
     873        <p><label for="rss-title-<?php echo $number; ?>">
     874        <?php _e('Give the feed a title (optional):'); ?>
     875        <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
     876        </label></p>
    873877<?php endif; if ( $inputs['items'] ) : ?>
    874         <p>
    875                 <label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?>
    876                         <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
    877                                 <?php
    878                                         for ( $i = 1; $i <= 20; ++$i )
    879                                                 echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
    880                                 ?>
    881                         </select>
    882                 </label>
    883         </p>
     878        <p><label for="rss-items-<?php echo $number; ?>">
     879        <?php _e('How many items would you like to display?'); ?>
     880        <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
     881<?php
     882                for ( $i = 1; $i <= 20; ++$i )
     883                        echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
     884?>
     885        </select>
     886        </label></p>
    884887<?php endif; if ( $inputs['show_summary'] ) : ?>
    885         <p>
    886                 <label for="rss-show-summary-<?php echo $number; ?>">
    887                         <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"'; ?>/>
    888                         <?php _e('Display item content?'); ?>
    889                 </label>
    890         </p>
     888        <p><label for="rss-show-summary-<?php echo $number; ?>">
     889        <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"'; ?>/>
     890        <?php _e('Display item content?'); ?>
     891        </label></p>
    891892<?php endif; if ( $inputs['show_author'] ) : ?>
    892         <p>
    893                 <label for="rss-show-author-<?php echo $number; ?>">
    894                         <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"'; ?>/>
    895                         <?php _e('Display item author if available?'); ?>
    896                 </label>
    897         </p>
     893        <p><label for="rss-show-author-<?php echo $number; ?>">
     894        <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"'; ?>/>
     895        <?php _e('Display item author if available?'); ?>
     896        </label></p>
    898897<?php endif; if ( $inputs['show_date'] ) : ?>
    899         <p>
    900                 <label for="rss-show-date-<?php echo $number; ?>">
    901                         <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"'; ?>/>
    902                         <?php _e('Display item date?'); ?>
    903                 </label>
    904         </p>
     898        <p><label for="rss-show-date-<?php echo $number; ?>">
     899        <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"'; ?>/>
     900        <?php _e('Display item date?'); ?>
     901        </label></p>
    905902<?php
    906903        endif;
    … …  
    957954}
    958955
    959 
    960 
    961 /**
    962  * Display tag cloud widget.
    963  *
    964  * @since 2.3.0
    965  *
    966  * @param array $args Widget arguments.
    967  */
    968 function wp_widget_tag_cloud($args) {
    969         extract($args);
    970         $options = get_option('widget_tag_cloud');
    971         $title = empty($options['title']) ? __('Tags') : apply_filters('widget_title', $options['title']);
    972 
    973         echo $before_widget;
    974         echo $before_title . $title . $after_title;
    975         wp_tag_cloud();
    976         echo $after_widget;
    977 }
    978 
    979 /**
    980  * Manage WordPress Tag Cloud widget options.
    981  *
    982  * Displays management form for changing the tag cloud widget title.
    983  *
    984  * @since 2.3.0
    985  */
    986 function wp_widget_tag_cloud_control() {
    987         $options = $newoptions = get_option('widget_tag_cloud');
    988 
    989         if ( isset($_POST['tag-cloud-submit']) ) {
    990                 $newoptions['title'] = strip_tags(stripslashes($_POST['tag-cloud-title']));
    991         }
    992 
    993         if ( $options != $newoptions ) {
    994                 $options = $newoptions;
    995                 update_option('widget_tag_cloud', $options);
    996         }
    997 
    998         $title = attribute_escape( $options['title'] );
    999 ?>
    1000         <p><label for="tag-cloud-title">
    1001         <?php _e('Title:') ?> <input type="text" class="widefat" id="tag-cloud-title" name="tag-cloud-title" value="<?php echo $title ?>" /></label>
    1002         </p>
    1003         <input type="hidden" name="tag-cloud-submit" id="tag-cloud-submit" value="1" />
    1004 <?php
     956/**
     957 * Tag cloud widget class
     958 *
     959 * @since 2.8.0
     960 */
     961class WP_Widget_Tag_Cloud extends WP_Widget {
     962
     963        function WP_Widget_Tag_Cloud() {
     964                $widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
     965                $this->WP_Widget('tag_cloud', __('Tag Cloud'), $widget_ops);
     966        }
     967
     968        function widget( $args, $instance ) {
     969                extract($args);
     970                $title = empty($instance['title']) ? __('Tags') : apply_filters('widget_title', $instance['title']);
     971
     972                echo $before_widget;
     973                echo $before_title . $title . $after_title;
     974                wp_tag_cloud();
     975                echo $after_widget;
     976        }
     977
     978        function update( $new_instance, $old_instance ) {
     979                $instance['title'] = strip_tags(stripslashes($new_instance['title']));
     980                return $instance;
     981        }
     982
     983        function form( $instance ) {
     984?>
     985        <p><label for="<?php echo $this->get_field_id('title'); ?>">
     986        <?php _e('Title:') ?>
     987        <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'] ); ?>" />
     988        </label></p>
     989<?php
     990        }
    1005991}
    1006992
    … …  
    10391025        register_widget('WP_Widget_RSS');
    10401026
    1041         $widget_ops = array('classname' => 'widget_tag_cloud', 'description' => __( "Your most used tags in cloud format") );
    1042         wp_register_sidebar_widget('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud', $widget_ops);
    1043         wp_register_widget_control('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud_control' );
     1027        register_widget('WP_Widget_Tag_Cloud');
    10441028
    10451029        do_action('widgets_init');
Note: See TracChangeset for help on using the changeset viewer.