bo-blog1.7x 转x-space2.x的简单代码

上一篇 / 下一篇  2007-03-07 04:39:52 / 个人分类:LAMP

写的比较简单
&} f*Asx8i O0
5\ t#]L&SN0<?
_m rJ`(_$U.OA\3F"_0# bo-blog 1.x 转换程序for 平凡的香草
"tpn3x7p4P`0# x-space中已经导入部分日志,来源是由bo-blog1.7升级后的bo-blog2.x木铎校园 BBS 社区cP3fK0i5d;VM3HN%E ]
# 但是在 bo-blog 1.7 升级到2.x的过程中,丢了了大量(300)篇日志(无法导入),一直没有补上
'Q[/B&Q5Pm h0# 借从bo-blog转换到x-space的机会,将原来的日志一并导入。这部分代码是专门用来处理1.7升级过程中无法导入的那部分日志的木铎校园 BBS 社区}];Wp:b
# 只导入日志,不处理其他内容木铎校园 BBS 社区m)t,[2A#E Ua8luz
# 补充:经过检查,发现bo-blog 1.x 文本版通过 list.php 文件作为索引,之前无法导入的日志,主要是由于list.php不再完整。
m DcU8j!o `7] `Tz0# 两种思路,1,修正list的php,导入数据库版本blog,然后再通过程序转换木铎校园 BBS 社区!}"eu4UiseXg4P
#            2,直接读类别列表,通过帖子时间检查是否已经导入x-space,如果没有,则直接从文件中读取数据,然后导入x-space
AYH1Yy B-H`0$target_server    = "localhost:/tmp/mysql.sock";
z/Bg a4e1WV0$target_db        = "discuz5_gbk";
T0I/A9qRh0$target_db_user = 'root';木铎校园 BBS 社区7m._7[2f_
$target_db_pw    = '';
0N:PNF,s.fW/E8J0$catid            = 32; #你想转入的类别id
+pc$]*c2w7sjw9U0$itemtypeid     = 55; # 你想转入的个人分类id木铎校园 BBS 社区s?(Lo%e?:G
$uid            = 3434324; #转入用户的uid,discuz的uid木铎校园 BBS 社区1@ Rr i%v3A
$username        = 'xxxx';  #转入用户的用户名
Af9ez~(^ j2z~0v0$username        = addslashes($username);
7l P|P,|UH&J1w2_&q0$datadir        = 'ofJ8Ls09';
+F1D t ZI`nE6m0$listfiles        = array('1.php','2.php','3.php','4.php','5.php','6.php','7.php','8.php','9.php','10.php','11.php','12.php');
!iy4L/l}0$line_array        = array();
}&qW"Ij?9t1e0木铎校园 BBS 社区6~pNI8W'lSP
$target_link = mysql_connect($target_server,$target_db_user,$target_db_pw);木铎校园 BBS 社区"N'R7G!?CT0g
if($target_link){木铎校园 BBS 社区P4g)}a8Q!]PNs
    mysql_select_db($target_db);木铎校园 BBS 社区;vW,LN @7t
}else {
/m l$S8we#{Qf:`;s%Gt0    echo "Connect to $target_server:$target_db with $target_db_user ERRor!";木铎校园 BBS 社区rPbN2JM/eJ
}
$M7dnS,XV x!M0
"Qh0~;~4uMu$Ex0if (is_dir($datadir)) {
n2T*p+S0x]6a0    if ($dh = opendir($datadir)) {
$I x M+f|%R _0        /*
*@a[x ^)h@-m0        while (($file = readdir($dh)) !== false) {
r.A:Md9e Kpo Id'P0            echo "filename: $file : filetype: " . filetype("$datadir/$file") . "\n";木铎校园 BBS 社区|4mqU EX
        }木铎校园 BBS 社区$|tYhV ^&u!|
        closedir($dh);
$};O I]KhHq;P&zj;E0        */木铎校园 BBS 社区P)ud6E`4Y(PAkoV
    }else {木铎校园 BBS 社区j3g bRJH
        echo "opendir error \n";木铎校园 BBS 社区9m,t8x d-Y4h9KZ:v8_"v
        exit(1);
@g!SG'E L0{0    }木铎校园 BBS 社区*]cnLInfF+~
    closedir($datadir);
3?$A~9G,\"D"wv0}木铎校园 BBS 社区:\)m8chR;[-\.p |!s _2U;P
foreach ($listfiles as $listfile) {木铎校园 BBS 社区%Rc At1A
    echo "\n Listfile : $listfile\n";
0bA^._&g-iv0    if($list = file("$datadir/$listfile")){木铎校园 BBS 社区 J]!N$MV"~.]
        foreach ($list as $line){
#j{rt k{TwE0             $line_array = explode('|',$line);木铎校园 BBS 社区5Y.m7}kJ:Cr
             print_r($line_array[1]);木铎校园 BBS 社区SeEmRf5T
             print("\n");木铎校园 BBS 社区M;]a-kKAf0e
             if($content = file_get_contents("$datadir/$line_array[1].art")){木铎校园 BBS 社区re-Ivd|X
                 $content = addslashes(convert_utf82gbk($content));
1~N*z5AZ`0             }else {木铎校园 BBS 社区%`3S+G'iI&a
                 echo "File_get_contents Error \n";木铎校园 BBS 社区%Xo ?;u e
                 exit(1);木铎校园 BBS 社区 ]3H/I:O ]c8pk.Y'{
             }木铎校园 BBS 社区 y4@dXhI8l$q_;Y
             $query_select = "select dateline from {$target_db}.supe_spaceitems where dateline=$line_array[3];";木铎校园 BBS 社区F%w dS,{
             if(mysql_query($query_select)){木铎校园 BBS 社区x)M ojE^
                 $num_rows = mysql_num_rows($result);木铎校园 BBS 社区+R`8f)F`E
                 if($num_rows>1){木铎校园 BBS 社区7Th!F2z8Q)},e
                     continue;    
:FZJRj3p5Z:I0                 }木铎校园 BBS 社区oE'U6E/_MA(~7w
             }
'q fN/J h0                print("\n\n");
*S%]MR8\VK"f0                $tid        =    0;            // 对应论坛主题 id
]QHF(D"ONP0                #$username    =    $i['username'];木铎校园 BBS 社区/[y G-[Xms3l YX7M
                #$itemtypeid    =    $i['dirid'];        // 个人分类ID
_;{x/G&Z0                $type        =    'blog';木铎校园 BBS 社区"C\,q5vC2x&}
                $subtype    =    '';            // 信息分类型木铎校园 BBS 社区fE i G'{X
                $subject    =    addslashes(convert_utf82gbk($line_array[2]));
9WV}8Q _:en-N'v0                $dateline    =    $line_array[3];木铎校园 BBS 社区3M'l%g)J*F+`6q8t!\r#D
                $lastpost    =    0;
}&u?K!r*o]0                $viewnum    =    $line_array[4];            // 点击次数木铎校园 BBS 社区D _-eINS
                $replynum    =    0;木铎校园 BBS 社区]'Js J\%O
                $trackbacknum    =    0;        // Trackback 数木铎校园 BBS 社区^tZ]"D m5T
                $goodrate    =    0;木铎校园 BBS 社区,sV9u'y9e2MW,Ahk
                $badrate    =    0;
