<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13573] trunk/wp-admin: add features to export, see #10317</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13573">13573</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-03-03 16:45:40 +0000 (Wed, 03 Mar 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>add features to export, see <a href="http://trac.wordpress.org/ticket/10317">#10317</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminexportphp">trunk/wp-admin/export.php</a></li>
<li><a href="#trunkwpadminincludesexportphp">trunk/wp-admin/includes/export.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminexportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/export.php (13572 => 13573)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/export.php        2010-03-03 07:57:44 UTC (rev 13572)
+++ trunk/wp-admin/export.php        2010-03-03 16:45:40 UTC (rev 13573)
</span><span class="lines">@@ -17,14 +17,42 @@
</span><span class="cx"> $title = __('Export');
</span><span class="cx">
</span><span class="cx"> if ( isset( $_GET['download'] ) ) {
</span><del>-        $author = isset($_GET['author']) ? $_GET['author'] : 'all';
-        export_wp( $author );
</del><ins>+                $author = isset($_GET['author']) ? $_GET['author'] : 'all';
+                $category = isset($_GET['category']) ? $_GET['category'] : '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 );
+                } 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 );
+                } else {
+                        $end_date = 'all';
+                }
+        export_wp( $author, $category, $post_type, $status, $start_date, $end_date );
</ins><span class="cx">         die();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> require_once ('admin-header.php');
</span><del>-?>
</del><span class="cx">
</span><ins>+$months = "";
+for ( $i = 1; $i < 13; $i++ ) {
+        $months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' .
+                $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
+} ?>
+
</ins><span class="cx"> <div class="wrap">
</span><span class="cx"> <?php screen_icon(); ?>
</span><span class="cx"> <h2><?php echo esc_html( $title ); ?></h2>
</span><span class="lines">@@ -37,6 +65,23 @@
</span><span class="cx">
</span><span class="cx"> <table class="form-table">
</span><span class="cx"> <tr>
</span><ins>+<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
+<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
+<select name="mm_start" id="mm_start">
+<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
+<?php echo $months; ?>
+</select>&nbsp;<?php _e('Year'); ?>&nbsp;
+<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" />
+</td>
+<td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>&nbsp;
+<select name="mm_end" id="mm_end">
+<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
+<?php echo $months; ?>
+</select>&nbsp;<?php _e('Year'); ?>&nbsp;
+<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
+</td>
+</tr>
+<tr>
</ins><span class="cx"> <th><label for="author"><?php _e('Restrict Author'); ?></label></th>
</span><span class="cx"> <td>
</span><span class="cx"> <select name="author" id="author">
</span><span class="lines">@@ -45,12 +90,50 @@
</span><span class="cx"> $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
</span><span class="cx"> foreach ( $authors as $id ) {
</span><span class="cx">         $o = get_userdata( $id );
</span><del>-        echo "<option value='" . esc_attr($o->ID) . "'>$o->display_name</option>";
</del><ins>+        echo "<option value='{$o->ID}'>{$o->display_name}</option>\n";
</ins><span class="cx"> }
</span><span class="cx"> ?>
</span><span class="cx"> </select>
</span><span class="cx"> </td>
</span><span class="cx"> </tr>
</span><ins>+<tr>
+<th><label for="category"><?php _e('Restrict Category'); ?></label></th>
+<td>
+<select name="category" id="category">
+<option value="all" selected="selected"><?php _e('All Categories'); ?></option>
+<?php
+$categories = (array) get_categories('get=all');
+if($categories) {
+        foreach ( $categories as $cat ) {
+                echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
+        }
+}
+?>
+</select>
+</td>
+</tr>
+<tr>
+<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
+<td>
+<select name="post_type" id="post_type">
+<option value="all" selected="selected"><?php _e('All Content'); ?></option>
+<option value="page"><?php _e('Pages'); ?></option>
+<option value="post"><?php _e('Posts'); ?></option>
+</select>
+</td>
+</tr>
+<tr>
+<th><label for="status"><?php _e('Restrict Status'); ?></label></th>
+<td>
+<select name="status" id="status">
+<option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
+<option value="draft"><?php _e('Draft'); ?></option>
+<option value="private"><?php _e('Privately published'); ?></option>
+<option value="publish"><?php _e('Published'); ?></option>
+<option value="future"><?php _e('Scheduled'); ?></option>
+</select>
+</td>
+</tr>
</ins><span class="cx"> </table>
</span><span class="cx"> <p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" />
</span><span class="cx"> <input type="hidden" name="download" value="true" />
</span></span></pre></div>
<a id="trunkwpadminincludesexportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/export.php (13572 => 13573)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/export.php        2010-03-03 07:57:44 UTC (rev 13572)
+++ trunk/wp-admin/includes/export.php        2010-03-03 16:45:40 UTC (rev 13573)
</span><span class="lines">@@ -23,22 +23,43 @@
</span><span class="cx"> *
</span><span class="cx"> * @param unknown_type $author
</span><span class="cx"> */
</span><del>-function export_wp($author='') {
</del><ins>+function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
</ins><span class="cx"> global $wpdb, $post_ids, $post, $wp_taxonomies;
</span><span class="cx">
</span><span class="cx"> do_action('export_wp');
</span><span class="cx">
</span><del>-$filename = 'wordpress.' . date('Y-m-d') . '.xml';
</del><ins>+if(strlen($start_date) > 4 && strlen($end_date) > 4) {
+        $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
+} else {
+        $filename = 'wordpress.' . date('Y-m-d') . '.xml';
+}
</ins><span class="cx">
</span><span class="cx"> header('Content-Description: File Transfer');
</span><span class="cx"> header("Content-Disposition: attachment; filename=$filename");
</span><span class="cx"> header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
</span><span class="cx">
</span><del>-$where = '';
-if ( $author and $author != 'all' ) {
-        $author_id = (int) $author;
-        $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
-}
</del><ins>+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);
+}
</ins><span class="cx">
</span><span class="cx"> // grab a snapshot of post IDs, just in case it changes during the export
</span><span class="cx"> $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
</span><span class="lines">@@ -300,9 +321,6 @@
</span><span class="cx">                         $where = "WHERE ID IN (".join(',', $next_posts).")";
</span><span class="cx">                         $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
</span><span class="cx">                                 foreach ($posts as $post) {
</span><del>-                        // Don't export revisions. They bloat the export.
-                        if ( 'revision' == $post->post_type )
-                                continue;
</del><span class="cx">                         setup_postdata($post);
</span><span class="cx">
</span><span class="cx">                         $is_sticky = 0;
</span></span></pre>
</div>
</div>
</body>
</html>