1 # Blosxom Plugin: static_file
2 # Author(s): Barijaona Ramaholimihaso <static_file@barijaona.com>
3 # original idea by Raffi Krikorian <r@bitwaste.com> (binary plugin)
5 # Documentation: See the bottom of this file or type: perldoc static_file
8 use lib qq{$blosxom::plugin_dir/lib};
9 use CGI qw/:standard :netscape/;
18 # --- Configuration Variables ---
20 # You may want to hide from the public some kind of files,
21 # for instance the files Blosxom renders, generally .txt files.
22 # Files whose filename extension is in the following list
23 # will be ignored in dynamic rendering
24 @exclude_extensions_dynamic = ();
26 # Files whose filename extension is in the following list
27 # will be ignored in static rendering
28 @exclude_extensions_static = ("$blosxom::file_extension", txt_);
30 # This is the MIME type that will be used if nothing else
31 # can be found. If your server contains mostly text or HTML
32 # documents, "text/plain" is a good value. If most of your
33 # content is binary, such as applications or images, you may
34 # want to use "application/octet-stream" instead to keep browsers
35 # from trying to display binary files as though they are text.
36 $default_type="text/plain";
38 # --------------------------------
45 if( $blosxom::static_or_dynamic eq "dynamic" ) {
46 # if Blosxom is being dynamically generated -- then we have to
47 # see if the URL requested specifies a file that is on the
48 # filesystem, then it will return that file with the right
50 if( ( $blosxom::path_info =~ m!^(.*?/?)([^/]*?\.?)([^\.]*?)$! ) &&
51 ( -e "$blosxom::datadir/$1$2$3" ) && (! -d "$blosxom::datadir/$1$2$3" ) )
53 # access path and name, name and extension of the file
54 $fileaccess = "$blosxom::datadir/$1$2$3" ;
55 # adequate file extension ?
56 if ( grep(/$3/, @exclude_extensions_dynamic) ) {return 0 ;}
57 my MIME::Types $types = MIME::Types->new;
58 my MIME::Type $mimetype = $types->mimeTypeOf($blosxom::flavour);
62 $mimetype->mediaType . "/" . $mimetype->subType :
64 my @data = stat( $fileaccess );
65 # forge some HTTP header stuff
66 print("Accept-Ranges: bytes\nContent-Length: $data[7]\n$blosxom::header");
67 cat( $fileaccess, \*STDOUT);
68 # empty what blosxom main script may use
71 # tell blosxom main script to end processing for this file
80 # if we are statically rendering the blog, then we have to copy
81 # over the entire data tree to the static tree so that it can be
83 if( $blosxom::static_or_dynamic eq "static" ) {
86 if( $File::Find::name =~
87 m!^$blosxom::datadir(.*?/?)([^/]*?\.?)([^\.]*?)$! ) {
88 # do we have to create a directory ?
89 if ( ( ! -e "$blosxom::static_dir$1$2$3")
90 && (-d $File::Find::name) ) {
91 mkpath ("$blosxom::static_dir$1$2$3");}
92 # is it a file to be updated ?
93 elsif ( ! grep(/$3/, @exclude_extensions_static) ) {
94 my @static = stat( "$blosxom::static_dir$1$2$3" );
95 my @data = stat( $File::Find::name );
96 ( ( ! -e "$blosxom::static_dir$1$2$3" ) ||
97 ( ( ( $static[9] < $data[9] ) ||
98 ( $static[7] != $data[7] ) ) ) ) &&
99 copy( $File::Find::name,
100 "$blosxom::static_dir$1$2$3" );
103 }, $blosxom::datadir );
119 Blosxom Plug-in: static_file
123 Cause Blosxom to see if the URL requested actually exists on the filesystem. If it does, then return the file, and then exit the script allowing for binary file serves. If the file does not exist, then the Bloxsom script will continue noting whether it needs to do a flavour translation on the data file, etc.
125 This allows you to integrate existing webpages to a Blosxom site.
127 Another convinience of this is that when you wish to include an image or anything besides just the blog entry, you can place the file in the same directory as your text file, and reference it with a <$url /><$path /> (supposing you are using interpolate_fancy and its ability to interpolate variables in stories).
133 Version number is the date on which this version of the plug-in was created.
137 Barijaona Ramaholimihaso <static_file@barijaona.com>
139 Original idea by Raffi Krikorian <r@bitwaste.com>, http://www.bitwaste.com/, author of the binary plugin.
143 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
145 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
149 If you are using this plugin in Blosxom's dynamic mode, you might consider creating a custom B<error> flavour, because Blosxom's default B<error> flavour could be confusing for the user.
151 It is recommanded, for performance optimization, to put a number in front of the name of this plugin, for instance to name it B<00static_file>, so that it loads among the first.
155 static_file Blosxom plugin
156 Copyright 2003, Barijaona Ramaholimihaso
157 Copyright 2003, Raffi Krikorian
159 Permission is hereby granted, free of charge, to any person obtaining a
160 copy of this software and associated documentation files (the "Software"),
161 to deal in the Software without restriction, including without limitation
162 the rights to use, copy, modify, merge, publish, distribute, sublicense,
163 and/or sell copies of the Software, and to permit persons to whom the
164 Software is furnished to do so, subject to the following conditions:
166 The above copyright notice and this permission notice shall be included
167 in all copies or substantial portions of the Software.
169 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
170 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
172 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
173 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
174 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
175 OTHER DEALINGS IN THE SOFTWARE.