% if( ($valsi!=0) && ($natlangword!=0) ) { Erm. I'm not sure what kinds of games you're trying to play, but, you can't specify both the valsi and the natural language word ID if you're trying to display a thread. % return; % } % if( ($valsi==0) && ($natlangword==0) ) { Sorry, you'll have to specify either a valsi, or a natural language word for which to retrieve the thread. % return; % } <%perl> my $threadquery = $dbh->prepare("SELECT * FROM convenientthreads WHERE valsiid=? AND natlangwordid=? AND definitionId=?"); $threadquery->execute($valsi,$natlangword,$definition); my $threadrow = $threadquery->fetchrow_hashref; my $commentquery = $dbh->prepare("SELECT * FROM convenientcomments WHERE threadid = ?"); $commentquery->execute($threadrow->{'threadid'}); my(@comments, $main_parent_id, $main_comment); while(defined(my $commentrow=$commentquery->fetchrow_hashref)) { if ($commentrow->{'commentid'} == $commentid) { $main_parent_id = $commentrow->{'parentid'}; $main_comment = $commentrow; } push @{ $comments[ $commentrow->{'parentid'} ] }, $commentrow; } sub gencomment { my $comment = shift; my $comments = shift; my $myvalsi = shift; my $mynatlangword = shift; my $mydefinition = shift; my $content = $comment->{'content'}; # let wiki keep the lines proper; make sure not to double up # any existing %%% that a user manually entered. $content =~ s/%%%\r?\n/\n/mg; $content =~ s/\r?\n/%%%/mg; $m->out( "
Comment #$comment->{'commentnum'}: {'commentid'};" . "definition=$mydefinition" . "\">" . Wiki::interpret( $comment->{'subject'}, undef, 1 ) . "
" . (sprintf("%s", $comment->{'username'},$comment->{'realname'})) . " (" . (scalar localtime $comment->{'time'}) . ")
" . Wiki::interpret( $content ) . (defined($session{'username'}) ? sprintf("[reply]",$comment->{'commentid'}) : "") . "
"); generatebyparent( $comment->{'commentid'}, $comments, $myvalsi, $mynatlangword, $mydefinition ); $m->out( "
"); } sub generatebyparent { my $parent = shift; my $comments = shift; my $myvalsi = shift; my $mynatlangword = shift; my $mydefinition = shift; my @commentset = @{ $comments->[$parent] || [ ] }; @commentset = sort { $a->{'time'} <=> $b->{'time'} } @commentset; foreach my $comment (@commentset) { gencomment($comment, $comments, $myvalsi, $mynatlangword, $mydefinition); } } % my $isvalsi = !!($threadrow->{'valsiid'}); % $wordbeingdiscussed = ($isvalsi?$threadrow->{'valsi'}:$threadrow->{'natlangword'}); % my $wordbeingdiscussed_link = "$wordbeingdiscussed"; Discussion of "<% $wordbeingdiscussed_link %>"
% if($commentid == 0) { % if(defined($session{'username'})) { {'valsiid'}) : sprintf("natlangword=%i",$threadrow->{'natlangword'}) %>">[post new] % } % } else { [parent] [root] % }
% if ($commentid == 0) { % &generatebyparent(0,\@comments,$valsi,$natlangword, $definition ) % } else { % &gencomment($main_comment, \@comments, $valsi, $natlangword, $definition) % } <%shared> our $wordbeingdiscussed; <%method title> Discussion of "<% $wordbeingdiscussed %>" <%init> our($dbh,%session); <%once> use Wiki; <%args> $valsi => 0 $natlangword => 0 $commentid => 0 $definition => 0