X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/1c09677af04c9e37714e09b73eb9dbc5b2e3eb13..a01a150d87a096c70b6ec80332b7ce89c943eefe:/wp-admin/includes/export.php?ds=sidebyside
diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php
index 921a2377..a9e8f22d 100644
--- a/wp-admin/includes/export.php
+++ b/wp-admin/includes/export.php
@@ -21,235 +21,260 @@ define('WXR_VERSION', '1.0');
*
* @since unknown
*
- * @param unknown_type $author
+ * @param unknown_type $args
*/
-function export_wp($author='') {
-global $wpdb, $post_ids, $post, $wp_taxonomies;
+function export_wp( $args = array() ) {
+ global $wpdb, $post_ids, $post, $wp_taxonomies;
-do_action('export_wp');
+ if ( ! is_array( $args ) )
+ $args = array( 'author' => $args );
-$filename = 'wordpress.' . date('Y-m-d') . '.xml';
+ $defaults = array( 'author' => null, 'taxonomy' => null, 'post_type' => null, 'post_status' => null, 'start_date' => null, 'end_date' => null );
+ $args = wp_parse_args( $args, $defaults );
-header('Content-Description: File Transfer');
-header("Content-Disposition: attachment; filename=$filename");
-header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
+ extract($args);
-$where = '';
-if ( $author and $author != 'all' ) {
- $author_id = (int) $author;
- $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
-}
-
-// grab a snapshot of post IDs, just in case it changes during the export
-$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
-
-$categories = (array) get_categories('get=all');
-$tags = (array) get_tags('get=all');
-
-$custom_taxonomies = $wp_taxonomies;
-unset($custom_taxonomies['category']);
-unset($custom_taxonomies['post_tag']);
-unset($custom_taxonomies['link_category']);
-$custom_taxonomies = array_keys($custom_taxonomies);
-$terms = (array) get_terms($custom_taxonomies, 'get=all');
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param unknown_type $categories
- */
-function wxr_missing_parents($categories) {
- if ( !is_array($categories) || empty($categories) )
- return array();
-
- foreach ( $categories as $category )
- $parents[$category->term_id] = $category->parent;
-
- $parents = array_unique(array_diff($parents, array_keys($parents)));
+ do_action('export_wp');
- if ( $zero = array_search('0', $parents) )
- unset($parents[$zero]);
+ if( strlen( $start_date ) > 4 && strlen( $end_date ) > 4 )
+ $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
+ else
+ $filename = 'wordpress.' . date( 'Y-m-d' ) . '.xml';
- return $parents;
-}
+ header( 'Content-Description: File Transfer' );
+ header( 'Content-Disposition: attachment; filename=' . $filename );
+ header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
-while ( $parents = wxr_missing_parents($categories) ) {
- $found_parents = get_categories("include=" . join(', ', $parents));
- if ( is_array($found_parents) && count($found_parents) )
- $categories = array_merge($categories, $found_parents);
+ if ( $post_type && $post_type != 'all' )
+ $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
else
- break;
-}
+ $where = "WHERE post_type != 'revision' ";
-// Put them in order to be inserted with no child going before its parent
-$pass = 0;
-$passes = 1000 + count($categories);
-while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
- if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
- $cats[$cat->term_id] = $cat;
- } else {
- $categories[] = $cat;
+ if ( $author && $author != 'all' ) {
+ $author_id = (int) $author;
+ $where .= $wpdb->prepare( "AND post_author = %d ", $author_id );
}
-}
-unset($categories);
-/**
- * Place string in CDATA tag.
- *
- * @since unknown
- *
- * @param string $str String to place in XML CDATA tag.
- */
-function wxr_cdata($str) {
- if ( seems_utf8($str) == false )
- $str = utf8_encode($str);
+ if ( $start_date && $start_date != 'all' )
+ $where .= $wpdb->prepare( "AND post_date >= %s ", $start_date );
- // $str = ent2ncr(esc_html($str));
+ if ( $end_date && $end_date != 'all' )
+ $where .= $wpdb->prepare( "AND post_date < %s ", $end_date );
- $str = "";
+ if ( $taxonomy && is_array( $taxonomy ) ) {
+ foreach ( $taxonomy as $term_id ) {
+ if ( $term_id != 'all' )
+ $where .= $wpdb->prepare( "AND ID IN (SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d) ", $term_id );
+ }
+ }
- return $str;
-}
+ if ( $post_status && $post_status != 'all' )
+ $where .= $wpdb->prepare( "AND post_status = %s", $post_status );
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @return string Site URL.
- */
-function wxr_site_url() {
- global $current_site;
+ // grab a snapshot of post IDs, just in case it changes during the export
+ $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );
- // mu: the base url
- if ( isset($current_site->domain) ) {
- return 'http://'.$current_site->domain.$current_site->path;
- }
- // wp: the blog url
- else {
- return get_bloginfo_rss('url');
- }
-}
+ $categories = (array) get_categories( array( 'get' => 'all' ) );
+ $tags = (array) get_tags( array( 'get' => 'all' ) );
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $c Category Object
- */
-function wxr_cat_name($c) {
- if ( empty($c->name) )
- return;
+ $custom_taxonomies = $wp_taxonomies;
+ unset( $custom_taxonomies['category'] );
+ unset( $custom_taxonomies['post_tag'] );
+ unset( $custom_taxonomies['link_category'] );
+ $custom_taxonomies = array_keys( $custom_taxonomies );
+ $terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
- echo '' . wxr_cdata($c->name) . '';
-}
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $categories
+ */
+ function wxr_missing_parents( $categories ) {
+ if ( ! is_array( $categories ) || empty( $categories ) )
+ return array();
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $c Category Object
- */
-function wxr_category_description($c) {
- if ( empty($c->description) )
- return;
+ foreach ( $categories as $category ){
+ $parents[$category->term_id] = $category->parent;
+ }
- echo '' . wxr_cdata($c->description) . '';
-}
+ $parents = array_unique( array_diff( $parents, array_keys( $parents ) ) );
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Tag Object
- */
-function wxr_tag_name($t) {
- if ( empty($t->name) )
- return;
+ if ( $zero = array_search( '0', $parents ) )
+ unset( $parents[$zero] );
- echo '' . wxr_cdata($t->name) . '';
-}
+ return $parents;
+ }
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Tag Object
- */
-function wxr_tag_description($t) {
- if ( empty($t->description) )
- return;
+ while ( $parents = wxr_missing_parents( $categories ) ) {
+ $found_parents = get_categories( array( 'include' => join( ', ', $parents) ) );
+ if ( is_array( $found_parents ) && count( $found_parents ) )
+ $categories = array_merge( $categories, $found_parents );
+ else
+ break;
+ }
- echo '' . wxr_cdata($t->description) . '';
-}
+ // Put them in order to be inserted with no child going before its parent
+ $pass = 0;
+ $passes = 1000 + count( $categories );
+ while ( ( $cat = array_shift( $categories ) ) && ++$pass < $passes ) {
+ if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
+ $cats[$cat->term_id] = $cat;
+ else
+ $categories[] = $cat;
+ }
+ unset( $categories );
+
+ /**
+ * Place string in CDATA tag.
+ *
+ * @since unknown
+ *
+ * @param string $str String to place in XML CDATA tag.
+ */
+ function wxr_cdata( $str ) {
+ if ( seems_utf8( $str ) == false )
+ $str = utf8_encode( $str );
+
+ // $str = ent2ncr(esc_html($str));
+ $str = "";
+
+ return $str;
+ }
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Term Object
- */
-function wxr_term_name($t) {
- if ( empty($t->name) )
- return;
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @return string Site URL.
+ */
+ function wxr_site_url() {
+ global $current_site;
+
+ // mu: the base url
+ if ( isset( $current_site->domain ) )
+ return network_home_url();
+ // wp: the blog url
+ else
+ return get_bloginfo_rss( 'url' );
+ }
- echo '' . wxr_cdata($t->name) . '';
-}
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $c Category Object
+ */
+ function wxr_cat_name( $c ) {
+ if ( empty( $c->name ) )
+ return;
+
+ echo '' . wxr_cdata( $c->name ) . '';
+ }
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param object $t Term Object
- */
-function wxr_term_description($t) {
- if ( empty($t->description) )
- return;
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $c Category Object
+ */
+ function wxr_category_description( $c ) {
+ if ( empty( $c->description ) )
+ return;
+
+ echo '' . wxr_cdata($c->description) . '';
+ }
- echo '' . wxr_cdata($t->description) . '';
-}
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $t Tag Object
+ */
+ function wxr_tag_name( $t ) {
+ if ( empty( $t->name ) )
+ return;
+
+ echo '' . wxr_cdata($t->name) . '';
+ }
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- */
-function wxr_post_taxonomy() {
- $categories = get_the_category();
- $tags = get_the_tags();
- $the_list = '';
- $filter = 'rss';
-
- if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
- $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
- // for backwards compatibility
- $the_list .= "\n\t\t\n";
- // forwards compatibility: use a unique identifier for each cat to avoid clashes
- // http://trac.wordpress.org/ticket/5447
- $the_list .= "\n\t\tslug}\">\n";
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $t Tag Object
+ */
+ function wxr_tag_description( $t ) {
+ if ( empty( $t->description ) )
+ return;
+
+ echo '' . wxr_cdata($t->description) . '';
}
- if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
- $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
- $the_list .= "\n\t\t\n";
- // forwards compatibility as above
- $the_list .= "\n\t\tslug}\">\n";
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $t Term Object
+ */
+ function wxr_term_name( $t ) {
+ if ( empty( $t->name ) )
+ return;
+
+ echo '' . wxr_cdata($t->name) . '';
}
- echo $the_list;
-}
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param object $t Term Object
+ */
+ function wxr_term_description( $t ) {
+ if ( empty( $t->description ) )
+ return;
+
+ echo '' . wxr_cdata($t->description) . '';
+ }
-echo '\n";
+ /**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ */
+ function wxr_post_taxonomy() {
+ global $post;
+
+ $the_list = '';
+ $filter = 'rss';
+
+ $taxonomies = get_object_taxonomies( 'post' );
+ $terms = wp_get_post_terms( $post->ID, $taxonomies );
+ foreach ( (array) $terms as $term ) {
+ $domain = ( 'post_tag' == $term->taxonomy ) ? 'tag' : $term->taxonomy;
+ $term_name = sanitize_term_field( 'name', $term->name, $term->term_id, $term->taxonomy, $filter );
+ // Back compat.
+ if ( 'category' == $term->taxonomy )
+ $the_list .= "\n\t\t\n";
+ elseif ( 'post_tag' == $term->taxonomy )
+ $the_list .= "\n\t\t\n";
+ // forwards compatibility as above
+ $the_list .= "\n\t\tslug}\">\n";
+ }
+ echo $the_list;
+ }
-?>
+ echo '\n";
+
+ ?>
@@ -266,7 +291,7 @@ echo '\n";
-
+
\n";
>
-
-
-
-
- http://wordpress.org/?v=
-
+
+
+
+
+ http://wordpress.org/?v=
+
-
-
- slug; ?>parent ? $cats[$c->parent]->name : ''; ?>
-
-
- slug; ?>
-
-
- taxonomy; ?>slug; ?>parent ? $custom_taxonomies[$t->parent]->name : ''; ?>
-
-
- in_the_loop = true; // Fake being in the loop.
- // fetch 20 posts at a time rather than loading the entire table into memory
- while ( $next_posts = array_splice($post_ids, 0, 20) ) {
- $where = "WHERE ID IN (".join(',', $next_posts).")";
- $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
- foreach ($posts as $post) {
- // Don't export revisions. They bloat the export.
- if ( 'revision' == $post->post_type )
- continue;
- setup_postdata($post);
-
- $is_sticky = 0;
- if ( is_sticky( $post->ID ) )
- $is_sticky = 1;
-
-?>
--
-post_title); ?>
-
-
-
-
-
-
-
-post_content) ); ?>
-post_excerpt) ); ?>
-ID; ?>
-post_date; ?>
-post_date_gmt; ?>
-comment_status; ?>
-ping_status; ?>
-post_name; ?>
-post_status; ?>
-post_parent; ?>
-menu_order; ?>
-post_type; ?>
-post_password; ?>
-
-post_type == 'attachment') { ?>
-ID); ?>
-
-get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
-if ( $postmeta ) {
-?>
-
-
-meta_key; ?>
-meta_value; ?>
-
-
-
-get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
-if ( $comments ) { foreach ( $comments as $c ) { ?>
-
-comment_ID; ?>
-comment_author); ?>
-comment_author_email; ?>
-comment_author_url ); ?>
-comment_author_IP; ?>
-comment_date; ?>
-comment_date_gmt; ?>
-comment_content) ?>
-comment_approved; ?>
-comment_type; ?>
-comment_parent; ?>
-user_id; ?>
-
-
+
+
+ slug; ?>parent ? $cats[$c->parent]->name : ''; ?>
+
+
+ slug; ?>
+
+
+ taxonomy; ?>slug; ?>parent ? $custom_taxonomies[$t->parent]->name : ''; ?>
+
+
+
+
+ in_the_loop = true; // Fake being in the loop.
+
+ // fetch 20 posts at a time rather than loading the entire table into memory
+ while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
+ $where = "WHERE ID IN (" . join( ',', $next_posts ) . ")";
+ $posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );
+
+ // Begin Loop
+ foreach ($posts as $post) {
+ setup_postdata( $post );
+
+ $is_sticky = 0;
+ if ( is_sticky( $post->ID ) )
+ $is_sticky = 1;
+
+ ?>
+
-
+ post_title ); ?>
+
+
+
+
+
+
+
+ post_content ) ); ?>
+ post_excerpt ) ); ?>
+ ID; ?>
+ post_date; ?>
+ post_date_gmt; ?>
+ comment_status; ?>
+ ping_status; ?>
+ post_name; ?>
+ post_status; ?>
+ post_parent; ?>
+ menu_order; ?>
+ post_type; ?>
+ post_password; ?>
+
+ post_type == 'attachment' ) { ?>
+ ID ); ?>
+
+ get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
+ if ( $postmeta ) {
+ ?>
+
+
+ meta_key; ?>
+ meta_value ); ?>
+
+
+
+ get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID ) );
+ if ( $comments ) { foreach ( $comments as $c ) { ?>
+
+ comment_ID; ?>
+ comment_author ); ?>
+ comment_author_email; ?>
+ comment_author_url ); ?>
+ comment_author_IP; ?>
+ comment_date; ?>
+ comment_date_gmt; ?>
+ comment_content ) ?>
+ comment_approved; ?>
+ comment_type; ?>
+ comment_parent; ?>
+ user_id; ?>
+
+
-
+