Initial addition of Barijaona Ramaholimihaso's plugins
[matthijs/upstream/blosxom-plugins.git] / barijaona / prefs
1 # Blosxom Plugin: prefs
2 # Author(s): Barijaona Ramaholimihaso <prefs@barijaona.com>
3 # based on config plugin authored by Rael Dornfest <rael@oreilly.com> 
4 # Version: 2005-11-20
5 # Documentation: See the bottom of this file or type: perldoc prefs
6
7 # WARNING: DO NOT PUT PREFERENCE FILES IN WORLD-READABLE PLACES SUCH AS WITHIN
8 # YOUR DOCUMENT ROOT.  IF YOUR $DATADIR IS LOCATED WITHIN YOUR DOCUMENT ROOT,
9 # I HEARTILY ADVISE THAT YOU MOVE IT.  WHILE MOST OF THE CONFIGURATION 
10 # DIRECTIVES ARE INNOCUOUS ENOUGH, IT'S A SLIPPERY SLOPE AND YOU MIGHT WELL
11 # FIND YOU'VE EXPOSED YOUR STATIC PASSWORD OR INTERNAL DIRECTORY STRUCTURE
12 # TO ANYONE WITH A WEB BROWSER!
13
14 package prefs;
15
16 # --- Configurable variables -----
17 # where are located the preference files
18
19 # I prefer to have mines in my flavour directory
20 # $basepath = "/Users/barijaon/blosxom/flavours";
21
22 $basepath = $blosxom::datadir unless defined $basepath ;
23 # --------------------------------
24
25 sub start {
26   1;
27 }
28
29 sub head {
30
31 $path='/';
32 $path_find = $blosxom::path_info ;
33 do {
34       $file = "$basepath$path"."pageprefs";
35       if (-r $file) { unless ($return = do $file) {
36             warn "Couldn't parse $file: $@" if $@;
37         }}
38
39
40       $file .= ".$blosxom::flavour";
41       if (-r $file) { unless ($return = do $file) {
42             warn "Couldn't parse $file: $@" if $@;
43         }}
44         }
45                 while ($path_find =~ s#/?([^/]*)##) and $1 and ($path .= $1."/" );
46 1;
47 }
48
49 sub story {
50
51 my ($pkg, $path_find, $filename, $story_ref, $title_ref, $body_ref)= @_;
52 $path='/';
53 do {
54       $file = "$basepath$path"."storyprefs";
55       if (-r $file) { unless ($return = do $file) {
56             warn "Couldn't parse $file: $@" if $@;
57         }}
58
59
60       $file .= ".$blosxom::flavour";
61       if (-r $file) { unless ($return = do $file) {
62             warn "Couldn't parse $file: $@" if $@;
63         }}
64         }
65                 while ($path_find =~ s#/?([^/]*)##) and $1 and ($path .= $1."/" );
66 1;
67 }
68
69 1;
70
71 __END__
72
73 =head1 NAME
74
75 Blosxom Plug-in: prefs
76
77 =head1 SYNOPSIS
78
79 Override Blosxom's inline configuration settings on a per-directory, per-flavour, and per-directory-per-flavour basis.
80
81 For each generated page, looks for B<pageprefs> and B<pageprefs.flavour> files which should contain valid Perl instructions.
82
83 For each story, looks for B<storyprefs> and B<storyprefs.flavour> files which should contain valid Perl instructions.
84
85 Prefs has a purpose very similar to Rael Dornfest's B<config> plugin, but was written because in static rendering, B<config> uses the same config file for all pages.
86
87 When Blosxom process a page or a story, all prefs files (pageprefs, pageprefs.flavour, storyprefs, storyprefs.flavour) in the directory tree for this page or story are executed. Prefs files for a specific flavour override prefs files applying to all flavours, and prefs files in subdirectories override prefs files in their parents.
88
89 pageprefs are executed once per page (when the head of the page is generated), and storyprefs are executed once per story (allowing a per story tuning inside a page).
90
91 It is recommanded that you prefix the name of the plugin with a number (for instance, naming it 10prefs) so that it loads before other Blosxom plugins (but after the B<meta> plugin if you use it).
92
93 =head1 VERSION
94
95 2005-11-20
96
97 Version number is the date on which this version of the plug-in was created.
98
99 =head1 AUTHOR
100
101 Barijaona Ramaholimihaso <prefs@barijaona.com>
102
103 Prefs is based on the config plugin written by Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
104
105
106 =head1 SEE ALSO
107
108 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
109
110 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
111
112 =head1 BUGS
113
114 Address bug reports and comments to <prefs@barijaona.com> or to the Blosxom mailing list 
115 [http://www.yahoogroups.com/group/blosxom].
116
117 =head1 LICENSE
118
119 Prefs plugin
120 Copyright 2003-2005, Barijaona Ramaholimihaso
121
122 Blosxom and config Plug-in
123 Copyright 2003, Rael Dornfest 
124
125 Permission is hereby granted, free of charge, to any person obtaining a
126 copy of this software and associated documentation files (the "Software"),
127 to deal in the Software without restriction, including without limitation
128 the rights to use, copy, modify, merge, publish, distribute, sublicense,
129 and/or sell copies of the Software, and to permit persons to whom the
130 Software is furnished to do so, subject to the following conditions:
131
132 The above copyright notice and this permission notice shall be included
133 in all copies or substantial portions of the Software.
134
135 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
137 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
138 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
139 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
140 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
141 OTHER DEALINGS IN THE SOFTWARE.