Inline editing. First cut. Props Aaron Harp. see #6815

git-svn-id: http://svn.automattic.com/wordpress/trunk@8857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-10 22:47:03 +00:00
parent d2b3b03d9f
commit 2f582d83e7
10 changed files with 657 additions and 84 deletions

View File

@ -12,6 +12,7 @@
* @since unknown
*/
define('DOING_AJAX', true);
define('WP_ADMIN', true);
require_once('../wp-load.php');
require_once('includes/admin.php');
@ -715,6 +716,24 @@ case 'sample-permalink':
$slug = isset($_POST['new_slug'])? $_POST['new_slug'] : '';
die(get_sample_permalink_html($post_id, $title, $slug));
break;
case 'inline-data':
get_inline_data( explode(',', $_POST['posts']) );
die();
break;
case 'inline-save':
inline_save_row( $_POST );
if ( 'page' == $_POST['post_type'] ) {
$post = array();
$post[] = get_post($_POST['post_ID']);
page_rows( $post );
} elseif ( 'post' == $_POST['post_type'] ) {
$mode = $_POST['post_view'];
$post = array();
$post[] = get_post($_POST['post_ID']);
post_rows($post);
}
die();
break;
case 'meta-box-order':
check_ajax_referer( 'meta-box-order' );
update_user_option( $GLOBALS['current_user']->ID, "meta-box-order_$_POST[page]", $_POST['order'] );

View File

