]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/media.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / media.php
1 <?php
2
3 require_once('admin.php');
4
5 $parent_file = 'edit.php';
6 $submenu_file = 'upload.php';
7
8 wp_reset_vars(array('action'));
9
10 switch( $action ) :
11 case 'editattachment' :
12         $attachment_id = (int) $_POST['attachment_id'];
13         check_admin_referer('media-form');
14
15         if ( !current_user_can('edit_post', $attachment_id) )
16                 wp_die ( __('You are not allowed to edit this attachment.') );
17
18         $errors = media_upload_form_handler();
19
20
21         check_admin_referer('media-form');
22
23         if ( !current_user_can('edit_post', $attachment_id) )
24                 wp_die ( __('You are not allowed to edit this attachment.') );
25
26         if ( empty($errors) ) {
27                 $location = 'media.php';
28                 if ( $referer = wp_get_original_referer() ) {
29                         if ( false !== strpos($referer, 'upload.php') || ( url_to_postid($referer) == $attachment_id )  )
30                                 $location = $referer;
31                 }
32                 if ( false !== strpos($location, 'upload.php') ) {
33                         $location = remove_query_arg('message', $location);
34                         $location = add_query_arg('posted',     $attachment_id, $location);
35                 } elseif ( false !== strpos($location, 'media.php') ) {
36                         $location = add_query_arg('message', 'updated', $location);
37                 }
38                 wp_redirect($location);
39                 exit;
40         }
41
42         // no break
43 case 'edit' :
44         $title = __('Edit Media');
45
46         if ( empty($errors) )
47                 $errors = null;
48
49         if ( empty( $_GET['attachment_id'] ) ) {
50                 wp_redirect('upload.php');
51                 exit();
52         }
53         $att_id = (int) $_GET['attachment_id'];
54
55         if ( !current_user_can('edit_post', $att_id) )
56                 wp_die ( __('You are not allowed to edit this attachment.') );
57
58         $att = get_post($att_id);
59
60         add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
61
62         wp_enqueue_script( 'wp-ajax-response' );
63         wp_admin_css( 'media' );
64
65
66         require( 'admin-header.php' );
67
68         $message = '';
69         $class = '';
70         if ( isset($_GET['message']) ) {
71                 switch ( $_GET['message'] ) :
72                 case 'updated' :
73                         $message = __('Media attachment updated.');
74                         $class = 'updated fade';
75                         break;
76                 endswitch;
77         }
78         if ( $message )
79                 echo "<div id='message' class='$class'><p>$message</p></div>\n";
80
81 ?>
82
83 <div class="wrap">
84
85 <h2><?php _e( 'Edit Media' ); ?></h2>
86
87 <form method="post" action="<?php echo clean_url( remove_query_arg( 'message' ) ); ?>" class="media-upload-form" id="media-single-form">
88 <div id="media-items" class="media-single">
89 <div id='media-item-<?php echo $att_id; ?>' class='media-item'>
90 <?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'errors' => $errors ) ); ?>
91 </div>
92 </div>
93
94 <p class="submit">
95 <input type="submit" class="button" name="save" value="<?php _e('Save Changes'); ?>" />
96 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
97 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo $att_id; ?>" />
98 <input type="hidden" name="action" value="editattachment" />
99 <?php wp_original_referer_field(true, 'previous'); ?>
100 <?php wp_nonce_field('media-form'); ?>
101 </p>
102 </form>
103
104 </div>
105
106 <?php
107
108         require( 'admin-footer.php' );
109
110         exit;
111
112 default:
113         wp_redirect( 'upload.php' );
114         exit;
115
116 endswitch;
117
118
119 ?>