Cutenews to WordPress Conversion

cutenews-logo

In my search to convert the flat file format of Cutenews over to the database driven WordPress, I came across a plugin that someone was creating.  This news transfer tool is called Other-Ext-WP.

I was pretty excited to find it, as I want to move two of my websites off of Cutenews and into the more secure database driven format.  It worked okay when I tried it out to see what it would do.  It did pull in the stories as well as some of the categories and the dates.

wordpress-logoHowever, there are a number of issues with the importing, however, that have been reported by others as well.

1) The Categories don’t transfer correctly.

2) The Full Story doesn’t transfer, just the short story field.

3) You can only attribute the stories to one user.

4) It strips out all mark-up.  In both stories and comments.

I’m not too worried about moving the uploaded pictures over, as that can be fixed later.  But I would love to have a working script to run that will properly convert things.

The latest WordPress version that the creator says that it works in is 2.3.1, so I tried that to see if it worked, and that’s where the issues came in.  The person developing it appears to have given up on the plugin, so I’m asking for anyone that has some spare time to help out if you can.


<?php
/*
Plugin Name: Other-Ext-WP
Plugin URI: http://www.nexterous.com/scripts/otherextwp.php
Description: This useful plugin allows Cutenews users to transfer their Cutenews installation into WordPress, including categories, posts, and comments.
Version: 1.0 Beta 2
Author: Daniel
Author URI: http://www.nexterous.com
*/