@ -44,6 +44,7 @@ if ( isset($_GET['action']) && isset($_GET['delete']) ) {
$title = __('Pages');
$parent_file = 'edit.php';
wp_enqueue_script('admin-forms');
wp_enqueue_script('inline-edit');
$post_stati = array( // array( adj, noun )
'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published (%s)', 'Published (%s)')),
@ -153,6 +154,7 @@ if ( $page_links )
<div class="alignleft">
<select name="action">
<option value="" selected><?php _e('Actions'); ?></option>
<option value="edit"><?php _e('Edit'); ?></option>
<option value="delete"><?php _e('Delete'); ?></option>
</select>
<input type="submit" value="<?php _e('Apply'); ?>" name="doaction" class="button-secondary action" />
@ -187,6 +189,7 @@ if ($posts) {
</tr>
</thead>
<tbody>
<?php inline_edit_row( 'page' ) ?>
<?php page_rows($posts, $pagenum, $per_page); ?>
</tbody>
</table>

View File

@ -27,6 +27,9 @@ if ( ! defined('ABSPATH') ) die();
</tr>
</thead>
<tbody>
<?php inline_edit_row( 'post' ) ?>
<?php
if ( have_posts() ) {
post_rows();

View File

@ -50,6 +50,8 @@ if ( !empty($_GET['action']) && $_GET['action'] != 'Actions' ) {
$title = __('Posts');
$parent_file = 'edit.php';
wp_enqueue_script('admin-forms');
wp_enqueue_script('inline-edit');
list($post_stati, $avail_post_stati) = wp_edit_posts_query();
@ -169,8 +171,8 @@ if ( $page_links )
<div class="alignleft">
<select name="action">
<option value="" selected><?php _e('Actions'); ?></option>
<option value="delete"><?php _e('Delete'); ?></option>
<option value="edit"><?php _e('Edit'); ?></option>
<option value="delete"><?php _e('Delete'); ?></option>
</select>
<input type="submit" value="<?php _e('Apply'); ?>" name="doaction" class="button-secondary action" />
<?php wp_nonce_field('bulk-posts'); ?>

View File

@ -9,29 +9,34 @@
* @since 2.6
*
* @param bool $update Are we updating a pre-existing post?
* @param post_data array Array of post data. Defaults to the contents of $_POST
* @return object|bool WP_Error on failure, true on success.
*/
function _wp_translate_postdata( $update = false ) {
if ( $update )
$_POST['ID'] = (int) $_POST['post_ID'];
$_POST['post_content'] = $_POST['content'];
$_POST['post_excerpt'] = $_POST['excerpt'];
$_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
if ( isset($_POST['trackback_url']) )
$_POST['to_ping'] = $_POST['trackback_url'];
function _wp_translate_postdata( $update = false, &$post_data = null ) {
if (!empty ( $_POST['post_author_override'] ) ) {
$_POST['post_author'] = (int) $_POST['post_author_override'];
if ( empty($post_data) )
$post_data = &$_POST;
if ( $update )
$post_data['ID'] = (int) $post_data['post_ID'];
$post_data['post_content'] = $post_data['content'];
$post_data['post_excerpt'] = $post_data['excerpt'];
$post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : '';
if ( isset($post_data['trackback_url']) )
$post_data['to_ping'] = $post_data['trackback_url'];
if (!empty ( $post_data['post_author_override'] ) ) {
$post_data['post_author'] = (int) $post_data['post_author_override'];
} else {
if (!empty ( $_POST['post_author'] ) ) {
$_POST['post_author'] = (int) $_POST['post_author'];
if (!empty ( $post_data['post_author'] ) ) {
$post_data['post_author'] = (int) $post_data['post_author'];
} else {
$_POST['post_author'] = (int) $_POST['user_ID'];
$post_data['post_author'] = (int) $post_data['user_ID'];
}
}
if ( isset($_POST['user_ID']) && ($_POST['post_author'] != $_POST['user_ID']) ) {
if ( 'page' == $_POST['post_type'] ) {
if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {
if ( 'page' == $post_data['post_type'] ) {
if ( !current_user_can( 'edit_others_pages' ) ) {
return new WP_Error( 'edit_others_pages', $update ?
__( 'You are not allowed to edit pages as this user.' ) :
@ -49,51 +54,51 @@ function _wp_translate_postdata( $update = false ) {
}
// What to do based on which button they pressed
if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
$_POST['post_status'] = 'draft';
if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
$_POST['post_status'] = 'private';
if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
$_POST['post_status'] = 'publish';
if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
$_POST['post_status'] = 'draft';
if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )
$post_data['post_status'] = 'draft';
if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )
$post_data['post_status'] = 'private';
if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( $post_data['post_status'] != 'private' ) )
$post_data['post_status'] = 'publish';
if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )
$post_data['post_status'] = 'draft';
$previous_status = get_post_field('post_status', $_POST['ID']);
$previous_status = get_post_field('post_status', $post_data['ID']);
// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
if ( 'page' == $_POST['post_type'] ) {
if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
if ( 'page' == $post_data['post_type'] ) {
if ( 'publish' == $post_data['post_status'] && !current_user_can( 'publish_pages' ) )
if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_pages') )
$_POST['post_status'] = 'pending';
$post_data['post_status'] = 'pending';
} else {
if ( isset($_POST['post_status']) && ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' )) ) :
if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( 'publish_posts' )) ) :
// Stop attempts to publish new posts, but allow already published posts to be saved if appropriate.
if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_posts') )
$_POST['post_status'] = 'pending';
$post_data['post_status'] = 'pending';
endif;
}
if (!isset( $_POST['comment_status'] ))
$_POST['comment_status'] = 'closed';
if (!isset( $post_data['comment_status'] ))
$post_data['comment_status'] = 'closed';
if (!isset( $_POST['ping_status'] ))
$_POST['ping_status'] = 'closed';
if (!isset( $post_data['ping_status'] ))
$post_data['ping_status'] = 'closed';
foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
$_POST['edit_date'] = '1';
if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {
$post_data['edit_date'] = '1';
break;
}
}
if ( !empty( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
$jj = $_POST['jj'];
$hh = $_POST['hh'];
$mn = $_POST['mn'];
$ss = $_POST['ss'];
if ( !empty( $post_data['edit_date'] ) ) {
$aa = $post_data['aa'];
$mm = $post_data['mm'];
$jj = $post_data['jj'];
$hh = $post_data['hh'];
$mn = $post_data['mn'];
$ss = $post_data['ss'];
$aa = ($aa <= 0 ) ? date('Y') : $aa;
$mm = ($mm <= 0 ) ? date('n') : $mm;
$jj = ($jj > 31 ) ? 31 : $jj;
@ -101,8 +106,8 @@ function _wp_translate_postdata( $update = false ) {
$hh = ($hh > 23 ) ? $hh -24 : $hh;
$mn = ($mn > 59 ) ? $mn -60 : $mn;
$ss = ($ss > 59 ) ? $ss -60 : $ss;
$_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
$_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
$post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
}
return true;
@ -110,11 +115,14 @@ function _wp_translate_postdata( $update = false ) {
// Update an existing post with values provided in $_POST.
function edit_post() {
function edit_post( $post_data = null ) {
$post_ID = (int) $_POST['post_ID'];
if ( empty($post_data) )
$post_data = &$_POST;
if ( 'page' == $_POST['post_type'] ) {
$post_ID = (int) $post_data['post_ID'];
if ( 'page' == $post_data['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_ID ) )
wp_die( __('You are not allowed to edit this page.' ));
} else {
@ -123,7 +131,7 @@ function edit_post() {
}
// Autosave shouldn't save too soon after a real save
if ( 'autosave' == $_POST['action'] ) {
if ( 'autosave' == $post_data['action'] ) {
$post =& get_post( $post_ID );
$now = time();
$then = strtotime($post->post_date_gmt . ' +0000');
@ -132,24 +140,24 @@ function edit_post() {
return $post_ID;
}
$translated = _wp_translate_postdata( true );
$translated = _wp_translate_postdata( true, $post_data );
if ( is_wp_error($translated) )
wp_die( $translated->get_error_message() );
// Meta Stuff
if ( isset($_POST['meta']) && $_POST['meta'] ) {
foreach ( $_POST['meta'] as $key => $value )
if ( isset($post_data['meta']) && $post_data['meta'] ) {
foreach ( $post_data['meta'] as $key => $value )
update_meta( $key, $value['key'], $value['value'] );
}
if ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
foreach ( $_POST['deletemeta'] as $key => $value )
if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {
foreach ( $post_data['deletemeta'] as $key => $value )
delete_meta( $key );
}
add_meta( $post_ID );
wp_update_post( $_POST );
wp_update_post( $post_data );
// Reunite any orphaned attachments with their parent
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
@ -163,7 +171,7 @@ function edit_post() {
wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
if ( current_user_can( 'edit_others_posts' ) ) {
if ( !empty($_POST['sticky']) )
if ( !empty($post_data['sticky']) )
stick_post($post_ID);
else
unstick_post($post_ID);

View File

@ -350,7 +350,7 @@ function wp_manage_posts_columns() {
$posts_columns['modified'] = __('Submitted');
else
$posts_columns['date'] = __('Date');
//$posts_columns['author'] = __('Author');
$posts_columns['author'] = __('Author');
$posts_columns['categories'] = __('Categories');
$posts_columns['tags'] = __('Tags');
if ( !isset($_GET['post_status']) || !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
@ -406,23 +406,248 @@ function wp_manage_pages_columns() {
return $posts_columns;
}
function post_rows() {
function inline_edit_row( $type ) {
global $current_user;
if ( 'post' == $type )
$post = get_default_post_to_edit();
else
$post = get_default_page_to_edit();
echo '<tr id="inline-edit" style="display: none">';
$columns = $type == 'post' ? wp_manage_posts_columns() : wp_manage_pages_columns();
foreach($columns as $column_name=>$column_display_name) {
switch($column_name) {
case 'cb': ?>
<th class="check-column"></th>
<?php
break;
case 'modified':
case 'date': ?>
<td class="date">
<?php touch_time(1, 1, 4, 1); ?>
</td>
<?php
break;
case 'title': ?>
<td class="<?php echo $type ?>-title">
<div class="title">
<input type="text" name="post_title" class="title" value="" /><br />
<label><?php _e('Slug'); ?></label><input type="text" name="post_name" value="" class="slug" />
</div>
<?php if($type == 'page'): ?>
<div class="other">
<label><?php _e('Parent'); ?></label>
<select name="post_parent">
<option value="0"><?php _e('Main Page (no parent)'); ?></option>
<?php parent_dropdown(); ?>
</select><br />
<label><?php _e('Template'); ?></label>
<select name="page_template">
<option value='default'><?php _e('Default Template'); ?></option>
<?php page_template_dropdown() ?>
</select>
</div>
<div class="more">
<label><?php _e('Order'); ?></label><input type="text" name="menu_order" value="<?php echo $post->menu_order ?>" />
<label><?php _e('Password'); ?></label><input type="text" name="post_password" value="<?php echo $post->post_password ?>" />
</div>
<?php endif; ?>
<div class="clear"></div>
<?php
$actions = array();
$actions['save'] = '<a href="#">' . __('Save') . '</a>';
$actions['cancel'] = '<a href="#">' . __('Cancel') . '</a>';
$action_count = count($actions);
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
echo "<span class='$action'>$link$sep</span>";
}
?>
</td>
<?php
break;
case 'categories': ?>
<td class="categories">
<ul class="categories">
<?php wp_category_checklist() ?>
</ul>
</td>
<?php
break;
case 'tags': ?>
<td class="tags">
<textarea name="tags_input"></textarea>
</td>
<?php
break;
case 'comments': ?>
<td class="comments num">
<input title="Allow Comments" type="checkbox" name="comment_status" value="open" /><br />
<input title="Allow Pings" type="checkbox" name="ping_status" value="open" />
</td>
<?php
break;
case 'author': ?>
<td class="author">
<?php
$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
if ( $authors && count( $authors ) > 1 ) {
wp_dropdown_users( array('include' => $authors, 'name' => 'post_author', 'class'=> 'author', 'selected' => $post->post_author) );
} else {
echo $current_user->user_nicename.'<input type="hidden" value="'.$post->post_author.'" class="author" />';
}
?>
</td>
<?php
break;
case 'status': ?>
<td class="status">
<select name="post_status">
<?php if ( current_user_can('publish_posts') ) : // Contributors only get "Unpublished" and "Pending Review" ?>
<option value='publish'><?php _e('Published') ?></option>
<option value='future'><?php _e('Scheduled') ?></option>
<?php endif; ?>
<option value='pending'><?php _e('Pending Review') ?></option>
<option value='draft'><?php _e('Unpublished') ?></option>
</select>
<?php if($type == 'page'): ?>
<br /><label><input type="checkbox" name="page_private" value="private" <?php checked($post->post_status, 'private'); ?> /> <?php _e('Private') ?></label></p>
<?php else: ?>
<?php if ( current_user_can( 'edit_others_posts' ) ) : ?>
<br /><label><input type="checkbox" name="sticky" value="sticky" /> <?php _e('Sticky') ?></label></p>
<?php endif; ?>
<?php endif; ?>
</td>
<?php
break;
case 'control_view': ?>
<td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e('View'); ?></a></td>
<?php
break;
case 'control_edit': ?>
<td><?php if ( current_user_can('edit_post',$post->ID) ) { echo "<a href='post.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<?php
break;
case 'control_delete': ?>
<td><?php if ( current_user_can('delete_post',$post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
<?php
break;
default: ?>
<td><?php do_action('manage_posts_custom_column', $column_name, $post->ID); ?></td>
<?php
break;
}
}
echo '</tr>';
}
function inline_save_row( $data ) {
// get the original post content
$post = get_post( $data['post_ID'], ARRAY_A );
$data['content'] = $post['post_content'];
// statuses
if ( 'page' == $data['post_type'] && 'private' == $data['page_private'] )
$data['post_status'] = 'private';
if ( empty($data['comment_status']) )
$data['comment_status'] = 'closed';
if ( empty($data['ping_status']) )
$data['ping_status'] = 'closed';
// rename
$data['user_ID'] = $GLOBALS['user_ID'];
$data['excerpt'] = $data['post_excerpt'];
$data['trackback_url'] = $data['to_ping'];
$data['parent_id'] = $data['post_parent'];
// update the post
$_POST = $data;
edit_post();
}
// outputs XML of the post/page data ready for use in the inline editor
// accepts array of post IDs
function get_inline_data($posts) {
global $post;
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
echo "<?xml version='1.0' ?>\n";
echo "<posts>\n";
foreach ($posts as $ID) {
$GLOBALS['post'] = get_post($ID);
$GLOBALS['post_ID'] = $ID;
if ( ($post->post_type == 'post' && !current_user_can('edit_post', $ID)) ||
($post->post_type == 'page' && !current_user_can('edit_page', $ID)) ||
($post->post_type != 'post' && $post->post_type != 'page'))
continue;
echo " <post id='$ID'>\n";
echo " <post_title>" . wp_specialchars($post->post_title, 1) . "</post_title>\n";
echo " <post_name>$post->post_name</post_name>\n";
echo " <post_author>$post->post_author</post_author>\n";
echo " <comment_status>$post->comment_status</comment_status>\n";
echo " <ping_status>$post->ping_status</ping_status>\n";
echo " <post_status>$post->post_status</post_status>\n";
echo " <jj>" . mysql2date( 'd', $post->post_date ) . "</jj>\n";
echo " <mm>" . mysql2date( 'm', $post->post_date ) . "</mm>\n";
echo " <aa>" . mysql2date( 'Y', $post->post_date ) . "</aa>\n";
echo " <hh>" . mysql2date( 'H', $post->post_date ) . "</hh>\n";
echo " <mn>" . mysql2date( 'i', $post->post_date ) . "</mn>\n";
if( $post->post_type == 'post' ) {
echo ' <tags_input>' . wp_specialchars(get_tags_to_edit( $post->ID ), 1) . "</tags_input>\n";
echo ' <post_category>' . implode( ',', wp_get_post_categories( $post->ID ) ) . "</post_category>\n";
echo ' <sticky>' . (is_sticky($post->ID) ? 'sticky' : '') . "</sticky>\n";
}
if( $post->post_type == 'page' ) {
echo " <post_parent>$post->post_parent</post_parent>\n";
echo ' <page_template>' . wp_specialchars(get_post_meta( $post->ID, '_wp_page_template', true ), 1) . "</page_template>\n";
echo " <post_password>" . wp_specialchars($post->post_password, 1) . "</post_password>\n";
echo " <menu_order>$post->menu_order</menu_order>\n";
}
echo " </post>\n";
}
echo '</posts>';
}
function post_rows( $posts = array() ) {
global $wp_query, $post, $mode;
add_filter('the_title','wp_specialchars');
// Create array of post IDs.
$post_ids = array();
foreach ( $wp_query->posts as $a_post )
if ( empty($posts) )
$posts = &$wp_query->posts;
foreach ( $posts as $a_post )
$post_ids[] = $a_post->ID;
$comment_pending_count = get_pending_comments_num($post_ids);
if ( empty($comment_pending_count[$post->ID]) )
if ( empty($comment_pending_count) )
$comment_pending_count = array();
while ( have_posts() ) {
the_post();
foreach ( $posts as $post ) {
if ( empty($comment_pending_count[$post->ID]) )
$comment_pending_count[$post->ID] = 0;
@ -436,6 +661,7 @@ function _post_row($a_post, $pending_comments, $mode) {
$global_post = $post;
$post = $a_post;
setup_postdata($post);
$class = 'alternate' == $class ? '' : 'alternate';
global $current_user;
@ -483,9 +709,9 @@ function _post_row($a_post, $pending_comments, $mode) {
}
if ( 'excerpt' == $mode ) { ?>
<td><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
<td class="date"><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
<?php } else { ?>
<td><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
<td class="date"><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
<?php }
break;
@ -500,6 +726,7 @@ function _post_row($a_post, $pending_comments, $mode) {
$actions = array();
$actions['edit'] = '<a href="post.php?action=edit&amp;post=' . $post->ID . '">' . __('Edit') . '</a>';
$actions['inline'] = '<a href="#" class="editinline">' . __('Quick Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
$action_count = count($actions);
$i = 0;
@ -515,7 +742,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'categories':
?>
<td><?php
<td class="categories"><?php
$categories = get_the_category();
if ( !empty( $categories ) ) {
$out = array();
@ -531,7 +758,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'tags':
?>
<td><?php
<td class="tags"><?php
$tags = get_the_tags();
if ( !empty( $tags ) ) {
$out = array();
@ -547,7 +774,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'comments':
?>
<td class="num"><div class="post-com-count-wrapper">
<td class="comments num"><div class="post-com-count-wrapper">
<?php
$pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
if ( $pending_comments )
@ -562,13 +789,13 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'author':
?>
<td><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<td class="author"><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<?php
break;
case 'status':
?>
<td>
<td class="status">
<a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
<?php
switch ( $post->post_status ) {
@ -654,7 +881,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
case 'cb':
?>
<th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="<?php the_ID(); ?>" /></th>
<th scope="row" class="check-column"><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /></th>
<?php
break;
case 'modified':
@ -681,7 +908,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
}
}
?>
<td><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
<td class="date"><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
<?php
break;
case 'title':
@ -696,6 +923,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['inline'] = '<a href="#" class="editinline">' . __('Quick Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $page->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n 'Cancel' to stop, 'OK' to delete."), $page->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
$action_count = count($actions);
$i = 0;
@ -711,7 +939,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
case 'comments':
?>
<td class="num"><div class="post-com-count-wrapper">
<td class="comments num"><div class="post-com-count-wrapper">
<?php
$left = get_pending_comments_num( $page->ID );
$pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
@ -727,13 +955,13 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
case 'author':
?>
<td><a href="edit-pages.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<td class="author"><a href="edit-pages.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<?php
break;
case 'status':
?>
<td>
<td class="status">
<a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
<?php
switch ( $page->post_status ) {
@ -1240,7 +1468,7 @@ function meta_form() {
}
function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
global $wp_locale, $post, $comment;
if ( $for_post )
@ -1261,7 +1489,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
$mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
$ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
$month = "<select id=\"mm\" name=\"mm\"$tab_index_attribute>\n";
$month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
for ( $i = 1; $i < 13; $i = $i +1 ) {
$month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
if ( $i == $mm )
@ -1270,11 +1498,14 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
}
$month .= '</select>';
$day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
$hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
$hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
printf(_c('%1$s%2$s, %3$s @ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute);
if ( $multi ) return;
echo "\n\n";
foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
@ -1317,7 +1548,7 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
else
$current = '';
echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
parent_dropdown( $default, $item->ID, $level +1 );
}
} else {

View File

@ -1,12 +1,12 @@
function checkAll(jQ) { // use attr( checked, fn )
jQuery(jQ).find( 'tbody:visible :checkbox' ).attr( 'checked', function() {
jQuery(jQ).find( 'tbody:visible .check-column :checkbox' ).attr( 'checked', function() {
return jQuery(this).attr( 'checked' ) ? '' : 'checked';
} );
}
jQuery( function($) {
var lastClicked = false;
$( 'tbody :checkbox' ).click( function(e) {
$( 'tbody .check-column :checkbox' ).click( function(e) {
if ( 'undefined' == e.shiftKey ) { return true; }
if ( e.shiftKey ) {
if ( !lastClicked ) { return true; }

186
wp-admin/js/inline-edit.js Normal file
View File

@ -0,0 +1,186 @@
var postType = null;
var postView = null;
var postsXml = null;
var inlineRows = null;
jQuery(document).ready(function() {
postType = window.location.href.indexOf('edit.php') == -1 ? 'page' : 'post';
postView = window.location.href.indexOf('mode=excerpt') == -1 ? 'list' : 'excerpt';
// get IDs of all editable rows
inlineRows = jQuery('table.widefat .check-column :checkbox[name="post[]"]').parents('tr');
// prepare the edit row
var blankRow = jQuery('#inline-edit');
jQuery('ul.categories *', blankRow).removeAttr('id');
jQuery('ul.categories label', blankRow).removeAttr('for');
blankRow.attr('title', 'Double-click to cancel')
.dblclick(function() { toggleRow(this); })
.keypress(function(event) { if(event.which == 13) return saveRow(this); });
jQuery('span.cancel a', blankRow).click(function() { return revertRow(this); });
jQuery('span.save a', blankRow).click(function() { return saveRow(this); });
// add events and get data
inlineRows.dblclick(function() { toggleRow(this); });
addEvents(inlineRows);
// get data
getInlineData('all');
});
function toggleRow(el) {
jQuery('#'+postType+'-'+getRowId(el)).css('display') == 'none' ? revertRow(el) : editRow(el);
}
// add events to links and make rows double-clickable
function addEvents(rows) {
rows.each(function() {
var row = jQuery(this);
jQuery('a.editinline', row).click(function() { editRow(this); return false; });
row.attr('title', 'Double-click to edit');
});
}
function getInlineData(id) {
if(id == 'all') {
var editable = [];
inlineRows.each(function(i) { editable[i] = getRowId(this); });
id = editable.join(',');
}
if(id == '')
return false;
jQuery.post('admin-ajax.php',
{
action: 'inline-data',
posts: id
},
function(xml) {
if(id.indexOf(',') == -1) {
var newData = jQuery(xml).find('post[id="'+id+'"]');
jQuery(postsXml).find('post[id="'+id+'"]').replaceWith(newData);
} else {
postsXml = xml;
}
}, 'xml'
);
}
function editRow(id) {
if(typeof(id) == 'object')
id = getRowId(id);
var blankRow = jQuery('#inline-edit');
var fields = ['post_title', 'post_name', 'post_author', 'post_status', 'jj', 'mm', 'aa', 'hh', 'mn'];
if(postType == 'page') fields.push('post_parent', 'menu_order', 'page_template', 'post_password');
if(postType == 'post') fields.push('tags_input');
// add the new blank row
var editRow = blankRow.clone(true);
jQuery(editRow).attr('id', 'edit-'+id).addClass('inline').show();
if(jQuery('#'+postType+'-'+id).hasClass('alternate'))
jQuery(editRow).addClass('alternate');
jQuery('#'+postType+'-'+id).hide().after(editRow);
// populate the data
var rowData = jQuery(postsXml).find('post[id="'+id+'"]');
for(var f = 0; f < fields.length; f++) {
jQuery(':input[name="'+fields[f]+'"]', editRow).val(jQuery(fields[f], rowData).text());
}
// ping, comments, and privacy
if(jQuery('comment_status', rowData).text() == 'open')
jQuery('input[name="comment_status"]', editRow).select();
if(jQuery('ping_status', rowData).text() == 'open')
jQuery('input[name="ping_status"]', editRow).select();
if(jQuery('sticky', rowData).text() == 'sticky')
jQuery('input[name="sticky"]', editRow).select();
// categories
var categories = jQuery('post_category', rowData).text().split(',');
jQuery(categories).each(function() {
jQuery('ul.categories :checkbox[value="'+this+'"]', editRow).select();
});
// handle the post status
var status = jQuery('post_status', rowData).text();
if(status != 'future') jQuery('select[name="post_status"] option[value="future"]', editRow).remove();
if(status == 'private') jQuery('input[name="page_private"]', editRow).select();
// enable autocomplete for tags
if(postType == 'post') {
jQuery('tr.inline textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
}
// remove the current page and children from the parent dropdown
var pageOpt = jQuery('select[name="post_parent"] option[value="'+id+'"]', editRow);
if(pageOpt.length > 0) {
var pageLevel = pageOpt[0].className.split('-')[1];
var nextPage = pageOpt; var pageLoop = true;
while(pageLoop) {
var nextPage = nextPage.next('option');
var nextLevel = nextPage[0].className.split('-')[1];
if(nextLevel <= pageLevel)
pageLoop = false;
else {
nextPage.remove();
nextPage = pageOpt;
}
}
pageOpt.remove();
}
return false;
}
function saveRow(id) {
if(typeof(id) == 'object')
id = getRowId(id);
jQuery('#edit-'+id+' .check-column').html('<img src="images/loading.gif" alt="Saving..." />');
var params = {
action: 'inline-save',
post_type: postType,
post_ID: id,
edit_date: 'true',
post_view: postView
};
var fields = jQuery('#edit-'+id+' :input').fieldSerialize();
params = fields + '&' + jQuery.param(params);
// make ajax request
jQuery.post('admin-ajax.php', params,
function(html) {
var row = jQuery('#'+postType+'-'+id);
jQuery('#edit-'+id).hide();
html = jQuery(html).html();
row.html(html).show();
row.animate( { backgroundColor: '#FFFBCC' }, 200)
.animate( { backgroundColor: row.css('background-color') }, 500);
getInlineData(id);
addEvents(row);
}
);
return false;
}
function revertRow(id) {
if(typeof(id) == 'object')
id = getRowId(id);
jQuery('#edit-'+id).remove();
jQuery('#'+postType+'-'+id).show();
return false;
}
function getRowId(obj) {
var id = obj.tagName == 'TR' ? obj.id : jQuery(obj).parents('tr').attr('id');
var parts = id.split('-');
return parts[parts.length - 1];
}

View File

@ -2139,3 +2139,122 @@ p#post-search-prep {
.metabox-prefs label input {
margin: 0 5px 0 2px;
}
/* Inline Editor */
.inline {
font-size: 10px;
}
.inline td {
padding-right: 4px;
padding-left: 7px;
}
.inline input, .inline select, .inline textarea {
font-size: 10px !important;
padding: 2px;
border: 1px solid #ddd;
}
.inline td.date {
width: 87px;
}
.inline td.page-title {
width: 495px;
}
.inline td.post-title input.title {
width: 250px;
}
.inline td.post-title input.slug {
width: 222px;
float: right;
}
.inline div.title {
float: left;
}
.inline div.title input.title {
font-size: 12px !important;
}
.inline div.title label {
float: left;
margin-top: 4px;
}
.inline td.page-title input.slug {
width: 123px;
float: right;
}
.inline div.other, .inline div.more {
width: 190px;
float: left;
padding-left: 5px;
}
.inline div.other label, .inline div.more label {
display: block; float: left;
width: 54px;
margin-top: 4px;
}
.inline div.other select {
width: 133px;
}
.inline div.more {
width: 125px;
}
.inline div.more input {
width: 60px;
}
.inline td.author select {
width: 110px;
}
.inline ul.categories {
list-style: none;
padding: 0; margin: 0;
height: 65px;
overflow: auto;
font-size: 10px;
}
.inline ul.categories ul.children {
list-style: none;
padding-left: 15px;
}
.inline ul.categories li {
margin-bottom: 2px;
}
.inline ul.categories input {
vertical-align: middle;
padding: 0; border: 0;
}
.inline td.tags textarea {
height: 58px; width: 100%;
}
.inline td.comments {
padding-left: 0;
}
.inline td.status select {
width: 98px;
}
.inline td.status input {
vertical-align: middle;
}

View File

@ -241,6 +241,8 @@ function wp_default_scripts( &$scripts ) {
));
$scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'jquery' ), '20080625' );
$scripts->add( 'inline-edit', '/wp-admin/js/inline-edit.js', array( 'jquery', 'jquery-form', 'suggest' ), '20080812' );
$scripts->add( 'plugin-install', '/wp-admin/js/plugin-install.js', array( 'thickbox', 'jquery' ), '20080803' );
$scripts->localize( 'plugin-install', 'plugininstallL10n', array(