Changeset 23
- Timestamp:
- 02/25/07 23:03:18 (3 years ago)
- Location:
- veekun
- Files:
-
- 5 modified
-
lib/Vee/Controller/Forum.pm (modified) (3 diffs)
-
lib/Vee/Controller/Forum/Create.pm (modified) (2 diffs)
-
site_options.yml (modified) (1 diff)
-
templates/forum/common.tt (modified) (2 diffs)
-
templates/forum/thread/view.tt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
veekun/lib/Vee/Controller/Forum.pm
r22 r23 85 85 order_by => 'FIND_IN_SET("sticky", me.flags) > 0 DESC, lastpost.time DESC', 86 86 prefetch => { firstpost => 'user', lastpost => 'user' }, 87 offset => $skip,88 rows => $perpage,87 offset => $skip, 88 rows => $perpage, 89 89 } ); 90 90 # TODO: ugly but for now I don't know the best way to clean it up … … 133 133 my $perpage = $c->site_opts->{page_sizes}{posts}; 134 134 my $lastpage = ($skip + $perpage >= $thread->postct); 135 my @posts = $c->model('DBIC::Posts')->search(135 my $posts_rs = $c->model('DBIC::Posts')->search( 136 136 { 'me.threadid' => $id, ( $filter_user ? ( 'me.userid' => $filter_user->id ) : () ) }, 137 137 { prefetch => [ 'user', { 'lastedit', 'user' } ], order_by => 'me.time ASC', offset => $skip, rows => $perpage + 1 } 138 ); # TODO: iterate138 ); 139 139 140 140 my $form = new Vee::Form( … … 148 148 my $threadflags = ''; # TODO 149 149 150 $s->{page_title }= $thread->subject . ' - Forums';150 $s->{page_title} = $thread->subject . ' - Forums'; 151 151 $s->{page_header} = $thread->subject; 152 $s->{link_name }= 'forum';153 $s->{crumbs }= [ '<a href="/forum">Forum Index</a>', '<a href="/forum/'.$thread->forum->id.'">'.$thread->forum->name.'</a>', qq'$threadflags<a href="/forum/thread/'.$thread->id.'">'.$thread->subject.'</a>' ];152 $s->{link_name} = 'forum'; 153 $s->{crumbs} = [ '<a href="/forum">Forum Index</a>', '<a href="/forum/'.$thread->forum->id.'">'.$thread->forum->name.'</a>', qq'$threadflags<a href="/forum/thread/'.$thread->id.'">'.$thread->subject.'</a>' ]; 154 154 if ($filter_user) { push @{ $s->{crumbs} }, '<a href="/user/'.$filter_user->id.'">'.$filter_user->name.'</a>\'s posts' } 155 $s->{extra_css } = 'forum'; 156 $s->{form } = $form; 157 $s->{postbar_color} = sub { Vee::Utils::hsv2rgb(shift, 192, 192) }; # Remove after making global 155 $s->{extra_css} = 'forum'; 156 $s->{form} = $form; 157 158 $s->{postbar_color} = sub { Vee::Utils::hsv2rgb(shift, 192, 192) }; # Remove after making global 159 $s->{physical_lastpost} = $thread->search_related('posts', undef, { order_by => [ 'time DESC', 'id DESC' ] })->single; 158 160 159 161 $s->{forum} = $thread->forum; 160 162 $s->{thread} = $thread; 161 163 $s->{page_islast} = $lastpage; 162 $s->{next_post} = $lastpage ? undef : pop @posts; 163 $s->{posts} = \@posts; 164 # $s->{can_post} = !$sess->test_post($thread, $thread->forumid), 164 $s->{posts_rs} = $posts_rs; 165 165 $s->{skip} = $skip; 166 166 $s->{filter} = $filter; -
veekun/lib/Vee/Controller/Forum/Create.pm
r20 r23 8 8 use Vee::Utils::Forum; 9 9 10 use DateTime; 11 10 12 =head1 NAME 11 13 … … 61 63 if (@bbcode_errors) { 62 64 $c->vee_abort("Your post contains invalid bbcode. Please go back and fix it. Also, vee really needs better error messages; sorry about that."); 63 } 65 } 66 $parsed_message = Vee::Utils::fix_newlines( $parsed_message ); 64 67 65 68 if ('preview' eq lc $c->req->params->{submit}) { 66 69 $c->detach('post_preview'); 67 70 } 68 69 # create the post 70 my $post = $c->model('DBIC')->schema->txn_do( sub { 71 my $post = $c->model('DBIC::Posts')->create({ 72 threadid => $thread->id, 73 userid => $c->user->obj->id, 74 time => time, 75 format => 'bbcode', 76 message => Vee::Utils::fix_newlines( $parsed_message ), 77 }); 78 # update thread's last-post stats 79 $thread->lastpostid( $post->id ); 80 $thread->lasttime( time ); 81 $thread->postct( $thread->postct + 1 ); 82 $thread->update; 83 # update forum's last-post stats 84 $thread->forum->lastpostid( $post->id ); 85 $thread->forum->postct( $thread->forum->postct + 1 ); 86 $thread->forum->update; 87 # update user's postcount 88 $c->user->obj->postct( $c->user->postct + 1 ); 89 $c->user->obj->update; 90 return $post; 91 } ); 71 72 # check for daabaru-post 73 # TODO: apply this to thread creation too? not as common.. and merge as well? 74 my $last_post = $c->model('DBIC::Posts')->search({ 75 threadid => $thread->id, 76 time => { '>=', time - $c->site_opts->{post_automerge_time} }, 77 }, { 78 order_by => 'time DESC', 79 })->single; 80 81 my $post; 82 # only do merging/prevention if the last post is this user's 83 if ($last_post and $last_post->userid == $c->user->obj->id) { 84 if ($last_post->message eq $parsed_message) { 85 $c->vee_abort("You have already posted that message recently."); 86 } 87 88 # different post; edit the last one 89 # TODO: what about formats/options of both posts? not a problem now, but later.. 90 $post = $c->model('DBIC')->schema->txn_do( sub { 91 my $edit = $c->model('DBIC::Edits')->create({ 92 postid => $last_post->id, 93 userid => $c->user->obj->id, 94 time => time, 95 oldmessage => $last_post->message, 96 }); 97 $last_post->message( 98 $last_post->message . 99 "\n[hr][i]Automerged:[/i]\n" . 100 $parsed_message 101 ); 102 $last_post->lasteditid( $edit->id ); 103 $last_post->update; 104 105 $thread->lastpostid( $last_post->id ); 106 $thread->lasttime( time ); 107 $thread->update 108 109 return $last_post; 110 } ); 111 } else { 112 # create the post 113 $post = $c->model('DBIC')->schema->txn_do( sub { 114 my $post = $c->model('DBIC::Posts')->create({ 115 threadid => $thread->id, 116 userid => $c->user->obj->id, 117 time => time, 118 format => 'bbcode', 119 message => $parsed_message, 120 }); 121 # update thread's last-post stats 122 $thread->lastpostid( $post->id ); 123 $thread->lasttime( time ); 124 $thread->postct( $thread->postct + 1 ); 125 $thread->update; 126 # update forum's last-post stats 127 $thread->forum->lastpostid( $post->id ); 128 $thread->forum->postct( $thread->forum->postct + 1 ); 129 $thread->forum->update; 130 # update user's postcount 131 $c->user->obj->postct( $c->user->postct + 1 ); 132 $c->user->obj->update; 133 return $post; 134 } ); 135 } 92 136 93 137 # finito! -
veekun/site_options.yml
r21 r23 70 70 user_activity_timeout: 900 71 71 72 # Number of seconds before a user can double-post on a thread 73 post_automerge_time: 1800 74 72 75 # URL for Subversion repository path to check for activity 73 76 # Note that at the moment this *requires* anon access! -
veekun/templates/forum/common.tt
r14 r23 147 147 <td class="forum-count">[% thread.postct - 1 %]</td><td class="forum-count">[% thread.hitct %]</td> 148 148 <td class="forum-postinfo"> 149 [% IF thread. lastpostid == thread.firstpostid-%]149 [% IF thread.postct <= 1 -%] 150 150 - 151 151 [% ELSE %] … … 175 175 176 176 [% BLOCK forums_each %][%# forum -%] 177 [%# last_post = sql.post_summary(forum.lastpost) %]178 [%# last_name = last_post.user.name %]179 [%# last_thread = sql.thread_info(last_post.threadid) -%]180 177 <tr><td class="forum-icon"> 181 178 [% UNLESS forum.accessibility == 'normal' %]<img src="/images/icons/[% forum.accessibility %].png" alt="[% forum.accessibility %]" title="[% forum.accessibility %]"/>[% END %] -
veekun/templates/forum/thread/view.tt
r5 r23 6 6 [% this_pagelist = pagelist(skip, c.site_opts.page_sizes.posts, thread.postct, c.uri('Forum', 'thread', thread.id), c.req.params); this_pagelist %] 7 7 [% INCLUDE posts_start %] 8 [% FOREACH p IN posts %] 9 [% IF !loop.first %] 10 <div class="forum-postdiff">[% p.time - loop.prev.time | timespan %]</div> 8 [% done_posts = 0 %] 9 [% WHILE (p = posts_rs.next) %] 10 [% IF done_posts > 0 %] 11 <div class="forum-postdiff">[% p.time - last_post_time | timespan %]</div> 11 12 [% END %] 12 13 [% INCLUDE posts_each post=p thread=thread forum=thread.forum show_deleted=0 %] 14 [% done_posts = done_posts + 1 %] 15 [% last_post_time = p.time %] 16 [% IF done_posts >= c.site_opts.page_sizes.posts; LAST; END %] 13 17 [% END %] 14 18 15 [% IF !posts.size%]19 [% IF NOT done_posts %] 16 20 [% IF filter %] 17 21 <div class="warning"><a href="/users/[% filter.id %]">[% filter.name %]</a> has no posts on this thread.</div> … … 27 31 28 32 [% IF page_islast %] 29 <div class="forum-postdiff">[% time - posts.last.time | timespan %]<br/>since last post</div>33 <div class="forum-postdiff">[% time - last_post_time | timespan %]<br/>since last post</div> 30 34 [% ELSE %] 31 <div class="forum-postdiff">[% next_post.time - posts.last.time | timespan %]<br/>to first post on next page</div>35 <div class="forum-postdiff">[% posts_rs.next.time - last_post_time | timespan %]<br/>to first post on next page</div> 32 36 [% END %] 33 37 <form action="/forum/thread/[% thread.id %]" method="get" class="forum-filter"> … … 47 51 [% IF can_post(thread) %] 48 52 <h1>Reply to this thread</h1> 49 [% IF thread.lastpost.time %]50 [% age = time - thread.lastpost.time %]53 [% IF physical_lastpost.time %] 54 [% age = time - physical_lastpost.time %] 51 55 [% IF age > 60 * 60 * 24 * 14 %] 52 56 <div class="warning"> <p>The last post on this thread is more than two weeks old.</p> <p>It has most likely been long forgotten. Please consider whether posting is that good an idea.</p> </div> … … 55 59 [% END %] 56 60 [% END %] 57 [% IF user AND thread.lastpost.userid AND thread.lastpost.userid == user.id %]58 <div class="warning"> <p>The last post on this thread is yours; if you reply again, your new post will be combined with the old one and the thread will be bumped. If you like, you can manually <a href="/forum/post/[% thread.lastpost.id %]/edit">edit the last post</a> instead.</p> </div>61 [% IF user AND physical_lastpost.userid AND physical_lastpost.userid == user.id %] 62 <div class="warning"> <p>The last post on this thread is yours; if you reply again, your new post will be combined with the old one and the thread will be bumped. If you like, you can manually <a href="/forum/post/[% physical_lastpost.id %]/edit">edit the last post</a> instead.</p> </div> 59 63 [% END %] 60 64 <form class="forum-reply" action="[% uri('Forum::Create', 'post') %]" method="post">
