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