Make WordPress Core


Ignore:
Timestamp:
08/25/2008 08:21:27 PM (17 years ago)
Author:
ryan
Message:

Move post row generation to functions in prep for some AJAX work. see #7552

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r8726 r8729  
    405405
    406406    return $posts_columns;
     407}
     408
     409function post_rows() {
     410    global $wp_query, $post, $mode;
     411
     412    add_filter('the_title','wp_specialchars');
     413
     414    // Create array of post IDs.
     415    $post_ids = array();
     416    foreach ( $wp_query->posts as $a_post )
     417        $post_ids[] = $a_post->ID;
     418
     419    $comment_pending_count = get_pending_comments_num($post_ids);
     420    if ( empty($comment_pending_count[$post->ID]) )
     421        $comment_pending_count = array();
     422
     423    while ( have_posts() ) {
     424        the_post();
     425
     426        if ( empty($comment_pending_count[$post->ID]) )
     427            $comment_pending_count[$post->ID] = 0;
     428
     429        _post_row($post, $comment_pending_count[$post->ID], $mode);
     430    }
     431}
     432
     433function _post_row($a_post, $pending_comments, $mode) {
     434    global $post;
     435    static $class;
     436
     437    $global_post = $post;
     438    $post = $a_post;
     439
     440    $class = 'alternate' == $class ? '' : 'alternate';
     441    global $current_user;
     442    $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
     443    $edit_link = get_edit_post_link( $post->ID );
     444    $title = get_the_title();
     445    if ( empty($title) )
     446        $title = __('(no title)');
     447?>
     448    <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $class . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
     449<?php
     450    $posts_columns = wp_manage_posts_columns();
     451    foreach($posts_columns as $column_name=>$column_display_name) {
     452
     453        switch($column_name) {
     454
     455        case 'cb':
     456        ?>
     457        <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
     458        <?php
     459        break;
     460
     461        case 'modified':
     462        case 'date':
     463            if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
     464                $t_time = $h_time = __('Unpublished');
     465            } else {
     466                if ( 'modified' == $column_name ) {
     467                    $t_time = get_the_modified_time(__('Y/m/d g:i:s A'));
     468                    $m_time = $post->post_modified;
     469                    $time = get_post_modified_time('G', true);
     470                } else {
     471                    $t_time = get_the_time(__('Y/m/d g:i:s A'));
     472                    $m_time = $post->post_date;
     473                    $time = get_post_time('G', true);
     474                }
     475                if ( ( abs(time() - $time) ) < 86400 ) {
     476                    if ( ( 'future' == $post->post_status) )
     477                        $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
     478                    else
     479                        $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
     480                } else {
     481                    $h_time = mysql2date(__('Y/m/d'), $m_time);
     482                }
     483            }
     484
     485            if ( 'excerpt' == $mode ) { ?>
     486        <td><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
     487        <?php } else { ?>
     488        <td><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
     489        <?php }
     490        break;
     491
     492        case 'title':
     493        ?>
     494        <td class="post-title"><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; } ?></strong>
     495        <?php
     496            if ( !empty($post->post_password) ) { _e(' &#8212; <strong>Protected</strong>'); } elseif ('private' == $post->post_status) { _e(' &#8212; <strong>Private</strong>'); }
     497
     498            if ( 'excerpt' == $mode )
     499                the_excerpt();
     500
     501            $actions = array();
     502            $actions['edit'] = '<a href="post.php?action=edit&amp;post=' . $post->ID . '">' . __('Edit') . '</a>';
     503            $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
     504            $action_count = count($actions);
     505            $i = 0;
     506            foreach ( $actions as $action => $link ) {
     507                ++$i;
     508                ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
     509                echo "<span class='$action'>$link$sep</span>";
     510            }
     511        ?>
     512        </td>
     513        <?php
     514        break;
     515
     516        case 'categories':
     517        ?>
     518        <td><?php
     519            $categories = get_the_category();
     520            if ( !empty( $categories ) ) {
     521                $out = array();
     522                foreach ( $categories as $c )
     523                    $out[] = "<a href='edit.php?category_name=$c->slug'> " . wp_specialchars(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
     524                    echo join( ', ', $out );
     525            } else {
     526                _e('Uncategorized');
     527            }
     528        ?></td>
     529        <?php
     530        break;
     531
     532        case 'tags':
     533        ?>
     534        <td><?php
     535            $tags = get_the_tags();
     536            if ( !empty( $tags ) ) {
     537                $out = array();
     538                foreach ( $tags as $c )
     539                    $out[] = "<a href='edit.php?tag=$c->slug'> " . wp_specialchars(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>";
     540                echo join( ', ', $out );
     541            } else {
     542                _e('No Tags');
     543            }
     544        ?></td>
     545        <?php
     546        break;
     547
     548        case 'comments':
     549        ?>
     550        <td class="num"><div class="post-com-count-wrapper">
     551        <?php
     552            $pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
     553            if ( $pending_comments )
     554                echo '<strong>';
     555                comments_number("<a href='edit.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('0') . '</span></a>', "<a href='edit.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('1') . '</span></a>', "<a href='edit.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('%') . '</span></a>');
     556                if ( $pending_comments )
     557                echo '</strong>';
     558        ?>
     559        </div></td>
     560        <?php
     561        break;
     562
     563        case 'author':
     564        ?>
     565        <td><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
     566        <?php
     567        break;
     568
     569        case 'status':
     570        ?>
     571        <td>
     572        <a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
     573        <?php
     574            switch ( $post->post_status ) {
     575                case 'publish' :
     576                case 'private' :
     577                    _e('Published');
     578                    break;
     579                case 'future' :
     580                    _e('Scheduled');
     581                    break;
     582                case 'pending' :
     583                    _e('Pending Review');
     584                    break;
     585                case 'draft' :
     586                    _e('Unpublished');
     587                    break;
     588            }
     589        ?>
     590        </a>
     591        </td>
     592        <?php
     593        break;
     594
     595        case 'control_view':
     596        ?>
     597        <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e('View'); ?></a></td>
     598        <?php
     599        break;
     600
     601        case 'control_edit':
     602        ?>
     603        <td><?php if ( current_user_can('edit_post', $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
     604        <?php
     605        break;
     606
     607        case 'control_delete':
     608        ?>
     609        <td><?php if ( current_user_can('delete_post', $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
     610        <?php
     611        break;
     612
     613        default:
     614        ?>
     615        <td><?php do_action('manage_posts_custom_column', $column_name, $post->ID); ?></td>
     616        <?php
     617        break;
     618    }
     619}
     620?>
     621    </tr>
     622<?php
     623    $post = $global_post;
    407624}
    408625
Note: See TracChangeset for help on using the changeset viewer.