Unable to connect to database at this time.

" ); exit(); // Halts the PHP script } if (! @mysql_select_db($database_name, $database_link) ) { echo( "

Unable to locate the database at this time.

" ); exit(); } // select all wordpress posts $sql = "SELECT ID, post_content FROM wp_posts"; $rst = mysql_query($sql); // loop through each post while($row = mysql_fetch_array($rst)) { // get wordpress post id $comment_post_id = $row['ID']; // get commented out blogger post id from content of post $end_id = strpos($row['post_content'], "-->"); $blogger_id = substr($row['post_content'],4,$end_id-4); // fetch haloscan page with comments for the current post $url_to_fetch = "http://www.haloscan.com/comments/" . $haloscan_userid . "/" . $blogger_id . "/"; $url_handle = @fopen($url_to_fetch, "r"); $content = ""; while (! feof($url_handle)) { $content .= fread($url_handle,4096); } fclose($url_handle); // the following code walks through comment html, parsing out comment details hidden in an html comment // using the following haloscan template code (before the {HSCommentEnd}). // note that i didn't import the email address /* */ $last_offset = 0; while (true) { // look for the beginning of a comment $comment_start = strpos($content, "", $last_offset); if ($comment_start !== false) { // print comment url for debugging print $url_to_fetch . "\n"; // find end of comment $comment_end = strpos($content, "", $comment_start); // get comment block, removing newlines $comment_block = preg_replace("/\r|\n/", "", substr($content, $comment_start + 8, ($comment_end - $comment_start - 8))); // explode comment block into an array on triple bars $comment_array = explode("|||", $comment_block); // check for bogus commentor url if ($comment_array[1] == "{HSCommentUrl}") { $comment_array[1] = ""; } //escape strings appropriately $comment_author = mysql_escape_string(trim($comment_array[0])); $comment_url = mysql_escape_string(trim($comment_array[1])); $comment_date = trim($comment_array[2]); $comment_content = mysql_escape_string(trim($comment_array[3])); // insert the comment into wordpress $sql = "INSERT INTO wp_comments SET comment_post_ID = $comment_post_id, comment_author = '$comment_author', comment_author_url = '$comment_url', comment_date = '$comment_date', comment_content = '$comment_content'"; mysql_query($sql); // update the offset $last_offset = $comment_end + 8; } else { break; } } } ?>