X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/3ccd0fa8e1b8039edd0332c8e079cd1add4f7703..a9a9cc16143ab7c16c4f140df5dff8473ed99119:/selfforum-cgi/shared/Template/_thread.pm?ds=inline diff --git a/selfforum-cgi/shared/Template/_thread.pm b/selfforum-cgi/shared/Template/_thread.pm index 74ae404..94b9fe4 100644 --- a/selfforum-cgi/shared/Template/_thread.pm +++ b/selfforum-cgi/shared/Template/_thread.pm @@ -1,136 +1,217 @@ -# Template/_thread.pm +package Template::_thread; -# ==================================================== -# Autor: n.d.p. / 2001-01-11 -# lm : n.d.p. / 2001-01-11 -# ==================================================== -# Funktion: -# HTML-Darstellung eines Threads -# ==================================================== +################################################################################ +# # +# File: shared/Template/_thread.pm # +# # +# Authors: André Malo # +# Christian Kruse # +# # +# Description: convert parsed thread to HTML # +# # +################################################################################ use strict; - -package Template::_thread; - -use vars qw(@ISA @EXPORT); +use vars qw( + @EXPORT +); use Encode::Plain; $Encode::Plain::utf8 = 1; use Posting::_lib qw(short_hr_time); use Template; use Template::_query; +use Data::Dumper; -# ==================================================== -# Funktionsexport -# ==================================================== +################################################################################ +# +# Version check +# +# last modified: +# $Date$ (GMT) +# by $Author$ +# +sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'} -require Exporter; -@ISA = qw(Exporter); +################################################################################ +# +# Export +# +use base qw(Exporter); @EXPORT = qw(html_thread); -################################ -# sub html_thread +### html_thread () ############################################################# # -# Thread erzeugen -################################ - -sub html_thread ($$$) { - my ($msg, $template, $par) = @_; +# create HTML string +# +# Params: $msg Reference of Message-Array +# (Output of parse_single_thread in Posting::_lib) +# $template Template object +# $par Hash Reference (see doc for details) +# $params Additional parameters +# +# Return: Reference of HTML String +# +sub html_thread ($$$;$) { + my ($msg, $template, $par, $params) = @_; + my $additionalVariables = $params->{'additionalVariables'} || {}; + my $actions = { + 'action' => $params->{'action'}, + 'actionDeleted' => $params->{'actionDeleted'} + }; + my $base = $params->{'base_link'}; return \'' unless @$msg; - my $temp = $par -> {template}; - my $i = $par -> {cgi} -> {user}; - my $t = $par -> {cgi} -> {thread}; - my $p = $par -> {cgi} -> {posting}; - my $c = $par -> {cgi} -> {command}; - my $tid = $par -> {thread}; - my $html=''; - my $startlevel=0; - my $oldlevel=0; + my $temp = $par->{'template'}; + my $i = $par->{'cgi'}->{'user'}; + my $t = $par->{'cgi'}->{'thread'}; + my $p = $par->{'cgi'}->{'posting'}; + my $c = $par->{'cgi'}->{'command'}; + my $tid = $par->{'thread'}; + my $html = ''; + my $startlevel = 0; + my $oldlevel = 0; my @indexes; - # ganzer Thread - if ($par -> {start} == -1) { - $_ = $msg -> [0]; - @indexes = (1..$_ -> {answers}); - - if ($_ -> {answers}) { - $html = '
' - .${$template -> scrap ($temp -> {(length $_ -> {cat})?'start':'startNC'}, - {$temp -> {name} => $_ -> {name}, - $temp -> {subject} => $_ -> {subject}, - $temp -> {cat} => $_ -> {cat}, - $temp -> {time} => plain(short_hr_time ($_ -> {time})), - $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})}, - $par -> {addParam})} - .'
';} + # whole thread + if ($par->{'start'} == -1) { + $_ = $msg->[0]; + @indexes = (1 .. $_->{answers}); + + my $del = $_->{deleted} ? 'Deleted' : ''; + my $action = $actions->{'action'.$del}; $action =~ s/\Q{mid}\E/$_->{mid}/g; + + if ($_->{answers}) { + $html = + '
'. + + ${$template->scrap( + $temp->{ + (length $_->{'cat'} + ? 'start' + : 'startNC').($actions->{'actionDeleted'} ? $del : '') + }, + { $temp->{'name'} => $_->{'name'}, + $temp->{'subject'} => $_->{'subject'}, + $temp->{'cat'} => $_->{'cat'}, + $temp->{'time'} => plain(short_hr_time($_->{'time'})), + $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}), + $temp->{'tid'} => $tid, + $temp->{'mid'} => $_->{'mid'}, + $temp->{'command'} => $action, + %{$additionalVariables} + }, + $par->{'addParam'} + )} . + '
'; + } else { - $html = '
' - .${$template -> scrap ($temp -> {(length $_ -> {cat})?'start':'startNC'}, - {$temp -> {name} => $_ -> {name}, - $temp -> {subject} => $_ -> {subject}, - $temp -> {cat} => $_ -> {cat}, - $temp -> {time} => plain(short_hr_time ($_ -> {time})), - $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})}, - $par -> {addParam})} - .'
'; - - return \$html;}} - - # Teilthread + $html = + '
'. + ${$template->scrap( + $temp->{ + (length $_->{'cat'} + ? 'start' + : 'startNC').($actions->{'actionDeleted'} ? $del : '') + }, + { $temp->{'name'} => $_->{'name'}, + $temp->{'subject'} => $_->{'subject'}, + $temp->{'cat'} => $_->{'cat'}, + $temp->{'time'} => plain(short_hr_time ($_->{'time'})), + $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}), + $temp->{'tid'} => $tid, + $temp->{'mid'} => $_->{'mid'}, + $temp->{'command'} => $action, + %{$additionalVariables} + }, + $par->{'addParam'} + )}. + '
'; + + return \$html; + } + } + + # only subthread + # else { - my $start=-1; - for (@$msg) {$start++; last if ($_ -> {mid} == $par -> {start});} - my $end = $start + $msg -> [$start] -> {answers}; + my $start = -1; + for (@$msg) { $start++; last if ($_->{'mid'} == $par->{'start'}); } + my $end = $start + $msg->[$start]->{'answers'}; $start++; - @indexes = ($start..$end); - $oldlevel = $startlevel = $msg -> [$start] -> {level};} + @indexes = ($start .. $end); + $oldlevel = $startlevel = $msg->[$start]->{'level'} + if (defined $msg->[$start]->{'level'}); + } - # HTML erzeugen + # create HTML + # for (@$msg[@indexes]) { + my $del = $_->{'deleted'} ? 'Deleted' : ''; + my $action = $actions->{'action'.$del}; $action =~ s/\Q{mid}\E/$_->{mid}/g; - if ($_ -> {level} < $oldlevel) { - $html.='
' x ($oldlevel - $_ -> {level});} - - $oldlevel = $_ -> {level}; - - if ($_ -> {answers}) { - $html.='
' - .${$template -> scrap ($temp -> {(length $_ -> {cat})?'line':'lineNC'}, - {$temp -> {name} => $_ -> {name}, - $temp -> {subject} => $_ -> {subject}, - $temp -> {cat} => $_ -> {cat}, - $temp -> {time} => plain(short_hr_time ($_ -> {time})), - $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})}, - $par -> {addParam})} - .'
'; + if ($_->{'level'} < $oldlevel) { + $html .= '
' x ($oldlevel - $_->{'level'}); + } + + $oldlevel = $_->{'level'}; + + if ($_->{'answers'}) { + $html .= + '
'. + ${$template->scrap( + $temp->{ + (length $_->{'cat'} + ? 'line' + : 'lineNC').($actions->{'actionDeleted'} ? $del : '') + }, + { $temp->{'name'} => $_->{'name'}, + $temp->{'subject'} => $_->{'subject'}, + $temp->{'cat'} => $_->{'cat'}, + $temp->{'time'} => plain(short_hr_time ($_->{'time'})), + $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}), + $temp->{'tid'} => $tid, + $temp->{'mid'} => $_->{'mid'}, + $temp->{'command'} => $action, + %{$additionalVariables} + }, + $par->{'addParam'} + )}. + '
'; } else { - $html.='
' - .${$template -> scrap ($temp -> {(length $_ -> {cat})?'line':'lineNC'}, - {$temp -> {name} => $_ -> {name}, - $temp -> {subject} => $_ -> {subject}, - $temp -> {cat} => $_ -> {cat}, - $temp -> {time} => plain(short_hr_time ($_ -> {time})), - $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})}, - $par -> {addParam})} - .'
'; + $html .= + '
'. + ${$template->scrap( + $temp->{ + (length $_->{'cat'} + ? 'line' + : 'lineNC').($actions->{'actionDeleted'} ? $del : '') + }, + { $temp->{'name'} => $_->{'name'}, + $temp->{'subject'} => $_->{'subject'}, + $temp->{'cat'} => $_->{'cat'}, + $temp->{'time'} => plain(short_hr_time ($_->{'time'})), + $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}), + $temp->{'tid'} => $tid, + $temp->{'mid'} => $_->{'mid'}, + $temp->{'command'} => $action, + %{$additionalVariables} + }, + $par->{'addParam'} + )}. + '
'; } } - - $html.='
' x ($oldlevel - $startlevel); + $html .= '
' x ($oldlevel - $startlevel); \$html; } -# ==================================================== -# Modulinitialisierung -# ==================================================== - -# making require happy +# keep 'require' happy 1; -# ==================================================== -# end of Template::_thread -# ==================================================== \ No newline at end of file +# +# +### end of Template::_thread ###################################################