/**
 * Output a term_description XML tag from a given term object
 *
 * @since 2.9.0
 *
 * @param object $term Term Object
 */
function wxr_term_description($term)
{
    if (empty($term->description)) {
        return;
    }
    echo '<wp:term_description>' . wxr_cdata($term->description) . '</wp:term_description>';
}
Esempio n. 2
0
 function option_item($name, $value)
 {
     $this->item = '';
     // if ( is_array($value) ) $value = tfuse_pk($value); // Do not export as urlencoded
     if (is_array($value)) {
         $value = serialize($value);
     }
     $value = wxr_cdata($value);
     // export as <![CDATA[ ... ]]>
     $this->item .= '<item>' . PHP_EOL;
     $this->item .= '<name>' . $name . '</name>' . PHP_EOL;
     $this->item .= '<value>' . $value . '</value>' . PHP_EOL;
     $this->item .= '</item>' . PHP_EOL . PHP_EOL;
     return $this->item;
 }
Esempio n. 3
0
 function wxr_category_description($c)
 {
     if (empty($c->category_description)) {
         return;
     }
     echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>';
 }
function lpr_export_attachment($post)
{
    if (has_post_thumbnail($post->ID)) {
        $attachment_id = get_post_thumbnail_id($post->ID);
        $attachment = wp_get_attachment_image_src($attachment_id, 'full');
        $url = $attachment[0];
        if ($data = @file_get_contents($url)) {
            $data = base64_encode($data);
        } else {
            $data = $url;
        }
        $parts = explode('.', basename($url));
        array_pop($parts);
        $filename = join('.', $parts);
        ?>
        <wp:attachment id="<?php 
        echo $attachment_id;
        ?>
" mime_type="<?php 
        echo get_post_mime_type($attachment_id);
        ?>
" filename="<?php 
        echo $filename;
        ?>
"><?php 
        echo wxr_cdata($data);
        ?>
</wp:attachment>
        <?php 
    }
}
Esempio n. 5
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");
    }
Esempio n. 6
0
 /**
  * Output list of taxonomy terms, in XML tag format, associated with a post
  *
  * @since 2.3.0
  */
 function wxr_post_taxonomy()
 {
     $post = get_post();
     $taxonomies = get_object_taxonomies($post->post_type);
     if (empty($taxonomies)) {
         return;
     }
     $terms = wp_get_object_terms($post->ID, $taxonomies);
     foreach ((array) $terms as $term) {
         echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata($term->name) . "</category>\n";
     }
 }
Esempio n. 7
0
 function wxr_tag_description($t)
 {
     if (empty($t->description)) {
         return;
     }
     echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
 }
Esempio n. 8
0
    /**
     * Add the table IDs for an exported post (table) to the WP WXR export file.
     *
     * The table IDs for a table are exported in a faked post meta field.
     * As there's no action for adding extra data to the WXR export file, we hijack the `wxr_export_skip_postmeta` filter hook.
     *
     * @since 1.5.0
     *
     * @param bool     $skip     Whether to skip the current post meta. Default false.
     * @param string   $meta_key Current meta key.
     * @param stdClass $meta     Current meta object.
     */
    public function add_table_id_to_wp_export($skip, $meta_key, $meta)
    {
        // Bail if the exporter doesn't process a TablePress table right now.
        if ($this->table_options_field_name !== $meta_key) {
            return $skip;
        }
        // Find all table IDs that map to the post ID of the table that is currently being exported.
        $table_post = $this->tables->get('table_post');
        $table_ids = array_keys($table_post, (int) $meta->post_id, true);
        // Bail if no table IDs are mapped to this post ID.
        if (empty($table_ids)) {
            return $skip;
        }
        // Pretend that there is a `_tablepress_export_table_id` post meta field with the list of table IDs.
        $key = '_tablepress_export_table_id';
        $value = wxr_cdata(implode(',', $table_ids));
        // Hijack the filter and print extra XML code for our faked post meta field.
        echo <<<WXR
\t\t<wp:postmeta>
\t\t\t<wp:meta_key>{$key}</wp:meta_key>
\t\t\t<wp:meta_value>{$value}</wp:meta_value>
\t\t</wp:postmeta>

WXR;
        return $skip;
    }
Esempio n. 9
0
/**
 * Output list of authors with posts
 *
 * @since 3.1.0
 */
