diff --git a/index.cgi b/index.cgi index 6c0abbd..e6f4872 100755 --- a/index.cgi +++ b/index.cgi @@ -5,6 +5,9 @@ # mark=id # mark item id as read # +# later=id +# mark item id as "later" +# # redir=id # 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')) { mark(); +} elsif ($q->param('later')) { + mark_later(); } elsif ($q->param('redir')) { redirect(); } 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 { my $feed_list_show = $q->param('fls') // "all"; @@ -168,7 +198,11 @@ sub list { } } else { - my @where = ("username is null"); + my @where = ("read.username is null"); + + if (!$show_later) { + push @where, "later.username is null" + } if (!$show_old) { 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 from items 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 order by issued", - { Slice => {} }, $q->remote_user); + { Slice => {} }, $q->remote_user, $q->remote_user); } my $feeds = $dbh->selectall_arrayref( "select id, title from feeds where active order by id", @@ -207,6 +242,7 @@ sub print_itemlist { print "\n"; } print "\n"; + print "\n"; my $fls = $q->param('fls'); print "\n" if defined $fls; print "\n"; @@ -219,6 +255,7 @@ sub print_itemlist { print_log("print_itemlist: \$q=" . $q->self_url); my $q1 = CGI->new($q); print_log("print_itemlist: \$q1=" . $q1->self_url . " (before loop)"); + my $q_later = CGI->new($q); print_log(scalar @$items . " before remix"); $items = remix($items); print_log(scalar @$items . " after remix"); @@ -236,6 +273,7 @@ sub print_itemlist { $n_scrub++; } $q1->param('mark', $item->{item_id}); + $q_later->param('later', $item->{item_id}); my $item_class = 'item' . ($is_read ? ' read' : ''); my $langattr = defined $item->{lang} ? "lang='$item->{lang}'" : ""; my $html = ""; @@ -245,12 +283,14 @@ sub print_itemlist { unless ($is_read) { print_log("print_itemlist: \$q1=" . $q1->self_url . " (in loop)"); $html .= "
Mark read
\n"; + $html .= "
Show later
\n"; } $html .= "
" . $q->escapeHTML($item->{feed_title}) . "
\n"; $html .= "

" . $q->escapeHTML($item->{item_title}) . "

\n"; $html .= "
" . $scrubbed_content . "
\n"; unless ($is_read) { $html .= "
Mark read
\n"; + $html .= "
Show later
\n"; } $html .= "
\n"; $html .= "";