Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Updated version #

* Fixed bug in which some unrecognized tags were being skipped due to multiline error message
* Added support for a status message when no unrecognized tags found
  • Loading branch information...
commit d71f0eb74ff40aa61c0785b6e7fd3c51d84a7a66 1 parent ba1d828
@byrnereese byrnereese authored finn committed
View
2  Makefile.PL
@@ -2,6 +2,6 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Unrecognized Tags',
- VERSION => '0.3',
+ VERSION => '0.4',
DISTNAME => 'UnrecognizedTags',
);
View
2  plugins/UnrecognizedTags/config.yaml
@@ -1,7 +1,7 @@
name: UnrecognizedTags
id: UnrecognizedTags
key: UnrecognizedTags
-version: 0.3
+version: 0.4
description: Identify unrecognized tags in use in all templates system-wide
applications:
cms:
View
57 plugins/UnrecognizedTags/lib/UnrecognizedTags/CMS.pm
@@ -17,6 +17,7 @@ use MT::Util;
sub unrecognized_tags {
my $app = shift;
+
require MT::Template;
require MT::Blog;
@@ -24,44 +25,52 @@ sub unrecognized_tags {
my $tmpls = {};
my $blogs = {};
- my $iter = MT::Template->load_iter;
-
+ my $iter;
+ if ($app->blog) {
+ $iter = MT::Template->load_iter( { blog_id => $app->blog->id } );
+ } else {
+ $iter = MT::Template->load_iter();
+ }
while (my $tmpl = $iter->()) {
$tmpl->compile;
if ($tmpl->{errors} && @{$tmpl->{errors}}) {
#print "Errors in " . $tmpl->id . "'" . $tmpl->name . "' (" . $tmpl->blog_id . ")\n";
- my @msgs = map { ($_->{message} =~ /unrecognized/) ? $_->{message} : () } @{$tmpl->{errors}};
+ my @msgs = map { ($_->{message} =~ /unrecognized/mi) ? $_->{message} : () } @{$tmpl->{errors}};
for my $msg (@msgs) {
- $msg =~ /^<([^>]+)>/;
- my $tag = $1;
- $tags->{$tag} ||= {};
- $tags->{$tag}->{$tmpl->id}++;
+ my ($tag) = ($msg =~ /^<([^>]+)>/);
+ $tags->{$tag} ||= {};
+ $tags->{$tag}->{$tmpl->id}++;
}
$tmpls->{$tmpl->id} = $tmpl;
$blogs->{$tmpl->blog_id} ||= MT::Blog->load($tmpl->blog_id);
}
}
my @tag_loop = ();
+ my $tag_count;
for my $tag (sort keys %$tags) {
- my @tmpl_loop = ();
- for my $tmpl_id (keys %{$tags->{$tag}}) {
- my $tmpl = $tmpls->{$tmpl_id};
+ $tag_count++;
+ my @tmpl_loop = ();
+ for my $tmpl_id (keys %{$tags->{$tag}}) {
+ my $tmpl = $tmpls->{$tmpl_id};
- push(@tmpl_loop, {
- 'name' => $tmpl->name,
- 'id' => $tmpl->id,
- 'blog_name' => ($tmpl->blog_id) ? $blogs->{$tmpl->blog_id}->name : "Global Templates",
- 'blog_id' => $tmpl->blog_id,
- });
- }
- @tmpl_loop = sort { "$a->{'blog_name'}$a->{'name'}" cmp "$b->{'blog_name'}$b->{'name'}" } @tmpl_loop;
- push(@tag_loop, {
- 'tag' => $tag,
- 'count' => scalar @tmpl_loop,
- 'tmpl_loop' => \@tmpl_loop,
- });
+ push(@tmpl_loop, {
+ 'name' => $tmpl->name,
+ 'id' => $tmpl->id,
+ 'blog_name' => ($tmpl->blog_id) ? $blogs->{$tmpl->blog_id}->name : "Global Templates",
+ 'blog_id' => $tmpl->blog_id,
+ });
+ }
+ @tmpl_loop = sort { "$a->{'blog_name'}$a->{'name'}" cmp "$b->{'blog_name'}$b->{'name'}" } @tmpl_loop;
+ push(@tag_loop, {
+ 'tag' => $tag,
+ 'count' => scalar @tmpl_loop,
+ 'tmpl_loop' => \@tmpl_loop,
+ });
}
- my $param = { 'tag_loop' => \@tag_loop };
+ my $param = {
+ 'tag_count' => $tag_count,
+ 'tag_loop' => \@tag_loop,
+ };
$app->{component} = 'UnrecognizedTags';
return $app->build_page('results.tmpl', $param);
}
View
4 plugins/UnrecognizedTags/tmpl/results.tmpl
@@ -3,6 +3,7 @@
<mt:include name="include/header.tmpl">
+<mt:if name="tag_count" gt="0">
<mt:loop name="tag_loop">
<h2><mt:var name="tag"> (<mt:var name="count"> templates)</h2>
<ul>
@@ -11,6 +12,9 @@
</mt:loop>
</ul>
</mt:loop>
+<mt:else>
+<p>No unrecognized template tags could be found.</p>
+</mt:if>
<mt:include name="include/footer.tmpl">
Please sign in to comment.
Something went wrong with that request. Please try again.