function wxr_authors_list()
{
    global $wpdb;
    $authors = array();
    $results = $wpdb->get_results("SELECT DISTINCT post_author FROM {$wpdb->posts}");
    foreach ((array) $results as $result) {
        $authors[] = get_userdata($result->post_author);
    }
    $authors = array_filter($authors);
    foreach ($authors as $author) {
        echo "\t<wp:author>";
        echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
        echo '<wp:author_login>' . $author->user_login . '</wp:author_login>';
        echo '<wp:author_email>' . $author->user_email . '</wp:author_email>';
        echo '<wp:author_display_name>' . wxr_cdata($author->display_name) . '</wp:author_display_name>';
        echo '<wp:author_first_name>' . wxr_cdata($author->user_firstname) . '</wp:author_first_name>';
        echo '<wp:author_last_name>' . wxr_cdata($author->user_lastname) . '</wp:author_last_name>';
        echo "</wp:author>\n";
    }
}
Esempio n. 10
0
    // endforeachh
}
if ($_lpr_course_author_ids) {
    foreach ((array) $_lpr_course_author_ids as $result) {
        $authors[] = get_userdata($result);
    }
    $authors = array_filter($authors);
    foreach ($authors as $author) {
        ob_start();
        echo "\t<wp:author>";
        echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
        echo '<wp:author_login>' . $author->user_login . '</wp:author_login>';
        echo '<wp:author_email>' . $author->user_email . '</wp:author_email>';
        echo '<wp:author_display_name>' . wxr_cdata($author->display_name) . '</wp:author_display_name>';
        echo '<wp:author_first_name>' . wxr_cdata($author->user_firstname) . '</wp:author_first_name>';
        echo '<wp:author_last_name>' . wxr_cdata($author->user_lastname) . '</wp:author_last_name>';
        echo "</wp:author>\n";
        $_lpr_course_authors[] = ob_get_clean();
    }
}
if ($_lpr_course_authors) {
    echo "\n<!-- START: Authors -->";
    echo "\n" . join("\n", $_lpr_course_authors);
    echo "\n<!-- END: Authors -->";
}
if ($_lpr_courses) {
    echo "\n<!-- START: Courses -->";
    echo "\n" . join("\n", $_lpr_courses);
    echo "\n<!-- END: Courses -->";
}
if ($_lpr_course_lesson_quiz) {
	/**
	 * Output a category_description XML tag from a given category object
	 *
	 * @since 2.1.0
	 *
	 * @param object $category Category Object
	 */
  	function wxr_category_description( $category ) {
		if ( empty( $category->description ) )
			return;

		echo '<wp:category_description>' . wxr_cdata( $category->description ) . '</wp:category_description>';
	}
         *
         * Returning a truthy value to the filter will skip the current meta
         * object from being exported.
         *
         * @since 4.0.0
         *
         * @param bool   $skip     Whether to skip the current comment meta. Default false.
         * @param string $meta_key Current meta key.
         * @param object $meta     Current meta object.
         */
        if (apply_filters('wxr_export_skip_commentmeta', false, $meta->meta_key, $meta)) {
            continue;
        }
        ?>
		<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 
}
echo "\n";
?>
</item>
Esempio n. 13
0
    /**
     *
     *
     *
     */
    function handle_export()
    {
        global $wpdb;
        if (!isset($_POST['option_page']) || $_POST['option_page'] != $this->plugin_slug . '_settings') {
            return;
        }
        define('WXR_VERSION', '1.2');
        /** Load WordPress export API */
        require_once plugin_dir_path(__FILE__) . '/includes/export.php';
        @($p_types = $_POST['wpefi_settings']['p_types']);
        if (!empty($p_types)) {
            foreach ($p_types as $k => $val) {
                $p_types_a[] = $k;
            }
            $post_types = $p_types_a;
            $esses = array_fill(0, count($post_types), '%s');
            $where = $wpdb->prepare("{$wpdb->posts}.post_type IN (" . implode(',', $esses) . ')', $post_types);
        }
        $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);
        if (!empty($posts_types)) {
            // 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;
                }
            }
        }
        $join = "LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)";
        $where .= " AND {$wpdb->postmeta}.meta_key = '_thumbnail_id'";
        // grab a snapshot of post IDs, just in case it changes during the export
        $post_ids = $wpdb->get_col("SELECT {$wpdb->postmeta}.meta_value FROM {$wpdb->posts} {$join} WHERE {$where}");
        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 
        bloginfo_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 
        if ($post_ids) {
            global $wp_query;
            $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) {
                    setup_postdata($post);
                    $is_sticky = is_sticky($post->ID) ? 1 : 0;
                    ?>
				<item>
					<?php 
                    /** This filter is documented in wp-includes/feed.php */
                    ?>
					<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 wxr_cdata(get_the_author_meta('login'));
                    ?>
</dc:creator>
					<guid isPermaLink="false"><?php 
                    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 
                    }
                    ?>
			<?php 
                    wxr_post_taxonomy();
                    ?>
			<?php 
                    $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 
                    }
                    ?>
			
				</item>
			<?php 
                }
            }
        }
        ?>
			<?php 
        do_action('rss2_head');
        ?>
			</channel>
			</rss><?php 
        die;
    }