Example #1
0
 function make_export()
 {
     if ($this->request->isset_GET('download') && ($this->request->isset_GET('page') && $this->request->GET('page') == 'tf_export')) {
         remove_filter('the_title_rss', 'strip_tags');
         remove_filter('the_title_rss', 'ent2ncr', 8);
         remove_filter('the_title_rss', 'esc_html');
         add_filter('the_title_rss', array($this, 'tfuse_post_title_export'), 99, 1);
         ob_start();
         require_once './includes/export.php';
         export_wp(array('content' => 'all'));
         if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
             header_remove('Content-Description');
             header_remove('Content-Disposition');
         } else {
             header("Content-Description: ");
             header("Content-Disposition: ");
         }
         $buffer = ob_get_contents();
         ob_end_clean();
         $buffer = explode('</rss>', $buffer);
         $tmp = explode('/', site_url());
         $multi = is_multisite() ? '-' . end($tmp) : '';
         $this->export_wp_filename = 'wordpress-' . TF_THEME_PREFIX . $multi . '.xml_.txt';
         $this->content = $buffer[0] . $this->tfuse_options_export() . '</rss>';
         //            $this->download_export($this->content);
         //            die();
     }
 }
Example #2
0
function cherry_plugin_export_xml()
{
    ob_start();
    export_wp();
    $xml = ob_get_clean();
    $xml = iconv('utf-8', 'utf-8//IGNORE', $xml);
    $xml = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $xml);
    $xml_dir = UPLOAD_BASE_DIR . '/sample_data.xml';
    file_put_contents($xml_dir, $xml);
    return $xml_dir;
}
Example #3
0
 /**
  * Procedure for "format/wxr" rewrite rule.
  */
 function transform()
 {
     // Check permissions
     if (!current_user_can('manage_options')) {
         $timestamp = absint(@$_REQUEST['timestamp']);
         $hashkey = @$_REQUEST['hashkey'];
         if (!$this->verifyNonce($timestamp, $hashkey)) {
             wp_die(__('Invalid permission error', 'pressbooks'));
         }
     }
     // ------------------------------------------------------------------------------------------------------------
     // WXR, Start!
     require_once ABSPATH . 'wp-admin/includes/export.php';
     export_wp();
 }
 /**
  * Rebuild every demo file
  */
 public function rebuild(ctImport $xmlImporter, ctNHP_Options $options)
 {
     //echo ctImport::getThemeOptionsPath();exit;
     //theme options
     if (file_put_contents(ctImport::getThemeOptionsPath(), $options->export()) === false) {
         throw new Exception("Cannot save file to: " . ctImport::getThemeOptionsPath());
     }
     $this->export(self::EXPORT_FILE);
     error_reporting(E_ERROR);
     require_once ABSPATH . 'wp-admin/includes/export.php';
     flush();
     ob_start();
     export_wp(array('content' => 'all'));
     $xml = ob_get_contents();
     ob_end_clean();
     file_put_contents(ctImport::getXmlPath(), $xml);
 }
Example #5
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);
    die;
}
require_once 'admin-header.php';
$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";
}
?>

