Changeset 5717
- Timestamp:
- 06/16/2007 02:03:25 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r5708 r5717 610 610 } 611 611 612 function wp_widget_categories($args ) {612 function wp_widget_categories($args, $number = 1) { 613 613 extract($args); 614 614 $options = get_option('widget_categories'); 615 $c = $options['count'] ? '1' : '0'; 616 $h = $options['hierarchical'] ? '1' : '0'; 617 $d = $options['dropdown'] ? '1' : '0'; 618 $title = empty($options['title']) ? __('Categories') : $options['title']; 615 616 $c = $options[$number]['count'] ? '1' : '0'; 617 $h = $options[$number]['hierarchical'] ? '1' : '0'; 618 $d = $options[$number]['dropdown'] ? '1' : '0'; 619 620 $title = empty($options[$number]['title']) ? __('Categories') : $options[$number]['title']; 619 621 620 622 echo $before_widget; … … 623 625 $cat_args = "orderby=name&show_count={$c}&hierarchical={$h}"; 624 626 625 if ($d) {627 if ( $d ) { 626 628 wp_dropdown_categories($cat_args . '&show_option_none= ' . __('Select Category')); 627 629 ?> … … 649 651 } 650 652 651 function wp_widget_categories_control( ) {653 function wp_widget_categories_control( $number ) { 652 654 $options = $newoptions = get_option('widget_categories'); 653 if ( $_POST['categories-submit'] ) { 654 $newoptions['count'] = isset($_POST['categories-count']); 655 $newoptions['hierarchical'] = isset($_POST['categories-hierarchical']); 656 $newoptions['dropdown'] = isset($_POST['categories-dropdown']); 657 $newoptions['title'] = strip_tags(stripslashes($_POST['categories-title'])); 658 } 655 656 if ( !is_array( $options ) ) { 657 $options = $newoptions = get_option( 'widget_categories' ); 658 } 659 660 if ( $_POST['categories-submit-' . $number] ) { 661 $newoptions[$number]['count'] = isset($_POST['categories-count-' . $number]); 662 $newoptions[$number]['hierarchical'] = isset($_POST['categories-hierarchical-' . $number]); 663 $newoptions[$number]['dropdown'] = isset($_POST['categories-dropdown-' . $number]); 664 $newoptions[$number]['title'] = strip_tags(stripslashes($_POST['categories-title-' . $number])); 665 } 666 659 667 if ( $options != $newoptions ) { 660 668 $options = $newoptions; 661 669 update_option('widget_categories', $options); 662 670 } 663 $count = $options['count'] ? 'checked="checked"' : ''; 664 $hierarchical = $options['hierarchical'] ? 'checked="checked"' : ''; 665 $dropdown = $options['dropdown'] ? 'checked="checked"' : ''; 666 $title = attribute_escape($options['title']); 667 ?> 668 <p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" /></label></p> 669 <p style="text-align:right;margin-right:40px;"><label for="categories-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p> 670 <p style="text-align:right;margin-right:40px;"><label for="categories-hierarchical" style="text-align:right;"><?php _e('Show hierarchy'); ?> <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" /></label></p> 671 <p style="text-align:right;margin-right:40px;"><label for="categories-dropdown" style="text-align:right;"><?php _e('Display as a drop down'); ?> <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="categories-dropdown" name="categories-dropdown" /></label></p> 672 <input type="hidden" id="categories-submit" name="categories-submit" value="1" /> 673 <?php 671 672 $title = attribute_escape( $options[$number]['title'] ); 673 ?> 674 <p><label for="categories-title-<?php echo $number; ?>"> 675 <?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; ?>" /> 676 </label></p> 677 678 <p><label for="categories-dropdown-<?php echo $number; ?>"> 679 <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' ); ?> 680 </label></p> 681 682 <p><label for="categories-count-<?php echo $number; ?>"> 683 <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' ); ?> 684 </label></p> 685 686 <p><label for="categories-hierarchical-<?php echo $number; ?>"> 687 <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' ); ?> 688 </label></p> 689 690 <input type="hidden" id="categories-submit-<?php echo $number; ?>" name="categories-submit-<?php echo $number; ?>" value="1" /> 691 <?php 692 } 693 694 function wp_widget_categories_setup() { 695 $options = $newoptions = get_option( 'widget_categories' ); 696 697 if ( isset( $_POST['categories-number-submit'] ) ) { 698 $number = (int) $_POST['categories-number']; 699 700 if ( $number > 9 ) { 701 $number = 9; 702 } elseif ( $number < 1 ) { 703 $number = 1; 704 } 705 706 $newoptions['number'] = $number; 707 } 708 709 if ( $newoptions != $options ) { 710 $options = $newoptions; 711 update_option( 'widget_categories', $options ); 712 wp_widget_categories_register( $options['number'] ); 713 } 714 } 715 716 function wp_widget_categories_page() { 717 $options = get_option( 'widget_categories' ); 718 ?> 719 <div class="wrap"> 720 <form method="post"> 721 <h2><?php _e( 'Categories Widgets' ); ?></h2> 722 <p style="line-height: 30px;"><?php _e( 'How many categories widgets would you like?' ); ?> 723 <select id="categories-number" name="categories-number" value="<?php echo attribute_escape( $options['number'] ); ?>"> 724 <?php 725 for ( $i = 1; $i < 10; $i++ ) { 726 echo '<option value="' . $i . '"' . ( $i == $options['number'] ? ' selected="selected"' : '' ) . '>' . $i . "</option>\n"; 727 } 728 ?> 729 </select> 730 <span class="submit"> 731 <input type="submit" value="<?php echo attribute_escape( __( 'Save' ) ); ?>" id="categories-number-submit" name="categories-number-submit" /> 732 </span> 733 </p> 734 </form> 735 </div> 736 <?php 737 } 738 739 function wp_widget_categories_upgrade() { 740 $options = get_option( 'widget_categories' ); 741 742 $newoptions = array( 'number' => 1, 1 => $options ); 743 744 update_option( 'widget_categories', $newoptions ); 745 746 $sidebars_widgets = get_option( 'sidebars_widgets' ); 747 if ( is_array( $sidebars_widgets ) ) { 748 foreach ( $sidebars_widgets as $sidebar => $widgets ) { 749 if ( is_array( $widgets ) ) { 750 foreach ( $widgets as $widget ) 751 $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget; 752 } else { 753 $new_widgets[$sidebar] = $widgets; 754 } 755 } 756 if ( $new_widgets != $sidebars_widgets ) 757 update_option( 'sidebars_widgets', $new_widgets ); 758 } 759 760 if ( isset( $_POST['categories-submit'] ) ) { 761 $_POST['categories-submit-1'] = $_POST['categories-submit']; 762 $_POST['categories-count-1'] = $_POST['categories-count']; 763 $_POST['categories-hierarchical-1'] = $_POST['categories-hierarchical']; 764 $_POST['categories-dropdown-1'] = $_POST['categories-dropdown']; 765 $_POST['categories-title-1'] = $_POST['categories-title']; 766 foreach ( $_POST as $k => $v ) 767 if ( substr($k, -5) == 'order' ) 768 $_POST[$k] = str_replace('categories', 'categories-1', $v); 769 } 770 771 return $newoptions; 772 } 773 774 function wp_widget_categories_register() { 775 $options = get_option( 'widget_categories' ); 776 if ( !isset($options['number']) ) 777 $options = wp_widget_categories_upgrade(); 778 $number = (int) $options['number']; 779 780 if ( $number > 9 ) { 781 $number = 9; 782 } elseif ( $number < 1 ) { 783 $number = 1; 784 } 785 786 $dims = array( 'width' => 350, 'height' => 170 ); 787 $class = array( 'classname' => 'widget_catgories' ); 788 789 for ( $i = 1; $i <= 9; $i++ ) { 790 $name = sprintf( __( 'Categories %d' ), $i ); 791 $id = 'categories-' . $i; 792 793 $widget_callback = ( $i <= $number ) ? 'wp_widget_categories' : ''; 794 $control_callback = ( $i <= $number ) ? 'wp_widget_categories_control' : ''; 795 796 wp_register_sidebar_widget( $id, $name, $widget_callback, $class, $i ); 797 wp_register_widget_control( $id, $name, $control_callback, $dims, $i ); 798 } 799 800 add_action( 'sidebar_admin_setup', 'wp_widget_categories_setup' ); 801 add_action( 'sidebar_admin_page', 'wp_widget_categories_page' ); 674 802 } 675 803 … … 955 1083 956 1084 function wp_widgets_init() { 957 global $wp_register_widget_defaults;958 959 $ wp_register_widget_defaults = true;960 $dims 90 = array('height' => 90, 'width' => 300);961 $dims1 00 = array('height' => 100, 'width' => 300);962 $dims150 = array('height' => 150, 'width' => 300);1085 $GLOBALS['wp_register_widget_defaults'] = true; 1086 1087 $dims90 = array( 'height' => 90, 'width' => 300 ); 1088 $dims100 = array( 'height' => 100, 'width' => 300 ); 1089 $dims150 = array( 'height' => 150, 'width' => 300 ); 1090 963 1091 $class = array('classname' => 'widget_pages'); 964 1092 wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $class); 965 1093 wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control', $dims150); 1094 966 1095 $class['classname'] = 'widget_calendar'; 967 1096 wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $class); 968 1097 wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control', $dims90); 1098 969 1099 $class['classname'] = 'widget_archives'; 970 1100 wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $class); 971 1101 wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control', $dims100); 1102 972 1103 $class['classname'] = 'widget_links'; 973 1104 wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $class); 1105 974 1106 $class['classname'] = 'widget_meta'; 975 1107 wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $class); 976 1108 wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control', $dims90); 1109 977 1110 $class['classname'] = 'widget_search'; 978 1111 wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $class); 979 $class['classname'] = 'widget_categories'; 980 wp_register_sidebar_widget('categories', __('Categories'), 'wp_widget_categories', $class); 981 wp_register_widget_control('categories', __('Categories'), 'wp_widget_categories_control', $dims150); 1112 982 1113 $class['classname'] = 'widget_recent_entries'; 983 1114 wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $class); 984 1115 wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control', $dims90); 1116 1117 wp_widget_categories_register(); 985 1118 wp_widget_text_register(); 986 1119 wp_widget_rss_register(); 987 1120 wp_widget_recent_comments_register(); 988 1121 989 $ wp_register_widget_defaults= false;1122 $GLOBALS['wp_register_widget_defaults'] = false; 990 1123 991 1124 do_action('widgets_init');
Note: See TracChangeset
for help on using the changeset viewer.