BBS-DiscuzX2
view release on metacpan or search on metacpan
lib/BBS/DiscuzX2.pm view on Meta::CPAN
#ABSTRACT: DISCUZ X2 å¸åå¤ç
=pod
=encoding utf8
=head1 NAME
BBS::DiscuzX2
=over
=back
=head1 DESCRIPTION
Discuz X2 è´´åå¤çå¨
=over
=back
=head1 SYNOPSIS
注æï¼æ°æ®åºä¸ç表ååç¼åºå®ä¸ºpre_
=over
=back
=head1 FUNCTION
=head2 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',
);
=over
=back
=head2 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',
});
=over
=back
=head2 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',
lib/BBS/DiscuzX2.pm view on Meta::CPAN
'save' => '',
'uploadalbum' => '',
],
);
return unless($res->is_success);
my ($tid, $pid) = $res->as_string =~ m[action=edit&fid=\d+&tid=(\d+)&pid=(\d+)&]s;
return {
tid => $tid,
pid => $pid,
response => $res,
};
}
#sub append_thread {
# my ($self, $data) = @_;
# my $url = "$self->{site}forum.php?mod=misc&action=postappend&tid=$data->{tid}&pid=$data->{pid}&extra=&postappendsubmit=yes&infloat=yes";
# my $res = $self->{browser}->post($url,
# [
# 'formhash' => $self->{formhash},
# 'postappendmessage' => $data->{message},
# 'handlekey' => 'postappend',
# ],
# );
#
# return unless($res->is_success);
# return $res;
#}
sub delete_thread {
my ($self, $data) = @_;
my $url = "$self->{site}forum.php?mod=post&action=edit&extra=&editsubmit=yes";
my $referer = "$self->{site}forum.php?mod=post&action=edit&fid=$data->{fid}&tid=$data->{tid}&pid=$data->{pid}&page=1";
$self->{browser}->add_header('Referer' => $referer);
my $res = $self->{browser}->post($url,
[
fid => $data->{fid},
tid => $data->{tid},
pid => $data->{pid},
formhash => $self->{formhash},
allownoticeauthor => $data->{notice_author} // 1,
delattachop => $data->{del_attach} || 0,
delete => 1,
],
);
return unless($res->is_success);
return 1;
}
sub init_db_handler {
my ($self, %db_opt) = @_;
$db_opt{db_port} ||= 3306;
my $dsn = "DBI:mysql:host=$db_opt{db_host};port=$db_opt{db_port};database=$db_opt{db_name}";
$self->{db_handler} = BBS::DiscuzX2::DB->new(
connect_info => [ $dsn, $db_opt{db_user}, $db_opt{db_passwd} ]
);
if($db_opt{db_charset}){
$self->{db_handler}->do("SET character_set_client='$db_opt{db_charset}'");
$self->{db_handler}->do("SET character_set_connection='$db_opt{db_charset}'");
$self->{db_handler}->do("SET character_set_results='$db_opt{db_charset}'");
}
for my $k (qw/default_passwd default_group_id/){
next unless(exists $db_opt{$k});
$self->{db_handler}{$k} = $db_opt{$k};
}
$self;
}
sub create_user {
my ($self,$data) = @_;
$self->{db_handler}->create_user($data);
}
sub load_thread {
my ($self,$data) = @_;
$self->{db_handler}->load_thread($data);
}
1;
( run in 0.580 second using v1.01-cache-2.11-cpan-6aa56a78535 )