"; $result = mysql_query($q_str); // consider wheather you want to post the error-mes to the users. if (mysql_errno() != 0) { die("Query Failed:". mysql_errno().": ".mysql_error()."
$q_str"); } return $result; } function xoopsCodeDecode($text) /** * taken from Xoops own library */ { $patterns = array(); $replacements = array(); $patterns[] = "/\[siteurl=(['\"]?)([^\"'<>]*)\\1](.*)\[\/siteurl\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[url=(['\"]?)(http[s]?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[url=(['\"]?)(ftp?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[url=(['\"]?)([^\"'<>]*)\\1](.*)\[\/url\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[color=(['\"]?)([a-zA-Z0-9]*)\\1](.*)\[\/color\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[size=(['\"]?)([a-z0-9-]*)\\1](.*)\[\/size\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[font=(['\"]?)([^;<>\*\(\)\"']*)\\1](.*)\[\/font\]/sU"; $replacements[] = '\\3'; $patterns[] = "/\[email]([^;<>\*\(\)\"']*)\[\/email\]/sU"; $replacements[] = '\\1'; $patterns[] = "/\[b](.*)\[\/b\]/sU"; $replacements[] = '\\1'; $patterns[] = "/\[i](.*)\[\/i\]/sU"; $replacements[] = '\\1'; $patterns[] = "/\[u](.*)\[\/u\]/sU"; $replacements[] = '\\1'; $patterns[] = "/\[d](.*)\[\/d\]/sU"; $replacements[] = '\\1'; $patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU"; $patterns[] = "/\[img]([^\"\(\)\?\&'<>]*)\[\/img\]/sU"; $patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 id=(['\"]?)([0-9]*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU"; $patterns[] = "/\[img id=(['\"]?)([0-9]*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU"; $patterns[] = "/\[quote]/sU"; $replacements[] = _QUOTEC.'
'; $patterns[] = "/\[\/quote]/sU"; $replacements[] = '
'; $patterns[] = "/javascript:/si"; $replacements[] = "java script:"; $patterns[] = "/about:/si"; $replacements[] = "about :"; return preg_replace($patterns, $replacements, $text); } function prep_text($text) { return addslashes(xoopsCodeDecode(utf8_encode($text))); } // retrieve the categories already in MT - this is done to avoid dublicates. $res = query("SELECT category_label, category_id FROM `mt_category`"); if (mysql_num_rows($res) > 0) { while ($row = mysql_fetch_array($res)) { $categories_tested[$row['category_label']] = $row['category_id']; } } // cancel these variables... $res = null; $row = null; // echo "
".print_r($categories_tested,1)."
"; // fetch the stories from Xoops along with user-name and topics.. $res = query("SELECT xu.name, xs.title, xt.topic_title, xt.topic_id, xs.storyid, xs.created, xs.published, xs.hometext, xs.comments FROM `xoops2_stories` xs, `xoops2_users` xu, `xoops2_topics` xt WHERE xs.uid = xu.uid AND xs.topicid = xt.topic_id"); while ($row = mysql_fetch_array($res)) { $org_storyid = $row['storyid']; $new_storyid = $row['storyid'] + 1000; /** * fetch any comments related to the xoops-story. */ if ((int) $row['comments'] > 0) { $comment_res = query("SELECT xxc.com_text, xxc.com_ip, xxc.com_created, xu.name, xxc.com_text FROM xoops2_xoopscomments xxc LEFT JOIN xoops2_users xu ON xxc.com_uid = xu.uid WHERE xxc.com_itemid = '".$org_storyid."'"); if (mysql_num_rows($comment_res) > 0) { while($comment_row = mysql_fetch_array($comment_res)) { // keep it in an array. Afterwards it'll be inserted. if ($comment_row['name'] == "") { $comment_row['name'] = "Un-registered"; } $insert_mt_comment[$new_storyid][] = "INSERT INTO `mt_comment` SET comment_author = '".prep_text($comment_row['name'])."', comment_blog_id = 1, comment_created_by = 1, comment_created_on = '".date('Y-m-d H:i:s',$comment_row['created'])."', comment_entry_id = $new_storyid, comment_ip = '".$comment_row['com_ip']."', comment_last_moved_on = '2000-01-01 00:00:00', comment_modified_on = '".date('Y-m-d H:i:s',$comment_row['created'])."', comment_text = '".prep_text($comment_row['com_text'])."', comment_visible = 1"; } } } // this will deal with any categories in Xoops which has not already been transfered to MT if (empty($categories_tested[utf8_encode($row['topic_title'])])) { query("INSERT INTO `mt_category` SET category_allow_pings = 1, category_author_id = 1, category_basename = '".prep_text(str_replace(" ","_",$row['topic_title']))."', category_blog_id = 1, category_class = 'category', category_created_by = 1, category_created_on = '".date('Y-m-d H:i:s',$comment_row['created'])."', category_label = '".prep_text($row['topic_title'])."', category_modified_on = '".date('Y-m-d H:i:s',$comment_row['created'])."', category_parent = 0"); $categories_tested[utf8_encode($row['topic_title'])] = mysql_insert_id(); } // insert an entry in mt_placement to link the category, entry and blog. query("INSERT INTO `mt_placement` SET placement_blog_id = 1, placement_category_id = ".$categories_tested[utf8_encode($row['topic_title'])].", placement_entry_id = $new_storyid, placement_is_primary = 1"); // create the actual sql-entry for the blog-post. $insert_mt_entry[$new_storyid] = "INSERT INTO `mt_entry` SET entry_id = $new_storyid, entry_allow_comments = 1, entry_allow_pings = 1, entry_atom_id = 'tag:www.wickedpixel.net,".date('Y',$row['created']).":/blog//1.".$new_storyid."', entry_author_id = '1', entry_authored_on = '".date('Y-m-d H:i:s',$row['created'])."', entry_basename = 'speciale_".$new_storyid."', entry_category_id = ".$categories_tested[utf8_encode($row['topic_title'])].", entry_blog_id = '1', entry_class = 'entry', entry_convert_breaks = 'richtext', entry_created_by = '1', entry_created_on = '".date('Y-m-d H:i:s',$row['published'])."', entry_modified_on = '".date('Y-m-d H:i:s',$row['published'])."', entry_status = '1', entry_text = '".nl2br(prep_text($row['hometext']))."', entry_title = '".prep_text($row['title'])."', entry_week_number = '".date('YW',$row['created'])."'"; } // Now run the two insert-scripts while (list($entry_key,$entry_val) = each($insert_mt_entry)) { query($entry_val); echo "Successfully inserted Entry with id#$entry_key
"; if (count($insert_mt_comment[$entry_key]) > 0) { while (list($comment_key,$comment_val) = each($insert_mt_comment[$entry_key])) { query($comment_val); echo "- Successfully inserted comment with id# for entry #$entry_key".mysql_insert_id()."
"; } } } ?>