From 03e6c2ed9a733349b14c5af6c1d3a81589d75377 Mon Sep 17 00:00:00 2001 From: rob1n Date: Tue, 24 Apr 2007 01:05:17 +0000 Subject: [PATCH] Widgets for 2.3. fixes #4186 git-svn-id: http://svn.automattic.com/wordpress/trunk@5297 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/menu.php | 1 + wp-admin/widgets.css | 215 +++++ wp-admin/widgets.js.php | 138 +++ wp-admin/widgets.php | 239 +++++ wp-includes/images/rss.png | Bin 0 -> 3341 bytes wp-includes/widgets.php | 1814 ++++++++++++++++++++++++++++++++++++ wp-settings.php | 7 +- 7 files changed, 2413 insertions(+), 1 deletion(-) create mode 100644 wp-admin/widgets.css create mode 100644 wp-admin/widgets.js.php create mode 100644 wp-admin/widgets.php create mode 100644 wp-includes/images/rss.png create mode 100644 wp-includes/widgets.php diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 383abeb79..4e0901583 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -67,6 +67,7 @@ $submenu['plugins.php'][5] = array(__('Plugins'), 'activate_plugins', 'plugins.p $submenu['plugins.php'][10] = array(__('Plugin Editor'), 'edit_plugins', 'plugin-editor.php'); $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); +$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_themes', 'widgets.php' ); $submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php'); // Create list of page plugin hook names. diff --git a/wp-admin/widgets.css b/wp-admin/widgets.css new file mode 100644 index 000000000..fc5acfcfb --- /dev/null +++ b/wp-admin/widgets.css @@ -0,0 +1,215 @@ +body { + height: 100%; +} + +#sbadmin #zones { + width: px; + -moz-user-select: none; + -khtml-user-select: none; + user-select: none; +} + +#sbreset { + float: left; + margin: 1px 0; +} + +.dropzone { + float: left; + margin-right: 10px; + padding: 5px; + border: 1px solid #bbb; + background-color: #f0f8ff; +} + +.dropzone h3 { + text-align: center; + color: #333; +} + +.dropzone ul { + list-style-type: none; + width: 240px; + height: px; + float: left; + margin: 0; + padding: 0; +} + +* .module, #lastmodule { + width: 238px; + padding: 0; + margin: 5px 0; + cursor: move; + display: block; + border: 1px solid #ccc; + background-color: #fbfbfb; + text-align: left; + line-height: 25px; +} + +* .handle, #lastmodule span { + display: block; + width: 216px; + padding: 0 10px; + border-top: 1px solid #f2f2f2; + border-right: 1px solid #e8e8e8; + border-bottom: 1px solid #e8e8e8; + border-left: 1px solid #f2f2f2; +} + +* .popper { + margin: 0; + display: inline; + position: absolute; + top: 3px; + right: 3px; + overflow: hidden; + text-align: center; + height: 16px; + font-size: 18px; + line-height: 14px; + cursor: pointer; + padding: 0 3px 1px; + border-top: 4px solid #6da6d1; + background: url( images/fade-butt.png ) -5px 0px; +} + +* html .popper { + padding: 1px 6px 0; + font-size: 16px; +} + +#sbadmin p.submit { + padding-right: 10px; + clear: left; +} + +.placematt { + position: absolute; + cursor: default; + margin: 10px 0 0; + padding: 0; + width: 238px; + background-color: #ffe; +} + +* html .placematt { + margin-top: 5px; +} + +.placematt h4 { + text-align: center; + margin-bottom: 5px; +} + +.placematt span { + padding: 0 10px 10px; + text-align: justify; +} + +#palettediv { + border: 1px solid #bbb; + background-color: #f0f8ff; + height: 180px; + margin-top: 10px; +} + +#palettediv h3 { + text-align: center; + color: #333; +} + +#palettediv ul { + padding: 0 0 0 10px; +} + +#palettediv .module, #lastmodule { + margin-right: 10px; + float: left; + width: 120px; +} + +#palettediv .handle, #lastmodule span { + height: 40px; + font-size: 90%; + width: 110px; + padding: 0 5px; +} + +#palettediv .popper { + visibility: hidden; +} + +#lastmodule { + visibility: hidden; +} + +* html #palettediv ul { + margin: 0; + padding: 0 0 0 10px; +} + +* html #palettediv .module { + float: none; + display: inline; +} + +#controls { + height: 0px; +} + +.control { + position: absolute; + display: block; + background: #f9fcfe; + padding: 0; +} + +.controlhandle { + cursor: move; + background-color: #6da6d1; + border-bottom: 2px solid #448abd; + color: #333; + display: block; + margin: 0 0 5px; + padding: 4px; + font-size: 120%; +} + +.controlcloser { + cursor: pointer; + font-size: 120%; + display: block; + position: absolute; + top: 2px; + right: 8px; + padding: 0 3px; + font-weight: bold; +} + +.controlform { + margin: 20px 30px; +} + +.controlform p { + text-align: center; +} + +.control .checkbox { + border: none; + background: transparent; +} + +.hidden { + display: none; +} + +#shadow { + background: black; + display: none; + position: absolute; + top: 0px; + left: 0px; + width: 100%; +} \ No newline at end of file diff --git a/wp-admin/widgets.js.php b/wp-admin/widgets.js.php new file mode 100644 index 000000000..f090d0944 --- /dev/null +++ b/wp-admin/widgets.js.php @@ -0,0 +1,138 @@ + $sidebar ) { + $cols[] = '\'' . $index . '\''; + } + $cols = implode( ', ', $cols ); + + $widgets = array(); + foreach ( $wp_registered_widgets as $name => $widget ) { + $widgets[] = '\'' . $widget['id'] . '\''; + } + $widgets = implode( ', ', $widgets ); +?> +var cols = []; +var widgets = []; +var controldims = new Array; + $widget ) : ?> + controldims['control'] = new Array; + controldims['control']['width'] = ; + controldims['control']['height'] = ; + +function initWidgets() { + $widget ) : ?> + $('popper').onclick = function() {popControl('control');}; + $('closer').onclick = function() {unpopControl('control');}; + new Draggable('control', {revert:false,handle:'controlhandle',starteffect:function(){},endeffect:function(){},change:function(o){dragChange(o);}}); + if ( true && window.opera ) + $('control').style.border = '1px solid #bbb'; + + if ( true && window.opera ) + $('shadow').style.background = 'transparent'; + new Effect.Opacity('shadow', {to:0.0}); + widgets.map(function(o) {o='widgetprefix-'+o; Position.absolutize(o); Position.relativize(o);} ); + $A(Draggables.drags).map(function(o) {o.startDrag(null); o.finishDrag(null);}); + for ( var n in Draggables.drags ) { + if ( Draggables.drags[n].element.id == 'lastmodule' ) { + Draggables.drags[n].destroy(); + break; + } + } + resetPaletteHeight(); +} +function resetDroppableHeights() { + var max = 6; + cols.map(function(o) {var c = $(o).childNodes.length; if ( c > max ) max = c;} ); + var height = 35 * ( max + 1); + cols.map(function(o) {h = (($(o).childNodes.length + 1) * 35); $(o).style.height = (h > 280 ? h : 280) + 'px';} ); +} +function resetPaletteHeight() { + var p = $('palette'), pd = $('palettediv'), last = $('lastmodule'); + p.appendChild(last); + if ( Draggables.activeDraggable && last.id == Draggables.activeDraggable.element.id ) + last = last.previousSibling; + var y1 = Position.cumulativeOffset(last)[1] + last.offsetHeight; + var y2 = Position.cumulativeOffset(pd)[1] + pd.offsetHeight; + var dy = y1 - y2; + pd.style.height = (pd.offsetHeight + dy + 9) + "px"; +} +function maxHeight(elm) { + htmlheight = document.body.parentNode.clientHeight; + bodyheight = document.body.clientHeight; + var height = htmlheight > bodyheight ? htmlheight : bodyheight; + $(elm).style.height = height + 'px'; +} +function dragChange(o) { + el = o.element ? o.element : $(o); + var p = Position.page(el); + var right = p[0]; + var top = p[1]; + var left = $('shadow').offsetWidth - (el.offsetWidth + left); + var bottom = $('shadow').offsetHeight - (el.offsetHeight + top); + if ( right < 1 ) el.style.left = 0; + if ( top < 1 ) el.style.top = 0; + if ( left < 1 ) el.style.left = (left + right) + 'px'; + if ( bottom < 1 ) el.style.top = (top + bottom) + 'px'; +} +function popControl(elm) { + el = $(elm); + el.style.width = controldims[elm]['width'] + 'px'; + el.style.height = controldims[elm]['height'] + 'px'; + var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2; + var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2; + el.style.position = 'absolute'; + el.style.right = '' + x + 'px'; + el.style.top = '' + y + 'px'; + el.style.zIndex = 1000; + el.className='control'; + $('shadow').onclick = function() {unpopControl(elm);}; + window.onresize = function(){maxHeight('shadow');dragChange(elm);}; + popShadow(); +} +function popShadow() { + maxHeight('shadow'); + var shadow = $('shadow'); + shadow.style.zIndex = 999; + shadow.style.display = 'block'; + new Effect.Opacity('shadow', {duration:0.5, from:0.0, to:0.2}); +} +function unpopShadow() { + new Effect.Opacity('shadow', {to:0.0}); + $('shadow').style.display = 'none'; +} +function unpopControl(el) { + $(el).className='hidden'; + unpopShadow(); +} +function serializeAll() { + $sidebar ) : ?> + $('order').value = Sortable.serialize(''); + +} +function updateAll() { + resetDroppableHeights(); + resetPaletteHeight(); + cols.map(function(o){ + var pm = $(o+'placematt'); + if ( $(o).childNodes.length == 0 ) { + pm.style.display = 'block'; + Position.absolutize(o+'placematt'); + } else { + pm.style.display = 'none'; + } + }); +} +function noSelection(event) { + if ( document.selection ) { + var range = document.selection.createRange(); + range.collapse(false); + range.select(); + return false; + } +} +addLoadEvent(updateAll); +addLoadEvent(initWidgets); +Event.observe(window, 'resize', resetPaletteHeight); \ No newline at end of file diff --git a/wp-admin/widgets.php b/wp-admin/widgets.php new file mode 100644 index 000000000..8a2bf2035 --- /dev/null +++ b/wp-admin/widgets.php @@ -0,0 +1,239 @@ + + +≡' + : ''; + + $output = '
  • %2$s
  • '; + + printf( $output, $sanitized_name, $name . $popper ); +} + +$title = __( 'Widgets' ); +$parent_file = 'themes.php'; + +require_once 'admin-header.php'; + +if ( count( $wp_registered_sidebars ) < 1 ) { +?> +
    +

    + +

    follow these instructions.' ); /* TODO: article on codex */; ?>

    +
    + $sidebar ) { + $postindex = $index . 'order'; + + parse_str( $_POST[$postindex], $order ); + + $new_order = $order[$index]; + + if ( is_array( $new_order ) ) { + foreach ( $new_order as $sanitized_name ) { + foreach ( $wp_registered_widgets as $name => $widget ) { + if ( $sanitized_name == $widget['id'] ) { + $sidebars_widgets[$index][] = $name; + } + } + } + } + } + + wp_set_sidebars_widgets( $sidebars_widgets ); + break; + } +} + +ksort( $wp_registered_widgets ); + +$inactive_widgets = array(); + +foreach ( $wp_registered_widgets as $name => $widget ) { + $is_active = false; + + foreach ( $wp_registered_sidebars as $index => $sidebar ) { + if ( is_array( $sidebars_widgets[$index] ) && in_array( $name, $sidebars_widgets[$index] ) ) { + $is_active = true; + break; + } + } + + if ( !$is_active ) { + $inactive_widgets[] = $name; + } +} + +$containers = array( 'palette' ); + +foreach ( $wp_registered_sidebars as $index => $sidebar ) { + $containers[] = $index; +} + +$c_string = ''; + +foreach ( $containers as $container ) { + $c_string .= '"' . $container . '",'; +} + +$c_string = substr( $c_string, 0, -1 ); + +if ( isset( $_POST['action'] ) ) { +?> +
    +

    View site »' ), get_bloginfo( 'url' ) . '/' ); ?>

    +
    + +
    +

    + +

    + +
    +
    + $sidebar ) { + ?> + + +
    +

    + +
    + +

    + +
    +
    + +
      + +
    +
    + + +
    + +
    + +
    +

    + +
      + +
    • +
    +
    + + + +

    + + + +

    + +
    + $widget ) { ?> + + +
    +
    + +
    +
    + +
    + + + + \ No newline at end of file diff --git a/wp-includes/images/rss.png b/wp-includes/images/rss.png new file mode 100644 index 0000000000000000000000000000000000000000..6e7b676b345588a734dce002843a442520931170 GIT binary patch literal 3341 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 Xq0QFqM~$u500000NkvXXu0mjf25>N; literal 0 HcmV?d00001 diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php new file mode 100644 index 000000000..33802acd9 --- /dev/null +++ b/wp-includes/widgets.php @@ -0,0 +1,1814 @@ + 1 ) { + if ( strpos( $name, '%d' ) === false ) { + $name = $name . ' %d'; + } + + $args['name'] = sprintf( $name, $i ); + } + + register_sidebar( $args ); + } + } +} + +if ( !function_exists( 'register_sidebar' ) ) { + function register_sidebar( $args = array() ) { + global $wp_registered_sidebars; + + if ( is_string( $args ) ) { + parse_str( $args, $args ); + } + + $defaults = array( + 'name' => sprintf( __( 'Sidebar %d' ), count( $wp_registered_sidebars ) + 1 ), + 'before_widget' => '
  • ', + 'after_widget' => "
  • \n", + 'before_title' => '

    ', + 'after_title' => "

    \n" + ); + + $defaults = apply_filters( 'register_sidebar_defaults', $defaults, $args ); + + $sidebar = array_merge( $defaults, $args ); + + $sidebar['id'] = sanitize_title( $sidebar['name'] ); + + $wp_registered_sidebars[$sidebar['id']] = $sidebar; + + return $sidebar['id']; + } +} + +if ( !function_exists( 'unregister_sidebar' ) ) { + function unregister_sidebar( $name ) { + global $wp_registered_sidebars; + + if ( isset( $wp_registered_sidebars[$name] ) ) { + unset( $wp_registered_sidebars[$name] ); + } + } +} + +if ( !function_exists( 'register_sidebar_widget' ) ) { + function register_sidebar_widget( $name, $output_callback, $classname = '' ) { + global $wp_registered_widgets, $wp_register_widget_defaults; + + if ( is_array( $name ) ) { + $id = sanitize_title( sprintf( $name[0], $name[2] ) ); + $name = sprintf( __( $name[0], $name[1] ), $name[2] ); + } else { + $id = sanitize_title( $name ); + $name = __( $name ); + } + + if ( ( empty( $classname ) || !is_string( $classname ) ) && is_string( $output_callback ) ) { + $classname = $output_callback; + } + + $widget = array( + 'id' => $id, + 'callback' => $output_callback, + 'classname' => $classname, + 'params' => array_slice( func_get_args(), 2 ) + ); + + if ( empty( $output_callback ) ) { + unset( $wp_registered_widgets[$name] ); + } elseif ( is_callable( $output_callback ) && ( !isset( $wp_registered_widgets[$name] ) || !$wp_register_widget_defaults ) ) { + $wp_registered_widgets[$name] = $widget; + } + } +} + +if ( !function_exists( 'unregister_sidebar_widget' ) ) { + function unregister_sidebar_widget( $name ) { + register_sidebar_widget( $name, '' ); + unregister_widget_control( $name ); + } +} + +if ( !function_exists( 'register_widget_control' ) ) { + function register_widget_control( $name, $control_callback, $width = 300, $height = 200 ) { + global $wp_registered_widget_controls, $wp_registered_sidebar_defaults; + + $width = (int) $width; + $height = (int) $height; + + if ( is_array( $name ) ) { + $id = sanitize_title( sprintf( $name[0], $name[2] ) ); + $name = sprintf( __( $name[0], $name[1] ), $name[2] ); + } else { + $id = sanitize_title( $name ); + $name = __( $name ); + } + + $width = ( $width > 90 ) ? $width + 60 : 360; + $height = ( $height > 60 ) ? $height + 40 : 240; + + if ( empty( $control_callback ) ) { + unset( $wp_registered_widget_controls[$name] ); + } elseif ( !isset( $wp_registered_widget_controls[$name] ) || !$wp_registered_sidebar_defaults ) { + $wp_registered_widget_controls[$name] = array( + 'id' => $id, + 'callback' => $control_callback, + 'width' => $width, + 'height' => $height, + 'params' => array_slice( func_get_args(), 4 ) + ); + } + } +} + +if ( !function_exists( 'unregister_widget_control' ) ) { + function unregister_widget_control( $name ) { + register_sidebar_control( $name, '' ); + } +} + +if ( !function_exists( 'dynamic_sidebar' ) ) { + function dynamic_sidebar( $name = 1 ) { + global $wp_registered_sidebars, $wp_registered_widgets; + + if ( is_int( $name ) ) { + $index = sanitize_title( __( 'Sidebar' ) . ' ' . $name ); + $name = sprintf( __( 'Sidebar %d' ), $name ); + } else { + $index = sanitize_title( $name ); + } + + $sidebars_widgets = wp_get_sidebars_widgets(); + + $sidebar = $wp_registered_sidebars[$index]; + + if ( empty( $sidebar ) || !is_array( $sidebars_widgets[$index] ) || empty( $sidebars_widgets[$index] ) ) { + return false; + } + + $did_one = false; + + foreach ( $sidebars_widgets[$index] as $name ) { + $callback = $wp_registered_widgets[$name]['callback']; + + $params = array_merge( array( $sidebar ), (array) $wp_registered_widgets[$name]['params'] ); + $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $wp_registered_widgets[$name]['id'], $wp_registered_widgets[$name]['classname'] ); + + if ( is_callable( $callback ) ) { + call_user_func_array( $callback, $params ); + $did_one = true; + } + } + + return $did_one; + } +} + +if ( !function_exists( 'is_active_widget' ) ) { + function is_active_widget( $callback ) { + global $wp_registered_widgets; + + $sidebars_widgets = wp_get_sidebars_widgets(); + + if ( is_array( $sidebars_widgets ) ) { + foreach ( $sidebars_widgets as $sidebar => $widgets ) { + if ( is_array( $widgets) ) { + foreach ( $widgets as $widget ) { + if ( $wp_registered_widgets[$widget]['callback'] == $callback ) { + return true; + } + } + } + } + } + + return false; + } +} + +if ( !function_exists( 'is_dynamic_sidebar' ) ) { + function is_dynamic_sidebar() { + global $wp_registered_sidebars, $wp_registered_widgets; + + $sidebars_widgets = wp_get_sidebars_widgets(); + + foreach ( $wp_registered_sidebars as $index => $sidebar ) { + if ( count( $sidebars_widgets[$index] ) > 0 ) { + foreach ( $sidebars_widgets[$index] as $widget ) { + if ( array_key_exists( $widget, $wp_registered_sidebars ) ) { + return true; + } + } + } + } + + return false; + } +} + +/* Internal Functions */ + +function wp_get_sidebars_widgets() { + return get_option( 'wp_sidebars_widgets' ); +} + +function wp_set_sidebars_widgets( $sidebars_widgets ) { + update_option( 'wp_sidebars_widgets', $sidebars_widgets ); +} + +function wp_get_widget_defaults() { + global $wp_registered_sidebars; + + $defaults = array(); + + foreach ( $wp_registered_sidebars as $index => $sidebar ) { + $defaults[$index] = array(); + } + + return $defaults; +} + +/* Default Widgets */ + +function wp_widget_pages( $args ) { + extract( $args ); + + $options = get_option( 'wp_widget_pages' ); + + $title = ( empty( $options['title'] ) ) ? __( 'Pages' ) : $options['title']; + + echo $before_widget . $before_title . $title . $after_title . "
      \n"; + wp_list_pages( 'title_li=' ); + echo "
    \n" . $after_widget; +} + +function wp_widget_pages_control() { + $options = $newoptions = get_option( 'wp_widget_pages' ); + + if ( isset( $_POST['pages-submit'] ) ) { + $newoptions['title'] = strip_tags( stripslashes( $_POST['pages-title'] ) ); + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_pages', $options ); + } + } + + $title = htmlspecialchars( $options['title'], ENT_QUOTES ); +?> +

    + + $before_title, 'title_after' => $after_title, + 'category_before' => $before_widget, 'category_after' => $after_widget + ) ); + } +} + +function wp_widget_search( $args ) { + extract( $args ); +?> + +
    +

    +
    +
    + + + + +
      + +
    + + +

    +

    + + + + + + + +

    + + + + +
    + +
    + + +

    + + + + +
    + + + + + + 9 ) { + $i = 9; + } elseif ( $i < 1 ) { + $i = 1; + } + + $newoptions['number'] = $i; + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_text', $options ); + } + } +} + +function wp_widget_text_page() { + $options = get_option( 'widget_text' ); + + $i = $options['number']; +?> +
    +
    +

    + +

    + + +

    +
    +
    + 9 ) { + $i = 9; + } + + for ( $j = 1; $j <= 9; $j++ ) { + $name = array( 'Text %s', '', $i ); + register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_text' : '', $j ); + register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_text_control' : '', 460, 350, $j ); + } + + add_action( 'sidebar_admin_setup', 'wp_widget_text_setup' ); + add_action( 'sidebar_admin_page', 'wp_widget_text_page' ); +} + +function wp_widget_categories( $args ) { + extract( $args ); + + $options = get_option( 'wp_widget_categories' ); + + $title = ( empty( $options['title'] ) ) ? __( 'Categories' ) : $options['title']; + $c = ( $options['count'] ) ? '1' : '0'; + $h = ( $options['hierarchical'] ) ? '1' : '0'; +?> + + +
      + +
    + + +

    +

    +

    + +have_posts() ) { + return; + } +?> + + +
      + have_posts() ) { + $query->the_post(); ?> +
    • + +
    + +get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5" ); + + if ( is_array( $comments ) && count( $comments ) > 0 ) { +?> + + +
      + +
    • comment_post_ID ) . '#comment-' . $comment->comment_ID . '">' . get_the_title( $comment->comment_post_ID ) . '' ); ?>
    • + +
    + + +

    + + + + 10 ) { + $number_items = 10; + } + + $url = $options[$i]['url']; + + if ( empty( $url ) ) { + return; + } + + while ( strstr( $url, 'http' ) != $url ) { + $url = substr( $url, 1 ); + } + + $rss = fetch_rss( $url ); + + $link = wp_specialchars( strip_tags( $rss->channel['link'] ), 1 ); + + while ( strstr( $link, 'http' ) != $link ) { + $link = substr( $link, 1 ); + } + + $desc = wp_specialchars( strip_tags( html_entity_decode( $rss->channel['description'], ENT_QUOTES ) ), 1 ); + + $title = $options[$i]['title']; + + if ( empty( $title ) ) { + $title = htmlentities( strip_tags( $rss->channel['title'] ) ); + } + + if ( empty( $title ) ) { + $title = $desc; + } + + if ( empty( $title ) ) { + $title = __( 'Unknown Feed' ); + } + + $url = wp_specialchars( strip_tags( $url ), 1 ); + + if ( file_exists( ABSPATH . 'wp-content/rss.png' ) ) { + $icon = get_bloginfo( 'wpurl' ) . '/wp-content/rss.png'; + } else { + $icon = get_bloginfo( 'wpurl' ) . '/wp-includes/images/rss.png'; + } + + $h2 = '%4$s %7$s'; + $h2 = sprintf( $h2, $url, __( 'Syndicate this content' ), $icon, __( 'RSS' ), $link, $desc, $title ); +?> + + +
      + items ) ) { + $rss->items = array_slice( $rss->items, 0, $number_items ); + + foreach ( $rss->items as $item ) { + while ( strstr( $item['link'], 'http' ) != $item['link'] ) { + $item['link'] = substr( $item['link'], 1 ); + } + + $link = wp_specialchars( strip_tags( $item['link'] ), 1 ); + $title = wp_specialchars( strip_tags( $item['title'] ), 1 ); + + if ( empty( $title ) ) { + $title = __( 'Untitled' ); + } + + $desc = ''; + + if ( $show_summary ) { + $summary = '
      ' . $item['description'] . '
      '; + } else { + $desc = str_replace( array( "\r", "\n" ), ' ', wp_specialchars( strip_tags( html_entity_decode( $item['description'], ENT_QUOTES ) ), 1 ) ); + $summary = ''; + } + ?> +
    • + +
    • + + + +

      + +

      + +

      + + 9 ) { + $number = 9; + } elseif ( $i < 1 ) { + $number = 1; + } + + $newoptions['number'] = $i; + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_rss', $options ); + widget_rss_register( $options['number'] ); + } + } +} + +function wp_widget_rss_page() { + $options = get_option( 'wp_widget_rss' ); + + $i = $options['number']; +?> +
      +
      +

      + +

      + +

      +
      +
      + 9 ) { + $i = 9; + } + + for ( $j = 1; $j <= 9; $j++ ) { + $name = array( 'RSS %s', '', $j ); + register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_rss' : '', $j ); + register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_rss_control' : '', 410, 200, $j ); + } + + add_action( 'sidebar_admin_setup', 'wp_widget_rss_setup' ); + add_action( 'sidebar_admin_page', 'wp_widget_rss_page' ); + + if ( is_active_widget( 'wp_widget_rss' ) ) { + add_action( 'wp_head', 'wp_widget_rss_wphead' ); + } +} + +function wp_widget_rss_wphead() { +?> + + + 1 ) { + if ( strpos( $name, '%d' ) === false ) { + $name = $name . ' %d'; + } + + $args['name'] = sprintf( $name, $i ); + } + + register_sidebar( $args ); + } + } +} + +if ( !function_exists( 'register_sidebar' ) ) { + function register_sidebar( $args = array() ) { + global $wp_registered_sidebars; + + if ( is_string( $args ) ) { + parse_str( $args, $args ); + } + + $defaults = array( + 'name' => sprintf( __( 'Sidebar %d' ), count( $wp_registered_sidebars + 1 ) ), + 'before_widget' => '
    • ', + 'after_widget' => "
    • \n", + 'before_title' => '

      ', + 'after_title' => "

      \n" + ); + + $defaults = apply_filters( 'register_sidebar_defaults', $defaults, $args ); + + $sidebar = array_merge( $defaults, $args ); + + $sidebar['id'] = sanitize_title( $sidebar['name'] ); + + $wp_registered_sidebars[$sidebar['id']] = $sidbar; + + return $sidebar['id']; + } +} + +if ( !function_exists( 'unregister_sidebar' ) ) { + function unregister_sidebar( $name ) { + global $wp_registered_sidebars; + + if ( isset( $wp_registered_sidebars[$name] ) ) { + unset( $wp_registered_sidebars[$name] ); + } + } +} + +if ( !function_exists( 'register_sidebar_widget' ) ) { + function register_sidebar_widget( $name, $output_callback, $classname = '' ) { + global $wp_registered_widgets, $wp_register_widget_defaults; + + if ( is_array( $name ) ) { + $id = sanitize_title( sprintf( $name[0], $name[2] ) ); + $name = sprintf( __( $name[0], $name[1] ), $name[2] ); + } else { + $id = sanitize_title( $name ); + $name = __( $name ); + } + + if ( ( empty( $classname ) || !is_string( $classname ) ) && is_string( $output_callback ) ) { + $classname = $output_callback; + } + + $widget = array( + 'id' => $id, + 'callback' => $output_callback, + 'classname' => $classname, + 'params' => array_slice( func_get_args(), 2 ) + ); + + if ( empty( $output_callback ) ) { + unset( $wp_registered_widgets[$name] ); + } elseif ( is_callable( $output_callback ) && ( !isset( $wp_registered_widgets[$name] ) || !$wp_register_widget_defaults ) ) { + $wp_registered_widgets[$name] = $widget; + } + } +} + +if ( !function_exists( 'unregister_sidebar_widget' ) ) { + function unregister_sidebar_widget( $name ) { + register_sidebar_widget( $name, '' ); + unregister_widget_control( $name ); + } +} + +if ( !function_exists( 'register_widget_control' ) ) { + function register_widget_control( $name, $control_callback, $width = 300, $height = 200 ) { + global $wp_registered_widget_controls, $wp_register_sidebar_defaults; + + $width = (int) $width; + $height = (int) $height; + + if ( is_array( $name ) ) { + $id = sanitize_title( sprintf( $name[0], $name[2] ) ); + $name = sprintf( __( $name[0], $name[1] ), $name[2] ); + } else { + $id = sanitize_title( $name ); + $name = __( $name ); + } + + $width = ( $width > 90 ) ? $width + 60 : 360; + $height = ( $height > 60 ) ? $height + 40 : 240; + + if ( empty( $control_callback ) ) { + unset( $wp_registered_widget_controls[$name] ); + } elseif ( !isset( $wp_registered_widget_controls[$name] ) || !$wp_registered_sidebar_defaults ) { + $wp_registered_widget_controls[$name] = array( + 'id' => $id, + 'callback' => $control_callback, + 'width' => $width, + 'height' => $height, + 'params' => array_slice( func_get_args(), 4 ) + ); + } + } +} + +if ( !function_exists( 'unregister_widget_control' ) ) { + function unregister_widget_control( $name ) { + register_sidebar_control( $name, '' ); + } +} + +if ( !function_exists( 'dynamic_sidebar' ) ) { + function dynamic_sidebar( $name = 1 ) { + global $wp_registered_sidebars, $wp_registered_widgets; + + if ( is_int( $name ) ) { + $index = sanitize_title( __( 'Sidebar' ) . ' ' . $name ); + $name = sprintf( __( 'Sidebar %d' ), $name ); + } else { + $index = sanitize_title( $name ); + } + + $sidebars_widgets = wp_get_sidebars_widgets(); + + $sidebar = $wp_registered_sidebars[$index]; + + if ( empty( $sidebar ) || !is_array( $sidebars_widgets[$index] ) || empty( $sidebars_widgets[$index] ) ) { + return false; + } + + $did_one = false; + + foreach ( $sidebars_widgets[$index] as $name ) { + $callback = $wp_registered_widgets[$name]['callback']; + + $params = array_merge( array( $sidebar ), (array) $wp_registered_widgets[$name]['params'] ); + $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $wp_registered_widgets[$name]['id'], $wp_registered_widgets[$name]['classname'] ); + + if ( is_callable( $callback ) ) { + call_user_func_array( $callback, $params ); + $did_one = true; + } + } + + return $did_one; + } +} + +if ( !function_exists( 'is_active_widget' ) ) { + function is_active_widget( $callback ) { + global $wp_registered_widgets; + + $sidebars_widgets = wp_get_sidebars_widgets(); + + if ( is_array( $sidebars_widgets ) ) { + foreach ( $sidebars_widgets as $sidebar => $widgets ) { + if ( is_array( $widgets) ) { + foreach ( $widgets as $widget ) { + if ( $wp_registered_widgets[$widget]['callback'] == $callback ) { + return true; + } + } + } + } + } + + return false; + } +} + +if ( !function_exists( 'is_dynamic_sidebar' ) ) { + function is_dynamic_sidebar() { + global $wp_registered_sidebars, $wp_registered_widgets; + + $sidebars_widgets = wp_get_sidebars_widgets(); + + foreach ( $wp_registered_sidebars as $index => $sidebar ) { + if ( count( $sidebars_widgets[$index] ) > 0 ) { + foreach ( $sidebars_widgets[$index] as $widget ) { + if ( array_key_exists( $widget, $wp_registered_sidebars ) ) { + return true; + } + } + } + } + + return false; + } +} + +/* Internal Functions (not admin-related) */ + +function wp_get_sidebars_widgets() { + return get_option( 'wp_sidebars_widgets' ); +} + +/* Default Widgets */ + +function wp_widget_pages( $args ) { + extract( $args ); + + $options = get_option( 'wp_widget_pages' ); + + $title = ( empty( $options['title'] ) ) ? __( 'Pages' ) : $options['title']; + + echo $before_widget . $before_title . $title . $after_title . "
        \n"; + wp_list_pages( 'title_li=' ); + echo "
      \n" . $after_widget; +} + +function wp_widget_pages_control() { + $options = $newoptions = get_option( 'wp_widget_pages' ); + + if ( isset( $_POST['pages-submit'] ) ) { + $newoptions['title'] = strip_tags( stripslashes( $_POST['pages-title'] ) ); + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_pages', $options ); + } + } + + $title = htmlspecialchars( $options['title'], ENT_QUOTES ); +?> +

      + + $before_title, 'title_after' => $after_title ) ); + } +} + +function wp_widget_search( $args ) { + extract( $args ); +?> + +
      +

      +
      +
      + + + + +
        + +
      + + +

      +

      + + + + + + + +

      + + + + +
      + +
      + + +

      + + + + +
      + + + + + + 9 ) { + $i = 9; + } elseif ( $i < 1 ) { + $i = 1; + } + + $newoptions['number'] = $i; + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_text', $options ); + } + } +} + +function wp_widget_text_page() { + $options = get_option( 'widget_text' ); + + $i = $option['number']; +?> +
      +
      +

      + +

      + + +

      +
      +
      + 9 ) { + $i = 9; + } + + for ( $j = 1; $j <= 9; $j++ ) { + $name = array( 'Text %s', '', $i ); + register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_text' : '', $j ); + register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_text_control' : '', 460, 350, $j ); + } + + add_action( 'sidebar_admin_setup', 'wp_widget_text_setup' ); + add_action( 'sidebar_admin_page', 'wp_widget_text_page' ); +} + +function wp_widget_categories( $args ) { + extract( $args ); + + $options = get_option( 'wp_widget_categories' ); + + $title = ( empty( $options['title'] ) ) ? __( 'Categories' ) : $options['title']; + $c = ( $options['count'] ) ? '1' : '0'; + $h = ( $options['hierarchical'] ) ? '1' : '0'; +?> + + +
        + +
      + + +

      +

      +

      + +have_posts() ) { +?> + + +
        + have_posts() ) { + $query->the_post(); + ?> +
      • + +
      + +get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5" ); + + if ( is_array( $comments ) && count( $comments ) > 0 ) { +?> + + +
        + +
      • comment_post_ID ) . '#comment-' . $comment->comment_ID . '">' . get_the_title( $comment->comment_post_ID ) . '' ); ?>
      • + +
      + + +

      + + + + 10 ) { + $number_items = 10; + } + + $url = $options[$i]['url']; + + if ( empty( $url ) ) { + return; + } + + while ( strstr( $url, 'http' ) != $url ) { + $url = substr( $url, 1 ); + } + + $rss = fetch_rss( $url ); + + $link = wp_specialchars( strip_tags( $rss->channel['link'] ), 1 ); + + while ( strstr( $link, 'http' ) != $link ) { + $link = substr( $link, 1 ); + } + + $desc = wp_specialchars( strip_tags( html_entity_decode( $rss->channel['description'], ENT_QUOTES ) ), 1 ); + + $title = $options[$i]['title']; + + if ( empty( $title ) ) { + $title = htmlentities( strip_tags( $rss->channel['title'] ) ); + } + + if ( empty( $title ) ) { + $title = $desc; + } + + if ( empty( $title ) ) { + $title = __( 'Unknown Feed' ); + } + + $url = wp_specialchars( strip_tags( $url ), 1 ); + + $icon = get_option( 'url' ) . '/wp-includes/images/rss.png'; + + $title = '%4$s %7$s'; + $title = sprintf( $title, $url, __( 'Syndicate this content' ), $icon, __( 'RSS' ), $link, $desc, $title ); +?> + + +
        + items ) ) { + $rss->items = array_slice( $rss->items, 0, $number_items ); + + foreach ( $rss->items as $item ) { + while ( strstr( $item['link'], 'http' ) != $item['link'] ) { + $item['link'] = substr( $item['link'], 1 ); + } + + $link = wp_specialchars( strip_tags( $item['link'] ), 1 ); + $title = wp_specialchars( strip_tags( $item['title'] ), 1 ); + + if ( empty( $title ) ) { + $title = __( 'Untitled' ); + } + + $desc = ''; + + if ( $show_summary ) { + $summary = '
        ' . $item['description'] . '
        '; + } else { + $desc = str_replace( array( "\r", "\n" ), ' ', wp_specialchars( strip_tags( html_entity_decode( $item['description'], ENT_QUOTES ) ), 1 ) ); + $summary = ''; + } + ?> +
      • + +
      • + + + +

        + +

        + +

        + + 9 ) { + $number = 9; + } elseif ( $i < 1 ) { + $number = 1; + } + + $newoptions['number'] = $i; + + if ( $newoptions != $options ) { + $options = $newoptions; + update_option( 'wp_widget_rss', $options ); + widget_rss_register( $options['number'] ); + } + } +} + +function wp_widget_rss_page() { + $options = get_option( 'wp_widget_rss' ); + + $i = $options['number']; +?> +
        +
        +

        + +

        + +

        +
        +
        + 9 ) { + $i = 9; + } + + for ( $j = 1; $j <= 9; $j++ ) { + $name = array( 'RSS %s', '', $j ); + register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_rss' : '', $j ); + register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_rss_control' : '', 410, 200, $j ); + } + + add_action( 'sidebar_admin_setup', 'wp_widget_rss_setup' ); + add_action( 'sidebar_admin_page', 'wp_widget_rss_page' ); + + if ( is_active_widget( 'wp_widget_rss' ) ) { + add_action( 'wp_head', 'wp_widget_rss_wphead' ); + } +} + +function wp_widget_rss_wphead() { +?> + + \ No newline at end of file diff --git a/wp-settings.php b/wp-settings.php index 3bfa481a2..980283af7 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -168,6 +168,7 @@ require (ABSPATH . WPINC . '/cron.php'); require (ABSPATH . WPINC . '/version.php'); require (ABSPATH . WPINC . '/deprecated.php'); require (ABSPATH . WPINC . '/script-loader.php'); +require (ABSPATH . WPINC . '/widgets.php'); if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) { // Used to guarantee unique hash cookies @@ -260,7 +261,11 @@ function shutdown_action_hook() { } register_shutdown_function('shutdown_action_hook'); +// widgets_init() BEFORE init, so plugins that launch on init can +// do stuff with default widgets +wp_widgets_init(); + // Everything is loaded and initialized. do_action('init'); -?> +?> \ No newline at end of file