1
# Blosxom Plugin: metadate
2
# Author(s): Mark Ivey <zovirl@zovirl.com>
4
# Documentation: See the bottom of this file or type: perldoc metadate
8
# --- Configurable variables -----
10
# fullpath to the external metadates file (see perldoc for description)
11
$external_file = "$blosxom::datadir/external_metadate";
13
$use_UK_dates = 0; # Default is mm/dd/yy (US)
14
# Set to 1 to use dd/mm/yy (UK)
16
# --------------------------------
25
use vars qw( %dirs, %all );
27
my $debug = 0; # log debug messages or not?
34
# FIXME: make the external metadate file optional
35
# FIXME: handle both creation date & modification date...
46
# read the external metadates file
47
unless (open(FILE, "< $external_file"))
49
warn "metadate::filter() couldn't open external file $external_file\n";
55
next if (/^\s*#/); # skip comments
58
my ($file, $time) = ($1, $2);
59
$file =~ s!/*$!!; # remove any trailing slashes
60
$file =~ s!^/*!!; # remove any leading slashes
61
$file = "$blosxom::datadir/$file";
62
warn "metadate: $file=>$time\n" if $debug > 0;
64
$time = parsedate($time);
78
_add($File::Find::name, extract_date($File::Find::name,$files{$File::Find::name}) ||
79
$files{$File::Find::name} ||
80
stat($File::Find::name)->mtime)
90
my $file = shift or return;
91
my $time = shift or return;
93
# check %files, then %others, then check for a directory. Always add to %all
94
if (exists $blosxom::files{$file})
96
$blosxom::files{$file} = $time;
98
elsif (exists $blosxom::others{$file})
100
$blosxom::others{$file} = $time;
104
$dirs{$file} = $time;
111
# extract_date() taken from Fletcher T. Penney's entriescache plugin
112
# <http://www.blosxom.com/plugins/indexing/entries_cache.htm>
114
# FIXME I should make _add_from_file() know about these and then
115
# make them user variables
117
$update_meta_date = 0;
118
$meta_timestamp = "meta-creation_timestamp:" unless defined $meta_timestamp;
119
$meta_date = "meta-creation_date:" unless defined $meta_date;
122
my ($file, $indexed_date) = @_;
124
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
126
# This is an attempt for compatibility with Eric Sherman's entries_index_tagged
127
# But it does not handle as many date formats, as there are too many additional
128
# necessary modules that I am not willing to require
130
if ( $use_date_tags != 0) {
134
while ($line = <FILE>) {
135
if ($line =~ /^$meta_timestamp\s*(\d+)/) {
136
# If present, this format is used
141
if ($line =~ /^$meta_date\s*(.*)/) {
143
return parsedate($1);
146
if ($line =~ /^\s*$/) {
147
# Empty Line signifying end of meta-tags
148
if ($update_meta_date eq 1) {
149
if ($indexed_date eq 0) {
150
$indexed_date = stat($file)->mtime;
153
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($indexed_date);
156
$hour = sprintf("%02d",$hour);
157
$min = sprintf("%02d",$min);
158
$sec = sprintf("%02d",$sec);
160
if ($use_UK_dates eq 1) {
161
$new_story .= "$meta_date $mday/$mon/$year $hour:$min:$sec\n\n";
163
$new_story .= "$meta_date $mon/$mday/$year $hour:$min:$sec\n\n";
166
while ($line = <FILE>) {
171
open (FILE, "> $file") or warn "Unable to update date meta-tag on $file\n";
172
print FILE $new_story;
187
# parsedate() taken from Fletcher T. Penney's entriescache plugin
188
# <http://www.blosxom.com/plugins/indexing/entries_cache.htm>
191
my ($datestring) = @_;
192
#warn "Parsing $datestring\n";
194
# Possible formatting
195
# Month can be 3 letter abbreviation or full name (in English)
196
# Time must be hh:mm or hh:mm:ss in 24 hour format
198
# The remaining 1 or 2 digits are treated as date
199
# ie: May 25 2003 18:40
200
# order is not important as long as pieces are there
202
# Convert the datestring to a time() format
204
# Find "Shorthand" Date
205
if ( $datestring =~ /\d\d?\/\d\d?\/\d\d\d?\d?/) {
206
if ( $use_UK_dates eq 0) {
208
$datestring =~ s/(\d\d?)\/(\d\d?)\/(\d\d\d?\d?)//;
214
$datestring =~ s/(\d\d?)\/(\d\d?)\/(\d\d\d?\d?)//;
220
# Now, clean up year if 2 digit
221
# You may change the 70 to whatever cutoff you like
222
$year += 2000 if ($year < 70 );
223
$year += 1900 if ($year < 100);
227
$mon = 0 if ($datestring =~ s/(Jan|January)//i);
228
$mon = 1 if ($datestring =~ s/(Feb|February)//i);
229
$mon = 2 if ($datestring =~ s/(Mar|March)//i);
230
$mon = 3 if ($datestring =~ s/(Apr|April)//i);
231
$mon = 4 if ($datestring =~ s/(May)//i);
232
$mon = 5 if ($datestring =~ s/(Jun|June)//i);
233
$mon = 6 if ($datestring =~ s/(Jul|July)//i);
234
$mon = 7 if ($datestring =~ s/(Aug|August)//i);
235
$mon = 8 if ($datestring =~ s/(Sep|September)//i);
236
$mon = 9 if ($datestring =~ s/(Oct|October)//i);
237
$mon = 10 if ($datestring =~ s/(Nov|November)//i);
238
$mon = 11 if ($datestring =~ s/(Dec|December)//i);
241
if ($datestring =~ s/(\d\d?):(\d\d)(:\d\d)?//) {
247
if ($datestring =~ s/(\d\d\d\d)//) {
251
if ($datestring =~ s/(\d\d?)//) {
255
return timelocal($sec,$min,$hour,$day,$mon,$year);
266
Blosxom Plug-in: metadate
270
Handles meta tags related to dates.
278
Mark Ivey <zovirl@zovirl.com>, http://zovirl.com
282
metadate parses metadates in stories. It also
283
provides a way to save metadates externally from a file.
284
This is most useful for non-story files, such as pictures or categories which
285
can't contain metadates internally.
287
The file $external_file should contain entries in this format:
289
# comment lines start with a "#"
290
/software=>11/17/2003 22:45
291
/software/screenshot.png=>11/18/2003 22:50
292
/software/static_file.patch.asc=>11/18/2003 22:50
294
WARNING: The file format changed between version 0.0.1 and 0.0.2. It used
295
to contain the full path to the file. Now it contains the path from
296
$blosxom::datadir, to make it easier to relocate $blosxom::datadir
298
metadates stores dates in %blosxom::files (for story files), %blosxom::others
299
(for non-story files), or %metadate::dirs (for directories). Metdates
300
also provides %metadates::all, which contains any file/directory metadate knows about.
304
Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
306
Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
308
parsedate() and extract_date() taken from Fletcher T. Penney's entriescache plugin:
309
http://www.blosxom.com/plugins/indexing/entries_cache.htm
313
Address bug reports and comments to the Blosxom mailing list
314
[http://www.yahoogroups.com/group/blosxom].
318
metadate Blosxom Plugin Copyright 2003-2004, Mark Ivey
320
Portions Copyright 2003, Fletcher Penney
322
Permission is hereby granted, free of charge, to any person obtaining a
323
copy of this software and associated documentation files (the "Software"),
324
to deal in the Software without restriction, including without limitation
325
the rights to use, copy, modify, merge, publish, distribute, sublicense,
326
and/or sell copies of the Software, and to permit persons to whom the
327
Software is furnished to do so, subject to the following conditions:
329
The above copyright notice and this permission notice shall be included
330
in all copies or substantial portions of the Software.
332
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
333
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
334
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
335
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
336
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
337
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
338
OTHER DEALINGS IN THE SOFTWARE.