4FFX,J)tw6y0                $digest        =    0;
t;HWFI Lou0                $top        =    0;木铎校园 BBS 社区$G-J(Es6Q
                $allowreply    =    1;
L!F+aO)s/n0                $folder        =    1;木铎校园 BBS 社区|5U({\\0[
                $haveattach    =    0;
lp F)Dm PU#t0                $grade        =    0;   木铎校园 BBS 社区&\7m C4Jl~ qe9N1^
                $query_insert = "INSERT INTO {$target_db}.supe_spaceitems (`catid`, `uid`, `tid`, `username`, `itemtypeid`, `type`, `subtype`, `subject`, `dateline`, `lastpost`, `viewnum`, `replynum`, `trackbacknum`, `goodrate`, `badrate`, `digest`, `top`, `allowreply`,  `folder`, `haveattach`, `grade`) VALUES('$catid', '$uid', '$tid', '$username', '$itemtypeid', '$type', '$subtype', '$subject', '$dateline', '$lastpost', '$viewnum', '$replynum', '$trackbacknum', '$goodrate', '$badrate', '$digest', '$top', '$allowreply', '$folder', '$haveattach', '$grade');";木铎校园 BBS 社区bzc;DW
                print_r ($query_insert);木铎校园 BBS 社区 d"r+X n)o!O
                echo "\n";
s'ko Vq{ {0                $includetags = '';
7y-r0W@'n+Eyg0                $message = $content;木铎校园 BBS 社区7f/|.[n6m
                
)wMW!mZ0                #exit(0);木铎校园 BBS 社区-u&Ob@It
                if(mysql_query($query_insert,$target_link)){
'Rj&W5W0S[4sx0                    $itemid        = mysql_insert_id($target_link);               
ZW XaIpD5h Qt0                    $hash        = substr(md5($itemid), 8, 16);    // 表单关联            木铎校园 BBS 社区F6b)S-T(QzU
                    $query_update    = "update {$target_db}.supe_spaceitems set hash='$hash' where itemid='$itemid';";木铎校园 BBS 社区 T'}Z Cg,@{3ec6M
                    print_r($query_update);木铎校园 BBS 社区C B Q0O+S3]E:o
                    if(mysql_query($query_update,$target_link)){木铎校园 BBS 社区.YX`a-DH3Pp
                        echo "convert subject:$subject \n\n";                   木铎校园 BBS 社区0]!DbsC*C{?
                    }else {
c(d:v0_rX jz-M0                        echo mysql_error();
;[!F'UE G$QO6`0                        exit(1);木铎校园 BBS 社区J{$\P)mE
                    }木铎校园 BBS 社区 YB N0soa|
                    $query_insert_content = "INSERT INTO {$target_db}.supe_spaceblogs (`itemid`, `message`, `relativetags`, `postip`, `relativeitemids`, `customfieldid`, `customfieldtext`, `includetags`, `mood`, `weather`) VALUES ('$itemid', '$message', '$relativetags', '$postip', '$relativeitemids', '$customfieldid', '$customfieldtext', '$includetags', '$mood', '$weather');";木铎校园 BBS 社区7g;[%e o/OE5V
                    echo "\n $query_insert_content \n";木铎校园 BBS 社区9\Nd E+c
                    #$query_insert_content = $post['content'];
/] U@"x,d0                    #exit(0);木铎校园 BBS 社区 tkIT1v(`\!i B5T
                    if(mysql_query($query_insert_content,$target_link)){
7? HP*v0mgvE_1d0                        echo "inster into supe_spaceblogs $itemid\n";
o%?&nf-f2W:p0                    }else {木铎校园 BBS 社区mQ(X/~WX!MMz;E
                        echo mysql_error();
qH#mo7L5I/Q4U0                        exit(1);
+mL)r {5C0                    }木铎校园 BBS 社区4w B-H2B f'z&f|'NW(y
                }else {木铎校园 BBS 社区WzPZ|e
                    echo mysql_error();
:}3Yw)PBwq0                    exit(1);
w5tGC)|@}4]0                }木铎校园 BBS 社区6T,UYS!uxNX3A9CA
        }木铎校园 BBS 社区f \7O+R!L
    }else {
M/h&Y,AO/g6m| k+b0        echo "file() $filelist error\n";
1dg_6L A A1Z&^0        exit(1);
q6UKe4qj0    }   
A/ruHH0}
_]%C%y7?^Q3G%\0
QjjP T;@i1?5PC0mysql_close();
S[${s|'Z4W1p7oG_0木铎校园 BBS 社区LET%Dqo*`
echo "\n All have convert into x-space \n";木铎校园 BBS 社区l?e0PD$o7m-g

L r{%v2c7O Xq0function daddslashes($string) {
8k7}(_&[7zey0    if(!@ini_get('register_globals') || !get_magic_quotes_gpc()) {木铎校园 BBS 社区L7R;@-T XrCjka
        if(is_array($string)) {木铎校园 BBS 社区4j cN R `4No
            foreach($string as $key => $val) {木铎校园 BBS 社区 k [@D/v5b)LWY~
                $string[$key] = daddslashes($val);木铎校园 BBS 社区;?e\~s|%Z
            }木铎校园 BBS 社区 }u&XoC(Up4x
        } else {木铎校园 BBS 社区D"G4p-D-y8|4I~G(N,N
            $string = addslashes($string);
(G i+f;p:j0        }
^mK b$Ix)UBB0    }
Q}+F'S*Ycs0    return $string;
D/J1z+~:mjd#La0}
o2kk;?Ef0木铎校园 BBS 社区FL!Hw_(aQ Y
function convert_utf82gbk($msg) {木铎校园 BBS 社区8o ^ P&gB
    return iconv('UTF-8','gbk', $msg);木铎校园 BBS 社区 sQ~F])J/Y[kG\
}
XTn U7Yg6Y0?>
9w0WlF O0

TAG: LAMP

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

关于作者