Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-admin / post.php
1 <?php
2 require_once('admin.php');
3
4 $parent_file = 'edit.php';
5 $submenu_file = 'edit.php';
6
7 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
8
9 if ( isset( $_POST['deletepost'] ) )
10         $action = 'delete';
11
12 switch($action) {
13 case 'postajaxpost':
14 case 'post':
15         $parent_file = 'post-new.php';
16         $submenu_file = 'post-new.php';
17         check_admin_referer('add-post');
18
19         $post_ID = 'post' == $action ? write_post() : edit_post();
20
21         // Redirect.
22         if (!empty($_POST['mode'])) {
23         switch($_POST['mode']) {
24                 case 'bookmarklet':
25                         $location = $_POST['referredby'];
26                         break;
27                 case 'sidebar':
28                         $location = 'sidebar.php?a=b';
29                         break;
30                 default:
31                         $location = 'post-new.php';
32                         break;
33                 }
34         } else {
35                 $location = "post-new.php?posted=$post_ID";
36         }
37
38         if ( isset($_POST['save']) )
39                 $location = "post.php?action=edit&post=$post_ID";
40
41         if ( empty($post_ID) )
42                 $location = 'post-new.php';
43
44         wp_redirect($location);
45         exit();
46         break;
47
48 case 'edit':
49         $title = __('Edit');
50         $editing = true;
51         $post_ID = $p = (int) $_GET['post'];
52         $post = get_post($post_ID);
53
54         if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
55
56         if ( 'page' == $post->post_type ) {
57                 wp_redirect("page.php?action=edit&post=$post_ID");
58                 exit();
59         }
60
61         if($post->post_status == 'draft') {
62                 wp_enqueue_script('prototype');
63                 wp_enqueue_script('autosave');
64         }
65         require_once('admin-header.php');
66
67         if ( !current_user_can('edit_post', $post_ID) )
68                 die ( __('You are not allowed to edit this post.') );
69
70         $post = get_post_to_edit($post_ID);
71
72         include('edit-form-advanced.php');
73
74         break;
75
76 case 'editattachment':
77         $post_id = (int) $_POST['post_ID'];
78
79         check_admin_referer('update-attachment_' . $post_id);
80
81         // Don't let these be changed
82         unset($_POST['guid']);
83         $_POST['post_type'] = 'attachment';
84
85         // Update the thumbnail filename
86         $newmeta = wp_get_attachment_metadata( $post_id, true );
87         $newmeta['thumb'] = $_POST['thumb'];
88
89         wp_update_attachment_metadata( $post_id, $newmeta );
90
91 case 'editpost':
92         $post_ID = (int) $_POST['post_ID'];
93         check_admin_referer('update-post_' . $post_ID);
94
95         $post_ID = edit_post();
96
97         if ( 'post' == $_POST['originalaction'] ) {
98                 if (!empty($_POST['mode'])) {
99                 switch($_POST['mode']) {
100                         case 'bookmarklet':
101                                 $location = $_POST['referredby'];
102                                 break;
103                         case 'sidebar':
104                                 $location = 'sidebar.php?a=b';
105                                 break;
106                         default:
107                                 $location = 'post-new.php';
108                                 break;
109                         }
110                 } else {
111                         $location = "post-new.php?posted=$post_ID";
112                 }
113
114                 if ( isset($_POST['save']) )
115                         $location = "post.php?action=edit&post=$post_ID";
116         } else {
117                 $referredby = '';
118                 if ( !empty($_POST['referredby']) )
119                         $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
120                 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
121
122                 if ($_POST['save']) {
123                         $location = "post.php?action=edit&post=$post_ID";
124                 } elseif ($_POST['updatemeta']) {
125                         $location = wp_get_referer() . '&message=2#postcustom';
126                 } elseif ($_POST['deletemeta']) {
127                         $location = wp_get_referer() . '&message=3#postcustom';
128                 } elseif (!empty($referredby) && $referredby != $referer) {
129                         $location = $_POST['referredby'];
130                         if ( $_POST['referredby'] == 'redo' )
131                                 $location = get_permalink( $post_ID );
132                 } elseif ($action == 'editattachment') {
133                         $location = 'attachments.php';
134                 } else {
135                         $location = 'post-new.php';
136                 }
137         }
138
139         wp_redirect($location); // Send user on their way while we keep working
140
141         exit();
142         break;
143
144 case 'delete':
145         $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
146         check_admin_referer('delete-post_' . $post_id);
147
148         $post = & get_post($post_id);
149
150         if ( !current_user_can('delete_post', $post_id) )
151                 wp_die( __('You are not allowed to delete this post.') );
152
153         if ( $post->post_type == 'attachment' ) {
154                 if ( ! wp_delete_attachment($post_id) )
155                         wp_die( __('Error in deleting...') );
156         } else {
157                 if ( !wp_delete_post($post_id) )
158                         wp_die( __('Error in deleting...') );
159         }
160
161         $sendback = wp_get_referer();
162         if (strpos($sendback, 'post.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/post-new.php';
163         elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php';
164         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
165         wp_redirect($sendback);
166         exit();
167         break;
168
169 default:
170         wp_redirect('edit.php');
171         exit();
172         break;
173 } // end switch
174 include('admin-footer.php');
175 ?>