tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / barijaona / exclude
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
8
9 package exclude;
10
11 # --- Configurable variables -----
12
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';
16
17 # location of the file : I prefer it in the flavour directory
18 $refdir = "$blosxom::basedir/flavours";
19
20 $refdir = $blosxom::datadir unless defined $refdir ;
21
22 # --------------------------------
23 use CGI qw/:standard/;
24
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 ;
28
29 }
30
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     }
46 }
47
48
49 sub filter {
50   my ($pkg, $files_ref) = @_;
51
52  
53   if (($blosxom::path_info) && ( $blosxom::path_info !~ m#^(\d{4})#)) { $path = "/$blosxom::path_info" ;} else { $path = '';} ;
54
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    } ;
62
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) ;
75
76
77
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;
84 }
85          
86
87 1;
88
89
90
91 =head1 NAME
92
93 Blosxom Plug-in: exclude
94
95 =head1 SYNOPSIS
96
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>
98  
99 This file does not make any new variables available for use in template files.
100
101 =head1 VERSION
102
103 2006-01-02blosxom2
104
105 Version number is the date on which this version of the plug-in was created.
106
107 =head2 CHANGES
108
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/)
110
111 2004-09-13blosxom2 : First published version. Very hackish, needs a specific version of blosxom.
112
113 =head1 AUTHOR
114
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.
118
119 =head1 BUGS
120
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/) 
123
124 =head1 CONFIGURATION
125
126 C<$ign_file> name to use for exclude files. Defaults to C<exclude>.
127
128 C<$refdir> directory where you put the exclude files. The default is your flavourdir. Some people might prefer the datadir.
129
130 =head1 EXAMPLE
131
132 Your C<exclude> file should look like this:
133
134 apps/
135 life/about.txt
136
137 One entry per line. You should be able to use regexes.
138
139 =head1 BUGS
140
141 None known; please send bug reports and feedback to the Blosxom
142 development mailing list <blosxom-devel@lists.sourceforge.net>.
143
144 =head1 LICENSE
145
146 this Blosxom Plug-in
147 Copyright 2003, Breyten Ernsting
148 Copyright 2004-2006, Barijaona Ramaholimihaso
149
150 (This license is the same as Blosxom's)
151
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:
158
159 The above copyright notice and this permission notice shall be included
160 in all copies or substantial portions of the Software.
161
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.