NAME
BBS::DiscuzX2
DESCRIPTION
Discuz X2 贴子处理器
SYNOPSIS
注意:数据库中的表名前缀固定为pre_
FUNCTION
init_db_handler
#初始化
my $bbs = BBS::DiscuzX2->new();
#初始化后台数据库连接
#dp_port / db_charset 也可不填
$bbs->init_db_handler(
db_host => 'xxx.xxx.xxx.xxx',
db_port => 3306,
db_user => 'xxx',
db_passwd => 'xxx',
db_name => 'xxx',
db_charset => 'utf8',
);
create_user
#后台新建论坛用户
#如果passwd未指定,则采用default_passwd
#group_id 为用户所在群组,如果未指定,则采用default_group_id
#mail/user_ip可不填
$bbs->{db_handler}{default_passwd} = 'ashaxj';
$bbs->{db_handler}{default_group_id} = 10;
my $uid = $bbs->create_user({
user => 'xxx',
passwd => 'xxx',
group_id => 10,
mail => 'xxx@xxx.xxx',
user_ip => 'xxx.xxx.xxx.xxx',
});
load_thread
#从后台向 版块10 载入一个贴子
my $data = {
fid => 10,
floors => [
{ poster => 'abc', subject => 'test', dateline => '2013-03-05 11:20:00',
message => 'just a test', user_ip => '123.123.123.123',
is_html => 0, is_bbcode => 1,
},
{ poster => 'def', dateline => '2013-03-05 11:21:00',
message => 'just a test reply', user_ip => '222.222.222.222',
},
{ poster => 'ghi', dateline => '2013-03-06 10:00:03',
message => 'just a test reply update', user_ip => '202.202.202.202',
},
],
};
my $tid = $self->load_thread($data);
init_browser
#初始化浏览器
$bbs->init_browser(
'User-Agent' =>
'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0',
);
login
#用户登录
$bbs->login(
site => 'http://127.0.0.1/discuz_x2/',
user => 'xxx',
passwd => 'xxx',
);
post_thread
#在版块2发新帖
my $r = $bbs->post_thread({
fid => 2,
subject => 'hello world',
message => 'just a test ',
});
#$r->{tid}为贴子编号
#$r->{pid}为贴子内容编号
#$r->{res}为返回的html response
delete_thread
#删帖
$bbs->delete_thread({
fid => 2,
tid => 6,
pid => 9,
});