]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/page.php
Wordpress 2.3.3
[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 if (isset($_POST['deletepost'])) {
10 $action = "delete";
11 }
12
13 switch($action) {
14 case 'post':
15         check_admin_referer('add-page');
16         $page_ID = write_post();
17
18         // Redirect.
19         if (!empty($_POST['mode'])) {
20         switch($_POST['mode']) {
21                 case 'bookmarklet':
22                         $location = $_POST['referredby'];
23                         break;
24                 case 'sidebar':
25                         $location = 'sidebar.php?a=b';
26                         break;
27                 default:
28                         $location = 'page-new.php';
29                         break;
30                 }
31         } else {
32                 $location = "page-new.php?posted=$page_ID";
33         }
34
35         if ( isset($_POST['save']) )
36                 $location = "page.php?action=edit&post=$page_ID";
37
38         wp_redirect($location);
39         exit();
40         break;
41
42 case 'edit':
43         $title = __('Edit');
44         $editing = true;
45         $page_ID = $post_ID = $p = (int) $_GET['post'];
46         $post = get_post_to_edit($page_ID);
47
48         if ( empty($post->ID) ) wp_die( __("You attempted to edit a page that doesn't exist. Perhaps it was deleted?") );
49
50         if ( 'post' == $post->post_type ) {
51                 wp_redirect("post.php?action=edit&post=$post_ID");
52                 exit();
53         }
54
55         if($post->post_status == 'draft') {
56                 wp_enqueue_script('prototype');
57                 wp_enqueue_script('interface');
58                 wp_enqueue_script('autosave');
59         }
60         require_once('admin-header.php');
61
62         if ( !current_user_can('edit_page', $page_ID) )
63                 die ( __('You are not allowed to edit this page.') );
64
65         include('edit-page-form.php');
66         break;
67
68 case 'editattachment':
69         $page_id = $post_ID = (int) $_POST['post_ID'];
70         check_admin_referer('update-attachment_' . $page_id);
71
72         // Don't let these be changed
73         unset($_POST['guid']);
74         $_POST['post_type'] = 'attachment';
75
76         // Update the thumbnail filename
77         $newmeta = wp_get_attachment_metadata( $page_id, true );
78         $newmeta['thumb'] = $_POST['thumb'];
79
80         wp_update_attachment_metadata( $newmeta );
81
82 case 'editpost':
83         $page_ID = (int) $_POST['post_ID'];
84         check_admin_referer('update-page_' . $page_ID);
85
86         $page_ID = edit_post();
87
88         if ( 'post' == $_POST['originalaction'] ) {
89                 if (!empty($_POST['mode'])) {
90                 switch($_POST['mode']) {
91                         case 'bookmarklet':
92                                 $location = $_POST['referredby'];
93                                 break;
94                         case 'sidebar':
95                                 $location = 'sidebar.php?a=b';
96                                 break;
97                         default:
98                                 $location = 'page-new.php';
99                                 break;
100                         }
101                 } else {
102                         $location = "page-new.php?posted=$page_ID";
103                 }
104
105                 if ( isset($_POST['save']) )
106                         $location = "page.php?action=edit&post=$page_ID";
107         } else {
108                 if ($_POST['save']) {
109                         $location = "page.php?action=edit&post=$page_ID";
110                 } elseif ($_POST['updatemeta']) {
111                         $location = wp_get_referer() . '&message=2#postcustom';
112                 } elseif ($_POST['deletemeta']) {
113                         $location = wp_get_referer() . '&message=3#postcustom';
114                 } elseif (!empty($_POST['referredby']) && $_POST['referredby'] != wp_get_referer()) {
115                         $location = $_POST['referredby'];
116                         if ( $_POST['referredby'] == 'redo' )
117                                 $location = get_permalink( $page_ID );
118                 } elseif ($action == 'editattachment') {
119                         $location = 'attachments.php';
120                 } else {
121                         $location = 'page-new.php';
122                 }
123         }
124         wp_redirect($location); // Send user on their way while we keep working
125
126         exit();
127         break;
128
129 case 'delete':
130         $page_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
131         check_admin_referer('delete-page_' .  $page_id);
132
133         $page = & get_post($page_id);
134
135         if ( !current_user_can('delete_page', $page_id) )
136                 wp_die( __('You are not allowed to delete this page.') );
137
138         if ( $page->post_type == 'attachment' ) {
139                 if ( ! wp_delete_attachment($page_id) )
140                         wp_die( __('Error in deleting...') );
141         } else {
142                 if ( !wp_delete_post($page_id) )
143                         wp_die( __('Error in deleting...') );
144         }
145
146         $sendback = wp_get_referer();
147         if (strpos($sendback, 'page.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/page.php';
148         elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php';
149         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
150         wp_redirect($sendback);
151         exit();
152         break;
153
154 default:
155         wp_redirect('edit-pages.php');
156         exit();
157         break;
158 } // end switch
159 include('admin-footer.php');
160 ?>