Ticket #8471: 8471.r10258.diff

File 8471.r10258.diff, 15.6 KB (added by jacobsantos, 4 years ago)

Based off of r10258

Line 
1Index: export.php
2===================================================================
3--- export.php  (revision 10258)
4+++ export.php  (working copy)
5@@ -24,28 +24,166 @@
6  * @param unknown_type $author
7  */
8 function export_wp($author='') {
9-global $wpdb, $post_ids, $post;
10+       global $wpdb, $post_ids, $post;
11 
12-do_action('export_wp');
13+       do_action('export_wp');
14 
15-$filename = 'wordpress.' . date('Y-m-d') . '.xml';
16+       $filename = 'wordpress.' . date('Y-m-d') . '.xml';
17 
18-header('Content-Description: File Transfer');
19-header("Content-Disposition: attachment; filename=$filename");
20-header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
21+       header('Content-Description: File Transfer');
22+       header("Content-Disposition: attachment; filename=$filename");
23+       header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
24 
25-$where = '';
26-if ( $author and $author != 'all' ) {
27-       $author_id = (int) $author;
28-       $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
29-}
30+       $where = '';
31 
32-// grab a snapshot of post IDs, just in case it changes during the export
33-$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
34+       if ( $author and $author != 'all' ) {
35+               $author_id = (int) $author;
36+               $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
37+       }
38 
39-$categories = (array) get_categories('get=all');
40-$tags = (array) get_tags('get=all');
41+       // grab a snapshot of post IDs, just in case it changes during the export
42+       $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
43 
44+       $categories = (array) get_categories('get=all');
45+       $tags = (array) get_tags('get=all');
46+
47+       while ( $parents = wxr_missing_parents($categories) ) {
48+               $found_parents = get_categories("include=" . join(', ', $parents));
49+               if ( is_array($found_parents) && count($found_parents) )
50+                       $categories = array_merge($categories, $found_parents);
51+               else
52+                       break;
53+       }
54+
55+       // Put them in order to be inserted with no child going before its parent
56+       $pass = 0;
57+       $passes = 1000 + count($categories);
58+       while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
59+               if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
60+                       $cats[$cat->term_id] = $cat;
61+               } else {
62+                       $categories[] = $cat;
63+               }
64+       }
65+       unset($categories);
66+
67+       echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
68+?>
69+<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
70+<!-- It contains information about your blog's posts, comments, and categories. -->
71+<!-- You may use this file to transfer that content from one site to another. -->
72+<!-- This file is not intended to serve as a complete backup of your blog. -->
73+
74+<!-- To import this information into a WordPress blog follow these steps. -->
75+<!-- 1. Log into that blog as an administrator. -->
76+<!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
77+<!-- 3. Choose "WordPress" from the list. -->
78+<!-- 4. Upload this file using the form provided on that page. -->
79+<!-- 5. You will first be asked to map the authors in this export file to users -->
80+<!--    on the blog.  For each author, you may choose to map to an -->
81+<!--    existing user on the blog or to create a new user -->
82+<!-- 6. WordPress will then import each of the posts, comments, and categories -->
83+<!--    contained in this file into your blog -->
84+
85+<?php the_generator('export');?>
86+<rss version="2.0"
87+       xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
88+       xmlns:content="http://purl.org/rss/1.0/modules/content/"
89+       xmlns:wfw="http://wellformedweb.org/CommentAPI/"
90+       xmlns:dc="http://purl.org/dc/elements/1.1/"
91+       xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/">
92+
93+<channel>
94+       <title><?php bloginfo_rss('name'); ?></title>
95+       <link><?php bloginfo_rss('url') ?></link>
96+       <description><?php bloginfo_rss("description") ?></description>
97+       <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
98+       <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
99+       <language><?php echo get_option('rss_language'); ?></language>
100+       <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
101+       <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
102+       <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
103+<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
104+       <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>
105+<?php endforeach; endif; ?>
106+<?php if ( $tags ) : foreach ( $tags as $t ) : ?>
107+       <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
108+<?php endforeach; endif; ?>
109+       <?php do_action('rss2_head'); ?>
110+       <?php if ($post_ids) {
111+               global $wp_query;
112+               $wp_query->in_the_loop = true;  // Fake being in the loop.
113+               // fetch 20 posts at a time rather than loading the entire table into memory
114+               while ( $next_posts = array_splice($post_ids, 0, 20) ) {
115+                       $where = "WHERE ID IN (".join(',', $next_posts).")";
116+                       $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
117+                               foreach ($posts as $post) {
118+                       // Don't export revisions.  They bloat the export.
119+                       if ( 'revision' == $post->post_type )
120+                               continue;
121+                       setup_postdata($post); ?>
122+<item>
123+<title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
124+<link><?php the_permalink_rss() ?></link>
125+<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
126+<dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
127+<?php wxr_post_taxonomy() ?>
128+
129+<guid isPermaLink="false"><?php the_guid(); ?></guid>
130+<description></description>
131+<content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
132+<excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
133+<wp:post_id><?php echo $post->ID; ?></wp:post_id>
134+<wp:post_date><?php echo $post->post_date; ?></wp:post_date>
135+<wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
136+<wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
137+<wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
138+<wp:post_name><?php echo $post->post_name; ?></wp:post_name>
139+<wp:status><?php echo $post->post_status; ?></wp:status>
140+<wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
141+<wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
142+<wp:post_type><?php echo $post->post_type; ?></wp:post_type>
143+<wp:post_password><?php echo $post->post_password; ?></wp:post_password>
144+<?php
145+if ($post->post_type == 'attachment') { ?>
146+<wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
147+<?php } ?>
148+<?php
149+$postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
150+if ( $postmeta ) {
151+?>
152+<?php foreach( $postmeta as $meta ) { ?>
153+<wp:postmeta>
154+<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
155+<wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
156+</wp:postmeta>
157+<?php } ?>
158+<?php } ?>
159+<?php
160+$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
161+if ( $comments ) { foreach ( $comments as $c ) { ?>
162+<wp:comment>
163+<wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
164+<wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
165+<wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
166+<wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
167+<wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
168+<wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
169+<wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
170+<wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
171+<wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
172+<wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
173+<wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
174+<wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
175+</wp:comment>
176+<?php } } ?>
177+       </item>
178+<?php } } } ?>
179+</channel>
180+</rss>
181+<?php
182+}
183+
184 /**
185  * {@internal Missing Short Description}}
186  *
187@@ -68,26 +206,6 @@
188        return $parents;
189 }
190 
191-while ( $parents = wxr_missing_parents($categories) ) {
192-       $found_parents = get_categories("include=" . join(', ', $parents));
193-       if ( is_array($found_parents) && count($found_parents) )
194-               $categories = array_merge($categories, $found_parents);
195-       else
196-               break;
197-}
198-
199-// Put them in order to be inserted with no child going before its parent
200-$pass = 0;
201-$passes = 1000 + count($categories);
202-while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
203-       if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
204-               $cats[$cat->term_id] = $cat;
205-       } else {
206-               $categories[] = $cat;
207-       }
208-}
209-unset($categories);
210-
211 /**
212  * Place string in CDATA tag.
213  *
214@@ -212,123 +330,4 @@
215        echo $the_list;
216 }
217 
218-echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
219-
220 ?>
221-<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
222-<!-- It contains information about your blog's posts, comments, and categories. -->
223-<!-- You may use this file to transfer that content from one site to another. -->
224-<!-- This file is not intended to serve as a complete backup of your blog. -->
225-
226-<!-- To import this information into a WordPress blog follow these steps. -->
227-<!-- 1. Log into that blog as an administrator. -->
228-<!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
229-<!-- 3. Choose "WordPress" from the list. -->
230-<!-- 4. Upload this file using the form provided on that page. -->
231-<!-- 5. You will first be asked to map the authors in this export file to users -->
232-<!--    on the blog.  For each author, you may choose to map to an -->
233-<!--    existing user on the blog or to create a new user -->
234-<!-- 6. WordPress will then import each of the posts, comments, and categories -->
235-<!--    contained in this file into your blog -->
236-
237-<?php the_generator('export');?>
238-<rss version="2.0"
239-       xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
240-       xmlns:content="http://purl.org/rss/1.0/modules/content/"
241-       xmlns:wfw="http://wellformedweb.org/CommentAPI/"
242-       xmlns:dc="http://purl.org/dc/elements/1.1/"
243-       xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
244->
245-
246-<channel>
247-       <title><?php bloginfo_rss('name'); ?></title>
248-       <link><?php bloginfo_rss('url') ?></link>
249-       <description><?php bloginfo_rss("description") ?></description>
250-       <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
251-       <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
252-       <language><?php echo get_option('rss_language'); ?></language>
253-       <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
254-       <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
255-       <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
256-<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
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 endforeach; endif; ?>
259-<?php if ( $tags ) : foreach ( $tags as $t ) : ?>
260-       <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
261-<?php endforeach; endif; ?>
262-       <?php do_action('rss2_head'); ?>
263-       <?php if ($post_ids) {
264-               global $wp_query;
265-               $wp_query->in_the_loop = true;  // Fake being in the loop.
266-               // fetch 20 posts at a time rather than loading the entire table into memory
267-               while ( $next_posts = array_splice($post_ids, 0, 20) ) {
268-                       $where = "WHERE ID IN (".join(',', $next_posts).")";
269-                       $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
270-                               foreach ($posts as $post) {
271-                       // Don't export revisions.  They bloat the export.
272-                       if ( 'revision' == $post->post_type )
273-                               continue;
274-                       setup_postdata($post); ?>
275-<item>
276-<title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
277-<link><?php the_permalink_rss() ?></link>
278-<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
279-<dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
280-<?php wxr_post_taxonomy() ?>
281-
282-<guid isPermaLink="false"><?php the_guid(); ?></guid>
283-<description></description>
284-<content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
285-<excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
286-<wp:post_id><?php echo $post->ID; ?></wp:post_id>
287-<wp:post_date><?php echo $post->post_date; ?></wp:post_date>
288-<wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
289-<wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
290-<wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
291-<wp:post_name><?php echo $post->post_name; ?></wp:post_name>
292-<wp:status><?php echo $post->post_status; ?></wp:status>
293-<wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
294-<wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
295-<wp:post_type><?php echo $post->post_type; ?></wp:post_type>
296-<wp:post_password><?php echo $post->post_password; ?></wp:post_password>
297-<?php
298-if ($post->post_type == 'attachment') { ?>
299-<wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
300-<?php } ?>
301-<?php
302-$postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
303-if ( $postmeta ) {
304-?>
305-<?php foreach( $postmeta as $meta ) { ?>
306-<wp:postmeta>
307-<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
308-<wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
309-</wp:postmeta>
310-<?php } ?>
311-<?php } ?>
312-<?php
313-$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
314-if ( $comments ) { foreach ( $comments as $c ) { ?>
315-<wp:comment>
316-<wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
317-<wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
318-<wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
319-<wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
320-<wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
321-<wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
322-<wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
323-<wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
324-<wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
325-<wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
326-<wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
327-<wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
328-</wp:comment>
329-<?php } } ?>
330-       </item>
331-<?php } } } ?>
332-</channel>
333-</rss>
334-<?php
335-}
336-
337-?>