\n\n";
// We're already filtering dynamic_sidebar_params obove
add_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' ); // here there be hackery
dynamic_sidebar( 'wp_dashboard' );
remove_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' );
echo "
\n
\n\n\n";
}
/**
* Makes sidebar_widgets option reflect the dashboard settings.
*
* @since unknown
*
* @return array WordPress Dashboard Widgets list.
*/
function wp_dashboard_sidebars_widgets() { // hackery
return $GLOBALS['wp_dashboard_sidebars'];
}
// Modifies sidbar params on the fly to set up ids, class names, titles for each widget (called once per widget)
// Switches widget to edit mode if $_GET['edit']
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $params
* @return unknown
*/
function wp_dashboard_dynamic_sidebar_params( $params ) {
global $wp_registered_widgets, $wp_registered_widget_controls;
$sidebar_defaults = array('widget_id' => 0, 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '');
extract( $sidebar_defaults, EXTR_PREFIX_ALL, 'sidebar' );
extract( $params[0], EXTR_PREFIX_ALL, 'sidebar' );
if ( !isset($wp_registered_widgets[$sidebar_widget_id]) || !is_array($wp_registered_widgets[$sidebar_widget_id]) ) {
return $params;
}
$widget_defaults = array('id' => '', 'width' => '', 'height' => '', 'class' => '', 'feed_link' => '', 'all_link' => '', 'notice' => false, 'error' => false);
extract( $widget_defaults, EXTR_PREFIX_ALL, 'widget' );
extract( $wp_registered_widgets[$sidebar_widget_id], EXTR_PREFIX_ALL, 'widget' );
$the_classes = array();
if ( in_array($widget_width, array( 'third', 'fourth', 'full' ) ) )
$the_classes[] = $widget_width;
if ( 'double' == $widget_height )
$the_classes[] = 'double';
if ( $widget_class )
$the_classes[] = $widget_class;
// Add classes to the widget holder
if ( $the_classes )
$sidebar_before_widget = str_replace( "' . ( isset($widget_all_link[1]) ? $widget_all_link[1] : __( 'View All' ) ) . '';
}
$content_class = 'dashboard-widget-content';
if ( current_user_can( 'edit_dashboard' ) && isset($wp_registered_widget_controls[$widget_id]) && is_callable($wp_registered_widget_controls[$widget_id]['callback']) ) {
// Switch this widget to edit mode
if ( isset($_GET['edit']) && $_GET['edit'] == $widget_id ) {
$content_class .= ' dashboard-widget-control';
$wp_registered_widgets[$widget_id]['callback'] = 'wp_dashboard_empty';
$sidebar_widget_name = $wp_registered_widget_controls[$widget_id]['name'];
$params[1] = 'wp_dashboard_trigger_widget_control';
$sidebar_before_widget .= '
$sidebar_after_widget";
$top_links[] = '
' . __( 'Cancel' ) . '';
} else {
$top_links[] = '
' . __( 'Edit' ) . '';
}
}
if ( $widget_feed_link )
$bottom_links[] = '
' . __( 'RSS' ) . '';
$bottom_links = apply_filters( "wp_dashboard_widget_links_$widget_id", $bottom_links );
// Could have put this in widget-content. Doesn't really matter
if ( $widget_notice )
$sidebar_after_title .= "\t\t\t
$widget_notice
\n\n";
if ( $widget_error )
$sidebar_after_title .= "\t\t\t
$widget_error
\n\n";
$sidebar_after_title .= "\t\t\t
\n\n";
// Add links to widget's title bar
if ( $top_links ) {
$sidebar_before_title .= '
';
$sidebar_after_title = '' . join( ' | ', $top_links ) . "$sidebar_after_title";
}
// Add links to bottom of widget
if ( $bottom_links )
$sidebar_after_widget .= "
" . join( ' | ', $bottom_links ) . "
";
$sidebar_after_widget .= "\t\t\t
\n\n";
foreach( array_keys( $params[0] ) as $key )
$$key = ${'sidebar_' . $key};
$params[0] = compact( array_keys( $params[0] ) );
return $params;
}
/* Dashboard Widgets */
function wp_dashboard_quick_press( $sidebar_args ) {
extract( $sidebar_args, EXTR_SKIP );
echo $before_widget;
echo $before_title;
echo $widget_name;
echo $after_title;
if ( ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) ) && 'post-quickpress-save-cont' === $_POST['action'] ) {
$post = get_post_to_edit( $_POST['post_ID'] );
} else {
$_REQUEST = array(); // hack
$post = get_default_post_to_edit();
}
?>
'rss2', 'withcomments' => 1));
remove_filter( 'option_posts_per_rss', $lambda );
$is_first = true;
if ( $comments_query->have_comments() ) {
while ( $comments_query->have_comments() ) { $comments_query->the_comment();
$comment_post_url = get_permalink( $comment->comment_post_ID );
$comment_post_title = get_the_title( $comment->comment_post_ID );
$comment_post_link = "
$comment_post_title";
$comment_link = '';
$comment_meta = sprintf( __( 'From
%1$s on %2$s %3$s' ), get_comment_author(), $comment_post_link, $comment_link );
if ( $is_first ) : $is_first = false;
?>
“”
comment_count > 1 ) : ?>
items) && 0 < count($rss->items) ) {
echo "
\n";
$rss->items = array_slice($rss->items, 0, $items);
foreach ( $rss->items as $item ) {
$publisher = '';
$site_link = '';
$link = '';
$content = '';
$date = '';
$link = clean_url( strip_tags( $item['link'] ) );
if ( isset( $item['author_uri'] ) )
$site_link = clean_url( strip_tags( $item['author_uri'] ) );
if ( !$publisher = wp_specialchars( strip_tags( isset($item['dc']['publisher']) ? $item['dc']['publisher'] : $item['author_name'] ) ) )
$publisher = __( 'Somebody' );
if ( $site_link )
$publisher = "$publisher";
else
$publisher = "$publisher";
if ( isset($item['description']) )
$content = $item['description'];
elseif ( isset($item['summary']) )
$content = $item['summary'];
elseif ( isset($item['atom_content']) )
$content = $item['atom_content'];
else
$content = __( 'something' );
$content = wp_html_excerpt($content, 50) . ' ...';
if ( $link )
$text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
else
$text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
if ( $show_date ) {
if ( $show_author || $show_summary )
$text .= _c( ' on %4$s|feed_display' );
$date = wp_specialchars( strip_tags( isset($item['pubdate']) ? $item['pubdate'] : $item['published'] ) );
$date = strtotime( $date );
$date = gmdate( get_option( 'date_format' ), $date );
}
echo "\t- " . sprintf( _c( "$text|feed_display" ), $publisher, $link, $content, $date ) . "
\n";
}
echo "
\n";
} else {
echo '
' . __('This dashboard widget queries Google Blog Search so that when another blog links to your site it will show up here. It has found no incoming links… yet. It’s okay — there is no rush.') . "
\n";
}
}
/**
* {@internal Missing Short Description}}
*
* $sidebar_args are handled by wp_dashboard_empty().
*
* @since unknown
*
* @param int $widget_id
*/
function wp_dashboard_rss_output( $widget_id ) {
$widgets = get_option( 'dashboard_widget_options' );
wp_widget_rss_output( $widgets[$widget_id] );
}
/**
* Display secondary dashboard RSS widget feed.
*
* $sidebar_args are handled by wp_dashboard_empty().
*
* @since unknown
*
* @return unknown
*/
function wp_dashboard_secondary_output() {
$widgets = get_option( 'dashboard_widget_options' );
@extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
$rss = @fetch_rss( $url );
if ( !isset($rss->items) || 0 == count($rss->items) )
return false;
echo "
\n";
$rss->items = array_slice($rss->items, 0, $items);
foreach ($rss->items as $item ) {
$title = wp_specialchars($item['title']);
list($author,$post) = explode( ':', $title, 2 );
$link = clean_url($item['link']);
echo "\t- $post - $author
\n";
}
echo "
\n
\n";
}
/**
* Display plugins most popular, newest plugins, and recently updated widget text.
*
* $sidebar_args are handled by wp_dashboard_empty().
*
* @since unknown
*/
function wp_dashboard_plugins_output() {
$popular = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
$new = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
$updated = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
if ( !isset($$feed->items) || 0 == count($$feed->items) )
continue;
$$feed->items = array_slice($$feed->items, 0, 5);
$item_key = array_rand($$feed->items);
// Eliminate some common badly formed plugin descriptions
while ( ( null !== $item_key = array_rand($$feed->items) ) && false !== strpos( $$feed->items[$item_key]['description'], 'Plugin Name:' ) )
unset($$feed->items[$item_key]);
if ( !isset($$feed->items[$item_key]) )
continue;
$item = $$feed->items[$item_key];
// current bbPress feed item titles are: user on "topic title"
if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) )
$title = $matches[1];
else // but let's make it forward compatible if things change
$title = $item['title'];
$title = wp_specialchars( $title );
$description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) );
list($link, $frag) = explode( '#', $item['link'] );
$link = clean_url($link);
if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
$slug = $matches[1];
else
$slug = '';
$ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
'&TB_iframe=true&width=600&height=800';
echo "
$label
\n";
echo "
(" . __( 'Install' ) . ")\n";
echo "
$description
\n";
}
}
/**
* Checks to see if all of the feed url in $check_urls are cached.
*
* If $check_urls is empty, look for the rss feed url found in the dashboard
* widget optios of $widget_id. If cached, call $callback, a function that
* echoes out output for this widget. If not cache, echo a "Loading..." stub
* which is later replaced by AJAX call (see top of /wp-admin/index.php)
*
* @since unknown
*
* @param int $widget_id
* @param callback $callback
* @param array $check_urls RSS feeds
* @return bool False on failure. True on success.
*/
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
$loading = '
' . __( 'Loading…' ) . '
';
if ( empty($check_urls) ) {
$widgets = get_option( 'dashboard_widget_options' );
if ( empty($widgets[$widget_id]['url']) ) {
echo $loading;
return false;
}
$check_urls = array( $widgets[$widget_id]['url'] );
}
require_once( ABSPATH . WPINC . '/rss.php' );
init(); // initialize rss constants
$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
foreach ( $check_urls as $check_url ) {
$status = $cache->check_cache( $check_url );
if ( 'HIT' !== $status ) {
echo $loading;
return false;
}
}
if ( $callback && is_callable( $callback ) ) {
$args = array_slice( func_get_args(), 2 );
array_unshift( $args, $widget_id );
call_user_func_array( $callback, $args );
}
return true;
}
/**
* Empty widget used for JS/AJAX created output.
*
* Callback inserts content between before_widget and after_widget. Used when
* widget is in edit mode. Can also be used for custom widgets.
*
* @since unknown
*
* @param array $sidebar_args
* @param callback $callback Optional. Only used in edit mode.
*/
function wp_dashboard_empty( $sidebar_args, $callback = false ) {
extract( $sidebar_args, EXTR_SKIP );
echo $before_widget;
echo $before_title;
echo $widget_name;
echo $after_title;
// When in edit mode, the callback passed to this function is the widget_control callback
if ( $callback && is_callable( $callback ) ) {
$args = array_slice( func_get_args(), 2 );
array_unshift( $args, $widget_id );
call_user_func_array( $callback, $args );
}
echo $after_widget;
}
/* Dashboard Widgets Controls. See also wp_dashboard_empty() */
// Temp
function wp_dashboard_empty_control() {
echo "This feature isn't enabled in this prototype.";
}
// Calls widget_control callback
/**
* Calls widget control callback.
*
* @since unknown
*
* @param int $widget_control_id Registered Widget ID.
*/
function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
global $wp_registered_widget_controls;
if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_registered_widget_controls[$widget_control_id]) && is_callable($wp_registered_widget_controls[$widget_control_id]['callback']) )
call_user_func_array( $wp_registered_widget_controls[$widget_control_id]['callback'], $wp_registered_widget_controls[$widget_control_id]['params'] );
}
/**
* The RSS dashboard widget control.
*
* Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
* from RSS-type widgets.
*
* @since unknown
*
* @param array $args Expects 'widget_id' and 'form_inputs'.
* @return bool|null False if no widget_id is given. Null on success.
*/
function wp_dashboard_rss_control( $args ) {
extract( $args );
if ( !$widget_id )
return false;
if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
$widget_options = array();
if ( !isset($widget_options[$widget_id]) )
$widget_options[$widget_id] = array();
$number = 1; // Hack to use wp_widget_rss_form()
$widget_options[$widget_id]['number'] = $number;
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
$_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
$widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
// title is optional. If black, fill it if possible
if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
require_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss($widget_options[$widget_id]['url']);
$widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->channel['title']));
}
update_option( 'dashboard_widget_options', $widget_options );
}
wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
}
?>