หัวข้อ: +++พอมีตัวช่วย Convert PHP-Nuke => WordPress ไหมครับ+++
เริ่มหัวข้อโดย: แอร๊ยยยๆๆๆ ที่ 18 เมษายน 2008, 03:26:44
พอดีมีเว็บที่ทำมานานแล้วเป็น PHP Nuke แล้วก้อเสียดายเรื่องที่เขียนๆ มา
พอจะมีวิธีที่จะแปลงฐานข้อมูล PHp Nuke เป็น WordPress ไหมครับ
หัวข้อ: Re: +++พอมีตัวช่วย Convert PHP-Nuke => WordPress ไหมครับ+++
เริ่มหัวข้อโดย: แอร๊ยยยๆๆๆ ที่ 18 เมษายน 2008, 03:29:02
เอ่อ พอดีไปเจอมา น่าจะเป็นประโยชน์สำหรับหลายๆ คนนะครับ <?php /* Script by Xyborg, based on the pnconvert of Bryan Klingner for postnuke, now it works with phpnuke and you can port all the news/stories content into wordpress :) Made on 4th July, 2007 */ ?>
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP-Nuke to Wordpress Converter/Port</title> <style type="text/css"> <!-- .td { font-family:Georgia, "Times New Roman", Times, serif; font-size:12px; color:#FFF; background-color:#333; } .htab { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#36C; background-color:#CCC; } .txt { font-family:Arial, Helvetica, sans-serif; font-size:14px; } --> </style> </head> <body> <p class="txt">This is a simple script which convert the stories and topics from a PHP-Nuke to a Wordpress database. <strong>This script not import the comments</strong> :P<br /> <br /> The first and most important thing <strong>you have to</strong> do is <strong>install a Wordpress blog on your account/domain</strong> and empty the wp_post, wp_categories and the wp_post2cat tables, then complete this form and press the button "<em>Start!</em>" when you have all ready.</p> <form id="migracion" name="migracion" method="post" action=""> <table width="600" border="0" align="center" cellpadding="0" cellspacing="2"> <tr> <td height="34" colspan="4" align="center" valign="middle" class="td">You have to use the same user and password for the 2 databases.</td> </tr> <tr> <td height="34" colspan="4" align="center" valign="middle" class="htab"><table width="250" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="right" valign="middle" class="htab"> Server: <input name="hostname" type="text" id="hostname" value="localhost" /><br> DB User: <input name="username" type="text" id="username" value="user" /> <br /> DB Password: <input name="password" type="text" id="password" value="pass" /></td> </tr> </table> </td> </tr> <tr> <td height="30" colspan="2" align="center" valign="middle" class="td">PHP-Nuke DB</td> <td colspan="2" align="center" valign="middle" class="td">Wordpress DB</td> </tr> <tr> <td width="250" align="right" valign="middle" class="htab"> DB Name: <input name="dbpn" type="text" id="dbpn" value="nuke_db" /><br /></td> <td width="50" align="right" valign="middle" class="htab"> </td> <td width="250" align="right" valign="middle" class="htab"> DB Name: <input name="dbwp" type="text" id="dbwp" value="wp_db" /><br /></td> <td width="50" align="right" valign="middle" class="htab"></td> </tr> <tr> <td height="36" colspan="4" align="center" valign="middle" class="htab"> <input type="submit" name="submit" id="submit" value="Start!" /></td> </tr> </table> </form> <p class="txt"><strong>Once you press the button the migration starts</strong>, and you just have to make some coffee and let it do the dirty work :P</p> <p class="txt">We assume that the name of the tables of the PHP-Nuke news are: <em>nuke_topics</em> and <em>nuke_stories</em> and the prefix for the Wordpress tables is <em>wp_</em></p> <p class="txt">One more thing, the database Collation type have to be the same for the 2 databases, if not, in some languages you will see some errors.</p> <p class="txt">If you like this tool :), please put a link on your blog to my website: <a href="http://www.phpes.net">PHP en Español</a></p> <hr align="center"> </body> </html> <?php $submit = $_POST['submit']; $hostname = $_POST['hostname']; $username = $_POST['username']; $password = $_POST['password'];
/* PHP-Nuke database */ $db_nuke = $_POST['dbpn']; $nuke_news = "nuke_stories"; // your phpnuke stories table $nuke_topics = "nuke_topics"; // your phpnuke topics table
/* Wordpress database */ $db_wp = $_POST['dbwp']; $wp_prefix = "wp_";
// sanitize function stolen from wordpress source // used to generate the dashed titles in the URLs function sanitize($title) { $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = preg_replace('/[^a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', ' ', $title); $title = str_replace(' ', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; }
if($submit) { $db_connect = @mysql_connect($hostname, $username, $password) or die("Error al conectar: ".mysql_error()); mysql_select_db($db_nuke, $db_connect); $srcresult = mysql_query("select * from $nuke_news", $db_connect) or die("Error: ".mysql_error()); $srccatresult = mysql_query("select * from $nuke_topics", $db_connect) or die("Error: ".mysql_error());
/* Here we do the topics -> categories convertion */ while ($myrow = mysql_fetch_array($srccatresult)) { $mytopictext = mysql_real_escape_string($myrow['topictext']); $mynicename = mysql_real_escape_string(sanitize($mytopictext)); $sql = "INSERT INTO `" . $wp_prefix . "categories` ( `cat_ID`, `cat_name`, `category_nicename`, `category_description` ) VALUES ( '$myrow[topicid]', '$myrow[topicname]', '$mynicename', '$mytopictext' );"; if($myrow[topicid] > 1) { mysql_select_db($db_wp, $db_connect); mysql_query($sql, $db_connect) or die("Fatal error: ".mysql_error()); } } /* Stories -> Posts convertion */ echo "Stories -> Posts convertion<hr align='center'>"; while ($myrow = mysql_fetch_array($srcresult)) { $myhometext = mysql_real_escape_string($myrow['hometext']); if($myrow['bodytext']) { $mybodytext = mysql_real_escape_string($myrow['bodytext']); $myhometext = $myhometext.'\n<!--more-->\n'.$mybodytext; } $mytitle = mysql_real_escape_string($myrow['title']); $myname = mysql_escape_string(sanitize($mytitle)); $sql = "INSERT INTO `" . $wp_prefix . "posts` ( `ID` , `post_author` , `post_date` , `post_date_gmt` , `post_content` , `post_title` , `post_name` , `post_category` , `post_excerpt` , `post_status` , `comment_status` , `ping_status` , `post_password` , `to_ping` , `pinged` , `post_modified` , `post_modified_gmt` , `post_content_filtered` , `post_parent` ) VALUES ( '$myrow[sid]', '1', '$myrow[time]', '0000-00-00 00:00:00', '$myhometext', '$mytitle', '$myname', '$myrow[topic]', '', 'publish', 'open', 'open', '', '', '', '$myrow[time]', '0000-00-00 00:00:00', '', '0' );"; mysql_select_db($db_wp, $db_connect); mysql_query($sql, $db_connect); // now get the ID of the post we just added $sql = "select MAX(ID) from " . $wp_prefix . "posts"; $getID = mysql_query($sql, $db_connect); $currentID = mysql_fetch_array($getID); $currentID = $currentID['MAX(ID)']; echo "- Just inserted ID $currentID <br/>\n"; // add post2cat map... why does he have this table? if ($myrow['topic'] == 0) $topicnum = 1; else $topicnum = $myrow['topic']; $sql = "insert into `" . $wp_prefix . "post2cat` (`post_id`, `category_id`) VALUES ('$currentID', '$topicnum');"; $result = mysql_query($sql, $db_connect) or die("Error: ".mysql_error()); } /* Updating Category Counts */ mysql_select_db($db_wp, $db_connect); $tidyresult = mysql_query("select * from $wp_prefix" . "categories", $db_connect) or die("Error: ".mysql_error()); echo "<hr align='center'>Updating Category Counts<hr align='center'>"; while ($myrow = mysql_fetch_array($tidyresult)) { $mypostid=$myrow['cat_ID']; $countsql="select COUNT(*) from $wp_prefix" . "post2cat" . " WHERE `category_id` = " . $mypostid; $countresult=mysql_query($countsql) or die("Fatal Error: ".mysql_error()); $catcount=mysql_result($countresult,0,0); $countsql="UPDATE `" . $wp_prefix . "categories` SET `category_count` = '" . $catcount . "' WHERE `cat_ID` = " . $mypostid . " LIMIT 1"; $countresult=mysql_query($countsql) or die("Fatal Error: ".mysql_error()); if($catcount > 0) { echo "- $mypostid : $catcount <br/>\n"; } } echo "<hr align='center'>Done!<hr align='center'>"; } ?>
หัวข้อ: Re: +++พอมีตัวช่วย Convert PHP-Nuke => WordPress ไหมครับ+++
เริ่มหัวข้อโดย: spiceday ที่ 18 เมษายน 2008, 07:56:44
น่าจะ ok ครับ
หัวข้อ: Re: +++พอมีตัวช่วย Convert PHP-Nuke => WordPress ไหมครับ+++
เริ่มหัวข้อโดย: tinnoi ที่ 10 พฤษภาคม 2008, 17:33:29
ตัว script ตัวนี้ insert ข้อมูลลงใน wp_categories กับ wp_posts
แต่ถ้าเป็น wp เวอร์ชัน ใหม่ ๆ อย่าง 2.5 ผมดูโครงสร้างตารางแล้วมันจะมี wp_posts - content wp_terms - id , name , slug wp_term_relationships - จับคู่ความสัมพันธ์ ของ tag wp_term_taxonomy - ความสัมพันธ์ต่าง ๆ wp_postmeta - เกี่ยวกับรูป การแนบไฟล์ต่าง ๆ
ที่ต้องใช้หมดเลย ตอนนี้กำลังหาความสัมพันธ์ของมันอยู่
เพราะว่าถ้าเราแค่ยิงกระทู้ลงไปเฉย ๆ ผมมองว่าตัว wp มันจะเสียความสามารถในเรื่อง tag ลงไป
|