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' ;
2005-02-01 02:49:51 +01:00
$wpvarstoreset = array ( 'action' , 'safe_mode' , 'withcomments' , 'posts' , 'content' , 'edited_post_title' , 'comment_error' , 'profile' , 'trackback_url' , 'excerpt' , 'showcomments' , 'commentstart' , 'commentend' , 'commentorder' );
2003-12-18 10:36:13 +01:00
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
2004-10-22 16:41:01 +02:00
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
if ( empty ( $_POST [ " $wpvar " ])) {
if ( empty ( $_GET [ " $wpvar " ])) {
$$wpvar = '' ;
} else {
2004-04-28 06:49:16 +02:00
$$wpvar = $_GET [ " $wpvar " ];
2004-10-22 16:41:01 +02:00
}
} else {
$$wpvar = $_POST [ " $wpvar " ];
2004-04-28 06:49:16 +02:00
}
}
}
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-18 08:49:22 +02:00
$parent_file = 'post-new.php' ;
$submenu_file = 'post-new.php' ;
2006-05-03 00:36:06 +02:00
check_admin_referer ( 'add-post' );
2006-03-06 09:19:41 +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
2005-06-18 21:08:38 +02:00
// Redirect.
2004-05-10 10:33:03 +02:00
if ( ! empty ( $_POST [ 'mode' ])) {
switch ( $_POST [ 'mode' ]) {
case 'bookmarklet' :
2005-11-17 04:26:24 +01:00
$location = $_POST [ 'referredby' ];
2004-05-10 10:33:03 +02:00
break ;
case 'sidebar' :
$location = 'sidebar.php?a=b' ;
break ;
default :
2006-02-21 07:11:46 +01:00
$location = 'post-new.php' ;
2004-05-10 10:33:03 +02:00
break ;
}
} else {
2006-02-21 07:11:46 +01:00
$location = 'post-new.php?posted=true' ;
2004-05-10 10:33:03 +02:00
}
2004-10-14 09:26:41 +02:00
2005-11-17 04:26:24 +01:00
if ( isset ( $_POST [ 'save' ]) )
2004-04-28 06:49:16 +02:00
$location = " post.php?action=edit&post= $post_ID " ;
2003-10-26 21:34:24 +01:00
2005-06-18 21:08:38 +02:00
header ( " Location: $location " );
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 ;
2004-04-28 06:49:16 +02:00
require_once ( 'admin-header.php' );
2005-06-19 04:51:48 +02:00
$post_ID = $p = ( int ) $_GET [ 'post' ];
2004-04-28 06:49:16 +02:00
2006-02-21 07:11:46 +01:00
$post = get_post ( $post_ID );
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
?>
< div id = 'preview' class = 'wrap' >
2005-10-29 03:52:56 +02:00
< h2 id = " preview-post " >< ? php _e ( 'Post Preview (updated when post is saved)' ); ?> <small class="quickjump"><a href="#write-post"><?php _e('edit ↑'); ?></a></small></h2>
2006-01-24 00:39:56 +01:00
< iframe src = " <?php echo add_query_arg('preview', 'true', get_permalink( $post->ID )); ?> " width = " 100% " height = " 600 " ></ iframe >
2004-10-22 16:41:01 +02:00
</ div >
< ? php
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
$oldmeta = $newmeta = get_post_meta ( $post_id , '_wp_attachment_metadata' , true );
$newmeta [ 'thumb' ] = $_POST [ 'thumb' ];
if ( '' !== $oldmeta )
update_post_meta ( $post_id , '_wp_attachment_metadata' , $newmeta , $oldmeta );
else
add_post_meta ( $post_id , '_wp_attachment_metadata' , $newmeta );
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-03-06 09:19:41 +01:00
2005-09-08 22:38:30 +02:00
$post_ID = edit_post ();
2004-04-28 06:49:16 +02:00
2005-02-14 10:46:08 +01:00
if ( $_POST [ 'save' ]) {
$location = $_SERVER [ 'HTTP_REFERER' ];
} elseif ( $_POST [ 'updatemeta' ]) {
$location = $_SERVER [ 'HTTP_REFERER' ] . '&message=2#postcustom' ;
} elseif ( $_POST [ 'deletemeta' ]) {
$location = $_SERVER [ 'HTTP_REFERER' ] . '&message=3#postcustom' ;
} elseif ( isset ( $_POST [ 'referredby' ]) && $_POST [ 'referredby' ] != $_SERVER [ 'HTTP_REFERER' ]) {
$location = $_POST [ 'referredby' ];
if ( $_POST [ 'referredby' ] == 'redo' )
$location = get_permalink ( $post_ID );
2005-12-13 20:19:56 +01:00
} elseif ( $action == 'editattachment' ) {
$location = 'attachments.php' ;
2005-02-14 10:46:08 +01:00
} else {
2006-02-27 06:15:13 +01:00
$location = 'post-new.php' ;
2005-02-14 10:46:08 +01:00
}
header ( 'Location: ' . $location ); // Send user on their way while we keep working
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 ) )
2005-02-25 01:20:48 +01:00
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 ) )
die ( __ ( 'Error in deleting...' ) );
} else {
if ( ! wp_delete_post ( $post_id ) )
die ( __ ( 'Error in deleting...' ) );
}
2003-11-12 16:22:47 +01:00
2004-04-28 06:49:16 +02:00
$sendback = $_SERVER [ 'HTTP_REFERER' ];
2006-02-27 06:15:13 +01:00
if ( strstr ( $sendback , 'post.php' )) $sendback = get_settings ( 'siteurl' ) . '/wp-admin/post-new.php' ;
2005-12-13 20:19:56 +01:00
elseif ( strstr ( $sendback , 'attachments.php' )) $sendback = get_settings ( 'siteurl' ) . '/wp-admin/attachments.php' ;
2004-10-05 18:22:31 +02:00
$sendback = preg_replace ( '|[^a-z0-9-~+_.?#=&;,/:]|i' , '' , $sendback );
2004-04-28 06:49:16 +02:00
header ( 'Location: ' . $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-04-04 02:12:43 +02:00
header ( 'Location: edit.php' );
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
?>