Set('isfolder','1'); $parentDoc->Save(); //Connect to TXP database $db = mysql_connect($txpServer, $txpUsername, $txpPassword) or die(mysql_error()); mysql_select_db($txpDatabase, $db) or die(mysql_error()); //use (txp) textpattern->Section to limit which articles we import $sql = "select * from textpattern where Section='$txpSection'"; $result = mysql_query($sql); //For each article found echo ''; echo ''; while($row = mysql_fetch_array($result)) { //convert txp's datetime to unixtime $createdUnixtime = datetimeToUnixtime($row['Posted']); echo '
'; echo ''.$row['Title'].''; echo ''.$row['Excerpt_html'].''; echo ''.strip_tags($row['Body_html']).''; echo ''.$row['Posted'].''; echo ''.$createdUnixtime.''; echo ''.$row['comments_count'].''; echo ''.$row['url_title'].''; if($importItems){ $doc = new Document(); $doc->Set('parent',$modxParentDoc); $doc->Set('pagetitle',mysql_escape_string($row['Title'])); $doc->Set('alias',$row['url_title']); if($includeComments){ $doc->Set('content',mysql_escape_string($row['Body_html']).'{{Comments}}'); } else { $doc->Set('content',$row['Body_html']); } $doc->Set('template',$modxTemplate); $doc->Set('createdon',$createdUnixtime); $doc->Set('createdby',$modxCreatorId); $doc->Set('introtext',mysql_escape_string($row['Excerpt_html'])); if($modxPublish){$doc->Set('published',1);} $doc->Save(); } //Copy comments from textpattern to modx (Jot) if($includeComments){ $txpId = $row['ID']; $sql = "select * from txp_discuss where parentid='$txpId'"; $comments = mysql_query($sql); while($comment = mysql_fetch_array($comments)) { //Need to strip

tags that surround txp comments $commentContent = strip_tags($comment['message']); $commentUnixtime = datetimeToUnixtime($comment['posted']); /* we also need to deal with comments*/ echo ''; //begin comment echo ''.$comment['visible'].''; echo ''.$comment['ip'].''; echo ''.$commentContent.''; //This preg gets rid of an & that was in a name, i think all amperstands are already //correctly handled for the text fields echo ''.preg_replace('/(&|&)/i', '&', $comment['name']).''; //echo ''.$comment['name'].''; echo ''.$comment['email'].''; echo ''.$comment['posted'].''; echo ''.$commentUnixtime.''; echo ''; //end comment if($importItems){ $fields = array('title' => 'From '.mysql_escape_string($comment['name']), 'tagid' => '', 'published' => '1', 'uparent' => $doc->Get('id'), 'parent' => 0, 'flags' => '', 'secip' => $comment['ip'], 'sechash' => '', 'content' => mysql_escape_string($commentContent), 'customfields' => ''.mysql_escape_string($comment['name']).''.mysql_escape_string($comment['email']).'', 'mode' => '0', 'createdby' => '0', 'createdon' => $commentUnixtime); $newcommentid = $modx->db->insert($fields,$modx->getFullTableName('jot_content')); //make new items in modx_jot_fields that hold the name/email (untested) $comment = array('id' => $newcommentid, 'label' => 'name', 'content' => mysql_escape_string($comment['name'])); $modx->db->insert($comment,$modx->getFullTableName('jot_fields')); $comment = array('id' => $newcommentid, 'label' => 'email', 'content' => mysql_escape_string($comment['email'])); $modx->db->insert($comment,$modx->getFullTableName('jot_fields')); } } } echo '

'; //end article } echo '
'; ?>