Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r19448 r20715  
    172172        if ( is_wp_error($post_data) )
    173173                wp_die( $post_data->get_error_message() );
    174         if ( 'autosave' != $post_data['action']  && 'auto-draft' == $post_data['post_status'] )
     174        if ( 'autosave' != $post_data['action'] && 'auto-draft' == $post_data['post_status'] )
    175175                $post_data['post_status'] = 'draft';
    176176
    … …  
    303303                                continue;
    304304                        if ( is_taxonomy_hierarchical( $tax_name ) ) {
    305                                 $tax_input[$tax_name] = array_map( 'absint', $terms );
     305                                $tax_input[ $tax_name ] = array_map( 'absint', $terms );
    306306                        } else {
    307                                 $tax_input[$tax_name] = preg_replace( '/\s*,\s*/', ',', rtrim( trim($terms), ' ,' ) );
    308                                 $tax_input[$tax_name] = explode(',', $tax_input[$tax_name]);
     307                                $comma = _x( ',', 'tag delimiter' );
     308                                if ( ',' !== $comma )
     309                                        $terms = str_replace( $comma, ',', $terms );
     310                                $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
    309311                        }
    310312                }
    … …  
    353355                foreach ( $tax_names as $tax_name ) {
    354356                        $taxonomy_obj = get_taxonomy($tax_name);
    355                         if (  isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->cap->assign_terms ) )
     357                        if ( isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->cap->assign_terms ) )
    356358                                $new_terms = $tax_input[$tax_name];
    357359                        else
    … …  
    416418
    417419        if ( $create_in_db ) {
    418                 // Cleanup old auto-drafts more than 7 days old
    419                 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
    420                 foreach ( (array) $old_posts as $delete )
    421                         wp_delete_post( $delete, true ); // Force delete
    422420                $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    423421                $post = get_post( $post_id );
    … …  
    748746 */
    749747function _fix_attachment_links( $post_ID ) {
    750         global $_fix_attachment_link_id;
    751 
    752748        $post = & get_post( $post_ID, ARRAY_A );
    753 
    754         $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
    755 
    756         // See if we have any rel="attachment" links
    757         if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
     749        $content = $post['post_content'];
     750
     751        // quick sanity check, don't run if no pretty permalinks or post is not published
     752        if ( !get_option('permalink_structure') || $post['post_status'] != 'publish' )
    758753                return;
    759754
    760         $i = 0;
    761         $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i";
    762         foreach ( $anchor_matches[0] as $anchor ) {
    763                 if ( 0 == preg_match( $search, $anchor, $id_matches ) )
     755        // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero)
     756        if ( !strpos($content, '?attachment_id=') || !preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) )
     757                return;
     758
     759        $site_url = get_bloginfo('url');
     760        $site_url = substr( $site_url, (int) strpos($site_url, '://') ); // remove the http(s)
     761        $replace = '';
     762
     763        foreach ( $link_matches[1] as $key => $value ) {
     764                if ( !strpos($value, '?attachment_id=') || !strpos($value, 'wp-att-')
     765                        || !preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
     766                        || !preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) )
     767                                continue;
     768
     769                $quote = $url_match[1]; // the quote (single or double)
     770                $url_id = (int) $url_match[2];
     771                $rel_id = (int) $rel_match[1];
     772
     773                if ( !$url_id || !$rel_id || $url_id != $rel_id || strpos($url_match[0], $site_url) === false )
    764774                        continue;
    765775
    766                 $id = (int) $id_matches[3];
    767 
    768                 // While we have the attachment ID, let's adopt any orphans.
    769                 $attachment = & get_post( $id, ARRAY_A );
    770                 if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) {
    771                         $attachment['post_parent'] = $post_ID;
    772                         // Escape data pulled from DB.
    773                         $attachment = add_magic_quotes( $attachment );
    774                         wp_update_post( $attachment );
    775                 }
    776 
    777                 $post_search[$i] = $anchor;
    778                  $_fix_attachment_link_id = $id;
    779                 $post_replace[$i] = preg_replace_callback( "#href=(\"|')[^'\"]*\\1#", '_fix_attachment_links_replace_cb', $anchor );
    780                 ++$i;
    781         }
    782 
    783         $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
    784 
    785         // Escape data pulled from DB.
    786         $post = add_magic_quotes( $post);
    787 
    788         return wp_update_post( $post);
    789 }
    790 
    791 function _fix_attachment_links_replace_cb($match) {
    792         global $_fix_attachment_link_id;
    793         return stripslashes( 'href='.$match[1] ).get_attachment_link( $_fix_attachment_link_id ).stripslashes( $match[1] );
     776                $link = $link_matches[0][$key];
     777                $replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
     778
     779                $content = str_replace( $link, $replace, $content );
     780        }
     781
     782        if ( $replace ) {
     783                $post['post_content'] = $content;
     784                // Escape data pulled from DB.
     785                $post = add_magic_quotes($post);
     786
     787                return wp_update_post($post);
     788        }
    794789}
    795790
    … …  
    974969
    975970function _edit_attachments_query_helper($where) {
    976         return $where .= ' AND post_parent < 1';
     971        global $wpdb;
     972        return $where .= " AND {$wpdb->posts}.post_parent < 1";
    977973}
    978974
    … …  
    11411137 *
    11421138 * @param int $thumbnail_id ID of the attachment used for thumbnail
     1139 * @param int $post_id ID of the post associated with the thumbnail, defaults to global $post_ID
    11431140 * @return string html
    11441141 */
    1145 function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
     1142function _wp_post_thumbnail_html( $thumbnail_id = null, $post_id = null ) {
    11461143        global $content_width, $_wp_additional_image_sizes, $post_ID;
    1147         $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="' . esc_url( get_upload_iframe_src('image') ) . '" id="set-post-thumbnail" class="thickbox">%s</a></p>';
    1148         $content = sprintf($set_thumbnail_link, esc_html__( 'Set featured image' ));
     1144
     1145        if ( empty( $post_id ) )
     1146                $post_id = $post_ID;
     1147
     1148        $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post_id) );
     1149        $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
     1150        $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) );
    11491151
    11501152        if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
    … …  
    11561158                        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
    11571159                if ( !empty( $thumbnail_html ) ) {
    1158                         $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$post_ID" );
    1159                         $content = sprintf($set_thumbnail_link, $thumbnail_html);
     1160                        $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$post_id" );
     1161                        $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html );
    11601162                        $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>';
    11611163                }
    … …  
    12601262                return $translated;
    12611263
    1262         // Only store one autosave.  If there is already an autosave, overwrite it.
     1264        // Only store one autosave. If there is already an autosave, overwrite it.
    12631265        if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
    12641266                $new_autosave = _wp_post_revision_fields( $_POST, true );
    … …  
    13211323        if ( 'draft' == $post->post_status ) {
    13221324                $id = edit_post();
    1323         } else { // Non drafts are not overwritten.  The autosave is stored in a special post revision.
     1325        } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
    13241326                $id = wp_create_post_autosave( $post->ID );
    13251327                if ( ! is_wp_error($id) )
Note: See TracChangeset for help on using the changeset viewer.