原帖子
http://bbs.guoxue.com/viewthread ... p;extra=page%3D1###
phpBB2Discuz 转换程序
phpbb2.*升级到Discuz! 5.5.0
//
我们原来的国学论坛功能太少了,现在升级到Discuz! 5.5.0,效果还不错,基本上所有的信息全保留了!!
共享一下这次国学论坛转换所用的代码,个人认为和官方论坛上的提供的程序功能差不多 ,这个程序可以支持异机器之间的转换,不要求数据库在同一台机器上,
所有带有_s的变量表示数据源,带有_t后缀的变量表示目标数据,本程序暂不提供版主转换功能!
和官方提供的程序相比,本程序可多转换myposts和mythreads表,自动处理quote,[em]等标记
源论坛附件会被自动重命名和拷贝到相应的文件夹中。
呵呵,本人不提供程序正确的担保哦,如果丢失信息了,我也没法子!
主要函数:
//////////////////
convertForums(); //必须先运行这个转换
convertMsg($limit);
convertUser($limit); //如果出现错误,可修改username 为 binary 属性
convertAttachment($limit);
convertPosts($limit);
convertTopics($limit);
/////////////////
- <?php
- /*
- src=http://bbs.guoxue.com
- Author=zhanjun,gxbd
- version=1.0
- Date=2007-05-31
- */
- set_time_limit(0);
- echo "phpbb2.*升级到Discuz! 5.5.0\n";
- //////////////////////
- $cat_count=14; //大分类数量 ,为零的话由程序自动判断
- $attpath="/var/www/html/bbs/files/"; //附件所在位置
- $debug=0; //==0 正式转换 ==1 测试
- $len=3000; //测试数据条数
- $adminid=2; //管理员UID
- $charset='GBK'; //字符集
- //数据源 GBK编码 phpbb2.2.*
- $host_s='localhost';
- $dbuser_s='root' ;
- $dbpasswd_s='';
- $mydb_s='bbs';
- $prefix_s='phpbb_';
- $link_s=mysql_pconnect($host_s,$dbuser_s,$dbpasswd_s) or die("Could not connect ".mysql_error($link_s)."connect s err\n");
- mysql_query("SET NAMES '".$charset."'",$link_s);
- ////////////////////
- ////////////////////////
- //目标数据 Discuz! 5.5.0
- $host_t='0.0.0.0';
- $dbuser_t='root' ;
- $dbpasswd_t='';
- $prefix_t='bbs_';
- $link_t=mysql_pconnect($host_t,$dbuser_t,$dbpasswd_t,3306) or die("Could not connect ".mysql_error($link_t)."connect t err\n");
- mysql_query("SET NAMES '".$charset."'",$link_t);
- $mydb_s='bbs';
- $mydb_t='bbs';
- mysql_select_db($mydb_s,$link_s) or die("Could not select s database");;
- mysql_select_db($mydb_t,$link_t) or die("Could not select t database");;
- ////////////////////////
- if($debug==0)
- {
- $limit="";
- echo "正式转换模式 \n";
- }
- else
- {
- $limit=" LIMIT 0,$len";
- echo $limit ." 测试模式\n" ;
- }
- /////////////////////////
- /////////用户表转换函数
- function convertUser($limit=" LIMIT 0,30 "){
- global $prefix_t,$prefix_s,$link_s,$link_t,$adminid;
- mysql_query("TRUNCATE TABLE `".$prefix_t."members` ",$link_t);
- mysql_query("TRUNCATE TABLE `".$prefix_t."memberspaces` ",$link_t);
- mysql_query("TRUNCATE TABLE `".$prefix_t."memberfields` ",$link_t);
- $sql_s ="select * from ".$prefix_s."users order by user_id $limit";
- //echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- $_username=$r_s['username'];
- if (empty($_username) || htmlspecialchars($_username) != $_username || (strlen($_username)>=15)) {
- echo "非法用户名:uid = ".$r_s['user_id'] ." username = $_username 不能被转换!!\r\n";
- //continue;
- }
- if ($r_s['user_avatar_type'] == 2){
- $avatar = $r_s['user_avatar'];
- } else if ($r_s['user_avatar_type'] == 1 || $r_s['user_avatar_type'] == 3){
- $avatar = 'customavatars/'.$r_s['user_avatar'];
- }
- //等级转换
- if ($r_s['user_rank']>=1)
- {
- $groupid=11+$r_s['user_rank'];
- if ($groupid>=15) $groupid=15;
- //15==论坛元老 14==高级
- }
- else
- {
- if ($r_s['user_posts'] >=10)
- $groupid=11; //注册用户
- else
- $groupid=10;
- if ($r_s['user_posts'] >=100)
- $groupid=13; //高级用户
- }
- $isadmin=0;
- if ($r_s['user_id']==$adminid)
- {
- $groupid=1; //
- $isadmin=1;
- }
- $sigstatus=$r_s['user_sig'] ? 1 : 0;
- $sql_t="INSERT INTO `".$prefix_t."members` (`uid`, `username`, `password`, `secques`, `gender`, `adminid`, `groupid`, `groupexpiry`, `extgroupids`, `regip`, `regdate`, `lastip`, `lastvisit`, `lastactivity`, `lastpost`, `posts`, `digestposts`, `oltime`, `pageviews`, `credits`, `extcredits1`, `extcredits2`, `extcredits3`, `extcredits4`, `extcredits5`, `extcredits6`, `extcredits7`, `extcredits8`, `email`, `bday`, `sigstatus`, `tpp`, `ppp`, `styleid`, `dateformat`, `timeformat`, `pmsound`, `showemail`, `newsletter`, `invisible`, `timeoffset`, `newpm`, `accessmasks`, `editormode`, `customshow`, `xspacestatus`) VALUES (".$r_s['user_id'].", '".addslashes(trim($r_s['username']))."', '".$r_s['user_password']."', '', 0, ".$isadmin.", ".$groupid.", 0, '', '', ".$r_s['user_regdate'].", '', ".$r_s['user_lastvisit'].", ".$r_s['user_session_time'].", 0, ".$r_s['user_posts'].", 0, 0, 0, ".$r_s['user_posts'].", ".$r_s['user_posts'].", 0, 0, 0, 0, 0, 0, 0, '".$r_s['user_email']."','0000-00-00', ".$sigstatus.", 0, 0, 0, '', 0, 1, 1, 1, 0, '9999', 0, 0, 2, 26, 0);";
- //echo $sql_t."\n";
- if (!$result_t=mysql_query($sql_t,$link_t) )
- {
- //echo $sql_t."\n";
- continue; //去除重复错误
- }
- mysql_free_result($result_t);
- $sql_t="INSERT INTO `".$prefix_t."memberspaces` (`uid`,`style`, `description`, `layout`, `side`) VALUES (".$r_s['user_id'].", 'default', '', '[userinfo][calendar][myreplies][myfavforums] [myblogs][mythreads] ', 1)";
- //echo $sql_t."\n";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- $sql_t="INSERT INTO `".$prefix_t."memberfields` (`uid`, `nickname`, `site`, `alipay`, `icq`, `qq`, `yahoo`, `msn`, `taobao`, `location`, `customstatus`, `medals`, `avatar`, `avatarwidth`, `avatarheight`, `bio`, `sightml`, `ignorepm`, `groupterms`, `authstr`, `spacename`) VALUES (".$r_s['user_id'].", '', '', '', '".addslashes($r_s['user_icq'])."', '', '".addslashes($r_s['user_yim'])."', '".addslashes($r_s['user_msnm'])."', '', '', '', '', '".$avatar."', 83, 92, '', '".addslashes(parsesign ( convertbbcode( $r_s['user_sig'] ) ) )."', '', '', '', '')";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- }
- echo "用户表转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- }
- /////////////////////////
- /////////短消息表转换函数
- function convertMsg($limit=" LIMIT 0,30 "){
- global $prefix_t,$prefix_s,$link_s,$link_t;
- mysql_query("TRUNCATE TABLE `".$prefix_t."pms` ",$link_t);
- //order by s.privmsgs_from_userid
- $sql_s ="select s.*,t.*, u.username from ".$prefix_s."privmsgs as s ,".$prefix_s."privmsgs_text as t ,".$prefix_s."users as u where (t.privmsgs_text_id=s.privmsgs_id) and (u.user_id=s.privmsgs_from_userid) $limit";
- //echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."-s\n");
- while($r_s=mysql_fetch_array($result_s)){
- $box=$r_s['privmsgs_type'];
- if ($box=='0')
- $boxtype='inbox';
- else
- $boxtype='outbox';
- $sql_t="INSERT INTO `".$prefix_t."pms` (`pmid`, `msgfrom`, `msgfromid`, `msgtoid`, `folder`, `new`, `subject`, `dateline`, `message`, `delstatus`) VALUES (".$r_s['privmsgs_id'].", '".addslashes($r_s[username])."', ".$r_s['privmsgs_from_userid'].", ".$r_s['privmsgs_to_userid'].", '".$boxtype."', 0, '".addslashes($r_s['privmsgs_subject'])."', ".$r_s['privmsgs_date'].", '".addslashes(trim(convertbbcode($r_s['privmsgs_text'])) )."', 0)";
- //echo $sql_t."\n";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- }
- echo "短消息转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- }
- //新旧版面对应关系 +$cat_count;
- function convertForums($limit=" LIMIT 0,30 "){
- global $prefix_t,$prefix_s,$link_s,$link_t,$cat_count;
- mysql_query("TRUNCATE TABLE `".$prefix_t."forums` ",$link_t);
- mysql_query("TRUNCATE TABLE `".$prefix_t."forumfields` ",$link_t);
- $sql_s ="SELECT * FROM `".$prefix_s."categories` ORDER BY `cat_id` ASC " ;
- //echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- //大分类转换
- $sql_t="INSERT INTO `".$prefix_t."forums` (`fid`, `fup`, `type`, `name`, `status`, `displayorder`, `styleid`, `threads`, `posts`, `todayposts`, `lastpost`, `allowsmilies`, `allowhtml`, `allowbbcode`, `allowimgcode`, `allowanonymous`, `allowshare`, `allowpostspecial`, `allowspecialonly`, `alloweditrules`, `recyclebin`, `modnewposts`, `jammer`, `disablewatermark`, `inheritedmod`, `autoclose`, `forumcolumns`, `threadcaches`, `allowpaytoauthor`, `alloweditpost`, `simple`) VALUES (".$r_s['cat_id'].", 0, 'group', '".$r_s['cat_title']."', 1, ".$r_s['cat_order'].", 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0)";
- //echo $sql_t."\n";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- $sql_t="INSERT INTO `".$prefix_t."forumfields` VALUES (".$r_s['cat_id'].", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- }
- if ($cat_count=='')
- $cat_count=mysql_num_rows($result_s);
- echo "大分类表转换完成,共转换记录".$cat_count."条\n";
- $sql_s ="SELECT * FROM `".$prefix_s."forums` ORDER BY `forum_id` ASC" ;
- //echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- $fname=strlen($r_s['forum_name']) < 50 ? $r_s['forum_name'] : cutstr(htmlspecialchars(trim(@strip_tags($r_s['forum_name']))),50);
- $fid=$r_s['forum_id']+$cat_count;
- $gid=$r_s['cat_id'];
- //子分类转换
- $sql_t="INSERT INTO `".$prefix_t."forums` (`fid`, `fup`, `type`, `name`, `status`, `displayorder`, `styleid`, `threads`, `posts`, `todayposts`, `lastpost`, `allowsmilies`, `allowhtml`, `allowbbcode`, `allowimgcode`, `allowanonymous`, `allowshare`, `allowpostspecial`, `allowspecialonly`, `alloweditrules`, `recyclebin`, `modnewposts`, `jammer`, `disablewatermark`, `inheritedmod`, `autoclose`, `forumcolumns`, `threadcaches`, `allowpaytoauthor`, `alloweditpost`, `simple`) VALUES (".$fid.", ".$gid.", 'forum', '".$fname."', 1, ".$r_s['forum_order'].", 0, ".$r_s['forum_topics'].", ".$r_s['forum_posts'].", 0, '', 1, 0, 1, 1, 0, 1, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0)";
- //echo $sql_t."\n";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- $sql_t="INSERT INTO `".$prefix_t."forumfields` VALUES (".$fid.", '".addslashes($r_s['forum_desc'])."', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- }
- echo "子分类表转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- }
- ////////////////////////
- function convertTopics($limit=" LIMIT 0,30 "){
- echo "topic表转换\n";
- global $prefix_t,$prefix_s,$link_s,$link_t,$cat_count;
- mysql_query("TRUNCATE TABLE `".$prefix_t."threads` ",$link_t) or print(mysql_error($link_t))."\n";
- mysql_query("TRUNCATE TABLE `".$prefix_t."mythreads` ",$link_t) or print(mysql_error($link_t))."\n";
- $sql_s ="SELECT t.*,u.username FROM ".$prefix_s."topics as t , ".$prefix_s."users AS u where u.user_id=t.topic_poster $limit";
- // echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- //threads 转换
- $fid= $r_s['forum_id']+$cat_count;
- if($r_s['topic_first_post_id']==$r_s['topic_last_post_id'])
- {
- $lastposter=addslashes($r_s['username']);
- }
- else
- {
- $lastposter=htmlspecialchars(getusername($r_s['topic_last_post_id']));
- }
- $isgood=$r_s['topic_good'] ? 1 : 0;//精华帖子,如果没有装相应的mod,可以不管这个
- $sql_t="INSERT INTO `".$prefix_t."mythreads` (`uid`, `tid`, `dateline`) VALUES (".$r_s['topic_poster'].", ".$r_s['topic_id'].", ".$r_s['topic_time'].")";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- //echo $sql_t."\n";
- $sql_t="INSERT INTO `".$prefix_t."threads` VALUES (".$r_s['topic_id'].", ".$fid.", 0, 0, 0, 0, '".addslashes($r_s['username'])."', ".$r_s['topic_poster'].", '".addslashes(strip_tags($r_s['topic_title']))."', ".$r_s['topic_time'].", ".$r_s['topic_time'].", '".$lastposter."', ".$r_s['topic_views'].", ".$r_s['topic_replies'].", ".$r_s['topic_type'].", 0, ".$isgood.", 0, 0, 0, ".$r_s['topic_attachment'].", 0, 0, ".($r_s['isok']-1).", 0, 0)";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- }
- echo "topic表转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- }
- ///////////////////////
- function convertPosts($limit=" LIMIT 0,30 "){
- echo "posts表转换\n";
- global $prefix_t,$prefix_s,$link_s,$link_t,$cat_count;
- mysql_query("TRUNCATE TABLE `".$prefix_t."posts` ",$link_t) or print(mysql_error($link_t))."\n";
- mysql_query("TRUNCATE TABLE `".$prefix_t."myposts` ",$link_t) or print(mysql_error($link_t))."\n";
- $sql_s="SELECT p.*,t.post_subject, t.post_text, u.username FROM ".$prefix_s."posts AS p, ".$prefix_s."posts_text AS t, ".$prefix_s."users AS u WHERE ( p.`post_id` = t.post_id ) AND ( p.poster_id = u.user_id)
- order by t.post_id $limit ";
- //echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- //posts转换
- $fid= $r_s['forum_id']+$cat_count;
- $ip=decode_ip($r_s['poster_ip']);
- $sql_t="INSERT INTO `".$prefix_t."posts` (`pid`, `fid`, `tid`, `first`, `author`, `authorid`, `subject`, `dateline`, `message`, `useip`, `invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`, `smileyoff`, `parseurloff`, `attachment`, `rate`, `ratetimes`) VALUES (".$r_s['post_id'].", ".$fid.", ".$r_s['topic_id'].", 0, '".addslashes($r_s['username'])."',".$r_s['poster_id'].",'".addslashes($r_s['post_subject'])."', ".$r_s['post_time'].", '".addslashes(convertbbcode($r_s['post_text']))."', '".$ip."', 0, 0, 0, 0, 0, 0, 0, ".$r_s['post_attachment'].", 0, 0)";
- //echo $sql_t."\n";
- $result_t=mysql_query($sql_t,$link_t) or print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- $sql_t="INSERT INTO `".$prefix_t."myposts` (`uid`, `tid`, `pid`, `position`, `dateline`) VALUES (".$r_s['poster_id'].", ".$r_s['topic_id'].", ".$r_s['post_id'].", 2, ".$r_s['post_time'].")";
- if (!$result_t=mysql_query($sql_t,$link_t) )
- {
- //echo $sql_t."\n";
- //仅第一个回复写入mypost
- continue;
- }
- //print(mysql_error($link_t)."\n".$sql_t."\n");
- mysql_free_result($result_t);
- // echo $sql_t."\n";
- }
- echo "posts表转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- /////////////////////////////
- }
- ///////////////////////
- //附件转换
- function convertAttachment($limit=" LIMIT 0,30 "){
- echo "附件表转换\n";
- global $prefix_t,$prefix_s,$link_s,$link_t,$cat_count,$attpath,$debug;
- mysql_query("TRUNCATE TABLE `".$prefix_t."attachments` ",$link_t);
- $sql_s ="SELECT s.*,t.*, p.topic_id FROM `".$prefix_s."attachments` as s,".$prefix_s."attachments_desc as t ,".$prefix_s."posts as p where (s.attach_id=t.attach_id ) and (s.post_id=p.post_id) ORDER BY s.attach_id ASC $limit" ;
- echo $sql_s."\n";
- $result_s=mysql_query($sql_s,$link_s) or print(mysql_error($link_s)."\n".$sql_s."\n");
- while($r_s=mysql_fetch_array($result_s)){
- //大分类转换
- $topic_id=$r_s['topic_id'];
- $year=date("y",$r_s['filetime']);
- $month=date("m",$r_s['filetime']);
- $dir="month_".$year.$month;
- $attname=$dir."/".MD5($r_s['physical_filename']).".".$r_s['extension'];
- //批量修改附件名称和位置
- if ( !is_dir($dir)) {
- mkdir($dir);
- }
- $cmd="cp ".$attpath.$r_s['physical_filename']." ".$attname;
- $isimage = in_array($r_s['mimetype'], array('image/pjpeg', 'image/gif', 'image/bmp', 'image/png')) ? 1 : 0;
- if ($debug==0) system($cmd);
- $sql_t="INSERT INTO `".$prefix_t."attachments` (`aid`, `tid`, `pid`, `dateline`, `readperm`, `price`, `filename`, `description`, `filetype`, `filesize`, `attachment`, `downloads`, `isimage`, `uid`, `thumb`, `remote`) VALUES ('', ".$topic_id.", ".$r_s['post_id'].", ".$r_s['filetime'].", 0, 0, '".addslashes($r_s['real_filename'])."', '".addslashes($r_s['comment'])."', '".$r_s['mimetype']."', ".$r_s['filesize'].", '".$attname."', ".$r_s['download_count'].", ".$isimage.", ".$r_s['user_id_1'].", 0, 0)";
- $result_t=mysql_query($sql_t,$link_t) or die(mysql_error($link_t)."\n".$sql_t."\n");
- }
- echo "附件表转换完成,共转换记录".mysql_num_rows($result_s)."条\n";
- mysql_free_result($result_s);
- }
- function cutstr($string, $length) {
- $wordscut = '';
- if(strlen($string) > $length) {
- for($i = 0; $i < $length - 3; $i++) {
- if(ord($string[$i]) > 127) {
- $wordscut .= $string[$i].$string[$i + 1];
- $i++;
- } else {
- $wordscut .= $string[$i];
- }
- }
- return $wordscut;
- }
- return $string;
- }
- function convertbbcode($message) {
- $searcharray1 = array(
- '<i>',
- '</i>',
- '[REPLY]',
- '[/REPLY]',
- '</align>',
- '<BR>'
- );
- $replacearray1 = array(
- '[i]',
- '[/i]',
- '[hide]',
- '[/hide]',
- '[align]',
- '\n',
- );
- $searcharray2 = array(
- "/(\[[^\]]*?)(\:\w+)?]/is",
- "/\<P align=([^\[\<]+?)\>/is"
- );
- $replacearray2 = array(
- "\\1]",
- "[align=\\1]"
- );
- $message=preg_replace("/\[quote.*?\]/","[quote]",$message);
- $message=preg_replace("/\[em.*?\]/",":)",$message);
- return preg_replace($searcharray2, $replacearray2, str_replace($searcharray1, $replacearray1, $message));
- }
- function decode_ip($int_ip) {
- $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
- return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
- }
- function pid2uid($uid) {
- return $uid ? @mysql_result(mysql_query("SELECT poster_id FROM `".$prefix_s."posts` WHERE post_id='$uid' LIMIT 1"), 0) : 0;
- die($uid);
- }
- function pid2tid($uid) {
- return $uid ? @mysql_result(mysql_query("SELECT topic_id FROM `".$prefix_s."posts` WHERE post_id='$uid' LIMIT 1"), 0) : 0;
- }
- function getusername($uid) {
- $uid= pid2uid($uid);
- return $uid ? @mysql_result(mysql_query("SELECT username FROM `".$prefix_s."users` WHERE user_id='$uid' LIMIT 1"), 0) : 0;
- }
- ///下面这些功能函数直接修改至discuzz!网上的一个程序
- function parsesign($sign) {
- $searcharray = array(
- '[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]',
- '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
- '[list=A]', '[*]', '[/list]', '[indent]', '[/indent]'
- );
- $replacearray = array(
- '</font>', '</font>', '</font>', '</p>', '<b>', '</b>', '<i>',
- '</i>', '<u>', '</u>', '<ul>', '<ol type=1>', '<ol type=a>',
- '<ol type=A>', '<li>', '</ul></ol>', '<blockquote>', '</blockquote>'
- );
- $pregfind = array(
- "/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/|callto:\/\/|ed2k:\/\/){1}([^\["']+?)\s*\[\/url\]/ie",
- "/\[url=www.([^\["']+?)\](.+?)\[\/url\]/is",
- "/\[url=(https?|ftp|gopher|news|telnet|rtsp|mms|callto|ed2k){1}:\/\/([^\["']+?)\](.+?)\[\/url\]/is",
- "/\[email\]\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*\[\/email\]/i",
- "/\[email=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\](.+?)\[\/email\]/is",
- "/\[color=([^\[\<]+?)\]/i",
- "/\[size=([^\[\<]+?)\]/i",
- "/\[font=([^\[\<]+?)\]/i",
- "/\[align=([^\[\<]+?)\]/i",
- "/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is",
- "/\s*\[code\](.+?)\[\/code\]\s*/ies",
- "/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
- "/\[img=(\d{1,3})[x|\,](\d{1,3})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies"
- );
- $pregreplace = array(
- "cuturl('\\1\\2')",
- "<a href="http://www.\\1" target="_blank">\\2</a>",
- "<a href="\\1://\\2" target="_blank">\\3</a>",
- "<a href="mailto:\\1@\\2">\\1@\\2</a>",
- "<a href="mailto:\\1@\\2">\\3</a>",
- "<font color="\\1">",
- "<font size="\\1">",
- "<font face="\\1">",
- "<p align="\\1">",
- "<div class="altbg2" style="margin: 2em; margin-top: 3px; padding: 10px; border: ".INNERBORDERWIDTH."px solid ".BORDERCOLOR."; word-break: break-all">\\1</div>",
- "<div class="altbg2" style="margin: 2em; margin-top: 3px; clear: both; padding: 10px; padding-top: 5px; border: ".INNERBORDERWIDTH."px solid ".BORDERCOLOR."; word-break: break-all">\\1</div>",
- "bbcodeurl('\\1', '<img src="%s" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}" onclick="if(!this.resized) {return true;} else {window.open(\'%s\');}" onmousewheel="return imgzoom(this);" alt="" />')",
- "bbcodeurl('\\3', '<img width="\\1" height="\\2" src="%s" border="0" alt="" />')"
- );
- return daddslashes(str_replace($searcharray, $replacearray, preg_replace($pregfind, $pregreplace, stripslashes($sign))));
- }
- function bbcodeurl($url, $tags) {
- if(!preg_match("/<.+?>/s", $url)) {
- if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'ftp://', 'rtsp:/', 'mms://'))) {
- $url = 'http://'.$url;
- }
- return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url)));
- } else {
- return ' '.$url;
- }
- }
- function cuturl($url) {
- $length = 65;
- $urllink = "<a href="".(substr(strtolower($url), 0, 4) == 'www.' ? "http://$url" : $url).'" target="_blank">';
- if(strlen($url) > $length) {
- $url = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
- }
- $urllink .= $url.'</a>';
- return $urllink;
- }
- function daddslashes($string) {
- if(is_array($string)) {
- foreach($string as $key => $val) {
- $string[$key] = daddslashes($val);
- }
- } else {
- $string = addslashes($string);
- }
- return $string;
- }
- convertForums(); //必须先运行这个转换
- convertMsg($limit);
- convertUser($limit); //如果出现错误,可修改username 为 binary 属性
- convertAttachment($limit);
- convertPosts($limit);
- convertTopics($limit);
- mysql_close($link_s);
- mysql_close($link_t);
- echo "ok\n";
- ?>
复制代码 |