Category Archives: CMS

Convert an old Scoop CMS to WordPress

I recently took on a project to move a site running on an old CMS called “Scoop” over to a new WordPress site. My original plan was to put the scoop site over on the new hosting site so that permalinks would forward past the wordpress site to the old site. I wouldn’t have to convert anything, and the new site would keep rolling. It turns out that the new hosting site does not support perl, which is the language of the Scoop CMS. Really… i had no idea what i was going to do so i started hunting…

I began looking at an extraction of the Scoop database given to me by Jeremy, who was awesome to work with (thanks Jeremy!).  I searched through wordpress and posted a couple of questions there (search for mpickell in the forum)… and their large list of importers/converters did not include one for this.  I did not get a lot of responses on my posts..   Long story short.. i wrote one in PHP and it is listed here — it works, i used it. I did edit it to make it prettier for this blog, let me know if something is not working right.

Since this was the first time i did something like this, and i was vaguely familiar with WordPress, I did not write an importer. This script extracts a Scoop CMS DB into a WordPress eXtended RSS (WXR) format ( a nice definition here ). So when you import this/these files, the importer to use is “WordPress”

A couple important notes:

  • You have to edit some variables at the beginning of this file to fill in your data.
  • There are two optional URL parameters (files and killAfter). Read the comments. Basically, you can split your export into multiple files so you have fewer problems ( see large import files and PHP.INI adjustments and here for memory issues. )
  • When you import split files, there is a problem with the 2nd, 3rd, 4th, etc. imports. You have to go through EVERY AUTHOR and select themseleves from the “or assign to existing user…” combo box. If you don’t, you LOSE the author link to every post — They all become “admin”. This is annoying. I posted to the wordpress forum and did not receive any response on this being an issue even when i mentioned the almost 500 authors i was working with… oh well, thank you jQuery
  • Turn on debugging. put the line define('WP_DEBUG', true); in your wp-config.php file. I think i read that there was more fine-grained debugging that could be enabled in the WordPress importer plugin code, but i didn’t end up needing that.
  • One last thing. You can fake the Scoop concept of “dairies” using a new user role and Pages. A new user role that enhances the “subscriber” role with the ability to create pages fits the need. I then added custom widgets to the site that automatically showed any new pages in reverse chronological order.

I think that’s it… i’ll update this post if I remember something i missed. I was going to write this in perl but i had trouble installing one of the modules for database access on my iMac. So i learned PHP, which i think turned out to be a much better decision anyway — although it leaves you with messy code, sorry.

<?php

/*
 *  I used MAMP as my testing system.  I received an extraction of the Scoop DB
 * in the form of an SQL file (i.e., create table statements, inserts, etc).  So I 
 * imported this into my local MySQL and worked on that copy of the data to create 
 * this script.
 *
 * I then used a local WordPress installation to test the imports
 */

// Don't allow a timeout... this is long!! 
ini_set('max_execution_time', 300); //300 seconds = 5 minutes

//Set up parameters
$mySqlUsername = "YourMySQLUsernameHere";
$mySqlPassword = "YourMySQLPasswordHere";
$mySqlHost = 'localhost';
$db_name = "YourScoopDatabaseNameHere!"; // This is the SCOOP DB name

// domain name you're switching to, as in "www.".$newDomainName.".com"
$newDomainName = 'mothertalkers'; 

print "Starting...";

/*
 * Attempt to get num of files from URL
 *
 * add something like "translate.php?files=10" to the URL to tell
 * this script how many different files to split the Scoop DB into.
 */
if (isset($_GET['files'])) {
  // This determines how to split the scoop stories into WXR import files
  $numOfWXRFilesToCreate = intval($_GET['files']);
} else {
  $numOfWXRFilesToCreate = 1;
}
print "files set ". isset($_GET['files']) . ", files is int " 
	. is_int($_GET['files']).", num is ".$_GET['files'];

