forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteback_recent-v0i2
122 lines (89 loc) · 3.05 KB
/
writeback_recent-v0i2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Blosxom Plugin: writeback_recent
# Author(s): John S J Anderson <[email protected]>
# Version: 0.2
# Documentation: See the bottom of this file or type: perldoc writeback_recent
package writeback_recent;
# --- Configurable variables -----
# number of entries with recent comments to display
my $writeback_count = 5;
# output configuration: $list_head will be ahead of the list of
# entries with comments; $list_foot will be after the list. each item
# in the list will be formated according to $list_item_tmpl
my $list_head = "<ol>\n";
my $list_foot = "</ol>\n";
# %F = name of entry with appropriate extension (.writeback)
# %T = title of entry
# %C = number of comments
# %L = 'comment' or 'comments', depending on %C
my $list_item_tmpl = qq|<li><a href="$blosxom::url/%F">%T</a> (%C %L)</li>\n|;
# 'writeback' configuration variables -- must be the same as in
# 'writeback' plugin
my $writeback_dir = "$blosxom::plugin_state_dir/writeback";
my $trackback_extension = "wb";
my $trackback_flavour = "writeback";
# --------------------------------
# ------ Output variables --------
$writeback_recent; # use as $writeback_recent::writeback_recent in flavour templates
# --------------------------------
use File::Find;
my %files;
sub start {
# build list of all writeback files
find( { wanted => \&wanted } , $writeback_dir );
# sort by mtime
my @files = sort { $files{$b} <=> $files{$a} } keys %files;
# initialize the output
$writeback_recent = $list_head || '';
for( 0 .. ( $writeback_count - 1 )) {
my %replace;
# bail if we're out of files
last unless my $file = $files[$_];
# get entry file associated with comments
my $entry = $file;
$entry =~ s/.$trackback_extension$/.$blosxom::file_extension/o;
# get title of entry
open( IN , "$blosxom::datadir/$entry" );
chomp( my $title = <IN> );
close( IN );
$replace{T} = $title;
# get number of comments/pings in writeback file
my $count;
open( IN , "$writeback_dir/$file" );
while( <IN> ) { $count++ if /^name:/ }
close( IN );
$replace{C} = $count;
# build the output
$replace{L} = $count == 1 ? 'comment' : 'comments';
$file =~ s/.$trackback_extension$/.$trackback_flavour/o;
$replace{F} = $file;
my $list_item = $list_item_tmpl;
$list_item =~ s/%(.)/defined($replace{$1})?$replace{$1}:''/ge;
$writeback_recent .= $list_item;
}
# finish up the output
$writeback_recent .= $list_foot;
}
sub wanted {
/.$trackback_extension$/o or return;
my $name = $File::Find::name;
$name =~ s/$writeback_dir\/?//o;
my $mtime = (stat($File::Find::name))[9];
$files{$name} = $mtime;
}
1;
__END__
=head1 NAME
Blosxom Plug-in: writeback_recent
=head1 SYNOPSIS
Searches your writeback directory and returns a list of the entries
most recently commented upon, in $writeback_recent::writeback_recent.
=head1 VERSION
0.2
=head1 AUTHOR
John S Jacobs Anderson <[email protected]>
=head1 SEE ALSO
Blosxom, http://www.blosxom.com/
writeback plugin
=head1 LICENSE
Released under the same license as blosxom.
=cut