Make WordPress Core

Changeset 10794


Ignore:
Timestamp:
03/16/2009 09:44:36 PM (16 years ago)
Author:
ryan
Message:

Move archives widget to WP_Widget. see #8441

File:
1 edited

Legend:

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

    r10789 r10794  
    10961096
    10971097/**
    1098  * Display archives widget.
    1099  *
    1100  * @since 2.2.0
    1101  *
    1102  * @param array $args Widget arguments.
    1103  */
    1104 function wp_widget_archives($args) {
    1105     extract($args);
    1106     $options = get_option('widget_archives');
    1107     $c = $options['count'] ? '1' : '0';
    1108     $d = $options['dropdown'] ? '1' : '0';
    1109     $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']);
    1110 
    1111     echo $before_widget;
    1112     echo $before_title . $title . $after_title;
    1113 
    1114     if($d) {
     1098 * Archives widget class
     1099 *
     1100 * @since 2.8.0
     1101 */
     1102class WP_Widget_Archives extends WP_Widget {
     1103
     1104    function WP_Widget_Archives() {
     1105        $widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
     1106        $this->WP_Widget('archives', __('Archives'), $widget_ops);
     1107    }
     1108
     1109    function widget( $args, $instance ) {
     1110        extract($args);
     1111        $c = $instance['count'] ? '1' : '0';
     1112        $d = $instance['dropdown'] ? '1' : '0';
     1113        $title = empty($instance['title']) ? __('Archives') : apply_filters('widget_title', $instance['title']);
     1114
     1115        echo $before_widget;
     1116        echo $before_title . $title . $after_title;
     1117
     1118        if ( $d ) {
    11151119?>
    11161120        <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>
    11171121<?php
    1118     } else {
     1122        } else {
    11191123?>
    11201124        <ul>
     
    11221126        </ul>
    11231127<?php
    1124     }
    1125 
    1126     echo $after_widget;
    1127 }
    1128 
    1129 /**
    1130  * Display and process archives widget options form.
    1131  *
    1132  * @since 2.2.0
    1133  */
    1134 function wp_widget_archives_control() {
    1135     $options = $newoptions = get_option('widget_archives');
    1136     if ( isset($_POST["archives-submit"]) ) {
    1137         $newoptions['count'] = isset($_POST['archives-count']);
    1138         $newoptions['dropdown'] = isset($_POST['archives-dropdown']);
    1139         $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"]));
    1140     }
    1141     if ( $options != $newoptions ) {
    1142         $options = $newoptions;
    1143         update_option('widget_archives', $options);
    1144     }
    1145     $count = $options['count'] ? 'checked="checked"' : '';
    1146     $dropdown = $options['dropdown'] ? 'checked="checked"' : '';
    1147     $title = attribute_escape($options['title']);
     1128        }
     1129
     1130        echo $after_widget;
     1131    }
     1132
     1133    function update( $new_instance, $old_instance ) {
     1134        if ( !isset($new_instance['submit']) ) // user clicked cancel?
     1135            return false;
     1136
     1137        $instance = $old_instance;
     1138        $instance['title'] = strip_tags($new_instance['title']);
     1139        $instance['count'] = $new_instance['count'] ? 1 : 0;
     1140        $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
     1141
     1142        return $instance;
     1143    }
     1144
     1145    function form( $instance ) {
     1146        $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
     1147        $title = strip_tags($instance['title']);
     1148        $count = $instance['count'] ? 'checked="checked"' : '';
     1149        $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
    11481150?>
    1149             <p><label for="archives-title"><?php _e('Title:'); ?> <input class="widefat" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p>
    1150             <p>
    1151                 <label for="archives-count"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /> <?php _e('Show post counts'); ?></label>
    1152                 <br />
    1153                 <label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label>
    1154             </p>
    1155             <input type="hidden" id="archives-submit" name="archives-submit" value="1" />
     1151        <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>
     1152        <p>
     1153            <label for="<?php echo $this->get_field_id('count'); ?>"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <?php _e('Show post counts'); ?></label>
     1154            <br />
     1155            <label for="<?php echo $this->get_field_id('dropdown'); ?>"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <?php _e('Display as a drop down'); ?></label>
     1156        </p>
     1157        <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
    11561158<?php
     1159    }
    11571160}
    11581161
     
    22452248    wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control' );
    22462249
    2247     $widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
    2248     wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $widget_ops);
    2249     wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control' );
     2250    new WP_Widget_Archives();
    22502251
    22512252    new WP_Widget_Links();
Note: See TracChangeset for help on using the changeset viewer.