# Blosxom Plugin: bugzilla_tag
# Author: Dean Wilson 
# Version: 0.1 (20060902)
# Plugin Homepage:
# http://www.unixdaemon.net/blosxom_plugins.html#bugzilla_tag
# License: GPL
# Documentation: Please see the end of this file.

package bugzilla_tag;

sub start { 1; }

sub story {
  my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;

  $$body_ref =~ s!<bug\s+"([^"]+)"\s*>(\d*)</bug>!return_link($1,$2)!esg;

  1;
}

sub return_link {
  my $project = shift;
  my $bug_id  = shift;

  # format - 'alias you use' => [ URL to bugzilla, pretty display name ]
  my %zillas = (
    redhat    => ['https://bugzilla.redhat.com/bugzilla/show_bug.cgi', 'Red Hat'],
    xensource => ['http://bugzilla.xensource.com/bugzilla/show_bug.cgi', 'Xen Source' ],
    mozilla   => ['https://bugzilla.mozilla.org/show_bug.cgi', 'Mozilla.org' ],
    # short aliases I use
    rh  => ['https://bugzilla.redhat.com/bugzilla/show_bug.cgi', 'Red Hat'],
    xen => ['http://bugzilla.xensource.com/bugzilla/show_bug.cgi', 'Xen Source' ],
    moz => ['https://bugzilla.mozilla.org/show_bug.cgi', 'Mozilla.org' ],
  );

  # default to the mozilla bugzilla if the given project can't be found.
  $project = 'mozilla' unless exists $zillas{$project};

  my $url = qq!<a href="$zillas{$project}[0]?id=$bug_id">$zillas{$project}[1] bug ID $bug_id</a>!;

  return $url;
}

1;

__END__

=head1 NAME

Blosxom Plugin: bugzilla_tag

=head1 SYNOPSIS

This extension allows you to link to bugs posted in a number of bugzilla
instances (you can easily add your own projects instance to the list) in
your blog posts without performing the usual tedious steps; getting the
URL, putting it in an <a href=""> etc.

You can specify a combination of bug ID and Bugzilla instance using the
following syntax

 <bug "redhat">84752</bug>

And it will be translated in to a full <a href=""> that points to the given
bug ID on the specified server. This centralision also makes it easier to
repoint your links in the future.

=head2 Default Bugzilla

You can specify a default bugzilla in the code, this is the bugzilla
server used if you mistype the project name.

=head1 VERSION

0.1

=head1 AUTHOR

Dean Wilson 

=head1 LICENSE

GPL

=cut
