2003-10-26 21:34:24 +01:00
|
|
|
<?php
|
2004-10-19 05:03:06 +02:00
|
|
|
require_once('admin.php');
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2006-05-18 08:49:22 +02:00
|
|
|
$parent_file = 'edit.php';
|
|
|
|
$submenu_file = 'edit.php';
|
2003-12-18 10:36:13 +01:00
|
|
|
|
2006-07-03 21:03:37 +02:00
|
|
|
wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
|
2006-04-19 10:02:16 +02:00
|
|
|
|
2008-03-26 19:55:24 +01:00
|
|
|
function redirect_post($post_ID = '') {
|
|
|
|
global $action;
|
|
|
|
|
|
|
|
$referredby = '';
|
2008-04-21 19:54:56 +02:00
|
|
|
if ( !empty($_POST['referredby']) ) {
|
2008-03-26 19:55:24 +01:00
|
|
|
$referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
|
2008-04-21 19:54:56 +02:00
|
|
|
$referredby = remove_query_arg('_wp_original_http_referer', $referredby);
|
|
|
|
}
|
2008-03-26 19:55:24 +01:00
|
|
|
$referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
|
|
|
|
|
2008-03-27 00:41:41 +01:00
|
|
|
if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
|
2008-03-26 19:55:24 +01:00
|
|
|
$location = $_POST['referredby'];
|
2008-03-27 00:41:41 +01:00
|
|
|
} elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
|
2008-03-26 19:55:24 +01:00
|
|
|
$location = 'sidebar.php?a=b';
|
|
|
|
} elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
|
2008-03-29 07:47:30 +01:00
|
|
|
if ( $_POST['_wp_original_http_referer'] && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post-new.php') === false )
|
2008-03-26 19:55:24 +01:00
|
|
|
$location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
|
|
|
|
else
|
|
|
|
$location = "post.php?action=edit&post=$post_ID&message=4";
|
|
|
|
} elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
|
|
|
|
$location = add_query_arg( 'message', 2, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
|
|
|
} elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
|
|
|
|
$location = add_query_arg( 'message', 3, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
|
|
|
} elseif (!empty($referredby) && $referredby != $referer) {
|
|
|
|
$location = $_POST['referredby'];
|
2008-04-21 21:30:54 +02:00
|
|
|
$location = remove_query_arg('_wp_original_http_referer', $location);
|
2008-03-26 19:55:24 +01:00
|
|
|
if ( $_POST['referredby'] == 'redo' )
|
|
|
|
$location = get_permalink( $post_ID );
|
|
|
|
elseif ( false !== strpos($location, 'edit.php') )
|
|
|
|
$location = add_query_arg('posted', $post_ID, $location);
|
|
|
|
elseif ( false !== strpos($location, 'wp-admin') )
|
|
|
|
$location = "post-new.php?posted=$post_ID";
|
|
|
|
} elseif ( isset($_POST['publish']) ) {
|
|
|
|
$location = "post-new.php?posted=$post_ID";
|
|
|
|
} elseif ($action == 'editattachment') {
|
|
|
|
$location = 'attachments.php';
|
|
|
|
} else {
|
|
|
|
$location = "post.php?action=edit&post=$post_ID&message=4";
|
|
|
|
}
|
|
|
|
|
|
|
|
wp_redirect( $location );
|
|
|
|
}
|
|
|
|
|
2006-04-19 10:02:16 +02:00
|
|
|
if ( isset( $_POST['deletepost'] ) )
|
|
|
|
$action = 'delete';
|
2005-04-16 18:31:38 +02:00
|
|
|
|
2003-10-26 21:34:24 +01:00
|
|
|
switch($action) {
|
2006-03-29 03:51:55 +02:00
|
|
|
case 'postajaxpost':
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'post':
|
2006-05-03 00:36:06 +02:00
|
|
|
check_admin_referer('add-post');
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-03-29 03:51:55 +02:00
|
|
|
$post_ID = 'post' == $action ? write_post() : edit_post();
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2008-03-26 19:55:24 +01:00
|
|
|
redirect_post($post_ID);
|
2004-04-28 06:49:16 +02:00
|
|
|
exit();
|
|
|
|
break;
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'edit':
|
|
|
|
$title = __('Edit');
|
2006-02-21 07:11:46 +01:00
|
|
|
$editing = true;
|
2008-02-06 22:40:52 +01:00
|
|
|
|
|
|
|
if ( empty( $_GET['post'] ) ) {
|
|
|
|
wp_redirect("post.php");
|
|
|
|
exit();
|
|
|
|
}
|
2005-06-19 04:51:48 +02:00
|
|
|
$post_ID = $p = (int) $_GET['post'];
|
2006-02-21 07:11:46 +01:00
|
|
|
$post = get_post($post_ID);
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2007-08-16 00:31:19 +02:00
|
|
|
if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
|
|
|
|
|
2008-04-19 01:38:21 +02:00
|
|
|
if ( 'post' != $post->post_type ) {
|
|
|
|
wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
|
2007-01-22 09:16:58 +01:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2008-01-03 02:34:11 +01:00
|
|
|
wp_enqueue_script('post');
|
2008-02-18 18:11:12 +01:00
|
|
|
if ( user_can_richedit() )
|
|
|
|
wp_enqueue_script('editor');
|
2008-01-09 09:14:29 +01:00
|
|
|
wp_enqueue_script('media-upload');
|
2008-04-29 21:17:23 +02:00
|
|
|
wp_enqueue_script('word-count');
|
2008-04-23 01:54:13 +02:00
|
|
|
|
|
|
|
if ( current_user_can('edit_post', $post_ID) ) {
|
|
|
|
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
|
|
|
$last_user = get_userdata( $last );
|
|
|
|
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
|
|
|
|
$message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
|
|
|
|
$message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
|
|
|
|
add_action('admin_notices', create_function( '', "echo '$message';" ) );
|
|
|
|
} else {
|
|
|
|
wp_set_post_lock( $post->ID );
|
|
|
|
wp_enqueue_script('autosave');
|
|
|
|
}
|
2008-02-29 10:51:36 +01:00
|
|
|
}
|
2008-01-03 02:34:11 +01:00
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
require_once('admin-header.php');
|
|
|
|
|
2005-07-12 00:39:50 +02:00
|
|
|
if ( !current_user_can('edit_post', $post_ID) )
|
2005-02-25 01:20:48 +01:00
|
|
|
die ( __('You are not allowed to edit this post.') );
|
2005-06-19 04:51:48 +02:00
|
|
|
|
|
|
|
$post = get_post_to_edit($post_ID);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-02-21 07:11:46 +01:00
|
|
|
include('edit-form-advanced.php');
|
2004-10-22 16:41:01 +02:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
break;
|
|
|
|
|
2005-12-13 20:19:56 +01:00
|
|
|
case 'editattachment':
|
|
|
|
$post_id = (int) $_POST['post_ID'];
|
|
|
|
|
2006-05-27 01:08:05 +02:00
|
|
|
check_admin_referer('update-attachment_' . $post_id);
|
2006-05-03 00:36:06 +02:00
|
|
|
|
2005-12-13 20:19:56 +01:00
|
|
|
// Don't let these be changed
|
|
|
|
unset($_POST['guid']);
|
2006-02-09 11:03:48 +01:00
|
|
|
$_POST['post_type'] = 'attachment';
|
2005-12-13 20:19:56 +01:00
|
|
|
|
|
|
|
// Update the thumbnail filename
|
2006-12-05 23:37:19 +01:00
|
|
|
$newmeta = wp_get_attachment_metadata( $post_id, true );
|
2005-12-13 20:19:56 +01:00
|
|
|
$newmeta['thumb'] = $_POST['thumb'];
|
|
|
|
|
2006-12-05 23:37:19 +01:00
|
|
|
wp_update_attachment_metadata( $post_id, $newmeta );
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'editpost':
|
2006-05-03 00:36:06 +02:00
|
|
|
$post_ID = (int) $_POST['post_ID'];
|
2006-05-27 01:08:05 +02:00
|
|
|
check_admin_referer('update-post_' . $post_ID);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2005-09-08 22:38:30 +02:00
|
|
|
$post_ID = edit_post();
|
2006-06-24 09:34:35 +02:00
|
|
|
|
2008-03-26 19:55:24 +01:00
|
|
|
redirect_post($post_ID); // Send user on their way while we keep working
|
2005-02-14 10:46:08 +01:00
|
|
|
|
2004-04-30 10:56:49 +02:00
|
|
|
exit();
|
2003-11-12 16:22:47 +01:00
|
|
|
break;
|
2003-11-06 01:34:41 +01:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'delete':
|
2004-11-27 05:46:54 +01:00
|
|
|
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
|
2006-05-27 01:08:05 +02:00
|
|
|
check_admin_referer('delete-post_' . $post_id);
|
2005-12-13 20:19:56 +01:00
|
|
|
|
|
|
|
$post = & get_post($post_id);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-02-21 07:11:46 +01:00
|
|
|
if ( !current_user_can('delete_post', $post_id) )
|
2006-07-06 00:00:03 +02:00
|
|
|
wp_die( __('You are not allowed to delete this post.') );
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2006-02-09 11:03:48 +01:00
|
|
|
if ( $post->post_type == 'attachment' ) {
|
2005-12-15 23:26:22 +01:00
|
|
|
if ( ! wp_delete_attachment($post_id) )
|
2006-07-06 00:00:03 +02:00
|
|
|
wp_die( __('Error in deleting...') );
|
2005-12-15 23:26:22 +01:00
|
|
|
} else {
|
2007-09-04 01:32:58 +02:00
|
|
|
if ( !wp_delete_post($post_id) )
|
2006-07-06 00:00:03 +02:00
|
|
|
wp_die( __('Error in deleting...') );
|
2005-12-15 23:26:22 +01:00
|
|
|
}
|
2003-11-12 16:22:47 +01:00
|
|
|
|
2006-06-24 09:34:35 +02:00
|
|
|
$sendback = wp_get_referer();
|
2007-03-07 06:29:15 +01:00
|
|
|
if (strpos($sendback, 'post.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/post-new.php';
|
|
|
|
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php';
|
2004-10-05 18:22:31 +02:00
|
|
|
$sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
|
2006-06-27 07:38:56 +02:00
|
|
|
wp_redirect($sendback);
|
2006-02-21 07:11:46 +01:00
|
|
|
exit();
|
2003-11-12 16:22:47 +01:00
|
|
|
break;
|
2004-04-28 06:49:16 +02:00
|
|
|
|
|
|
|
default:
|
2006-06-27 07:38:56 +02:00
|
|
|
wp_redirect('edit.php');
|
2006-04-04 02:12:43 +02:00
|
|
|
exit();
|
2004-04-28 06:49:16 +02:00
|
|
|
break;
|
2003-10-26 21:34:24 +01:00
|
|
|
} // end switch
|
2003-12-11 01:22:36 +01:00
|
|
|
include('admin-footer.php');
|
2003-11-12 16:22:47 +01:00
|
|
|
?>
|