// 
/*
 * If testing, kill after creating X number of files... 
 *
 * add something like "translate.php?killAfter=1" to the URL to tell
 * this script when to stop.. for when you are testing and don't want
 * to wait for the full extraction
 */
if (isset($_GET['killAfter'])) {
  // This determines how to split the scoop stories into WXR import files
  $killAfter = intval($_GET['killAfter']);
} else {
  $killAfter = -1;
}


print "Breaking scoop db into " . $numOfWXRFilesToCreate . " files.<br>";

// Open connection to MAMP mySql -- I used MAMP, this shouldn't matter.
// We need two connections for when we are pulling the posts and comments.
$dbConnection1 = mysql_connect($mySqlHost, $mySqlUsername, $mySqlPassword);
$dbConnection2 = mysql_connect($mySqlHost, $mySqlUsername, $mySqlPassword);

if (!$dbConnection1) {
    die('Not connected : ' . mysql_error($dbConnection1));
} else {
	print "Connection 1 to mysql is ok!<br>";
}
if (!$dbConnection2) {
    die('Not connected : ' . mysql_error($dbConnection2));
} else {
	print "Connection 2 to mysql is ok!<br>";
}


// Open connection to scoop database
$db_selected = mysql_select_db($db_name, $dbConnection1);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error($dbConnection1));
} else {
	print 'Connected to ' . $db_name . '!<br>';
}
$db_selected2 = mysql_select_db($db_name, $dbConnection2);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error($dbConnection2));
} else {
	print 'Connected to ' . $db_name . '!<br>';
}

// Prep for looping to create files
$count = getNumberOfScoopStories();
$postsPerFile = ((int) ($count / $numOfWXRFilesToCreate));
// $postsperFile count may leave a few stragglers at the end..
$remainderPosts = $count - ($postsPerFile * $numOfWXRFilesToCreate);

// increase posts per file by 1 if necessary to make sure we get everything
$postsPerFile += ($remainderPosts > 0) ? 1 : 0;
print "There will be " . $postsPerFile . " posts in each file.  The last will be smaller.<br>";

$loopVar = 0; // global so i don't have to rewrite all the writeToFile function calls.. multi-files was added late.

// count the processed posts... we might not need as many files.  
// This was for escaping early, as well as debug to make sure i got everything.
$processedPostsCount = 0;
$totalTagsWritten = 0;

// Loop to create separate files
for ($i=0; $i<$numOfWXRFilesToCreate; $i++) {
  if ($killAfter > 0 && $i >= $killAfter) {
    break; // quit now..
  }
  
  if ($processedPostsCount >= $count) {
    break; //quit early, we got everything (this doesn't happen anymore, i was counting incorrectly... )
  }
  
  
      $loopVar = $i;

      //start file -- always put the header
      writeToFile('<?xml version="1.0" encoding="UTF-8" ?>', 'w');
      writeToFile('<rss version="2.0"');
      writeToFile('xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"');
      writeToFile(	'xmlns:content="http://purl.org/rss/1.0/modules/content/"');
      writeToFile(	'xmlns:wfw="http://wellformedweb.org/CommentAPI/"');
      writeToFile(	'xmlns:dc="http://purl.org/dc/elements/1.1/"');
      writeToFile(	'xmlns:wp="http://wordpress.org/export/1.2/"');
      writeToFile('>');
      writeToFile('<channel>');
      writeToFile(	'<title>Mothertalkers test import</title>');
      writeToFile(	'<link>http://www.mothertalkers.com</link>');
      writeToFile(	'<description>a tagline</description>');
      writeToFile(	'<pubDate>Sat, 17 Mar 2012 23:22:58 +0000</pubDate>');
      writeToFile(	'<language>en</language>');
      writeToFile(	'<wp:wxr_version>1.2</wp:wxr_version>');
      writeToFile(	'<wp:base_site_url>http://mothertalkers.com/</wp:base_site_url>');
      writeToFile(	'<wp:base_blog_url>http://www.mothertalkers.com</wp:base_blog_url>');
      
      
	// These "output..." functions take a boolean left over from debugging

      /*****************************************************************
       *  FIRST, pull out all users who are authors
       *****************************************************************/
      outputAuthorXML();
      
      
      /*****************************************************************
       *  NEXT, Get the categories and tags
       *****************************************************************/
      outputTagsXML();
      
      
      /*****************************************************************
       *  NEXT, Add stories with comments
       *****************************************************************/
      outputStoriesXML(true, $i); // explicitly passed in so you know where it's used.
      
      // end file -- always put the closing tags
      writeToFile("\n\n" . "</channel> </rss>");

} // end of main loop

