| 1 | <?php |
| 2 | |
| 3 | /* Global Variables */ |
| 4 | |
| 5 | $wp_registered_sidebars = array(); |
| 6 | $wp_registered_widgets = array(); |
| 7 | $wp_registered_widget_controls = array(); |
| 8 | $wp_registered_widget_styles = array(); |
| 9 | $wp_register_widget_defaults = false; |
| 10 | |
| 11 | /* Template tags & API functions */ |
| 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 ); |
| 19 | } |
| 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'; |
| 27 | } |
| 28 | |
| 29 | $args['name'] = sprintf( $name, $i ); |
| 30 | } |
| 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' ); |
| 234 | } |
| 235 | |
| 236 | function wp_set_sidebars_widgets( $sidebars_widgets ) { |
| 237 | update_option( 'wp_sidebars_widgets', $sidebars_widgets ); |
| 238 | } |
| 239 | |
| 240 | function wp_get_widget_defaults() { |
| 241 | global $wp_registered_sidebars; |
| 242 | |
| 243 | $defaults = array(); |
| 244 | |
| 245 | foreach ( $wp_registered_sidebars as $index => $sidebar ) { |
| 246 | $defaults[$index] = array(); |
| 247 | } |
| 248 | |
| 249 | return $defaults; |
| 250 | } |
| 251 | |
| 252 | /* Default Widgets */ |
| 253 | |
| 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 | |
| 261 | echo $before_widget . $before_title . $title . $after_title . "<ul>\n"; |
| 262 | wp_list_pages( 'title_li=' ); |
| 263 | echo "</ul>\n" . $after_widget; |
| 264 | } |
| 265 | |
| 266 | 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 ) { |
| 286 | global $wp_db_version; |
| 287 | extract( $args ); |
| 288 | |
| 289 | if ( $wp_db_version < 3582 ) { |
| 290 | get_links_list(); |
| 291 | } 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 ); |
| 301 | ?> |
| 302 | <?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> |
| 306 | </form> |
| 307 | <?php echo $after_widget; ?> |
| 308 | <?php |
| 309 | } |
| 310 | |
| 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']; |
| 317 | ?> |
| 318 | <?php echo $before_widget; ?> |
| 319 | <?php echo $before_title . $title . $after_title; ?> |
| 320 | <ul> |
| 321 | <?php wp_get_archives( 'type=monthly&show_post_count=' . $c ); ?> |
| 322 | </ul> |
| 323 | <?php echo $after_widget; ?> |
| 324 | <?php |
| 325 | } |
| 326 | |
| 327 | 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']; |
| 354 | ?> |
| 355 | <?php echo $before_widget; ?> |
| 356 | <?php echo $before_title . $title . $after_title; ?> |
| 357 | <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(); ?> |
| 364 | </ul> |
| 365 | <?php echo $after_widget; ?> |
| 366 | <?php |
| 367 | } |
| 368 | |
| 369 | 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']; |
| 392 | ?> |
| 393 | <?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; ?> |
| 430 | <div class="textwidget"><?php echo $text; ?></div> |
| 431 | <?php echo $after_widget; ?> |
| 432 | <?php |
| 433 | } |
| 434 | |
| 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" /> |
| 458 | <?php |
| 459 | } |
| 460 | |
| 461 | 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 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | function wp_widget_text_page() { |
| 483 | $options = get_option( 'widget_text' ); |
| 484 | |
| 485 | $i = $options['number']; |
| 486 | ?> |
| 487 | <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> |
| 499 | </form> |
| 500 | </div> |
| 501 | <?php |
| 502 | } |
| 503 | |
| 504 | 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'; |
| 533 | ?> |
| 534 | <?php echo $before_widget; ?> |
| 535 | <?php echo $before_title . $title . $after_title; ?> |
| 536 | <ul> |
| 537 | <?php wp_list_cats( 'sort_column=name&optioncount=' . $c . '&hierarchical=' . $h ); ?> |
| 538 | </ul> |
| 539 | <?php echo $after_widget; ?> |
| 540 | <?php |
| 541 | } |
| 542 | |
| 543 | 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 | } |
| 578 | ?> |
| 579 | <?php echo $before_widget; ?> |
| 580 | <?php echo $before_title . $title . $after_title; ?> |
| 581 | <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 } ?> |
| 592 | </ul> |
| 593 | <?php echo $after_widget; ?> |
| 594 | <?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 | ?> |
| 610 | <?php echo $before_widget; ?> |
| 611 | <?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 } ?> |
| 616 | </ul> |
| 617 | <?php echo $after_widget; ?> |
| 618 | <?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 ); |
| 631 | } |
| 632 | } |
| 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 | $icon = get_option( 'url' ) . '/wp-includes/images/rss.png'; |
| 717 | |
| 718 | $title = '<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>'; |
| 719 | $title = sprintf( $title, $url, __( 'Syndicate this content' ), $icon, __( 'RSS' ), $link, $desc, $title ); |
| 720 | ?> |
| 721 | <?php echo $before_widget; ?> |
| 722 | <?php echo $before_title . $title . $after_title; ?> |
| 723 | <ul> |
| 724 | <?php |
| 725 | if ( is_array( $rss->items ) ) { |
| 726 | $rss->items = array_slice( $rss->items, 0, $number_items ); |
| 727 | |
| 728 | foreach ( $rss->items as $item ) { |
| 729 | while ( strstr( $item['link'], 'http' ) != $item['link'] ) { |
| 730 | $item['link'] = substr( $item['link'], 1 ); |
| 731 | } |
| 732 | |
| 733 | $link = wp_specialchars( strip_tags( $item['link'] ), 1 ); |
| 734 | $title = wp_specialchars( strip_tags( $item['title'] ), 1 ); |
| 735 | |
| 736 | if ( empty( $title ) ) { |
| 737 | $title = __( 'Untitled' ); |
| 738 | } |
| 739 | |
| 740 | $desc = ''; |
| 741 | |
| 742 | if ( $show_summary ) { |
| 743 | $summary = '<div class="rssSummary">' . $item['description'] . '</div>'; |
| 744 | } else { |
| 745 | $desc = str_replace( array( "\r", "\n" ), ' ', wp_specialchars( strip_tags( html_entity_decode( $item['description'], ENT_QUOTES ) ), 1 ) ); |
| 746 | $summary = ''; |
| 747 | } |
| 748 | ?> |
| 749 | <li><a class="rsswidget" href="<?php echo $link; ?>" title="<?php echo $desc; ?>"><?php echo $title; ?></a><?php echo $summary; ?></li> |
| 750 | <?php |
| 751 | } |
| 752 | } else { |
| 753 | ?> |
| 754 | <li><?php _e( 'An error has occurred; the feed is probably down. Try again later.' ); ?></li> |
| 755 | <?php |
| 756 | } |
| 757 | ?> |
| 758 | <?php echo $after_widget; ?> |
| 759 | <?php |
| 760 | } |
| 761 | |
| 762 | function wp_widget_rss_control( $i ) { |
| 763 | $options = $newoptions = get_option( 'wp_widget_rss' ); |
| 764 | |
| 765 | if ( isset( $_POST['rss-submit-' . $i] ) ) { |
| 766 | $newoptions[$i]['number_items'] = (int) $_POST['rss-items-' . $i]; |
| 767 | $newoptions[$i]['url'] = strip_tags( stripslashes( $_POST['rss-url-' . $i] ) ); |
| 768 | $newoptions[$i]['title'] = trim( strip_tags( stripslashes( $_POST['rss-title-' . $i] ) ) ); |
| 769 | |
| 770 | if ( $newoptions != $options ) { |
| 771 | $options = $newoptions; |
| 772 | update_option( 'wp_widget_rss', $options ); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | $url = htmlspecialchars( $options[$i]['url'], ENT_QUOTES ); |
| 777 | $number_items = (int) $options[$i]['number_items']; |
| 778 | $title = htmlspecialchars( $options[$i]['title'], ENT_QUOTES ); |
| 779 | |
| 780 | if ( empty( $number_items ) || $number_items < 1 ) { |
| 781 | $number_items = 10; |
| 782 | } |
| 783 | ?> |
| 784 | <p style="text-align:center;"><?php _e( 'Enter the RSS feed URL here:' ); ?></p> |
| 785 | <input style="width: 400px;" id="rss-url-<?php echo $i; ?>" name="rss-url-<?php echo $i; ?>" type="text" value="<?php echo $url; ?>" /> |
| 786 | <p style="text-align:center;"><?php _e( 'Give the feed a title (optional):' ); ?></p> |
| 787 | <input style="width: 400px;" id="rss-title-<?php echo $i; ?>" name="rss-title-<?php echo $i; ?>" type="text" value="<?php echo $title; ?>" /> |
| 788 | <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> |
| 789 | <input type="hidden" id="rss-submit-<?php echo $i; ?>" name="rss-submit-<?php echo $i; ?>" value="1" /> |
| 790 | <?php |
| 791 | } |
| 792 | |
| 793 | function wp_widget_rss_setup() { |
| 794 | $options = $newoptions = get_option( 'wp_widget_rss' ); |
| 795 | |
| 796 | if ( isset( $_POST['rss-number-submit'] ) ) { |
| 797 | $i = (int) $_POST['rss-number']; |
| 798 | |
| 799 | if ( $i > 9 ) { |
| 800 | $number = 9; |
| 801 | } elseif ( $i < 1 ) { |
| 802 | $number = 1; |
| 803 | } |
| 804 | |
| 805 | $newoptions['number'] = $i; |
| 806 | |
| 807 | if ( $newoptions != $options ) { |
| 808 | $options = $newoptions; |
| 809 | update_option( 'wp_widget_rss', $options ); |
| 810 | widget_rss_register( $options['number'] ); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | function wp_widget_rss_page() { |
| 816 | $options = get_option( 'wp_widget_rss' ); |
| 817 | |
| 818 | $i = $options['number']; |
| 819 | ?> |
| 820 | <div class="wrap"> |
| 821 | <form method="post"> |
| 822 | <h2><?php _e( 'RSS Feed Widgets' ); ?></h2> |
| 823 | |
| 824 | <p style="line-height:30px"><?php _e( 'How many RSS widgets would you like?' ); ?> |
| 825 | <select id="rss-number" name="rss-number" value="<?php echo $i; ?>"> |
| 826 | <?php for ( $j = 1; $j < 10; $j++ ) { ?> |
| 827 | <option value="<?php echo $j; ?>"<?php |
| 828 | if ( $i == $j ) { |
| 829 | echo ' selected="selected"'; |
| 830 | } |
| 831 | ?>><?php echo $j; ?></option> |
| 832 | <?php } ?> |
| 833 | </select> |
| 834 | </p> |
| 835 | </form> |
| 836 | </div> |
| 837 | <?php |
| 838 | } |
| 839 | |
| 840 | function wp_widget_rss_register() { |
| 841 | $options = get_option( 'wp_widget_rss' ); |
| 842 | |
| 843 | $i = $options['number']; |
| 844 | |
| 845 | if ( $i < 1 ) { |
| 846 | $i = 1; |
| 847 | } elseif ( $i > 9 ) { |
| 848 | $i = 9; |
| 849 | } |
| 850 | |
| 851 | for ( $j = 1; $j <= 9; $j++ ) { |
| 852 | $name = array( 'RSS %s', '', $j ); |
| 853 | register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_rss' : '', $j ); |
| 854 | register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_rss_control' : '', 410, 200, $j ); |
| 855 | } |
| 856 | |
| 857 | add_action( 'sidebar_admin_setup', 'wp_widget_rss_setup' ); |
| 858 | add_action( 'sidebar_admin_page', 'wp_widget_rss_page' ); |
| 859 | |
| 860 | if ( is_active_widget( 'wp_widget_rss' ) ) { |
| 861 | add_action( 'wp_head', 'wp_widget_rss_wphead' ); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | function wp_widget_rss_wphead() { |
| 866 | ?> |
| 867 | <style type="text/css"> |
| 868 | a.rsswidget { |
| 869 | display: inline !important; |
| 870 | } |
| 871 | |
| 872 | a.rsswidget img { |
| 873 | background: orange; |
| 874 | color: white; |
| 875 | } |
| 876 | </style> |
| 877 | <?php |
| 878 | } |
| 879 | |
| 880 | function wp_widgets_init() { |
| 881 | global $wp_register_widget_defaults; |
| 882 | |
| 883 | $wp_register_widget_defaults = true; |
| 884 | |
| 885 | wp_widget_text_register(); |
| 886 | wp_widget_rss_register(); |
| 887 | wp_widget_recent_comments_register(); |
| 888 | |
| 889 | register_sidebar_widget( 'Pages', 'wp_widget_pages' ); |
| 890 | register_widget_control( 'Pages', 'wp_widget_pages_control', 300, 90 ); |
| 891 | |
| 892 | register_sidebar_widget( 'Calendar', 'wp_widget_calendar' ); |
| 893 | register_widget_control( 'Calendar', 'wp_widget_calendar_control', 300, 90 ); |
| 894 | |
| 895 | register_sidebar_widget( 'Archives', 'wp_widget_archives' ); |
| 896 | register_widget_control( 'Archives', 'wp_widget_archives_control', 300, 90 ); |
| 897 | |
| 898 | register_sidebar_widget( 'Links', 'wp_widget_links' ); |
| 899 | |
| 900 | register_sidebar_widget( 'Meta', 'wp_widget_meta' ); |
| 901 | register_widget_control( 'Meta', 'wp_widget_meta_control', 300, 90 ); |
| 902 | |
| 903 | register_sidebar_widget( 'Search', 'wp_widget_search' ); |
| 904 | |
| 905 | register_sidebar_widget( 'Categories', 'wp_widget_categories' ); |
| 906 | register_widget_control( 'Categories', 'wp_widget_categories_control', 300, 150 ); |
| 907 | |
| 908 | register_sidebar_widget( 'Recent Posts', 'wp_widget_recent_entries' ); |
| 909 | |
| 910 | $wp_register_widget_defaults = false; |
| 911 | |
| 912 | do_action( 'widgets_init' ); |
| 913 | } |
| 914 | |
| 915 | ?> |
| 916 | No newline at end of file |