tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / general / menu
1 # Blosxom Plugin: menu
2 # Author: Fletcher T. Penney
3 # Version: 0.5
4 # Exclude functions copied from exclude plugin
5
6 package menu;
7
8 # --- Configurable variables ----
9
10 # HTML code to insert before the menu
11 $menustart=qq%<span class="menu">%;
12
13 # HTML code to insert between items
14 $menuseparator=qq% :: %;
15
16 # HTML code to insert after menu
17 $menuend=qq%</span>%;
18
19 # These serve the same purpose as above, but for the root menu
20 $rootmenustart = $menustart;
21 $rootmenuseparator=qq%<br>%;
22 $rootmenuend=$menuend;
23
24 $pretty=1;      # Enable "prettying" up category names
25
26 # -------------------------------
27
28
29 $menu = "";
30 $rootmenu = "";
31 $path_noflavour = "";
32 $pretty_path = "";
33
34 $ign_file = $exclude::ign_file;
35 $hide_file = $hide::ign_file;
36
37 sub start {
38         @excludes = ();
39
40         if ($ign_file) {
41                 $ign_fp = "$blosxom::datadir";
42                 $ign_fn = "$ign_fp/$ign_file";
43                 if (open(EXCLUDE, "< $ign_fn")) {
44                         while (<EXCLUDE>) {
45                                 chomp;
46                                 push(@excludes, "$_") if $_;
47                         }
48                         close(EXCLUDE);
49                 }
50         }
51         
52         # Now do the same for hide
53         if ($hide_file) {
54                 $ign_fp = "$blosxom::datadir";
55                 $ign_fn = "$ign_fp/$hide_file";
56                 if (open(EXCLUDE, "< $ign_fn")) {
57                         while (<EXCLUDE>) {
58                                 chomp;
59                                 push(@excludes, "$_") if $_;
60                         }
61                         close(EXCLUDE);
62                 }
63         }
64         
65         $path_noflavour = $blosxom::path_info;
66         if ($path_noflavour !~ s/\.[^\.]*$//) {
67                 $path_noflavour =~ s/\/$//;
68                 $path_noflavour .= "\/index";
69                 $path_noflavour =~ s/^([^\/])/$1/;
70         }
71         $path_noflavour =~ s/^\/*//;
72         1;
73 }
74
75 sub filter {
76         my ($pkg, $files) = @_;
77
78         @files_list = sort keys %$files;
79         @rootlist = @files_list;
80
81         $myroot = $blosxom::datadir ."/" . $blosxom::path_info;
82         $myurl = $blosxom::url ."/" . $blosxom::path_info;
83         $myurl =~ s/\/$//;
84
85         @dirs = ();
86         @rootdirs = ();
87
88         $lastdir="";
89         $lastroot="";
90
91         foreach (@files_list) {
92                 if ($_ =~ s/$myroot//) {
93                         # These are subdirectories of the current directory
94                         $_ =~ s/^\/?([^\/]+)\/.*/$1/;
95                         $_ =~ s/\/?[^\/]+\.txt//;
96                         if ($_ and ($lastdir ne $_)) {
97                                 $lastdir=$_;
98                                 push(@dirs,$_);
99                         }
100                 } 
101         }
102
103         foreach (@rootlist) {
104                 #These are not
105         #               $rootmenu.="$_ <br>";
106                 if ($_ =~ s/$blosxom::datadir\///) {
107                         $_ =~ s/^\/?([^\/]+)\/.*/$1/;
108                         $_ =~ s/\/?[^\/]+\.txt//;
109                         if ($_ and ($lastroot ne $_)) {
110                                 $lastroot=$_;
111                                 push(@rootdirs,$_);
112                         }
113                 }
114         }
115
116
117         @rootdirs = @dirs if ($blosxom::path_info eq "");
118
119         $menu = $menustart;
120         for ($i=0;$i<scalar(@dirs)-1;$i++) {
121                 $pretty = $dirs[$i];
122                 $pretty =~ s/^(.)/\u$1/;
123                 $pretty =~ s/[_-](.)/ \u$1/g;
124                 $pretty =~ s/ojh/OJH/gi;
125
126                 $menu.= "<a href=\"$myurl/$dirs[$i]/\">" . $pretty . "</a>" .$menuseparator;
127         }
128
129         for (;$i<scalar(@dirs);$i++) {
130                 $pretty = $dirs[$i];
131                 $pretty =~ s/^(.)/\u$1/;
132                 $pretty =~ s/[_-](.)/ \u$1/g;
133                 $pretty =~ s/ojh/OJH/gi;
134                 
135                 $menu.= "<a href=\"$myurl/$dirs[$i]/\">" . $pretty . "</a>" ;
136         }
137         $menu.=$menuend;
138
139         $sepholder = "";
140
141         $rootmenu .= $rootmenustart;
142         for ($i=0;$i<scalar(@rootdirs);$i++) {
143                 $use = 1;
144                 foreach $exclude (@excludes) {
145                         foreach $ign_cf (@files_list) {
146                                 $use = 0 if ($rootdirs[$i] =~ m/^$exclude/) ;
147                         }
148                 }
149                 $sepholder = $rootmenuseparator if ($rootmenu ne $rootmenustart);
150
151                 $pretty = $rootdirs[$i];
152                 $pretty =~ s/^(.)/\u$1/;
153                 $pretty =~ s/[_-](.)/ \u$1/g;
154                 $pretty =~ s/ojh/OJH/gi;
155
156                 $rootmenu.= $sepholder . "<a href=\"$blosxom::url/$rootdirs[$i]/\">" . $pretty . "</a>" if $use;
157         }
158
159         $rootmenu.=$rootmenuend;
160         
161 1;
162 }
163
164 sub story {
165         my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
166         
167         $pretty_path = $path;
168         $pretty_path =~ s/^\/?(.)/\u$1/;
169         $pretty_path =~ s/[_-](.)/ \u$1/g;
170         $pretty_path =~ s/\/(.)/ :: \u$1/g;
171         1;
172 }
173
174 sub date {
175         my ($pkg, $date_ref, $mtime, $dw,$mo,$mo_num,$da,$ti,$yr) = @_;
176         
177         $pretty_path = $blosxom::path;
178         $pretty_path =~ s/^\/?(.)/\u$1/;
179         $pretty_path =~ s/[_-](.)/ \u$1/g;
180         $pretty_path =~ s/\/(.)/ :: \u$1/g;
181         1;
182 }
183
184 1;
185
186
187 __END__
188
189 =head1 NAME
190
191 Blosxom Plug-in: menu
192
193 =head1 DESCRIPTION
194
195 This creates a menu ($menu::menu)showing the available subdirectories from your current position.  A subdirectory, or one of its "descendents" must have a story in it in order to be shown in the menu (ie, it does not lead down "blind alleys").  Additionally, it abides by the excluded sections if the exclude plug-in is enabled.
196
197 The default configuration settings at the begin lead to a sort of reversal of the breadcrumbs plug-in.
198
199 Additionally, the $menu::rootmenu variable contains the top level directories, regardless of the current page.
200
201 =head1 BUGS
202
203 None known; please send bug reports and feedback to the Blosxom
204 development mailing list <blosxom-devel@lists.sourceforge.net>.
205
206 =head1 AUTHOR
207
208 Fletcher T. Penney - http://fletcher.freeshell.org
209
210 This plugin is now maintained by the Blosxom Sourceforge Team,
211 <blosxom-devel@lists.sourceforge.net>.
212
213 =head1 LICENSE
214
215 This source is submitted to the public domain.  Feel free to use and modify it.  If you like, a comment in your modified source attributing credit to myself for my work would be appreciated.
216
217 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.  USE AT YOUR OWN RISK!