print $totalTagsWritten . " tags were written from this DB<br>";

print "<br><br>boo-yah!  done!";

/*****************************************************************
 *  Helper functions
 *****************************************************************/

// Get a count of the stories in the SCOOP DB
function getNumberOfScoopStories() {
  global $dbConnection1;

  $returnVal = -1;

	// This WHERE clause must match the where clause in outputStoriesXML!
    $query = 'Select count(*) as count from stories WHERE displaystatus in (0,1)';
    
    $result = mysql_query($query,$dbConnection1);
    if (!$result) {
        $message  = 'Invalid COUNT query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole COUNT query: ' . $query;
        die($message);
      }
    
    // output the tags
    while ($row = mysql_fetch_assoc($result)) {
      $returnVal = $row['count'];
    }
    mysql_free_result($result);
    
    print "Scoop DB contains " . $returnVal . " posts!";

  return $returnVal;
}

/* 
 * This takes a string and makes it a nicename to match
 * how scoop did it.  (this was tested.. )
 *
 * (Jeremy @ dailykos gave me the way "scoop" does it in perl so i could match it here)
 */
function makeScoopStyleNiceName($text, $useLeadingDash = true, $sanitize = true)
{
  // build patterns
  $patterns = array("/ /", "/&(.*?);/", "/\?/", '/\"/', "/=/", "/&/", "/%/", "/-{2,}/", "/~/", "/\//");
  $replacements = array("-", "", "", "", "", "", "", "", "", "-");

  $var = preg_replace($patterns, $replacements, $text);
  
  if ($sanitize) {
      return ($useLeadingDash ? '-' : '') . urlencode($var);
    } else {
      return ($useLeadingDash ? '-' : '') . $var;
    }
}

/*
 * Extract the authors... i left in the comments from wherever i 
 * copied this from... 
 */
function outputAuthorXML($showAuthorOutput = true) {
  global $dbConnection1, $dbConnection2;
  // Formulate Query
    // This is the best way to perform an SQL query
    // For more examples, see mysql_real_escape_string()
    /*
    EXAMPLE
    $query = sprintf("SELECT firstname, lastname, address, age FROM friends 
    WHERE firstname='%s' AND lastname='%s'",
    mysql_real_escape_string($firstname),
        mysql_real_escape_string($lastname));
    */
    
    // only pull users who have stories... 
    $query = "Select distinct uid, nickname from users where uid in (select distinct aid from stories)";
    // Perform Query
    $result = mysql_query($query, $dbConnection1);
    // This shows the actual query sent to MySQL, and the error. Useful for debugging.
    if (!$result) {
        $message  = 'Invalid AUTHORS query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole AUTHORS query: ' . $query;
        die($message);
      }
    // Use result
    // Attempting to print $result won't allow access to information in the resource
    // One of the mysql result functions must be used
    // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
    while ($row = mysql_fetch_assoc($result)) {
        $newNickName = changeNickName($row['nickname']);
        
        $output = "<wp:author><wp:author_id>".$row['uid']."</wp:author_id><wp:author_login>".$newNickName."</wp:author_login><wp:author_email></wp:author_email><wp:author_display_name>".wxr_cdata($newNickName)."</wp:author_display_name><wp:author_first_name>".wxr_cdata($newNickName)."</wp:author_first_name><wp:author_last_name>".wxr_cdata(" ")."</wp:author_last_name></wp:author>";
        if ($showAuthorOutput) {
          //echo htmlspecialchars($output, ENT_QUOTES);
          //echo "<br>";
          writeToFile($output);
        }
     
    }
    // Free the resources associated with the result set
    // This is done automatically at the end of the script
    mysql_free_result($result);
}

