-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlatest
127 lines (106 loc) · 2.86 KB
/
latest
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
122
123
124
125
126
127
######################################################################
#
# Show EPrints modified or added in the past 7 days
#
######################################################################
#
# __COPYRIGHT__
#
# Copyright 2000-2008 University of Southampton. All Rights Reserved.
#
# __LICENSE__
#
######################################################################
use EPrints;
use strict;
my $session = new EPrints::Session;
exit( 0 ) unless( defined $session );
my $ds = $session->dataset( "archive" );
my $page=$session->make_doc_fragment();
$page->appendChild( $session->html_phrase( "cgi/latest:intro" ) );
my $citation = $session->config( "latest_citation" );
my $date = time() - 86400 * 7; # 7 days
$date = EPrints::Time::iso_date( $date );
$date = "$date-".EPrints::Time::iso_date( time() ); # 7 days ago til now
my @entries;
$ds->search(
custom_order => "-datestamp",
filters => [
{ meta_fields => [qw( metadata_visibility )], value => "show" },
{ meta_fields => [qw( datestamp )], value => $date },
],
)->map(sub {
my( undef, undef, $item ) = @_;
my $datestamp = $item->value( "datestamp" );
$datestamp = EPrints::Time::datetime_utc( EPrints::Time::split_value( $datestamp ) );
$datestamp -= $datestamp % 86400;
my $age = int(((time() - time() % 86400) - $datestamp) / 86400);
$entries[$age] ||= [];
push @{$entries[$age]}, $item->render_citation_link(
$citation,
n => [scalar(@{$entries[$age]})+1, "INTEGER"] );
});
my $seensome = 0;
for( my $d=0; $d<7; ++$d )
{
my $list = $entries[$d];
next if !$list;
$seensome = 1;
my $day;
if( $d == 0 )
{
$day = $session->html_phrase( "cgi/latest:today" );
}
elsif( $d == 1 )
{
$day = $session->html_phrase( "cgi/latest:yesterday" );
}
else
{
my $dow = (localtime(time-$d*86400))[6];
$day = $session->html_phrase( "cgi/latest:day_".$dow );
}
my $h2= $session->make_element( "h2" );
$h2->appendChild( $day );
$page->appendChild( $h2 );
my $type = $session->get_citation_type( $ds, $citation );
my $container;
if( $type eq "table_row" )
{
$container = $session->make_element(
"table",
class=>"ep_latest_list" );
}
else
{
$container = $session->make_element(
"div",
class=>"ep_latest_list" );
}
$page->appendChild( $container );
foreach my $entry (@$list)
{
if( $type eq "table_row" )
{
$container->appendChild( $entry );
}
else
{
my $div = $session->make_element(
"div",
class=>"ep_latest_result" );
$div->appendChild( $entry );
$container->appendChild( $div );
}
}
$page->appendChild( $session->render_ruler() );
}
if( !$seensome )
{
$page->appendChild( $session->html_phrase( "cgi/latest:none" ) );
}
$page->appendChild( $session->html_phrase( "general:frontpage_link" ) );
my $title = $session->html_phrase( "cgi/latest:title" );
$session->build_page( $title, $page, "latest" );
$session->send_page();
$session->terminate;