前些天,写了一个PHP脚本用于supesite7.0导入PHPCMS2008:
<?PHP/*
supesite7.0导入PHPCMS 2008 sp3 导入脚本
warran@qq.com
http://www.veryhuo.com
*/
header("Content-Type: text/HTML;charset=utf-8");
set_time_limit(0);
define('IN_admin',TRUE);
define('IN_PHPCMS',TRUE);
require_once '../include/common.inc.PHP';
require_once '../include/admin/process.class.PHP';
require '../include/priv_role.class.PHP';
require_once '../include/attachment.class.PHP';
require_once '../include/admin/content.class.PHP';
//数据库连接
//conn1为supesite数据库
//conn2为PHPCMS数据库
$conn1=MysqL_connect("localhost","root","");
MysqL_select_db("site",$conn1);
$conn2=MysqL_connect("localhost","");
MysqL_select_db("PHPCMS",$conn2);
//清空PHPCMS 文章和评论数据
if($_GET["action"]=='clean'){
MysqL_query("delete from PHPCMS_content where 1=1",$conn2);
MysqL_query("delete from PHPCMS_content_count where 1=1",$conn2);
MysqL_query("delete from PHPCMS_c_news where 1=1",$conn2);
MysqL_query("delete from PHPCMS_content_tag where 1=1",$conn2);
MysqL_query("delete from PHPCMS_keyword where 1=1",$conn2);
MysqL_query("delete from PHPCMS_member_group_priv where 1=1",$conn2);
MysqL_query("delete from PHPCMS_comment where 1=1",$conn2);
exit("清空完成");
}
if($_GET["action"]=='test'){
echo hasuser("warran");
exit();
}
//读取分类表
$result=MysqL_query("select catID,catname from PHPCMS_category",$conn2);
while($row=MysqL_fetch_array($result)){
$cat["$row[catname]"]=$row[catID];
}
$_roleID = cache_read('admin_role_'.$_userID.'.PHP');
$priv_role = new priv_role();
$c = new content();
$tmp=0;
//添加文章
$result=MysqL_query("select supe_spaceitems.*,supe_categorIEs.name as catname from supe_spaceitems,supe_categorIEs where supe_spaceitems.catID=supe_categorIEs.catID and supe_spaceitems.folder=1",$conn1);
while($row=MysqL_fetch_array($result)){
//使用PHPCMS自带的类,添加内容
$data["catID"]=$cat[$row["catname"]];
$attachment = new attachment("PHPCMS",$data["catID"]);
$data["Title"]=addslashes($row["subject"]);
$data["style"]="";
$data["thumb"]="";
$res=MysqL_query("select * from supe_spacenews where itemID=$row[itemID]",$conn1);
$includeTags="";
$message="";
while($rs=MysqL_fetch_array($res)){
$message.=$rs["message"];
if($rs["includeTags"]!=''){
$includeTags.=" ".$rs["includeTags"];
}
}
$data["keywords"]=addslashes($includeTags);
$data["author"]=addslashes($row["username"]);
$data["copyfrom"]=addslashes($row["newsauthor"]);
$data["description"]="";
$data["content"]=addslashes($message);
$data["paginationtype"]="0";
$data["maxcharperpage"]="10000";
$data["Titleintact"]=addslashes($row["short_subject"]);
$data["islink"]="99";
$time_tmp=date("Y-m-d h:i:s");
$data["inputtime"]=$time_tmp;
$data["posIDs"]="-99";
$data["groupIDs_vIEw"]=array("-99");
$data["readpoint"]="";
$data["prefix"]="";
$data["template"]="show";
$data["status"]=99;
$data["updatetime"]=$time_tmp;
$contentID=$c->add($data,"",1);
//添加评论
$res=MysqL_query("select * from supe_spacecomments where itemID=$row[itemID] and rates=0",$conn1);
$comment_num=0;
while($rs=MysqL_fetch_array($res)){
$comment["keyID"]="PHPCMS-content-Title-".$contentID;
if($rs["authorID"]==0){
$comment["username"]="游客";
$comment["userID"]=0;
}else{
$comment["username"]=addslashes($rs["author"]);
$hasuser=hasuser($rs["author"]);
if($hasuser==0){
$userinfo["username"]=addslashes($rs["author"]);
$userinfo["password"]="82790085228cf8a1e3bac41f45271e5f";
$userinfo["touserID"]=$rs["authorID"];
$userinfo["email"]="";
$comment["userID"]=adduser($userinfo);
}else{
$comment["userID"]=$hasuser;
}
}
$comment["content"]=$rs["message"];
$comment["ip"]=$rs["ip"];
$comment["addtime"]=$rs["dateline"];
if(MysqL_query("insert into PHPCMS_comment(keyID,userID,username,content,ip,addtime,status) values('$comment[keyID]',$comment[userID],'$comment[username]','$comment[content]','$comment[ip]',$comment[addtime],1)",$conn2)){
$comment_num+=1;
}
}
MysqL_query("update PHPCMS_content_count set comments=$comment_num,comments_checked=$comment_num where contentID=$contentID");
}
function dump($vars,$label = '',$return = false)
{
if (ini_get('HTML_errors')) {
$content = "<pre>";
if ($label != '') {
$content .= "<b>{$label} :</b>";
}
$content .= HTMLspecialchars(print_r($vars,true));
$content .= "</pre>";
} else {
$content = $label . " :" . print_r($vars,true);
}
if ($return) { return $content; }
echo $content;
return null;
}
/*
向PHPCMS中添加用户
*/
function adduser($userinfo){
global $conn2;
MysqL_query("insert into PHPCMS_member(username,password,groupID,touserID,email) values('$userinfo[username]','$userinfo[password]',6,$userinfo[touserID],'$userinfo[email]')",$conn2);
$userID=MysqL_insert_ID();
MysqL_query("insert into PHPCMS_member_cache(username,$conn2);
return $userID;
}
/*
判断PHPCMS中是否有此用户
*/
function hasuser($username)
{
global $conn2;
$res=MysqL_query("select userID from PHPCMS_member where username='".$username."'",$conn2);
$row=MysqL_fetch_array($res);
if($row[0]){
//有用户
return $row[0];
}else{
//没用户
return 0;
}
}
?>
需要的可以试用一下
完成了如下功能:
1、文章导入
2、评论导入
3、关键字导入
4、如果supesite中某个用户做了评论,则在PHPCMS中建立相应的帐号,并将评论和其绑定
使用方法:
1、因为没有导入分类,要在PHPCMS中手动建立同名分类,因为管理是根据分类名称关联的
2、修改conn1和conn2数据库地址、库名、用户、密码
3、将代码存为conv.PHP,放到PHPCMS根目录的 temp 文件夹中
4、以管理员身份登录PHPCMS
5、浏览器中运行localhost/temp/conv.PHP
需要说明的是:
1、数据库连接要改成自己的
2、代码中有些目录结构,表名要注意,可能你的环境和我的不一样
3、当运行conv.PHP?action=clean的时候,可以清空PHPCMS中的文章、评论、关键字等数据
4、function dump可以用更美观的形式打印array数组,用以调试
5、附件手动复制到相应的目录下就可以了,按supesite的结构复制过来attachments/***
6、因为我的PHPCMS是和ucenter整合的,所以导过来的用户在PHPCMS中,密码是什么无所谓的,以后的注册和登录验证都是走ucenter那边
7、只导入了supesite中已发表的文章,未审核通过和垃圾箱的都没有导入。评论也是只有审核过的
以上是内存溢出为你收集整理的Supesite7.0 转换导入phpcms 2008 sp3的方法全部内容,希望文章能够帮你解决Supesite7.0 转换导入phpcms 2008 sp3的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)