function outputTagsXML($showCategoriesAndTagsOutput = true) {
  global $dbConnection1, $dbConnection2;

  // pull tags.  Scoop doesn't have categories, so all tags will be from 'uncategorized'
    $query = "Select distinct tag from story_tags";
    $result = mysql_query($query,$dbConnection1);
    if (!$result) {
        $message  = 'Invalid CAT/TAGS query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole CAT/TAGS query: ' . $query;
        die($message);
      }
    
    // Print out the category
    if ($showCategoriesAndTagsOutput) {
      $output = "<wp:category><wp:term_id>1</wp:term_id><wp:category_nicename>uncategorized</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name>".wxr_cdata("Uncategorized")."</wp:cat_name></wp:category>";
      //echo htmlspecialchars($output, ENT_QUOTES);
      writeToFile($output);
    }
    
    // output the tags
    while ($row = mysql_fetch_assoc($result)) {
        $tag = $row['tag'];
        $niceTag = makeScoopStyleNiceName($tag, false);
        
        $output = "<wp:tag><wp:tag_slug>".$niceTag."</wp:tag_slug><wp:tag_name>".wxr_cdata($tag)."</wp:tag_name></wp:tag>";
        if ($showCategoriesAndTagsOutput) {
          //echo htmlspecialchars($output, ENT_QUOTES);
          //echo "<br>";
          writeToFile($output);
        }
     
    }
    // Free the resources associated with the result set
    // This is done automatically at the end of the script
    mysql_free_result($result);
 
}

