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 |
* 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('../wp-load.php'); |
|
15 |
||
16 |
// Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead |
|
17 |
if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) ) |
|
18 |
$_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie']; |
|
19 |
elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) ) |
|
20 |
$_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie']; |
|
21 |
if ( empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie']) ) |
|
22 |
$_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie']; |
|
23 |
unset($current_user); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
require_once('./admin.php'); |
136 | 25 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
136 | 27 |
|
28 |
if ( !current_user_can('upload_files') ) |
|
29 |
wp_die(__('You do not have permission to upload files.')); |
|
30 |
||
31 |
// just fetch the detail form for that attachment |
|
32 |
if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
$post = get_post( $id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
34 |
if ( 'attachment' != $post->post_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
wp_die( __( 'Unknown post type.' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
36 |
$post_type_object = get_post_type_object( 'attachment' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
37 |
if ( ! current_user_can( $post_type_object->cap->edit_post, $id ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
wp_die( __( 'You are not allowed to edit this item.' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
|
136 | 40 |
if ( 2 == $_REQUEST['fetch'] ) { |
41 |
add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); |
|
42 |
echo get_media_item($id, array( 'send' => false, 'delete' => true )); |
|
43 |
} else { |
|
44 |
add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); |
|
45 |
echo get_media_item($id); |
|
46 |
} |
|
47 |
exit; |
|
48 |
} |
|
49 |
||
50 |
check_admin_referer('media-form'); |
|
51 |
||
52 |
$id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
if ( is_wp_error($id) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
54 |
echo '<div class="error-div"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
<a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
<strong>' . sprintf(__('“%s” has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' . |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
esc_html($id->get_error_message()) . '</div>'; |
136 | 58 |
exit; |
59 |
} |
|
60 |
||
61 |
if ( $_REQUEST['short'] ) { |
|
62 |
// short form response - attachment ID only |
|
63 |
echo $id; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
64 |
} else { |
136 | 65 |
// long form response - big chunk o html |
66 |
$type = $_REQUEST['type']; |
|
67 |
echo apply_filters("async_upload_{$type}", $id); |
|
68 |
} |