Changeset 5301

Show
Ignore:
Timestamp:
04/24/07 21:36:17 (1 year ago)
Author:
ryan
Message:

Update widgets to latest bits. see #4169

Files:

Legend:

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

    r5300 r5301  
    1111/* Template tags & API functions */ 
    1212 
    13 if ( !function_exists( 'register_sidebars' ) ) { 
    14     function register_sidebars( $number = 1, $args = array() ) { 
    15         $number = (int) $number; 
    16      
    17         if ( is_string( $args ) ) { 
    18             parse_str( $args, $args ); 
     13if ( !function_exists( 'register_sidebars' ) ): 
     14function register_sidebars($number = 1, $args = array()) { 
     15    $number = (int) $number; 
     16 
     17    if ( is_string($args) ) 
     18        parse_str($args, $args); 
     19 
     20    $i = 1; 
     21 
     22    while ( $i <= $number ) { 
     23        $_args = $args; 
     24        if ( $number > 1 ) { 
     25            $_args['name'] = isset($args['name']) ? $args['name'] : sprintf(__('Sidebar %d'), $i); 
     26        } else { 
     27            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); 
    1928        } 
    20      
    21         $name = ( !empty( $args['name'] ) ) ? $args['name'] : __( 'Sidebar' ); 
    22      
    23         for ( $i = 1; $i <= $number; $i++ ) { 
    24             if ( isset( $args['name'] ) && $number > 1 ) { 
    25                 if ( strpos( $name, '%d' ) === false ) { 
    26                     $name = $name . ' %d'; 
     29        $_args['id'] = isset($args['id']) ? $args['id'] : "sidebar-$i"; 
     30        register_sidebar($_args); 
     31        ++$i; 
     32    } 
     33
     34endif; 
     35 
     36if ( !function_exists( 'register_sidebar' ) ): 
     37function register_sidebar($args = array()) { 
     38    global $wp_registered_sidebars; 
     39 
     40    if ( is_string($args) ) 
     41        parse_str($args, $args); 
     42 
     43    $i = count($wp_registered_sidebars) + 1; 
     44 
     45    $defaults = array( 
     46        'name' => sprintf(__('Sidebar %d'), count($wp_registered_sidebars) + 1 ), 
     47        'id' => "sidebar-$i", 
     48        'before_widget' => '<li id="%1$s" class="widget %2$s">', 
     49        'after_widget' => "</li>\n", 
     50        'before_title' => '<h2 class="widgettitle">', 
     51        'after_title' => "</h2>\n", 
     52    ); 
     53 
     54    $sidebar = array_merge($defaults, $args); 
     55 
     56    $wp_registered_sidebars[$sidebar['id']] = $sidebar; 
     57 
     58    return $sidebar['id']; 
     59
     60endif; 
     61 
     62if ( !function_exists( 'unregister_sidebar' ) ): 
     63function unregister_sidebar( $name ) { 
     64    global $wp_registered_sidebars; 
     65         
     66    if ( isset( $wp_registered_sidebars[$name] ) ) 
     67        unset( $wp_registered_sidebars[$name] ); 
     68
     69endif; 
     70 
     71if ( !function_exists( 'register_sidebar_widget' ) ): 
     72function register_sidebar_widget($name, $output_callback, $classname = '', $id = '') { 
     73    global $wp_registered_widgets, $wp_register_widget_defaults; 
     74 
     75    // Compat 
     76    if ( is_array($name) ) { 
     77        if ( count($name) == 3 ) 
     78            $name = sprintf($name[0], $name[2]); 
     79        else 
     80            $name = $name[0]; 
     81    } 
     82 
     83    // Last resort -- this can be broken when names get translated so please provide a unique id. 
     84    if ( !isset($id) ) 
     85        $id = sanitize_title($name); 
     86 
     87    if ( (!isset($classname) || empty($classname) || !is_string($classname)) && is_string($output_callback) ) 
     88            $classname = $output_callback; 
     89 
     90    $widget = array( 
     91        'name' => $name, 
     92        'id' => $id, 
     93        'callback' => $output_callback, 
     94        'classname' => $classname, 
     95        'params' => array_slice(func_get_args(), 4) 
     96    ); 
     97 
     98    if ( empty($output_callback) ) 
     99        unset($wp_registered_widgets[$id]); 
     100    elseif ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || !$wp_register_widget_defaults) ) 
     101        $wp_registered_widgets[$id] = $widget; 
     102
     103endif; 
     104 
     105if ( !function_exists( 'unregister_sidebar_widget' ) ): 
     106function unregister_sidebar_widget($id) { 
     107    $id = sanitize_title($id); 
     108    register_sidebar_widget('', '', '', $id); 
     109    unregister_widget_control($id); 
     110
     111endif; 
     112 
     113if ( !function_exists( 'register_widget_control' ) ): 
     114function register_widget_control($name, $control_callback, $width = 300, $height = 200, $id = '') { 
     115    global $wp_registered_widget_controls, $wp_register_widget_defaults; 
     116 
     117    // Compat 
     118    if ( is_array($name) ) { 
     119        if ( count($name) == 3 ) 
     120            $name = sprintf($name[0], $name[2]); 
     121        else 
     122            $name = $name[0]; 
     123    } 
     124 
     125    if ( !isset($id) || empty($id) ) 
     126        $id = $name; 
     127 
     128    $id = sanitize_title($id); 
     129 
     130    $width = (int) $width > 90 ? (int) $width + 60 : 360; 
     131    $height = (int) $height > 60 ? (int) $height + 40 : 240; 
     132 
     133    if ( empty($control_callback) ) 
     134        unset($wp_registered_widget_controls[$name]); 
     135    elseif ( !isset($wp_registered_widget_controls[$name]) || !$wp_register_widget_defaults ) 
     136        $wp_registered_widget_controls[$id] = array( 
     137            'name' => $name, 
     138            'id' => $id, 
     139            'callback' => $control_callback, 
     140            'width' => $width, 
     141            'height' => $height, 
     142            'params' => array_slice(func_get_args(), 5) 
     143        ); 
     144
     145endif; 
     146 
     147if ( !function_exists( 'unregister_widget_control' ) ): 
     148function unregister_widget_control($id) { 
     149    $id = sanitize_title($id); 
     150    return register_widget_control($id, ''); 
     151
     152endif; 
     153 
     154if ( !function_exists( 'dynamic_sidebar' ) ): 
     155function dynamic_sidebar($index = 1) { 
     156    global $wp_registered_sidebars, $wp_registered_widgets; 
     157 
     158    if ( is_int($index) ) { 
     159        $index = "sidebar-$index"; 
     160    } else { 
     161        $index = sanitize_title($index); 
     162    } 
     163 
     164    $sidebars_widgets = wp_get_sidebars_widgets(); 
     165 
     166    if ( empty($wp_registered_sidebars[$index]) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) ) 
     167        return false; 
     168 
     169    $sidebar = $wp_registered_sidebars[$index]; 
     170 
     171    $did_one = false; 
     172    foreach ( $sidebars_widgets[$index] as $id ) { 
     173        $callback = $wp_registered_widgets[$id]['callback']; 
     174 
     175        $params = array_merge(array($sidebar), (array) $wp_registered_widgets[$id]['params']); 
     176 
     177        // Substitute HTML id and class attributes into before_widget 
     178        $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $wp_registered_widgets[$id]['classname']); 
     179 
     180        if ( is_callable($callback) ) { 
     181            call_user_func_array($callback, $params); 
     182            $did_one = true; 
     183        } 
     184    } 
     185 
     186    return $did_one; 
     187
     188endif; 
     189 
     190if ( !function_exists( 'is_active_widget' ) ): 
     191function is_active_widget($callback) { 
     192    global $wp_registered_widgets; 
     193 
     194    $sidebars_widgets = wp_get_sidebars_widgets(false); 
     195 
     196    if ( is_array($sidebars_widgets) ) foreach ( $sidebars_widgets as $sidebar => $widgets ) 
     197        if ( is_array($widgets) ) foreach ( $widgets as $widget ) 
     198            if ( $wp_registered_widgets[$widget]['callback'] == $callback ) 
     199                return true; 
     200 
     201    return false; 
     202
     203endif; 
     204 
     205if ( !function_exists( 'is_dynamic_sidebar' ) ): 
     206function is_dynamic_sidebar() { 
     207    global $wp_registered_widgets, $wp_registered_sidebars; 
     208    $sidebars_widgets = get_option('sidebars_widgets'); 
     209    foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
     210        if ( count($sidebars_widgets[$index]) ) { 
     211            foreach ( $sidebars_widgets[$index] as $widget ) 
     212                if ( array_key_exists($widget, $wp_registered_widgets) ) 
     213                    return true; 
     214        } 
     215    } 
     216    return false; 
     217
     218endif; 
     219 
     220/* Internal Functions */ 
     221 
     222function wp_get_sidebars_widgets($update = true) { 
     223    global $wp_registered_widgets; 
     224 
     225    $sidebars_widgets = get_option('sidebars_widgets'); 
     226    $_sidebars_widgets = array(); 
     227 
     228    if ( !isset($sidebars_widgets['array_version']) ) 
     229        $sidebars_widgets['array_version'] = 1; 
     230 
     231    switch ( $sidebars_widgets['array_version'] ) { 
     232        case 1 : 
     233            foreach ( $sidebars_widgets as $index => $sidebar ) 
     234            if ( is_array($sidebar) ) 
     235            foreach ( $sidebar as $i => $name ) { 
     236                $id = strtolower($name); 
     237                if ( isset($wp_registered_widgets[$id]) ) { 
     238                    $_sidebars_widgets[$index][$i] = $id; 
     239                    continue; 
    27240                } 
    28              
    29                 $args['name'] = sprintf( $name, $i ); 
     241                $id = sanitize_title($name); 
     242                if ( isset($wp_registered_widgets[$id]) ) { 
     243                    $_sidebars_widgets[$index][$i] = $id; 
     244                    continue; 
     245                } 
     246                unset($_sidebars_widgets[$index][$i]); 
    30247            } 
    31          
    32             register_sidebar( $args ); 
    33         } 
    34     } 
    35 
    36  
    37 if ( !function_exists( 'register_sidebar' ) ) { 
    38     function register_sidebar( $args = array() ) { 
    39         global $wp_registered_sidebars; 
    40          
    41         if ( is_string( $args ) ) { 
    42             parse_str( $args, $args ); 
    43         } 
    44          
    45         $defaults = array( 
    46             'name' => sprintf( __( 'Sidebar %d' ), count( $wp_registered_sidebars ) + 1 ),  
    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         $defaults = apply_filters( 'register_sidebar_defaults', $defaults, $args ); 
    54          
    55         $sidebar = array_merge( $defaults, $args ); 
    56          
    57         $sidebar['id'] = sanitize_title( $sidebar['name'] ); 
    58          
    59         $wp_registered_sidebars[$sidebar['id']] = $sidebar; 
    60          
    61         return $sidebar['id']; 
    62     } 
    63 
    64  
    65 if ( !function_exists( 'unregister_sidebar' ) ) { 
    66     function unregister_sidebar( $name ) { 
    67         global $wp_registered_sidebars; 
    68          
    69         if ( isset( $wp_registered_sidebars[$name] ) ) { 
    70             unset( $wp_registered_sidebars[$name] ); 
    71         } 
    72     } 
    73 
    74  
    75 if ( !function_exists( 'register_sidebar_widget' ) ) { 
    76     function register_sidebar_widget( $name, $output_callback, $classname = '' ) { 
    77         global $wp_registered_widgets, $wp_register_widget_defaults; 
    78          
    79         if ( is_array( $name ) ) { 
    80             $id = sanitize_title( sprintf( $name[0], $name[2] ) ); 
    81             $name = sprintf( __( $name[0], $name[1] ), $name[2] ); 
    82         } else { 
    83             $id = sanitize_title( $name ); 
    84             $name = __( $name ); 
    85         } 
    86          
    87         if ( ( empty( $classname ) || !is_string( $classname ) ) && is_string( $output_callback ) ) { 
    88             $classname = $output_callback; 
    89         } 
    90          
    91         $widget = array( 
    92             'id' => $id,  
    93             'callback' => $output_callback,  
    94             'classname' => $classname,  
    95             'params' => array_slice( func_get_args(), 2 ) 
    96         ); 
    97          
    98         if ( empty( $output_callback ) ) { 
    99             unset( $wp_registered_widgets[$name] ); 
    100         } elseif ( is_callable( $output_callback ) && ( !isset( $wp_registered_widgets[$name] ) || !$wp_register_widget_defaults ) ) { 
    101             $wp_registered_widgets[$name] = $widget; 
    102         } 
    103     } 
    104 
    105  
    106 if ( !function_exists( 'unregister_sidebar_widget' ) ) { 
    107     function unregister_sidebar_widget( $name ) { 
    108         register_sidebar_widget( $name, '' ); 
    109         unregister_widget_control( $name ); 
    110     } 
    111 
    112  
    113 if ( !function_exists( 'register_widget_control' ) ) { 
    114     function register_widget_control( $name, $control_callback, $width = 300, $height = 200 ) { 
    115         global $wp_registered_widget_controls, $wp_registered_sidebar_defaults; 
    116          
    117         $width = (int) $width; 
    118         $height = (int) $height; 
    119          
    120         if ( is_array( $name ) ) { 
    121             $id = sanitize_title( sprintf( $name[0], $name[2] ) ); 
    122             $name = sprintf( __( $name[0], $name[1] ), $name[2] ); 
    123         } else { 
    124             $id = sanitize_title( $name ); 
    125             $name = __( $name ); 
    126         } 
    127          
    128         $width = ( $width > 90 ) ? $width + 60 : 360; 
    129         $height = ( $height > 60 ) ? $height + 40 : 240; 
    130          
    131         if ( empty( $control_callback ) ) { 
    132             unset( $wp_registered_widget_controls[$name] ); 
    133         } elseif ( !isset( $wp_registered_widget_controls[$name] ) || !$wp_registered_sidebar_defaults ) { 
    134             $wp_registered_widget_controls[$name] = array( 
    135                 'id' => $id,  
    136                 'callback' => $control_callback,  
    137                 'width' => $width,  
    138                 'height' => $height,  
    139                 'params' => array_slice( func_get_args(), 4 ) 
    140             ); 
    141         } 
    142     } 
    143 
    144  
    145 if ( !function_exists( 'unregister_widget_control' ) ) { 
    146     function unregister_widget_control( $name ) { 
    147         register_sidebar_control( $name, '' ); 
    148     } 
    149 
    150  
    151 if ( !function_exists( 'dynamic_sidebar' ) ) { 
    152     function dynamic_sidebar( $name = 1 ) { 
    153         global $wp_registered_sidebars, $wp_registered_widgets; 
    154          
    155         if ( is_int( $name ) ) { 
    156             $index = sanitize_title( __( 'Sidebar' ) . ' ' . $name ); 
    157             $name = sprintf( __( 'Sidebar %d' ), $name ); 
    158         } else { 
    159             $index = sanitize_title( $name ); 
    160         } 
    161          
    162         $sidebars_widgets = wp_get_sidebars_widgets(); 
    163          
    164         $sidebar = $wp_registered_sidebars[$index]; 
    165          
    166         if ( empty( $sidebar ) || !is_array( $sidebars_widgets[$index] ) || empty( $sidebars_widgets[$index] ) ) { 
    167             return false; 
    168         } 
    169          
    170         $did_one = false; 
    171          
    172         foreach ( $sidebars_widgets[$index] as $name ) { 
    173             $callback = $wp_registered_widgets[$name]['callback']; 
    174              
    175             $params = array_merge( array( $sidebar ), (array) $wp_registered_widgets[$name]['params'] ); 
    176             $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $wp_registered_widgets[$name]['id'], $wp_registered_widgets[$name]['classname'] ); 
    177              
    178             if ( is_callable( $callback ) ) { 
    179                 call_user_func_array( $callback, $params ); 
    180                 $did_one = true; 
    181             } 
    182         } 
    183          
    184         return $did_one; 
    185     } 
    186 
    187  
    188 if ( !function_exists( 'is_active_widget' ) ) { 
    189     function is_active_widget( $callback ) { 
    190         global $wp_registered_widgets; 
    191          
    192         $sidebars_widgets = wp_get_sidebars_widgets(); 
    193          
    194         if ( is_array( $sidebars_widgets ) ) { 
    195             foreach ( $sidebars_widgets as $sidebar => $widgets ) { 
    196                 if ( is_array( $widgets) ) { 
    197                     foreach ( $widgets as $widget ) { 
    198                         if ( $wp_registered_widgets[$widget]['callback'] == $callback ) { 
    199                             return true; 
    200                         } 
    201                     } 
    202                 } 
    203             } 
    204         } 
    205          
    206         return false; 
    207     } 
    208 
    209  
    210 if ( !function_exists( 'is_dynamic_sidebar' ) ) { 
    211     function is_dynamic_sidebar() { 
    212         global $wp_registered_sidebars, $wp_registered_widgets; 
    213          
    214         $sidebars_widgets = wp_get_sidebars_widgets(); 
    215          
    216         foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
    217             if ( count( $sidebars_widgets[$index] ) > 0 ) { 
    218                 foreach ( $sidebars_widgets[$index] as $widget ) { 
    219                     if ( array_key_exists( $widget, $wp_registered_sidebars ) ) { 
    220                         return true; 
    221                     } 
    222                 } 
    223             } 
    224         } 
    225          
    226         return false; 
    227     } 
    228 
    229  
    230 /* Internal Functions */ 
    231  
    232 function wp_get_sidebars_widgets() { 
    233     return get_option( 'wp_sidebars_widgets' ); 
     248            $_sidebars_widgets['array_version'] = 2; 
     249            if ( $update ) 
     250                update_option('sidebars_widgets', $_sidebars_widgets); 
     251            break; 
     252        case 2 : 
     253            $_sidebars_widgets = $sidebars_widgets; 
     254            break; 
     255    } 
     256 
     257    unset($_sidebars_widgets['array_version']); 
     258 
     259    return $_sidebars_widgets; 
    234260} 
    235261 
    236262function wp_set_sidebars_widgets( $sidebars_widgets ) { 
    237     update_option( 'wp_sidebars_widgets', $sidebars_widgets ); 
     263    update_option( 'sidebars_widgets', $sidebars_widgets ); 
    238264} 
    239265 
    240266function wp_get_widget_defaults() { 
    241267    global $wp_registered_sidebars; 
    242      
     268 
    243269    $defaults = array(); 
    244      
    245     foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
     270 
     271    foreach ( $wp_registered_sidebars as $index => $sidebar ) 
    246272        $defaults[$index] = array(); 
    247     } 
    248      
     273 
    249274    return $defaults; 
    250275} 
     
    252277/* Default Widgets */ 
    253278 
    254 function wp_widget_pages( $args ) { 
    255     extract( $args ); 
    256      
    257     $options = get_option( 'wp_widget_pages' ); 
    258      
    259     $title = ( empty( $options['title'] ) ) ? __( 'Pages' ) : $options['title']; 
    260      
     279function wp_widget_pages($args) { 
     280    extract($args); 
     281    $options = get_option('widget_pages'); 
     282    $title = empty($options['title']) ? __('Pages') : $options['title']; 
    261283    echo $before_widget . $before_title . $title . $after_title . "<ul>\n"; 
    262     wp_list_pages( 'title_li=' ); 
     284    wp_list_pages("title_li="); 
    263285    echo "</ul>\n" . $after_widget; 
    264286} 
    265287 
    266288function wp_widget_pages_control() { 
    267     $options = $newoptions = get_option( 'wp_widget_pages' ); 
    268      
    269     if ( isset( $_POST['pages-submit'] ) ) { 
    270         $newoptions['title'] = strip_tags( stripslashes( $_POST['pages-title'] ) ); 
    271          
    272         if ( $newoptions != $options ) { 
    273             $options = $newoptions; 
    274             update_option( 'wp_widget_pages', $options ); 
    275         } 
    276     } 
    277      
    278     $title = htmlspecialchars( $options['title'], ENT_QUOTES ); 
    279 ?> 
    280         <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> 
    281         <input type="hidden" id="pages-submit" name="pages-submit" value="1" /> 
    282 <?php 
    283 
    284  
    285 function wp_widget_links( $args ) { 
     289    $options = $newoptions = get_option('widget_pages'); 
     290    if ( $_POST["pages-submit"] ) { 
     291        $newoptions['title'] = strip_tags(stripslashes($_POST["pages-title"])); 
     292    } 
     293    if ( $options != $newoptions ) { 
     294        $options = $newoptions; 
     295        update_option('widget_pages', $options); 
     296    } 
     297    $title = htmlspecialchars($options['title'], ENT_QUOTES); 
     298?> 
     299            <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> 
     300            <input type="hidden" id="pages-submit" name="pages-submit" value="1" /> 
     301<?php 
     302
     303 
     304function wp_widget_links($args) { 
    286305    global $wp_db_version; 
    287     extract( $args ); 
    288      
     306    extract($args); 
    289307    if ( $wp_db_version < 3582 ) { 
     308        // This ONLY works with li/h2 sidebars. 
    290309        get_links_list(); 
    291310    } else { 
    292         wp_list_bookmarks( array( 
    293             'title_before' => $before_title, 'title_after' => $after_title,  
    294             'category_before' => $before_widget, 'category_after' => $after_widget 
    295         ) ); 
    296     } 
    297 
    298  
    299 function wp_widget_search( $args ) { 
    300     extract( $args ); 
     311        wp_list_bookmarks(array('title_before'=>$before_title, 'title_after'=>$after_title, 'show_images'=>true, 'class'=>'linkcat widget')); 
     312    } 
     313
     314 
     315function wp_widget_search($args) { 
     316    extract($args); 
    301317?> 
    302318        <?php echo $before_widget; ?> 
    303             <form id="searchform" action="<?php bloginfo( 'url' ); ?>" method="get"> 
    304                 <div><input type="text" name="s" id="s" size="15" /><br /> 
    305                     <input type="submit" value="<?php _e( 'Search' ); ?>" /></div> 
     319            <form id="searchform" method="get" action="<?php bloginfo('home'); ?>"> 
     320            <div> 
     321            <input type="text" name="s" id="s" size="15" /><br /> 
     322            <input type="submit" value="<?php _e('Search'); ?>" /> 
     323            </div> 
    306324            </form> 
    307325        <?php echo $after_widget; ?> 
     
    309327} 
    310328 
    311 function wp_widget_archives( $args ) { 
    312     extract( $args ); 
    313      
    314     $options = get_option( 'wp_widget_archives' ); 
    315     $c = ( $options['count'] ) ? '1' : '0'; 
    316     $title = ( empty( $options['title'] ) ) ? __( 'Archives' ) : $options['title']; 
     329function wp_widget_archives($args) { 
     330    extract($args); 
     331    $options = get_option('widget_archives'); 
     332    $c = $options['count'] ? '1' : '0'; 
     333    $title = empty($options['title']) ? __('Archives') : $options['title']; 
    317334?> 
    318335        <?php echo $before_widget; ?> 
    319336            <?php echo $before_title . $title . $after_title; ?> 
    320337            <ul> 
    321             <?php wp_get_archives( 'type=monthly&show_post_count=' . $c ); ?> 
     338            <?php wp_get_archives("type=monthly&show_post_count=$c"); ?> 
    322339            </ul> 
    323340        <?php echo $after_widget; ?> 
     
    326343 
    327344function wp_widget_archives_control() { 
    328     $options = $newoptions = get_option( 'wp_widget_archives' ); 
    329      
    330     if ( isset( $_POST['archives-submit'] ) ) { 
    331         $newoptions['count'] = isset( $_POST['archives-count'] ); 
    332         $newoptions['title'] = strip_tags( stripslashes( $_POST['archives-title'] ) ); 
    333          
    334         if ( $newoptions != $options ) { 
    335             $options = $newoptions; 
    336             update_option( 'wp_widget_archives', $options ); 
    337         } 
    338     } 
    339      
    340     $count = ( isset( $options['count'] ) ) ? ' checked="checked"' : ''; 
    341     $title = htmlspecialchars( $options['title'], ENT_QUOTES ); 
    342 ?> 
    343         <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> 
    344         <p style="text-align:right;margin-right:40px"><label for="archives-count"><?php _e( 'Show post counts?' ); ?> <input type="checkbox" class="checkbox" name="archives-count" id="archives-count" <?php echo $count; ?>/></p> 
    345         <input type="hidden" name="archives-submit" id="archives-submit" value="1" /> 
    346 <?php 
    347 
    348  
    349 function wp_widget_meta( $args ) { 
    350     extract( $args ); 
    351      
    352     $options = get_option( 'wp_widget_meta' ); 
    353     $title = ( empty( $options['title'] ) ) ? __( 'Meta' ) : $options['title']; 
     345    $options = $newoptions = get_option('widget_archives'); 
     346    if ( $_POST["archives-submit"] ) { 
     347        $newoptions['count'] = isset($_POST['archives-count']); 
     348        $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"])); 
     349    } 
     350    if ( $options != $newoptions ) { 
     351        $options = $newoptions; 
     352        update_option('widget_archives', $options); 
     353    } 
     354    $count = $options['count'] ? 'checked="checked"' : ''; 
     355    $title = htmlspecialchars($options['title'], ENT_QUOTES); 
     356?> 
     357            <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> 
     358            <p style="text-align:right;margin-right:40px;"><label for="archives-count">Show post counts <input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /></label></p> 
     359            <input type="hidden" id="archives-submit" name="archives-submit" value="1" /> 
     360<?php 
     361
     362 
     363function wp_widget_meta($args) { 
     364    extract($args); 
     365    $options = get_option('widget_meta'); 
     366    $title = empty($options['title']) ? __('Meta') : $options['title']; 
    354367?> 
    355368        <?php echo $before_widget; ?> 
    356369            <?php echo $before_title . $title . $after_title; ?> 
    357370            <ul> 
    358                <?php wp_register(); ?> 
    359                <li><?php wp_loginout(); ?></li> 
    360                <li><a href="<?php bloginfo( 'rss2_url' ); ?>" title="<?php _e( 'Syndicate this site using RSS 2.0' ); ?>"><?php _e( 'Entries <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li> 
    361                <li><a href="<?php bloginfo( 'comments_rss2_url' ); ?>" title="<?php _e( 'The latest comments to all posts in RSS' ); ?>"><?php _e( 'Comments <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li> 
    362                <li><a href="http://wordpress.org/" title="<?php _e( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ); ?>">WordPress</a></li> 
    363                <?php wp_meta(); ?> 
     371            <?php wp_register(); ?> 
     372            <li><?php wp_loginout(); ?></li> 
     373            <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS 2.0'); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> 
     374            <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> 
     375            <li><a href="http://wordpress.com/" title="<?php _e('Powered by WordPress, state-of-the-art semantic personal publishing platform.'); ?>">WordPress.com</a></li> 
     376            <?php wp_meta(); ?> 
    364377            </ul> 
    365378        <?php echo $after_widget; ?> 
    366379<?php 
    367380} 
    368  
    369381function wp_widget_meta_control() { 
    370     $options = $newoptions = get_option( 'wp_widget_meta' ); 
    371      
    372     if ( isset( $_POST['meta-submit'] ) ) { 
    373         $newoptions['title'] = strip_tags( stripslashes( $_POST['meta-title'] ) ); 
    374          
    375         if ( $newoptions != $options ) { 
    376             $options = $newoptions; 
    377             update_option( 'wp_widget_meta', $options ); 
    378         } 
    379     } 
    380      
    381     $title = htmlspecialchars( $options['title'], ENT_QUOTES ); 
    382 ?> 
    383         <p><label for="meta-title"><?php _e( 'Title:' ); ?> <input type="text" name="meta-title" id="meta-title" style="width:250px" value="<?php echo $title; ?>" /></label></p> 
    384         <input type="hidden" name="meta-submit" id="meta-submit" value="1" /> 
    385 <?php 
    386 
    387  
    388 function wp_widget_calendar( $args ) { 
    389     extract( $args ); 
    390      
    391     $title = ( empty( $options['title'] ) ) ? '&nbsp;' : $options['title']; 
     382    $options = $newoptions = get_option('widget_meta'); 
     383    if ( $_POST["meta-submit"] ) { 
     384        $newoptions['title'] = strip_tags(stripslashes($_POST["meta-title"])); 
     385    } 
     386    if ( $options != $newoptions ) { 
     387        $options = $newoptions; 
     388        update_option('widget_meta', $options); 
     389    } 
     390    $title = htmlspecialchars($options['title'], ENT_QUOTES); 
     391?> 
     392            <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> 
     393            <input type="hidden" id="meta-submit" name="meta-submit" value="1" /> 
     394<?php 
     395
     396 
     397function wp_widget_calendar($args) { 
     398    extract($args); 
     399    $options = get_option('widget_calendar'); 
     400    $title = $options['title']; 
     401    if ( empty($title) ) 
     402        $title = '&nbsp;'; 
     403    echo $before_widget . $before_title . $title . $after_title; 
     404    echo '<div id="calendar_wrap">'; 
     405    get_calendar(); 
     406    echo '</div>'; 
     407    echo $after_widget; 
     408
     409function wp_widget_calendar_control() { 
     410    $options = $newoptions = get_option('widget_calendar'); 
     411    if ( $_POST["calendar-submit"] ) { 
     412        $newoptions['title'] = strip_tags(stripslashes($_POST["calendar-title"])); 
     413    } 
     414    if ( $options != $newoptions ) { 
     415        $options = $newoptions; 
     416        update_option('widget_calendar', $options); 
     417    } 
     418    $title = htmlspecialchars($options['title'], ENT_QUOTES); 
     419?> 
     420            <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> 
     421            <input type="hidden" id="calendar-submit" name="calendar-submit" value="1" /> 
     422<?php 
     423
     424 
     425function wp_widget_text($args, $number = 1) { 
     426    extract($args); 
     427    $options = get_option('widget_text'); 
     428    $title = $options[$number]['title']; 
     429    if ( empty($title) ) 
     430        $title = '&nbsp;'; 
     431    $text = $options[$number]['text']; 
    392432?> 
    393433        <?php echo $before_widget; ?> 
    394             <?php echo $before_title . $title . $after_title; ?> 
    395             <div id="calendar_wrap"> 
    396                 <?php get_calendar(); ?> 
    397             </div> 
    398         <?php echo $after_widget; ?> 
    399 <?php 
    400 
    401  
    402 function wp_widget_calendar_control() { 
    403     $options = $newoptions = get_option( 'wp_widget_calendar' ); 
    404      
    405     if ( isset( $_POST['calendar-submit'] ) ) { 
    406         $newoptions['title'] = strip_tags( stripslashes( $_POST['calendar-title'] ) ); 
    407          
    408         if ( $newoptions != $options ) { 
    409             $options = $newoptions; 
    410             update_option( 'wp_widget_calendar', $options ); 
    411         } 
    412     } 
    413      
    414     $title = htmlspecialchars( $options['title'], ENT_QUOTES ); 
    415 ?> 
    416         <p><label for="calendar-title"><?php _e( 'Title:' ); ?> <input type="text" style="width:250px" id="calendar-title" name="calendar-title" value="<?php echo $title; ?>" /></label></p> 
    417         <input type="hidden" id="calendar-title" name="calendar-title" value="1" /> 
    418 <?php 
    419 
    420  
    421 function wp_widget_text( $args, $i = 1 ) { 
    422     extract( $args ); 
    423      
    424     $options = get_option( 'wp_widget_text' ); 
    425      
    426     $title = ( empty( $options[$i]['title'] ) ) ? '' : $options[$i]['title']; 
    427 ?> 
    428         <?php echo $before_widget; ?> 
    429             <?php print ( empty( $title ) ) ? '' : $before_title . $title . $after_title; ?> 
     434            <?php $title ? print($before_title . $title . $after_title) : null; ?> 
    430435            <div class="textwidget"><?php echo $text; ?></div> 
    431436        <?php echo $after_widget; ?> 
     
    433438} 
    434439 
    435 function wp_widget_text_control( $i ) { 
    436     $options = $newoptions = get_option( 'wp_widget_text' ); 
    437      
    438     if ( isset( $_POST['text-submit-' . $i] ) ) { 
    439         $newoptions[$i]['title'] = strip_tags( stripslashes( $_POST['text-title-' . $i] ) ); 
    440         $newoptions[$i]['text'] = stripslashes( $_POST['text-text-' . $i] ); 
    441          
    442         if ( !current_user_can( 'unfiltered_html' ) ) { 
    443             $newoptions[$i]['text'] = stripslashes( wp_filter_post_kses( $newoptions[$i]['text'] ) ); 
    444         } 
    445          
    446         if ( $newoptions != $options ) { 
    447             $options = $newoptions; 
    448             update_options( 'wp_widget_text', $options ); 
    449         } 
    450     } 
    451      
    452     $title = htmlspecialchars( $options[$i]['title'], ENT_QUOTES ); 
    453     $text = htmlspecialchars( $options[$i]['text'], ENT_QUOTES ); 
    454 ?> 
    455         <input style="width:450px" id="text-title-<?php echo $i; ?>" name="text-title-<?php echo $i; ?>" type="text" value="<?php echo $title; ?>" /> 
    456         <textarea style="width:450px;height:280px" id="text-text-<?php echo $i; ?>" name="text-text-<?php echo $i; ?>"><?php echo $text; ?></textarea> 
    457         <input type="hidden" id="text-submit-<?php echo $i; ?>" name="text-submit-<?php echo $i; ?>" value="1" /> 
     440function wp_widget_text_control($number) { 
     441    $options = $newoptions = get_option('widget_text'); 
     442    if ( !is_array($options) ) 
     443        $options = $newoptions = array(); 
     444    if ( $_POST["text-submit-$number"] ) { 
     445        $newoptions[$number]['title'] = strip_tags(stripslashes($_POST["text-title-$number"])); 
     446        $newoptions[$number]['text'] = stripslashes($_POST["text-text-$number"]); 
     447        if ( !current_user_can('unfiltered_html') ) 
     448            $newoptions[$number]['text'] = stripslashes(wp_filter_post_kses($newoptions[$number]['text'])); 
     449    } 
     450    if ( $options != $newoptions ) { 
     451        $options = $newoptions; 
     452        update_option('widget_text', $options); 
     453    } 
     454    $title = htmlspecialchars($options[$number]['title'], ENT_QUOTES); 
     455    $text = htmlspecialchars($options[$number]['text'], ENT_QUOTES); 
     456?> 
     457            <input style="width: 450px;" id="text-title-<?php echo "$number"; ?>" name="text-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" /> 
     458            <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo "$number"; ?>" name="text-text-<?php echo "$number"; ?>"><?php echo $text; ?></textarea> 
     459            <input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" /> 
    458460<?php 
    459461} 
    460462 
    461463function wp_widget_text_setup() { 
    462     $options = $newoptions = get_option( 'wp_widget_text' ); 
    463      
    464     if ( isset( $_POST['text-number-submit'] ) ) { 
    465         $i = (int) $_POST['text-number']; 
    466          
    467         if ( $i > 9 ) { 
    468             $i = 9; 
    469         } elseif ( $i < 1 ) { 
    470             $i = 1; 
    471         } 
    472          
    473         $newoptions['number'] = $i; 
    474          
    475         if ( $newoptions != $options ) { 
    476             $options = $newoptions; 
    477             update_option( 'wp_widget_text', $options ); 
    478         } 
     464    $options = $newoptions = get_option('widget_text'); 
     465    if ( isset($_POST['text-number-submit']) ) { 
     466        $number = (int) $_POST['text-number']; 
     467        if ( $number > 9 ) $number = 9; 
     468        if ( $number < 1 ) $number = 1; 
     469        $newoptions['number'] = $number; 
     470    } 
     471    if ( $options != $newoptions ) { 
     472        $options = $newoptions; 
     473        update_option('widget_text', $options); 
     474        widget_text_register($options['number']); 
    479475    } 
    480476} 
    481477 
    482478function wp_widget_text_page() { 
    483     $options = get_option( 'widget_text' ); 
    484      
    485     $i = $options['number']; 
     479    $options = $newoptions = get_option('widget_text'); 
    486480?> 
    487481    <div class="wrap"> 
    488         <form method="post"> 
    489             <h2><?php _e( 'Text Widgets' ); ?></h2> 
    490              
    491             <p style="line-height:30px"><?php _e( 'How many widgets would you like?' ); ?>  
    492                 <select id="text-number" name="text-number" value="<?php echo $i; ?>"> 
    493                 <?php for ( $j = 1; $j < 10; $j++ ) { ?> 
    494                     <option value="<?php echo $j; ?>"<?php if ( $i == $j ) { ?> selected="selected"<?php } ?>><?php echo $j; ?></option> 
    495                 <?php } ?> 
    496                 </select> 
    497                 <span class="submit"><input type="submit" name="text-number-submit" id="text-number-submit" value="<?php _e( 'Save' ); ?>" /></span> 
    498             </p> 
     482        <form method="POST"> 
     483            <h2><?php _e('Text Widgets'); ?></h2> 
     484            <p style="line-height: 30px;"><?php _e('How many text widgets would you like?'); ?> 
     485            <select id="text-number" name="text-number" value="<?php echo $options['number']; ?>"> 
     486<?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?> 
     487            </select> 
     488            <span class="submit"><input type="submit" name="text-number-submit" id="text-number-submit" value="<?php _e('Save'); ?>" /></span></p> 
    499489        </form> 
    500490    </div> 
     
    503493 
    504494function wp_widget_text_register() { 
    505     $options = get_option( 'wp_widget_text' ); 
    506      
    507     $i = $options['number']; 
    508      
    509     if ( $i < 1 ) { 
    510         $i = 1; 
    511     } elseif ( $i > 9 ) { 
    512         $i = 9; 
    513     } 
    514      
    515     for ( $j = 1; $j <= 9; $j++ ) { 
    516         $name = array( 'Text %s', '', $i ); 
    517         register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_text' : '', $j ); 
    518         register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_text_control' : '', 460, 350, $j ); 
    519     } 
    520      
    521     add_action( 'sidebar_admin_setup', 'wp_widget_text_setup' ); 
    522     add_action( 'sidebar_admin_page', 'wp_widget_text_page' ); 
    523 
    524  
    525 function wp_widget_categories( $args ) { 
    526     extract( $args ); 
    527      
    528     $options = get_option( 'wp_widget_categories' ); 
    529      
    530     $title = ( empty( $options['title'] ) ) ? __( 'Categories' ) : $options['title']; 
    531     $c = ( $options['count'] ) ? '1' : '0'; 
    532     $h = ( $options['hierarchical'] ) ? '1' : '0'; 
     495    $options = get_option('widget_text'); 
     496    $number = $options['number']; 
     497    if ( $number < 1 ) $number = 1; 
     498    if ( $number > 9 ) $number = 9; 
     499    for ($i = 1; $i <= 9; $i++) { 
     500        $name = sprintf(__('Text %d'), $i); 
     501        $id = "text-$i"; // Never never never translate an id 
     502        register_sidebar_widget($name, $i <= $number ? 'widget_text' : /* unregister */ '', null, $id, $i); 
     503        register_widget_control($name, $i <= $number ? 'widget_text_control' : /* unregister */ '', 460, 350, $id, $i); 
     504    } 
     505    add_action('sidebar_admin_setup', 'wp_widget_text_setup'); 
     506    add_action('sidebar_admin_page', 'wp_widget_text_page'); 
     507
     508 
     509function wp_widget_categories($args) { 
     510    extract($args); 
     511    $options = get_option('widget_categories'); 
     512    $c = $options['count'] ? '1' : '0'; 
     513    $h = $options['hierarchical'] ? '1' : '0'; 
     514    $title = empty($options['title']) ? __('Categories') : $options['title']; 
    533515?> 
    534516        <?php echo $before_widget; ?> 
    535517            <?php echo $before_title . $title . $after_title; ?> 
    536518            <ul> 
    537                <?php wp_list_cats( 'sort_column=name&optioncount=' . $c . '&hierarchical=' . $h ); ?> 
     519            <?php wp_list_cats("sort_column=name&optioncount=$c&hierarchical=$h"); ?> 
    538520            </ul> 
    539521        <?php echo $after_widget; ?> 
     
    542524 
    543525function wp_widget_categories_control() { 
    544     $options = $newoptions = get_option( 'wp_widget_categories' ); 
    545      
    546     if ( isset( $_POST['categories-submit'] ) ) { 
    547         $newoptions['count'] = isset( $_POST['categories-count'] ); 
    548         $newoptions['hierarchical'] = isset( $_POST['categories-hierarchical'] ); 
    549         $newoptions['title'] = strip_tags( stripslashes( $_POST['categories-title'] ) ); 
    550          
    551         if ( $newoptions != $options ) { 
    552             $options = $newoptions; 
    553             update_option( 'wp_widget_categories', $options ); 
    554         } 
    555     } 
    556      
    557     $count = ( $options['count'] ) ? ' checked="checked"' : ''; 
    558     $hierarchical = ( $options['hierarchical'] ) ? ' checked="checked"' : ''; 
    559     $title = wp_specialchars( $options['title'] ); 
    560 ?> 
    561         <p><label for="categories-title"><?php _e( 'Title:' ); ?> <input type="text" value="<?php echo $title; ?>" id="categories-title" name="categories-title" /></label></p> 
    562         <p style="text-align:right;margin-right:40px"><label for="categories-count"><?php _e( 'Show post counts? '); ?> <input type="checkbox" class="checkbox"<?php echo $count; ?> id="categories-count" name="categories-count" /></label></p> 
    563         <p style="text-align:right;margin-right:40px"><label for="categories-hierarchical"><?php _e( 'Show hierarchy?' ); ?> <input type="checkbox" class="checkbox"<?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" /></label></p> 
    564         <input type="hidden" name="categories-submit" id="categories-submit" value="1" /> 
    565 <?php 
    566 
    567  
    568 function wp_widget_recent_entries( $args ) { 
    569     extract( $args ); 
    570      
    571     $title = __( 'Recent Posts' ); 
    572      
    573     $query = new WP_Query( 'showposts=10' ); 
    574      
    575     if ( !$query->have_posts() ) { 
    576         return; 
    577     } 
     526    $options = $newoptions = get_option('widget_categories'); 
     527    if ( $_POST['categories-submit'] ) { 
     528        $newoptions['count'] = isset($_POST['categories-count']); 
     529        $newoptions['hierarchical'] = isset($_POST['categories-hierarchical']); 
     530        $newoptions['title'] = strip_tags(stripslashes($_POST['categories-title'])); 
     531    } 
     532    if ( $options != $newoptions ) { 
     533        $options = $newoptions; 
     534        update_option('widget_categories', $options); 
     535    } 
     536    $count = $options['count'] ? 'checked="checked"' : ''; 
     537    $hierarchical = $options['hierarchical'] ? 'checked="checked"' : ''; 
     538    $title = wp_specialchars($options['title']); 
     539?> 
     540            <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> 
     541            <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> 
     542            <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> 
     543            <input type="hidden" id="categories-submit" name="categories-submit" value="1" /> 
     544<?php 
     545
     546 
     547function wp_widget_recent_entries($args) { 
     548    if ( $output = wp_cache_get('widget_recent_entries') ) 
     549        return print($output); 
     550 
     551    ob_start(); 
     552    extract($args); 
     553    $options = get_option('widget_recent_entries'); 
     554    $title = empty($options['title']) ? __('Recent Posts') : $options['title']; 
     555    if ( !$number = (int) $options['number'] ) 
     556        $number = 10; 
     557    else if ( $number < 1 ) 
     558        $number = 1; 
     559    else if ( $number > 15 ) 
     560        $number = 15; 
     561 
     562    $r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0"); 
     563    if ($r->have_posts()) : 
    578564?> 
    579565        <?php echo $before_widget; ?> 
    580566            <?php echo $before_title . $title . $after_title; ?> 
    581567            <ul> 
    582             <?php while ( $query->have_posts() ) { 
    583                 $query->the_post(); ?> 
    584                 <li><a href="<?php the_permalink(); ?>"><?php  
    585                     if ( get_the_title() != '' ) { 
    586                         the_title(); 
    587                     } else { 
    588                         the_ID(); 
    589                     } 
    590                 ?></a></li> 
    591             <?php } ?> 
     568            <?php  while ($r->have_posts()) : $r->the_post(); ?> 
     569            <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li> 
     570            <?php endwhile; ?> 
    592571            </ul> 
    593572