diff --git a/wp-admin/export.php b/wp-admin/export.php index f88599196..1f3ffc4a4 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -18,40 +18,38 @@ $title = __('Export'); if ( isset( $_GET['download'] ) ) { $author = isset($_GET['author']) ? $_GET['author'] : 'all'; - $category = isset($_GET['category']) ? $_GET['category'] : 'all'; + $taxonomy = array(); + foreach ( get_taxonomies( array( 'show_ui' => true ) ) as $tax ) + $taxonomy[ $tax ] = ! empty( $_GET['taxonomy'][ $tax ] ) ? $_GET['taxonomy'][ $tax ] : 'all'; $post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all'; $status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all'; $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all'; $mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all'; - $aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0; - $aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0; - if($mm_start != 'all' && $aa_start > 0) { - $start_date = sprintf( "%04d-%02d-%02d", $aa_start, $mm_start, 1 ); + if( $mm_start != 'all' ) { + $start_date = sprintf( "%04d-%02d-%02d", substr( $mm_start, 0, 4 ), substr( $mm_start, 5, 2 ), 1 ); } else { $start_date = 'all'; } - if($mm_end != 'all' && $aa_end > 0) { - if($mm_end == 12) { - $mm_end = 1; - $aa_end++; - } else { - $mm_end++; - } - $end_date = sprintf( "%04d-%02d-%02d", $aa_end, $mm_end, 1 ); + if( $mm_end != 'all' ) { + $end_date = sprintf( "%04d-%02d-%02d", substr( $mm_end, 0, 4 ), substr( $mm_end, 5, 2 ), 1 ); } else { $end_date = 'all'; } - export_wp( $author, $category, $post_type, $status, $start_date, $end_date ); + + export_wp( array( 'author' => $author, 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'post_status' => $status, 'start_date' => $start_date, 'end_date' => $end_date ) ); die(); } require_once ('admin-header.php'); -$months = ""; -for ( $i = 1; $i < 13; $i++ ) { - $months .= "\t\t\t\n"; -} ?> +$dateoptions = ''; +if ( $monthyears = $wpdb->get_results( "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC " ) ) { + foreach ( $monthyears as $monthyear ) { + $dateoptions .= "\t\n"; + } +} + +?>
- | + | - - | -
+
+
+ + - + + + |
---|---|---|---|
- | - | ||
+ |
+ true ), 'objects' ) as $tax_obj ) {
+ $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 ) );
+ if ( $term_dropdown )
+ echo ': ' . $term_dropdown . ' '; +} +?> + |
+||
diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php index d58a31428..07ee5fb4d 100644 --- a/wp-admin/includes/export.php +++ b/wp-admin/includes/export.php @@ -21,253 +21,260 @@ define('WXR_VERSION', '1.0'); * * @since unknown * - * @param unknown_type $author + * @param unknown_type $args */ -function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') { -global $wpdb, $post_ids, $post, $wp_taxonomies; - -do_action('export_wp'); - -if(strlen($start_date) > 4 && strlen($end_date) > 4) { - $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml'; -} else { - $filename = 'wordpress.' . date('Y-m-d') . '.xml'; -} - -header('Content-Description: File Transfer'); -header("Content-Disposition: attachment; filename=$filename"); -header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); - -if ( $post_type and $post_type != 'all' ) { - $where = $wpdb->prepare("WHERE post_type = %s ", $post_type); -} else { - $where = "WHERE post_type != 'revision' "; -} -if ( $author and $author != 'all' ) { - $author_id = (int) $author; - $where .= $wpdb->prepare("AND post_author = %d ", $author_id); -} -if ( $start_date and $start_date != 'all' ) { - $where .= $wpdb->prepare("AND post_date >= %s ", $start_date); -} -if ( $end_date and $end_date != 'all' ) { - $where .= $wpdb->prepare("AND post_date < %s ", $end_date); -} -if ( $category and $category != 'all' ) { - $taxomony_id = (int) $category; - $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . "WHERE term_taxonomy_id = %d) ", $taxomony_id); -} -if ( $status and $status != 'all' ) { - $where .= $wpdb->prepare("AND post_status = %s ", $status); -} - -// 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(array('get' => 'all')); -$tags = (array) get_tags(array('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, array('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))); - - if ( $zero = array_search('0', $parents) ) - unset($parents[$zero]); - - return $parents; -} - -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); +function export_wp( $args = array() ) { + global $wpdb, $post_ids, $post, $wp_taxonomies; + + if ( ! is_array( $args ) ) + $args = array( 'author' => $args ); + + $defaults = array( 'author' => null, 'taxonomy' => null, 'post_type' => null, 'post_status' => null, 'start_date' => null, 'end_date' => null ); + $args = wp_parse_args( $args, $defaults ); + + extract($args); + + do_action('export_wp'); + + if( strlen( $start_date ) > 4 && strlen( $end_date ) > 4 ) + $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml'; else - break; -} - -// 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; + $filename = 'wordpress.' . date( 'Y-m-d' ) . '.xml'; + + header( 'Content-Description: File Transfer' ); + header( 'Content-Disposition: attachment; filename=' . $filename ); + header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); + + if ( $post_type && $post_type != 'all' ) + $where = $wpdb->prepare("WHERE post_type = %s ", $post_type); + else + $where = "WHERE post_type != 'revision' "; + + 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); - - // $str = ent2ncr(esc_html($str)); - - $str = ""; - - return $str; -} - -/** - * {@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 'http://'.$current_site->domain.$current_site->path; + + if ( $start_date && $start_date != 'all' ) + $where .= $wpdb->prepare( "AND post_date >= %s ", $start_date ); + + if ( $end_date && $end_date != 'all' ) + $where .= $wpdb->prepare( "AND post_date < %s ", $end_date ); + + 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 ); + } } - // wp: the blog url - else { - return get_bloginfo_rss('url'); + + if ( $post_status && $post_status != 'all' ) + $where .= $wpdb->prepare( "AND post_status = %s", $status ); + + // 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( array( 'get' => 'all' ) ); + $tags = (array) get_tags( array( '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, array( '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 ) ) ); + + if ( $zero = array_search( '0', $parents ) ) + unset( $parents[$zero] ); + + return $parents; } -} - -/** - * {@internal Missing Short Description}} - * - * @since unknown - * - * @param object $c Category Object - */ -function wxr_cat_name($c) { - if ( empty($c->name) ) - return; - - echo ' |