Pageinate upload tabs. From the Paginator, mdawaffe. fixes #3193

git-svn-id: https://develop.svn.wordpress.org/trunk@4276 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2006-10-03 15:40:26 +00:00
parent c1d042931b
commit 8f25e35913
6 changed files with 59 additions and 20 deletions

View File

@@ -24,14 +24,16 @@ elseif ( get_post( $post_id ) )
$wp_upload_tabs = array();
$all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
$post_atts = 0;
if ( $pid ) {
$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload');
// 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
$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse");
$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
if ( $post_atts < $all_atts )
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
} else
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
$wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
@@ -54,14 +56,37 @@ include_once('admin-header.php');
echo "<ul id='upload-menu'>\n";
foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check
$class = 'upload-tab';
$href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '') );
if ( isset($tab_array[3]) && is_array($tab_array[3]) )
add_query_arg( $tab_array[3], $href );
$href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '', 'paged' => '') );
if ( isset($tab_array[4]) && is_array($tab_array[4]) )
add_query_arg( $tab_array[4], $href );
$_href = wp_specialchars( $href, 1 );
if ( $tab == $t )
$page_links = '';
if ( $tab == $t ) {
$class .= ' current';
echo "\t<li class='$class left'><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a></li>\n";
if ( $tab_array[3] ) {
if ( is_array($tab_array[3]) ) {
$total = $tab_array[3][0];
$per = $tab_array[3][1];
} else {
$total = $tab_array[3];
$per = 10;
}
$page_links = paginate_links( array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'total' => ceil($total / $per),
'current' => $paged ? $paged : 1,
'prev_text' => '&laquo;',
'next_text' => '&raquo;'
));
if ( $page_links )
$page_links = "<span id='current-tab-nav'>: $page_links</span>";
}
}
echo "\t<li class='$class left'><div><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a>$page_links</div></li>\n";
}
unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class);
echo "</ul>\n\n";
echo "<div id='upload-content'>\n";