[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-admin/ -> async-upload.php (source)

   1  <?php
   2  /**
   3   * Accepts file uploads from swfupload or other asynchronous upload methods.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  define('WP_ADMIN', true);
  10  
  11  if ( defined('ABSPATH') )
  12      require_once (ABSPATH . 'wp-load.php');
  13  else
  14      require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
  15  
  16  if ( ! ( isset( $_REQUEST['action'] ) && 'upload-attachment' == $_REQUEST['action'] ) ) {
  17      // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
  18      if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  19          $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  20      elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  21          $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  22      if ( empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie']) )
  23          $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie'];
  24      unset($current_user);
  25  }
  26  
  27  require_once ( ABSPATH . 'wp-admin/admin.php' );
  28  
  29  if ( !current_user_can('upload_files') )
  30      wp_die(__('You do not have permission to upload files.'));
  31  
  32  header('Content-Type: text/html; charset=' . get_option('blog_charset'));
  33  
  34  if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
  35      define( 'DOING_AJAX', true );
  36      include  ABSPATH . 'wp-admin/includes/ajax-actions.php';
  37  
  38      send_nosniff_header();
  39      nocache_headers();
  40  
  41      wp_ajax_upload_attachment();
  42      die( '0' );
  43  }
  44  
  45  // just fetch the detail form for that attachment
  46  if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
  47      $post = get_post( $id );
  48      if ( 'attachment' != $post->post_type )
  49          wp_die( __( 'Unknown post type.' ) );
  50      if ( ! current_user_can( 'edit_post', $id ) )
  51          wp_die( __( 'You are not allowed to edit this item.' ) );
  52  
  53      switch ( $_REQUEST['fetch'] ) {
  54          case 3 :
  55              if ( $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ) )
  56                  echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
  57              echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
  58              $title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // title shouldn't ever be empty, but use filename just in cas.e
  59              echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
  60              break;
  61          case 2 :
  62              add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
  63              echo get_media_item($id, array( 'send' => false, 'delete' => true ));
  64              break;
  65          default:
  66              add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  67              echo get_media_item($id);
  68              break;
  69      }
  70      exit;
  71  }
  72  
  73  check_admin_referer('media-form');
  74  
  75  $post_id = 0;
  76  if ( isset( $_REQUEST['post_id'] ) ) {
  77      $post_id = absint( $_REQUEST['post_id'] );
  78      if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
  79          $post_id = 0;
  80  }
  81  
  82  $id = media_handle_upload( 'async-upload', $post_id );
  83  if ( is_wp_error($id) ) {
  84      echo '<div class="error-div">
  85      <a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a>
  86      <strong>' . sprintf(__('&#8220;%s&#8221; has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' .
  87      esc_html($id->get_error_message()) . '</div>';
  88      exit;
  89  }
  90  
  91  if ( $_REQUEST['short'] ) {
  92      // short form response - attachment ID only
  93      echo $id;
  94  } else {
  95      // long form response - big chunk o html
  96      $type = $_REQUEST['type'];
  97  
  98      /**
  99       * Filter the returned ID of an uploaded attachment.
 100       *
 101       * The dynamic portion of the hook name, $type, refers to the attachment type,
 102       * such as 'iamge', 'audio', 'video', 'file', etc.
 103       *
 104       * @since 2.5.0
 105       *
 106       * @param int $id Uploaded attachment ID.
 107       */
 108      echo apply_filters( "async_upload_{$type}", $id );
 109  }


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu