All my plugins in the released stable versions, so the repository starts
[matthijs/upstream/blosxom-plugins.git] / xtaran / dept
1 # -*- perl -*-
2 # Blosxom Plugin: dept
3 # Author(s): Axel Beckert <blosxom@deuxchevaux.org>, http://noone.org/blog
4 # Version: 0.01
5 # Licensing: GPL v2 or newer, http://www.gnu.org/licenses/gpl.txt
6 # Dept plugin web page: http://noone.org/blog?-tags=dept
7 # Dept plugin download: http://noone.org/blosxom/dept
8 # Blosxom web page: http://blosxom.ookee.com/
9
10 ### Documentation:
11 #
12 # This is a plugin for blosxom.
13 #
14 # Installation:
15 #
16 #  Just drop it into your blosxoms plugin directory and it should start
17 #  working. If you want, change some of the configuration variables
18 #  below.
19
20 # What it does:
21 #
22 #  It allows you to decorate Blosxom postings with "From the XYZ
23 #  dept." like on Slashdot and other Slashsites.
24 #
25 # Configuration:
26 #
27 #  You can configure different texts based on regular expressions
28 #  matched on the path. By default it looks if the path starts with
29 #  and indicator for German or English language and uses and
30 #  apropriate text in that language.
31 #
32 # How to use it:
33 #
34 #  Add an additional line after the title, starting with "Dept: ".
35 #  Between this Dept line and the body text there should be a blank
36 #  line. (This is in conformance with other Plugins, e.g. the one for
37 #  meta tags, which work the same way.) After this keyword, the tags
38 #  should be listed and separated by commata.
39 #
40 # Example:
41 #
42 #  The follwing two examples have the same effect.
43 #
44 #  | Story Headline
45 #  | Dept: Slashdot Fan Club
46 #  |
47 #  | Story Body [...]
48 #
49 # Including the dept line into templates:
50 #
51 #  Use $dept::deptline in your templates.
52 #
53 # Known bugs and other ugly obstacles:
54 #
55 #  + None yet. :-)
56 #
57 # Version History:
58 #
59 #  0.01:   Initial release, losely based on my tagging plugin.
60 #
61
62 package dept;
63
64 ###
65 ### Config
66 ###
67
68 # Texts by path
69
70 my %path2text = (
71                 '^/(Deutsch|de)($|/)' => 'Aus der <b>%s</b> Abteilung',
72                 '^/(English|en)($|/)' => 'from the <b>%s</b> dept.',
73                 '*' => 'From the <b>%s</b> dept.', # Default value. Keep it!
74                 );
75
76 # Regular expression
77
78 my $dept_re = qr/Dept:/i;
79
80 # Joining white space with:
81 my $joinchar = '-';
82
83 # Texts for tags
84
85 my $dept_prefix = '<div class="dept">';
86 my $dept_suffix = '</div>';
87
88 # End of configuration.
89
90 # Global variables
91
92 $deptline = '';
93 $dept = '';
94
95 # Code
96
97 sub start {
98     1;
99 }
100
101 sub story {
102     my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
103     my %localtags = ();
104     my $body = '';
105     my $in_header = 1;
106
107     $deptline = '';
108     $dept = '';
109
110     foreach (split /\n/, $$body_ref) {
111         $dept .= 'x';
112         if (/^\s*$/) {
113             $in_header = 0;
114             $body .= "$_\n";
115             next;
116         }
117
118         if ($in_header) {
119             if (/^$dept_re\s*(.+?)\s*$/) {
120                 $dept = $1;
121                 $dept =~ s/\s/$joinchar/gs;
122                 my $fmtstr = $path2text{'*'};
123                 foreach my $re (sort keys %path2text) {
124                     next if $re eq '*';
125                     if ($path =~ /$re/) {
126                         $fmtstr = $path2text{$re};
127                         last;
128                     }
129                 }
130                 $deptline = 
131                     $dept_prefix.
132                     sprintf($fmtstr, $dept).
133                     $dept_suffix;
134                 $in_header = 0;
135                 next;
136             }
137         }
138
139         $body .= "$_\n";
140     }
141     $$body_ref = $body;
142
143     return 1;
144 }
145
146 1;
147
148
149
150