OMatic/recent.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 71 CC 3 SCAR 16.1
CC
3
Cov
0%
main
12.0
byModDate
2.0
BEGIN
2.0
CRAP 5.0
1 ##############################################################################
2 # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. #
3 # #
4 # This program is free software; you can redistribute it and/or #
5 # modify it under the terms of the GNU General Public License #
6 # as published by the Free Software Foundation; either version 2 #
7 # of the License, or (at your option) any later version. #
8 # #
9 # This program is distributed in the hope that it will be useful, #
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 # GNU General Public License for more details. #
13 # #
14 # You should have received a copy of the GNU General Public License #
15 # along with this program; if not, write to the Free Software #
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
17 # #
18 # Jon Howell can be contacted at: #
19 # 6211 Sudikoff Lab, Dartmouth College #
20 # Hanover, NH 03755-3510 #
21 # jonh@cs.dartmouth.edu #
22 # #
23 # An electronic copy of the GPL is available at: #
24 # http://www.gnu.org/copyleft/gpl.html #
25 # #
26 ##############################################################################
27  
28 use strict;
29  
30 package FAQ::OMatic::recent;
31  
32 use CGI;
33 use FAQ::OMatic::Item;
34 use FAQ::OMatic;
35 use FAQ::OMatic::SearchMod;
36 use FAQ::OMatic::I18N;
37  
38 sub main {
39 my $cgi = FAQ::OMatic::dispatch::cgi();
40
41 my $params = FAQ::OMatic::getParams($cgi);
42  
43 # Get the names of the recent files
44 my $matchset = FAQ::OMatic::SearchMod::getRecentSet($params);
45  
46 # Filter out those in the trash
47 # THANKS: dschulte@facstaff.wisc.edu for the suggestion
48 my @finalset = ();
49 my $file;
50 foreach $file (@{$matchset}) {
51 my $item = new FAQ::OMatic::Item($file);
52 if (not $item->hasParent('trash')) {
53 push @finalset, $item;
54 }
55 }
56  
57 # reasonable text for 'n' days
58 my $textDays = FAQ::OMatic::SearchMod::textDays($params->{'_duration'});
59
60 my $rt = FAQ::OMatic::pageHeader($params);
61 if (scalar(@{$matchset})==0) {
62 $rt.=gettexta("No items were modified in the last %0.", $textDays)
63 ."\n<br>\n";
64 } else {
65 $rt.=gettexta("Items modified in the last %0:", $textDays)
66 ."\n<p>\n";
67  
68 my $item;
69 my $itemboxes = [];
70 foreach $item (sort byModDate @finalset) {
71 push @$itemboxes, {
72 'item'=>$item,
73 'rows'=>[
74 { 'type'=>'wide', 'text'=>
75 FAQ::OMatic::makeAref("faq",
76 { 'file' => $item->{'filename'} })
77 .$item->getTitle()."</a>",
78 'id'=>'recent-title' },
79 # TODO -- include first part or an excerpt from it?
80 { 'type'=>'wide',
81 'text'=>FAQ::OMatic::Item::compactDate(
82 $item->{'LastModifiedSecs'}),
83 'id'=>'recent-date' }
84 ] };
85 }
86 $rt.=FAQ::OMatic::Appearance::itemRender($params, $itemboxes);
87 }
88
89 $rt .= FAQ::OMatic::pageFooter($params, ['search', 'faq']);
90  
91 print $rt;
92  
93 FAQ::OMatic::SearchMod::closeWordDB();
94 }
95  
96 sub byModDate {
97 my $lmsa = $a->{'LastModifiedSecs'} || -1;
98 my $lmsb = $b->{'LastModifiedSecs'} || -1;
99 return $lmsb <=> $lmsa;
100 }
101  
102 1;