Created
September 19, 2012 07:55
-
-
Save Glowin/3748269 to your computer and use it in GitHub Desktop.
黑科技新网站迁移内容代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| set_time_limit(0); | |
| //连接 access 数据库 | |
| $conn = new com("ADODB.Connection"); | |
| $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("a.mdb"); | |
| $conn -> Open($connstr); | |
| $rs = new com("ADODB.RecordSet"); | |
| $sql = "select * from PE_Article"; | |
| $rs->Open( $sql, $conn, 1,1); | |
| //目的数据库 | |
| $db = mysql_connect('localhost:3306', 'root', 'li0621'); | |
| $db_name = 'usth-bak'; | |
| //处理文章的图片链接 | |
| //200604 200607 200608 200609 200612 | |
| $table_change = array(' class=MsoNormal '=>' '); | |
| $table_change += array('MARGIN: 0cm 0cm 0pt; '=>' '); | |
| $table_change += array('[InstallDir_ChannelDir]{$UploadDir}/201301'=>'http://www.usth.edu.cn/2013/01', | |
| ';;;'=>';', | |
| '\'Times New Roman\''=>'Tahoma', | |
| '\'TimesNewRoman,Bold\''=>'Tahoma,Bold', | |
| '\'Angsana New\''=>'Tahoma', | |
| '\''=>'"', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200601'=>'http://www.usth.edu.cn/wp-content/uploads/2006/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200602'=>'http://www.usth.edu.cn/wp-content/uploads/2006/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200603'=>'http://www.usth.edu.cn/wp-content/uploads/2006/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200604'=>'http://www.usth.edu.cn/wp-content/uploads/2006/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200605'=>'http://www.usth.edu.cn/wp-content/uploads/2006/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200606'=>'http://www.usth.edu.cn/wp-content/uploads/2006/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200607'=>'http://www.usth.edu.cn/wp-content/uploads/2006/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200608'=>'http://www.usth.edu.cn/wp-content/uploads/2006/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200609'=>'http://www.usth.edu.cn/wp-content/uploads/2006/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200610'=>'http://www.usth.edu.cn/wp-content/uploads/2006/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200611'=>'http://www.usth.edu.cn/wp-content/uploads/2006/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200612'=>'http://www.usth.edu.cn/wp-content/uploads/2006/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200701'=>'http://www.usth.edu.cn/wp-content/uploads/2007/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200702'=>'http://www.usth.edu.cn/wp-content/uploads/2007/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200703'=>'http://www.usth.edu.cn/wp-content/uploads/2007/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200704'=>'http://www.usth.edu.cn/wp-content/uploads/2007/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200705'=>'http://www.usth.edu.cn/wp-content/uploads/2007/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200706'=>'http://www.usth.edu.cn/wp-content/uploads/2007/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200707'=>'http://www.usth.edu.cn/wp-content/uploads/2007/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200708'=>'http://www.usth.edu.cn/wp-content/uploads/2007/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200709'=>'http://www.usth.edu.cn/wp-content/uploads/2007/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200710'=>'http://www.usth.edu.cn/wp-content/uploads/2007/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200711'=>'http://www.usth.edu.cn/wp-content/uploads/2007/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200712'=>'http://www.usth.edu.cn/wp-content/uploads/2007/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200801'=>'http://www.usth.edu.cn/wp-content/uploads/2008/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200802'=>'http://www.usth.edu.cn/wp-content/uploads/2008/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200803'=>'http://www.usth.edu.cn/wp-content/uploads/2008/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200804'=>'http://www.usth.edu.cn/wp-content/uploads/2008/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200805'=>'http://www.usth.edu.cn/wp-content/uploads/2008/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200806'=>'http://www.usth.edu.cn/wp-content/uploads/2008/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200807'=>'http://www.usth.edu.cn/wp-content/uploads/2008/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200808'=>'http://www.usth.edu.cn/wp-content/uploads/2008/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200809'=>'http://www.usth.edu.cn/wp-content/uploads/2008/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200810'=>'http://www.usth.edu.cn/wp-content/uploads/2008/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200811'=>'http://www.usth.edu.cn/wp-content/uploads/2008/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200812'=>'http://www.usth.edu.cn/wp-content/uploads/2008/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200901'=>'http://www.usth.edu.cn/wp-content/uploads/2009/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200902'=>'http://www.usth.edu.cn/wp-content/uploads/2009/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200903'=>'http://www.usth.edu.cn/wp-content/uploads/2009/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200904'=>'http://www.usth.edu.cn/wp-content/uploads/2009/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200905'=>'http://www.usth.edu.cn/wp-content/uploads/2009/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200906'=>'http://www.usth.edu.cn/wp-content/uploads/2009/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200907'=>'http://www.usth.edu.cn/wp-content/uploads/2009/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200908'=>'http://www.usth.edu.cn/wp-content/uploads/2009/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200909'=>'http://www.usth.edu.cn/wp-content/uploads/2009/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200910'=>'http://www.usth.edu.cn/wp-content/uploads/2009/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200911'=>'http://www.usth.edu.cn/wp-content/uploads/2009/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/200912'=>'http://www.usth.edu.cn/wp-content/uploads/2009/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201001'=>'http://www.usth.edu.cn/wp-content/uploads/2010/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201002'=>'http://www.usth.edu.cn/wp-content/uploads/2010/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201003'=>'http://www.usth.edu.cn/wp-content/uploads/2010/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201004'=>'http://www.usth.edu.cn/wp-content/uploads/2010/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201005'=>'http://www.usth.edu.cn/wp-content/uploads/2010/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201006'=>'http://www.usth.edu.cn/wp-content/uploads/2010/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201007'=>'http://www.usth.edu.cn/wp-content/uploads/2010/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201008'=>'http://www.usth.edu.cn/wp-content/uploads/2010/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201009'=>'http://www.usth.edu.cn/wp-content/uploads/2010/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201010'=>'http://www.usth.edu.cn/wp-content/uploads/2010/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201011'=>'http://www.usth.edu.cn/wp-content/uploads/2010/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201012'=>'http://www.usth.edu.cn/wp-content/uploads/2010/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201101'=>'http://www.usth.edu.cn/wp-content/uploads/2011/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201102'=>'http://www.usth.edu.cn/wp-content/uploads/2011/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201103'=>'http://www.usth.edu.cn/wp-content/uploads/2011/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201104'=>'http://www.usth.edu.cn/wp-content/uploads/2011/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201105'=>'http://www.usth.edu.cn/wp-content/uploads/2011/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201106'=>'http://www.usth.edu.cn/wp-content/uploads/2011/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201107'=>'http://www.usth.edu.cn/wp-content/uploads/2011/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201108'=>'http://www.usth.edu.cn/wp-content/uploads/2011/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201109'=>'http://www.usth.edu.cn/wp-content/uploads/2011/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201110'=>'http://www.usth.edu.cn/wp-content/uploads/2011/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201111'=>'http://www.usth.edu.cn/wp-content/uploads/2011/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201112'=>'http://www.usth.edu.cn/wp-content/uploads/2011/12', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201201'=>'http://www.usth.edu.cn/wp-content/uploads/2012/01', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201202'=>'http://www.usth.edu.cn/wp-content/uploads/2012/02', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201203'=>'http://www.usth.edu.cn/wp-content/uploads/2012/03', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201204'=>'http://www.usth.edu.cn/wp-content/uploads/2012/04', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201205'=>'http://www.usth.edu.cn/wp-content/uploads/2012/05', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201206'=>'http://www.usth.edu.cn/wp-content/uploads/2012/06', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201207'=>'http://www.usth.edu.cn/wp-content/uploads/2012/07', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201208'=>'http://www.usth.edu.cn/wp-content/uploads/2012/08', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201209'=>'http://www.usth.edu.cn/wp-content/uploads/2012/09', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201210'=>'http://www.usth.edu.cn/wp-content/uploads/2012/10', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201211'=>'http://www.usth.edu.cn/wp-content/uploads/2012/11', | |
| '[InstallDir_ChannelDir]{$UploadDir}/201212'=>'http://www.usth.edu.cn/wp-content/uploads/2012/12', | |
| ); | |
| /* | |
| ' mso-ascii-font-family: \'Times New Roman\''=>'', | |
| ' mso-hansi-font-family: \'Times New Roman\''=>'', | |
| ' mso-fareast-font-family: \'TimesNewRoman,Bold\';'=>'', | |
| ' style="mso-hansi-font-family: \'Times New Roman\'"'=>'', | |
| */ | |
| while( !$rs -> eof) { | |
| //文章ID | |
| $id = $rs -> Fields(0); | |
| //文章作者,此处为默认值为 1 | |
| $author = 1; | |
| //发表时间 | |
| $date = $rs -> Fields(14); | |
| $date = strtr($date,"/","-"); | |
| //发表的 gmt 时间 | |
| $date_gmt = '0000-00-00 00:00:00'; | |
| //文章内容 | |
| $content = $rs -> Fields(19); | |
| $content = strtr($content, $table_change); | |
| ////echo $content.'<br />'; | |
| //文章标题 | |
| $title = $rs -> Fields(3); | |
| //文章状态 | |
| $status = 'publish'; | |
| //评论状态 | |
| $comment_status = 'closed'; | |
| //ping 状态 | |
| $ping_status = 'open'; | |
| //文章名的域名编码 | |
| $name = $rs -> Fields(3); | |
| $name = substr(urlencode($name),0, 200);//编码文字为%形式 | |
| //文章修改时间 | |
| $modified = $rs -> Fields(14); | |
| $modified = strtr($modified, "/","-"); | |
| //文章修改的GMT时间 | |
| $modified_gmt = '0000-00-00 00:00:00'; | |
| //父目录 | |
| //wordpress object_id 对应的是 文章ID,term_taxonomy_id对应的是父目录的id | |
| //科院新闻 1001 3 news | |
| //科>高教荟萃 1002 5 feature | |
| //科>重要政策 1002 9 feature | |
| //科>重要信息 1002 10 feature | |
| //科>重要讲话 1002 11 feature | |
| //科>重要文章 1002 12 feature | |
| //院系动态 1003 6 institute-trend | |
| //其他 1004 7 others | |
| //公告 1004 4 announce | |
| //学术动态 1005 8 academic-trend | |
| $parentID = $rs -> Fields(1); | |
| switch($parentID) { | |
| case 1001: | |
| $parent = 3; | |
| break; | |
| case 1002: | |
| $parent = 5; | |
| break; | |
| case 1003: | |
| $parent = 6; | |
| break; | |
| case 1004: | |
| $parent = 4; | |
| break; | |
| case 1005: | |
| $parent = 8; | |
| break; | |
| default: | |
| $parent = 1; | |
| break; | |
| } | |
| $guid = 'http://www.usth.edu.cn/?p='.$id;//文章的域名 | |
| $menu_order = 0; | |
| $post_type = 'post'; | |
| //$post_mine_type = $rs -> Fields(11); | |
| $comment_count = 0; | |
| //mysql的term_relationship 表为文章对应的分类列表,object_id对应相应的文章,term_taxonomy_id 对应着相应的分类。', term_taxonmy_id= '.$parent.', term_order=0';object_id= '.$id | |
| $update = 'INSERT usth_posts SET ID='.$id.', post_author='.$author.', post_date='.$date.', post_date_gmt='.$date_gmt.', post_content="'.$content.'", post_title="'.$title.'", post_status='.$status.', comment_status='.$comment_status.', ping_status='.$ping_status.', post_name='.$name.', post_modified='.$modified.', post_modified_gmt='.$modified_gmt.', post_parent=0 guid='.$guid.', menu_order='.$menu_order.', post_type='.$post_type.', comment_count= '.$comment_count; | |
| $select = 'select option_id from usth_options'; | |
| $insert = 'INSERT INTO usth_posts ( | |
| ID, | |
| post_author, | |
| post_date, | |
| post_date_gmt, | |
| post_content, | |
| post_title, | |
| post_excerpt, | |
| post_status, | |
| comment_status, | |
| ping_status, | |
| post_name, | |
| to_ping, | |
| pinged, | |
| post_modified, | |
| post_modified_gmt, | |
| post_content_filtered, | |
| post_parent, | |
| guid, | |
| menu_order, | |
| post_type, | |
| comment_count | |
| ) VALUES ( | |
| '.$id.', | |
| '.$author.', | |
| \''.$date.'\', | |
| \''.$date_gmt.'\', | |
| \''.$content.'\', | |
| \''.$title.'\', | |
| \'\', | |
| \''.$status.'\', | |
| \''.$comment_status.'\', | |
| \''.$ping_status.'\', | |
| \''.$name.'\', | |
| \'\', | |
| \'\', | |
| \''.$modified.'\', | |
| \''.$modified_gmt.'\', | |
| \'\', | |
| \'0\', | |
| \''.$guid.'\', | |
| \''.$menu_order.'\', | |
| \''.$post_type.'\', | |
| '.$comment_count.' | |
| )'; | |
| $insert1 = 'INSERT INTO usth_term_relationships (object_id, term_taxonomy_id, term_order) | |
| VALUES('.$id.','.$parent.',0) | |
| '; | |
| mysql_select_db( $db_name, $db); | |
| mysql_query('SET NAMES \'gbk\''); | |
| mysql_query('SET CHARACTER_SET \'gbk\''); | |
| if(! (mysql_query($insert, $db) && mysql_query($insert1, $db))) { | |
| echo '<h1>error!</h1>'; | |
| echo mysql_error().'<br />'; | |
| echo $insert."<br />"; | |
| echo $insert1."<br />"; | |
| } else { | |
| echo '<h1>success</h1>'; | |
| } | |
| $rs -> MoveNext(); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment