summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Template/Plugin
diff options
context:
space:
mode:
authorjocuri%softhome.net <>2006-02-28 23:39:00 +0100
committerjocuri%softhome.net <>2006-02-28 23:39:00 +0100
commit90e1688ef09332be00b31278f8d5ee7703ac81b2 (patch)
tree5bc8d02bc88eda0c195229b3bd2cb6c96c0037d5 /Bugzilla/Template/Plugin
parentda1db1402be5d249990d1beb5f41390b92f7e0be (diff)
downloadbugzilla-90e1688ef09332be00b31278f8d5ee7703ac81b2.tar.gz
bugzilla-90e1688ef09332be00b31278f8d5ee7703ac81b2.tar.xz
Patch for bug 298341: Implement code hook mechanism; patch by zach@zachlipton.com, r=timeless, a=justdave.
Diffstat (limited to 'Bugzilla/Template/Plugin')
-rw-r--r--Bugzilla/Template/Plugin/Hook.pm60
1 files changed, 59 insertions, 1 deletions
diff --git a/Bugzilla/Template/Plugin/Hook.pm b/Bugzilla/Template/Plugin/Hook.pm
index b189c5d26..bcfda1e5b 100644
--- a/Bugzilla/Template/Plugin/Hook.pm
+++ b/Bugzilla/Template/Plugin/Hook.pm
@@ -18,12 +18,19 @@
# Rights Reserved.
#
# Contributor(s): Myk Melez <myk@mozilla.org>
+# Zach Lipton <zach@zachlipton.com>
#
package Bugzilla::Template::Plugin::Hook;
use strict;
+use Bugzilla::Config;
+use Bugzilla::Template;
+use Bugzilla::Util;
+use Bugzilla::Error;
+use File::Spec;
+
use base qw(Template::Plugin);
sub load {
@@ -42,7 +49,38 @@ sub process {
my $paths = $self->{_CONTEXT}->{LOAD_TEMPLATES}->[0]->paths;
my $template = $self->{_CONTEXT}->stash->{component}->{name};
my @hooks = ();
+
+ # sanity check:
+ if (!$template =~ /[\w\.\/\-_\\]+/) {
+ ThrowCodeError("Template with invalid file name found in hook call: $template");
+ }
+ # also get extension hook files that live in extensions/:
+ # parse out the parts of the template name
+ my ($vol, $subpath, $filename) = File::Spec->splitpath($template);
+ $subpath = $subpath || '';
+ $filename =~ m/(.*)\.(.*)\.tmpl/;
+ my $templatename = $1;
+ my $type = $2;
+ # munge the filename to create the extension hook filename:
+ my $extensiontemplate = $subpath.'/'.$templatename.'-'.$hook_name.'.'.$type.'.tmpl';
+ my @extensions = glob($Bugzilla::Config::extensionsdir."/*");
+ my @usedlanguages = getLanguages();
+ foreach my $extension (@extensions) {
+ foreach my $language (@usedlanguages) {
+ my $file = $extension.'/template/'.$language.'/'.$extensiontemplate;
+ if (-e $file) {
+ # tt is stubborn and won't take a template file not in its
+ # include path, so we open a filehandle and give it to process()
+ # so the hook gets invoked:
+ open (my $fh, $file);
+ push(@hooks, $fh);
+ }
+ }
+ }
+
+ # we keep this too since you can still put hook templates in
+ # template/en/custom/hook
foreach my $path (@$paths) {
my @files = glob("$path/hook/$template/$hook_name/*.tmpl");
@@ -65,6 +103,24 @@ sub process {
return $output;
}
+# get a list of languages we accept so we can find the hook
+# that corresponds to our desired languages:
+sub getLanguages() {
+ my $languages = trim(Param('languages'));
+ if (not ($languages =~ /,/)) { # only one language
+ return $languages;
+ }
+ my @languages = Bugzilla::Template::sortAcceptLanguage($languages);
+ my @accept_language = Bugzilla::Template::sortAcceptLanguage($ENV{'HTTP_ACCEPT_LANGUAGE'} || "" );
+ my @usedlanguages;
+ foreach my $lang (@accept_language) {
+ if(my @found = grep /^\Q$lang\E(-.+)?$/i, @languages) {
+ push (@usedlanguages, @found);
+ }
+ }
+ return @usedlanguages;
+}
+
1;
__END__
@@ -79,5 +135,7 @@ Template Toolkit plugin to process hooks added into templates by extensions.
=head1 SEE ALSO
-L<Template::Plugin>,
+L<Template::Plugin>
+L<Customization.xml in the Bugzilla Guide>
L<http://bugzilla.mozilla.org/show_bug.cgi?id=229658>
+L<http://bugzilla.mozilla.org/show_bug.cgi?id=298341>