Skip to content

Instantly share code, notes, and snippets.

@ArsTechnica
Created November 10, 2009 18:06
Show Gist options
  • Save ArsTechnica/231111 to your computer and use it in GitHub Desktop.
Save ArsTechnica/231111 to your computer and use it in GitHub Desktop.
sub primary_entries{
my ($ctx, $args, $cond) = @_;
my $url = exec_tag($ctx, { tag => 'ArchiveLink' }, { type => 'Category' });
my $blog_url = $ctx->stash('blog')->site_url;
my $blog_rel_url = exec_tag($ctx, { tag => 'BlogRelativeUrl'}, {});
$url =~ s/$blog_url//;
$url = $blog_rel_url . $url . "%";
my @entries = MT::Entry->load(undef,{'join' => MT::FileInfo->join_on( 'entry_id', { url => { like => $url } }, {}), sort => 'created_on', direction => 'descend', limit => 25});
if(@entries > 0){
local $ctx->{__stash}{entries} = \@entries;
defined(my $txt = $ctx->slurp($args,$cond)) or return;
return $txt;
}
return '';
}
sub exec_tag{
my ($ctx, $args, $cond) = @_;
my $tag = $args->{tag};
$tag =~ s/^MT:?//i;
my ($handler, $type) = $ctx->handler_for($tag);
if (defined($handler)) {
local $ctx->{__stash}{tag} = $args->{tag};
my $value = $handler->($ctx, { %$args }); if ($type == 2) { # conditional tag; just use boolean $value = $value ? 1 : 0;
} else {
if (my $ph = $ctx->post_process_handler) {
$value = $ph->($ctx, $args, $value);
}
}
$ctx->{__stash}{vars}{__cond_tag__} = $args->{tag};
return $value;
}
else {
return $ctx->error(MT->translate("Invalid tag [_1] specified.", $tag));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment