Skip to content

Instantly share code, notes, and snippets.

@segphault
Created January 18, 2009 19:19
Show Gist options
  • Save segphault/48749 to your computer and use it in GitHub Desktop.
Save segphault/48749 to your computer and use it in GitHub Desktop.
Movable Type XML-RPC enhancement
sub _get_entries {
my $class = shift;
my %param = @_;
my($blog_id, $user, $pass, $num, $titles_only) =
@param{qw( blog_id user pass num titles_only )};
my $obj_type = $param{page} ? 'page' : 'entry';
my $mt = MT::XMLRPCServer::Util::mt_new(); ## Will die if MT->new fails.
my($author, $perms) = $class->_login($user, $pass, $blog_id);
die _fault(MT->translate("Invalid login")) unless $author;
die _fault(MT->translate("Permission denied.")) unless $perms && $perms->can_create_post;
my $iter = MT->model($obj_type)->load_iter({ blog_id => $blog_id },
{ 'sort' => 'authored_on',
direction => 'descend',
limit => $num });
my @res;
while (my $entry = $iter->()) {
my $co = sprintf "%04d%02d%02dT%02d:%02d:%02d",
unpack 'A4A2A2A2A2A2', $entry->authored_on;
my $row = { dateCreated => SOAP::Data->type(dateTime => $co),
userid => SOAP::Data->type(string => $entry->author_id) };
## Added by SegPhault
$row->{ars_status} = SOAP::Data->type(string => $entry->status);
$row->{ars_author_name} = SOAP::Data->type(string => encode_text($entry->author->nickname, undef, 'utf-8'));
$row->{ars_category} = ($entry->category) ? SOAP::Data->type(string => $entry->category->label) : '';
#####
$row->{ $param{page} ? 'page_id' : 'postid' } =
SOAP::Data->type(string => $entry->id);
if ($class eq 'blogger') {
$row->{content} = SOAP::Data->type(string => encode_text($entry->text, undef, 'utf-8'));
} else {
$row->{title} = SOAP::Data->type(string => encode_text($entry->title, undef, 'utf-8'));
unless ($titles_only) {
require MT::Tag;
my $tag_delim = chr($author->entry_prefs->{tag_delim});
my $tags = MT::Tag->join($tag_delim, $entry->tags);
$row->{description} = SOAP::Data->type(string => encode_text($entry->text, undef, 'utf-8'));
my $link = $entry->permalink;
$row->{link} = SOAP::Data->type(string => $link);
$row->{permaLink} = SOAP::Data->type(string => $link),
$row->{mt_basename} = SOAP::Data->type(string => encode_text($entry->basename, undef, 'utf-8'));
$row->{mt_allow_comments} = SOAP::Data->type(int => $entry->allow_comments);
$row->{mt_allow_pings} = SOAP::Data->type(int => $entry->allow_pings);
$row->{mt_convert_breaks} = SOAP::Data->type(string => $entry->convert_breaks);
$row->{mt_text_more} = SOAP::Data->type(string => encode_text($entry->text_more, undef, 'utf-8'));
$row->{mt_excerpt} = SOAP::Data->type(string => encode_text($entry->excerpt, undef, 'utf-8'));
$row->{mt_keywords} = SOAP::Data->type(string => encode_text($entry->keywords, undef, 'utf-8'));
$row->{mt_tags} = SOAP::Data->type(string => encode_text($tags, undef, 'utf-8'));
}
}
push @res, $row;
}
\@res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment