WordPress.org

Make WordPress Core

Ticket #10317: 10317-2.diff

File 10317-2.diff, 30.3 KB (added by blepoxp, 8 years ago)

First revision of nacin's latest diff - more will be needed.

  • wp-admin/includes/export.php

     
    2121 *
    2222 * @since unknown
    2323 *
    24  * @param unknown_type $author
     24 * @param unknown_type $args
    2525 */
    26 function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
    27 global $wpdb, $post_ids, $post, $wp_taxonomies;
    28 
    29 do_action('export_wp');
    30 
    31 if(strlen($start_date) > 4 && strlen($end_date) > 4) {
    32         $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
    33 } else {
    34         $filename = 'wordpress.' . date('Y-m-d') . '.xml';
    35 }
    36 
    37 header('Content-Description: File Transfer');
    38 header("Content-Disposition: attachment; filename=$filename");
    39 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    40 
    41 if ( $post_type and $post_type != 'all' ) {
     26function export_wp( $args = array() ) {
     27        global $wpdb, $post_ids, $post, $wp_taxonomies;
     28       
     29        if ( ! is_array( $args ) )
     30                $args = array( 'author' => $args );
     31       
     32        $defaults = array( 'author' => null, 'taxonomy' => null, 'post_type' => null, 'post_status' => null, 'start_date' => null, 'end_date' => null );
     33        $args = wp_parse_args( $args, $defaults );
     34       
     35        extract($args);
     36       
     37        do_action('export_wp');
     38       
     39        if( strlen( $start_date ) > 4 && strlen( $end_date ) > 4 )
     40                $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
     41        else
     42                $filename = 'wordpress.' . date( 'Y-m-d' ) . '.xml';
     43       
     44        header( 'Content-Description: File Transfer' );
     45        header( 'Content-Disposition: attachment; filename=' . $filename );
     46        header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
     47       
     48        if ( $post_type && $post_type != 'all' )
    4249                $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
    43 } else {
     50        else
    4451                $where = "WHERE post_type != 'revision' ";
    45 }
    46 if ( $author and $author != 'all' ) {
     52       
     53        if ( $author && $author != 'all' ) {
    4754                $author_id = (int) $author;
    48                 $where .= $wpdb->prepare("AND post_author = %d ", $author_id);
    49 }
    50 if ( $start_date and $start_date != 'all' ) {
    51                 $where .= $wpdb->prepare("AND post_date >= %s ", $start_date);
    52 }
    53 if ( $end_date and $end_date != 'all' ) {
    54                 $where .= $wpdb->prepare("AND post_date < %s ", $end_date);
    55 }
    56 if ( $category and $category != 'all' ) {
    57                 $taxomony_id = (int) $category;
    58                 $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . "WHERE term_taxonomy_id = %d) ", $taxomony_id);
    59 }
    60 if ( $status and $status != 'all' ) {
    61                 $where .= $wpdb->prepare("AND post_status = %s ", $status);
    62 }
    63 
    64 // grab a snapshot of post IDs, just in case it changes during the export
    65 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    66 
    67 $categories = (array) get_categories(array('get' => 'all'));
    68 $tags = (array) get_tags(array('get' => 'all'));
    69 
    70 $custom_taxonomies = $wp_taxonomies;
    71 unset($custom_taxonomies['category']);
    72 unset($custom_taxonomies['post_tag']);
    73 unset($custom_taxonomies['link_category']);
    74 $custom_taxonomies = array_keys($custom_taxonomies);
    75 $terms = (array) get_terms($custom_taxonomies, array('get' => 'all'));
    76 
    77 /**
    78  * {@internal Missing Short Description}}
    79  *
    80  * @since unknown
    81  *
    82  * @param unknown_type $categories
    83  */
    84 function wxr_missing_parents($categories) {
    85         if ( !is_array($categories) || empty($categories) )
    86                 return array();
    87 
    88         foreach ( $categories as $category )
    89                 $parents[$category->term_id] = $category->parent;
    90 
    91         $parents = array_unique(array_diff($parents, array_keys($parents)));
    92 
    93         if ( $zero = array_search('0', $parents) )
    94                 unset($parents[$zero]);
    95 
    96         return $parents;
    97 }
    98 
    99 while ( $parents = wxr_missing_parents($categories) ) {
    100         $found_parents = get_categories(array('include' => join(', ', $parents)));
    101         if ( is_array($found_parents) && count($found_parents) )
    102                 $categories = array_merge($categories, $found_parents);
    103         else
    104                 break;
    105 }
    106 
    107 // Put them in order to be inserted with no child going before its parent
    108 $pass = 0;
    109 $passes = 1000 + count($categories);
    110 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
    111         if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
    112                 $cats[$cat->term_id] = $cat;
    113         } else {
    114                 $categories[] = $cat;
     55                $where .= $wpdb->prepare( "AND post_author = %d ", $author_id );
    11556        }
    116 }
    117 unset($categories);
    118 
    119 /**
    120  * Place string in CDATA tag.
    121  *
    122  * @since unknown
    123  *
    124  * @param string $str String to place in XML CDATA tag.
    125  */
    126 function wxr_cdata($str) {
    127         if ( seems_utf8($str) == false )
    128                 $str = utf8_encode($str);
    129 
    130         // $str = ent2ncr(esc_html($str));
    131 
    132         $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
    133 
    134         return $str;
    135 }
    136 
    137 /**
    138  * {@internal Missing Short Description}}
    139  *
    140  * @since unknown
    141  *
    142  * @return string Site URL.
    143  */
    144 function wxr_site_url() {
    145         global $current_site;
    146 
    147         // mu: the base url
    148         if ( isset($current_site->domain) ) {
    149                 return 'http://'.$current_site->domain.$current_site->path;
     57       
     58        if ( $start_date && $start_date != 'all' )
     59                $where .= $wpdb->prepare( "AND post_date >= %s ", $start_date );
     60       
     61        if ( $end_date && $end_date != 'all' )
     62                $where .= $wpdb->prepare( "AND post_date < %s ", $end_date );
     63       
     64        if ( $taxonomy && is_array( $taxonomy ) ) {
     65                foreach ( $taxonomy as $term_id ) {
     66                        if ( $term_id != 'all' )
     67                                $where .= $wpdb->prepare( "AND ID IN (SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d) ", $term_id );
     68                }
    15069        }
    151         // wp: the blog url
    152         else {
    153                 return get_bloginfo_rss('url');
     70       
     71        if ( $post_status && $post_status != 'all' )
     72                $where .= $wpdb->prepare( "AND post_status = %s", $status );
     73       
     74        // grab a snapshot of post IDs, just in case it changes during the export
     75        $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );
     76       
     77        $categories = (array) get_categories( array( 'get' => 'all' ) );
     78        $tags = (array) get_tags( array( 'get' => 'all' ) );
     79       
     80        $custom_taxonomies = $wp_taxonomies;
     81        unset( $custom_taxonomies['category'] );
     82        unset( $custom_taxonomies['post_tag'] );
     83        unset( $custom_taxonomies['link_category'] );
     84        $custom_taxonomies = array_keys( $custom_taxonomies );
     85        $terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
     86       
     87        /**
     88         * {@internal Missing Short Description}}
     89         *
     90         * @since unknown
     91         *
     92         * @param unknown_type $categories
     93         */
     94        function wxr_missing_parents( $categories ) {
     95                if ( ! is_array( $categories ) || empty( $categories ) )
     96                        return array();
     97       
     98                foreach ( $categories as $category ){
     99                        $parents[$category->term_id] = $category->parent;
     100                }
     101       
     102                $parents = array_unique( array_diff( $parents, array_keys( $parents ) ) );
     103       
     104                if ( $zero = array_search( '0', $parents ) )
     105                        unset( $parents[$zero] );
     106       
     107                return $parents;
    154108        }
    155 }
    156 
    157 /**
    158  * {@internal Missing Short Description}}
    159  *
    160  * @since unknown
    161  *
    162  * @param object $c Category Object
    163  */
    164 function wxr_cat_name($c) {
    165         if ( empty($c->name) )
    166                 return;
    167 
    168         echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
    169 }
    170 
    171 /**
    172  * {@internal Missing Short Description}}
    173  *
    174  * @since unknown
    175  *
    176  * @param object $c Category Object
    177  */
    178 function wxr_category_description($c) {
    179         if ( empty($c->description) )
    180                 return;
    181 
    182         echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
    183 }
    184 
    185 /**
    186  * {@internal Missing Short Description}}
    187  *
    188  * @since unknown
    189  *
    190  * @param object $t Tag Object
    191  */
    192 function wxr_tag_name($t) {
    193         if ( empty($t->name) )
    194                 return;
    195 
    196         echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
    197 }
    198 
    199 /**
    200  * {@internal Missing Short Description}}
    201  *
    202  * @since unknown
    203  *
    204  * @param object $t Tag Object
    205  */
    206 function wxr_tag_description($t) {
    207         if ( empty($t->description) )
    208                 return;
    209 
    210         echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
    211 }
    212 
    213 /**
    214  * {@internal Missing Short Description}}
    215  *
    216  * @since unknown
    217  *
    218  * @param object $t Term Object
    219  */
    220 function wxr_term_name($t) {
    221         if ( empty($t->name) )
    222                 return;
    223 
    224         echo '<wp:term_name>' . wxr_cdata($t->name) . '</wp:term_name>';
    225 }
    226 
    227 /**
    228  * {@internal Missing Short Description}}
    229  *
    230  * @since unknown
    231  *
    232  * @param object $t Term Object
    233  */
    234 function wxr_term_description($t) {
    235         if ( empty($t->description) )
    236                 return;
    237 
    238         echo '<wp:term_description>' . wxr_cdata($t->description) . '</wp:term_description>';
    239 }
    240 
    241 /**
    242  * {@internal Missing Short Description}}
    243  *
    244  * @since unknown
    245  */
    246 function wxr_post_taxonomy() {
    247         global $post;
    248 
    249         $the_list = '';
    250         $filter = 'rss';
    251 
    252         $taxonomies = get_object_taxonomies('post');
    253         $terms = wp_get_post_terms($post->ID, $taxonomies);
    254         foreach ( (array) $terms as $term ) {
    255                 $domain = ( 'post_tag' == $term->taxonomy ) ? 'tag' : $term->taxonomy;
    256                 $term_name = sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, $filter);
    257                 // Back compat.
    258                 if ( 'category' == $term->taxonomy )
    259                         $the_list .= "\n\t\t<category><![CDATA[$term_name]]></category>\n";
    260                 elseif ( 'post_tag' == $term->taxonomy )
    261                         $the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[$term_name]]></category>\n";
    262                 // forwards compatibility as above
    263                 $the_list .= "\n\t\t<category domain=\"$domain\" nicename=\"{$term->slug}\"><![CDATA[$term_name]]></category>\n";
     109       
     110        while ( $parents = wxr_missing_parents( $categories ) ) {
     111                $found_parents = get_categories( array( 'include' => join( ', ', $parents) ) );
     112                if ( is_array( $found_parents ) && count( $found_parents ) )
     113                        $categories = array_merge( $categories, $found_parents );
     114                else
     115                        break;
    264116        }
    265         echo $the_list;
    266 }
    267 
    268 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
    269 
    270 ?>
     117       
     118        // Put them in order to be inserted with no child going before its parent
     119        $pass = 0;
     120        $passes = 1000 + count( $categories );
     121        while ( ( $cat = array_shift( $categories ) ) && ++$pass < $passes ) {
     122                if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
     123                        $cats[$cat->term_id] = $cat;
     124                else
     125                        $categories[] = $cat;
     126        }
     127        unset( $categories );
     128       
     129        /**
     130         * Place string in CDATA tag.
     131         *
     132         * @since unknown
     133         *
     134         * @param string $str String to place in XML CDATA tag.
     135         */
     136        function wxr_cdata( $str ) {
     137                if ( seems_utf8( $str ) == false )
     138                        $str = utf8_encode( $str );
     139       
     140                // $str = ent2ncr(esc_html($str));
     141                $str = "<![CDATA[$str" . ( ( substr( $str, -1 ) == ']' ) ? ' ' : '') . "]]>";
     142       
     143                return $str;
     144        }
     145       
     146        /**
     147         * {@internal Missing Short Description}}
     148         *
     149         * @since unknown
     150         *
     151         * @return string Site URL.
     152         */
     153        function wxr_site_url() {
     154                global $current_site;
     155       
     156                // mu: the base url
     157                if ( isset( $current_site->domain ) )
     158                        return 'http://' . $current_site->domain . $current_site->path;
     159                // wp: the blog url
     160                else
     161                        return get_bloginfo_rss( 'url' );
     162        }
     163       
     164        /**
     165         * {@internal Missing Short Description}}
     166         *
     167         * @since unknown
     168         *
     169         * @param object $c Category Object
     170         */
     171        function wxr_cat_name( $c ) {
     172                if ( empty( $c->name ) )
     173                        return;
     174       
     175                echo '<wp:cat_name>' . wxr_cdata( $c->name ) . '</wp:cat_name>';
     176        }
     177       
     178        /**
     179         * {@internal Missing Short Description}}
     180         *
     181         * @since unknown
     182         *
     183         * @param object $c Category Object
     184         */
     185        function wxr_category_description( $c ) {
     186                if ( empty( $c->description ) )
     187                        return;
     188       
     189                echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
     190        }
     191       
     192        /**
     193         * {@internal Missing Short Description}}
     194         *
     195         * @since unknown
     196         *
     197         * @param object $t Tag Object
     198         */
     199        function wxr_tag_name( $t ) {
     200                if ( empty( $t->name ) )
     201                        return;
     202       
     203                echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
     204        }
     205       
     206        /**
     207         * {@internal Missing Short Description}}
     208         *
     209         * @since unknown
     210         *
     211         * @param object $t Tag Object
     212         */
     213        function wxr_tag_description( $t ) {
     214                if ( empty( $t->description ) )
     215                        return;
     216       
     217                echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
     218        }
     219       
     220        /**
     221         * {@internal Missing Short Description}}
     222         *
     223         * @since unknown
     224         *
     225         * @param object $t Term Object
     226         */
     227        function wxr_term_name( $t ) {
     228                if ( empty( $t->name ) )
     229                        return;
     230       
     231                echo '<wp:term_name>' . wxr_cdata($t->name) . '</wp:term_name>';
     232        }
     233       
     234        /**
     235         * {@internal Missing Short Description}}
     236         *
     237         * @since unknown
     238         *
     239         * @param object $t Term Object
     240         */
     241        function wxr_term_description( $t ) {
     242                if ( empty( $t->description ) )
     243                        return;
     244       
     245                echo '<wp:term_description>' . wxr_cdata($t->description) . '</wp:term_description>';
     246        }
     247       
     248        /**
     249         * {@internal Missing Short Description}}
     250         *
     251         * @since unknown
     252         */
     253        function wxr_post_taxonomy() {
     254                global $post;
     255       
     256                $the_list = '';
     257                $filter = 'rss';
     258       
     259                $taxonomies = get_object_taxonomies( 'post' );
     260                $terms = wp_get_post_terms( $post->ID, $taxonomies );
     261                foreach ( (array) $terms as $term ) {
     262                        $domain = ( 'post_tag' == $term->taxonomy ) ? 'tag' : $term->taxonomy;
     263                        $term_name = sanitize_term_field( 'name', $term->name, $term->term_id, $term->taxonomy, $filter );
     264                        // Back compat.
     265                        if ( 'category' == $term->taxonomy )
     266                                $the_list .= "\n\t\t<category><![CDATA[$term_name]]></category>\n";
     267                        elseif ( 'post_tag' == $term->taxonomy )
     268                                $the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[$term_name]]></category>\n";
     269                        // forwards compatibility as above
     270                        $the_list .= "\n\t\t<category domain=\"$domain\" nicename=\"{$term->slug}\"><![CDATA[$term_name]]></category>\n";
     271                }
     272                echo $the_list;
     273        }
     274       
     275        echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
     276       
     277        ?>
    271278<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
    272279<!-- It contains information about your blog's posts, comments, and categories. -->
    273280<!-- You may use this file to transfer that content from one site to another. -->
     
    284291<!-- 6. WordPress will then import each of the posts, comments, and categories -->
    285292<!--    contained in this file into your blog -->
    286293
    287 <?php the_generator('export');?>
     294<?php the_generator( 'export' );?>
    288295<rss version="2.0"
    289296        xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
    290297        xmlns:content="http://purl.org/rss/1.0/modules/content/"
     
    294301>
    295302
    296303<channel>
    297         <title><?php bloginfo_rss('name'); ?></title>
    298         <link><?php bloginfo_rss('url') ?></link>
    299         <description><?php bloginfo_rss("description") ?></description>
    300         <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
    301         <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
    302         <language><?php echo get_option('rss_language'); ?></language>
     304        <title><?php bloginfo_rss( 'name' ); ?></title>
     305        <link><?php bloginfo_rss( 'url' ) ?></link>
     306        <description><?php bloginfo_rss( 'description' ) ?></description>
     307        <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ); ?></pubDate>
     308        <generator>http://wordpress.org/?v=<?php bloginfo_rss( 'version' ); ?></generator>
     309        <language><?php echo get_option( 'rss_language' ); ?></language>
    303310        <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
    304311        <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
    305         <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
    306 <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
    307         <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
    308 <?php endforeach; endif; ?>
    309 <?php if ( $tags ) : foreach ( $tags as $t ) : ?>
    310         <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
    311 <?php endforeach; endif; ?>
    312 <?php if ( $terms ) : foreach ( $terms as $t ) : ?>
    313         <wp:term><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $custom_taxonomies[$t->parent]->name : ''; ?></wp:term_parent><?php wxr_term_name($t); ?><?php wxr_term_description($t); ?></wp:term>
    314 <?php endforeach; endif; ?>
    315         <?php do_action('rss2_head'); ?>
    316         <?php if ($post_ids) {
    317                 global $wp_query;
    318                 $wp_query->in_the_loop = true;  // Fake being in the loop.
    319                 // fetch 20 posts at a time rather than loading the entire table into memory
    320                 while ( $next_posts = array_splice($post_ids, 0, 20) ) {
    321                         $where = "WHERE ID IN (".join(',', $next_posts).")";
    322                         $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    323                                 foreach ($posts as $post) {
    324                         setup_postdata($post);
     312        <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
     313        <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
     314        <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name( $c ); ?><?php wxr_category_description( $c ); ?></wp:category>
     315        <?php endforeach; endif; ?>
     316        <?php if ( $tags ) : foreach ( $tags as $t ) : ?>
     317        <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name( $t ); ?><?php wxr_tag_description( $t ); ?></wp:tag>
     318        <?php endforeach; endif; ?>
     319        <?php if ( $terms ) : foreach ( $terms as $t ) : ?>
     320        <wp:term><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $custom_taxonomies[$t->parent]->name : ''; ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term>
     321        <?php endforeach; endif; ?>
     322       
     323        <?php do_action( 'rss2_head' ); ?>
    325324
    326                         $is_sticky = 0;
    327                         if ( is_sticky( $post->ID ) )
    328                                 $is_sticky = 1;
     325        <?php if ( $post_ids ) {
     326        global $wp_query;
     327        $wp_query->in_the_loop = true;  // Fake being in the loop.
     328       
     329        // fetch 20 posts at a time rather than loading the entire table into memory
     330        while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
     331        $where = "WHERE ID IN (" . join( ',', $next_posts ) . ")";
     332        $posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );
     333       
     334        // Begin Loop
     335        foreach ($posts as $post) {
     336        setup_postdata( $post );
    329337
    330 ?>
    331 <item>
    332 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
    333 <link><?php the_permalink_rss() ?></link>
    334 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
    335 <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
    336 <?php wxr_post_taxonomy() ?>
     338        $is_sticky = 0;
     339        if ( is_sticky( $post->ID ) )
     340                $is_sticky = 1;
    337341
    338 <guid isPermaLink="false"><?php the_guid(); ?></guid>
    339 <description></description>
    340 <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
    341 <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
    342 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
    343 <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
    344 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
    345 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
    346 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
    347 <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
    348 <wp:status><?php echo $post->post_status; ?></wp:status>
    349 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
    350 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
    351 <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
    352 <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
    353 <wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky>
    354 <?php
    355 if ($post->post_type == 'attachment') { ?>
    356 <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
    357 <?php } ?>
    358 <?php
    359 $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
    360 if ( $postmeta ) {
    361 ?>
    362 <?php foreach( $postmeta as $meta ) { ?>
    363 <wp:postmeta>
    364 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
    365 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
    366 </wp:postmeta>
    367 <?php } ?>
    368 <?php } ?>
    369 <?php
    370 $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
    371 if ( $comments ) { foreach ( $comments as $c ) { ?>
    372 <wp:comment>
    373 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
    374 <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
    375 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
    376 <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
    377 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
    378 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
    379 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
    380 <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
    381 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
    382 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
    383 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
    384 <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
    385 </wp:comment>
    386 <?php } } ?>
     342        ?>
     343        <item>
     344                <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
     345                <link><?php the_permalink_rss() ?></link>
     346                <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
     347                <dc:creator><?php echo wxr_cdata( get_the_author() ); ?></dc:creator>
     348                <?php wxr_post_taxonomy() ?>
     349       
     350                <guid isPermaLink="false"><?php the_guid(); ?></guid>
     351                <description></description>
     352                <content:encoded><?php echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); ?></content:encoded>
     353                <excerpt:encoded><?php echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); ?></excerpt:encoded>
     354                <wp:post_id><?php echo $post->ID; ?></wp:post_id>
     355                <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
     356                <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
     357                <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
     358                <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
     359                <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
     360                <wp:status><?php echo $post->post_status; ?></wp:status>
     361                <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
     362                <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
     363                <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
     364                <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
     365                <wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky>
     366                <?php
     367                if ( $post->post_type == 'attachment' ) { ?>
     368                <wp:attachment_url><?php echo wp_get_attachment_url( $post->ID ); ?></wp:attachment_url>
     369                <?php } ?>
     370                <?php
     371                $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
     372                if ( $postmeta ) {
     373                ?>
     374                <?php foreach( $postmeta as $meta ) { ?>
     375                <wp:postmeta>
     376                <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
     377                <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
     378                </wp:postmeta>
     379                <?php } ?>
     380                <?php } ?>
     381                <?php
     382                $comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID ) );
     383                if ( $comments ) { foreach ( $comments as $c ) { ?>
     384                <wp:comment>
     385                <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
     386                <wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
     387                <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
     388                <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
     389                <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
     390                <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
     391                <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
     392                <wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content>
     393                <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
     394                <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
     395                <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
     396                <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
     397                </wp:comment>
     398                <?php } } ?>
    387399        </item>
    388 <?php } } } ?>
     400        <?php
     401        }
     402        }
     403} ?>
    389404</channel>
    390405</rss>
    391406<?php
  • wp-admin/export.php

     
    1818
    1919if ( isset( $_GET['download'] ) ) {
    2020                $author = isset($_GET['author']) ? $_GET['author'] : 'all';
    21                 $category = isset($_GET['category']) ? $_GET['category'] : 'all';
     21                $taxonomy = array();
     22                foreach ( get_taxonomies( array( 'show_ui' => true ) ) as $tax )
     23                        $taxonomy[ $tax ] = ! empty( $_GET['taxonomy'][ $tax ] ) ? $_GET['taxonomy'][ $tax ] : 'all';
    2224                $post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all';
    2325                $status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all';
    2426                $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all';
     
    4143                } else {
    4244                        $end_date = 'all';
    4345                }
    44         export_wp( $author, $category, $post_type, $status, $start_date, $end_date );
     46        export_wp( array( 'author' => $author, 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'post_status' => $status, 'start_date' => $start_date, 'end_date' => $end_date ) );
    4547        die();
    4648}
    4749
    4850require_once ('admin-header.php');
    4951
    5052$months = "";
    51 for ( $i = 1; $i < 13; $i++ ) {
    52         $months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' .
    53                 $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
     53for ( $i = 1; $i <= 12; $i++ ) {
     54        $months .= "\t<option value=\"" . zeroise($i, 2) . '">' .
     55                $wp_locale->get_month( $i ) . "</option>\n";
    5456} ?>
    5557
    5658<div class="wrap">
     
    6668<table class="form-table">
    6769<tr>
    6870<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
    69 <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
     71<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>
    7072<select name="mm_start" id="mm_start">
    71 <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
     73        <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
    7274<?php echo $months; ?>
    73 </select>&nbsp;<?php _e('Year'); ?>&nbsp;
    74 <input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" />
    75 </td>
    76 <td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>&nbsp;
     75</select> <?php _e('Year'); ?>
     76<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" /><br/>
     77<strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>
    7778<select name="mm_end" id="mm_end">
    78 <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
     79        <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
    7980<?php echo $months; ?>
    80 </select>&nbsp;<?php _e('Year'); ?>&nbsp;
     81</select> <?php _e('Year'); ?>
    8182<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
    8283</td>
    8384</tr>
     
    8788<select name="author" id="author">
    8889<option value="all" selected="selected"><?php _e('All Authors'); ?></option>
    8990<?php
    90 $authors = $wpdb->get_results( "SELECT DISTINCT u.id, u.display_name FROM $wpdb->users u INNER JOIN $wpdb->posts p ON u.id = p.post_author ORDER BY u.display_name" );
    91 foreach ( (array) $authors as $author )
    92        echo "<option value='{$author->id}'>{$author->display_name}</option>\n";
     91$authors = $wpdb->get_results( "SELECT DISTINCT u.id, u.display_name FROM $wpdb->users u INNER JOIN $wpdb->posts p WHERE u.id = p.post_author ORDER BY u.display_name" );
     92foreach ( (array) $authors as $author ) {
     93        echo "<option value='{$author->id}'>{$author->display_name}</option>\n";
     94}
    9395?>
    9496</select>
    9597</td>
    9698</tr>
    9799<tr>
    98 <th><label for="category"><?php _e('Restrict Category'); ?></label></th>
     100<th><?php _e('Restrict Taxonomies'); ?></th>
    99101<td>
    100 <select name="category" id="category">
    101 <option value="all" selected="selected"><?php _e('All Categories'); ?></option>
    102 <?php
    103 $categories = (array) get_categories('get=all');
    104 if($categories) {
    105         foreach ( $categories as $cat ) {
    106                 echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
    107         }
     102<?php foreach ( get_taxonomies( array( 'show_ui' => true ), 'objects' ) as $tax_obj ) {
     103        $term_dropdown = wp_dropdown_categories( array( 'taxonomy' => $tax_obj->name, 'hide_if_empty' => true, 'show_option_all' => __( 'All Terms' ), 'name' => 'taxonomy[' . $tax_obj->name . ']', 'id' => 'taxonomy-' . $tax_obj->name, 'class' => '', 'echo' => false ) );
     104        if ( $term_dropdown )
     105                echo '<label for="taxonomy-' . $tax_obj->name . '">' . $tax_obj->label . '</label>: ' . $term_dropdown . '<br/>';
    108106}
    109107?>
    110 </select>
    111108</td>
    112109</tr>
    113110<tr>
    114111<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
    115112<td>
    116113<select name="post_type" id="post_type">
    117 <option value="all" selected="selected"><?php _e('All Content'); ?></option>
    118 <option value="page"><?php _e('Pages'); ?></option>
    119 <option value="post"><?php _e('Posts'); ?></option>
     114        <option value="all" selected="selected"><?php _e('All Content'); ?></option>
     115        <?php foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $post_type_obj ) { ?>
     116                <option value="<?php echo $post_type_obj->name; ?>"><?php echo $post_type_obj->label; ?></option>
     117        <?php } ?>
    120118</select>
    121119</td>
    122120</tr>
     
    124122<th><label for="status"><?php _e('Restrict Status'); ?></label></th>
    125123<td>
    126124<select name="status" id="status">
    127 <option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
    128 <option value="draft"><?php _e('Draft'); ?></option>
    129 <option value="private"><?php _e('Privately published'); ?></option>
    130 <option value="publish"><?php _e('Published'); ?></option>
    131 <option value="future"><?php _e('Scheduled'); ?></option>
     125        <option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
     126<?php foreach ( get_post_stati( array( 'internal' => false ), 'objects' ) as $post_status_obj ) { ?>
     127        <option value="<?php echo $post_status_obj->name; ?>"><?php echo $post_status_obj->label; ?></option>
     128<?php } ?>
    132129</select>
    133130</td>
    134131</tr>