diff options
author | Yorhel <git@yorhel.nl> | 2020-08-06 09:56:39 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-08-06 13:30:20 +0200 |
commit | 55fd685c182397616be8c5af1d8db996b1d2d9b1 (patch) | |
tree | 231a4a9bb7dc364f538c8ca91af8b3106e5d3732 /lib | |
parent | 96084614898f30f06b63fe121b36ba1a25c4f9e7 (diff) |
Discussions: Make /t#.# load the correct page without redirect
This removes the need for the post_url() function.
This is a small step towards supporting non-continuous post numbers.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Handler/Misc.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/Discussions/Edit.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/Discussions/Lib.pm | 11 | ||||
-rw-r--r-- | lib/VNWeb/Discussions/Thread.pm | 17 |
4 files changed, 11 insertions, 21 deletions
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm index 36c18d08..70588d45 100644 --- a/lib/VNDB/Handler/Misc.pm +++ b/lib/VNDB/Handler/Misc.pm @@ -122,7 +122,7 @@ sub homepage { my $boards = join ', ', map $BOARD_TYPE{$_->{type}}{txt}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}}; li; txt fmtage($_->{lastpost_date}).' '; - a href => VNWeb::Discussions::Lib::post_url($_->{id}, $_->{count}, 'last'), title => "Posted in $boards", shorten $_->{title}, 25; + a href => "/$_->{id}.$_->{count}#last", title => "Posted in $boards", shorten $_->{title}, 25; lit ' by '; VNWeb::HTML::user_($_, 'lastpost_'); end; diff --git a/lib/VNWeb/Discussions/Edit.pm b/lib/VNWeb/Discussions/Edit.pm index d954dbb0..3f1d495a 100644 --- a/lib/VNWeb/Discussions/Edit.pm +++ b/lib/VNWeb/Discussions/Edit.pm @@ -122,7 +122,7 @@ elm_api DiscussionsEdit => $FORM_OUT, $FORM_IN, sub { tuwf->dbExeci('INSERT INTO threads_posts', $post) if !$data->{tid}; tuwf->dbExeci('UPDATE threads_posts SET', $post, 'WHERE', { tid => $tid, num => $num }) if $data->{tid}; - elm_Redirect post_url $tid, $num, $num; + elm_Redirect "/$tid.$num"; }; diff --git a/lib/VNWeb/Discussions/Lib.pm b/lib/VNWeb/Discussions/Lib.pm index a43df50a..d16708c4 100644 --- a/lib/VNWeb/Discussions/Lib.pm +++ b/lib/VNWeb/Discussions/Lib.pm @@ -3,19 +3,12 @@ package VNWeb::Discussions::Lib; use VNWeb::Prelude; use Exporter 'import'; -our @EXPORT = qw/$BOARD_RE post_url sql_visible_threads sql_boards enrich_boards threadlist_ boardsearch_ boardtypes_/; +our @EXPORT = qw/$BOARD_RE sql_visible_threads sql_boards enrich_boards threadlist_ boardsearch_ boardtypes_/; our $BOARD_RE = join '|', map $_.($BOARD_TYPE{$_}{dbitem}?'(?:[1-9][0-9]{0,5})?':''), keys %BOARD_TYPE; -# Returns the URL to the thread page holding the given post (with optional location.hash) -sub post_url { - my($id, $num, $hash) = @_; - "/$id".($num > 25 ? '/'.ceil($num/25) : '').($hash ? "#$hash" : ''); -} - - # Returns a WHERE condition to filter threads that the current user is allowed to see. sub sql_visible_threads { return '1=1' if auth && auth->uid == 2; # Yorhel sees everything @@ -112,7 +105,7 @@ sub threadlist_ { td_ class => 'tc4', sub { user_ $l, 'lastpost_'; txt_ ' @ '; - a_ href => post_url($l->{id}, $l->{count}, 'last'), fmtdate $l->{lastpost_date}, 'full'; + a_ href => "/$l->{id}.$l->{count}#last", fmtdate $l->{lastpost_date}, 'full'; }; } for @$lst; } diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm index b3536680..87756b50 100644 --- a/lib/VNWeb/Discussions/Thread.pm +++ b/lib/VNWeb/Discussions/Thread.pm @@ -62,7 +62,7 @@ elm_api DiscussionsReply => $REPLY_OUT, $REPLY_IN, sub { my $msg = bb_subst_links $data->{msg}; tuwf->dbExeci('INSERT INTO threads_posts', { tid => $t->{id}, num => $num, uid => auth->uid, msg => $msg }); tuwf->dbExeci('UPDATE threads SET count =', \$num, 'WHERE id =', \$t->{id}); - elm_Redirect post_url $t->{id}, $num, 'last'; + elm_Redirect "/$t->{id}.$num#last"; }; @@ -152,8 +152,8 @@ sub reply_ { } -TUWF::get qr{/$RE{tid}(?:/$RE{num})?}, sub { - my($id, $page) = (tuwf->capture('id'), tuwf->capture('num')||1); +TUWF::get qr{/$RE{tid}(?:(?<sep>[\./])$RE{num})?}, sub { + my($id, $sep, $num) = (tuwf->capture('id'), tuwf->capture('sep')||'', tuwf->capture('num')); my $t = tuwf->dbRowi( 'SELECT id, title, count, hidden, locked, private @@ -165,6 +165,9 @@ TUWF::get qr{/$RE{tid}(?:/$RE{num})?}, sub { enrich_boards '', $t; + my $page = $sep eq '/' ? $num||1 : $sep eq '.' ? ceil($num/25) : 1; + $num = 0 if $sep ne '.'; + my $posts = tuwf->dbPagei({ results => 25, page => $page }, 'SELECT tp.tid as id, tp.num, tp.hidden, tp.msg', ',', sql_user(), @@ -192,7 +195,7 @@ TUWF::get qr{/$RE{tid}(?:/$RE{num})?}, sub { 'UPDATE notifications SET read = NOW() WHERE uid =', \auth->uid, 'AND ltype = \'t\' AND iid = vndbid_num(', \$id, ') AND read IS NULL' ) if auth && $t->{count} <= $page*25; - framework_ title => $t->{title}, sub { + framework_ title => $t->{title}, $num ? (js => 1, pagevars => {sethash=>"#$num"}) : (), sub { metabox_ $t; elm_ 'Discussions.Poll' => $POLL_OUT, { question => $t->{poll_question}, @@ -213,10 +216,4 @@ TUWF::get qr{/$RE{tid}(?:/$RE{num})?}, sub { } }; - -TUWF::get qr{/$RE{postid}}, sub { - my($id, $num) = (tuwf->capture('id'), tuwf->capture('num')); - tuwf->resRedirect(post_url($id, $num, $num), 'perm') -}; - 1; |