Viewing file: vna_category.pl (2 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# News Categories addon for viewnews.cgi - 1.0
push(@Addons_ViewNews_Handler, 'ProfHandler');
sub ProfHandler {
if (query_string() =~ /^profile(\S+)/) {
&BuildProfile($1);
exit;
}
}
sub BuildProfile {
my $profilename = shift;
&loadND;
print header();
@newscategories = sort(split(/\|x\|/, $NPConfig{'NewsCategories'}));
@nprof = split(/\|x\|/, $NPConfig{'NewsProfiles'});
foreach $i (@nprof) {
@nprof2 = split(/\~/, $i);
my $j = shift(@nprof2);
if ($j) {
$newsprofiles{$j} = [];
@{$newsprofiles{$j}} = @nprof2;
}
}
my $prof = $newsprofiles{$profilename};
unless ($prof) {&NPdie("No such profile.");}
# Filter by category and date.
my $filtsub;
if ($prof->[8]) {$filtsub = $prof->[8];}
else {$filtsub = 'NewsCatFilter';}
my @FilteredND = &$filtsub(split(/\!/, $prof->[2]), $prof->[3]);
# Filter by maximum number.
if (@FilteredND > $prof->[4]) {
my $maxnum = @FilteredND - 1;
my $minnum = $maxnum - $prof->[4];
$minnum++;
@FilteredND = @FilteredND[$minnum..$maxnum];
}
# Filtered! Build news.
$newsnum = @FilteredND - 1;
my $content = "";
while ($newsnum >= 0) {
my $ff;
foreach $ff (keys %{$FilteredND[$newsnum]}) {
${$ff} = $FilteredND[$newsnum]->{$ff};
}
$newsdate = GetTheDate($newstime);
&{$prof->[5]};
if ($NPConfig{'CreateAnchors'}) {$content .= qq~<a name="newsitem$newsid"></a>~;}
$content .= $newshtml;
$newsnum--;
}
&GenPage($prof->[7], $content);
}
sub NewsCatFilter {
my $mintime = pop;
$mintime = $mintime * 86400;
my @filtcats = @_;
my %filtcats;
my $nd;
undef @NewNewsData;
my @NewNewsData;
foreach $i (@filtcats) {
$filtcats{$i} = 1;
}
foreach $nd (@NewsData) {
# First, check if it matches the category.
if ($filtcats{$nd->{'newscat'}} || $filtcats{'AllCategories'}) {
# It matches. Now check the time.
if ($nd->{'newstime'} >= (time - $mintime)) {
# It's good. Add to the new array.
push(@NewNewsData, $nd);
}
}
}
return @NewNewsData;
}
|