Changes from tags/5.1.1/src/wp-admin/includes/export.php at r45013 to tags/5.0.3/src/wp-admin/includes/export.php at r45013
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/5.0.3/src/wp-admin/includes/export.php
r45013 r45013 57 57 global $wpdb, $post; 58 58 59 $defaults = array( 60 'content' => 'all', 61 'author' => false, 62 'category' => false, 63 'start_date' => false, 64 'end_date' => false, 65 'status' => false, 59 $defaults = array( 'content' => 'all', 'author' => false, 'category' => false, 60 'start_date' => false, 'end_date' => false, 'status' => false, 66 61 ); 67 $args 62 $args = wp_parse_args( $args, $defaults ); 68 63 69 64 /** … … 80 75 $sitename .= '.'; 81 76 } 82 $date 83 $wp_filename = $sitename . ' WordPress.' . $date . '.xml';77 $date = date( 'Y-m-d' ); 78 $wp_filename = $sitename . 'wordpress.' . $date . '.xml'; 84 79 /** 85 80 * Filters the export filename. … … 99 94 if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { 100 95 $ptype = get_post_type_object( $args['content'] ); 101 if ( ! $ptype->can_export ) {96 if ( ! $ptype->can_export ) 102 97 $args['content'] = 'post'; 103 }104 98 105 99 $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); 106 100 } else { 107 101 $post_types = get_post_types( array( 'can_export' => true ) ); 108 $esses = array_fill( 0, count( $post_types), '%s' );109 $where 110 } 111 112 if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) {102 $esses = array_fill( 0, count($post_types), '%s' ); 103 $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); 104 } 105 106 if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) 113 107 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); 114 } else {108 else 115 109 $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; 116 }117 110 118 111 $join = ''; 119 112 if ( $args['category'] && 'post' == $args['content'] ) { 120 113 if ( $term = term_exists( $args['category'], 'category' ) ) { 121 $join 114 $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; 122 115 $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); 123 116 } … … 125 118 126 119 if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) { 127 if ( $args['author'] ) {120 if ( $args['author'] ) 128 121 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); 129 } 130 131 if ( $args['start_date'] ) { 132 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime( $args['start_date'] ) ) ); 133 } 134 135 if ( $args['end_date'] ) { 136 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) ); 137 } 122 123 if ( $args['start_date'] ) 124 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) ); 125 126 if ( $args['end_date'] ) 127 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); 138 128 } 139 129 … … 147 137 $cats = $tags = $terms = array(); 148 138 if ( isset( $term ) && $term ) { 149 $cat 139 $cat = get_term( $term['term_id'], 'category' ); 150 140 $cats = array( $cat->term_id => $cat ); 151 141 unset( $term, $cat ); 152 142 } elseif ( 'all' == $args['content'] ) { 153 143 $categories = (array) get_categories( array( 'get' => 'all' ) ); 154 $tags 144 $tags = (array) get_tags( array( 'get' => 'all' ) ); 155 145 156 146 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 157 $custom_terms 147 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 158 148 159 149 // Put categories in order with no child going before its parent. 160 150 while ( $cat = array_shift( $categories ) ) { 161 if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {162 $cats[ $cat->term_id] = $cat;163 } else {151 if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 152 $cats[$cat->term_id] = $cat; 153 else 164 154 $categories[] = $cat; 165 }166 155 } 167 156 168 157 // Put terms in order with no child going before its parent. 169 158 while ( $t = array_shift( $custom_terms ) ) { 170 if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {171 $terms[ $t->term_id] = $t;172 } else {159 if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) 160 $terms[$t->term_id] = $t; 161 else 173 162 $custom_terms[] = $t; 174 }175 163 } 176 164 … … 204 192 */ 205 193 function wxr_site_url() { 206 if ( is_multisite() ) {207 // Multisite: the base URL.194 // Multisite: the base URL. 195 if ( is_multisite() ) 208 196 return network_home_url(); 209 } else {210 // WordPress (single site): the blog URL.197 // WordPress (single site): the blog URL. 198 else 211 199 return get_bloginfo_rss( 'url' ); 212 }213 200 } 214 201 … … 221 208 */ 222 209 function wxr_cat_name( $category ) { 223 if ( empty( $category->name ) ) { 224 return; 225 } 210 if ( empty( $category->name ) ) 211 return; 226 212 227 213 echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n"; … … 236 222 */ 237 223 function wxr_category_description( $category ) { 238 if ( empty( $category->description ) ) { 239 return; 240 } 224 if ( empty( $category->description ) ) 225 return; 241 226 242 227 echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n"; … … 251 236 */ 252 237 function wxr_tag_name( $tag ) { 253 if ( empty( $tag->name ) ) { 254 return; 255 } 238 if ( empty( $tag->name ) ) 239 return; 256 240 257 241 echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n"; … … 266 250 */ 267 251 function wxr_tag_description( $tag ) { 268 if ( empty( $tag->description ) ) { 269 return; 270 } 252 if ( empty( $tag->description ) ) 253 return; 271 254 272 255 echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n"; … … 281 264 */ 282 265 function wxr_term_name( $term ) { 283 if ( empty( $term->name ) ) { 284 return; 285 } 266 if ( empty( $term->name ) ) 267 return; 286 268 287 269 echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n"; … … 296 278 */ 297 279 function wxr_term_description( $term ) { 298 if ( empty( $term->description ) ) { 299 return; 300 } 280 if ( empty( $term->description ) ) 281 return; 301 282 302 283 echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n"; … … 341 322 * @global wpdb $wpdb WordPress database abstraction object. 342 323 * 343 * @param int[] $post_ids Optional. Array of post IDs to filter the query by.324 * @param array $post_ids Array of post IDs to filter the query by. Optional. 344 325 */ 345 326 function wxr_authors_list( array $post_ids = null ) { 346 327 global $wpdb; 347 328 348 if ( ! 329 if ( !empty( $post_ids ) ) { 349 330 $post_ids = array_map( 'absint', $post_ids ); 350 $and 331 $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')'; 351 332 } else { 352 333 $and = ''; … … 355 336 $authors = array(); 356 337 $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" ); 357 foreach ( (array) $results as $result ) {338 foreach ( (array) $results as $result ) 358 339 $authors[] = get_userdata( $result->post_author ); 359 }360 340 361 341 $authors = array_filter( $authors ); … … 380 360 function wxr_nav_menu_terms() { 381 361 $nav_menus = wp_get_nav_menus(); 382 if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) { 383 return; 384 } 362 if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) 363 return; 385 364 386 365 foreach ( $nav_menus as $menu ) { … … 403 382 404 383 $taxonomies = get_object_taxonomies( $post->post_type ); 405 if ( empty( $taxonomies ) ) { 406 return; 407 } 384 if ( empty( $taxonomies ) ) 385 return; 408 386 $terms = wp_get_object_terms( $post->ID, $taxonomies ); 409 387 … … 414 392 415 393 /** 394 * 416 395 * @param bool $return_me 417 396 * @param string $meta_key … … 419 398 */ 420 399 function wxr_filter_postmeta( $return_me, $meta_key ) { 421 if ( '_edit_lock' == $meta_key ) {400 if ( '_edit_lock' == $meta_key ) 422 401 $return_me = true; 423 }424 402 return $return_me; 425 403 } 426 404 add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 ); 427 405 428 echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset') . "\" ?>\n";406 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n"; 429 407 430 408 ?> … … 446 424 <!-- contained in this file into your site. --> 447 425 448 426 <?php the_generator( 'export' ); ?> 449 427 <rss version="2.0" 450 428 xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/" … … 465 443 <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url> 466 444 467 468 469 445 <?php wxr_authors_list( $post_ids ); ?> 446 447 <?php foreach ( $cats as $c ) : ?> 470 448 <wp:category> 471 449 <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id> 472 450 <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename> 473 <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent> 474 <?php 475 wxr_cat_name( $c ); 451 <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent> 452 <?php wxr_cat_name( $c ); 476 453 wxr_category_description( $c ); 477 wxr_term_meta( $c ); 478 ?> 454 wxr_term_meta( $c ); ?> 479 455 </wp:category> 480 481 456 <?php endforeach; ?> 457 <?php foreach ( $tags as $t ) : ?> 482 458 <wp:tag> 483 459 <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id> 484 460 <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug> 485 <?php 486 wxr_tag_name( $t ); 461 <?php wxr_tag_name( $t ); 487 462 wxr_tag_description( $t ); 488 wxr_term_meta( $t ); 489 ?> 463 wxr_term_meta( $t ); ?> 490 464 </wp:tag> 491 492 465 <?php endforeach; ?> 466 <?php foreach ( $terms as $t ) : ?> 493 467 <wp:term> 494 468 <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id> 495 469 <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy> 496 470 <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug> 497 <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ); ?></wp:term_parent> 498 <?php 499 wxr_term_name( $t ); 471 <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent> 472 <?php wxr_term_name( $t ); 500 473 wxr_term_description( $t ); 501 wxr_term_meta( $t ); 502 ?> 474 wxr_term_meta( $t ); ?> 503 475 </wp:term> 504 <?php endforeach; ?> 505 <?php 506 if ( 'all' == $args['content'] ) { 507 wxr_nav_menu_terms();} 508 ?> 476 <?php endforeach; ?> 477 <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?> 509 478 510 479 <?php … … 513 482 ?> 514 483 515 <?php 516 if ( $post_ids ) { 517 /** 518 * @global WP_Query $wp_query 519 */ 520 global $wp_query; 521 522 // Fake being in the loop. 523 $wp_query->in_the_loop = true; 524 525 // Fetch 20 posts at a time rather than loading the entire table into memory. 526 while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { 527 $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')'; 528 $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); 529 530 // Begin Loop. 531 foreach ( $posts as $post ) { 532 setup_postdata( $post ); 533 $is_sticky = is_sticky( $post->ID ) ? 1 : 0; 534 ?> 484 <?php if ( $post_ids ) { 485 /** 486 * @global WP_Query $wp_query 487 */ 488 global $wp_query; 489 490 // Fake being in the loop. 491 $wp_query->in_the_loop = true; 492 493 // Fetch 20 posts at a time rather than loading the entire table into memory. 494 while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { 495 $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')'; 496 $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); 497 498 // Begin Loop. 499 foreach ( $posts as $post ) { 500 setup_postdata( $post ); 501 $is_sticky = is_sticky( $post->ID ) ? 1 : 0; 502 ?> 535 503 <item> 536 <title> 537 <?php 538 /** This filter is documented in wp-includes/feed.php */ 539 echo apply_filters( 'the_title_rss', $post->post_title ); 540 ?> 541 </title> 542 <link><?php the_permalink_rss(); ?></link> 504 <title><?php 505 /** This filter is documented in wp-includes/feed.php */ 506 echo apply_filters( 'the_title_rss', $post->post_title ); 507 ?></title> 508 <link><?php the_permalink_rss() ?></link> 543 509 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate> 544 510 <dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator> 545 511 <guid isPermaLink="false"><?php the_guid(); ?></guid> 546 512 <description></description> 547 <content:encoded> 548 <?php 549 /** 550 * Filters the post content used for WXR exports. 551 * 552 * @since 2.5.0 553 * 554 * @param string $post_content Content of the current post. 555 */ 556 echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); 557 ?> 558 </content:encoded> 559 <excerpt:encoded> 560 <?php 561 /** 562 * Filters the post excerpt used for WXR exports. 563 * 564 * @since 2.6.0 565 * 566 * @param string $post_excerpt Excerpt for the current post. 567 */ 568 echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); 569 ?> 570 </excerpt:encoded> 513 <content:encoded><?php 514 /** 515 * Filters the post content used for WXR exports. 516 * 517 * @since 2.5.0 518 * 519 * @param string $post_content Content of the current post. 520 */ 521 echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); 522 ?></content:encoded> 523 <excerpt:encoded><?php 524 /** 525 * Filters the post excerpt used for WXR exports. 526 * 527 * @since 2.6.0 528 * 529 * @param string $post_excerpt Excerpt for the current post. 530 */ 531 echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); 532 ?></excerpt:encoded> 571 533 <wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id> 572 534 <wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date> … … 581 543 <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password> 582 544 <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky> 583 545 <?php if ( $post->post_type == 'attachment' ) : ?> 584 546 <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url> 585 <?php endif; ?> 586 <?php wxr_post_taxonomy(); ?> 587 <?php 588 $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); 589 foreach ( $postmeta as $meta ) : 590 /** 591 * Filters whether to selectively skip post meta used for WXR exports. 592 * 593 * Returning a truthy value to the filter will skip the current meta 594 * object from being exported. 595 * 596 * @since 3.3.0 597 * 598 * @param bool $skip Whether to skip the current post meta. Default false. 599 * @param string $meta_key Current meta key. 600 * @param object $meta Current meta object. 601 */ 602 if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) { 603 continue; 604 } 605 ?> 547 <?php endif; ?> 548 <?php wxr_post_taxonomy(); ?> 549 <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); 550 foreach ( $postmeta as $meta ) : 551 /** 552 * Filters whether to selectively skip post meta used for WXR exports. 553 * 554 * Returning a truthy value to the filter will skip the current meta 555 * object from being exported. 556 * 557 * @since 3.3.0 558 * 559 * @param bool $skip Whether to skip the current post meta. Default false. 560 * @param string $meta_key Current meta key. 561 * @param object $meta Current meta object. 562 */ 563 if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) 564 continue; 565 ?> 606 566 <wp:postmeta> 607 <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>608 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>567 <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> 568 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> 609 569 </wp:postmeta> 610 <?php 611 endforeach; 612 613 $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); 614 $comments = array_map( 'get_comment', $_comments ); 615 foreach ( $comments as $c ) : 616 ?> 570 <?php endforeach; 571 572 $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); 573 $comments = array_map( 'get_comment', $_comments ); 574 foreach ( $comments as $c ) : ?> 617 575 <wp:comment> 618 576 <wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id> … … 623 581 <wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date> 624 582 <wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt> 625 <wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ;?></wp:comment_content>583 <wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content> 626 584 <wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved> 627 585 <wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type> 628 586 <wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent> 629 587 <wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id> 630 <?php 631 $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); 632 foreach ( $c_meta as $meta ) : 633 /** 634 * Filters whether to selectively skip comment meta used for WXR exports. 635 * 636 * Returning a truthy value to the filter will skip the current meta 637 * object from being exported. 638 * 639 * @since 4.0.0 640 * 641 * @param bool $skip Whether to skip the current comment meta. Default false. 642 * @param string $meta_key Current meta key. 643 * @param object $meta Current meta object. 644 */ 645 if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) { 646 continue; 647 } 648 ?> 649 <wp:commentmeta> 650 <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> 651 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> 588 <?php $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); 589 foreach ( $c_meta as $meta ) : 590 /** 591 * Filters whether to selectively skip comment meta used for WXR exports. 592 * 593 * Returning a truthy value to the filter will skip the current meta 594 * object from being exported. 595 * 596 * @since 4.0.0 597 * 598 * @param bool $skip Whether to skip the current comment meta. Default false. 599 * @param string $meta_key Current meta key. 600 * @param object $meta Current meta object. 601 */ 602 if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) { 603 continue; 604 } 605 ?> 606 <wp:commentmeta> 607 <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> 608 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> 652 609 </wp:commentmeta> 653 <?phpendforeach; ?>610 <?php endforeach; ?> 654 611 </wp:comment> 655 <?php endforeach; ?> 656 </item> 657 <?php 658 } 659 } 660 } 661 ?> 612 <?php endforeach; ?> 613 </item> 614 <?php 615 } 616 } 617 } ?> 662 618 </channel> 663 619 </rss> 664 620 <?php 665 621 }
Note: See TracChangeset
for help on using the changeset viewer.