Changeset 5301
- Timestamp:
- 04/24/2007 09:36:17 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r5300 r5301 11 11 /* Template tags & API functions */ 12 12 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 ); 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); 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'); 19 28 } 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 } 34 endif; 35 36 if ( !function_exists( 'register_sidebar' ) ): 37 function 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 } 60 endif; 61 62 if ( !function_exists( 'unregister_sidebar' ) ): 63 function unregister_sidebar( $name ) { 64 global $wp_registered_sidebars; 65 66 if ( isset( $wp_registered_sidebars[$name] ) ) 67 unset( $wp_registered_sidebars[$name] ); 68 } 69 endif; 70 71 if ( !function_exists( 'register_sidebar_widget' ) ): 72 function 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 } 103 endif; 104 105 if ( !function_exists( 'unregister_sidebar_widget' ) ): 106 function unregister_sidebar_widget($id) { 107 $id = sanitize_title($id); 108 register_sidebar_widget('', '', '', $id); 109 unregister_widget_control($id); 110 } 111 endif; 112 113 if ( !function_exists( 'register_widget_control' ) ): 114 function 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 } 145 endif; 146 147 if ( !function_exists( 'unregister_widget_control' ) ): 148 function unregister_widget_control($id) { 149 $id = sanitize_title($id); 150 return register_widget_control($id, ''); 151 } 152 endif; 153 154 if ( !function_exists( 'dynamic_sidebar' ) ): 155 function 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 } 188 endif; 189 190 if ( !function_exists( 'is_active_widget' ) ): 191 function 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 } 203 endif; 204 205 if ( !function_exists( 'is_dynamic_sidebar' ) ): 206 function 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 } 218 endif; 219 220 /* Internal Functions */ 221 222 function 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; 27 240 } 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]); 30 247 } 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; 234 260 } 235 261 236 262 function wp_set_sidebars_widgets( $sidebars_widgets ) { 237 update_option( ' wp_sidebars_widgets', $sidebars_widgets );263 update_option( 'sidebars_widgets', $sidebars_widgets ); 238 264 } 239 265 240 266 function wp_get_widget_defaults() { 241 267 global $wp_registered_sidebars; 242 268 243 269 $defaults = array(); 244 245 foreach ( $wp_registered_sidebars as $index => $sidebar ) {270 271 foreach ( $wp_registered_sidebars as $index => $sidebar ) 246 272 $defaults[$index] = array(); 247 } 248 273 249 274 return $defaults; 250 275 } … … 252 277 /* Default Widgets */ 253 278 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 279 function wp_widget_pages($args) { 280 extract($args); 281 $options = get_option('widget_pages'); 282 $title = empty($options['title']) ? __('Pages') : $options['title']; 261 283 echo $before_widget . $before_title . $title . $after_title . "<ul>\n"; 262 wp_list_pages( 'title_li=');284 wp_list_pages("title_li="); 263 285 echo "</ul>\n" . $after_widget; 264 286 } 265 287 266 288 function 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 304 function wp_widget_links($args) { 286 305 global $wp_db_version; 287 extract( $args ); 288 306 extract($args); 289 307 if ( $wp_db_version < 3582 ) { 308 // This ONLY works with li/h2 sidebars. 290 309 get_links_list(); 291 310 } 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 315 function wp_widget_search($args) { 316 extract($args); 301 317 ?> 302 318 <?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> 306 324 </form> 307 325 <?php echo $after_widget; ?> … … 309 327 } 310 328 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']; 329 function 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']; 317 334 ?> 318 335 <?php echo $before_widget; ?> 319 336 <?php echo $before_title . $title . $after_title; ?> 320 337 <ul> 321 <?php wp_get_archives( 'type=monthly&show_post_count=' . $c); ?>338 <?php wp_get_archives("type=monthly&show_post_count=$c"); ?> 322 339 </ul> 323 340 <?php echo $after_widget; ?> … … 326 343 327 344 function 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 363 function wp_widget_meta($args) { 364 extract($args); 365 $options = get_option('widget_meta'); 366 $title = empty($options['title']) ? __('Meta') : $options['title']; 354 367 ?> 355 368 <?php echo $before_widget; ?> 356 369 <?php echo $before_title . $title . $after_title; ?> 357 370 <ul> 358 359 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 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(); ?> 364 377 </ul> 365 378 <?php echo $after_widget; ?> 366 379 <?php 367 380 } 368 369 381 function 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'] ) ) ? ' ' : $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 397 function wp_widget_calendar($args) { 398 extract($args); 399 $options = get_option('widget_calendar'); 400 $title = $options['title']; 401 if ( empty($title) ) 402 $title = ' '; 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 } 409 function 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 425 function 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 = ' '; 431 $text = $options[$number]['text']; 392 432 ?> 393 433 <?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; ?> 430 435 <div class="textwidget"><?php echo $text; ?></div> 431 436 <?php echo $after_widget; ?> … … 433 438 } 434 439 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" /> 440 function 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" /> 458 460 <?php 459 461 } 460 462 461 463 function 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']); 479 475 } 480 476 } 481 477 482 478 function wp_widget_text_page() { 483 $options = get_option( 'widget_text' ); 484 485 $i = $options['number']; 479 $options = $newoptions = get_option('widget_text'); 486 480 ?> 487 481 <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> 499 489 </form> 500 490 </div> … … 503 493 504 494 function 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 509 function 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']; 533 515 ?> 534 516 <?php echo $before_widget; ?> 535 517 <?php echo $before_title . $title . $after_title; ?> 536 518 <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"); ?> 538 520 </ul> 539 521 <?php echo $after_widget; ?> … … 542 524 543 525 function 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 547 function 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()) : 578 564 ?> 579 565 <?php echo $before_widget; ?> 580 566 <?php echo $before_title . $title . $after_title; ?> 581 567 <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; ?> 592 571 </ul> 593 572 <?php echo $after_widget; ?> 594 573 <?php 595 } 596 597 function wp_widget_recent_comments( $args ) { 598 global $wpdb; 599 600 extract( $args ); 601 602 $options = get_option( 'wp_widget_recent_comments' ); 603 604 $title = ( empty( $options['title'] ) ) ? __( 'Recent Comments' ) : $options['title']; 605 606 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5" ); 607 608 if ( is_array( $comments ) && count( $comments ) > 0 ) { 609 ?> 574 endif; 575 wp_cache_add('widget_recent_entries', ob_get_flush()); 576 } 577 578 function wp_flush_widget_recent_entries() { 579 wp_cache_delete('widget_recent_entries'); 580 } 581 582 add_action('save_post', 'wp_flush_widget_recent_entries'); 583 add_action('post_deleted', 'wp_flush_widget_recent_entries'); 584 585 function wp_widget_recent_entries_control() { 586 $options = $newoptions = get_option('widget_recent_entries'); 587 if ( $_POST["recent-entries-submit"] ) { 588 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-entries-title"])); 589 $newoptions['number'] = (int) $_POST["recent-entries-number"]; 590 } 591 if ( $options != $newoptions ) { 592 $options = $newoptions; 593 update_option('widget_recent_entries', $options); 594 wp_flush_widget_recent_entries(); 595 } 596 $title = htmlspecialchars($options['title'], ENT_QUOTES); 597 if ( !$number = (int) $options['number'] ) 598 $number = 5; 599 ?> 600 <p><label for="recent-entries-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="recent-entries-title" name="recent-entries-title" type="text" value="<?php echo $title; ?>" /></label></p> 601 <p><label for="recent-entries-number"><?php _e('Number of posts to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-entries-number" name="recent-entries-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p> 602 <input type="hidden" id="recent-entries-submit" name="recent-entries-submit" value="1" /> 603 <?php 604 } 605 606 function wp_widget_recent_comments($args) { 607 global $wpdb, $comments, $comment; 608 extract($args, EXTR_SKIP); 609 $options = get_option('widget_recent_comments'); 610 $title = empty($options['title']) ? __('Recent Comments') : $options['title']; 611 if ( !$number = (int) $options['number'] ) 612 $number = 5; 613 else if ( $number < 1 ) 614 $number = 1; 615 else if ( $number > 15 ) 616 $number = 15; 617 618 if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 619 $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number"); 620 wp_cache_add( 'recent_comments', $comments, 'widget' ); 621 } 622 ?> 623 610 624 <?php echo $before_widget; ?> 611 625 <?php echo $before_title . $title . $after_title; ?> 612 <ul id="recentcomments"> 613 <?php foreach ( $comments as $comment ) { ?> 614 <li class="recentcomments"><?php echo sprintf( __( '%1$s on %2$s' ), get_comment_author_link(), '<a href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' ); ?></li> 615 <?php } ?> 626 <ul id="recentcomments"><?php 627 if ( $comments ) : foreach ($comments as $comment) : 628 echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 629 endforeach; endif;?></ul> 630 <?php echo $after_widget; ?> 631 <?php 632 } 633 634 function wp_delete_recent_comments_cache() { 635 wp_cache_delete( 'recent_comments', 'widget' ); 636 } 637 add_action( 'comment_post', 'wp_delete_recent_comments_cache' ); 638 add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' ); 639 640 function wp_widget_recent_comments_control() { 641 $options = $newoptions = get_option('widget_recent_comments'); 642 if ( $_POST["recent-comments-submit"] ) { 643 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"])); 644 $newoptions['number'] = (int) $_POST["recent-comments-number"]; 645 } 646 if ( $options != $newoptions ) { 647 $options = $newoptions; 648 update_option('widget_recent_comments', $options); 649 delete_recent_comments_cache(); 650 } 651 $title = htmlspecialchars($options['title'], ENT_QUOTES); 652 if ( !$number = (int) $options['number'] ) 653 $number = 5; 654 ?> 655 <p><label for="recent-comments-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="recent-comments-title" name="recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p> 656 <p><label for="recent-comments-number"><?php _e('Number of comments to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-comments-number" name="recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p> 657 <input type="hidden" id="recent-comments-submit" name="recent-comments-submit" value="1" /> 658 <?php 659 } 660 661 function wp_widget_recent_comments_style() { 662 ?> 663 <style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style> 664 <?php 665 } 666 667 function wp_widget_recent_comments_register() { 668 register_sidebar_widget(__('Recent Comments'), 'wp_widget_recent_comments', null, 'recent-comments'); 669 register_widget_control(__('Recent Comments'), 'wp_widget_recent_comments_control', 320, 90, 'recent-comments'); 670 671 if ( is_active_widget('wp_widget_recent_comments') ) 672 add_action('wp_head', 'wp_widget_recent_comments_style'); 673 } 674 675 function wp_widget_rss($args, $number = 1) { 676 require_once(ABSPATH . WPINC . '/rss.php'); 677 extract($args); 678 $options = get_option('widget_rss'); 679 if ( isset($options['error']) && $options['error'] ) 680 return; 681 $num_items = (int) $options[$number]['items']; 682 $show_summary = $options[$number]['show_summary']; 683 if ( empty($num_items) || $num_items < 1 || $num_items > 10 ) $num_items = 10; 684 $url = $options[$number]['url']; 685 while ( strstr($url, 'http') != $url ) 686 $url = substr($url, 1); 687 if ( empty($url) ) 688 return; 689 $rss = fetch_rss_summary($url, array( 'link', 'title', 'description' ) ); 690 $link = wp_specialchars(strip_tags($rss->channel['link']), 1); 691 while ( strstr($link, 'http') != $link ) 692 $link = substr($link, 1); 693 $desc = wp_specialchars(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES)), 1); 694 $title = $options[$number]['title']; 695 if ( empty($title) ) 696 $title = htmlentities(strip_tags($rss->channel['title'])); 697 if ( empty($title) ) 698 $title = $desc; 699 if ( empty($title) ) 700 $title = __('Unknown Feed'); 701 $url = wp_specialchars(strip_tags($url), 1); 702 if ( file_exists(dirname(__FILE__) . '/rss.png') ) 703 $icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png'; 704 else 705 $icon = get_option('siteurl').'/wp-includes/images/rss.png'; 706 $title = "<a class='rsswidget' href='$url' title='Syndicate this content'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>"; 707 ?> 708 <?php echo $before_widget; ?> 709 <?php $title ? print($before_title . $title . $after_title) : null; ?> 710 <ul> 711 <?php 712 if ( is_array( $rss->items ) ) { 713 $rss->items = array_slice($rss->items, 0, $num_items); 714 foreach ($rss->items as $item ) { 715 while ( strstr($item['link'], 'http') != $item['link'] ) 716 $item['link'] = substr($item['link'], 1); 717 $link = wp_specialchars(strip_tags($item['link']), 1); 718 $title = wp_specialchars(strip_tags($item['title']), 1); 719 if ( empty($title) ) 720 $title = __('Untitled'); 721 $desc = ''; 722 if ( $show_summary ) { 723 $summary = '<div class="rssSummary">' . $item['description'] . '</div>'; 724 } else { 725 if ( isset( $item['description'] ) && is_string( $item['description'] ) ) 726 $desc = str_replace(array("\n", "\r"), ' ', wp_specialchars(strip_tags(html_entity_decode($item['description'], ENT_QUOTES)), 1)); 727 $summary = ''; 728 } 729 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>$summary</li>"; 730 } 731 } else { 732 echo __('<li>An error has occured; the feed is probably down. Try again later.</li>'); 733 } 734 ?> 616 735 </ul> 617 736 <?php echo $after_widget; ?> 618 737 <?php 619 } 620 } 621 622 function wp_widget_recent_comments_control() { 623 $options = $newoptions = get_option( 'wp_widget_recent_comments' ); 624 625 if ( isset( $_POST['recent-comments-submit'] ) ) { 626 $newoptions['title'] = strip_tags( stripslashes( $_POST['recent-comments-title'] ) ); 627 628 if ( $newoptions != $options ) { 629 $options = $newoptions; 630 update_option( 'wp_widget_recent_comments', $options ); 738 } 739 740 function wp_widget_rss_control($number) { 741 $options = $newoptions = get_option('widget_rss'); 742 if ( $_POST["rss-submit-$number"] ) { 743 $newoptions[$number]['items'] = (int) $_POST["rss-items-$number"]; 744 $url = strip_tags(stripslashes($_POST["rss-url-$number"])); 745 $newoptions[$number]['title'] = trim(strip_tags(stripslashes($_POST["rss-title-$number"])));print_r($_POST); 746 if ( $url !== $options[$number]['url'] ) { 747 require_once(ABSPATH . WPINC . '/rss.php'); 748 $rss = fetch_rss_summary($url); 749 if ( is_object($rss) && $rss->status == 200 ) { 750 $newoptions[$number]['url'] = $url; 751 $newoptions[$number]['error'] = false; 752 } else { 753 $newoptions[$number]['error'] = true; 754 $newoptions[$number]['url'] = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); 755 $error = sprintf(__('Error in RSS %1$d: %2$s', 'sandbox'), $number, $newoptions[$number]['error']); 756 } 631 757 } 632 758 } 633 634 $title = htmlspecialchars( $options['title'], ENT_QUOTES ); 635 ?> 636 <p><label for="recent-comments-title"><?php _e( 'Title:' ); ?> <input type="text" style="width:250px" id="recent-comments-title" name="recent-comments-title" value="<?php echo $title; ?>" /></label></p> 637 <input type="hidden" name="recent-comments-submit" id="recent-comments-submit" value="1" /> 638 <?php 639 } 640 641 function wp_widget_recent_comments_wphead() { 642 ?> 643 <style type="text/css"> 644 .recentcomments a { 645 display: inline !important; 646 padding: 0 !important; 647 margin: 0 !important; 648 } 649 </style> 650 <?php 651 } 652 653 function wp_widget_recent_comments_register() { 654 register_sidebar_widget( array( 'Recent Comments', '' ), 'wp_widget_recent_comments' ); 655 register_widget_control( array( 'Recent Comments', '' ), 'wp_widget_recent_comments_control' ); 656 657 if ( is_active_widget( 'wp_widget_recent_comments' ) ) { 658 add_action( 'wp_head', 'wp_widget_recent_comments_wphead' ); 659 } 660 } 661 662 function wp_widget_rss( $args, $i = 1 ) { 663 extract( $args ); 664 665 if ( file_exists( ABSPATH . WPINC . '/rss.php' ) ) { 666 require_once ABSPATH . WPINC . '/rss.php'; 667 } else { 668 require_once ABSPATH . WPINC . '/rss-functions.php'; 669 } 670 671 $options = get_option( 'wp_widget_rss' ); 672 673 $number_items = (int) $options[$i]['number_items']; 674 $show_summary = $options[$i]['show_summary']; 675 676 if ( empty( $number_items ) || $number_items < 1 || $number_items > 10 ) { 677 $number_items = 10; 678 } 679 680 $url = $options[$i]['url']; 681 682 if ( empty( $url ) ) { 683 return; 684 } 685 686 while ( strstr( $url, 'http' ) != $url ) { 687 $url = substr( $url, 1 ); 688 } 689 690 $rss = fetch_rss( $url ); 691 692 $link = wp_specialchars( strip_tags( $rss->channel['link'] ), 1 ); 693 694 while ( strstr( $link, 'http' ) != $link ) { 695 $link = substr( $link, 1 ); 696 } 697 698 $desc = wp_specialchars( strip_tags( html_entity_decode( $rss->channel['description'], ENT_QUOTES ) ), 1 ); 699 700 $title = $options[$i]['title']; 701 702 if ( empty( $title ) ) { 703 $title = htmlentities( strip_tags( $rss->channel['title'] ) ); 704 } 705 706 if ( empty( $title ) ) { 707 $title = $desc; 708 } 709 710 if ( empty( $title ) ) { 711 $title = __( 'Unknown Feed' ); 712 } 713 714 $url = wp_specialchars( strip_tags( $url ), 1 ); 715 716 if ( file_exists( ABSPATH . 'wp-content/rss.png' ) ) { 717 $icon = get_bloginfo( 'wpurl' ) . '/wp-content/rss.png'; 718 } else { 719 $icon = get_bloginfo( 'wpurl' ) . '/wp-includes/images/rss.png'; 720 } 721 722 $h2 = '<a href="%1$s" class="rsswidget" title="%2$s"><img src="%3$s" style="width:14px;height:14px" alt="%4$s" /></a> <a href="%5$s" class="rsswidget" title="%6$s">%7$s</a>'; 723 $h2 = sprintf( $h2, $url, __( 'Syndicate this content' ), $icon, __( 'RSS' ), $link, $desc, $title ); 724 ?> 725 <?php echo $before_widget; ?> 726 <?php echo $before_title . $h2 . $after_title; ?> 727 <ul> 728 <?php 729 if ( is_array( $rss->items ) ) { 730 $rss->items = array_slice( $rss->items, 0, $number_items ); 731 732 foreach ( $rss->items as $item ) { 733 while ( strstr( $item['link'], 'http' ) != $item['link'] ) { 734 $item['link'] = substr( $item['link'], 1 ); 735 } 736 737 $link = wp_specialchars( strip_tags( $item['link'] ), 1 ); 738 $title = wp_specialchars( strip_tags( $item['title'] ), 1 ); 739 740 if ( empty( $title ) ) { 741 $title = __( 'Untitled' ); 742 } 743 744 $desc = ''; 745 746 if ( $show_summary ) { 747 $summary = '<div class="rssSummary">' . $item['description'] . '</div>'; 748 } else { 749 $desc = str_replace( array( "\r", "\n" ), ' ', wp_specialchars( strip_tags( html_entity_decode( $item['description'], ENT_QUOTES ) ), 1 ) ); 750 $summary = ''; 751 } 752 ?> 753 <li><a class="rsswidget" href="<?php echo $link; ?>" title="<?php echo $desc; ?>"><?php echo $title; ?></a><?php echo $summary; ?></li> 754 <?php 755 } 756 } else { 757 ?> 758 <li><?php _e( 'An error has occurred; the feed is probably down. Try again later.' ); ?></li> 759 <?php 760 } 761 ?> 762 <?php echo $after_widget; ?> 763 <?php 764 } 765 766 function wp_widget_rss_control( $i ) { 767 $options = $newoptions = get_option( 'wp_widget_rss' ); 768 769 if ( isset( $_POST['rss-submit-' . $i] ) ) { 770 $newoptions[$i]['number_items'] = (int) $_POST['rss-items-' . $i]; 771 $newoptions[$i]['url'] = strip_tags( stripslashes( $_POST['rss-url-' . $i] ) ); 772 $newoptions[$i]['title'] = trim( strip_tags( stripslashes( $_POST['rss-title-' . $i] ) ) ); 773 774 if ( $newoptions != $options ) { 775 $options = $newoptions; 776 update_option( 'wp_widget_rss', $options ); 777 } 778 } 779 780 $url = htmlspecialchars( $options[$i]['url'], ENT_QUOTES ); 781 $number_items = (int) $options[$i]['number_items']; 782 $title = htmlspecialchars( $options[$i]['title'], ENT_QUOTES ); 783 784 if ( empty( $number_items ) || $number_items < 1 ) { 785 $number_items = 10; 786 } 787 ?> 788 <p style="text-align:center;"><?php _e( 'Enter the RSS feed URL here:' ); ?></p> 789 <input style="width: 400px;" id="rss-url-<?php echo $i; ?>" name="rss-url-<?php echo $i; ?>" type="text" value="<?php echo $url; ?>" /> 790 <p style="text-align:center;"><?php _e( 'Give the feed a title (optional):' ); ?></p> 791 <input style="width: 400px;" id="rss-title-<?php echo $i; ?>" name="rss-title-<?php echo $i; ?>" type="text" value="<?php echo $title; ?>" /> 792 <p style="text-align:center; line-height: 30px;"><?php _e('How many items would you like to display?', 'widgets'); ?> <select id="rss-items-<?php echo $i; ?>" name="rss-items-<?php echo $i; ?>"><?php for ( $j = 1; $j <= 10; $j++ ) echo "<option value='$j' ".($i==$j ? "selected='selected'" : '').">$j</option>"; ?></select></p> 793 <input type="hidden" id="rss-submit-<?php echo $i; ?>" name="rss-submit-<?php echo $i; ?>" value="1" /> 759 if ( $options != $newoptions ) { 760 $options = $newoptions; 761 update_option('widget_rss', $options); 762 } 763 $url = htmlspecialchars($options[$number]['url'], ENT_QUOTES); 764 $items = (int) $options[$number]['items']; 765 $title = htmlspecialchars($options[$number]['title'], ENT_QUOTES); 766 if ( empty($items) || $items < 1 ) $items = 10; 767 ?> 768 <p style="text-align:center;"><?php _e('Enter the RSS feed URL here:'); ?></p> 769 <input style="width: 400px;" id="rss-url-<?php echo "$number"; ?>" name="rss-url-<?php echo "$number"; ?>" type="text" value="<?php echo $url; ?>" /> 770 <p style="text-align:center;"><?php _e('Give the feed a title (optional):'); ?></p> 771 <input style="width: 400px;" id="rss-title-<?php echo "$number"; ?>" name="rss-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" /> 772 <p style="text-align:center; line-height: 30px;"><?php _e('How many items would you like to display?'); ?> <select id="rss-items-<?php echo $number; ?>" name="rss-items-<?php echo $number; ?>"><?php for ( $i = 1; $i <= 10; ++$i ) echo "<option value='$i' ".($items==$i ? "selected='selected'" : '').">$i</option>"; ?></select></p> 773 <input type="hidden" id="rss-submit-<?php echo "$number"; ?>" name="rss-submit-<?php echo "$number"; ?>" value="1" /> 794 774 <?php 795 775 } 796 776 797 777 function wp_widget_rss_setup() { 798 $options = $newoptions = get_option( 'wp_widget_rss' ); 799 800 if ( isset( $_POST['rss-number-submit'] ) ) { 801 $i = (int) $_POST['rss-number']; 802 803 if ( $i > 9 ) { 804 $number = 9; 805 } elseif ( $i < 1 ) { 806 $number = 1; 807 } 808 809 $newoptions['number'] = $i; 810 811 if ( $newoptions != $options ) { 812 $options = $newoptions; 813 update_option( 'wp_widget_rss', $options ); 814 widget_rss_register( $options['number'] ); 815 } 778 $options = $newoptions = get_option('widget_rss'); 779 if ( isset($_POST['rss-number-submit']) ) { 780 $number = (int) $_POST['rss-number']; 781 if ( $number > 9 ) $number = 9; 782 if ( $number < 1 ) $number = 1; 783 $newoptions['number'] = $number; 784 } 785 if ( $options != $newoptions ) { 786 $options = $newoptions; 787 update_option('widget_rss', $options); 788 widget_rss_register($options['number']); 816 789 } 817 790 } 818 791 819 792 function wp_widget_rss_page() { 820 $options = get_option( 'wp_widget_rss' ); 821 822 $i = $options['number']; 793 $options = $newoptions = get_option('widget_rss'); 823 794 ?> 824 795 <div class="wrap"> 825 <form method="post"> 826 <h2><?php _e( 'RSS Feed Widgets' ); ?></h2> 827 828 <p style="line-height:30px"><?php _e( 'How many RSS widgets would you like?' ); ?> 829 <select id="rss-number" name="rss-number" value="<?php echo $i; ?>"> 830 <?php for ( $j = 1; $j < 10; $j++ ) { ?> 831 <option value="<?php echo $j; ?>"<?php 832 if ( $i == $j ) { 833 echo ' selected="selected"'; 834 } 835 ?>><?php echo $j; ?></option> 836 <?php } ?> 837 </select> 838 </p> 796 <form method="POST"> 797 <h2><?php _e('RSS Feed Widgets'); ?></h2> 798 <p style="line-height: 30px;"><?php _e('How many RSS widgets would you like?'); ?> 799 <select id="rss-number" name="rss-number" value="<?php echo $options['number']; ?>"> 800 <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?> 801 </select> 802 <span class="submit"><input type="submit" name="rss-number-submit" id="rss-number-submit" value="<?php _e('Save'); ?>" /></span></p> 839 803 </form> 840 804 </div> … … 843 807 844 808 function wp_widget_rss_register() { 845 $options = get_option( 'wp_widget_rss' ); 846 847 $i = $options['number']; 848 849 if ( $i < 1 ) { 850 $i = 1; 851 } elseif ( $i > 9 ) { 852 $i = 9; 853 } 854 855 for ( $j = 1; $j <= 9; $j++ ) { 856 $name = array( 'RSS %s', '', $j ); 857 register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_rss' : '', $j ); 858 register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_rss_control' : '', 410, 200, $j ); 859 } 860 861 add_action( 'sidebar_admin_setup', 'wp_widget_rss_setup' ); 862 add_action( 'sidebar_admin_page', 'wp_widget_rss_page' ); 863 864 if ( is_active_widget( 'wp_widget_rss' ) ) { 865 add_action( 'wp_head', 'wp_widget_rss_wphead' ); 866 } 867 } 868 869 function wp_widget_rss_wphead() { 870 ?> 871 <style type="text/css"> 872 a.rsswidget { 873 display: inline !important; 874 } 875 876 a.rsswidget img { 877 background: orange; 878 color: white; 879 } 880 </style> 881 <?php 809 $options = get_option('widget_rss'); 810 $number = $options['number']; 811 if ( $number < 1 ) $number = 1; 812 if ( $number > 9 ) $number = 9; 813 for ($i = 1; $i <= 9; $i++) { 814 $name = sprintf(__('RSS %d'), $i); 815 $id = "rss-$i"; // Never never never translate an id 816 register_sidebar_widget($name, $i <= $number ? 'widget_rss' : /* unregister */ '', null, $id, $i); 817 register_widget_control($name, $i <= $number ? 'widget_rss_control' : /* unregister */ '', 410, 200, $id, $i); 818 } 819 add_action('sidebar_admin_setup', 'wp_widget_rss_setup'); 820 add_action('sidebar_admin_page', 'wp_widget_rss_page'); 882 821 } 883 822 884 823 function wp_widgets_init() { 885 824 global $wp_register_widget_defaults; 886 825 887 826 $wp_register_widget_defaults = true; 888 827 828 register_sidebar_widget(__('Pages'), 'wp_widget_pages', null, 'pages'); 829 register_widget_control(__('Pages'), 'wp_widget_pages_control', 300, 90, 'pages'); 830 register_sidebar_widget(__('Calendar'), 'wp_widget_calendar', null, 'calendar'); 831 register_widget_control(__('Calendar'), 'wp_widget_calendar_control', 300, 90, 'calendar'); 832 register_sidebar_widget(__('Archives'), 'wp_widget_archives', null, 'archives'); 833 register_widget_control(__('Archives'), 'wp_widget_archives_control', 300, 90, 'archives'); 834 register_sidebar_widget(__('Links'), 'wp_widget_links', null, 'links'); 835 register_sidebar_widget(__('Meta'), 'wp_widget_meta', null, 'meta'); 836 register_widget_control(__('Meta'), 'wp_widget_meta_control', 300, 90, 'meta'); 837 register_sidebar_widget(__('Search'), 'wp_widget_search', null, 'search'); 838 register_sidebar_widget(__('Categories'), 'wp_widget_categories', null, 'categories'); 839 register_widget_control(__('Categories'), 'wp_widget_categories_control', 300, 150, 'categories'); 840 register_sidebar_widget(__('Recent Posts'), 'wp_widget_recent_entries', null, 'recent-posts'); 841 register_widget_control(__('Recent Posts'), 'wp_widget_recent_entries_control', 300, 90, 'recent-posts'); 889 842 wp_widget_text_register(); 890 843 wp_widget_rss_register(); 891 844 wp_widget_recent_comments_register(); 892 893 register_sidebar_widget( 'Pages', 'wp_widget_pages' ); 894 register_widget_control( 'Pages', 'wp_widget_pages_control', 300, 90 ); 895 896 register_sidebar_widget( 'Calendar', 'wp_widget_calendar' ); 897 register_widget_control( 'Calendar', 'wp_widget_calendar_control', 300, 90 ); 898 899 register_sidebar_widget( 'Archives', 'wp_widget_archives' ); 900 register_widget_control( 'Archives', 'wp_widget_archives_control', 300, 90 ); 901 902 register_sidebar_widget( 'Links', 'wp_widget_links' ); 903 904 register_sidebar_widget( 'Meta', 'wp_widget_meta' ); 905 register_widget_control( 'Meta', 'wp_widget_meta_control', 300, 90 ); 906 907 register_sidebar_widget( 'Search', 'wp_widget_search' ); 908 909 register_sidebar_widget( 'Categories', 'wp_widget_categories' ); 910 register_widget_control( 'Categories', 'wp_widget_categories_control', 300, 150 ); 911 912 register_sidebar_widget( 'Recent Posts', 'wp_widget_recent_entries' ); 913 845 914 846 $wp_register_widget_defaults = false; 915 916 do_action( 'widgets_init');917 } 918 919 ?> 847 848 do_action('widgets_init'); 849 } 850 851 ?>
Note: See TracChangeset
for help on using the changeset viewer.