Add "Show later" button and checkbox
This commit is contained in:
parent
c9dc0a56f6
commit
d3466e4420
46
index.cgi
46
index.cgi
|
@ -5,6 +5,9 @@
|
||||||
# mark=id
|
# mark=id
|
||||||
# mark item id as read
|
# mark item id as read
|
||||||
#
|
#
|
||||||
|
# later=id
|
||||||
|
# mark item id as "later"
|
||||||
|
#
|
||||||
# redir=id
|
# redir=id
|
||||||
# redirect to url of item id and mark item as read
|
# redirect to url of item id and mark item as read
|
||||||
#
|
#
|
||||||
|
@ -54,6 +57,8 @@ my $mcd = Cache::Memcached->new(servers => ['127.0.0.1:11211']);
|
||||||
|
|
||||||
if ($q->param('mark')) {
|
if ($q->param('mark')) {
|
||||||
mark();
|
mark();
|
||||||
|
} elsif ($q->param('later')) {
|
||||||
|
mark_later();
|
||||||
} elsif ($q->param('redir')) {
|
} elsif ($q->param('redir')) {
|
||||||
redirect();
|
redirect();
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,6 +109,31 @@ sub mark {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub mark_later {
|
||||||
|
print_log("mark_later start");
|
||||||
|
my $dbh = DBI->connect($db_conn, "", "");
|
||||||
|
$dbh->{sqlite_unicode} = 1;
|
||||||
|
my $item_id = $q->param('later');
|
||||||
|
my $item = $dbh->selectrow_hashref("select * from items where id=?", {}, $item_id);
|
||||||
|
if ($item) {
|
||||||
|
my $q1 = CGI->new($q);
|
||||||
|
$q1->delete('later');
|
||||||
|
print "Status: 302\n";
|
||||||
|
print "Location: ", $q1->self_url, "\n";
|
||||||
|
print "\n";
|
||||||
|
$dbh->do("insert into later(username, item_id) values(?, ?)", {}, $q->remote_user, $item_id);
|
||||||
|
$mcd->delete(item_info_key($q->remote_user, $item->{feed_id}));
|
||||||
|
print_log("mark_later done");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
print "Status: 404\n";
|
||||||
|
print "Content-Type: text/html; charset=utf-8\n";
|
||||||
|
print "\n";
|
||||||
|
print "not found\n";
|
||||||
|
print_log("mark_later failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sub list {
|
sub list {
|
||||||
|
|
||||||
my $feed_list_show = $q->param('fls') // "all";
|
my $feed_list_show = $q->param('fls') // "all";
|
||||||
|
@ -168,7 +198,11 @@ sub list {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my @where = ("username is null");
|
my @where = ("read.username is null");
|
||||||
|
|
||||||
|
if (!$show_later) {
|
||||||
|
push @where, "later.username is null"
|
||||||
|
}
|
||||||
|
|
||||||
if (!$show_old) {
|
if (!$show_old) {
|
||||||
push @where, "(items.old is null or items.old = 0)"
|
push @where, "(items.old is null or items.old = 0)"
|
||||||
|
@ -181,10 +215,11 @@ sub list {
|
||||||
"select feeds.id as feed_id, feeds.title as feed_title, allow_img, link, items.title as item_title, content, items.id as item_id, issued, lang
|
"select feeds.id as feed_id, feeds.title as feed_title, allow_img, link, items.title as item_title, content, items.id as item_id, issued, lang
|
||||||
from items
|
from items
|
||||||
join feeds on items.feed_id=feeds.id
|
join feeds on items.feed_id=feeds.id
|
||||||
left outer join read on (items.id=read.item_id and username=?)
|
left outer join read on (items.id=read.item_id and read.username=?)
|
||||||
|
left outer join later on (items.id=later.item_id and later.username=?)
|
||||||
$where
|
$where
|
||||||
order by issued",
|
order by issued",
|
||||||
{ Slice => {} }, $q->remote_user);
|
{ Slice => {} }, $q->remote_user, $q->remote_user);
|
||||||
}
|
}
|
||||||
my $feeds = $dbh->selectall_arrayref(
|
my $feeds = $dbh->selectall_arrayref(
|
||||||
"select id, title from feeds where active order by id",
|
"select id, title from feeds where active order by id",
|
||||||
|
@ -207,6 +242,7 @@ sub print_itemlist {
|
||||||
print "<option value='" . $q->escapeHTML($f->{id}) . "' " . ($f->{selected} ? "selected='selected'" : "") .">" . $q->escapeHTML($f->{title}) . "</option>\n";
|
print "<option value='" . $q->escapeHTML($f->{id}) . "' " . ($f->{selected} ? "selected='selected'" : "") .">" . $q->escapeHTML($f->{title}) . "</option>\n";
|
||||||
}
|
}
|
||||||
print "</select>\n";
|
print "</select>\n";
|
||||||
|
print "<label><input type='checkbox' name='sl'" . ($q->param('sl') ? " checked" : "") . "> Show later</label>\n";
|
||||||
my $fls = $q->param('fls');
|
my $fls = $q->param('fls');
|
||||||
print "<input type='hidden' name='fls' value='" . $q->escapeHTML($fls) . "'>\n" if defined $fls;
|
print "<input type='hidden' name='fls' value='" . $q->escapeHTML($fls) . "'>\n" if defined $fls;
|
||||||
print "<input type='hidden' name='sr' value='10'>\n";
|
print "<input type='hidden' name='sr' value='10'>\n";
|
||||||
|
@ -219,6 +255,7 @@ sub print_itemlist {
|
||||||
print_log("print_itemlist: \$q=" . $q->self_url);
|
print_log("print_itemlist: \$q=" . $q->self_url);
|
||||||
my $q1 = CGI->new($q);
|
my $q1 = CGI->new($q);
|
||||||
print_log("print_itemlist: \$q1=" . $q1->self_url . " (before loop)");
|
print_log("print_itemlist: \$q1=" . $q1->self_url . " (before loop)");
|
||||||
|
my $q_later = CGI->new($q);
|
||||||
print_log(scalar @$items . " before remix");
|
print_log(scalar @$items . " before remix");
|
||||||
$items = remix($items);
|
$items = remix($items);
|
||||||
print_log(scalar @$items . " after remix");
|
print_log(scalar @$items . " after remix");
|
||||||
|
@ -236,6 +273,7 @@ sub print_itemlist {
|
||||||
$n_scrub++;
|
$n_scrub++;
|
||||||
}
|
}
|
||||||
$q1->param('mark', $item->{item_id});
|
$q1->param('mark', $item->{item_id});
|
||||||
|
$q_later->param('later', $item->{item_id});
|
||||||
my $item_class = 'item' . ($is_read ? ' read' : '');
|
my $item_class = 'item' . ($is_read ? ' read' : '');
|
||||||
my $langattr = defined $item->{lang} ? "lang='$item->{lang}'" : "";
|
my $langattr = defined $item->{lang} ? "lang='$item->{lang}'" : "";
|
||||||
my $html = "";
|
my $html = "";
|
||||||
|
@ -245,12 +283,14 @@ sub print_itemlist {
|
||||||
unless ($is_read) {
|
unless ($is_read) {
|
||||||
print_log("print_itemlist: \$q1=" . $q1->self_url . " (in loop)");
|
print_log("print_itemlist: \$q1=" . $q1->self_url . " (in loop)");
|
||||||
$html .= "<div class='op'><a href='" . $q->escapeHTML($q1->self_url) . "'>Mark read</a></div>\n";
|
$html .= "<div class='op'><a href='" . $q->escapeHTML($q1->self_url) . "'>Mark read</a></div>\n";
|
||||||
|
$html .= "<div class='op'><a href='" . $q->escapeHTML($q_later->self_url) . "'>Show later</a></div>\n";
|
||||||
}
|
}
|
||||||
$html .= "<div class='feed'>" . $q->escapeHTML($item->{feed_title}) . "</div>\n";
|
$html .= "<div class='feed'>" . $q->escapeHTML($item->{feed_title}) . "</div>\n";
|
||||||
$html .= "<h2><a href='./?redir=" . $q->escapeHTML($item->{item_id}) . "'>" . $q->escapeHTML($item->{item_title}) . "</a></h2>\n";
|
$html .= "<h2><a href='./?redir=" . $q->escapeHTML($item->{item_id}) . "'>" . $q->escapeHTML($item->{item_title}) . "</a></h2>\n";
|
||||||
$html .= "<div class='content'>" . $scrubbed_content . "</div>\n";
|
$html .= "<div class='content'>" . $scrubbed_content . "</div>\n";
|
||||||
unless ($is_read) {
|
unless ($is_read) {
|
||||||
$html .= "<div class='op'><a href='" . $q->escapeHTML($q1->self_url) . "'>Mark read</a></div>\n";
|
$html .= "<div class='op'><a href='" . $q->escapeHTML($q1->self_url) . "'>Mark read</a></div>\n";
|
||||||
|
$html .= "<div class='op'><a href='" . $q->escapeHTML($q_later->self_url) . "'>Show later</a></div>\n";
|
||||||
}
|
}
|
||||||
$html .= "<div class='end'></div>\n";
|
$html .= "<div class='end'></div>\n";
|
||||||
$html .= "</div\n>";
|
$html .= "</div\n>";
|
||||||
|
|
Loading…
Reference in New Issue