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