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