-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlast_modified
104 lines (77 loc) · 2.35 KB
/
last_modified
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
# Blosxom Plugin: last_modified
# Author(s): Kyo Nagashima <[email protected]>
# Version: 2013-07-29
# Blosxom Home/Docs/Licensing: http://www.blosxom.com/
package last_modified;
use strict;
use vars qw($string);
# --- Configurable variables -----------
my $wb_dir = "$blosxom::plugin_state_dir/writeback";
my $wb_ext = "wb";
my $cache_control = 'max-age=' . 2 * 60 * 60;
my $tzd_w3cdtf = "+09:00";
# --- Plug-in package variables --------
my $mtime;
# --------------------------------------
use CGI qw(:standard);
use File::stat;
use HTTP::Date;
sub start {
$string = "Unknown";
return 0 if $ENV{'QUERY_STRING'};
return 0 if $blosxom::flavour ne $blosxom::default_flavour;
return 0 if $blosxom::path_info_yr;
return 1;
}
sub filter {
my($pkg, $files_ref, $others_ref) = @_;
my(@files, @mtimes);
my $currentpath = "$blosxom::datadir/$blosxom::path_info";
$currentpath =~ s/\.\Q$blosxom::flavour\E$//;
foreach (keys %$files_ref) {
push @files, $_ if /^\Q$currentpath\E/;
}
@files = sort { $files_ref->{$b} <=> $files_ref->{$a} } @files;
@files = splice @files, 0, $blosxom::num_entries;
foreach my $file (@files) {
push @mtimes, stat($file)->mtime if -f $file;
$file =~ s/^$blosxom::datadir/$wb_dir/;
$file =~ s/$blosxom::file_extension$/$wb_ext/;
push @mtimes, stat($file)->mtime if -f $file;
}
@mtimes = sort { $b <=> $a } @mtimes;
$mtime = $mtimes[0];
$string = &format_time_w3c($mtime);
return 1;
}
sub skip {
if ($ENV{'HTTP_IF_MODIFIED_SINCE'}) {
my $since = $ENV{'HTTP_IF_MODIFIED_SINCE'};
$since =~ s/;.*$//;
$since = str2time($since);
if (defined($since) and $since >= $mtime) {
$blosxom::header->{-status} = '304 Not Modified';
$blosxom::header->{-Last_modified} = time2str($mtime);
$blosxom::header->{-Cache_control} = $cache_control;
$blosxom::output = '';
return 1;
}
}
$blosxom::header->{-Last_modified} = time2str($mtime);
$blosxom::header->{-Cache_control} = $cache_control;
return 0;
}
sub format_time_w3c {
my $time = shift;
my($ss, $nn, $hh, $dd, $mm, $yy, $ww) = localtime($time);
$yy = $yy + 1900;
$mm = sprintf "%02d", ++$mm;
$dd = sprintf "%02d", $dd;
$hh = sprintf "%02d", $hh;
$nn = sprintf "%02d", $nn;
$ss = sprintf "%02d", $ss;
$time = "$yy-$mm-$dd" . "T" . "$hh:$nn:$ss$tzd_w3cdtf";
return $time;
}
1;
# vim:ft=perl