]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/post.php
Wordpress 2.6.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 function redirect_post($post_ID = '') {
10         global $action;
11
12         $referredby = '';
13         if ( !empty($_POST['referredby']) ) {
14                 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
15                 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
16         }
17         $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
18
19         if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
20                 $location = $_POST['referredby'];
21         } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
22                 $location = 'sidebar.php?a=b';
23         } elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
24                 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 )
25                         $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
26                 else
27                         $location = "post.php?action=edit&post=$post_ID&message=4";
28         } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
29                 $location = add_query_arg( 'message', 2, wp_get_referer() );
30                 $location = explode('#', $location);
31                 $location = $location[0] . '#postcustom';
32         } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
33                 $location = add_query_arg( 'message', 3, wp_get_referer() );
34                 $location = explode('#', $location);
35                 $location = $location[0] . '#postcustom';
36         } elseif (!empty($referredby) && $referredby != $referer) {
37                 $location = $_POST['referredby'];
38                 $location = remove_query_arg('_wp_original_http_referer', $location);
39                 if ( false !== strpos($location, 'edit.php') )
40                         $location = add_query_arg('posted', $post_ID, $location);               
41                 elseif ( false !== strpos($location, 'wp-admin') )
42                         $location = "post-new.php?posted=$post_ID";
43         } elseif ( isset($_POST['publish']) ) {
44                 $location = "post-new.php?posted=$post_ID";
45         } elseif ($action == 'editattachment') {
46                 $location = 'attachments.php';
47         } else {
48                 $location = "post.php?action=edit&post=$post_ID&message=4";
49         }
50
51         wp_redirect( $location );
52 }
53
54 if ( isset( $_POST['deletepost'] ) )
55         $action = 'delete';
56
57 switch($action) {
58 case 'postajaxpost':
59 case 'post':
60         check_admin_referer('add-post');
61
62         $post_ID = 'post' == $action ? write_post() : edit_post();
63
64         redirect_post($post_ID);
65         exit();
66         break;
67
68 case 'edit':
69         $title = __('Edit');
70         $editing = true;
71
72         if ( empty( $_GET['post'] ) ) {
73                 wp_redirect("post.php");
74                 exit();
75         }
76         $post_ID = $p = (int) $_GET['post'];
77         $post = get_post($post_ID);
78
79         if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
80
81         if ( 'post' != $post->post_type ) {
82                 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
83                 exit();
84         }
85
86         wp_enqueue_script('post');
87         if ( user_can_richedit() )
88                 wp_enqueue_script('editor');
89         add_thickbox();
90         wp_enqueue_script('media-upload');
91         wp_enqueue_script('word-count');
92
93         if ( current_user_can('edit_post', $post_ID) ) {
94                 if ( $last = wp_check_post_lock( $post->ID ) ) {
95                         $last_user = get_userdata( $last );
96                         $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
97                         $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
98                         $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
99                         add_action('admin_notices', create_function( '', "echo '$message';" ) );
100                 } else {
101                         wp_set_post_lock( $post->ID );
102                         wp_enqueue_script('autosave');
103                 }
104         }
105
106         require_once('admin-header.php');
107
108         if ( !current_user_can('edit_post', $post_ID) )
109                 die ( __('You are not allowed to edit this post.') );
110
111         $post = get_post_to_edit($post_ID);
112
113         include('edit-form-advanced.php');
114
115         break;
116
117 case 'editattachment':
118         $post_id = (int) $_POST['post_ID'];
119
120         check_admin_referer('update-attachment_' . $post_id);
121
122         // Don't let these be changed
123         unset($_POST['guid']);
124         $_POST['post_type'] = 'attachment';
125
126         // Update the thumbnail filename
127         $newmeta = wp_get_attachment_metadata( $post_id, true );
128         $newmeta['thumb'] = $_POST['thumb'];
129
130         wp_update_attachment_metadata( $post_id, $newmeta );
131
132 case 'editpost':
133         $post_ID = (int) $_POST['post_ID'];
134         check_admin_referer('update-post_' . $post_ID);
135
136         $post_ID = edit_post();
137
138         redirect_post($post_ID); // Send user on their way while we keep working
139
140         exit();
141         break;
142
143 case 'delete':
144         $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
145         check_admin_referer('delete-post_' . $post_id);
146
147         $post = & get_post($post_id);
148
149         if ( !current_user_can('delete_post', $post_id) )
150                 wp_die( __('You are not allowed to delete this post.') );
151
152         if ( $post->post_type == 'attachment' ) {
153                 if ( ! wp_delete_attachment($post_id) )
154                         wp_die( __('Error in deleting...') );
155         } else {
156                 if ( !wp_delete_post($post_id) )
157                         wp_die( __('Error in deleting...') );
158         }
159
160         $sendback = wp_get_referer();
161         if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('post-new.php');
162         elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
163         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
164         wp_redirect($sendback);
165         exit();
166         break;
167
168 default:
169         wp_redirect('edit.php');
170         exit();
171         break;
172 } // end switch
173 include('admin-footer.php');
174 ?>