package IIbaeecde032f749e1cf53bc335cb08cc3::mod_wordpress; use strict; use LWP::UserAgent; use WordPress::XMLRPC; sub publish { my $class = shift; my ($blog, $subject, $message, $catz, $tags) = @_; my $error_header = "Error: "; my $rpc = _get_rpc($blog); return $error_header . $rpc unless ref($rpc); my $data = { title => $subject, description => $message, }; $data->{categories} = [ split(',', $catz) ] if $catz; $data->{mt_keywords} = $tags if $tags; $rpc->newPost($data) or return $error_header . $rpc->errstr; return; } sub listCatz { my $class = shift; my $blog = shift; my $rpc = _get_rpc($blog); return () unless ref($rpc); my $catz = $rpc->getCategories; return () unless $catz && ref($catz) eq 'ARRAY'; map { $_->{categoryName} } @$catz; } sub listTags { my $class = shift; my $blog = shift; my $rpc = _get_rpc($blog); return () unless ref($rpc); my $tags = $rpc->getTags; return () unless $tags && ref($tags) eq 'ARRAY'; map { $_->{name} } @$tags; } sub createCat { my $class = shift; my ($blog, $cat) = @_; my $rpc = _get_rpc($blog); return () unless ref($rpc); $rpc->newCategory({ name => $cat }); } sub _get_rpc { my $blog = shift; Zen->getRequest->getRequestCache->{BlogpubRPC}{$blog->{id}} ||= do { my $rpc_url = "$blog->{url}/xmlrpc.php"; my $ua = LWP::UserAgent->new; $ua->timeout(20); $ua->env_proxy; my $response = $ua->post($rpc_url); return $response->status_line unless $response->is_success; my $rpc = WordPress::XMLRPC->new; $rpc->username($blog->{username}); $rpc->password($blog->{password}); $rpc->proxy($rpc_url); $rpc->server or return $rpc->errstr; $rpc; }; } 1; 