[$ include( catfile( get_setting("dir_templates"), "tpl_header.html") ) $]
[$ # display each channel that has been successfully downloaded.
### I miss my lib.pm :'(
BEGIN {
my %names;
unshift @INC, catdir(get_setting("dir_templates"), "lib");
@INC = grep { ++$names{$_} == 1 } @INC;
}
no warnings;
use AmphetaDecaf::Digest;
use AmphetaDecaf::ChannelsMeta;
$AmphetaDecaf::ChannelsMeta::INCLUDE_MAX = 50;
$AmphetaDecaf::ChannelsMeta::SHOWN_MAX = 15;
$AmphetaDecaf::ChannelsMeta::CLICKED_MAX = 0;
$AmphetaDecaf::ChannelsMeta::SEEN_MAX = 7;
$AmphetaDecaf::ChannelsMeta::AGE_MAX = 60 * 60 * 24 * 5;
our $ITEM_LEVEL1 = 5;
our $ITEM_LEVEL2 = 8;
our $DESC_AS_TITLE_LEN = 80;
use Data::Dumper qw(Dumper);
use CGI;
my @OUT;
# get the user's window target preference (which controls
# whether links should open up in the current or a new window.
my $link_target = get_setting( "user_link_target" );
### Load up the channels and their metadata, apply metadata-based sorting
my @channels = get_meta_sorted_channels("date_downloaded", "reversed_data");
my @CHANNELS_SHOWN = ();
my @CHANNELS_HIDDEN = ();
my $channels_shown_count = 0;
my $channels_hidden_count = 0;
# for each channel, parse and display.
foreach my $channel (@channels) {
my @CHANNEL_OUT = ();
### Get channel metadata
my $channel_meta = get_channel_meta($channel);
### Figure out a page-unique id for the channel
my $channel_id = $channel->{filename}.'_root'; $channel_id =~ s/\./_/g;
### Load all the channel data, moving on if nothing's there.
my $data = load_channel($channel->{filename}); next unless $data;
# if there's nothing in our date_downloaded, then we maybe
# coming from an importing, so we'll skip this feed for now.
next unless $channel->{date_downloaded};
### Get click total for the channel
my $channel_clicks = $channel_meta->{clicked} || 0;
### Output buffers for shown and hidden items
my @ITEMS_SHOWN = ();
my @ITEMS_HIDDEN = ();
### Counters for all, shown, and hidden items
my $shown_count = 0;
my $hidden_count = 0;
### Iterate through all of the items for formatting & display...
my @items = get_meta_sorted_items($channel, $data);
clean_old_item_meta($channel, @items);
foreach my $item (@items) {
### Create output line buffer for the channel item
my @ITEM_OUT = ();
my $item_meta = get_item_meta($channel, $item);
my $item_id = $item->{digest};
my $item_shown = $item_meta->{shown};
### Set the item's display class, based on the position in shown items.
my $item_style_class;
if ($item_shown) {
if ($shown_count <= $ITEM_LEVEL1) {
$item_style_class = "itemAge1";
} elsif ($shown_count <= $ITEM_LEVEL2) {
$item_style_class = "itemAge2";
} else {
$item_style_class = "itemAge3";
}
} else {
$item_style_class = "itemAge3";
}
### Produce a title for the item, basing it on the description if
### no explicit title available.
my $item_title = '';
if ($item->{title}) {
$item_title = $item->{title};
$item_title =~ s/\<[^\>]+\>//g;
} else {
$item_title = $item->{description};
$item_title =~ s/\<[^\>]+\>//g;
$item_title = substr($item_title, 0, $DESC_AS_TITLE_LEN);
}
### Clean up the title, and label it untitled if need be.
$item_title =~ s/\</g;
$item_title =~ s/\>/>/g;
$item_title = '(untitled)' if ($item_title eq '');
### Start the show.
push @ITEM_OUT, qq^
^;
### Produce the outline widget for described items.
if ($item->{description}) {
push @ITEM_OUT, qq^
^;
} else {
push @ITEM_OUT, qq^
^;
}
### Construct the link (if any), using the redirect page for click counting (view_item.html).
my $encoded_link = CGI::escape($item->{link});
push @ITEM_OUT, qq{} if $item->{link};
push @ITEM_OUT, qq{$item_title};
push @ITEM_OUT, qq{} if $item->{link};
### Close up the item title
push @ITEM_OUT, qq^^;
### Toss some statistics after items.
my $item_date = $item_meta->{date};
my $item_age = time() - $item_date;
my $item_clicked = $item_meta->{clicked} || 0;
my $item_seen = $item_meta->{seen} || 0;
my $item_age_in_hours = sprintf("%.2f", ($item_age / (60 * 60)));
push @ITEM_OUT, qq{ - (S:$item_seen C:$item_clicked A:$item_age_in_hours) };
push @ITEM_OUT, qq{
};
### Include the item description (default collapsed)
if ($item->{description}) {
my $desc = $item->{description};
### Clean the item description of possible harmful junk
$desc =~ s/\
//g;
$desc =~ s/\<\/div\>//g;
$desc =~ s/\//g;
$desc =~ s/\<\/table\>//g;
$desc =~ s/\//g;
$desc =~ s/\<\/tr\>//g;
$desc =~ s/\//g;
$desc =~ s/\<\/td\>//g;
push @ITEM_OUT, qq^
^;
}
### In the end, append the output for this item onto the shown or
### hidden list, as required
$item_meta->{seen}++;
if ($item_shown) {
### Increment the 'times seen' counter on this item.
$shown_count++;
push @ITEMS_SHOWN, join('', @ITEM_OUT);
} else {
$hidden_count++;
push @ITEMS_HIDDEN, join('', @ITEM_OUT);
};
}
save_all_item_meta($channel, @items);
my $total_channel_items = $shown_count + $hidden_count;
### Produce the channel header, as expanded or collapsed as there are
### items shown in the channel
my $channel_expand = ($shown_count > 0) ? 'expanded' : 'collapsed';
push @CHANNEL_OUT, qq{
|
|
$channel->{title}
- $channel_clicks clicks
- $total_channel_items total items
- Expand all
- Collapse all
|
Update: $channel->{date_downloaded}.
|
};
# is there an email address associated with this site?
my $email = $data->{channel}{managingEditor} ||
$data->{channel}{webMaster} ||
$data->{header}{webMaster} ||
$data->{header}{managingEditor} || undef;
if ($email) {
push @CHANNEL_OUT, qq{
|
};
}
# continue on with the rest of our header.
# we create an encoded 'xmlurl' for our del_url.
# this is so we don't get confused with channel
# query_strings being interpreted as part of our own.
my $encoded_xmlurl = encode_to_dec($channel->{xmlurl});
push @CHANNEL_OUT, qq{
|
|
|
};
# if there are no channel items, say so.
if ( not defined($data->{item}) or scalar @{$data->{item}} <= 0) {
push @CHANNEL_OUT, qq{ This channel has no items that AmphetaDesk can display. };
}
push @CHANNEL_OUT, join('', @ITEMS_SHOWN);
if ($hidden_count > 0) {
my $hidden_plural = ($hidden_count > 1) ? "s" : "";
push @CHANNEL_OUT, qq^
$hidden_count item$hidden_plural hidden...
^;
push @CHANNEL_OUT, join('', @ITEMS_HIDDEN);
push @CHANNEL_OUT, qq^
^;
}
push @CHANNEL_OUT, qq{
};
if ($shown_count > 0) {
push @CHANNELS_SHOWN, join('', @CHANNEL_OUT);
$channels_shown_count++;
} else {
push @CHANNELS_HIDDEN, join('', @CHANNEL_OUT);
$channels_hidden_count++;
}
}
push @OUT, @CHANNELS_SHOWN;
if ($channels_hidden_count > 0) {
my $hidden_plural = ($channels_hidden_count > 1) ? "s" : "";
push @OUT, qq^
|
$channels_hidden_count channel$hidden_plural hidden...
|
|
^;
push @OUT, @CHANNELS_HIDDEN;
push @OUT, qq^
^;
}
save_all_channel_meta(@channels);
$OUT .= join('', @OUT);
$]
[$ include( catfile( get_setting("dir_templates"), "tpl_footer.html") ) $]