<?php
/**
 * 转换微博内容 - 评论
 * pre_form_post
 */

if($start <= 1) {

}

$fid = $xc->db['discuz']->result_first("SELECT svalue FROM {$discuz_tablepre}common_setting WHERE skey='guangbofid'");
$maxmid = $xc->db['source']->result_first("SELECT MAX(cid) FROM {$source_tablepre}weibo_comment");

$smilequery = $xc->db['discuz']->query("SELECT * FROM {$discuz_tablepre}common_smiley WHERE typeid=99");
while($smile = $xc->db['discuz']->fetch_array($smilequery)) {
	$smiles[] = $smile;
}

if($start < $maxmid) {
	$converted = 1;
}

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}weibo_comment WHERE cid>=$start AND cid<$start+$rpp") or dexit();

while($comment = $xc->db['source']->fetch_array($query)) {
	$tid 			= $xc->db['discuz']->result_first("SELECT tid FROM {$discuz_tablepre}mid2tid WHERE mid='{$comment[mid]}'");
	if(empty($tid)) {
		continue;
	}
	$xc->db['discuz']->query("INSERT INTO {$discuz_tablepre}forum_post_tableid VALUES (NULL)");
	$pid			= $xc->db['discuz']->insert_id();
	$fid			= $fid;
	$first			= 0;
	$author			= addslashes(getusername($comment['uid']));
	$authorid		= intval($comment['uid']);
	$subject		= '';
	$dateline		= $comment['postdate'];
	$message		= addslashes(_parseLink($comment['content']));
	$attachment		= 0;
	$position		= $xc->db['discuz']->result_first("SELECT maxposition FROM {$discuz_tablepre}forum_thread WHERE tid='{$tid}'");
	$position		=	$position ? $position + 1 : 2;


	$field1 = array('pid','fid','tid','first','author','authorid','subject','dateline','message','attachment','position');
	$query1 = getinsertsql("{$discuz_tablepre}forum_post", $field1);
	
	if(!$xc->db['discuz']->query($query1)) {
		reportlog("无法转换广播内容(评论) cid = {$comment[cid]}");
	} else {
		$xc->db['discuz']->query("UPDATE {$discuz_tablepre}forum_thread SET maxposition='$position' WHERE tid='{$tid}'");
		$convertedrows++;
	}
	$converted = 1;
	$totalrows ++;
}
?>
