function wp_upload_tab_browse() {
	global $wpdb, $action, $paged;
	$old_vars = compact( 'paged' );

	switch ( $action ) :
	case 'edit' :
	case 'view' :
		global $ID;
		$attachments = query_posts("attachment_id=$ID");
		if ( have_posts() ) : while ( have_posts() ) : the_post();
			'edit' == $action ? wp_upload_form() : wp_upload_view();
		endwhile; endif;
		break;
	default :
		global $tab, $post_id, $style;
		add_action( 'pre_get_posts', 'wp_upload_grab_attachments' );
		if ( 'browse' == $tab && $post_id )
			add_filter( 'posts_where', 'wp_upload_posts_where' );
		$attachments = query_posts("what_to_show=posts&posts_per_page=10&paged=$paged");
		$count_query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'";
		if ( $post_id )
			$count_query .= " AND post_parent = '$post_id'";
        	$total =  $wpdb->get_var($count_query);

		echo "<ul id='upload-files'>\n";
		if ( have_posts() ) : while ( have_posts() ) : the_post();
			$href = wp_specialchars( add_query_arg( array(
				'action' => 'inline' == $style ? 'view' : 'edit',
				'ID' => get_the_ID())
			 ), 1 );

			echo "\t<li id='file-";
			the_ID();
			echo "' class='alignleft'>\n";
			echo wp_upload_display( array(128,128), $href );
			echo "\t</li>\n";
		endwhile;
		else :
			echo "\t<li>" . __('There are no attachments to show.') . "</li>\n";
		endif;
		echo "</ul>\n\n";

		echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce( 'inlineuploading' )  . "' /></form>\n";
		break;
	endswitch;

	extract($old_vars);
}
Пример #2
0
function wp_upload_tab_browse()
{
    global $action, $paged;
    $old_vars = compact('paged');
    switch ($action) {
        case 'edit':
        case 'view':
            global $ID;
            $attachments = query_posts("attachment_id={$ID}");
            if (have_posts()) {
                while (have_posts()) {
                    the_post();
                    'edit' == $action ? wp_upload_form() : wp_upload_view();
                }
            }
            break;
        default:
            global $tab, $post_id, $style;
            add_action('pre_get_posts', 'wp_upload_grab_attachments');
            if ('browse' == $tab && $post_id) {
                add_filter('posts_where', 'wp_upload_posts_where');
            }
            $attachments = query_posts("what_to_show=posts&post_status=any&posts_per_page=10&paged={$paged}");
            echo "<ul id='upload-files'>\n";
            if (have_posts()) {
                while (have_posts()) {
                    the_post();
                    $href = wp_specialchars(add_query_arg(array('action' => 'inline' == $style ? 'view' : 'edit', 'ID' => get_the_ID())), 1);
                    echo "\t<li id='file-";
                    the_ID();
                    echo "' class='alignleft'>\n";
                    echo wp_upload_display(array(128, 128), $href);
                    echo "\t</li>\n";
                }
            } else {
                echo "\t<li>" . __('There are no attachments to show.') . "</li>\n";
            }
            echo "</ul>\n\n";
            echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce('inlineuploading') . "' /></form>\n";
            break;
    }
    extract($old_vars);
}