function run($step = 0) { global $dsql, $update_sqls, $cfg_db_language, $cfg_webname; if (!file_exists(DEDEINC . '/helpers/changyan.helper.php')) { $this->errmsg = '未成功安装畅言模块文件'; return FALSE; } helper('changyan'); if (!$dsql->IsTable("#@__plus_changyan_setting")) { $this->errmsg = '未成功初始化畅言模块所需数据库'; return FALSE; } if (empty($version)) { $version = '0.0.1'; } if (version_compare($version, CHANGYAN_VER, '<')) { $mysql_version = $dsql->GetVersion(TRUE); foreach ($update_sqls as $ver => $sqls) { if (version_compare($ver, $version, '<')) { continue; } foreach ($sqls as $sql) { $sql = preg_replace("#ENGINE=MyISAM#i", 'TYPE=MyISAM', $sql); $sql41tmp = 'ENGINE=MyISAM DEFAULT CHARSET=' . $cfg_db_language; if ($mysql_version >= 4.1) { $sql = preg_replace("#TYPE=MyISAM#i", $sql41tmp, $sql); } $dsql->ExecuteNoneQuery($sql); } changyan_set_setting('version', $ver); $version = changyan_get_setting('version'); } $isv_app_key = changyan_get_isv_app_key(); } $db_user = changyan_get_setting('user'); if (!empty($db_user)) { $this->errmsg = '已经初始化畅言账号,无需再进行初始化'; return FALSE; } $sign = changyan_gen_sign(CHANGYAN_CLIENT_ID); $url = $_SERVER['SERVER_NAME']; $isv_name = cn_substr($cfg_webname, 20); $paramsArr = array('client_id' => CHANGYAN_CLIENT_ID, 'isv_name' => changyan_autoCharset($isv_name), 'url' => 'http://' . $url, 'sign' => $sign); $rs = changyan_http_send(CHANGYAN_API_AUTOREG, 0, $paramsArr); $result = json_decode($rs, TRUE); if ($result['status'] == 0) { // 保存appid,id信息 changyan_set_setting('user', $result['user']); changyan_set_setting('appid', $result['appid']); changyan_set_setting('id', $result['id']); changyan_set_setting('isv_app_key', $result['isv_app_key']); changyan_set_setting('isv_id', $result['isv_id']); changyan_clearcache(); $passwd = changyan_mchStrCode($result['passwd'], 'ENCODE'); changyan_set_setting('pwd', $passwd); return TRUE; } else { if ($step > 3) { $this->errmsg = '无法成功初始化畅言模块'; return FALSE; } $step++; return $this->run($step); } }
function changyan_insert_comments($comment, $aid, $title) { global $dsql; if (!isset($comment['comments'])) { return FALSE; } $dsql->SetQuery("SELECT comment_id FROM `#@__plus_changyan_insertids` WHERE aid={$aid}"); $dsql->Execute('dd'); $comment_ids = array(); while ($arr = $dsql->GetArray('dd')) { $comment_ids[] = $arr['comment_id']; } $i = 0; foreach ($comment['comments'] as $comment) { $content = ''; if (in_array($comment['comment_id'], $comment_ids)) { continue; } if (count($comment['comments']) > 0) { $comment['comments'] = changyan_list_sort_by($comment['comments'], 'create_time', 'desc'); foreach ($comment['comments'] as $c) { $c['content'] = changyan_autoCharset($c['content'], 'in'); $content = '{quote}{content}' . $content . $c['content'] . '{/content}{title}' . $c['passport']['nickname'] . ' 的原帖:{/title}{/quote}'; } } $aid = intval($aid); $typeid = 0; $username = changyan_autoCharset($comment['passport']['nickname'], 'in'); $arctitle = changyan_autoCharset($title, 'in'); $ip = $comment['ip']; $comment_id = $comment['comment_id']; $ischeck = 1; $dtime = intval($comment['create_time'] / 1000); $msg = $content . changyan_autoCharset($comment['content'], 'in'); $inquery = "INSERT INTO `#@__feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`, `mid`,`bad`,`good`,`ftype`,`face`,`msg`)\n VALUES ('{$aid}','{$typeid}','{$username}','{$arctitle}','{$ip}','{$ischeck}','{$dtime}', '0','0','0','feedback','','{$msg}'); "; $rs = $dsql->ExecuteNoneQuery($inquery); $feedback_id = $dsql->GetLastID(); $inquery = "INSERT INTO `#@__plus_changyan_importids`(`aid`,`feedback_id`) VALUES ('{$aid}','{$feedback_id}')"; $rs = $dsql->ExecuteNoneQuery($inquery); $inquery = "INSERT INTO `#@__plus_changyan_insertids`(`aid`,`comment_id`) VALUES ('{$aid}','{$comment_id}')"; $rs = $dsql->ExecuteNoneQuery($inquery); $i++; } return $i; // return $comment; }
$feedArr['ownerid'] = $row['mid']; $feedArr['metadata'] = ''; $dsql->SetQuery("SELECT feedback_id FROM `#@__plus_changyan_importids` WHERE aid={$arr['aid']}"); $dsql->Execute('dd'); $feedback_ids = array(); while ($farr = $dsql->GetArray('dd')) { $feedback_ids[] = $farr['feedback_id']; } $squery = "SELECT * FROM `#@__feedback` WHERE aid={$arr['aid']} order by dtime asc;"; $dsql->SetQuery($squery); $dsql->Execute('xx'); while ($fRow = $dsql->GetArray('xx')) { if (in_array($fRow['id'], $feedback_ids)) { continue; } $feedArr['comments'][] = array('cmtid' => $fRow['id'], 'ctime' => date('Y-m-d h:m:s', $fRow['dtime']), 'content' => changyan_Quote_replace(changyan_autoCharset($fRow['msg'])), 'replyid' => 0, 'spcount' => $fRow['good'], 'opcount' => $fRow['bad'], 'user' => array('userid' => $fRow['mid'], 'nickname' => changyan_autoCharset($fRow['username']), 'usericon' => '', 'userurl' => '')); $inquery = "INSERT INTO `#@__plus_changyan_importids`(`aid`,`feedback_id`) VALUES ('{$arr['aid']}','{$fRow['id']}')"; $rs = $dsql->ExecuteNoneQuery($inquery); } if (count($feedArr['comments']) < 1) { continue; } $content = json_encode($feedArr); $md5 = changyan_hmacsha1($content, $isv_app_key); $paramsArr = array('appid' => $client_id, 'md5' => $md5, 'jsondata' => $content); $rs = changyan_http_send(CHANGYAN_API_IMPORT, 0, $paramsArr); } $start = $start + $pagesize; $end = $start + $pagesize; ShowMsg("成功导出评论数据,接下来导入[{$start}-{$end}]的评论数据", "?dopost=dedecms_to_changyan&start={$start}"); //echo json_encode($result);