Replace atomfeed $feed_url with $path_info_full, for correct self links.
[blosxom-plugins.git] / barijaona / exclude
blob9d9e2f620bc95afd64eb16d051aa58404d85d831
1 # Blosxom Plugin: exclude
2 # Author(s): Barijaona Ramaholimihaso
3 # Credits to :
4 #   Breyten Ernsting author of the original exclude plugin http://www.bje.nu/
5 #   Fletcher T. Penney author of the hide plugin http://fletcher.freeshell.org
6 # IMPORTANT : requires a recent version of Blosxom (v2.0.1+ aka CVS revision 1.9)
7 # Version: 2006-01-02blosxom2
9 package exclude;
11 # --- Configurable variables -----
13 # name of the file where the patterns of the posts to be hidden
14 # are stored ; another popular choice is 'hide'
15 $ign_file = 'exclude';
17 # location of the file : I prefer it in the flavour directory
18 $refdir = "$blosxom::basedir/flavours";
20 $refdir = $blosxom::datadir unless defined $refdir ;
22 # --------------------------------
23 use CGI qw/:standard/;
25 sub start {
26   # compatiblily with Fletcher T. Penney find plugin and wikieditish
27  ((param('plugin') eq 'find') || (param('find')) || (param('plugin') eq 'wikieditish')) ? 0 : 1 ;
31 sub read_exclude_file {
32   if (open(EXCLUDE, "< $ign_fn")) {
33     while ($line = <EXCLUDE>) {
34       chomp $line;
35       $line =~ s/\r//;
36       $line =~ s/\n//;
37       $exclude_pattern = "$ign_fp2$line";
38       # takes into account patterns corresponding to our directory path,
39       # and patterns from parallel paths which are hidden from upper index views
40       if ( $line && (( $ign_fp2 eq $workingdir2 ) || ($exclude_pattern  !~ /$workingdir/ )) ){
41                 push(@excludes, $exclude_pattern);
42           }
43     }
44     close(EXCLUDE);
45     }
49 sub filter {
50   my ($pkg, $files_ref) = @_;
53   if (($blosxom::path_info) && ( $blosxom::path_info !~ m#^(\d{4})#)) { $path = "/$blosxom::path_info" ;} else { $path = '';} ;
55   # if the path_info corresponds to a single story, we remember it,
56   # and we refer to the directory where our file is stored, 
57   $queried_file = "$blosxom::datadir$path";
58   if ( ! -d "$blosxom::datadir$path" ) {
59    $path =~ s#\/?[^\/]*$## ;
60    $queried_file =~ s/$blosxom::flavour$/$blosxom::file_extension/ ;
61    } ;
63   $workingdir = "$blosxom::datadir$path";
64   $path .= "/";
65   $workingdir2 = "$blosxom::datadir$path" ;
66   @excludes =();
67   do {
68       $ign_fp = "$refdir$path";
69       $ign_fp2 = "$blosxom::datadir$path";
70       $ign_fn = "$ign_fp$ign_file.$blosxom::flavour";
71       if (-e $ign_fn) {read_exclude_file(); };
72       $ign_fn = "$ign_fp$ign_file";
73       if ( -e $ign_fn) {read_exclude_file(); };
74         } while ($path =~ s#([^/]*\/?)$## and $1) ;
78   foreach $exclude (@excludes) {
79     foreach $ign_cf (keys %$files_ref) {
80         if ($ign_cf =~ m#^$exclude# && $ign_cf ne $queried_file){ delete $files_ref->{$ign_cf} ;  };
81         }
82   }
83  1;
85          
91 =head1 NAME
93 Blosxom Plug-in: exclude
95 =head1 SYNOPSIS
97 Purpose: ignores files and directories in entries. Still allow these stories to appear in the results of a search via Fletcher T. Penney's find plugin <http://fletcher.freeshell.org>
99 This file does not make any new variables available for use in template files.
101 =head1 VERSION
103 2006-01-02blosxom2
105 Version number is the date on which this version of the plug-in was created.
107 =head2 CHANGES
109 2006-01-02blosxom2 : takes into account the modified call of filter subroutines in recent versions of blosxom.cgi. Tested with Blosxom CVS revision 1.9  (http://cvs.sourceforge.net/viewcvs.py/blosxom/blosxom2/)
111 2004-09-13blosxom2 : First published version. Very hackish, needs a specific version of blosxom.
113 =head1 AUTHOR
115 Barijaona Ramaholimihaso http://homepage.mac.com/barijaona/
116 The original exclude plugin was written by Breyten J. Ernsting <bje@dds.nl> http://www.bje.nu/
117 Compatibility with the find plugin provided by Fletcher Penney.
119 =head1 BUGS
121 Probably ;)
122 IMPORTANT : Needs a recent version of Blosxom2. Tested with Blosxom CVS revision 1.9  (http://cvs.sourceforge.net/viewcvs.py/blosxom/blosxom2/) 
124 =head1 CONFIGURATION
126 C<$ign_file> name to use for exclude files. Defaults to C<exclude>.
128 C<$refdir> directory where you put the exclude files. The default is your flavourdir. Some people might prefer the datadir.
130 =head1 EXAMPLE
132 Your C<exclude> file should look like this:
134 apps/
135 life/about.txt
137 One entry per line. You should be able to use regexes.
139 =head1 BUGS
141 None known; please send bug reports and feedback to the Blosxom
142 development mailing list <blosxom-devel@lists.sourceforge.net>.
144 =head1 LICENSE
146 this Blosxom Plug-in
147 Copyright 2003, Breyten Ernsting
148 Copyright 2004-2006, Barijaona Ramaholimihaso
150 (This license is the same as Blosxom's)
152 Permission is hereby granted, free of charge, to any person obtaining a
153 copy of this software and associated documentation files (the "Software"),
154 to deal in the Software without restriction, including without limitation
155 the rights to use, copy, modify, merge, publish, distribute, sublicense,
156 and/or sell copies of the Software, and to permit persons to whom the
157 Software is furnished to do so, subject to the following conditions:
159 The above copyright notice and this permission notice shall be included
160 in all copies or substantial portions of the Software.
162 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
165 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
166 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
167 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
168 OTHER DEALINGS IN THE SOFTWARE.