Projects : mp-wp : mp-wp_genesis
1 | <?php |
2 | /** |
3 | * Edit page administration panel. |
4 | * |
5 | * Manage edit page: post, edit, delete, etc. |
6 | * |
7 | * @package WordPress |
8 | * @subpackage Administration |
9 | */ |
10 | |
11 | /** WordPress Administration Bootstrap */ |
12 | require_once('admin.php'); |
13 | |
14 | $parent_file = 'edit-pages.php'; |
15 | $submenu_file = 'edit-pages.php'; |
16 | |
17 | wp_reset_vars(array('action')); |
18 | |
19 | /** |
20 | * Redirect to previous page. |
21 | * |
22 | * @param int $page_ID Page ID. |
23 | */ |
24 | function redirect_page($page_ID) { |
25 | global $action; |
26 | |
27 | $referredby = ''; |
28 | if ( !empty($_POST['referredby']) ) { |
29 | $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']); |
30 | $referredby = remove_query_arg('_wp_original_http_referer', $referredby); |
31 | } |
32 | $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer()); |
33 | |
34 | if ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) { |
35 | $location = $_POST['referredby']; |
36 | } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { |
37 | $location = 'sidebar.php?a=b'; |
38 | } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) { |
39 | if ( isset($_POST['_wp_original_http_referer']) && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/page.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/page-new.php') === false ) |
40 | $location = add_query_arg( array( |
41 | '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), |
42 | 'message' => 1 |
43 | ), get_edit_post_link( $page_ID, 'url' ) ); |
44 | else { |
45 | if ( isset( $_POST['publish'] ) ) { |
46 | if ( 'pending' == get_post_status( $page_ID ) ) |
47 | $location = add_query_arg( 'message', 6, get_edit_post_link( $page_ID, 'url' ) ); |
48 | else |
49 | $location = add_query_arg( 'message', 5, get_edit_post_link( $page_ID, 'url' ) ); |
50 | } else { |
51 | $location = add_query_arg( 'message', 4, get_edit_post_link( $page_ID, 'url' ) ); |
52 | } |
53 | } |
54 | } elseif ( isset($_POST['addmeta']) ) { |
55 | $location = add_query_arg( 'message', 2, wp_get_referer() ); |
56 | $location = explode('#', $location); |
57 | $location = $location[0] . '#postcustom'; |
58 | } elseif ( isset($_POST['deletemeta']) ) { |
59 | $location = add_query_arg( 'message', 3, wp_get_referer() ); |
60 | $location = explode('#', $location); |
61 | $location = $location[0] . '#postcustom'; |
62 | } elseif (!empty($referredby) && $referredby != $referer) { |
63 | $location = $_POST['referredby']; |
64 | $location = remove_query_arg('_wp_original_http_referer', $location); |
65 | if ( false !== strpos($location, 'edit-pages.php') ) |
66 | $location = add_query_arg('posted', $page_ID, $location); |
67 | elseif ( false !== strpos($location, 'wp-admin') ) |
68 | $location = "page-new.php?posted=$page_ID"; |
69 | } elseif ( isset($_POST['publish']) ) { |
70 | $location = "page-new.php?posted=$page_ID"; |
71 | } elseif ($action == 'editattachment') { |
72 | $location = 'attachments.php'; |
73 | } else { |
74 | $location = add_query_arg( 'message', 4, get_edit_post_link( $page_ID, 'url' ) ); |
75 | } |
76 | |
77 | wp_redirect($location); |
78 | } |
79 | |
80 | if (isset($_POST['deletepost'])) |
81 | $action = "delete"; |
82 | elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
83 | $action = 'preview'; |
84 | |
85 | switch($action) { |
86 | case 'post': |
87 | check_admin_referer('add-page'); |
88 | $page_ID = write_post(); |
89 | |
90 | redirect_page($page_ID); |
91 | |
92 | exit(); |
93 | break; |
94 | |
95 | case 'edit': |
96 | $title = __('Edit Page'); |
97 | $editing = true; |
98 | $page_ID = $post_ID = $p = (int) $_GET['post']; |
99 | $post = get_post_to_edit($page_ID); |
100 | |
101 | if ( empty($post->ID) ) wp_die( __("You attempted to edit a page that doesn't exist. Perhaps it was deleted?") ); |
102 | |
103 | if ( 'page' != $post->post_type ) { |
104 | wp_redirect( get_edit_post_link( $post_ID, 'url' ) ); |
105 | exit(); |
106 | } |
107 | |
108 | wp_enqueue_script('page'); |
109 | if ( user_can_richedit() ) |
110 | wp_enqueue_script('editor'); |
111 | add_thickbox(); |
112 | wp_enqueue_script('media-upload'); |
113 | wp_enqueue_script('word-count'); |
114 | |
115 | if ( current_user_can('edit_page', $page_ID) ) { |
116 | if ( $last = wp_check_post_lock( $post->ID ) ) { |
117 | $last_user = get_userdata( $last ); |
118 | $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); |
119 | $message = sprintf( __( 'Warning: %s is currently editing this page' ), wp_specialchars( $last_user_name ) ); |
120 | $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" ); |
121 | add_action('admin_notices', create_function( '', "echo '$message';" ) ); |
122 | } else { |
123 | wp_set_post_lock( $post->ID ); |
124 | wp_enqueue_script('autosave'); |
125 | } |
126 | } |
127 | |
128 | if ( !current_user_can('edit_page', $page_ID) ) |
129 | die ( __('You are not allowed to edit this page.') ); |
130 | |
131 | include('edit-page-form.php'); |
132 | break; |
133 | |
134 | case 'editattachment': |
135 | $page_id = $post_ID = (int) $_POST['post_ID']; |
136 | check_admin_referer('update-attachment_' . $page_id); |
137 | |
138 | // Don't let these be changed |
139 | unset($_POST['guid']); |
140 | $_POST['post_type'] = 'attachment'; |
141 | |
142 | // Update the thumbnail filename |
143 | $newmeta = wp_get_attachment_metadata( $page_id, true ); |
144 | $newmeta['thumb'] = $_POST['thumb']; |
145 | |
146 | wp_update_attachment_metadata( $newmeta ); |
147 | |
148 | case 'editpost': |
149 | $page_ID = (int) $_POST['post_ID']; |
150 | check_admin_referer('update-page_' . $page_ID); |
151 | |
152 | $page_ID = edit_post(); |
153 | |
154 | redirect_page($page_ID); |
155 | |
156 | exit(); |
157 | break; |
158 | |
159 | case 'delete': |
160 | $page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']); |
161 | check_admin_referer('delete-page_' . $page_id); |
162 | |
163 | $page = & get_post($page_id); |
164 | |
165 | if ( !current_user_can('delete_page', $page_id) ) |
166 | wp_die( __('You are not allowed to delete this page.') ); |
167 | |
168 | if ( $page->post_type == 'attachment' ) { |
169 | if ( ! wp_delete_attachment($page_id) ) |
170 | wp_die( __('Error in deleting...') ); |
171 | } else { |
172 | if ( !wp_delete_post($page_id) ) |
173 | wp_die( __('Error in deleting...') ); |
174 | } |
175 | |
176 | $sendback = wp_get_referer(); |
177 | if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?deleted=1'); |
178 | elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php'); |
179 | else $sendback = add_query_arg('deleted', 1, $sendback); |
180 | wp_redirect($sendback); |
181 | exit(); |
182 | break; |
183 | |
184 | case 'preview': |
185 | check_admin_referer( 'autosave', 'autosavenonce' ); |
186 | |
187 | $url = post_preview(); |
188 | |
189 | wp_redirect($url); |
190 | exit(); |
191 | break; |
192 | |
193 | default: |
194 | wp_redirect('edit-pages.php'); |
195 | exit(); |
196 | break; |
197 | } // end switch |
198 | include('admin-footer.php'); |
199 | ?> |