1 # Blosxom Plugin: RecentWritebacks
2 # Author: Fletcher T. Penney
5 package recentwritebacks;
7 # --- Configurable variables -----
9 $writebacks_extension = "wb";
11 $writebacksdir = "$blosxom::plugin_state_dir/writeback";
13 $switch_word = "recent"; # This defines the term that needs to be added to the url
14 # ie "http://some.host/weblog/?recent=5"
15 # This finds posts with comments in last 5 days
17 $use_datestamp = 1; # Use embedded datestamp, rather than file modification date
19 $date_field = "date"; # What variable contains the date
21 $use_UK_dates = 0; # Default is mm/dd/yy (US)
22 # Set to 1 to use dd/mm/yy (UK)
24 # --------------------------------
28 use CGI qw/:standard/;
35 my $fh = new FileHandle;
38 if (CGI::param($switch_word)) {
39 $time_window = CGI::param($switch_word);
40 $time = $time - $time_window*60*60*24;
48 my ($pkg, $files_ref) = @_;
49 my @files_list = keys %$files_ref;
51 foreach $file (@files_list) {
53 $file =~ s/$blosxom::datadir/$writebacksdir/;
54 $file =~ s/txt$/$writebacks_extension/;
55 if ($fh->open("$file")) {
58 $stats = stat($file)->mtime;
60 if ( $use_datestamp == 1 ) {
61 while ( $line = <$fh> ) {
62 if ($line =~ /^$date_field\:\s*(.*)/) {
65 $stat2 = parsedate($datestamp);
66 if ($stat2 gt $stats) {
73 if ($stats lt $time) {
74 delete $files_ref->{$realfile};
78 # No writebacks available
79 delete $files_ref->{$realfile};
87 my ($datestring) = @_;
88 #warn "Parsing $datestring\n";
91 # Month can be 3 letter abbreviation or full name (in English)
92 # Time must be hh:mm or hh:mm:ss in 24 hour format
94 # The remaining 1 or 2 digits are treated as date
95 # ie: May 25 2003 18:40
96 # order is not important as long as pieces are there
98 # Convert the datestring to a time() format
100 # Find "Shorthand" Date
101 if ( $datestring =~ /\d\d?\/\d\d?\/\d\d\d?\d?/) {
102 if ( $use_UK_dates eq 0) {
104 $datestring =~ s/(\d\d?)\/(\d\d?)\/(\d\d\d?\d?)//;
110 $datestring =~ s/(\d\d?)\/(\d\d?)\/(\d\d\d?\d?)//;
116 # Now, clean up year if 2 digit
117 # You may change the 70 to whatever cutoff you like
118 $year += 2000 if ($year < 70 );
119 $year += 1900 if ($year < 100);
123 $mon = 0 if ($datestring =~ s/(Jan|January)//i);
124 $mon = 1 if ($datestring =~ s/(Feb|February)//i);
125 $mon = 2 if ($datestring =~ s/(Mar|March)//i);
126 $mon = 3 if ($datestring =~ s/(Apr|April)//i);
127 $mon = 4 if ($datestring =~ s/(May)//i);
128 $mon = 5 if ($datestring =~ s/(Jun|June)//i);
129 $mon = 6 if ($datestring =~ s/(Jul|July)//i);
130 $mon = 7 if ($datestring =~ s/(Aug|August)//i);
131 $mon = 8 if ($datestring =~ s/(Sep|September)//i);
132 $mon = 9 if ($datestring =~ s/(Oct|October)//i);
133 $mon = 10 if ($datestring =~ s/(Nov|November)//i);
134 $mon = 11 if ($datestring =~ s/(Dec|December)//i);
137 if ($datestring =~ s/(\d\d?):(\d\d)(:\d\d)?//) {
143 if ($datestring =~ s/(\d\d\d\d)//) {
147 if ($datestring =~ s/(\d\d?)//) {
151 return timelocal($sec,$min,$hour,$day,$mon,$year);
161 Blosxom Plug-in: recentwritebacks
165 RecentWritebacks locates stories with comments posted within a specified period of time. If you are like me, you find it hard to keep up with comments posted to older articles. This plugin is designed to assist with that. You can also use it to make it easier for visitors to your site to locate the "Hot Topics" where writebacks are being submitted.
167 To use it, simply install the plugin and configure the $writebacks_extension and $writebacksdir variables. They should match whatever you used in the writebacks plugin.
169 You can then use a url similar to:
170 http://some.host/weblog/index.html?recent=5
171 to locate posts with comments written in the last 5 days. You can also create links on your site to make this easier for your visitors.
173 You are also welcome to change the $switch_word variable to whatever you like to fit your site.
177 Fletcher T. Penney - http://fletcher.freeshell.org
181 This source is submitted to the public domain. Feel free to use and modify it. If you like, a comment in your modified source attributing credit for my original work would be appreciated.
183 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND. USE AT YOUR OWN RISK!