PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/media-upload.php

https://bitbucket.org/aqge/deptandashboard
PHP | 139 lines | 98 code | 25 blank | 16 comment | 22 complexity | 4b2c37a1ae08cc211087f5dd68bdaa63 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.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. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  22. // IDs should be integers
  23. $ID = isset($ID) ? (int) $ID : 0;
  24. $post_id = isset($post_id)? (int) $post_id : 0;
  25. // Require an ID for the edit screen
  26. if ( isset($action) && $action == 'edit' && !$ID )
  27. wp_die(__("You are not allowed to be here"));
  28. if ( isset($_GET['inline']) ) {
  29. $errors = array();
  30. if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
  31. check_admin_referer('media-form');
  32. // Upload File button was clicked
  33. $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
  34. unset($_FILES);
  35. if ( is_wp_error($id) ) {
  36. $errors['upload_error'] = $id;
  37. $id = false;
  38. }
  39. }
  40. if ( isset($_GET['upload-page-form']) ) {
  41. $errors = array_merge($errors, (array) media_upload_form_handler());
  42. $location = 'upload.php';
  43. if ( $errors )
  44. $location .= '?message=3';
  45. wp_redirect( admin_url($location) );
  46. exit;
  47. }
  48. $title = __('Upload New Media');
  49. $parent_file = 'upload.php';
  50. get_current_screen()->add_help_tab( array(
  51. 'id' => 'overview',
  52. 'title' => __('Overview'),
  53. 'content' =>
  54. '<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>' .
  55. '<ul>' .
  56. '<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' .
  57. '<li>' . __('<strong>Select Files</strong> will open the multi-file uploader, or you can use the <strong>Browser Uploader</strong>.') . '</li>' .
  58. '<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>' .
  59. '</ul>' .
  60. '<p>' . __('Basic image editing is available after upload is complete. Make sure you click Save before leaving this screen.') . '</p>'
  61. ) );
  62. get_current_screen()->set_help_sidebar(
  63. '<p><strong>' . __('For more information:') . '</strong></p>' .
  64. '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
  65. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  66. );
  67. require_once('./admin-header.php');
  68. $form_class = 'media-upload-form type-form validate';
  69. if ( get_user_setting('uploader') )
  70. $form_class .= ' html-uploader';
  71. ?>
  72. <div class="wrap">
  73. <?php screen_icon(); ?>
  74. <h2><?php echo esc_html( $title ); ?></h2>
  75. <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">
  76. <?php media_upload_form(); ?>
  77. <script type="text/javascript">
  78. jQuery(function($){
  79. var preloaded = $(".media-item.preloaded");
  80. if ( preloaded.length > 0 ) {
  81. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  82. }
  83. updateMediaForm();
  84. post_id = 0;
  85. shortform = 1;
  86. });
  87. </script>
  88. <input type="hidden" name="post_id" id="post_id" value="0" />
  89. <?php wp_nonce_field('media-form'); ?>
  90. <div id="media-items" class="hide-if-no-js"></div>
  91. <?php submit_button( __( 'Save all changes' ), 'button savebutton hidden', 'save' ); ?>
  92. </form>
  93. </div>
  94. <?php
  95. include('./admin-footer.php');
  96. } else {
  97. // upload type: image, video, file, ..?
  98. if ( isset($_GET['type']) )
  99. $type = strval($_GET['type']);
  100. else
  101. $type = apply_filters('media_upload_default_type', 'file');
  102. // tab: gallery, library, or type-specific
  103. if ( isset($_GET['tab']) )
  104. $tab = strval($_GET['tab']);
  105. else
  106. $tab = apply_filters('media_upload_default_tab', 'type');
  107. $body_id = 'media-upload';
  108. // let the action code decide how to handle the request
  109. if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) )
  110. do_action("media_upload_$type");
  111. else
  112. do_action("media_upload_$tab");
  113. }
  114. ?>