function outputStoriesXML($showStoriesOutput = true, $loopVar) {
  global $dbConnection1, $dbConnection2, $postsPerFile, $processedPostsCount, $numOfWXRFilesToCreate, $newDomainName;
  // pull tags.  Scoop doesn't have categories, so all tags will be from 'uncategorized'
    $query = 'Select s.title, s.sid, s.dsid, s.id, UNIX_TIMESTAMP(s.time) as time, u.nickname, s.aid, s.introtext, s.bodytext, s.commentstatus FROM stories s, users u ' .
             'WHERE u.uid=s.aid AND s.displaystatus in (0,1) '.
             'LIMIT ' . ($postsPerFile * $loopVar) . ', ' . $postsPerFile;//((($numOfWXRFilesToCreate-1) == $loopVar) ? '' : ', ' . $postsPerFile);
    
    $result = mysql_query($query,$dbConnection1);
    if (!$result) {
        $message  = 'Invalid STORIES query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole STORIES query: ' . $query;
        die($message);
      }
    
    // output the tags
    $postsInThisFile = 0;
    while ($row = mysql_fetch_assoc($result)) {
      $processedPostsCount++; 
      $postsInThisFile++;
      
      // Get the dates for the posts
      //ex: Wed, 07 Jan 2009 17:30:08 +0000
      $publishDate = date("D, d M Y H:i:s O", $row['time']);
      //ex: 2009-01-07 17:30:08
      $postDate_gmt = date("Y-m-d H:i:s", $row['time']);
      
      
      $sidSplit = preg_split("/\//", $row['sid'], -1, PREG_SPLIT_OFFSET_CAPTURE);
      $link = "http://www.".$newDomainName.".com/story/".$sidSplit[0][0]."/".$sidSplit[1][0]."/".$sidSplit[2][0]."/".$row['id']."/" . makeScoopStyleNiceName($row['title']);
      //echo $link . "<br>";
      
        writeToFile( '	<item>' .
                      '<title>'.fixOldHtmlCodes($row['title']).'</title>' .
                      '<link>'.$link.'</link>' .
                      '<pubDate>'.$publishDate.'</pubDate>' .
                      '<dc:creator>'.changeNickName($row['nickname']).'</dc:creator>' .
                      '<guid isPermaLink="false">'.$link.'</guid>' .
                      '<description></description>' .
                      '<content:encoded>'.wxr_cdata($row['introtext'] . (IsNullOrEmptyString($row['bodytext']) ? '' : '<br/>') .$row['bodytext']).'</content:encoded>' .
                      '<excerpt:encoded>'.wxr_cdata(" ").'</excerpt:encoded>' .
                      '<wp:post_id>'.$row['id'] .'</wp:post_id>' .
                      '<wp:post_date>'.$postDate_gmt.'</wp:post_date>' .
                      '<wp:post_date_gmt>'.$postDate_gmt.'</wp:post_date_gmt>' .
                      '<wp:comment_status>'.($row['commentstatus'] == 0 ? 'open' : 'closed').'</wp:comment_status>' .
                      '<wp:ping_status>open</wp:ping_status>' .
                      '<wp:post_name>'.makeScoopStyleNiceName($row['title']).'</wp:post_name>' .
                      '<wp:status>publish</wp:status>' . // because we're only bringing in published stories
                      '<wp:post_parent>0</wp:post_parent>' .
                      '<wp:menu_order>0</wp:menu_order>' .
                      '<wp:post_type>post</wp:post_type>' .
                      '<wp:post_password></wp:post_password>' .
                      '<wp:is_sticky>0</wp:is_sticky>' .
                      '<category domain="category" nicename="uncategorized">'.wxr_cdata("Uncategorized").'</category>');
            insertTags($row['sid'], $row['id']);
            writeToFile('<wp:postmeta>' .
                      '  <wp:meta_key>_edit_last</wp:meta_key>' .
                      '  <wp:meta_value>'.wxr_cdata($row['aid']).'</wp:meta_value>' .
                      '</wp:postmeta>' );
            insertComments($row['id']) ;
            writeToFile('</item>');
        if ($showStoriesOutput) {
          //echo htmlspecialchars($output, ENT_QUOTES);
          //echo "<br>";
          //writeToFile($output . "\r");
        }
    }
    // Free the resources associated with the result set
    // This is done automatically at the end of the script
    mysql_free_result($result);
    
    print $postsInThisFile . " posts added to file " . ($loopVar + 1) . "<br>";
}

function insertTags($story_sid, $id) {
  global $dbConnection1, $totalTagsWritten;
    // Get tags for this story.
    $query = 'Select tag FROM story_tags where sid=\''.$story_sid.'\' order by tag_order';
    //print $query . "<br>";
    
    $result = mysql_query($query,$dbConnection1);
    if (!$result) {
        $message  = 'Invalid STORY TAGS query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole STORY TAGS query: ' . $query;
        die($message);
      }
    
    // output the tags
    while ($row = mysql_fetch_assoc($result)) {
      //print "Writing tag " . $row['tag'] . " for id " . $id . "<br>";
      $totalTagsWritten++;
      writeToFile( '<category domain="post_tag" nicename="'.makeScoopStyleNiceName($row['tag'], false).'">'.wxr_cdata($row['tag']).'</category>' );
    
    }
    // Free the resources associated with the result set
    // This is done automatically at the end of the script
    mysql_free_result($result);
}


