Howdy! This importer allows you to extract posts from web-log.nl XML
back-ups into your blog.
Warning: this script has barely been tested. It worked for me.
I hope it works for you too. If it doesn't and you lose data--well, that
wasn't very smart now, was it?
The following tags are supported:
XML:
<log></log>
<datum></datum>
<tekst></tekst>
<titel></titel>
BBstyle:
[b][/b]
[center][/center]
[i][/i]
[img=left][/img]
[img=right][/img]
[localurl][/localurl]
[localurl=http://www.example.com][/localurl]
[url][/url]
[url=http://www.example.com][/url]
(This is actually a bit less than the (BB-style) tags that web-log.nl
supports, so if you need the extra BB-style tags, I suggest you extend
this script.)
What's more, the back-up tool of web-log.nl does not export comments
and categories!
First, you must create a back-up of your web-log.nl log
entries. You do this at the Beheer (management) pages under Logs / Backup.
Create a back-up, and copy the resulting .xml file to a location on the
webserver that contains your Wordpress installation.
Second, you must edit the following line in this file
(import-web-log_nl.php
)
define('WEBLOGNLFILE', '');
You want to define where the RSS file we'll be working with is, for example:
define('WEBLOGNLFILE', 'logs.xml');
You have to do this manually for security reasons. When you're done reload
this page and we'll take you to the next step.
(.*?)|is', $importdata, $posts);
$posts = $posts[1];
echo '';
foreach ($posts as $post) :
$title = $date = $categories = $content = $post_id = '';
echo "- Importing post... ";
preg_match('|(.*?)|is', $post, $title);
$title = str_replace( array(''), '', addslashes( trim($title[1]) ) );;
$post_name = sanitize_title($title);
preg_match('|(.*?)|is', $post, $date);
$eurodate = preg_replace('/([0-9]+)-([0-9]+)-([0-9]+)/','$3-$2-$1',$date[1]);
$date = strtotime($eurodate);
if (!$date) : // if we don't already have something from pubDate
preg_match('|(.*?)|is', $post, $date);
$date = preg_replace('|(-[0-9:]+)$|', '', $date[1]);
$date = strtotime($date);
endif;
$post_date = gmdate('Y-m-d H:i:s', $date);
preg_match('|(.*?)|is', $post, $content);
$content = str_replace( array(''), '', addslashes( trim($content[1]) ) );
// Convert double newlines to paragraphs
/* stolen from the functions.php file */
$pee = $content . "\n"; // just to make things a little easier, pad the end
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "
$1
\n\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|\s*?
|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
// Convert single newlines to linebreaks
$pee = preg_replace('/([^\n])(\n)([^\n])/', '$1$2
$3', $pee);
// Convert (some) BB-style tags
$pee = str_replace("[b]", "", $pee);
$pee = str_replace("[/b]", "", $pee);
$pee = str_replace("[i]", "", $pee);
$pee = str_replace("[/i]", "", $pee);
$pee = str_replace("[center]", "", $pee);
$pee = str_replace("[/center]", "
", $pee);
$pee = preg_replace('/\[img\]([^[]+)\[\/img\]/','
',$pee);
$pee = preg_replace('/\[img=([a-z]+)\]([^[]+)\[\/img\]/','
',$pee);
$pee = preg_replace('/\[url\]([^[]+)\[\/url\]/','$1',$pee);
$pee = preg_replace('/\[url=([^\]]+)\]([^[]+)\[\/url\]/','$2',$pee);
$pee = preg_replace('/\[localurl\]([^[]+)\[\/localurl\]/','$1',$pee);
$pee = preg_replace('/\[localurl=([^\]]+)\]([^[]+)\[\/localurl\]/','$2',$pee);
$content = balanceTags($pee);
// Clean up content
$content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $content);
$content = str_replace('
', '
', $content);
$content = str_replace('
', '
', $content);
// This can mess up on posts with no titles, but checking content is much slower
// So we do it as a last resort
if ('' == $title) :
$dupe = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_content = '$content' AND post_date = '$post_date'");
else :
$dupe = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$title' AND post_date = '$post_date'");
endif;
// Now lets put it in the DB
if ($dupe) :
echo 'Post already imported';
else :
$wpdb->query("INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title,post_status, comment_status, ping_status, post_name) VALUES ('$post_author', '$post_date', DATE_ADD('$post_date', INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE), '$content', '$title', 'publish', '$comment_status', '$ping_status', '$post_name')");
$post_id = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$title' AND post_date = '$post_date'");
if (!$post_id) die("couldn't get post ID");
echo 'Done! ';
$exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_id AND category_id = 1");
if (!$exists) $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_id, 1) ");
endif;
endforeach;
?>