/*  Copyright 2007  Daniel  (contact: use form at www.nexterous.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

// Hook for adding admin menus
add_action(‘admin_menu’, ‘display’);

// Add the page first
function display(){
add_submenu_page(‘plugins.php’, ‘Other-Ext-WP’, ‘Other-Ext-WP’, 10, ‘extwp.php’, ‘display_options’);
}

// Function to control what is displayed or activated
function display_options(){
if(isset($_POST[‘submit’])){

// Start the functions of the transfer
// Begin to set all the variables: $option, $path
if($_POST[‘add_comments’] == ‘yes’){
$option = TRUE;
} else {
$option = FALSE;
}
if(empty($_POST[‘path’]) OR ($_POST[‘path’] == ‘enter a different path’)){
$path = $_POST[‘pathorigin’];
} else {
$path = $_POST[‘path’];
}

// Check the path & report error if not correct
$dp = opendir($path);
while($file = readdir($dp)){
$filearray[] = $file;
}
closedir($dp);
$checklist = array(
1 => ‘data’,
2 => ‘inc’,
3 => ‘rte’,
4 => ‘skins’);
$checkarray = array_intersect($filearray, $checklist);
if(empty($checkarray)){
?>
<div class=”wrap”>
<h2>Error</h2>
<p>Are you sure you have the correct Cutenews path? Please go <a href=”plugins.php?page=extwp.php”>back</a> and try a different path.</p>
</div>
<?php
exit;
}
$path = $path . ‘/data/’;

// Clear all the categories before beginning
$result = mysql_query(“TRUNCATE TABLE `wp_terms`”);
$result = mysql_query(“TRUNCATE TABLE `wp_term_taxonomy`”);

// Define all functions necessary
// Read the file and retrieve the each line into a separate row in an array
function read_cn($file){
$fp = fopen($file, ‘r’);
$read_array = file($file);
fclose($fp);
return $read_array;
}

// Take each row and explode it into another array and return back to a master array of all values
function return_entry($read_array){
foreach($read_array as $key => $data){
if($data == ”){
continue;
}
$array[$key] = explode(‘|’, strip_tags($data));
}
return $array;
}

// Get the information from each row and send it to the database using the post_wp() function
function send_post($array){
define(‘CONSTANT’, 18061);
foreach($array as $key => $data){
list($date, , $title, $post, , , $categories) = $data;
$title = mysql_real_escape_string($title);
$post = mysql_real_escape_string($post);

// Convert Date
$date = $date + CONSTANT;
$date = date(‘Y-m-d H:i:s’, $date);

// Separate Categories
$categories = explode(‘,’, $categories);

// Set-Up Post
$user = $_POST[‘user’];
$post = array(
‘post_author’        => $user,
‘post_date’            => $date,
‘post_date_gmt’        => $date,
‘post_title’        => $title,
‘post_content’        => $post,
‘post_status’        => ‘publish’,
‘post_type’            => ‘post’,
‘post_category’        => $categories);

// Send the post
wp_insert_post($post);
}
}

// Add category to the database
function add_category($category){
$cat_edited = mysql_real_escape_string(trim(strtolower($category)));
GLOBAL $table_prefix;
$terms = $table_prefix . ‘terms’;
$term_tax = $table_prefix . ‘term_taxonomy’;
$query = “INSERT INTO `$terms` (`name`, `slug`) VALUES (‘$cat_edited’, ‘$cat_edited’)”;
$result = mysql_query($query);
$id = mysql_insert_id();
$queryrel = “INSERT INTO `$term_tax` (`term_id`, `taxonomy`) VALUES (‘$id’, ‘category’)”;
$resultrel = mysql_query($queryrel);
}

// Set all the new categories
$url = $path . ‘category.db.php’;
$categories = read_cn($url);
$categories = return_entry($categories);
foreach($categories as $key => $category){
$category = $category[1];
if($category == ”){
continue;
}
add_category($category);
}

// Set all the posts
$url = $path . ‘archives/’;
$dp = opendir($url);
while($dirarray = readdir($dp)){
if($dirarray == ‘.’ OR $dirarray == ‘..’){
continue;
} else if(eregi(‘(comments){1}|(index){1}’, $dirarray)){
continue;
} else {
$url2 = $url . $dirarray;
$array = read_cn($url2);
$array = return_entry($array);
$result = send_post($array);
}
}
closedir($dp);
$url = $path . ‘news.txt’;
$array = read_cn($url);
$array = return_entry($array);
$result = send_post($array);

if($option){ // Check for comment option

// New Feature as of v.1.0 Beta 2: Transferring comments
// New functions must be defined due to the nature of the comment set-up on Cutenews
// These functions are only defined and used if you select “yes” on the comments option

// Get all the comments and format them correctly
function cn_getcomments($file){
$array = array();
$rawarray = file($file);
foreach($rawarray as $key => $data){
$blogtime = substr($data, 0, 13);
$data = substr(strip_tags($data), 13);
$comments = explode(‘||’, $data);
foreach($comments as $key => $comment){
if(md5($comments[$key]) == ‘81051bcc2cf1bedf378224b0a93e2877’){
// This checks for a blank comment; cannot use empty() because of the way comment is formatted
continue;
}
$array[] = $comment . ‘|’ . $blogtime;
}
}
return $array;
}
function cn_addcomments($array){
foreach($array as $key => $comment){
$newarray = explode(‘|’, $comment);
list($date, $author, $email, $ip, $comment, $blogtime) = $newarray;
if(empty($comment) OR $comment == ‘81051bcc2cf1bedf378224b0a93e2877’){
// This checks for a blank comment; cannot use empty() because of the way comment is formatted
continue;
}
$author = mysql_real_escape_string($author);
$email = mysql_real_escape_string($email);
$comment = mysql_real_escape_string($comment);

// Try quick spam protection – sets most of them to need approval
if(eregi(‘(http://)|www|(?p=)|(?pid=)’, $comment)){
$status = 0;
} else {
$status = 1;
}

// Convert Date
define(‘CONSTANT’, 18061);
$date = $date + CONSTANT;
$date = date(‘Y-m-d H:i:s’, $date);
$blogtime = $blogtime + CONSTANT;
$blogtime = date(‘Y-m-d H:i:s’, $blogtime);

// Change Email
if($email == ‘none’){
$email = ”;
}

// Check Entry
GLOBAL $table_prefix;
$wp_posts = $table_prefix . ‘posts’;
$result = mysql_query(“SELECT `ID` FROM `$wp_posts` WHERE (`post_date` = ‘$blogtime’)”);
while($array = mysql_fetch_array($result)){
$postid = $array[‘ID’];
}

// Set-Up Comment
$comment = array(
‘comment_post_ID’ =>        $postid,
‘comment_author’ =>         $author,
‘comment_author_email’ =>     $email,
‘comment_author_url’ =>     ”,
‘comment_author_IP’ =>        $ip,
‘comment_date’ =>            $date,
‘comment_date_gmt’ =>        $date,
‘comment_content’ =>        $comment,
‘comment_approved’ =>        $status,
‘comment_agent’ =>             ”,
‘comment_type’ =>            ”);

wp_insert_comment($comment);
}
}
$url = $path . ‘archives/’;
$dp = opendir($url);
while($dirarray = readdir($dp)){
if($dirarray == ‘.’ OR $dirarray == ‘..’){
continue;
} else if(eregi(‘(news){1}|(index){1}’, $dirarray)){
continue;
} else {
$url2 = $url . $dirarray;
$array = cn_getcomments($url2);
$array = cn_addcomments($array);
}
}
closedir($dp);
$url = $path . ‘comments.txt’;
$array = cn_getcomments($url);
$array = cn_addcomments($array);
}

?>
<div class=”wrap”>
<h2>Congradulations!</h2>
<p>You have now finished converting your Cutenews installtation into WordPress. Don’t forget to delete this plugin now since it has no security besides basic plugins. For more scripts and goodies, check out <a href=”http://www.nexterous.com”>Nexterous.com</a>.</p>
</div>
<?
// Start the functions of the application
} else {
?>
<div class=”wrap”>
<h2>Other-Ext-WP</h2>
<p>Other-Ext-WP is a WordPress plugin that allows the user to transfer there Cutenews installation into WordPress. It supports categories, blog entries, and comments. To set up the transfer, check the options below. Please see the <a href=”http://www.nexterous.com/scripts/otherextwp.php”>instructions and help</a> before beginning. </p>
<h2>Notes</h2>
<p>This plugin takes a while depending on the number of posts and comments (if you select it) you have on your Cutenews installation. This plugin is recommended for use on a fresh installation of WordPress. It does wipe all the categories when it begins the transfer. Also, this script automatically files any comments with a link into moderation because most spam originates from that. </p>
<h2>Begin…</h2>
<p>Select the options that you would like to apply to the transfer. Please also make sure that all the configurations are correct. <br />
<em>Note</em>: This plugin automatically detects the path if it can find it. If not, it will present an input box. After you click “transfer”, it will check the path for certain directories to make sure you have the correct path.<br />
<em>Warning</em>: If you click the transfer button, the process will begin. </p>
<br /><br />
<form action=”plugins.php?page=extwp.php” method=”post” id=”searchform”>
<fieldset>
<legend>Add Comments?</legend>
<select name=”add_comments”>
<option selected=”selected” value=’yes’>Yes – Add All Comments</option>
<option value=’no’>No – Do Not Add Comments</option>
</select>
</fieldset>
<fieldset>
<legend>Select User for all Posts</legend>
<select name=”user”>
<?php
GLOBAL $table_prefix;
$table = $table_prefix . ‘usermeta’;
$result = mysql_query(“SELECT `user_id`, `meta_value` FROM $table WHERE (`meta_key` = ‘nickname’)”);
while($array = mysql_fetch_array($result)){
$id = $array[‘user_id’];
$nick = $array[‘meta_value’];
$combo = $id . ‘ – ‘ . $nick;
print “<option value=’$id’>&nbsp; &nbsp; &nbsp; &nbsp; $combo &nbsp; &nbsp; &nbsp; &nbsp; </option>”;
}
?>
</select>
</fieldset>
<fieldset>
<legend>Path to Cutenews</legend>
<?php
$path = ‘../../’;
$dp = opendir($path);
while($file = readdir($dp)){
if(eregi(‘^(cutenews)$’, $file)){
$path = $path . $file;
echo $path . ‘&nbsp; &nbsp; &nbsp; &nbsp; OR &nbsp; &nbsp; &nbsp; &nbsp;’;
print ‘<input type=”text” name=”path” value=”enter a different path” />’;
print “<input type=’hidden’ name=’pathorigin’ value=’$path’ />”;
$lock = TRUE;
break;
}
}
if($lock != TRUE){
print ‘<input type=”text” name=”path” value=”enter the path to cutenews (where ../ is one directory up)” style=”width: 400px;” />’;
}
?>
</fieldset>
<fieldset>
<legend>Click to start!</legend>
<input type=”submit” name=”submit” id=”submit” value=”Start Transfer” class=”button” />
</fieldset>
</form>
<br style=”clear:both;” />
</div>
<?php
}
}
?>
I have also found the blog of a man named Mark that was able to pull all the cutenews data with MySQL queries.  I’m not sure how it works just yet, but you can find it here: Migrating from Cutenews to WordPress

Resources:

Plugin Other-Ext-WP Plugin
Wordpress 2.3.1: zip | tar.gz | md5
Cutenews 1.4.6: Cutephp

13 thoughts on “Cutenews to WordPress Conversion”

  1. Well, I guess with ‘Mark’ you have me in mind. ^^ I have experienced many converters to be either buggy or written for already obsolete versions of either blog engine. But migrating isn’t as complicated as it might seem.

    If you have difficulties following my instructions drop me a line (or launch Jabber/Google talk and find me by my email). I’d be happy to help you, and can maybe enrich my instructions.

    1. Wow, thanks Mark! I’ll let you know how it goes when I run your scripts. For whatever reason, I wasn’t expecting a response from you. haha

    1. I didn’t check to see. If not, that stinks, and perhaps someone will come up with something.

  2. I have 2.8.2 and it worked – I had to clean up some categories but other than that it worked like a charm!

    THANK YOU.

  3. unfortunately, no! it didn’t convert long story, images and some special characters like šđčćž are mising.
    did you have more luck then me?

    1. I’ve been meaning to write an update to this with another path. I went from Cutenews to Flatpress to WordPress.

  4. hi !

    worked great for me with the last version of wordpress except that it didn’t transfert all the news, maybe because there were too much ? about 1000 and it transfered 300 of them.

    1. Good question. I haven’t tested it for any sites with that many posts. Perhaps there was a problem in the code with the story that it stopped at. That happened to me once.

  5. Does someone have a converter to the CuteNews.ru CMS?

    This is based on cutenews, but is stores it in the MYSQL db

    Thanks!

  6. Hi guys, i loved cutenews UTF8 mod for its simplicity and modded it pretty heavy as you can see at site in my sgi , but unfortunately it still very limited and not well written from beginning, im tired to do everything from scratch if i need to add some feature… also comments db was to easy to broke (so once and since my was broken i replaced comments by discus and still trying to restore old broken db with interesting discussions in comments) so i decided today to move from CNUTF8 to WP 3.21 but it seems that conversion would not be so easy. Can you guys update your scripts to let them work with CN UTF8 v8 and v9 and WordPress 3.2.1 ?

Leave a Reply