function insertComments($story_id) {
  global $dbConnection1, $dbConnection2;
    // pull tags.  Scoop doesn't have categories, so all tags will be from 'uncategorized'
    $query = 'Select c.id, c.uid, u.nickname, c.commentip as ip, UNIX_TIMESTAMP(c.date) as date, c.subject, c.comment, c.pending, c.pid FROM comments c, users u ' .
             ' WHERE c.story_id='.$story_id.
             ' AND c.uid=u.uid';
    
    $result = mysql_query($query,$dbConnection1);
    if (!$result) {
        $message  = 'Invalid COMMENTS query: ' . mysql_error($dbConnection1) . "\r";
        $message .= 'Whole COMMENTS query: ' . $query;
        die($message);
      }
    
    // output the tags
    while ($row = mysql_fetch_assoc($result)) {
      
      //ex: 2009-01-07 17:30:08
      $commentDate_gmt = date("Y-m-d H:i:s", $row['date']);
      
      writeToFile( '<wp:comment>'.
      '   <wp:comment_id>'.$row['id'].'</wp:comment_id>'.
      '   <wp:comment_author>'.($row['id'] == -1 ? 'anonymous' : wxr_cdata(changeNickName($row['nickname']))).'</wp:comment_author>'.
      '   <wp:comment_author_email></wp:comment_author_email>'.
      '   <wp:comment_author_url></wp:comment_author_url>'.
      '   <wp:comment_author_IP>'.$row['ip'].'</wp:comment_author_IP>'.
      '   <wp:comment_date>'.$commentDate_gmt.'</wp:comment_date>'.
      '   <wp:comment_date_gmt>'.$commentDate_gmt.'</wp:comment_date_gmt>'.
      '   <wp:comment_date>'.$commentDate_gmt.'</wp:comment_date>'.
      '   <wp:comment_date_gmt>'.$commentDate_gmt.'</wp:comment_date_gmt>'.
      '   <wp:comment_content>'.wxr_cdata('<b>'.$row['subject'] . '</b><br/><br/>' .$row['comment']).'</wp:comment_content>'.
      '   <wp:comment_approved>'.($row['pending'] == 0 ? '1' : '0').'</wp:comment_approved>'.
			'   <wp:comment_type></wp:comment_type>');
              // Subquery to figure out parents
              $query2 = 'Select id FROM comments ' .
                        ' WHERE story_id='.$story_id.
                        ' AND cid='.$row['pid'];
              
              $parentComment = mysql_query($query2,$dbConnection2);
              if (!$parentComment) {
                $message  = 'Invalid Parent Comment query: ' . mysql_error($dbConnection2) . "\r";
                $message .= 'Whole Parent Comment query: ' . $query2;
                die($message);
              }
              
              // output the tags
              $foundParent = false;
              while ($parentCommentRow = mysql_fetch_assoc($parentComment)) {
                writeToFile( '   <wp:comment_parent>'.$parentCommentRow['id'].'</wp:comment_parent>');
                $foundParent=true;
                break;//there can be only one!  but just in case... 
              }
              if (!$foundParent) {
                writeToFile( '   <wp:comment_parent>0</wp:comment_parent>');
              }
              mysql_free_result($parentComment);
			writeToFile( '   <wp:comment_user_id>'.($row['uid'] == -1 ? '0' : $row['uid']).'</wp:comment_user_id>');
      writeToFile( '</wp:comment>');
    }
    // Free the resources associated with the result set
    // This is done automatically at the end of the script
    mysql_free_result($result);
}

/*
 * This is important... WordPress's import tool crapped out on me 
 * when it hit characters it couldn't handle... like control chars,
 * which took me a long time to figure out.. 
 */
function fixOldHtmlCodes($str) {
    // build patterns
    $patterns = array("/[&]rsquo[;]/", "/[&]ldquo[;]/", "/[&]rdquo[;]/", "/[&]mdash[;]/", "/&(?!(?i:\#((x([\dA-F]){1,5})|(104857[0-5]|10485[0-6]\d|1048[0-4]\d\d|104[0-7]\d{3}|10[0-3]\d{4}|0?\d{1,6}))|([A-Za-z\d.]{2,31}));)/" );
  $replacements = array("&#x2019;", "&#x201C;", "&#x201C;", "&#x2014;", "&amp;" ); // These are &amps; that are not part of an html code group
  
  array_push($patterns, "/[&][#]8220[;]/", "/[&][#]8221[;]/", "/[&][#]8217[;]/", "/[&][#]8212[;]/");
  array_push($replacements, "&#x201C;", "&#x201C;", "&#x2019;", "&#x2014;");

  return preg_replace($patterns, $replacements, $str);
}