<div class="wrap">
<?php 
screen_icon();
?>
<h2><?php 
echo esc_html($title);
Example #6
0
    /**
     * Export function as it is defined in the original code of export_wp defined in wp-admin/includes/export.php
     */
    private function export_wp($args = array())
    {
        require_once ABSPATH . 'wp-admin/includes/export.php';
        global $wpdb;
        /**
         * This is mostly the original code of export_wp defined in wp-admin/includes/export.php
         */
        $defaults = array('post_type' => 'all', 'post__in' => false, 'author' => false, 'category' => false, 'start_date' => false, 'end_date' => false, 'status' => false, 'skip_comments' => false, 'file_item_count' => 1000);
        $args = wp_parse_args($args, $defaults);
        WP_CLI::line("Exporting with export_wp with arguments: " . var_export($args, true));
        do_action('export_wp');
        $sitename = sanitize_key(get_bloginfo('name'));
        if (!empty($sitename)) {
            $sitename .= '.';
        }
        $append = array(date('Y-m-d'));
        foreach (array_keys($args) as $arg_key) {
            if ($defaults[$arg_key] != $args[$arg_key] && 'post__in' != $arg_key) {
                $append[] = "{$arg_key}-" . (string) $args[$arg_key];
            }
        }
        $file_name_base = sanitize_file_name($sitename . 'wordpress.' . implode(".", $append));
        if ('all' != $args['post_type'] && post_type_exists($args['post_type'])) {
            $ptype = get_post_type_object($args['post_type']);
            if (!$ptype->can_export) {
                $args['post_type'] = 'post';
            }
            $where = $wpdb->prepare("{$wpdb->posts}.post_type = %s", $args['post_type']);
        } else {
            $post_types = get_post_types(array('can_export' => true));
            $esses = array_fill(0, count($post_types), '%s');
            $where = $wpdb->prepare("{$wpdb->posts}.post_type IN (" . implode(',', $esses) . ')', $post_types);
        }
        if ($args['status'] && ('post' == $args['post_type'] || 'page' == $args['post_type'])) {
            $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_status = %s", $args['status']);
        } else {
            $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
        }
        $join = '';
        if ($args['category'] && 'post' == $args['post_type']) {
            if ($term = term_exists($args['category'], 'category')) {
                $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
                $where .= $wpdb->prepare(" AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id']);
            }
        }
        if ($args['author']) {
            $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_author = %d", $args['author']);
        }
        if ($args['start_date']) {
            $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_date >= %s", date('Y-m-d 00:00:00', strtotime($args['start_date'])));
        }
        if ($args['end_date']) {
            $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_date <= %s", date('Y-m-d 23:59:59', strtotime($args['end_date'])));
        }
        // grab a snapshot of post IDs, just in case it changes during the export
        if (empty($args['post__in'])) {
            $all_the_post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} {$join} WHERE {$where} ORDER BY post_date ASC, post_parent ASC");
        } else {
            $all_the_post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE ID IN ({$args['post__in']}) ORDER BY post_date ASC, post_parent ASC");
        }
        // Make sure we're getting all of the attachments for these posts too
        if ('all' != $args['post_type'] || !empty($args['post__in'])) {
            $all_post_ids_with_attachments = array();
            while ($post_ids = array_splice($all_the_post_ids, 0, 100)) {
                $attachment_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_parent IN (" . implode(",", array_map('intval', $post_ids)) . ")");
                $all_post_ids_with_attachments = array_merge($all_post_ids_with_attachments, $post_ids, (array) $attachment_ids);
            }
            $all_the_post_ids = $all_post_ids_with_attachments;
        }
        // get the requested terms ready, empty unless posts filtered by category or all content
        $cats = $tags = $terms = array();
        if (isset($term) && $term) {
            $cat = get_term($term['term_id'], 'category');
            $cats = array($cat->term_id => $cat);
            unset($term, $cat);
        } else {
            if ('all' == $args['post_type']) {
                $categories = (array) get_categories(array('get' => 'all'));
                $tags = (array) get_tags(array('get' => 'all'));
                $custom_taxonomies = get_taxonomies(array('_builtin' => false));
                $custom_terms = (array) get_terms($custom_taxonomies, array('get' => 'all'));
                // put categories in order with no child going before its parent
                while ($cat = array_shift($categories)) {
                    if ($cat->parent == 0 || isset($cats[$cat->parent])) {
                        $cats[$cat->term_id] = $cat;
                    } else {
                        $categories[] = $cat;
                    }
                }
                // put terms in order with no child going before its parent
                while ($t = array_shift($custom_terms)) {
                    if ($t->parent == 0 || isset($terms[$t->parent])) {
                        $terms[$t->term_id] = $t;
                    } else {
                        $custom_terms[] = $t;
                    }
                }
                unset($categories, $custom_taxonomies, $custom_terms);
            }
        }
        // Load the functions available in wp-admin/includes/export.php
        ob_start();
        export_wp(array('content' => 'page', 'start_date' => '1971-01-01', 'end_date' => '1971-01-02'));
        ob_end_clean();
        WP_CLI::line('Exporting ' . count($all_the_post_ids) . ' items to be broken into ' . ceil(count($all_the_post_ids) / $args['file_item_count']) . ' files');
        WP_CLI::line('Exporting ' . count($cats) . ' cateogries');
        WP_CLI::line('Exporting ' . count($tags) . ' tags');
        WP_CLI::line('Exporting ' . count($terms) . ' terms');
        WP_CLI::line();
        $file_count = 1;
        while ($post_ids = array_splice($all_the_post_ids, 0, $args['file_item_count'])) {
            $full_path = $this->wxr_path . $file_name_base . '.' . str_pad($file_count, 3, '0', STR_PAD_LEFT) . '.xml';
            // Create the file if it doesn't exist
            if (!file_exists($full_path)) {
                touch($full_path);
            }
            if (!file_exists($full_path)) {
                WP_CLI::error("Failed to create file " . $full_path);
                exit;
            } else {
                WP_CLI::line('Writing to file ' . $full_path);
            }
            $progress = new \cli\progress\Bar('Exporting', count($post_ids));
            $this->start_export();
            echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
            ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->

<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!--    on the site. For each author, you may choose to map to an -->
<!--    existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!--    contained in this file into your site. -->

<?php 
            the_generator('export');
            ?>
<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/<?php 
            echo WXR_VERSION;
            ?>
/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/<?php 
            echo WXR_VERSION;
            ?>
/"
>

<channel>
	<title><?php 
            bloginfo_rss('name');
            ?>
</title>
	<link><?php 
            bloginfo_rss('url');
            ?>
</link>
	<description><?php 
            bloginfo_rss('description');
            ?>
</description>
	<pubDate><?php 
            echo date('D, d M Y H:i:s +0000');
            ?>
</pubDate>
	<language><?php 
            echo get_option('rss_language');
            ?>
</language>
	<wp:wxr_version><?php 
            echo WXR_VERSION;
            ?>
</wp:wxr_version>
	<wp:base_site_url><?php 
            echo wxr_site_url();
            ?>
</wp:base_site_url>
	<wp:base_blog_url><?php 
            bloginfo_rss('url');
            ?>
</wp:base_blog_url>

<?php 
            wxr_authors_list();
            ?>

<?php 
            foreach ($cats as $c) {
                ?>
	<wp:category><wp:term_id><?php 
                echo $c->term_id;
                ?>
</wp:term_id><wp:category_nicename><?php 
                echo $c->slug;
                ?>
</wp:category_nicename><wp:category_parent><?php 
                echo $c->parent ? $cats[$c->parent]->slug : '';
                ?>
</wp:category_parent><?php 
                wxr_cat_name($c);
                wxr_category_description($c);
                ?>
</wp:category>
<?php 
            }
            foreach ($tags as $t) {
                ?>
	<wp:tag><wp:term_id><?php 
                echo $t->term_id;
                ?>
</wp:term_id><wp:tag_slug><?php 
                echo $t->slug;
                ?>
</wp:tag_slug><?php 
                wxr_tag_name($t);
                wxr_tag_description($t);
                ?>
</wp:tag>
<?php 
            }
            foreach ($terms as $t) {
                ?>
	<wp:term><wp:term_id><?php 
                echo $t->term_id;
                ?>
</wp:term_id><wp:term_taxonomy><?php 
                echo $t->taxonomy;
                ?>
</wp:term_taxonomy><wp:term_slug><?php 
                echo $t->slug;
                ?>
</wp:term_slug><wp:term_parent><?php 
                echo $t->parent ? $terms[$t->parent]->slug : '';
                ?>
</wp:term_parent><?php 
                wxr_term_name($t);
                wxr_term_description($t);
                ?>
</wp:term>
<?php 
            }
            if ('all' == $args['post_type']) {
                wxr_nav_menu_terms();
            }
            ?>

	<?php 
            do_action('rss2_head');
            ?>
	<?php 
            $this->flush_export($full_path, false);
            ?>

<?php 
            if ($post_ids) {
                global $wp_query, $post;
                $wp_query->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}");
                    // Begin Loop
                    foreach ($posts as $post) {
                        $progress->tick();
                        setup_postdata($post);
                        $is_sticky = is_sticky($post->ID) ? 1 : 0;
                        ?>
	<item>
		<title><?php 
                        echo apply_filters('the_title_rss', $post->post_title);
                        ?>
</title>
		<link><?php 
                        the_permalink_rss();
                        ?>
</link>
		<pubDate><?php 
                        echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false);
                        ?>
</pubDate>
		<dc:creator><?php 
                        echo get_the_author_meta('login');
                        ?>
</dc:creator>
		<guid isPermaLink="false"><?php 
                        esc_url(the_guid());
                        ?>
</guid>
		<description></description>
		<content:encoded><?php 
                        echo wxr_cdata(apply_filters('the_content_export', $post->post_content));
                        ?>
</content:encoded>
		<excerpt:encoded><?php 
                        echo wxr_cdata(apply_filters('the_excerpt_export', $post->post_excerpt));
                        ?>
</excerpt:encoded>
		<wp:post_id><?php 
                        echo $post->ID;
                        ?>
</wp:post_id>
		<wp:post_date><?php 
                        echo $post->post_date;
                        ?>
</wp:post_date>
		<wp:post_date_gmt><?php 
                        echo $post->post_date_gmt;
                        ?>
</wp:post_date_gmt>
		<wp:comment_status><?php 
                        echo $post->comment_status;
                        ?>
</wp:comment_status>
		<wp:ping_status><?php 
                        echo $post->ping_status;
                        ?>
</wp:ping_status>
		<wp:post_name><?php 
                        echo $post->post_name;
                        ?>
</wp:post_name>
		<wp:status><?php 
                        echo $post->post_status;
                        ?>
</wp:status>
		<wp:post_parent><?php 
                        echo $post->post_parent;
                        ?>
</wp:post_parent>
		<wp:menu_order><?php 
                        echo $post->menu_order;
                        ?>
</wp:menu_order>
		<wp:post_type><?php 
                        echo $post->post_type;
                        ?>
</wp:post_type>
		<wp:post_password><?php 
                        echo $post->post_password;
                        ?>
</wp:post_password>
		<wp:is_sticky><?php 
                        echo $is_sticky;
                        ?>
</wp:is_sticky>
<?php 
                        if ($post->post_type == 'attachment') {
                            ?>
		<wp:attachment_url><?php 
                            echo wp_get_attachment_url($post->ID);
                            ?>
</wp:attachment_url>
<?php 
                        }
                        wxr_post_taxonomy();
                        $postmeta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE post_id = %d", $post->ID));
                        foreach ($postmeta as $meta) {
                            if (apply_filters('wxr_export_skip_postmeta', false, $meta->meta_key, $meta)) {
                                continue;
                            }
                            ?>
		<wp:postmeta>
			<wp:meta_key><?php 
                            echo $meta->meta_key;
                            ?>
</wp:meta_key>
			<wp:meta_value><?php 
                            echo wxr_cdata($meta->meta_value);
                            ?>
</wp:meta_value>
		</wp:postmeta>
<?php 
                        }
                        if (false === $args['skip_comments']) {
                            $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID));
                            foreach ($comments as $c) {
                                ?>
		<wp:comment>
			<wp:comment_id><?php 
                                echo $c->comment_ID;
                                ?>
</wp:comment_id>
			<wp:comment_author><?php 
                                echo wxr_cdata($c->comment_author);
                                ?>
</wp:comment_author>
			<wp:comment_author_email><?php 
                                echo $c->comment_author_email;
                                ?>
</wp:comment_author_email>
			<wp:comment_author_url><?php 
                                echo esc_url_raw($c->comment_author_url);
                                ?>
</wp:comment_author_url>
			<wp:comment_author_IP><?php 
                                echo $c->comment_author_IP;
                                ?>
</wp:comment_author_IP>
			<wp:comment_date><?php 
                                echo $c->comment_date;
                                ?>
</wp:comment_date>
			<wp:comment_date_gmt><?php 
                                echo $c->comment_date_gmt;
                                ?>
</wp:comment_date_gmt>
			<wp:comment_content><?php 
                                echo wxr_cdata($c->comment_content);
                                ?>
</wp:comment_content>
			<wp:comment_approved><?php 
                                echo $c->comment_approved;
                                ?>
</wp:comment_approved>
			<wp:comment_type><?php 
                                echo $c->comment_type;
                                ?>
</wp:comment_type>
			<wp:comment_parent><?php 
                                echo $c->comment_parent;
                                ?>
</wp:comment_parent>
			<wp:comment_user_id><?php 
                                echo $c->user_id;
                                ?>
</wp:comment_user_id>
<?php 
                                $c_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->commentmeta} WHERE comment_id = %d", $c->comment_ID));
                                foreach ($c_meta as $meta) {
                                    ?>
			<wp:commentmeta>
				<wp:meta_key><?php 
                                    echo $meta->meta_key;
                                    ?>
</wp:meta_key>
				<wp:meta_value><?php 
                                    echo wxr_cdata($meta->meta_value);
                                    ?>
</wp:meta_value>
			</wp:commentmeta>
<?php 
                                }
                                ?>
		</wp:comment>
<?php 
                            }
                        }
                        ?>
	</item>
