Revert rss20 to using $ENV{PATH_INFO} in self link.
[blosxom-plugins.git] / general / menu
blobe559fc54ffdf81c83c06bd5f654d7353769c3893
1 # Blosxom Plugin: menu
2 # Author: Fletcher T. Penney
3 # Version: 0.5
4 # Exclude functions copied from exclude plugin
6 package menu;
8 # --- Configurable variables ----
10 # HTML code to insert before the menu
11 $menustart=qq%<span class="menu">%;
13 # HTML code to insert between items
14 $menuseparator=qq% :: %;
16 # HTML code to insert after menu
17 $menuend=qq%</span>%;
19 # These serve the same purpose as above, but for the root menu
20 $rootmenustart = $menustart;
21 $rootmenuseparator=qq%<br>%;
22 $rootmenuend=$menuend;
24 $pretty=1;      # Enable "prettying" up category names
26 # -------------------------------
29 $menu = "";
30 $rootmenu = "";
31 $path_noflavour = "";
32 $pretty_path = "";
34 $ign_file = $exclude::ign_file;
35 $hide_file = $hide::ign_file;
37 sub start {
38         @excludes = ();
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;
75 sub filter {
76         my ($pkg, $files) = @_;
78         @files_list = sort keys %$files;
79         @rootlist = @files_list;
81         $myroot = $blosxom::datadir ."/" . $blosxom::path_info;
82         $myurl = $blosxom::url ."/" . $blosxom::path_info;
83         $myurl =~ s/\/$//;
85         @dirs = ();
86         @rootdirs = ();
88         $lastdir="";
89         $lastroot="";
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         }
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         }
117         @rootdirs = @dirs if ($blosxom::path_info eq "");
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;
126                 $menu.= "<a href=\"$myurl/$dirs[$i]/\">" . $pretty . "</a>" .$menuseparator;
127         }
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;
139         $sepholder = "";
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);
151                 $pretty = $rootdirs[$i];
152                 $pretty =~ s/^(.)/\u$1/;
153                 $pretty =~ s/[_-](.)/ \u$1/g;
154                 $pretty =~ s/ojh/OJH/gi;
156                 $rootmenu.= $sepholder . "<a href=\"$blosxom::url/$rootdirs[$i]/\">" . $pretty . "</a>" if $use;
157         }
159         $rootmenu.=$rootmenuend;
160         
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;
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;
187 __END__
189 =head1 NAME
191 Blosxom Plug-in: menu
193 =head1 DESCRIPTION
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.
197 The default configuration settings at the begin lead to a sort of reversal of the breadcrumbs plug-in.
199 Additionally, the $menu::rootmenu variable contains the top level directories, regardless of the current page.
201 =head1 BUGS
203 None known; please send bug reports and feedback to the Blosxom
204 development mailing list <blosxom-devel@lists.sourceforge.net>.
206 =head1 AUTHOR
208 Fletcher T. Penney - http://fletcher.freeshell.org
210 This plugin is now maintained by the Blosxom Sourceforge Team,
211 <blosxom-devel@lists.sourceforge.net>.
213 =head1 LICENSE
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.
217 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.  USE AT YOUR OWN RISK!