function writeToFile($text, $writeOrAppend = 'a') {
  global $loopVar, $numOfWXRFilesToCreate;

  $myFile = "wordpress_import_".($loopVar + 1)."_of_".$numOfWXRFilesToCreate.".xml";
  $fh = fopen($myFile, $writeOrAppend) or die("can't open file");
  fwrite($fh, utf8_encode ( $text . "\n") );
  fclose($fh);
}

// From WordPress... not sure i need it.  I was having issues with CDATA and this is 
// EXACTLY (even the function name) of the code used in WordPress.  I added my own
// filtering to it, but the CDATA line is theirs.
function wxr_cdata( $str ) {
    $str = fixOldHtmlCodes($str); 
    $str = preg_replace('/[\x00-\x1F\x7F]/', '', $str);

		$str = utf8_encode( $str );

		// $str = ent2ncr(esc_html($str));
		$str = "<![CDATA[$str" . ( ( substr( $str, -1 ) == ']' ) ? ' ' : '' ) . ']]>';

		return $str;
	}
  
/* 
 * Change all authors to have a suffix so they
 * do not cause problems for people who want the same
 * name in the new system.  
 *
 * You can get rid of the suffix if you don't have a 
 * huge number of authors... you just have to change
 * each one's password, i think... i didn't do that.
 */
function changeNickName($name) {
  return $name . '_scoop';    
}

// Function for basic field validation (present and neither empty nor only white space
function IsNullOrEmptyString($question){
    return (!isset($question) || trim($question)==='');
}


  
?>
Share

Fixing authors when importing a split WXR file for WordPress

If you have a large WordPress Extended RSS import file, WordPress suggests that you split the file in order to create multiple smaller files.  If you do this, then each file will have the same authors.  If you import the second file, third, fourth, etc… then those authors will be seen as duplicates and dropped (and all imported posts will be credited to ‘admin’) unless you go through each author and select them in the “or assign this post to existing author” combo boxes.   These combo boxes become available after you select a file and press “Import.”

If you are importing multiple files because a single one is too big, there is a chance you could have way too many authors to go through each one and do this.  This post describes a hack method of populating all of these combo boxes using jQuery and the browsers development tools.

I had to import 6 WXR files that i created, each one around 80Megs, and a total of almost 500 authors.

1) Get jQueryify here and add the bookmarklet per the instructions.

2) When you get to the “assign authors” page, right-click on the browser page and select “Inspect Element” (Chrome), or “Inspect with Firebug” in Firefox (install firebug if you haven’t already). In IE press F12 to start the Dev Tools.

3) Press the jQuerify bookmarklet button that you installed from step 1. This will turn on jQuery for the page.

4) Go to the console tab, enable the console if you need to, paste this code in and press RUN:

jQuery.noConflict(); //Disable jQuery $ just incase.

jQuery('#authors li').each(function() {
  // Get the author login text
  var username = jQuery(this).find('strong').html();
  var author_login = jQuery.trim((username.split('('))[0]);

  //Figure out which option this author is in the drop down.
  var selectOptionval = -1;
  jQuery(this).find('select option').each(function(){
    if (jQuery(this).html() === author_login) {
      selectOptionval = jQuery(this).val();
      return false;//quit .each() early.
    }
  });

  // Set the combo box to this author's option key.
  jQuery(this).find('select').val(selectOptionval);

  // For test...
  //console.log(author_login + ": " + selectOptionval);
});
Share