author | Anthony Ly <anthonyly.com@gmail.com> |
Mon, 19 Nov 2012 18:26:13 +0100 | |
changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 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 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
12 |
if ( ! isset( $_GET['inline'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
13 |
define( 'IFRAME_REQUEST' , true ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
14 |
|
136 | 15 |
/** Load WordPress Administration Bootstrap */ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
require_once('./admin.php'); |
136 | 17 |
|
18 |
if (!current_user_can('upload_files')) |
|
19 |
wp_die(__('You do not have permission to upload files.')); |
|
20 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
wp_enqueue_script('plupload-handlers'); |
136 | 22 |
wp_enqueue_script('image-edit'); |
23 |
wp_enqueue_script('set-post-thumbnail' ); |
|
24 |
wp_enqueue_style('imgareaselect'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
wp_enqueue_script( 'media-gallery' ); |
136 | 26 |
|
27 |
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); |
|
28 |
||
29 |
// IDs should be integers |
|
30 |
$ID = isset($ID) ? (int) $ID : 0; |
|
31 |
$post_id = isset($post_id)? (int) $post_id : 0; |
|
32 |
||
33 |
// Require an ID for the edit screen |
|
34 |
if ( isset($action) && $action == 'edit' && !$ID ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
wp_die( __( 'Cheatin’ uh?' ) ); |
136 | 36 |
|
37 |
if ( isset($_GET['inline']) ) { |
|
38 |
$errors = array(); |
|
39 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
40 |
if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
41 |
wp_die( __( 'Cheatin’ uh?' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
42 |
|
136 | 43 |
if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
check_admin_referer('media-form'); |
136 | 45 |
// Upload File button was clicked |
46 |
$id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
|
47 |
unset($_FILES); |
|
48 |
if ( is_wp_error($id) ) { |
|
49 |
$errors['upload_error'] = $id; |
|
50 |
$id = false; |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
if ( isset($_GET['upload-page-form']) ) { |
|
55 |
$errors = array_merge($errors, (array) media_upload_form_handler()); |
|
56 |
||
57 |
$location = 'upload.php'; |
|
58 |
if ( $errors ) |
|
59 |
$location .= '?message=3'; |
|
60 |
||
61 |
wp_redirect( admin_url($location) ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
62 |
exit; |
136 | 63 |
} |
64 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
65 |
if ( isset( $_REQUEST['post_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
66 |
wp_die( __( 'Cheatin’ uh?' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
67 |
|
136 | 68 |
$title = __('Upload New Media'); |
69 |
$parent_file = 'upload.php'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
70 |
get_current_screen()->add_help_tab( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
71 |
'id' => 'overview', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
72 |
'title' => __('Overview'), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
73 |
'content' => |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
74 |
'<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>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
75 |
'<ul>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
76 |
'<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
77 |
'<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>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
78 |
'<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
79 |
'</ul>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
80 |
'<p>' . __('Basic image editing is available after upload is complete. Make sure you click Save before leaving this screen.') . '</p>' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
81 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
82 |
get_current_screen()->set_help_sidebar( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
'<p><strong>' . __('For more information:') . '</strong></p>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
84 |
'<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
86 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
87 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
88 |
require_once('./admin-header.php'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
89 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
90 |
$form_class = 'media-upload-form type-form validate'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
92 |
if ( get_user_setting('uploader') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
93 |
$form_class .= ' html-uploader'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
94 |
?> |
136 | 95 |
<div class="wrap"> |
96 |
<?php screen_icon(); ?> |
|
97 |
<h2><?php echo esc_html( $title ); ?></h2> |
|
98 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
99 |
<form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-upload.php?inline=&upload-page-form='); ?>" class="<?php echo $form_class; ?>" id="file-form"> |
136 | 100 |
|
101 |
<?php media_upload_form(); ?> |
|
102 |
||
103 |
<script type="text/javascript"> |
|
104 |
jQuery(function($){ |
|
105 |
var preloaded = $(".media-item.preloaded"); |
|
106 |
if ( preloaded.length > 0 ) { |
|
107 |
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
|
108 |
} |
|
109 |
updateMediaForm(); |
|
110 |
post_id = 0; |
|
111 |
shortform = 1; |
|
112 |
}); |
|
113 |
</script> |
|
114 |
<input type="hidden" name="post_id" id="post_id" value="0" /> |
|
115 |
<?php wp_nonce_field('media-form'); ?> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
116 |
<div id="media-items" class="hide-if-no-js"></div> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
<?php submit_button( __( 'Save all changes' ), 'button savebutton hidden', 'save' ); ?> |
136 | 118 |
</form> |
119 |
</div> |
|
120 |
||
121 |
<?php |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
122 |
include('./admin-footer.php'); |
136 | 123 |
|
124 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
125 |
if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
126 |
wp_die( __( 'Cheatin’ uh?' ) ); |
136 | 127 |
|
128 |
// upload type: image, video, file, ..? |
|
129 |
if ( isset($_GET['type']) ) |
|
130 |
$type = strval($_GET['type']); |
|
131 |
else |
|
132 |
$type = apply_filters('media_upload_default_type', 'file'); |
|
133 |
||
134 |
// tab: gallery, library, or type-specific |
|
135 |
if ( isset($_GET['tab']) ) |
|
136 |
$tab = strval($_GET['tab']); |
|
137 |
else |
|
138 |
$tab = apply_filters('media_upload_default_tab', 'type'); |
|
139 |
||
140 |
$body_id = 'media-upload'; |
|
141 |
||
142 |
// let the action code decide how to handle the request |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
143 |
if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) ) |
136 | 144 |
do_action("media_upload_$type"); |
145 |
else |
|
146 |
do_action("media_upload_$tab"); |
|
147 |
} |