<?php 
                        $this->flush_export($full_path);
                    }
                }
            }
            ?>
</channel>
</rss>
<?php 
            $this->flush_export($full_path);
            $this->end_export();
            $this->stop_the_insanity();
            $progress->finish();
            $file_count++;
        }
        WP_CLI::success("All done with export");
    }
                    $args['status'] = $_GET['page_status'];
                }
            } else {
                $args['content'] = $_GET['content'];
            }
        }
    }
    /**
     * Filter the export args.
     *
     * @since 3.5.0
     *
     * @param array $args The arguments to send to the exporter.
     */
    $args = apply_filters('export_args', $args);
    export_wp($args);
    die;
}
require_once ABSPATH . 'wp-admin/admin-header.php';
/**
 * Create the date options fields for exporting a given post type.
 *
 * @global wpdb      $wpdb      WordPress database object.
 * @global WP_Locale $wp_locale Date and Time Locale object.
 *
 * @since 3.1.0
 *
 * @param string $post_type The post type. Default 'post'.
 */
function export_date_options($post_type = 'post')
{
 function codeless_export_content()
 {
     ob_start();
     if (!function_exists('export_wp')) {
         $export = ABSPATH . 'wp-admin/includes/export.php';
         require_once $export;
     }
     export_wp();
     $output = ob_get_clean();
     if ($this->save('content.xml', $output)) {
         $this->message = __("Content exported successfully", "redux-framework");
         return 1;
     } else {
         return 2;
     }
 }
<?php
require_once ('admin.php');
require_once('includes/export.php');
$title = __('Export');
$parent_file = 'edit.php';

if ( isset( $_GET['download'] ) ) {
	export_wp( $_GET['author'] );
	die();
}

require_once ('admin-header.php');
?>

<div class="wrap">
<h2><?php _e('Export'); ?></h2>
<p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
<p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
<p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress blog to import this blog.'); ?></p>
<form action="" method="get">
<h3><?php _e('Options'); ?></h3>

<table class="form-table">
<tr>
<th><?php _e('Restrict Author'); ?></th>
<td>
<select name="author">
<option value="all" selected="selected"><?php _e('All Authors'); ?></option>
<?php
$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
foreach ( $authors as $id ) {
 /**
  * The actual export is done here
  */
 function run_export()
 {
     if (is_admin() && isset($_GET['wp-attachment-export-download'])) {
         if (current_user_can('administrator') && isset($_REQUEST['wp_attachment_export_nonce']) && wp_verify_nonce($_REQUEST['wp_attachment_export_nonce'], 'wp_attachment_export_download')) {
             require_once ABSPATH . '/wp-admin/includes/export.php';
             $args = array();
             $args['content'] = $_GET['content'];
             export_wp($args);
             die;
         } else {
             wp_nonce_ays('wp_attachment_export_download');
         }
     }
 }
Example #11
0
    }
    $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';
    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') {
        $end_date = sprintf("%04d-%02d-%02d", substr($mm_end, 0, 4), substr($mm_end, 5, 2), 1);
    } else {
        $end_date = 'all';
    }
    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';
