]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/post.php
Wordpress 2.5.1-scripts
[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 ( $_POST['referredby'] == 'redo' )
40                         $location = get_permalink( $post_ID );
41                 elseif ( false !== strpos($location, 'edit.php') )
42                         $location = add_query_arg('posted', $post_ID, $location);               
43                 elseif ( false !== strpos($location, 'wp-admin') )
44                         $location = "post-new.php?posted=$post_ID";
45         } elseif ( isset($_POST['publish']) ) {
46                 $location = "post-new.php?posted=$post_ID";
47         } elseif ($action == 'editattachment') {
48                 $location = 'attachments.php';
49         } else {
50                 $location = "post.php?action=edit&post=$post_ID&message=4";
51         }
52
53         wp_redirect( $location );
54 }
55
56 if ( isset( $_POST['deletepost'] ) )
57         $action = 'delete';
58
59 switch($action) {
60 case 'postajaxpost':
61 case 'post':
62         check_admin_referer('add-post');
63
64         $post_ID = 'post' == $action ? write_post() : edit_post();
65
66         redirect_post($post_ID);
67         exit();
68         break;
69
70 case 'edit':
71         $title = __('Edit');
72         $editing = true;
73
74         if ( empty( $_GET['post'] ) ) {
75                 wp_redirect("post.php");
76                 exit();
77         }
78         $post_ID = $p = (int) $_GET['post'];
79         $post = get_post($post_ID);
80
81         if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
82
83         if ( 'page' == $post->post_type ) {
84                 wp_redirect("page.php?action=edit&post=$post_ID");
85                 exit();
86         }
87
88         wp_enqueue_script('post');
89         if ( user_can_richedit() )
90                 wp_enqueue_script('editor');
91         wp_enqueue_script('thickbox');
92         wp_enqueue_script('media-upload');
93
94         if ( current_user_can('edit_post', $post_ID) ) {
95                 if ( $last = wp_check_post_lock( $post->ID ) ) {
96                         $last_user = get_userdata( $last );
97                         $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
98                         $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
99                         $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
100                         add_action('admin_notices', create_function( '', "echo '$message';" ) );
101                 } else {
102                         wp_set_post_lock( $post->ID );
103                         wp_enqueue_script('autosave');
104                 }
105         }
106
107         require_once('admin-header.php');
108
109         if ( !current_user_can('edit_post', $post_ID) )
110                 die ( __('You are not allowed to edit this post.') );
111
112         $post = get_post_to_edit($post_ID);
113
114         include('edit-form-advanced.php');
115
116         break;
117
118 case 'editattachment':
119         $post_id = (int) $_POST['post_ID'];
120
121         check_admin_referer('update-attachment_' . $post_id);
122
123         // Don't let these be changed
124         unset($_POST['guid']);
125         $_POST['post_type'] = 'attachment';
126
127         // Update the thumbnail filename
128         $newmeta = wp_get_attachment_metadata( $post_id, true );
129         $newmeta['thumb'] = $_POST['thumb'];
130
131         wp_update_attachment_metadata( $post_id, $newmeta );
132
133 case 'editpost':
134         $post_ID = (int) $_POST['post_ID'];
135         check_admin_referer('update-post_' . $post_ID);
136
137         $post_ID = edit_post();
138
139         redirect_post($post_ID); // 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 ?>