花了一个晚上时间,终于把博客改版了。原来ASP版的博客问题太多了,用起来很不方便。
现在博客采用DEDE系统,风格模板由 "一花一叶" 友情提供,这是它的博客地址: http://www.1h1y.cn/index.html ,这个风格我很喜欢,在此表此感谢!
改版大部分时间是花在数据导入上。原博客采用的是ACCESS数据库。好在之前就做过几次将Access数据库导入DEDE系统的案例,所以这次数据导入基本很顺利。
向DEDE中插入文章数据,需要插入三张表:blog_arctiny,blog_archives,blog_addonarticle 。
下面给出我本次导入数据使用的PHP脚本:
原Access数据库文章表的结构如下图所示:
<?php
// redice's Blog 数据导入DEDE程序
// by redice 2010.11.28
// 设置执行超时为不限时长
set_time_limit(0);
//exit;
// 栏目对应关系,即就是“原博客分类ID=>DEDE分类ID”这种对应关系
$maps = array(30=>11,
29=>7,
28=>2,
27=>5,
25=>13,
23=>9,
22=>12,
21=>13,
20=>4,
19=>13,
18=>6,
17=>10,
16=>8,
15=>5,
14=>3,
13=>10,
12=>1);
// 连接mdb数据库
$mdb_conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("redice2008@seeblog.mdb");
$mdb_conn->Open($connstr);
// 连接mysql数据库
$mysql_conn = mysql_connect("localhost","root","******");
if (!$mysql_conn)
{
die("不能打开数据库连接,错误: " . mysql_error());
}
// 选择数据库
mysql_select_db("rediceblog", $mysql_conn);
// 设置mysql数据库输出数据的字符集
mysql_query("set names 'gbk'");
$mdb_rs = new com("ADODB.RecordSet");
$mdb_rs->Open("select * from blog_content order by content_id asc",$mdb_conn,1,1);
$num=0;
while(! $mdb_rs->eof)
{
// 获取分类
$f = $mdb_rs->Fields("content_class");
$big_class=$f->value;
// 找到映射关系
// 目标分类ID
$typeid=$maps[$big_class];
if($typeid)
{
// 插入blog_arctiny
// 标题
$f = $mdb_rs->Fields("content_title");
$title=$f->value;
// 作者
$zuozhe='redice';
// 来源
$laiyuan="redice\'s Blog";
// 来源
$f = $mdb_rs->Fields("Content_Count");
$click=$f->value;
// 内容
$f = $mdb_rs->Fields("content_content");
$content=ubbcode(HTMLEncode($f->value));
// 处理图片
$content=str_replace("attachments2008@see","/uploads/files",$content);
// 转义
$content=str_replace("'","\'",$content);
//echo $content . "<br/><br/>";
// 时间
$f = $mdb_rs->Fields("content_time");
$addtime=$f->value;
$sql="insert into blog_arctiny (typeid,typeid2,arcrank,channel,senddate,sortrank,mid) values('$typeid',0,0,1,UNIX_TIMESTAMP('$addtime'),1282119815,1);";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
// 获取id
$aid=mysql_insert_id();
// 插入辅表
$sql="INSERT INTO `blog_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,weight)
VALUES ($aid,$typeid,0,1282119815,'',1,1,0,'$click',0,'$title','',
'','$zuozhe','$laiyuan','',UNIX_TIMESTAMP('$addtime'),UNIX_TIMESTAMP('$addtime'),1,0,'$title','$title','',1,0);";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
// 插入副表
$sql="insert into blog_addonarticle (aid,typeid,body,redirecturl,templet,userip) values($aid,$typeid,'$content','','','127.0.0.1');";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
echo $title . "-" . $aid . "<br/>";
$num++;
}
$mdb_rs->MoveNext();
//exit;
}
echo "共导入记录数: $num";
function HTMLEncode($str)
{
$str = str_replace("&","&",$str);
$str = str_replace(">",">",$str);
$str = str_replace("<","<",$str);
$str = str_replace(chr(9)," ",$str);
$str = str_replace(chr(32)," ",$str);
$str = str_replace(chr(34),""",$str);
$str = str_replace(chr(39),"'",$str);
$str = str_replace(chr(13),"",$str);
$str = str_replace(chr(10),"<br>",$str);
return $str;
}
function ubbcode($str)
{
//url
$str = preg_replace("/\[url=([^<>]*)\]([^<>]*)\[\/url\]/i","<a href='\${1}' target='_blank' >\${2}</a>",$str);
$str = preg_replace("/\[url\]([^<>]*)\[\/url\]/i","<a href='\${1}' target='_blank'>\${1}</a>",$str);
//file
$str = preg_replace("/\[file=([^<>]*)\]([^<>]*)\[\/file\]/i","<a href='\${1}'><b>File:</b> \${2}</a>",$str);
$str = preg_replace("/\[file\]([^<>]*)\[\/file\]/i","<a href='\${1}'><b>File:</b> \${2}</a>",$str);
//font style
$str = preg_replace("/\[color=([^<>\]]*)\]/i","<font color='\${1}'>",$str);
$str = str_replace("[/color]","</font>",$str);
$str = str_replace("[b]","<b>",$str);
$str = str_replace("[/b]","</b>",$str);
$str = str_replace("[u]","<u>",$str);
$str = str_replace("[/u]","</u>",$str);
$str = preg_replace("/\[size=(\d*)\]/i","<font size='\${1}'>",$str);
$str = str_replace("[/size]","</font>",$str);
//img
$str = preg_replace("/\[img\]([^<>]*)\[\/img\]/i","<img src='\${1}'/>",$str);
return $str;
}
?>
// redice's Blog 数据导入DEDE程序
// by redice 2010.11.28
// 设置执行超时为不限时长
set_time_limit(0);
//exit;
// 栏目对应关系,即就是“原博客分类ID=>DEDE分类ID”这种对应关系
$maps = array(30=>11,
29=>7,
28=>2,
27=>5,
25=>13,
23=>9,
22=>12,
21=>13,
20=>4,
19=>13,
18=>6,
17=>10,
16=>8,
15=>5,
14=>3,
13=>10,
12=>1);
// 连接mdb数据库
$mdb_conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("redice2008@seeblog.mdb");
$mdb_conn->Open($connstr);
// 连接mysql数据库
$mysql_conn = mysql_connect("localhost","root","******");
if (!$mysql_conn)
{
die("不能打开数据库连接,错误: " . mysql_error());
}
// 选择数据库
mysql_select_db("rediceblog", $mysql_conn);
// 设置mysql数据库输出数据的字符集
mysql_query("set names 'gbk'");
$mdb_rs = new com("ADODB.RecordSet");
$mdb_rs->Open("select * from blog_content order by content_id asc",$mdb_conn,1,1);
$num=0;
while(! $mdb_rs->eof)
{
// 获取分类
$f = $mdb_rs->Fields("content_class");
$big_class=$f->value;
// 找到映射关系
// 目标分类ID
$typeid=$maps[$big_class];
if($typeid)
{
// 插入blog_arctiny
// 标题
$f = $mdb_rs->Fields("content_title");
$title=$f->value;
// 作者
$zuozhe='redice';
// 来源
$laiyuan="redice\'s Blog";
// 来源
$f = $mdb_rs->Fields("Content_Count");
$click=$f->value;
// 内容
$f = $mdb_rs->Fields("content_content");
$content=ubbcode(HTMLEncode($f->value));
// 处理图片
$content=str_replace("attachments2008@see","/uploads/files",$content);
// 转义
$content=str_replace("'","\'",$content);
//echo $content . "<br/><br/>";
// 时间
$f = $mdb_rs->Fields("content_time");
$addtime=$f->value;
$sql="insert into blog_arctiny (typeid,typeid2,arcrank,channel,senddate,sortrank,mid) values('$typeid',0,0,1,UNIX_TIMESTAMP('$addtime'),1282119815,1);";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
// 获取id
$aid=mysql_insert_id();
// 插入辅表
$sql="INSERT INTO `blog_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,weight)
VALUES ($aid,$typeid,0,1282119815,'',1,1,0,'$click',0,'$title','',
'','$zuozhe','$laiyuan','',UNIX_TIMESTAMP('$addtime'),UNIX_TIMESTAMP('$addtime'),1,0,'$title','$title','',1,0);";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
// 插入副表
$sql="insert into blog_addonarticle (aid,typeid,body,redirecturl,templet,userip) values($aid,$typeid,'$content','','','127.0.0.1');";
// 执行
//echo $sql . "<br/>";
if(!mysql_query($sql,$mysql_conn)) echo mysql_error();
echo $title . "-" . $aid . "<br/>";
$num++;
}
$mdb_rs->MoveNext();
//exit;
}
echo "共导入记录数: $num";
function HTMLEncode($str)
{
$str = str_replace("&","&",$str);
$str = str_replace(">",">",$str);
$str = str_replace("<","<",$str);
$str = str_replace(chr(9)," ",$str);
$str = str_replace(chr(32)," ",$str);
$str = str_replace(chr(34),""",$str);
$str = str_replace(chr(39),"'",$str);
$str = str_replace(chr(13),"",$str);
$str = str_replace(chr(10),"<br>",$str);
return $str;
}
function ubbcode($str)
{
//url
$str = preg_replace("/\[url=([^<>]*)\]([^<>]*)\[\/url\]/i","<a href='\${1}' target='_blank' >\${2}</a>",$str);
$str = preg_replace("/\[url\]([^<>]*)\[\/url\]/i","<a href='\${1}' target='_blank'>\${1}</a>",$str);
//file
$str = preg_replace("/\[file=([^<>]*)\]([^<>]*)\[\/file\]/i","<a href='\${1}'><b>File:</b> \${2}</a>",$str);
$str = preg_replace("/\[file\]([^<>]*)\[\/file\]/i","<a href='\${1}'><b>File:</b> \${2}</a>",$str);
//font style
$str = preg_replace("/\[color=([^<>\]]*)\]/i","<font color='\${1}'>",$str);
$str = str_replace("[/color]","</font>",$str);
$str = str_replace("[b]","<b>",$str);
$str = str_replace("[/b]","</b>",$str);
$str = str_replace("[u]","<u>",$str);
$str = str_replace("[/u]","</u>",$str);
$str = preg_replace("/\[size=(\d*)\]/i","<font size='\${1}'>",$str);
$str = str_replace("[/size]","</font>",$str);
//img
$str = preg_replace("/\[img\]([^<>]*)\[\/img\]/i","<img src='\${1}'/>",$str);
return $str;
}
?>
ACCESS导入PHP脚本 |
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