$dateoptions = $edateoptions = '';
$types = "'" . implode("', '", get_post_types(array('public' => true, 'can_export' => true), 'names')) . "'";
$stati = "'" . implode("', '", get_post_stati(array('internal' => false), 'names')) . "'";
if ($monthyears = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, YEAR(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `eyear`, MONTH(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `emonth` FROM {$wpdb->posts} WHERE post_type IN ({$types}) AND post_status IN ({$stati}) ORDER BY post_date ASC ")) {
    foreach ($monthyears as $k => $monthyear) {
        $monthyears[$k]->lmonth = $wp_locale->get_month($monthyear->month, 2);
    }
    for ($s = 0, $e = count($monthyears) - 1; $e >= 0; $s++, $e--) {
        $dateoptions .= "\t<option value=\"" . $monthyears[$s]->year . '-' . zeroise($monthyears[$s]->month, 2) . '">' . $monthyears[$s]->lmonth . ' ' . $monthyears[$s]->year . "</option>\n";
        $edateoptions .= "\t<option value=\"" . $monthyears[$e]->eyear . '-' . zeroise($monthyears[$e]->emonth, 2) . '">' . $monthyears[$e]->lmonth . ' ' . $monthyears[$e]->year . "</option>\n";
    }
}
 /**
  * Export content into XML file
  *
  * @since  1.0.0
  * @return string
  */
 function do_export_xml()
 {
     ob_start();
     $use_custom_export = apply_filters('cherry_data_manager_use_custom_export', false);
     if ($use_custom_export && function_exists($use_custom_export)) {
         call_user_func($use_custom_export);
     } else {
         export_wp();
     }
     $xml = ob_get_clean();
     $xml = iconv('utf-8', 'utf-8//IGNORE', $xml);
     $xml = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $xml);
     $upload_dir = wp_upload_dir();
     $upload_base_dir = $upload_dir['basedir'];
     $xml_dir = $upload_base_dir . '/sample_data.xml';
     file_put_contents($xml_dir, $xml);
     return $xml_dir;
 }
 /**
  * @param $job_object
  * @return bool
  */
 public function job_run(&$job_object)
 {
     $job_object->substeps_todo = 2;
     $job_object->log(sprintf(__('%d. Trying to create a WordPress export to XML file&#160;&hellip;', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']));
     //build filename
     $job_object->temp['wpexportfile'] = $job_object->generate_filename($job_object->job['wpexportfile'], 'xml');
     //check export file for writing
     if (!touch(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'])) {
         $job_object->log(__('WP Export file could not generated.', 'backwpup'), E_USER_ERROR);
         return FALSE;
     }
     //include WP export function
     $this->job_object =& $job_object;
     $this->job_object->temp['wp_export_part'] = 0;
     require_once ABSPATH . 'wp-admin/includes/export.php';
     ob_start(array($this, 'ob_callback'), 1024 * 1024);
     //start output buffering
     $args = array('content' => $job_object->job['wpexportcontent']);
     @export_wp($args);
     //WP export
     ob_end_clean();
     //End output buffering
     if (filesize(BackWPup::get_plugin_data('TEMP') . $this->job_object->temp['wpexportfile']) < 1500) {
         $job_object->log(__('Could not generate a WordPress export file.', 'backwpup'), E_USER_ERROR);
         return FALSE;
     }
     if (extension_loaded('simplexml') && class_exists('DOMDocument')) {
         $job_object->log(__('Check WP Export file&#160;&hellip;', 'backwpup'));
         $job_object->need_free_memory(filesize(BackWPup::get_plugin_data('TEMP') . $this->job_object->temp['wpexportfile']) * 2);
         $valid = TRUE;
         $internal_errors = libxml_use_internal_errors(TRUE);
         $dom = new DOMDocument();
         $old_value = NULL;
         if (function_exists('libxml_disable_entity_loader')) {
             $old_value = libxml_disable_entity_loader(TRUE);
         }
         $success = $dom->loadXML(file_get_contents(BackWPup::get_plugin_data('TEMP') . $this->job_object->temp['wpexportfile']));
         if (!is_null($old_value)) {
             libxml_disable_entity_loader($old_value);
         }
         if (!$success || isset($dom->doctype)) {
             $errors = libxml_get_errors();
             $valid = FALSE;
             foreach ($errors as $error) {
                 switch ($error->level) {
                     case LIBXML_ERR_WARNING:
                         $job_object->log(E_USER_WARNING, sprintf(__('XML WARNING (%s): %s', 'backwpup'), $error->code, trim($error->message)), BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'], $error->line);
                         break;
                     case LIBXML_ERR_ERROR:
                         $job_object->log(E_USER_WARNING, sprintf(__('XML RECOVERABLE (%s): %s', 'backwpup'), $error->code, trim($error->message)), BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'], $error->line);
                         break;
                     case LIBXML_ERR_FATAL:
                         $job_object->log(E_USER_WARNING, sprintf(__('XML ERROR (%s): %s', 'backwpup'), $error->code, trim($error->message)), BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'], $error->line);
                         break;
                 }
             }
         } else {
             $xml = simplexml_import_dom($dom);
             unset($dom);
             // halt if loading produces an error
             if (!$xml) {
                 $job_object->log(__('There was an error when reading this WXR file', 'backwpup'), E_USER_ERROR);
                 $valid = FALSE;
             } else {
                 $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
                 if (!$wxr_version) {
                     $job_object->log(__('This does not appear to be a WXR file, missing/invalid WXR version number', 'backwpup'), E_USER_ERROR);
                     $valid = FALSE;
                 }
                 $wxr_version = (string) trim($wxr_version[0]);
                 // confirm that we are dealing with the correct file format
                 if (!preg_match('/^\\d+\\.\\d+$/', $wxr_version)) {
                     $job_object->log(__('This does not appear to be a WXR file, missing/invalid WXR version number', 'backwpup'), E_USER_ERROR);
                     $valid = FALSE;
                 }
             }
         }
         libxml_use_internal_errors($internal_errors);
         if ($valid) {
             $job_object->log(__('WP Export file is a valid WXR file.', 'backwpup'));
         }
     } else {
         $job_object->log(__('WP Export file can not checked, because no XML extension loaded with the file can checked.', 'backwpup'));
     }
     $job_object->substeps_done++;
     //Compress file
     if (!empty($job_object->job['wpexportfilecompression'])) {
         $job_object->log(__('Compressing file&#160;&hellip;', 'backwpup'));
         try {
             $compress = new BackWPup_Create_Archive(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'] . $job_object->job['wpexportfilecompression']);
             if ($compress->add_file(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'])) {
                 unset($compress);
                 unlink(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile']);
                 $job_object->temp['wpexportfile'] .= $job_object->job['wpexportfilecompression'];
                 $job_object->log(__('Compressing done.', 'backwpup'));
             }
         } catch (Exception $e) {
             $job_object->log($e->getMessage(), E_USER_ERROR, $e->getFile(), $e->getLine());
             unset($compress);
             return FALSE;
         }
     }
     $job_object->substeps_done++;
     //add XML file to backup files
     if (is_readable(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'])) {
         $job_object->additional_files_to_backup[] = BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile'];
         $job_object->count_files++;
         $job_object->count_filesize = $job_object->count_filesize + @filesize(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile']);
         $job_object->log(sprintf(__('Added XML export "%1$s" with %2$s to backup file list.', 'backwpup'), $job_object->temp['wpexportfile'], size_format(filesize(BackWPup::get_plugin_data('TEMP') . $job_object->temp['wpexportfile']), 2)));
     }
     $job_object->substeps_done = 1;
     return TRUE;
 }
Example #14
0
 function export_sliders()
 {
     if (isset($_POST['export_button']) && $_POST['export_button']) {
         // Load Importer API
         require_once ABSPATH . 'wp-admin/includes/export.php';
         ob_start();
         export_wp(array('content' => 'slide'));
         $export = ob_get_contents();
         ob_get_clean();
         $terms = get_terms('slide-page', array('hide_empty' => 1));
         foreach ($terms as $term) {
             $term_meta = get_option('taxonomy_' . $term->term_id);
             $export_terms[$term->slug] = $term_meta;
         }
         $json_export_terms = json_encode($export_terms);
         $upload_dir = wp_upload_dir();
         $base_dir = trailingslashit($upload_dir['basedir']);
         $fs_dir = $base_dir . 't4p_slider/';
         $loop = new WP_Query(array('post_type' => 'slide', 'posts_per_page' => -1, 'meta_key' => '_thumbnail_id'));
         while ($loop->have_posts()) {
             $loop->the_post();
             $post_image_id = get_post_thumbnail_id(get_the_ID());
             $image_path = get_attached_file($post_image_id);
             if (isset($image_path) && $image_path) {
                 $ext = pathinfo($image_path, PATHINFO_EXTENSION);
                 @copy($image_path, $fs_dir . $post_image_id . '.' . $ext);
             }
         }
         wp_reset_query();
         $url = wp_nonce_url('edit.php?post_type=slide&page=fs_export_import');
         if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
             return;
             // stop processing here
         }
         wp_mkdir_p($fs_dir);
         if (WP_Filesystem($creds)) {
             global $wp_filesystem;
             if (!$wp_filesystem->put_contents($fs_dir . 'sliders.xml', $export, FS_CHMOD_FILE) || !$wp_filesystem->put_contents($fs_dir . 'settings.json', $json_export_terms, FS_CHMOD_FILE)) {
                 echo 'Couldn\'t export sliders, make sure wp-content/uploads is writeable.';
             } else {
                 // Initialize archive object
                 $zip = new ZipArchive();
                 $zip->open('t4p_slider.zip', ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
                 foreach (new DirectoryIterator($fs_dir) as $file) {
                     if ($file->isDot()) {
                         continue;
                     }
                     $zip->addFile($fs_dir . $file->getFilename(), $file->getFilename());
                 }
                 $zip_file = $zip->filename;
                 // Zip archive will be created only after closing object
                 $zip->close();
                 header('Content-type: application/zip');
                 header('Content-Disposition: attachment; filename="t4p_slider.zip"');
                 header('Content-length: ' . filesize($zip_file));
                 header('Pragma: no-cache');
                 header('Expires: 0');
                 readfile($zip_file);
                 foreach (new DirectoryIterator($fs_dir) as $file) {
                     if ($file->isDot()) {
                         continue;
                     }
                     @unlink($fs_dir . $file->getFilename());
                 }
             }
         }
     }
 }
 public static function export_xml()
 {
     $ids = array();
     foreach ($items as $i) {
         $ids[] = (int) $i;
         unset($i);
     }
     $ids = implode(',', array_filter($id, 'is_numeric'));
     export_wp(array('content' => 'frm_display'));
     $sitename = sanitize_key(get_bloginfo('name'));
     if (!empty($sitename)) {
         $sitename .= '.';
     }
     $filename = $sitename . '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);
     // 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 post_type = 'frm_display' and ID in (" . $ids . ")");
     add_filter('wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2);
     include FrmAppHelper::plugin_path() . '/pro/classes/views/displays/xml.php';
     die;
 }
<?php
require_once ('admin.php');
$title = __('Export');
$parent_file = 'edit.php';

if ( isset( $_GET['download'] ) )
	export_wp();

require_once ('admin-header.php');
?>

<div class="wrap">
<h2><?php _e('Export'); ?></h2>
<div class="narrow">
<p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
<p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, comments, custom fields, and categories.'); ?></p>
<p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress blog to import this blog.'); ?></p>
<form action="" method="get">
<h3><?php _e('Optional options'); ?></h3>

<table>
<tr>
<th><?php _e('Restrict Author:'); ?></th>
<td>
<select name="author">
<option value="all" selected="selected"><?php _e('All'); ?></option>
<?php
$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );  
foreach ( $authors as $id ) {
	$o = get_userdata( $id );
	echo "<option value='$o->ID'>$o->display_name</option>";
 /**
  * Output export file for single form
  *
  * @since 6.5
  */
 public function action_handle_export()
 {
     if (!empty($_GET['post']) && !empty($_GET['export']) && wp_verify_nonce($_GET['nonce'], 'ccf_form_export')) {
         require_once ABSPATH . 'wp-admin/includes/export.php';
         /**
          * We use ccf_form so we can be sure we are referring to the
          * right query later.
          */
         add_filter('query', array($this, 'filter_query'));
         export_wp(array('content' => 'ccf_form'));
         exit;
     }
 }
Example #18
0
<?php

/**
 * WordPress Export Administration Panel
 *
 * @package WordPress
 * @subpackage Administration
 */
/** Load WordPress Bootstrap */
require_once 'admin.php';
/** Load WordPress export API */
require_once 'includes/export.php';
$title = __('Export');
if (isset($_GET['download'])) {
    $author = isset($_GET['author']) ? $_GET['author'] : 'all';
    export_wp($author);
    die;
}
require_once 'admin-header.php';
?>

<div class="wrap">
<?php 
screen_icon();
?>
<h2><?php 
echo wp_specialchars($title);
?>
</h2>

<p><?php 
Example #19
0
 function wpexport_init()
 {
     if ($_POST['wpexportdownload']) {
         $catexport = $_POST['catexport'];
         export_wp($_POST['catexport']);
     }
 }
 /**
  * export content into XML file
  *
  * @since 1.0.0
  */
 function do_export_xml()
 {
     ob_start();
     export_wp();
     $xml = ob_get_clean();
     $xml = iconv('utf-8', 'utf-8//IGNORE', $xml);
     $xml = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $xml);
     $upload_dir = wp_upload_dir();
     $upload_base_dir = $upload_dir['basedir'];
     $xml_dir = $upload_base_dir . '/sample_data.xml';
     file_put_contents($xml_dir, $xml);
     return $xml_dir;
 }