'OE', chr(197).chr(147) => 'oe', chr(197).chr(160) => 'S', chr(197).chr(189) => 'Z', chr(197).chr(161) => 's', chr(197).chr(190) => 'z', chr(226).chr(130).chr(172) => 'E'); //print_r($invalid_latin_chars); $string = utf8_decode(strtr($string, $invalid_latin_chars)); } $string = strtr($string, $chars['in'], $chars['out']); $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); $string = str_replace($double_chars['in'], $double_chars['out'], $string); return $string; } /* function sanitize_title_with_dashes($title) { $title = remove_accents($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, '-'); // remove trailing dashes return $title; } */ } // Connecting to pMachine database $pmdb = new wpdb(PM_USERNAME, PM_PASSWORD, PM_DATABASE, PM_HOST); $pmachine_blog_textid = $pmdb->get_var('SELECT weblog FROM '.PM_MULTIWEBLOGS.' WHERE id = '.$pmachine_blog_id); // Importing prefs echo "# Importing preferences... \n\n"; $pm2wp_pref_equivalence = array( array('sitename', 'blogname'), array('adminemail', 'admin_email'), array('rss_rows_weblog', 'posts_per_rss'), array('rss_description_weblog', 'blogdescription'), array('rss_lang_weblog', 'rss_language'), array('pages_path_abs_weblog', 'siteurl'), //array('weblog_page', 'blogfilename'), array('is_collective_weblog', 'new_users_can_blog'), array('closed_by_default_weblog', 'users_can_register'), array('posts_per_page_weblog', 'posts_per_page'), array('date_and_time_weblog', 'time_format'), array('notify_of_comment_weblog', 'comments_notify', array('yes', 'no'), array(1, 0)), array('ping_weblog', 'ping_sites', array('yes', 'no'), array(1, 0)) ); foreach($pm2wp_pref_equivalence as $equiv) { $pm_pref_value = $pmdb->get_var('SELECT pm_value FROM '.PM_PREFS.' WHERE pm_option = \''.$equiv[0].'\''); $wp_pref = $equiv[1]; $wp_pref_value = (count($equiv)>2) ? str_replace($equiv[2], $equiv[3], $pm_pref_value) : $pm_pref_value; //echo "UPDATE $tableoptions SET option_value = '".$pmdb->escape($wp_pref_value)."' WHERE option_name = '$wp_pref' \n"; if (!$wpdb->query("UPDATE $tableoptions SET option_value = '".$wpdb->escape($wp_pref_value)."' WHERE option_name = '$wp_pref'")) { echo 'oops while converting '.$wp_pref; } } // $gmt_offset = $pmdb->get_var('SELECT pm_value FROM '.PM_PREFS.' WHERE pm_option = \'timeoffset\''); // $wpdb->query("UPDATE $tableoptions SET option_value = '".intval($gmt_offset)."' WHERE option_name = 'gmt_offset'"); $pm_upload_prefs = $pmdb->get_row('SELECT * FROM '.PM_UPLOAD_PREFS); $wpdb->query("UPDATE $tableoptions SET option_value='".$pm_upload_prefs->abspath."' WHERE option_name='fileupload_url'"); $wpdb->query("UPDATE $tableoptions SET option_value='".realpath($pm_upload_prefs->relpath)."' WHERE option_name='fileupload_realpath'"); $wpdb->query("UPDATE $tableoptions SET option_value='".$pm_upload_prefs->allowedtypes."' WHERE option_name='fileupload_allowedtypes'"); $wpdb->query("UPDATE $tableoptions SET option_value='".$pm_upload_prefs->minlevel."' WHERE option_name='fileupload_minlevel'"); # we NEED these options $wpdb->query("UPDATE $tableoptions SET option_value=0 WHERE option_name='use_htmltrans'"); //$wpdb->query("UPDATE $tableoptions SET option_value=1 WHERE option_name='use_bbcode'"); echo "# OK\n\n\n"; // Importing members echo "# Importing members... \n\n"; $pm_members = $pmdb->get_results('SELECT * FROM '.PM_MEMBERS); $wpdb->query("UPDATE $tableusers SET ID=0 WHERE user_login='admin'"); foreach($pm_members as $member) { $query = "INSERT INTO $tableusers (ID, user_login, user_pass, user_nickname, user_icq, user_email, user_url, user_aim, user_msn, user_yim, user_idmode, user_ip, user_registered, user_description, user_level, user_status, user_nicename) VALUES ($member->id, '$member->username', '$member->password', '$member->signature', '$member->icq', '".str_replace('_at_', '@', $member->email)."', '$member->url', '$member->aol_im', '$member->msn_im', '$member->yahoo_im', 'nickname', '$member->ipaddress', '".gmdate('Y-m-d H:i:s', $member->joindate)."', '$member->bio', '0', '0', '".sanitize_title_with_dashes($member->username)."')"; // echo $query; $wpdb->query($query); } echo "# OK\n\n\n"; // Importing categories echo "# Importing categories... \n\n"; $pm_categories = $pmdb->get_results('SELECT id, category FROM '.PM_CATEGORIES.' WHERE weblog=\''.$pmachine_blog_textid.'\''); // print_r($pm_categories); $wpdb->query("DELETE FROM $tablecategories WHERE cat_ID=1"); foreach($pm_categories as $category) { $query = "INSERT INTO $tablecategories (cat_ID, cat_name, category_nicename) VALUES ($category->id, '".$category->category."', '".sanitize_title_with_dashes($category->category)."')"; // echo $query.";\n"; $wpdb->query($query); } echo "# OK\n\n\n"; // Importing posts echo "# Importing posts... \n\n"; $pm_posts = $pmdb->get_results('SELECT * FROM '.PM_WEBLOG.' WHERE weblog = \''.$pmachine_blog_textid.'\''); $pm_upload_paths = $pmdb->get_results('SELECT id, abspath FROM '.PM_UPLOAD_PREFS); foreach($pm_upload_paths as $upload_path) { $pm_upload_path_search[] = '%%dir['.$upload_path->id.']%%'; $pm_upload_path_replace[] = $upload_path->abspath; } $wpdb->query("DELETE FROM $tableposts WHERE ID=1"); $bbcode['in'] = array( '#\[b](.+?)\[/b]#is', '#\[i](.+?)\[/i]#is', '#\[strong](.+?)\[/strong]#is', '#\[em](.+?)\[/em]#is', '#\[u](.+?)\[/u]#is', '#\[s](.+?)\[/s]#is', '#\[pre](.+?)\[/pre]#is', '#\[code](.+?)\[/code]#is', '#\[quote](.+?)\[/quote]#is', '#\[color=(.+?)](.+?)\[/color]#is', '#\[size=1](.+?)\[/size]#is', '#\[size=2](.+?)\[/size]#is', '#\[size=3](.+?)\[/size]#is', '#\[size=[4|5]](.+?)\[/size]#is', '#\[size=6](.+?)\[/size]#is', '#\[size=7](.+?)\[/size]#is', '#\[font=(.+?)](.+?)\[/font]#is', '#\[img](.+?)\[/img]#is', '#\[url](.+?)\[/url]#is', '#\[url=(.+?)](.+?)\[/url]#is', '#\[email](.+?)\[/email]#is', '#\[email=(.+?)](.+?)\[/email]#is', '#\[encode](.+?)\[/encode]#eis', '#\[encode=(.+?)](.+?)\[/encode]#eis', '#\[style=(.+?)](.+?)\[/style]#is' ); $bbcode['out'] = array( '$1', '$1', '$1', '$1', '$1', '$1', '
$1
', '
$1
', '
$1
', '$2', '$1', '$1', '$1', '$1', '$1', '$1', '$2', '', '$1', '$2', '$1', '$2', "''.antispambot('\\1').''", "''.antispambot('\\1').''", '$2' ); function convert_pm_bbcode($string) { global $bbcode, $wpdb, $pm_upload_path_search, $pm_upload_path_replace; $string = str_replace($pm_upload_path_search, $pm_upload_path_replace, $string); $string = preg_replace($bbcode['in'], $bbcode['out'], $string); return $wpdb->escape($string); } foreach($pm_posts as $post) { $wp_post_id = $post->post_id; $wp_post_author = $post->member_id; $wp_post_date = gmdate('Y-m-d H:i:s', $post->t_stamp); $wp_post_date_gmt = gmdate('Y-m-d H:i:s', $post->t_stamp - 3600*get_settings('gmt_offset')); $wp_post_modified = $wp_post_date; $wp_post_modified_gmt = $wp_post_date_gmt; $wp_post_content = convert_pm_bbcode($post->body); if (trim($post->more != '')) { $wp_post_content .= $wpdb->escape("\n\n".str_replace($pm_upload_path_search, $pm_upload_path_replace, $post->more)); } $wp_post_title = $wpdb->escape($post->title); $wp_post_excerpt = convert_pm_bbcode($post->blurb); $wp_post_status = str_replace(array('open', 'closed'), array('publish', 'draft'), $post->status); $wp_post_comment_status = str_replace(array(1, 0), array('open', 'closed'), $post->showcomments); $wp_post_name = sanitize_title_with_dashes($post->title); $wp_post_pinged = $wpdb->escape($post->trackback); $wp_post_category = (strlen($post->category)) ? $post->category : 1; $query = "INSERT INTO $tableposts (ID, post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_status, comment_status, post_name, pinged) VALUES ($wp_post_id, $wp_post_author, '$wp_post_date', '$wp_post_date_gmt', '$wp_post_modified', '$wp_post_modified_gmt', '$wp_post_content', '$wp_post_title', '$wp_post_excerpt', '$wp_post_status', '$wp_post_comment_status', '$wp_post_name', '$wp_post_pinged')"; $wpdb->query($query); // echo $query.";\n"; $query = "INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($wp_post_id, $wp_post_category)"; $wpdb->query($query); // echo $query.";\n"; // echo $wp_post_id."\n"; } unset($pm_posts); echo "# OK\n\n\n"; // Importing comments echo "# Importing comments...\n\n"; $pm_comments = $pmdb->get_results('SELECT comment_id, post_id, member_id, t_stamp, body FROM '.PM_COMMENTS.' WHERE weblog = \''.$pmachine_blog_textid.'\''); $wpdb->query("DELETE FROM $tablecomments WHERE comment_ID=1"); //echo "DELETE FROM $tablecomments WHERE comment_ID=1;"; foreach($pm_comments as $comment) { $commenter_id = $comment->member_id; // echo $commenter_id; if (substr($commenter_id, 0, 2) == 'NM') { $commenter = $pmdb->get_row('SELECT signature, email, url, ipaddress FROM '.PM_NONMEMBERS.' WHERE id = '.substr($commenter_id, 2, 4)); } else { $commenter = $pmdb->get_row('SELECT signature, email, url, ipaddress FROM '.PM_MEMBERS.' WHERE id = '.$commenter_id); } $wp_comment_post_ID = $comment->post_id; $wp_comment_author = $wpdb->escape($commenter->signature); $wp_comment_author_email = $wpdb->escape($commenter->email); $wp_comment_author_url = $wpdb->escape($commenter->url); $wp_comment_author_IP = $commenter->ipaddress; $wp_comment_date = gmdate('Y-m-d H:i:s', $comment->t_stamp); $wp_comment_content = convert_pm_bbcode($comment->body); $wp_comment_user_id = (substr($commenter_id, 0, 2) == 'NM') ? 0 : $comment->member_id; $query = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved, user_id) VALUES ($wp_comment_post_ID, '$wp_comment_author', '$wp_comment_author_email', '$wp_comment_author_url', '$wp_comment_author_IP', '$wp_comment_date', '$wp_comment_content', '1', $wp_comment_user_id)"; $wpdb->query($query); // echo $query.";\n"; } unset($pm_comments); echo "# OK\n\n\n"; // Importing trackbacks echo "# Importing trackbacks...\n\n"; $pm_trackbacks = $pmdb->get_results('SELECT * FROM '.PM_TRACKBACK); foreach($pm_trackbacks as $trackback) { $wp_comment_post_ID = $trackback->post_id; $wp_comment_author = $wpdb->escape($trackback->blog_name); $wp_comment_author_url = $wpdb->escape($trackback->entry_url); $wp_comment_date = gmdate('Y-m-d H:i:s', $trackback->t_stamp); $wp_comment_content = ''; $wp_comment_content .= str_replace('"', '"', $trackback->entry_title); $wp_comment_content .= "\n".$trackback->excerpt; $wp_comment_content = $wpdb->escape($wp_comment_content); $query = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_url, comment_date, comment_content, comment_approved) VALUES ($wp_comment_post_ID, '$wp_comment_author', '$wp_comment_author_url', '$wp_comment_date', '$wp_comment_content', '1')"; $wpdb->query($query); // echo $query.";\n"; } unset($pm_trackbacks); echo "# OK\n\n\n"; // Importing pingbacks echo "# Importing pingbacks...\n\n"; $pm_pingbacks = $pmdb->get_results('SELECT * FROM '.PM_PINGBACK); foreach($pm_pingbacks as $pingback) { $wp_comment_post_ID = $pingback->post_id; $wp_comment_author = $wpdb->escape($pingback->from_title); $wp_comment_author_url = $wpdb->escape($pingback->from_url); $wp_comment_date = gmdate('Y-m-d H:i:s', $pingback->t_stamp); $wp_comment_content = $wpdb->escape(''.$pingback->from_context); $query = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_url, comment_date, comment_content, comment_approved) VALUES ($wp_comment_post_ID, '$wp_comment_author', '$wp_comment_author_url', '$wp_comment_date', '$wp_comment_content', '1')"; $wpdb->query($query); // echo $query.";\n"; } unset($pm_pingbacks); echo "# OK\n\n\n"; ?>