Make WordPress Core


Ignore:
Timestamp:
11/20/2012 06:50:15 PM (12 years ago)
Author:
nacin
Message:

Fix up the 'Attach' dialog on upload.php.

We are de-emphasising attaching (see [22630]) but this is existing
core functionality and will remain for now. This commit just cleans
it up a bit so as to be less embarrassing.

props lessbloat, helenyhou.
fixes #20164.

File:
1 edited

Legend:

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

    r22653 r22723  
    14221422    check_ajax_referer( 'find-posts' );
    14231423
    1424     if ( empty($_POST['ps']) )
    1425         wp_die();
    1426 
    1427     if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
    1428         $what = $_POST['post_type'];
    1429     else
    1430         $what = 'post';
    1431 
    1432     $s = stripslashes($_POST['ps']);
    1433     preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
    1434     $search_terms = array_map('_search_terms_tidy', $matches[0]);
    1435 
     1424    $post_types = get_post_types( array( 'public' => true ), 'objects' );
     1425    unset( $post_types['attachment'] );
     1426
     1427    $s = stripslashes( $_POST['ps'] );
    14361428    $searchand = $search = '';
    1437     foreach ( (array) $search_terms as $term ) {
    1438         $term = esc_sql( like_escape( $term ) );
    1439         $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
    1440         $searchand = ' AND ';
    1441     }
    1442     $term = esc_sql( like_escape( $s ) );
    1443     if ( count($search_terms) > 1 && $search_terms[0] != $s )
    1444         $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
    1445 
    1446     $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
    1447 
    1448     if ( ! $posts ) {
    1449         $posttype = get_post_type_object($what);
    1450         wp_die( $posttype->labels->not_found );
    1451     }
    1452 
    1453     $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
     1429    $args = array(
     1430        'post_type' => array_keys( $post_types ),
     1431        'post_status' => 'any',
     1432        'posts_per_page' => 50,
     1433    );
     1434    if ( '' !== $s )
     1435        $args['s'] = $s;
     1436
     1437    $posts = get_posts( $args );
     1438
     1439    if ( ! $posts )
     1440        wp_die( __('No items found.') );
     1441
     1442    $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>';
    14541443    foreach ( $posts as $post ) {
     1444        $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
    14551445
    14561446        switch ( $post->post_status ) {
     
    14781468
    14791469        $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
    1480         $html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n";
    1481     }
     1470        $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n";
     1471    }
     1472
    14821473    $html .= '</tbody></table>';
    14831474
    14841475    $x = new WP_Ajax_Response();
    14851476    $x->add( array(
    1486         'what' => $what,
    14871477        'data' => $html
    14881478    ));
    14891479    $x->send();
    1490 
    14911480}
    14921481
Note: See TracChangeset for help on using the changeset viewer.