PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> post.php (source)

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


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt