PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-admin/media-upload.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 147 lines | 104 code | 27 blank | 16 comment | 27 complexity | a5550ef40900e683530582f97ea5bddf MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Manage media uploaded file.
  4. *
  5. * There are many filters in here for media. Plugins can extend functionality
  6. * by hooking into the filters.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. if ( ! isset( $_GET['inline'] ) )
  12. define( 'IFRAME_REQUEST' , true );
  13. /** Load WordPress Administration Bootstrap */
  14. require_once('./admin.php');
  15. if (!current_user_can('upload_files'))
  16. wp_die(__('You do not have permission to upload files.'));
  17. wp_enqueue_script('plupload-handlers');
  18. wp_enqueue_script('image-edit');
  19. wp_enqueue_script('set-post-thumbnail' );
  20. wp_enqueue_style('imgareaselect');
  21. wp_enqueue_script( 'media-gallery' );
  22. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  23. // IDs should be integers
  24. $ID = isset($ID) ? (int) $ID : 0;
  25. $post_id = isset($post_id)? (int) $post_id : 0;
  26. // Require an ID for the edit screen
  27. if ( isset($action) && $action == 'edit' && !$ID )
  28. wp_die( __( 'Cheatin&#8217; uh?' ) );
  29. if ( isset($_GET['inline']) ) {
  30. $errors = array();
  31. if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) )
  32. wp_die( __( 'Cheatin&#8217; uh?' ) );
  33. if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
  34. check_admin_referer('media-form');
  35. // Upload File button was clicked
  36. $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
  37. unset($_FILES);
  38. if ( is_wp_error($id) ) {
  39. $errors['upload_error'] = $id;
  40. $id = false;
  41. }
  42. }
  43. if ( isset($_GET['upload-page-form']) ) {
  44. $errors = array_merge($errors, (array) media_upload_form_handler());
  45. $location = 'upload.php';
  46. if ( $errors )
  47. $location .= '?message=3';
  48. wp_redirect( admin_url($location) );
  49. exit;
  50. }
  51. if ( isset( $_REQUEST['post_id'] ) )
  52. wp_die( __( 'Cheatin&#8217; uh?' ) );
  53. $title = __('Upload New Media');
  54. $parent_file = 'upload.php';
  55. get_current_screen()->add_help_tab( array(
  56. 'id' => 'overview',
  57. 'title' => __('Overview'),
  58. 'content' =>
  59. '<p>' . __('You can upload media files here without creating a post first. This allows you to upload files to use with posts and pages later and/or to get a web link for a particular file that you can share. There are three options for uploading files:') . '</p>' .
  60. '<ul>' .
  61. '<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' .
  62. '<li>' . __('Clicking <strong>Select Files</strong> opens a navigation window showing you files in your operating system. Selecting <strong>Open</strong> after clicking on the file you want activates a progress bar on the uploader screen.') . '</li>' .
  63. '<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' .
  64. '</ul>' .
  65. '<p>' . __('Basic image editing is available after upload is complete. Make sure you click Save before leaving this screen.') . '</p>'
  66. ) );
  67. get_current_screen()->set_help_sidebar(
  68. '<p><strong>' . __('For more information:') . '</strong></p>' .
  69. '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
  70. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  71. );
  72. require_once('./admin-header.php');
  73. $form_class = 'media-upload-form type-form validate';
  74. if ( get_user_setting('uploader') )
  75. $form_class .= ' html-uploader';
  76. ?>
  77. <div class="wrap">
  78. <?php screen_icon(); ?>
  79. <h2><?php echo esc_html( $title ); ?></h2>
  80. <form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-upload.php?inline=&amp;upload-page-form='); ?>" class="<?php echo $form_class; ?>" id="file-form">
  81. <?php media_upload_form(); ?>
  82. <script type="text/javascript">
  83. jQuery(function($){
  84. var preloaded = $(".media-item.preloaded");
  85. if ( preloaded.length > 0 ) {
  86. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  87. }
  88. updateMediaForm();
  89. post_id = 0;
  90. shortform = 1;
  91. });
  92. </script>
  93. <input type="hidden" name="post_id" id="post_id" value="0" />
  94. <?php wp_nonce_field('media-form'); ?>
  95. <div id="media-items" class="hide-if-no-js"></div>
  96. <?php submit_button( __( 'Save all changes' ), 'button savebutton hidden', 'save' ); ?>
  97. </form>
  98. </div>
  99. <?php
  100. include('./admin-footer.php');
  101. } else {
  102. if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) )
  103. wp_die( __( 'Cheatin&#8217; uh?' ) );
  104. // upload type: image, video, file, ..?
  105. if ( isset($_GET['type']) )
  106. $type = strval($_GET['type']);
  107. else
  108. $type = apply_filters('media_upload_default_type', 'file');
  109. // tab: gallery, library, or type-specific
  110. if ( isset($_GET['tab']) )
  111. $tab = strval($_GET['tab']);
  112. else
  113. $tab = apply_filters('media_upload_default_tab', 'type');
  114. $body_id = 'media-upload';
  115. // let the action code decide how to handle the request
  116. if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) )
  117. do_action("media_upload_$type");
  118. else
  119. do_action("media_upload_$tab");
  120. }