crazyhorse dash see #7552

git-svn-id: http://svn.automattic.com/wordpress/trunk@8751 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-27 19:36:12 +00:00
parent 34e52c7010
commit 332d54f319
1 changed files with 270 additions and 14 deletions

View File

@ -35,6 +35,33 @@ function wp_dashboard_setup() {
array( 'all_link' => 'edit-comments.php', 'notice' => $notice, 'width' => 'half' )
);
// QuickPress Widget
if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) ) {
$view = get_permalink( $_POST['post_ID'] );
$edit = clean_url( get_edit_post_link( $_POST['post_ID'] ) );
if ( 'post-quickpress-publish' == $_POST['action'] )
$notice = sprintf( __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ), clean_url( $view ), $edit );
else
$notice = sprintf( __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ), clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
} else {
$notice = '';
}
wp_register_sidebar_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press',
array( 'all_link' => array( 'edit.php?post_status=draft', __('View All Drafts') ), 'width' => 'half', 'height' => 'double', 'notice' => $notice )
);
wp_register_widget_control( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_empty_control',
array( 'widget_id' => 'dashboard_quick_press' )
);
// Inbox Widget
wp_register_sidebar_widget( 'dashboard_inbox', __( 'Inbox' ), 'wp_dashboard_inbox',
array( 'all_link' => 'inbox.php', 'height' => 'double' )
);
wp_register_widget_control( 'dashboard_inbox', __( 'Inbox' ), 'wp_dashboard_empty_control',
array( 'widget_id' => 'dashboard_inbox' )
);
// Incoming Links Widget
if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
$update = true;
@ -106,7 +133,7 @@ function wp_dashboard_setup() {
/* Dashboard Widget Template
wp_register_sidebar_widget( $widget_id (unique slug) , $widget_title, $output_callback,
array(
'all_link' => full url for "See All" link,
'all_link' => full url for "View All" link,
'feed_link' => full url for "RSS" link,
'width' => 'fourth', 'third', 'half', 'full' (defaults to 'half'),
'height' => 'single', 'double' (defaults to 'single'),
@ -132,15 +159,23 @@ function wp_dashboard_setup() {
// Hard code the sidebar's widgets and order
$dashboard_widgets = array();
$dashboard_widgets[] = 'dashboard_inbox';
$dashboard_widgets[] = 'dashboard_quick_press';
/*
$dashboard_widgets[] = 'dashboard_recent_comments';
$dashboard_widgets[] = 'dashboard_incoming_links';
$dashboard_widgets[] = 'dashboard_primary';
if ( current_user_can( 'activate_plugins' ) )
$dashboard_widgets[] = 'dashboard_plugins';
*/
$dashboard_widgets[] = 'dashboard_secondary';
// Filter widget order
$dashboard_widgets = apply_filters( 'wp_dashboard_widgets', $dashboard_widgets );
if ( in_array( 'dashboard_quick_press', $dashboard_widgets ) ) {
// add_action( 'admin_head', 'wp_teeny_mce' );
add_action( 'admin_head', 'wp_dashboard_quick_press_js' );
}
$wp_dashboard_sidebars = array( 'wp_dashboard' => $dashboard_widgets, 'array_version' => 3.5 );
@ -205,9 +240,11 @@ function wp_dashboard_dynamic_sidebar_params( $params ) {
if ( $the_classes )
$sidebar_before_widget = str_replace( "<div class='dashboard-widget-holder ", "<div class='dashboard-widget-holder " . join( ' ', $the_classes ) . ' ', $sidebar_before_widget );
$links = array();
if ( $widget_all_link )
$links[] = '<a href="' . clean_url( $widget_all_link ) . '">' . __( 'See&nbsp;All' ) . '</a>';
$top_links = $bottom_links = array();
if ( $widget_all_link ) {
$widget_all_link = (array) $widget_all_link;
$bottom_links[] = '<a href="' . clean_url( $widget_all_link[0] ) . '">' . ( isset($widget_all_link[1]) ? $widget_all_link[1] : __( 'View All' ) ) . '</a>';
}
$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']) ) {
@ -219,22 +256,16 @@ function wp_dashboard_dynamic_sidebar_params( $params ) {
$params[1] = 'wp_dashboard_trigger_widget_control';
$sidebar_before_widget .= '<form action="' . clean_url(remove_query_arg( 'edit' )) . '" method="post">';
$sidebar_after_widget = "<div class='dashboard-widget-submit'><input type='hidden' name='sidebar' value='wp_dashboard' /><input type='hidden' name='widget_id' value='$widget_id' /><input type='submit' value='" . __( 'Save' ) . "' /></div></form>$sidebar_after_widget";
$links[] = '<a href="' . clean_url(remove_query_arg( 'edit' )) . '">' . __( 'Cancel' ) . '</a>';
$top_links[] = '<a href="' . clean_url(remove_query_arg( 'edit' )) . '">' . __( 'Cancel' ) . '</a>';
} else {
$links[] = '<a href="' . clean_url(add_query_arg( 'edit', $widget_id )) . "#$widget_id" . '">' . __( 'Edit' ) . '</a>';
$top_links[] = '<a href="' . clean_url(add_query_arg( 'edit', $widget_id )) . "#$widget_id" . '">' . __( 'Edit' ) . '</a>';
}
}
if ( $widget_feed_link )
$links[] = '<img class="rss-icon" src="' . includes_url('images/rss.png') . '" alt="' . __( 'rss icon' ) . '" /> <a href="' . clean_url( $widget_feed_link ) . '">' . __( 'RSS' ) . '</a>';
$bottom_links[] = '<img class="rss-icon" src="' . includes_url('images/rss.png') . '" alt="' . __( 'rss icon' ) . '" /> <a href="' . clean_url( $widget_feed_link ) . '">' . __( 'RSS' ) . '</a>';
$links = apply_filters( "wp_dashboard_widget_links_$widget_id", $links );
// Add links to widget's title bar
if ( $links ) {
$sidebar_before_title .= '<span>';
$sidebar_after_title = '</span><small>' . join( '&nbsp;|&nbsp;', $links ) . "</small><br class='clear' />$sidebar_after_title";
}
$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 )
@ -245,6 +276,16 @@ function wp_dashboard_dynamic_sidebar_params( $params ) {
$sidebar_after_title .= "\t\t\t<div class='$content_class'>\n\n";
// Add links to widget's title bar
if ( $top_links ) {
$sidebar_before_title .= '<span>';
$sidebar_after_title = '</span><small>' . join( '&nbsp;|&nbsp;', $top_links ) . "</small><br class='clear' />$sidebar_after_title";
}
// Add links to bottom of widget
if ( $bottom_links )
$sidebar_after_widget .= "<p class='dashboard-widget-links'>" . join( ' | ', $bottom_links ) . "</p>";
$sidebar_after_widget .= "\t\t\t</div>\n\n";
foreach( array_keys( $params[0] ) as $key )
@ -258,6 +299,216 @@ function wp_dashboard_dynamic_sidebar_params( $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();
}
?>
<form name="post" action="<?php echo clean_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
<h3 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h3>
<div class="input-text-wrap">
<input type="text" name="post_title" id="title" autocomplete="off" value="<?php echo attribute_escape( $post->post_title ); ?>" />
</div>
<h3><label for="content"><?php _e('Post') ?></label></h3>
<div class="textarea-wrap">
<textarea name="content" id="quickpress-content" class="mceEditor" rows="3" cols="15"><?php echo $post->post_content; ?></textarea>
</div>
<h3><label for="tags-input"><?php _e('Tags') ?></label></h3>
<div class="input-text-wrap">
<input type="text" name="tags_input" id="tags-input" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
</div>
<p class='field-tip'><?php _e('Separate tags with commas'); ?></p>
<p class="submit">
<input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
<input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
<?php wp_nonce_field('add-post'); ?>
<input type="submit" name="save" id="save-post" class="button" value="<?php _e('Save'); ?>" />
<input type="submit" name="save-cont" id="save-cont" class="button" value="<?php _e('Save and Continue'); ?>" />
<input type="submit" name="publish" id="publish" accesskey="p" class="button button-highlighted" value="<?php _e('Publish'); ?>" />
</p>
<?php
$drafts_query = new WP_Query( array(
'post_type' => 'post',
'what_to_show' => 'posts',
'post_status' => 'draft',
'author' => $GLOBALS['current_user']->ID,
'posts_per_page' => 5,
'orderby' => 'modified',
'order' => 'DESC'
) );
if ( $drafts_query->posts ) :
$list = array();
foreach ( $drafts_query->posts as $draft ) {
$url = get_edit_post_link( $draft->ID );
$title = get_the_title( $draft->ID );
$list[] = "<a href='$url' title='" . sprintf( __( 'Edit "%s"' ), attribute_escape( $title ) ) . "'>$title</a>";
}
?>
<h3><?php _e('Recent Drafts'); ?></h3>
<p id='recent-drafts'>
<?php echo join( ', ', $list ); ?>
</p>
<?php
endif; // drafts
?>
</form>
<?php
echo $after_widget;
}
function wp_dashboard_quick_press_js() {
?>
<script type="text/javascript">
/* <![CDATA[ */
var quickPressLoad = function($) {
var act = $('#quickpost-action');
var t = $('#quick-press').submit( function() {
if ( 'post-quickpress-save-cont' == act.val() ) {
return true;
}
var head = $('#dashboard_quick_press div.dashboard-widget').children( 'div').hide().end().find('h3 small');
head.prepend( '<img src="images/loading.gif" style="margin: 0 6px 0 0; vertical-align: middle" />' );
if ( 'post' == act.val() ) { act.val( 'post-quickpress-publish' ); }
if ( 'undefined' != typeof tinyMCE ) {
tinyMCE.get('quickpress-content').save();
tinyMCE.get('quickpress-content').remove();
}
$('#dashboard_quick_press').load( t.attr( 'action' ) + ' #dashboard_quick_press > *', t.serializeArray(), function() {
if ( 'undefined' != typeof wpTeenyMCEInit && $.isFunction( wpTeenyMCEInit ) ) { wpTeenyMCEInit(); }
quickPressLoad($);
} );
return false;
} );
$('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
$('#save-cont').click( function() { act.val( 'post-quickpress-save-cont' ); t.attr( 'action', 'post.php' ); } );
};
jQuery( quickPressLoad );
/* ]]> */
</script>
<?php
}
function wp_dashboard_inbox( $sidebar_args ) {
extract( $sidebar_args, EXTR_SKIP );
echo $before_widget;
echo $before_title;
echo $widget_name;
echo $after_title;
?>
<style type="text/css">
#inbox-filter ul {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#inbox-filter ul li {
position: relative;
padding-right: 20px;
}
#inbox-filter ul input.checkbox {
float: left;
}
#inbox-filter ul p {
float: left;
margin: 0;
margin-left: -40px;
width: 100%;
position: relative;
left: 50px;
}
#inbox-message {
margin:0 0 0 7.5em;
padding:5px;
}
</style>
<script type="text/javascript">
jQuery( function($) {
$('#inbox-filter').submit( function() { return false; } )
.find( ':button' ).click( function() {
var done = $(':checked').size().toString(), txt = (done == '1') ? '<?php _e(' item archived'); ?>' : '<?php _e(' items archived'); ?>';
$(':checked').parent().slideUp( 'normal', function() {
$('.inbox-count').text( $('#inbox-filter li:visible').size().toString() );
$('#inbox-message').addClass('updated');
$('#inbox-message').text(done+txt+" (This feature isn't enabled in this prototype)");
} );
} );
} );
</script>
<form id="inbox-filter" action="" method="get">
<p class="actions"><input type="button" value="Archive" name="archive" class="button"></p>
<div id="inbox-message"></div>
<br class="clear" />
<ul>
<?php $crazy_posts = array( '', 'some post', 'a post', 'my cool post' ); foreach ( wp_get_inbox_items() as $k => $item ) : // crazyhorse ?>
<li id="message-<?php echo $k; ?>">
<input type="checkbox" name="messages[]" value="<?php echo $k; ?>" class="checkbox" />
<p><?php
if ( $item->href )
echo "<a href='$item->href' class='no-crazy'>";
echo wp_specialchars( $item->text );
if ( strlen( $item->text ) > 180 ) // crazyhorse
echo '<br/><span class="inbox-more">more&hellip;</span>';
if ( $item->href )
echo '</a>';
?><br />
-- <cite><?php
echo $item->from;
if ( 'comment' == $item->type ) // crazyhorse
echo " on &quot;<a href='#' class='no-crazy'>{$crazy_posts[$item->parent]}</a>&quot;";
?></cite>, <?php echo "$item->date, $item->time"; ?>
</p>
<br class="clear" />
</li>
<?php endforeach; ?>
</ul>
</form>
<?php
echo $after_widget;
}
function wp_dashboard_recent_comments( $sidebar_args ) {
global $comment;
extract( $sidebar_args, EXTR_SKIP );
@ -509,6 +760,11 @@ function wp_dashboard_empty( $sidebar_args, $callback = false ) {
/* Dashboard Widgets Controls. Ssee also wp_dashboard_empty() */
// Temp
function wp_dashboard_empty_control() {
echo "This feature isn't enabled in this prototype.";
}
// Calls widget_control callback
function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
global $wp_registered_widget_controls;