2 require_once('admin.php');
4 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
6 if (!current_user_can('upload_files'))
7 wp_die(__('You do not have permission to upload files.'));
9 wp_reset_vars(array('action', 'tab', 'from_tab', 'style', 'post_id', 'ID', 'paged', 'post_title', 'post_content', 'delete'));
11 // IDs should be integers
13 $post_id = (int) $post_id;
15 // Require an ID for the edit screen
16 if ( $action == 'edit' && !$ID )
17 wp_die(__("You are not allowed to be here"));
19 require_once('includes/upload.php');
23 do_action( "upload_files_$tab" );
28 elseif ( get_post( $post_id ) )
30 $wp_upload_tabs = array();
31 $all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
35 // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args
36 $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
37 if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
38 $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
39 if ( $post_atts < $all_atts )
40 $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
42 $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
44 $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
46 if ( !is_callable($wp_upload_tabs[$tab][2]) ) {
47 $to_tab = isset($wp_upload_tabs['upload']) ? 'upload' : 'browse-all';
48 wp_redirect( add_query_arg( 'tab', $to_tab ) );
52 foreach ( $wp_upload_tabs as $t => $tab_array ) {
53 if ( !current_user_can( $tab_array[1] ) ) {
54 unset($wp_upload_tabs[$t]);
56 wp_die(__("You are not allowed to be here"));
60 if ( 'inline' == $style ) : ?>
61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
62 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
64 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
65 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — WordPress</title>
66 <?php wp_admin_css(); ?>
67 <script type="text/javascript">
69 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
72 <?php do_action('admin_print_scripts'); wp_upload_admin_head(); ?>
77 add_action( 'admin_head', 'wp_upload_admin_head' );
78 include_once('admin-header.php');
81 <h2><?php _e('Uploads'); ?></h2>
85 echo "<ul id='upload-menu'>\n";
86 foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check
87 $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '', 'paged' => '') );
88 if ( isset($tab_array[4]) && is_array($tab_array[4]) )
89 $href = add_query_arg( $tab_array[4], $href );
90 $_href = clean_url( $href);
92 $class = 'upload-tab alignleft';
95 if ( $tab_array[3] ) {
96 if ( is_array($tab_array[3]) ) {
97 $total = $tab_array[3][0];
98 $per = $tab_array[3][1];
100 $total = $tab_array[3];
103 $page_links = paginate_links( array(
104 'base' => add_query_arg( 'paged', '%#%' ),
106 'total' => ceil($total / $per),
107 'current' => $paged ? $paged : 1,
108 'prev_text' => '«',
109 'next_text' => '»'
112 $page_links = "<span id='current-tab-nav'>: $page_links</span>";
116 echo "\t<li class='$class'><a href='$_href' class='upload-tab-link' title='{$tab_array[0]}'>{$tab_array[0]}</a>$page_links</li>\n";
118 unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class);
121 echo "<div id='upload-content' class='$tab'>\n";
123 call_user_func( $wp_upload_tabs[$tab][2] );
127 if ( 'inline' != $style ) :
128 echo "<div class='clear'></div></div>";
129 include_once('admin-footer.php');
131 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>