PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/async-upload.php

https://github.com/muskmelon/Greemo
PHP | 70 lines | 49 code | 11 blank | 10 comment | 20 complexity | 3a1aa62c93a9974c19f8f15692784099 MD5 | raw file
  1. <?php
  2. /**
  3. * Accepts file uploads from swfupload or other asynchronous upload methods.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. define('WP_ADMIN', true);
  9. if ( defined('ABSPATH') )
  10. require_once(ABSPATH . 'wp-load.php');
  11. else
  12. require_once('../wp-load.php');
  13. // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
  14. if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  15. $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  16. elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  17. $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  18. if ( empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie']) )
  19. $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie'];
  20. unset($current_user);
  21. require_once('./admin.php');
  22. header('Content-Type: text/plain; charset=' . get_option('blog_charset'));
  23. if ( !current_user_can('upload_files') )
  24. wp_die(__('You do not have permission to upload files.'));
  25. // just fetch the detail form for that attachment
  26. if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
  27. $post = get_post( $id );
  28. if ( 'attachment' != $post->post_type )
  29. wp_die( __( 'Unknown post type.' ) );
  30. $post_type_object = get_post_type_object( 'attachment' );
  31. if ( ! current_user_can( $post_type_object->cap->edit_post, $id ) )
  32. wp_die( __( 'You are not allowed to edit this item.' ) );
  33. if ( 2 == $_REQUEST['fetch'] ) {
  34. add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
  35. echo get_media_item($id, array( 'send' => false, 'delete' => true ));
  36. } else {
  37. add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  38. echo get_media_item($id);
  39. }
  40. exit;
  41. }
  42. check_admin_referer('media-form');
  43. $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
  44. if ( is_wp_error($id) ) {
  45. echo '<div class="error-div">
  46. <a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a>
  47. <strong>' . sprintf(__('&#8220;%s&#8221; has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' .
  48. esc_html($id->get_error_message()) . '</div>';
  49. exit;
  50. }
  51. if ( $_REQUEST['short'] ) {
  52. // short form response - attachment ID only
  53. echo $id;
  54. } else {
  55. // long form response - big chunk o html
  56. $type = $_REQUEST['type'];
  57. echo apply_filters("async_upload_{$type}", $id);
  58. }
  59. ?>