PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> upload.php (source)

   1  <?php
   2  require_once ('admin.php');
   3  
   4  @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
   5  
   6  if (!current_user_can('upload_files'))
   7      wp_die(__('You do not have permission to upload files.'));
   8  
   9  wp_reset_vars(array('action', 'tab', 'from_tab', 'style', 'post_id', 'ID', 'paged', 'post_title', 'post_content', 'delete'));
  10  
  11  // IDs should be integers
  12  $ID = (int) $ID;
  13  $post_id = (int) $post_id;
  14  
  15  // Require an ID for the edit screen
  16  if ( $action == 'edit' && !$ID )
  17      wp_die(__("You are not allowed to be here"));
  18  
  19  require_once ('includes/upload.php');
  20  if ( !$tab )
  21      $tab = 'browse-all';
  22  
  23  do_action( "upload_files_$tab" );
  24  
  25  $pid = 0;
  26  if ( $post_id < 0 )
  27      $pid = $post_id;
  28  elseif ( get_post( $post_id ) )
  29      $pid = $post_id;
  30  $wp_upload_tabs = array();
  31  $all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
  32  $post_atts = 0;
  33  
  34  if ( $pid ) {
  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);
  41  } else
  42      $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
  43  
  44      $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
  45  
  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 ) );
  49      exit;
  50  }
  51  
  52  foreach ( $wp_upload_tabs as $t => $tab_array ) {
  53      if ( !current_user_can( $tab_array[1] ) ) {
  54          unset($wp_upload_tabs[$t]);
  55          if ( $tab == $t )
  56              wp_die(__("You are not allowed to be here"));
  57      }
  58  }
  59  
  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(); ?>>
  63  <head>
  64  <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
  65  <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; WordPress</title>
  66  <?php wp_admin_css(); ?>
  67  <script type="text/javascript">
  68  //<![CDATA[
  69  function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
  70  //]]>
  71  </script>
  72  <?php do_action('admin_print_scripts'); wp_upload_admin_head(); ?>
  73  </head>
  74  <body>
  75  <?php
  76  else :
  77      add_action( 'admin_head', 'wp_upload_admin_head' );
  78      include_once ('admin-header.php');
  79  ?>
  80      <div class='wrap'>
  81      <h2><?php _e('Uploads'); ?></h2>
  82  <?php
  83  endif;
  84  
  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);
  91      $page_links = '';
  92      $class = 'upload-tab alignleft';
  93      if ( $tab == $t ) {
  94          $class .= ' current';
  95          if ( $tab_array[3] ) {
  96              if ( is_array($tab_array[3]) ) {
  97                  $total = $tab_array[3][0];
  98                  $per = $tab_array[3][1];
  99              } else {
 100                  $total = $tab_array[3];
 101                  $per = 10;
 102              }
 103              $page_links = paginate_links( array(
 104                  'base' => add_query_arg( 'paged', '%#%' ),
 105                  'format' => '',
 106                  'total' => ceil($total / $per),
 107                  'current' => $paged ? $paged : 1,
 108                  'prev_text' => '&laquo;',
 109                  'next_text' => '&raquo;'
 110              ));
 111              if ( $page_links )
 112                  $page_links = "<span id='current-tab-nav'>: $page_links</span>";
 113          }
 114      }
 115  
 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";
 117  }
 118  unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class);
 119  echo "</ul>\n\n";
 120  
 121  echo "<div id='upload-content' class='$tab'>\n";
 122  
 123  call_user_func( $wp_upload_tabs[$tab][2] );
 124  
 125  echo "</div>\n";
 126  
 127  if ( 'inline' != $style ) :
 128      echo "<div class='clear'></div></div>";
 129      include_once ('admin-footer.php');
 130  else : ?>
 131  <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
 132  
 133  </body>
 134  </html>
 135  <?php endif; ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt