SPHPBlog to Wordpress migration script by Miguel Herrero

Migration in progress... (please wait)

",$text); $text = str_replace("[/b]","",$text); $text = str_replace("[/i]","",$text); $text = str_replace("[i]","",$text); $text = str_replace("[url=","",$text); $text = str_replace("[","<",$text); $text = str_replace("]",">",$text); //$text = ereg_replace(".*","",$text); $text = str_replace("",'">',$text); $text = htmlspecialchars_decode($text); $text = utf8_encode($text); return $text; } // MAIN PROGRAM /////////////////////////////// // We load all the labels chdir("config"); $cat = file_get_contents("categories.txt"); $contents = explode('|',$cat); for ($i = 0; $i < count($contents); $i += 3) { $tags[$contents[$i]] = ProcessText($contents[$i+1]); $tagsCount[$contents[$i]] = 0; echo $contents[$i]."-".$tags[$contents[$i]]."
"; // Inserting the category mysql_query("INSERT INTO $tagsTable (cat_name) VALUES ('".$tags[$contents[$i]]."')",$dbConn); $result = mysql_query("SELECT cat_ID FROM $tagsTable WHERE cat_name LIKE '".$tags[$contents[$i]]."'", $dbConn); $row = @mysql_fetch_row($result); $tags[$contents[$i]] = $row[0]; } chdir(".."); chdir("content"); $rootdir = opendir("."); // We browse all the entries while ($yearname = readdir($rootdir)) { // Year list if (is_dir($yearname) && is_numeric($yearname)) { $yeardir = opendir($yearname); echo "$yearname
"; chdir($yearname); // Month list while ($monthname = readdir($yeardir)) { if (is_dir($monthname) && is_numeric($monthname)) { $monthdir = opendir($monthname); echo "|--$monthname
"; chdir($monthname); // Post list while ($postname = readdir($monthdir)) { if (!is_dir($postname)) { echo "|     |--$postname
"; // Post-processing $post = file_get_contents($postname); $contents = explode('|',$post); // Post title $postTitle = ProcessText($contents[3]); echo "|     |      |--Title: ".$title."
"; // Post tags $postTag = $tags[$contents[7]]; echo "|     |      |--Tags: ".$postTag."
"; $tagsCount[$contents[7]]++; // Date $dateString = ProcessDate(substr($postname,5)); echo "|     |      |--Date: ".$dateString."
"; // Post text $postText = ProcessText($contents[5]); // Insert the post $query = "INSERT INTO $postsTable (post_author,post_date,post_date_gmt,post_content,post_title,post_category) VALUES ('1','$dateString','$dateString','$postText','$postTitle','$postTag')"; //echo $query."
"; mysql_query($query,$dbConn); $result = mysql_query("SELECT ID FROM $postsTable WHERE post_title LIKE '$postTitle'", $dbConn); $row = @mysql_fetch_row($result); $postID = $row[0]; // Comments $commentDirName = substr($postname,0,18); $numComments = 0; if (is_dir($commentDirName)) { chdir($commentDirName); chdir("comments"); $commentDir = opendir("."); // Comment list while ($commentFile = readdir($commentDir)) { if (!is_dir($commentFile)) { $comment = file_get_contents($commentFile); $contents = explode('|',$comment); // Author $author = $contents[3]; // Date $dateString = ProcessDate(substr($commentFile,7)); // Comment text $commentText = ProcessText($contents[7]); $numComments++; // Insert the comment mysql_query("INSERT INTO $commentsTable (comment_post_ID,comment_author,comment_author_email,comment_date_gmt,comment_content) VALUES ('$postID','$author','dummy@mail.com','$dateString','$commentText')",$dbConn); } } // And update the posts tag mysql_query("UPDATE $postsTable SET comment_count = '$numComments' WHERE ID = '$postID'"); mysql_query("INSERT INTO $tags2postsTable(post_id,category_id) VALUES ('$postID','$postTag')"); closedir($commentDir); chdir(".."); chdir(".."); } echo "|     |      |--Comments: ".$numComments."
"; } } echo "|
"; chdir(".."); closedir($monthdir); } } chdir(".."); closedir($yeardir); } } closedir($rootdir); chdir(".."); // We update labels count foreach($tagsCount as $index => $value) { mysql_query("UPDATE $tagsTable SET category_count = '$value' WHERE cat_ID = '".$tags[$index]."'"); } mysql_close($dbConn); ?>

Complete!