PluginProbe
Welcart e-Commerce / 1.3.17
Welcart e-Commerce v1.3.17
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / includes / usces_item_master_edit.php

usces_item_master_edit.php in Welcart e-Commerce 1.3.17, at includes/usces_item_master_edit.php

395 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Edit post administration panel.
4 *
5 * Manage Post actions: post, edit, delete, etc.
6 *
7 * @package WordPress
8 * @subpackage Administration
9 */
10
11 /** WordPress Administration Bootstrap */
12 //require_once('admin.php');
13 /* 30 **************************************/
14 global $wp_version;
15 /***************************************/
16
17 //$parent_file = 'admin.php?page=usces_itemedit';
18 //$submenu_file = 'admin.php?page=usces_itemedit';
19 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
20
21 /**
22 * Redirect to previous page.
23 *
24 * @param int $post_ID Optional. Post ID.
25 */
26 function redirect_post($post_ID = '') {
27 global $action;
28
29 $referredby = '';
30 if ( !empty($_POST['referredby']) ) {
31 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
32 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
33 }
34 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
35
36 if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
37 $location = $_POST['referredby'];
38 } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
39 if ( isset($_POST['saveasdraft']) )
40 $location = 'sidebar.php?a=c';
41 elseif ( isset($_POST['publish']) )
42 $location = 'sidebar.php?a=b';
43 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
44 if ( isset($_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 ) {
45 $location = add_query_arg( array(
46 '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ),
47 'message' => 1
48 ), usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) );
49 } else {
50 if ( isset( $_POST['publish'] ) ) {
51 if ( 'pending' == get_post_status( $post_ID ) )
52 $location = add_query_arg( 'message', 8, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) );
53 else
54 $location = add_query_arg( 'message', 6, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) );
55 } else {
56 $location = add_query_arg( 'message', 7, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) );
57 }
58 //$dd=usces_link_replace( get_edit_post_link( $post_ID, 'url' ) );
59 // var_dump($referer);echo "<br>\n";
60 // var_dump($dd);echo "<br>\n";
61 // var_dump($location);echo "\n";
62 // exit;
63 }
64 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
65 $location = add_query_arg( 'message', 2, wp_get_referer() );
66 $location = explode('#', $location);
67 $location = $location[0] . '#postcustom';
68 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
69 $location = add_query_arg( 'message', 3, wp_get_referer() );
70 $location = explode('#', $location);
71 $location = $location[0] . '#postcustom';
72 } elseif (!empty($referredby) && $referredby != $referer) {
73 $location = $_POST['referredby'];
74 $location = remove_query_arg('_wp_original_http_referer', $location);
75 if ( false !== strpos($location, 'edit.php') || false !== strpos($location, 'edit-post-drafts.php') )
76 $location = add_query_arg('posted', $post_ID, $location);
77 elseif ( false !== strpos($location, 'wp-admin') )
78 $location = "post-new.php?posted=$post_ID";
79 } elseif ( isset($_POST['publish']) ) {
80 $location = "post-new.php?posted=$post_ID";
81 } elseif ($action == 'editattachment') {
82 $location = 'attachments.php';
83 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
84 $location = "post.php?action=edit&post=$post_ID&message=7";
85 } else {
86 $location = add_query_arg( 'message', 4, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) );
87 }
88 //var_dump($location);echo "<br>\n";
89 wp_redirect( $location );
90 }
91
92 function usces_get_message($post_ID) {
93
94 if ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) {
95 if ( isset($_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 ) {
96 $this->action_message = sprintf(__('Post updated. <a href="%s">View post</a>'), get_permalink($post_ID));
97 } else {
98 if ( isset( $_POST['publish'] ) ) {
99 if ( 'pending' == get_post_status( $post_ID ) )
100 $this->action_message = sprintf(__('Post submitted. <a href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
101 else
102 $this->action_message = sprintf(__('Post published. <a href="%s">View post</a>'), get_permalink($post_ID));
103 } else {
104 $this->action_message = __('Post saved.');
105 }
106 }
107 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
108 $this->action_message = __('Custom field updated.');
109 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
110 $this->action_message = __('Custom field deleted.');
111 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
112 $this->action_message = __('Post saved.');
113 } else {
114 $this->action_message = __('Post updated.');
115 }
116
117 $this->action_status = 'none';
118 }
119
120 if ( isset( $_POST['deletepost'] ) )
121 $action = 'delete';
122 //elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
123 // $action = 'preview';
124
125 switch($action) {
126 //case 'postajaxpost':
127 //case 'post-quickpress-publish':
128 //case 'post-quickpress-save':
129 // check_admin_referer('add-post');
130 //
131 // if ( 'post-quickpress-publish' == $action )
132 // $_POST['publish'] = 'publish'; // tell write_post() to publish
133 //
134 // if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
135 // $_POST['comment_status'] = get_option('default_comment_status');
136 // $_POST['ping_status'] = get_option('default_ping_status');
137 // }
138 //
139 // if ( !empty( $_POST['quickpress_post_ID'] ) ) {
140 // $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
141 // $post_ID = edit_post();
142 // } else {
143 // $post_ID = 'postajaxpost' == $action ? item_option_edit_post() : write_post();
144 // }
145 //
146 // if ( 0 === strpos( $action, 'post-quickpress' ) ) {
147 // $_POST['post_ID'] = $post_ID;
148 // // output the quickpress dashboard widget
149 // require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
150 // wp_dashboard_quick_press();
151 // exit;
152 // }
153 //
154 // redirect_post($post_ID);
155 // exit();
156 // break;
157
158 case 'post':
159 case 'edit':
160 $editing = true;
161
162 if ( empty( $_GET['post'] ) ) {
163 wp_redirect("post.php");
164 exit();
165 }
166
167 $title = 'Welcart Shop '.__('Edit item', 'usces');
168
169 $this->action_status = 'none';
170
171 if ( version_compare($wp_version, '3.0-beta', '>') ){
172 global $post;
173 if ( $post ) {
174 $post_type_object = get_post_type_object($post->post_type);
175 if ( $post_type_object ) {
176 $post_type = $post->post_type;
177 if( !isset($current_screen) ){
178 $current_screen = new stdClass();
179 }
180 $current_screen->post_type = $post->post_type;
181 $current_screen->id = $current_screen->post_type;
182 }
183 $post_id = $post->ID;
184 $post_ID = $post->ID;
185 }
186
187 $p = $post_id;
188
189 if ( empty($post->ID) )
190 wp_die( __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?') );
191
192 if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
193 wp_die( __('You are not allowed to edit this item.') );
194
195 if ( 'trash' == $post->post_status )
196 wp_die( __('You can&#8217;t edit this item because it is in the Trash. Please restore it and try again.') );
197
198 if ( null == $post_type_object )
199 wp_die( __('Unknown post type.') );
200
201 $post_type = $post->post_type;
202 //$title = sprintf(__('Edit %s'), $post_type_object->singular_label);
203 if ( version_compare($wp_version, '3.4-beta', '>') ){
204 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced34.php");
205 }else{
206 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced30.php");
207 }
208
209 }else{
210
211 $post_ID = $p = (int) $_GET['post'];
212 $post = get_post($post_ID);
213
214 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
215
216 if ( 'post' != $post->post_type ) {
217 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
218 exit();
219 }
220 if ( !current_user_can('edit_post', $post_ID) )
221 die ( __('You are not allowed to edit this post.') );
222
223 $post = get_post_to_edit($post_ID);
224 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced.php");
225 }
226
227 break;
228
229 //case 'editattachment':
230 // $post_id = (int) $_POST['post_ID'];
231 //
232 // check_admin_referer('update-attachment_' . $post_id);
233 //
234 // // Don't let these be changed
235 // unset($_POST['guid']);
236 // $_POST['post_type'] = 'attachment';
237 //
238 // // Update the thumbnail filename
239 // $newmeta = wp_get_attachment_metadata( $post_id, true );
240 // $newmeta['thumb'] = $_POST['thumb'];
241 //
242 // wp_update_attachment_metadata( $post_id, $newmeta );
243 //
244 case 'editpost':
245
246 global $post;
247 $title = 'Welcart Shop '.__('Edit item', 'usces');
248 // if ( !current_user_can('edit_post', $post->ID) )
249 // die ( __('You are not allowed to edit this post.') );
250
251 if ( version_compare($wp_version, '3.0-beta', '>') ){
252 if ( $post ) {
253 $post_type_object = get_post_type_object($post->post_type);
254 if ( $post_type_object ) {
255 $post_type = $post->post_type;
256 if( !isset($current_screen) ){
257 $current_screen = new stdClass();
258 }
259 $current_screen->post_type = $post->post_type;
260 $current_screen->id = $current_screen->post_type;
261 }
262 $post_id = $post->ID;
263 $post_ID = $post->ID;
264 }
265 add_action('check_admin_referer', 'usces_update_check_admin');
266
267 check_admin_referer('update-' . $post_type . '_' . $post_id);
268 $post_id = edit_post();
269 $post_ID = $post_id;
270
271 if ( version_compare($wp_version, '3.5-beta', '>') ){
272 $post = get_post($post_id, OBJECT, 'edit');
273 }else{
274 $post = get_post_to_edit($post_ID);
275 }
276
277 //redirect_post($post_id); // Send user on their way while we keep working
278 if ( version_compare($wp_version, '3.4-beta', '>') ){
279 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced34.php");
280 }else{
281 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced30.php");
282 }
283 }else{
284
285 $post_ID = edit_post();
286 $post = get_post_to_edit($post_ID);
287
288 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced.php");
289 }
290
291
292 if ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) {
293 if ( isset($_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 ) {
294 $this->action_message = sprintf(__('Post updated. <a href="%s">View post</a>'), get_permalink($post_ID));
295 } else {
296 if ( isset( $_POST['publish'] ) ) {
297 if ( 'pending' == get_post_status( $post_ID ) )
298 $this->action_message = sprintf(__('Post submitted. <a href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
299 else
300 $this->action_message = sprintf(__('Post published. <a href="%s">View post</a>'), get_permalink($post_ID));
301 } else {
302 $this->action_message = __('Post saved.');
303 }
304 }
305 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
306 $this->action_message = __('Custom field updated.');
307 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
308 $this->action_message = __('Custom field deleted.');
309 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
310 $this->action_message = __('Post saved.');
311 } else {
312 $this->action_message = __('Post updated.');
313 }
314 $this->action_status = 'success';
315 // redirect_post($post_ID); // Send user on their way while we keep working
316 // exit();
317 break;
318
319 case 'new':
320
321 $title = 'Welcart Shop ' . __('Add New Item', 'usces');
322 global $post;
323
324 if ( version_compare($wp_version, '3.0-beta', '>') ){
325 global $post_ID, $current_screen;
326 if ( !isset($_GET['post_type']) )
327 $post_type = 'post';
328 elseif ( in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
329 $post_type = $_GET['post_type'];
330 else
331 wp_die( __('Invalid post type') );
332
333 $action = 'post';
334 $post = get_default_post_to_edit( $post_type, true );
335 $post_ID = $post->ID;
336
337 if ( version_compare($wp_version, '3.4-beta', '>') ){
338 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced34.php");
339 }else{
340 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced30.php");
341 }
342 }else{
343 if ( current_user_can('edit_pages') ) {
344 $action = 'post';
345 $post = get_default_post_to_edit();
346 include(USCES_PLUGIN_DIR."/includes/edit-form-advanced.php");
347 }
348 }
349
350
351 break;
352
353 case 'delete':
354 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
355 check_admin_referer('delete-post_' . $post_id);
356
357 $post = & get_post($post_id);
358
359 if ( !current_user_can('delete_post', $post_id) )
360 wp_die( __('You are not allowed to delete this post.') );
361
362 if ( $post->post_type == 'attachment' ) {
363 if ( ! wp_delete_attachment($post_id) )
364 wp_die( __('Error in deleting...') );
365 } else {
366 if ( !wp_delete_post($post_id) )
367 wp_die( __('Error in deleting...') );
368 }
369
370 $sendback = wp_get_referer();
371 if (strpos($sendback, 'admin.php') !== false) $sendback = admin_url('admin.php?page=usces_itemedit&deleted=1');
372 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
373 //else $sendback = add_query_arg('deleted', 1, $sendback);
374 else $sendback = admin_url('admin.php?page=usces_itemedit&deleted=1');
375 //wp_redirect($sendback);
376 exit();
377 break;
378
379 //case 'preview':
380 // check_admin_referer( 'autosave', 'autosavenonce' );
381 //
382 // $url = post_preview();
383 //var_dump($url);
384 //// wp_redirect($url);
385 // exit();
386 // break;
387
388 default:
389 //wp_redirect('admin.php?page=usces_itemedit');
390 exit();
391 break;
392 } // end switch
393 //include('admin-footer.php');
394 ?>
395