function doImportWP($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite) { global $txpcfg; //Keep some response on some part $results = array(); // let's go - Dean says ;-). $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true); if (!$b2link) { return 'wp database values don’t work. Go back, replace them and try again'; } mysql_select_db($b2db, $b2link); $results[] = 'connected to wp database. Importing Data'; $a = mysql_query("\n\t\t select\n\t\t " . $wpdbprefix . "posts.ID as ID,\n\t\t " . $wpdbprefix . "posts.post_date as Posted,\n\t\t " . $wpdbprefix . "posts.post_title as Title,\n\t\t " . $wpdbprefix . "posts.post_content as Body,\n\t\t " . $wpdbprefix . "users.user_login as AuthorID\n\t\t from " . $wpdbprefix . "posts\n\t\t left join " . $wpdbprefix . "users on\n\t\t " . $wpdbprefix . "users.ID = " . $wpdbprefix . "posts.post_author\n\t\t ", $b2link) or $results[] = mysql_error(); while ($b = mysql_fetch_array($a)) { //Clean ugly wp slashes before to continue $b = undoSlash(undoSlash($b)); //Trap comments for each article $comments = array(); $q = "\n\t\t\t select\n\t\t\t " . $wpdbprefix . "comments.comment_author_IP as ip,\n\t\t\t " . $wpdbprefix . "comments.comment_author as name,\n\t\t\t " . $wpdbprefix . "comments.comment_author_email as email,\n\t\t\t " . $wpdbprefix . "comments.comment_author_url as web,\n\t\t\t " . $wpdbprefix . "comments.comment_content as message,\n\t\t\t " . $wpdbprefix . "comments.comment_date as posted\n\t\t\t from " . $wpdbprefix . "comments where comment_post_ID='" . $b['ID'] . "'\n\t\t\t "; $c = mysql_query($q, $b2link) or $results[] = mysql_error(); while ($d = mysql_fetch_assoc($c)) { $d = undoSlash(undoSlash($d)); $comments[] = $d; } $b['comments'] = $comments; unset($comments); //Post categories now $q = "\n\t\t\t select\n\t\t\t " . $wpdbprefix . "post2cat.category_id as catid,\n\t\t\t " . $wpdbprefix . "categories.cat_name as catname\n\t\t\t from " . $wpdbprefix . "post2cat\n\t\t\t left join " . $wpdbprefix . "categories on\n\t\t\t " . $wpdbprefix . "categories.cat_ID = " . $wpdbprefix . "post2cat.category_id where " . $wpdbprefix . "post2cat.post_id='" . $b['ID'] . "' limit 2 \n\t\t\t "; $e = mysql_query($q, $b2link) or $results[] = mysql_error(); while ($f = mysql_fetch_array($e)) { $categories[] = $f; } $b['Category1'] = !empty($categories[0]) ? $categories[0]['catname'] : ''; $b['Category2'] = !empty($categories[1]) ? $categories[1]['catname'] : ''; unset($categories); $articles[] = $b; } $a = mysql_query("\n\t\t select\n\t\t " . $wpdbprefix . "categories.cat_ID as catid,\n\t\t " . $wpdbprefix . "categories.cat_name as catname,\n\t\t " . $wpdbprefix . "categories.category_parent as catparent\n\t\t from " . $wpdbprefix . "categories\n\t\t ", $b2link) or $results[] = mysql_error(); while ($b = mysql_fetch_array($a)) { $cats[] = $b; } mysql_close($b2link); //keep a handy copy of txpdb values, and do not alter Dean code // for now! ;-) $txpdb = $txpcfg['db']; $txpdblogin = $txpcfg['user']; $txpdbpass = $txpcfg['pass']; $txpdbhost = $txpcfg['host']; //Yes, we have to make a new connection //otherwise doArray complains $DB = new DB(); $txplink =& $DB->link; mysql_select_db($txpdb, $txplink); include txpath . '/lib/classTextile.php'; $textile = new Textile(); if (!empty($articles)) { foreach ($articles as $a) { //Ugly, really ugly way to workaround the slashes WP gotcha $a['Body'] = str_replace('<!--more-->', '', $a['Body']); $a['Body_html'] = $textile->textileThis($a['Body']); extract($a); //can not use array slash due to way on which comments are selected $q = mysql_query("\n\t\t\t insert into " . PFX . "textpattern set\n\t\t\t Posted = '" . addslashes($Posted) . "',\n\t\t\t Title = '" . addslashes($textile->TextileThis($Title, 1)) . "',\n\t\t\t url_title = '" . stripSpace($Title) . "',\n\t\t\t Body = '" . addslashes($Body) . "',\n\t\t\t Body_html = '" . addslashes($Body_html) . "',\n\t\t\t AuthorID = '" . addslashes($AuthorID) . "',\n\t\t\t Category1 = '" . addslashes($Category1) . "',\n\t\t\t Category2 = '" . addslashes($Category2) . "',\n\t\t\t Section = '{$insert_into_section}',\n\t\t\t uid='" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\t\t\tfeed_time='" . substr($Posted, 0, 10) . "',\n\t\t\t AnnotateInvite = '{$default_comment_invite}',\n\t\t\t Status = '{$insert_with_status}'\n\t\t\t ", $txplink) or $results[] = mysql_error(); if ($insertID = mysql_insert_id()) { $results[] = 'inserted wp_ entry ' . $Title . ' into Textpattern as article ' . $insertID . ''; if (!empty($comments)) { foreach ($comments as $comment) { extract(array_slash($comment)); //The ugly workaroud again $message = nl2br($message); $r = mysql_query("insert into " . PFX . "txp_discuss set\t\t\t\t\t\n\t\t\t\t\t\t\t parentid = '{$insertID}',\n\t\t\t\t\t\t\t name = '{$name}',\n\t\t\t\t\t\t\t email = '{$email}',\n\t\t\t\t\t\t\t web = '{$web}',\n\t\t\t\t\t\t\t ip = '{$ip}',\n\t\t\t\t\t\t\t posted = '{$posted}',\n\t\t\t\t\t\t\t message = '{$message}',\n\t\t\t\t\t\t\t visible = 1", $txplink) or $results[] = mysql_error(); if ($commentID = mysql_insert_id()) { $results[] = 'inserted wp_ comment <strong>' . $commentID . '</strong> into txp_discuss'; } } } } } } if (!empty($cats)) { $right = 2; $left = 1; foreach ($cats as $cat) { extract(array_slash($cat)); //Prevent repeated categories $rs = safe_row('id', 'txp_category', "name='{$catname}'"); if (!$rs) { $left++; $right++; $q = mysql_query("\n\t\t\t\t insert into " . PFX . "txp_category set\n\t\t\t\t name = '{$catname}',\n\t\t\t\t type = 'article',\n\t\t\t\t parent = 'root',\n\t\t\t\t lft = '{$left}',\n\t\t\t\t rgt = '{$right}'", $txplink) or $results[] = mysql_error($q); if (mysql_insert_id()) { $results[] = 'inserted wp_ category <strong>' . $catname . '</strong> into txp_category'; } } } } return join('<br />', $results); }
function doImportWP($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite, $wpdbcharset) { global $txpcfg; $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true); if (!$b2link) { return 'WordPress database values don’t work. Go back, replace them and try again.'; } mysql_select_db($b2db, $b2link); if (!mysql_query('SET NAMES ' . doslash($wpdbcharset), $b2link)) { return 'WordPress database does not support the requested character set. Aborting.'; } // Keep some response on some part $results = array(); $errors = array(); $results[] = hed('Connected to WordPress database. Importing Data…', 1); /* export users */ $users = array(); $user_query = mysql_query("\n\t\t\tselect\n\t\t\t\tID as user_id,\n\t\t\t\tuser_login as name,\n\t\t\t\tuser_email as email,\n\t\t\t\tdisplay_name as RealName\n\t\t\tfrom " . $wpdbprefix . "users\n\t\t", $b2link) or $errors[] = mysql_error(); while ($user = mysql_fetch_array($user_query)) { $user_privs_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tmeta_value\n\t\t\t\tfrom " . $wpdbprefix . "usermeta\n\t\t\t\twhere user_id = " . $user['user_id'] . " and meta_key = '" . $wpdbprefix . "capabilities'\n\t\t\t", $b2link) or $errors[] = mysql_error(); $privs = unserialize(mysql_result($user_privs_query, 0)); foreach ($privs as $key => $val) { // convert the built-in WordPress roles // to their Txp equivalent switch ($key) { // publisher case 'administrator': $user['privs'] = 1; break; // managing editor // managing editor case 'editor': $user['privs'] = 2; break; // staff writer // staff writer case 'author': $user['privs'] = 4; break; // freelancer // freelancer case 'contributor': $user['privs'] = 5; break; // none // none case 'subscriber': default: $user['privs'] = 0; break; } } $users[] = $user; } /* export article and link categories */ $categories = array(); $category_query = mysql_query("\n\t\t\tselect\n\t\t\t\tt.slug as name,\n\t\t\t\tt.name as title,\n\t\t\t\ttt.taxonomy as type,\n\t\t\t\ttt.parent as parent\n\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\torder by field(tt.taxonomy, 'category','post_tag','link_category'), tt.parent asc, t.name asc\n\t\t", $b2link) or $errors[] = mysql_error(); while ($category = mysql_fetch_array($category_query)) { if ($category['parent'] != 0) { $category_parent_query = mysql_query("\n\t\t\t\t\tselect\n\t\t\t\t\t\tslug as name\n\t\t\t\t\tfrom " . $wpdbprefix . "terms\n\t\t\t\t\twhere term_id = '" . doSlash($category['parent']) . "'\n\t\t\t\t", $b2link) or $errors[] = mysql_error(); while ($parent = mysql_fetch_array($category_parent_query)) { $category['parent'] = $parent['name']; } } else { $category['parent'] = 'root'; } switch ($category['type']) { case 'post_tag': case 'category': $category['type'] = 'article'; break; case 'link_category': $category['type'] = 'link'; break; } $categories[] = $category; } /* export articles - do not export post revisions from WP 2.6+ */ $article_query = mysql_query("\n\t\t\tselect\n\t\t\t\tp.ID as ID,\n\t\t\t\tp.post_status as Status,\n\t\t\t\tp.post_date as Posted,\n\t\t\t\tp.post_modified as LastMod,\n\t\t\t\tp.post_title as Title,\n\t\t\t\tp.post_content as Body,\n\t\t\t\tp.comment_status as Annotate,\n\t\t\t\tp.comment_count as comments_count,\n\t\t\t\tp.post_name as url_title,\n\t\t\t\tu.user_login as AuthorID\n\t\t\tfrom " . $wpdbprefix . "posts as p left join " . $wpdbprefix . "users as u\n\t\t\t\ton u.ID = p.post_author\n\t\t\twhere p.post_type = 'post'\n\t\t\torder by p.ID asc\n\t\t", $b2link) or $errors[] = mysql_error(); while ($article = mysql_fetch_array($article_query)) { // convert WP article status to Txp equivalent switch ($article['Status']) { case 'draft': $article['Status'] = 1; break; // hidden // hidden case 'private': $article['Status'] = 2; break; case 'pending': $article['Status'] = 3; break; // live // live case 'publish': $article['Status'] = 4; break; default: $article['Status'] = $insert_with_status; break; } // convert WP comment status to Txp equivalent switch ($article['Annotate']) { // on case 'open': $article['Annotate'] = 1; break; // off // off case 'closed': case 'registered_only': $article['Annotate'] = 0; break; } // article commments $comments = array(); $comment_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tcomment_author_IP as ip,\n\t\t\t\t\tcomment_author as name,\n\t\t\t\t\tcomment_author_email as email,\n\t\t\t\t\tcomment_author_url as web,\n\t\t\t\t\tcomment_content as message,\n\t\t\t\t\tcomment_date as posted\n\t\t\t\tfrom " . $wpdbprefix . "comments\n\t\t\t\twhere comment_post_ID = '" . $article['ID'] . "'\n\t\t\t\torder by comment_ID asc\n\t\t\t", $b2link) or $errors[] = mysql_error(); while ($comment = mysql_fetch_assoc($comment_query)) { $comments[] = $comment; } $article['comments'] = $comments; // article categories $article_categories = array(); $article_category_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $article['ID'] . "' and tt.taxonomy in('post_tag', 'category')\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t\tlimit 2;\n\t\t\t", $b2link) or $errors[] = mysql_error(); while ($category = mysql_fetch_array($article_category_query)) { $article_categories[] = $category; } $article['Category1'] = !empty($article_categories[0]) ? $article_categories[0]['name'] : ''; $article['Category2'] = !empty($article_categories[1]) ? $article_categories[1]['name'] : ''; // article images $article_images = array(); $article_image_query = mysql_query("\n\t\t\tselect\n\t\t\t\tguid\n\t\t\tfrom " . $wpdbprefix . "posts\n\t\t\twhere post_type = 'attachment' and post_mime_type like 'image/%' and post_parent=" . $article['ID'], $b2link) or $errors[] = mysql_error(); while ($image = mysql_fetch_array($article_image_query)) { $article_images[] = $image['guid']; } // Comma-separated image urls preserve multiple attachments. // Attn: If more than one image is attached, <txp:article_image /> will not work out of the box. $article['Image'] = join(',', $article_images); $articles[] = $article; } /* export links */ $links = array(); $link_query = mysql_query("\n\t\t\tselect\n\t\t\t\tlink_id as id,\n\t\t\t\tlink_name as linkname,\n\t\t\t\tlink_description as description,\n\t\t\t\tlink_updated as date,\n\t\t\t\tlink_url as url\n\t\t\tfrom " . $wpdbprefix . "links\n\t\t\torder by link_id asc\n\t\t", $b2link) or $errors[] = mysql_error(); while ($link = mysql_fetch_array($link_query)) { // link categories $link_categories = array(); $link_category_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $link['id'] . "' and tt.taxonomy = 'link_category'\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t", $b2link) or $errors[] = mysql_error(); while ($category = mysql_fetch_array($link_category_query)) { $link['category'] = $category['name']; } $links[] = $link; } mysql_close($b2link); /* begin import */ // keep a handy copy of txpdb values, and do not alter Dean code // for now! ;-) $txpdb = $txpcfg['db']; $txpdblogin = $txpcfg['user']; $txpdbpass = $txpcfg['pass']; $txpdbhost = $txpcfg['host']; // Yes, we have to make a new connection // otherwise doArray complains $DB = new DB(); $txplink =& $DB->link; mysql_select_db($txpdb, $txplink); /* import users */ if ($users) { include_once txpath . '/lib/txplib_admin.php'; $results[] = hed('Imported Users:', 2) . n . graf('Because WordPress uses a different password mechanism than Textpattern, you will need to reset each user’s password from <a href="index.php?event=admin">the Users tab</a>.') . n . '<ul>'; foreach ($users as $user) { extract($user); if (!safe_row('user_id', 'txp_users', "name = '" . doSlash($name) . "'")) { $pass = doSlash(generate_password(6)); $nonce = doSlash(md5(uniqid(mt_rand(), TRUE))); $rs = mysql_query("\n\t\t\t\t\t\tinsert into " . safe_pfx('txp_users') . " set\n\t\t\t\t\t\t\tname = '" . doSlash($name) . "',\n\t\t\t\t\t\t\tpass = '******',\n\t\t\t\t\t\t\temail = '" . doSlash($email) . "',\n\t\t\t\t\t\t\tRealName = '" . doSlash($RealName) . "',\n\t\t\t\t\t\t\tprivs = " . $privs . ",\n\t\t\t\t\t\t\tnonce = '" . doSlash($nonce) . "'\n\t\t\t\t\t", $txplink) or $errors[] = mysql_error(); if (mysql_insert_id()) { $results[] = '<li>' . $name . ' (' . $RealName . ')</li>'; } } } $results[] = '</ul>'; } /* import categories */ if ($categories) { $results[] = hed('Imported Categories:', 2) . n . '<ul>'; foreach ($categories as $category) { extract($category); if (!safe_row('id', 'txp_category', "name = '" . doSlash($name) . "' and type = '" . doSlash($type) . "' and parent = '" . doSlash($parent) . "'")) { $rs = mysql_query("\n\t\t\t\t\t\tinsert into " . safe_pfx('txp_category') . " set\n\t\t\t\t\t\t\tname = '" . doSlash($name) . "',\n\t\t\t\t\t\t\ttitle = '" . doSlash($title) . "',\n\t\t\t\t\t\t\ttype = '" . doSlash($type) . "',\n\t\t\t\t\t\t\tparent = '" . doSlash($parent) . "'\n\t\t\t\t\t", $txplink) or $errors[] = mysql_error(); if (mysql_insert_id()) { $results[] = '<li>' . $title . ' (' . $type . ')</li>'; } } } rebuild_tree_full('article'); rebuild_tree_full('link'); $results[] = '</ul>'; } /* import articles */ if ($articles) { $results[] = hed('Imported Articles and Comments:', 2) . n . '<ul>'; include txpath . '/lib/classTextile.php'; $textile = new Textile(); foreach ($articles as $article) { extract($article); // Ugly, really ugly way to workaround the slashes WP gotcha $Body = str_replace('<!--more-->', '', $Body); $Body_html = $textile->textileThis($Body); // can not use array slash due to way on which comments are selected $rs = mysql_query("\n\t\t\t\t\tinsert into " . safe_pfx('textpattern') . " set\n\t\t\t\t\t\tPosted = '" . doSlash($Posted) . "',\n\t\t\t\t\t\tLastMod = '" . doSlash($LastMod) . "',\n\t\t\t\t\t\tTitle = '" . doSlash($textile->TextileThis($Title, 1)) . "',\n\t\t\t\t\t\turl_title = '" . doSlash($url_title) . "',\n\t\t\t\t\t\tBody = '" . doSlash($Body) . "',\n\t\t\t\t\t\tBody_html = '" . doSlash($Body_html) . "',\n\t\t\t\t\t\tImage = '" . doSlash($Image) . "',\n\t\t\t\t\t\tAuthorID = '" . doSlash($AuthorID) . "',\n\t\t\t\t\t\tCategory1 = '" . doSlash($Category1) . "',\n\t\t\t\t\t\tCategory2 = '" . doSlash($Category2) . "',\n\t\t\t\t\t\tSection = '{$insert_into_section}',\n\t\t\t\t\t\tuid = '" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\t\tfeed_time = '" . substr($Posted, 0, 10) . "',\n\t\t\t\t\t\tAnnotate = '" . doSlash($Annotate) . "',\n\t\t\t\t\t\tAnnotateInvite = '{$default_comment_invite}',\n\t\t\t\t\t\tStatus = '" . doSlash($Status) . "'\n\t\t\t\t", $txplink) or $errors[] = mysql_error(); if ((int) ($insert_id = mysql_insert_id($txplink))) { $results[] = '<li>' . $Title . '</li>'; if (!empty($comments)) { $inserted_comments = 0; foreach ($comments as $comment) { extract(array_slash($comment)); // The ugly workaroud again $message = nl2br($message); $rs = mysql_query("\n\t\t\t\t\t\t\t\tinsert into " . safe_pfx('txp_discuss') . " set\n\t\t\t\t\t\t\t\t\tparentid = '{$insert_id}',\n\t\t\t\t\t\t\t\t\tname = '" . doSlash($name) . "',\n\t\t\t\t\t\t\t\t\temail = '" . doSlash($email) . "',\n\t\t\t\t\t\t\t\t\tweb = '" . doSlash($web) . "',\n\t\t\t\t\t\t\t\t\tip = '" . doSlash($ip) . "',\n\t\t\t\t\t\t\t\t\tposted = '" . doSlash($posted) . "',\n\t\t\t\t\t\t\t\t\tmessage = '" . doSlash($message) . "',\n\t\t\t\t\t\t\t\t\tvisible = 1\n\t\t\t\t\t\t\t", $txplink) or $results[] = mysql_error(); if (mysql_insert_id()) { $inserted_comments++; } } $results[] = '<li>- ' . $inserted_comments . ' of ' . $comments_count . ' comment(s)</li>'; } } } $results[] = '</ul>'; } /* import links */ if ($links) { $results[] = hed('Imported Links:', 2) . n . '<ul>'; foreach ($links as $link) { extract($link); $rs = mysql_query("\n\t\t\t\t\tinsert into " . safe_pfx('txp_link') . " set\n\t\t\t\t\t\tlinkname = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tlinksort = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tdescription = '" . doSlash($description) . "',\n\t\t\t\t\t\tcategory = '" . doSlash($category) . "',\n\t\t\t\t\t\tdate = '" . doSlash($date) . "',\n\t\t\t\t\t\turl = '" . doSlash($url) . "'\n\t\t\t\t", $txplink) or $errors[] = mysql_error(); if (mysql_insert_id()) { $results[] = '<li>' . $linkname . '</li>'; } } $results[] = '</ul>'; } /* show any errors we encountered */ if ($errors) { $results[] = hed('Errors Encountered:', 2) . n . '<ul>'; foreach ($errors as $error) { $results[] = '<li>' . $error . '</li>'; } $results[] = '</ul>'; } return join(n, $results); }
function doImportB2($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $insert_into_section, $insert_with_status, $default_comment_invite) { global $txpcfg; //Keep some response on some part $results = array(); // let's go - Dean says ;-). $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true); if (!$b2link) { return 'b2 database values don’t work. Go back, replace them and try again'; } mysql_select_db($b2db, $b2link); $results[] = 'connected to b2 database. Importing Data'; // Copy & Paste your table-definitions from b2config.php $tableposts = 'b2posts'; $tableusers = 'b2users'; $tablecategories = 'b2categories'; $tablecomments = 'b2comments'; $a = mysql_query("\n\t\t\tselect \n\t\t\t" . $tableposts . ".ID as ID,\n\t\t\t" . $tableposts . ".post_date as Posted, \n\t\t\t" . $tableposts . ".post_title as Title, \n\t\t\t" . $tableposts . ".post_content as Body, \n\t\t\t" . $tablecategories . ".cat_name as Category1, \n\t\t\t" . $tableusers . ".user_login as AuthorID \n\t\t\tfrom " . $tableposts . " \n\t\t\tleft join " . $tablecategories . " on \n\t\t\t\t" . $tablecategories . ".cat_ID = " . $tableposts . ".post_category \n\t\t\tleft join " . $tableusers . " on \n\t\t\t\t" . $tableusers . ".ID = " . $tableposts . ".post_author\n ORDER BY post_date DESC\n\t\t", $b2link) or $results[] = mysql_error(); while ($b = mysql_fetch_array($a)) { $articles[] = $b; } $a = mysql_query("\n\t\t\tselect\n\t\t\t" . $tablecomments . ".comment_ID as discussid, \n\t\t\t" . $tablecomments . ".comment_post_ID as parentid, \n\t\t\t" . $tablecomments . ".comment_author_IP as ip, \n\t\t\t" . $tablecomments . ".comment_author as name, \n\t\t\t" . $tablecomments . ".comment_author_email as email, \n\t\t\t" . $tablecomments . ".comment_author_url as web, \n\t\t\t" . $tablecomments . ".comment_content as message, \n\t\t\t" . $tablecomments . ".comment_date as posted\n\t\t\tfrom " . $tablecomments . "\n\t\t", $b2link) or $results[] = mysql_error(); while ($b = mysql_fetch_assoc($a)) { $comments[] = $b; } mysql_close($b2link); //keep a handy copy of txpdb values, and do not alter Dean code // for now! ;-) $txpdb = $txpcfg['db']; $txpdblogin = $txpcfg['user']; $txpdbpass = $txpcfg['pass']; $txpdbhost = $txpcfg['host']; //Yes, we have to make a new connection //otherwise doArray complains $DB = new DB(); $txplink =& $DB->link; mysql_select_db($txpdb, $txplink); include txpath . '/lib/classTextile.php'; $textile = new Textile(); if (!empty($articles)) { foreach ($articles as $a) { if (is_callable('utf8_encode')) { // Also fixing break-tags for users with b2s Auto-BR $a['Body'] = utf8_encode(str_replace("<br />\n", "\n", stripslashes($a['Body']))); $a['Title'] = utf8_encode(stripslashes($a['Title'])); $a['Title'] = $textile->TextileThis($a['Title'], '', 1); } // b2 uses the magic word "<!--more-->" to generate excerpts if (strpos($a['Body'], '<!--more-->')) { //Everything that is before "more" can be treated as the excerpt. $pos = strpos($a['Body'], '<!--more-->'); $a['Excerpt'] = substr($a['Body'], 0, $pos); $a['Excerpt_html'] = $textile->textileThis($a['Excerpt']); $a['Body'] = str_replace('<!--more-->', '', $a['Body']); } else { $a['Excerpt'] = ''; $a['Excerpt_html'] = ''; } $a['url_title'] = stripSpace($a['Title']); $a['Body_html'] = $textile->textileThis($a['Body']); extract(array_slash($a)); $q = mysql_query("\n\t\t\t\t\tinsert into " . PFX . "textpattern set \n\t\t\t\t\tID = '{$ID}',\n\t\t\t\t\tPosted = '{$Posted}',\n\t\t\t\t\tTitle = '{$Title}',\n url_title = '{$url_title}',\n\t\t\t\t\tBody = '{$Body}',\n\t\t\t\t\tBody_html = '{$Body_html}',\n\t\t\t\t\tExcerpt = '{$Excerpt}',\n\t\t\t\t\tExcerpt_html = '{$Excerpt_html}',\n\t\t\t\t\tCategory1 = '{$Category1}',\n\t\t\t\t\tAuthorID = '{$AuthorID}',\n\t\t\t\t\tSection = '{$insert_into_section}',\n\t\t\t\t\tAnnotateInvite = '{$default_comment_invite}',\n\t\t\t\t\tuid='" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\tfeed_time='" . substr($Posted, 0, 10) . "',\n\t\t\t\t\tStatus = '{$insert_with_status}'\n\t\t\t\t", $txplink) or $results[] = mysql_error(); if (mysql_insert_id()) { $results[] = 'inserted b2 entry ' . $Title . ' into Textpattern as article ' . $ID . ''; } } } if (!empty($comments)) { foreach ($comments as $comment) { extract(array_slash($comment)); if (is_callable('utf8_encode')) { $message = utf8_encode($message); } $message = nl2br($message); $q = mysql_query("insert into " . PFX . "txp_discuss values \n\t\t\t\t\t({$discussid},{$parentid},'{$name}','{$email}','{$web}','{$ip}','{$posted}','{$message}',1)", $txplink) or $results[] = mysql_error($q); if (mysql_insert_id()) { $results[] = 'inserted b2 comment <strong>' . $parentid . '</strong> into txp_discuss'; } } } return join('<br />', $results); }