Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 196 lines (168 sloc) 5.967 kb
b881fe7 Patrick S. Perkins add 2.8.4 from http://plugins.svn.wordpress.org/disqus-comment-system/tr...
psperkins authored
1 <?php
2 /**
3 * Adapted from WordPress 2.8
4 */
5 @set_time_limit(0);
6 @ini_set('memory_limit', '256M');
7 define('WXR_VERSION', '1.0');
8
9 /**
10 * {@internal Missing Short Description}}
11 *
12 * @since unknown
13 *
14 * @param unknown_type $categories
15 */
16 function dsq_export_wxr_missing_parents($categories) {
17 if ( !is_array($categories) || empty($categories) )
18 return array();
19
20 foreach ( $categories as $category )
21 $parents[$category->term_id] = $category->parent;
22
23 $parents = array_unique(array_diff($parents, array_keys($parents)));
24
25 if ( $zero = array_search('0', $parents) )
26 unset($parents[$zero]);
27
28 return $parents;
29 }
30
31 /**
32 * Place string in CDATA tag.
33 *
34 * @since unknown
35 *
36 * @param string $str String to place in XML CDATA tag.
37 */
38 function dsq_export_wxr_cdata($str) {
39 if ( seems_utf8($str) == false )
40 $str = utf8_encode($str);
41
42 // $str = ent2ncr(esc_html($str));
43
44 $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
45
46 return $str;
47 }
48
49 /**
50 * {@internal Missing Short Description}}
51 *
52 * @since unknown
53 *
54 * @return string Site URL.
55 */
56 function dsq_export_wxr_site_url() {
57 global $current_site;
58
59 // mu: the base url
60 if ( isset($current_site->domain) ) {
61 return 'http://'.$current_site->domain.$current_site->path;
62 }
63 // wp: the blog url
64 else {
65 return get_bloginfo_rss('url');
66 }
67 }
68
69 /**
70 * {@internal Missing Short Description}}
71 *
72 * @since unknown
73 *
74 * @param object $c Category Object
75 */
76 function dsq_export_wxr_cat_name($c) {
77 if ( empty($c->name) )
78 return;
79
80 echo '<wp:cat_name>' . dsq_export_wxr_cdata($c->name) . '</wp:cat_name>';
81 }
82
83 /**
84 * {@internal Missing Short Description}}
85 *
86 * @since unknown
87 *
88 * @param object $c Category Object
89 */
90 function dsq_export_wxr_category_description($c) {
91 if ( empty($c->description) )
92 return;
93
94 echo '<wp:category_description>' . dsq_export_wxr_cdata($c->description) . '</wp:category_description>';
95 }
96
97 /**
98 * {@internal Missing Short Description}}
99 *
100 * @since unknown
101 *
102 * @param object $t Tag Object
103 */
104 function dsq_export_wxr_tag_name($t) {
105 if ( empty($t->name) )
106 return;
107
108 echo '<wp:tag_name>' . dsq_export_wxr_cdata($t->name) . '</wp:tag_name>';
109 }
110
111 /**
112 * {@internal Missing Short Description}}
113 *
114 * @since unknown
115 *
116 * @param object $t Tag Object
117 */
118 function dsq_export_wxr_tag_description($t) {
119 if ( empty($t->description) )
120 return;
121
122 echo '<wp:tag_description>' . dsq_export_wxr_cdata($t->description) . '</wp:tag_description>';
123 }
124
125 // receives an array of posts to export
126 function dsq_export_wp($post, $comments=null) {
127 global $wpdb;
128
129 if (!$comments) {
130 $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%'", $post->ID) );
131 }
132
133 // start catching output
134 ob_start();
135
136 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
137 ?>
138 <?php the_generator('export');?>
139 <rss version="2.0"
140 xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
141 xmlns:content="http://purl.org/rss/1.0/modules/content/"
142 xmlns:dsq="http://www.disqus.com/"
143 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
144 xmlns:dc="http://purl.org/dc/elements/1.1/"
145 xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
146 >
147
148 <channel>
149 <title><?php bloginfo_rss('name'); ?></title>
150 <link><?php bloginfo_rss('url') ?></link>
151 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
152 <generator>WordPress <?php bloginfo_rss('version'); ?>; Disqus <?php echo DISQUS_VERSION; ?></generator>
153 <?php
154 global $wp_query, $post;
155 $wp_query->in_the_loop = true; // Fake being in the loop.
156 setup_postdata($post); ?>
157 <item>
158 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
159 <link><?php the_permalink_rss() ?></link>
160 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
161 <dc:creator><?php echo dsq_export_wxr_cdata(get_the_author()); ?></dc:creator>
162 <guid isPermaLink="false"><?php the_guid(); ?></guid>
163 <content:encoded><?php echo dsq_export_wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
164 <dsq:thread_identifier><?php echo dsq_identifier_for_post($post); ?></dsq:thread_identifier>
165 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
166 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
167 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
168 <?php
169 if ( $comments ) { foreach ( $comments as $c ) { ?>
170 <wp:comment>
171 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
172 <wp:comment_author><?php echo dsq_export_wxr_cdata($c->comment_author); ?></wp:comment_author>
173 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
174 <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
175 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
176 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
177 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
178 <wp:comment_content><?php echo dsq_export_wxr_cdata($c->comment_content) ?></wp:comment_content>
179 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
180 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
181 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
182 </wp:comment>
183 <?php } } // comments ?>
184 </item>
185 </channel>
186 </rss>
187 <?php
188
189 // end of WXR output
190 $output = ob_get_clean();
191
192 return $output;
193 }
194
195 ?>
Something went wrong with that request. Please try again.