WordPress.org

Make WordPress Core

Ticket #8471: export-indent.diff

File export-indent.diff, 22.1 KB (added by tott, 11 years ago)

patch against rev 10020 indenting wxr exports as well as improving readbility in export.php

  • wp-admin/includes/export.php

     
    11<?php
    2 /**
    3  * WordPress Export Administration API
    4  *
    5  * @package WordPress
    6  * @subpackage Administration
    7  */
     2  /**
     3   * WordPress Export Administration API
     4   *
     5   * @package WordPress
     6   * @subpackage Administration
     7   */
    88
    9 /**
    10  * Version number for the export format.
    11  *
    12  * Bump this when something changes that might affect compatibility.
    13  *
    14  * @since unknown
    15  * @var string
    16  */
     9  /**
     10   * Version number for the export format.
     11   *
     12   * Bump this when something changes that might affect compatibility.
     13   *
     14   * @since unknown
     15   * @var string
     16   */
    1717define('WXR_VERSION', '1.0');
    1818
    1919/**
     
    2424 * @param unknown_type $author
    2525 */
    2626function export_wp($author='') {
    27 global $wpdb, $post_ids, $post;
     27    global $wpdb, $post_ids, $post;
    2828
    29 do_action('export_wp');
     29    do_action('export_wp');
    3030
    31 $filename = 'wordpress.' . date('Y-m-d') . '.xml';
     31    $filename = 'wordpress.' . date('Y-m-d') . '.xml';
    3232
    33 header('Content-Description: File Transfer');
    34 header("Content-Disposition: attachment; filename=$filename");
    35 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
     33    header('Content-Description: File Transfer');
     34    header("Content-Disposition: attachment; filename=$filename");
     35    header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    3636
    37 $where = '';
    38 if ( $author and $author != 'all' ) {
    39         $author_id = (int) $author;
    40         $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
    41 }
     37    $where = '';
     38    if ( $author and $author != 'all' ) {
     39        $author_id = (int) $author;
     40        $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
     41    }
    4242
    43 // grab a snapshot of post IDs, just in case it changes during the export
    44 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     43    // grab a snapshot of post IDs, just in case it changes during the export
     44    $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    4545
    46 $categories = (array) get_categories('get=all');
    47 $tags = (array) get_tags('get=all');
     46    $categories = (array) get_categories('get=all');
     47    $tags = (array) get_tags('get=all');
    4848
    49 /**
    50  * {@internal Missing Short Description}}
    51  *
    52  * @since unknown
    53  *
    54  * @param unknown_type $categories
    55  */
    56 function wxr_missing_parents($categories) {
    57         if ( !is_array($categories) || empty($categories) )
    58                 return array();
     49    /**
     50     * {@internal Missing Short Description}}
     51     *
     52     * @since unknown
     53     *
     54     * @param unknown_type $categories
     55     */
     56    function wxr_missing_parents($categories) {
     57        if ( !is_array($categories) || empty($categories) )
     58            return array();
    5959
    60         foreach ( $categories as $category )
    61                 $parents[$category->term_id] = $category->parent;
     60        foreach ( $categories as $category )
     61            $parents[$category->term_id] = $category->parent;
    6262
    63         $parents = array_unique(array_diff($parents, array_keys($parents)));
     63        $parents = array_unique(array_diff($parents, array_keys($parents)));
    6464
    65         if ( $zero = array_search('0', $parents) )
    66                 unset($parents[$zero]);
     65        if ( $zero = array_search('0', $parents) )
     66            unset($parents[$zero]);
    6767
    68         return $parents;
    69 }
     68        return $parents;
     69    }
    7070
    71 while ( $parents = wxr_missing_parents($categories) ) {
    72         $found_parents = get_categories("include=" . join(', ', $parents));
    73         if ( is_array($found_parents) && count($found_parents) )
    74                 $categories = array_merge($categories, $found_parents);
    75         else
    76                 break;
    77 }
     71    while ( $parents = wxr_missing_parents($categories) ) {
     72        $found_parents = get_categories("include=" . join(', ', $parents));
     73        if ( is_array($found_parents) && count($found_parents) )
     74            $categories = array_merge($categories, $found_parents);
     75        else
     76            break;
     77    }
    7878
    79 // Put them in order to be inserted with no child going before its parent
    80 $pass = 0;
    81 $passes = 1000 + count($categories);
    82 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
    83         if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
    84                 $cats[$cat->term_id] = $cat;
    85         } else {
    86                 $categories[] = $cat;
    87         }
    88 }
    89 unset($categories);
     79    // Put them in order to be inserted with no child going before its parent
     80    $pass = 0;
     81    $passes = 1000 + count($categories);
     82    while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
     83        if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
     84            $cats[$cat->term_id] = $cat;
     85        } else {
     86            $categories[] = $cat;
     87        }
     88    }
     89    unset($categories);
    9090
    91 /**
    92  * Place string in CDATA tag.
    93  *
    94  * @since unknown
    95  *
    96  * @param string $str String to place in XML CDATA tag.
    97  */
    98 function wxr_cdata($str) {
    99         if ( seems_utf8($str) == false )
    100                 $str = utf8_encode($str);
     91    /**
     92     * Place string in CDATA tag.
     93     *
     94     * @since unknown
     95     *
     96     * @param string $str String to place in XML CDATA tag.
     97     */
     98    function wxr_cdata($str) {
     99        if ( seems_utf8($str) == false )
     100            $str = utf8_encode($str);
    101101
    102         // $str = ent2ncr(wp_specialchars($str));
     102        // $str = ent2ncr(wp_specialchars($str));
    103103
    104         $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
     104        $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
    105105
    106         return $str;
    107 }
     106        return $str;
     107    }
    108108
    109 /**
    110  * {@internal Missing Short Description}}
    111  *
    112  * @since unknown
    113  *
    114  * @return string Site URL.
    115  */
    116 function wxr_site_url() {
    117         global $current_site;
     109    /**
     110     * {@internal Missing Short Description}}
     111     *
     112     * @since unknown
     113     *
     114     * @return string Site URL.
     115     */
     116    function wxr_site_url() {
     117        global $current_site;
    118118
    119         // mu: the base url
    120         if ( isset($current_site->domain) ) {
    121                 return 'http://'.$current_site->domain.$current_site->path;
    122         }
    123         // wp: the blog url
    124         else {
    125                 return get_bloginfo_rss('url');
    126         }
    127 }
     119        // mu: the base url
     120        if ( isset($current_site->domain) ) {
     121            return 'http://'.$current_site->domain.$current_site->path;
     122        }
     123        // wp: the blog url
     124        else {
     125            return get_bloginfo_rss('url');
     126        }
     127    }
    128128
    129 /**
    130  * {@internal Missing Short Description}}
    131  *
    132  * @since unknown
    133  *
    134  * @param object $c Category Object
    135  */
    136 function wxr_cat_name($c) {
    137         if ( empty($c->name) )
    138                 return;
     129    /**
     130     * {@internal Missing Short Description}}
     131     *
     132     * @since unknown
     133     *
     134     * @param object $c Category Object
     135     */
     136    function wxr_cat_name($c) {
     137        if ( empty($c->name) )
     138            return;
    139139
    140         echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
    141 }
     140        echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
     141    }
    142142
    143 /**
    144  * {@internal Missing Short Description}}
    145  *
    146  * @since unknown
    147  *
    148  * @param object $c Category Object
    149  */
    150 function wxr_category_description($c) {
    151         if ( empty($c->description) )
    152                 return;
     143    /**
     144     * {@internal Missing Short Description}}
     145     *
     146     * @since unknown
     147     *
     148     * @param object $c Category Object
     149     */
     150    function wxr_category_description($c) {
     151        if ( empty($c->description) )
     152            return;
    153153
    154         echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
    155 }
     154        echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
     155    }
    156156
    157 /**
    158  * {@internal Missing Short Description}}
    159  *
    160  * @since unknown
    161  *
    162  * @param object $t Tag Object
    163  */
    164 function wxr_tag_name($t) {
    165         if ( empty($t->name) )
    166                 return;
     157    /**
     158     * {@internal Missing Short Description}}
     159     *
     160     * @since unknown
     161     *
     162     * @param object $t Tag Object
     163     */
     164    function wxr_tag_name($t) {
     165        if ( empty($t->name) )
     166            return;
    167167
    168         echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
    169 }
     168        echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
     169    }
    170170
    171 /**
    172  * {@internal Missing Short Description}}
    173  *
    174  * @since unknown
    175  *
    176  * @param object $t Tag Object
    177  */
    178 function wxr_tag_description($t) {
    179         if ( empty($t->description) )
    180                 return;
     171    /**
     172     * {@internal Missing Short Description}}
     173     *
     174     * @since unknown
     175     *
     176     * @param object $t Tag Object
     177     */
     178    function wxr_tag_description($t) {
     179        if ( empty($t->description) )
     180            return;
    181181
    182         echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
    183 }
     182        echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
     183    }
    184184
    185 /**
    186  * {@internal Missing Short Description}}
    187  *
    188  * @since unknown
    189  */
    190 function wxr_post_taxonomy() {
    191         $categories = get_the_category();
    192         $tags = get_the_tags();
    193         $the_list = '';
    194         $filter = 'rss';
     185    /**
     186     * {@internal Missing Short Description}}
     187     *
     188     * @since unknown
     189     */
     190    function wxr_post_taxonomy() {   
     191        $categories = get_the_category();
     192        $tags = get_the_tags();
     193        $the_list = '';
     194        $filter = 'rss';
    195195
    196         if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
    197                 $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
    198                 // for backwards compatibility
    199                 $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
    200                 // forwards compatibility: use a unique identifier for each cat to avoid clashes
    201                 // http://trac.wordpress.org/ticket/5447
    202                 $the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
    203         }
     196        if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
     197                $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
     198                // for backwards compatibility
     199                $the_list .= "\t<category><![CDATA[$cat_name]]></category>\n";
     200                // forwards compatibility: use a unique identifier for each cat to avoid clashes
     201                // http://trac.wordpress.org/ticket/5447
     202                $the_list .= "\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
     203            }
    204204
    205         if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
    206                 $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
    207                 $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
    208                 // forwards compatibility as above
    209                 $the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
    210         }
     205        if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
     206                $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
     207                $the_list .= "\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
     208                // forwards compatibility as above
     209                $the_list .= "\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
     210            }
    211211
    212         echo $the_list;
    213 }
     212        echo $the_list;
     213    }
    214214
    215 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
     215    echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
    216216
    217217?>
    218218<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
     
    233233
    234234<?php the_generator('export');?>
    235235<rss version="2.0"
    236         xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
    237         xmlns:content="http://purl.org/rss/1.0/modules/content/"
    238         xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    239         xmlns:dc="http://purl.org/dc/elements/1.1/"
    240         xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
     236xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
     237xmlns:content="http://purl.org/rss/1.0/modules/content/"
     238xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     239xmlns:dc="http://purl.org/dc/elements/1.1/"
     240xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
    241241>
    242242
    243243<channel>
    244         <title><?php bloginfo_rss('name'); ?></title>
    245         <link><?php bloginfo_rss('url') ?></link>
    246         <description><?php bloginfo_rss("description") ?></description>
    247         <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
    248         <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
    249         <language><?php echo get_option('rss_language'); ?></language>
    250         <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
    251         <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
    252         <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
    253 <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
    254         <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>
    255 <?php endforeach; endif; ?>
    256 <?php if ( $tags ) : foreach ( $tags as $t ) : ?>
    257         <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
    258 <?php endforeach; endif; ?>
    259         <?php do_action('rss2_head'); ?>
    260         <?php if ($post_ids) {
    261                 global $wp_query;
    262                 $wp_query->in_the_loop = true;  // Fake being in the loop.
    263                 // fetch 20 posts at a time rather than loading the entire table into memory
    264                 while ( $next_posts = array_splice($post_ids, 0, 20) ) {
    265                         $where = "WHERE ID IN (".join(',', $next_posts).")";
    266                         $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    267                                 foreach ($posts as $post) {
    268                         // Don't export revisions.  They bloat the export.
    269                         if ( 'revision' == $post->post_type )
    270                                 continue;
    271                         setup_postdata($post); ?>
    272 <item>
    273 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
    274 <link><?php the_permalink_rss() ?></link>
    275 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
    276 <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
     244  <title><?php bloginfo_rss('name'); ?></title>
     245  <link><?php bloginfo_rss('url') ?></link>
     246  <description><?php bloginfo_rss("description") ?></description>
     247  <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
     248  <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
     249  <language><?php echo get_option('rss_language'); ?></language>
     250  <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
     251  <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
     252  <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
     253<?php
     254  if ( $cats ) :
     255      foreach ( $cats as $c ) :
     256?>
     257  <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>
     258<?php
     259      endforeach;
     260  endif;
     261  if ( $tags ) :
     262      foreach ( $tags as $t ) :
     263?>
     264  <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
     265<?php
     266      endforeach;
     267  endif;
     268  do_action('rss2_head');
     269  if ($post_ids) {
     270      global $wp_query;
     271      $wp_query->in_the_loop = true;  // Fake being in the loop.
     272      // fetch 20 posts at a time rather than loading the entire table into memory
     273      while ( $next_posts = array_splice($post_ids, 0, 20) ) {
     274         
     275          // unset wpdb->queries as this is growing with each query.
     276          unset($wpdb->queries);
     277          $wpdb->queries=array();
     278
     279          $where = "WHERE ID IN (".join(',', $next_posts).")";
     280          $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     281          foreach ($posts as $post) {
     282              // Don't export revisions.  They bloat the export.
     283              if ( 'revision' == $post->post_type )
     284                  continue;
     285              setup_postdata($post);
     286?>
     287  <item>
     288        <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
     289        <link><?php the_permalink_rss() ?></link>
     290        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
     291        <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
    277292<?php wxr_post_taxonomy() ?>
     293        <guid isPermaLink="false"><?php the_guid(); ?></guid>
     294        <description></description>
     295        <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
     296        <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
     297        <wp:post_id><?php echo $post->ID; ?></wp:post_id>
     298        <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
     299        <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
     300        <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
     301        <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
     302        <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
     303        <wp:status><?php echo $post->post_status; ?></wp:status>
     304        <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
     305        <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
     306        <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
     307        <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
     308<?php
     309              if ($post->post_type == 'attachment') {
     310?>
     311        <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
     312<?php
     313              }
     314              $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
     315              if ( $postmeta ) {
     316                  foreach( $postmeta as $meta ) {
     317?>
     318        <wp:postmeta>
     319          <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
     320          <wp:meta_value><?php echo $meta->meta_value; ?></wp:meta_value>
     321        </wp:postmeta>
     322<?php
     323                  }
     324              }
    278325
    279 <guid isPermaLink="false"><?php the_guid(); ?></guid>
    280 <description></description>
    281 <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
    282 <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
    283 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
    284 <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
    285 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
    286 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
    287 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
    288 <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
    289 <wp:status><?php echo $post->post_status; ?></wp:status>
    290 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
    291 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
    292 <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
    293 <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
     326              $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
     327
     328              if ( $comments ) {
     329                  foreach ( $comments as $c ) {
     330?>
     331        <wp:comment>
     332          <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
     333          <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
     334          <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
     335          <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
     336          <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
     337          <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
     338          <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
     339          <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
     340          <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
     341          <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
     342          <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
     343          <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
     344        </wp:comment>
    294345<?php
    295 if ($post->post_type == 'attachment') { ?>
    296 <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
    297 <?php } ?>
     346                  }
     347              } ?>
     348  </item>
    298349<?php
    299 $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
    300 if ( $postmeta ) {
     350            }
     351      }
     352  }
    301353?>
    302 <?php foreach( $postmeta as $meta ) { ?>
    303 <wp:postmeta>
    304 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
    305 <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
    306 </wp:postmeta>
    307 <?php } ?>
    308 <?php } ?>
    309 <?php
    310 $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
    311 if ( $comments ) { foreach ( $comments as $c ) { ?>
    312 <wp:comment>
    313 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
    314 <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
    315 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
    316 <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
    317 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
    318 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
    319 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
    320 <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
    321 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
    322 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
    323 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
    324 <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
    325 </wp:comment>
    326 <?php } } ?>
    327         </item>
    328 <?php } } } ?>
    329 </channel>
     354  </channel>
    330355</rss>
    331356<?php
    332357}