Source for file mvblog_import_wordpress.php
Documentation is available at mvblog_import_wordpress.php
* MvBlog -- An open source no-nosense blogtool
* Copyright (C) 2005-2007, Michiel van Baak
* Michiel van Baak <mvanbaak@users.sourceforge.net>
* See http://dev.mvblog.org for more information on MvBlog.
* That page also provides Bugtrackers, Filereleases etc.
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
* @author Michiel van Baak
* @copyright 2005-2007 Michiel van Baak
* Class that holds methods for WordPress import
switch ($options["importaction"]) {
echo
"<p>This importer allows you to import WordPress data into MvBlog.<br />";
echo
"Your Mileage may vary.<br /><br /></p>\n";
echo
"<p>Your WordPress database settings<br />\n";
echo
"<form name=\"wp_import\" action=\"index.php\" method=\"post\">\n";
echo
"<input type=\"hidden\" name=\"action\" value=\"import\" />\n";
echo
"<input type=\"hidden\" name=\"type\" value=\"wordpress\" />\n";
echo
"<input type=\"hidden\" name=\"importaction\" value=\"run_import\" />\n";
echo
"<table border=\"0\"><tr>\n";
echo
"<td>WordPress Database server:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"dbserver\" /></td>\n";
echo
"<td>WordPress Database name:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"dbname\" /></td>\n";
echo
"<td>WordPress Database user:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"dbuser\" /></td>\n";
echo
"<td>WordPress Database password:</td><td><input type=\"password\" style=\"width: 200px;\" name=\"dbpass\" /></td>\n";
echo
"<td>WordPress Table prefix:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"dbprefix\" /></td>\n";
echo
"<td>WordPress Base URL:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"orig_url\" /></td>\n";
echo
"<td>WordPress Filesystem Location:</td><td><input type=\"text\" style=\"width: 200px;\" name=\"fs_location\" /></td>\n";
echo
"<input type=\"submit\" value=\"".
gettext("import").
"\" />\n";
// first try to copy all files
$this->copy_files($data["fs_location"].
"wp-content/uploads", "", "wp-uploads", 1);
// find out if we have enough info for a database connection
echo
"not enough information.";
$db =
mysql_connect($data["dbserver"], $data["dbuser"], $data["dbpass"]);
//grab WP db version as we only support 2.3 and newer
$sql =
sprintf("SELECT option_value FROM %soptions WHERE option_name='db_version'", $data["dbprefix"]);
die("You need at least WP 2.3.0");
//import categories and maintain array with oldid=>newid so we can link the articles to the correct ids
* WP categories are stored in the table <prefix>terms
* The table <prefix>term_taxonomy holds a count for them
* The table <prefix>term_relationships links articles and term_taxonomy records together
* <posts> -> <term_relationships> -> <term_taxonomy> -> <terms>
$sql =
sprintf("SELECT %1\$sterms.term_id, %1\$sterms.name, %1\$sterm_taxonomy.term_taxonomy_id from %1\$sterms LEFT JOIN %1\$sterm_taxonomy ON %1\$sterm_taxonomy.term_id = %1\$sterms.term_id", $data["dbprefix"]);
$cat_sql =
sprintf("INSERT INTO categories (name, `desc`, public, active) VALUES ('%1\$s', '%1\$s', 1, 1)",
$r =
$GLOBALS["admin"]->db->query($cat_sql);
$category[$row["term_taxonomy_id"]] =
$GLOBALS["admin"]->db->lastInsertID("categories", "id");
$sql =
sprintf("SELECT * FROM %sposts WHERE post_type='post'", $data["dbprefix"]);
if ($row["comment_status"] ==
"open")
if ($row["post_status"] ==
"publish" ||
$row["post_status"] ==
"static")
$last_modified =
strtotime($row["post_modified"]);
$q =
sprintf("SELECT term_taxonomy_id FROM %sterm_relationships WHERE object_id=%d", $data["dbprefix"], $row["ID"]);
$categories[] =
$category[$catr["term_taxonomy_id"]];
$data["oldsite"] =
$data["orig_url"];
$wpuploadurl =
sprintf("%s%s", $data["oldsite"], "wp-content/uploads/");
//find all links pointing to internal links and replace them with the new structure
preg_match_all("/<[img|a][^>]*[.]*>/si", $row["post_content"], $matches);
foreach ($matches[0] as $match) {
foreach ($filtermatch as $v) {
if (strstr($v, $data["oldsite"]) &&
strstr($v, $wpuploadurl)) {
$row["post_content"] =
str_replace($v, "site_images/wp-uploads/".
str_replace($wpuploadurl, "", $v), $row["post_content"]);
foreach ($filtermatch as $v) {
if (strstr($v, $data["oldsite"]) &&
strstr($v, $wpuploadurl)) {
$row["post_content"] =
str_replace($v, "site_images/wp-uploads/".
str_replace($wpuploadurl, "", $v), $row["post_content"]);
$post_sql =
sprintf("INSERT INTO articles (date, title, head, body, authors_id, allowanoncomments, active, public, last_modified, modified_by, categories_ids) VALUES (%d, '%s', '%s', '%s', %d, %d, 1, %d, %d, %d, '%s')",
$allow_anon_comment, $public, $last_modified, $_SESSION["author_id"], implode(",", $categories));
$r =
$GLOBALS["admin"]->db->query($post_sql);
Documentation generated on Fri, 28 Dec 2007 13:17:40 +0100 by phpDocumentor 1.4.1