X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/33dc5903af2c531fdd07df0ac1591c55ea13c5d3..1783408d3a61b5bd23ee6e3bb637b6d92ac40490:/selfforum-cgi/shared/Template/Posting.pm diff --git a/selfforum-cgi/shared/Template/Posting.pm b/selfforum-cgi/shared/Template/Posting.pm index 64b0537..3fafa4a 100644 --- a/selfforum-cgi/shared/Template/Posting.pm +++ b/selfforum-cgi/shared/Template/Posting.pm @@ -4,7 +4,7 @@ package Template::Posting; # # # File: shared/Template/Posting.pm # # # -# Authors: Andre Malo , 2001-06-16 # +# Authors: AndrĂ© Malo # # # # Description: show HTML formatted posting # # # @@ -13,13 +13,12 @@ package Template::Posting; use strict; use vars qw( @EXPORT - $VERSION ); use Encode::Posting; use Encode::Plain; $Encode::Plain::utf8 = 1; use Id; -use Lock qw(:READ); +use Lock; use Posting::_lib qw( get_message_node get_message_header @@ -40,7 +39,11 @@ use XML::DOM; # # Version check # -$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +# last modified: +# $Date$ (GMT) +# by $Author$ +# +sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'} ################################################################################ # @@ -72,133 +75,146 @@ sub print_posting_as_HTML ($$$) { adminDefault => $param -> {adminDefault} }); - my ($xmlfile, $locked, $xml) = ($threadpath.'t'.$param -> {thread}.'.xml', 0); + my $fh = new Lock ($threadpath.'t'.$param -> {thread}.'.xml'); - unless (($locked = lock_file ($xmlfile)) and ($xml = parse_xml_file ($xmlfile))) { - violent_unlock_file ($xmlfile); + unless ($fh -> lock (LH_SHARED)) { print ${$template -> scrap ( $assign -> {errorDoc}, { $assign -> {errorText} => $template -> insert ( - $assign -> {(defined $locked) - ? 'occupied' - : 'notAvailable' - }) + $assign -> { + $fh -> masterlocked + ? 'notAvailable' + : 'occupied' + } + ) } )}; } else { - violent_unlock_file ($xmlfile) unless (unlock_file($xmlfile)); - - my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting}); - - unless ($mnode and not $mnode->getAttribute('invisible')) { - print ${$template -> scrap ( - $assign -> {errorDoc}, - { $assign -> {errorText} => $template -> insert ($assign -> {'notAvailable'}) } - )}; + unless (-f $fh -> filename) { + $fh -> unlock; + print ${$template -> scrap ($assign -> {errorDoc}, {$assign -> {errorText} => $template -> insert ($assign->{notAvailable})})}; } else { - my $pnode = $mnode -> getParentNode; - my $header = get_message_header ($mnode); - my $msg = parse_single_thread ($tnode, $param -> {showDeleted}, $view -> {sortedMsg}); - my $pheader = ($pnode -> getNodeName eq 'Message')?get_message_header ($pnode):{}; - - my $formdata = $param -> {form} -> {data}; - my $formact = $param -> {form} -> {action}; - - my $body = get_message_body ($xml, 'm'.$param -> {posting}); - - my $text = message_field ( - $body, - { quoteChars => plain($view -> {quoteChars}), - quoting => $view -> {quoting}, - startCite => ${$template -> scrap ($assign -> {startCite})}, - endCite => ${$template -> scrap ($assign -> {endCite})} - } - ); + my $xml = parse_xml_file ($fh -> filename); #... + $fh -> unlock; - my $area = answer_field ( - $body, - { quoteArea => 1, - quoteChars => plain($view -> {quoteChars}), - messages => $param -> {messages} + unless ($xml) { + print ${$template -> scrap ($assign -> {errorDoc}, {$assign -> {errorText} => $template -> insert ($assign->{corrupt})})}; + } + else { + my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting}); + + unless ($mnode and not $mnode->getAttribute('invisible')) { + print ${$template -> scrap ( + $assign -> {errorDoc}, + { $assign -> {errorText} => $template -> insert ($assign -> {'notAvailable'}) } + )}; } - ); - - my $pars = {}; - - $pars -> {$formdata -> {$_} -> {assign} -> {name}} = plain($formdata -> {$_} -> {name}) - for (qw( - posterBody - uniqueID - followUp - quoteChar - userID - posterName - posterEmail - posterURL - posterImage - ) - ); - - my $cgi = $param -> {cgi}; - - my $tpar = { - thread => $param -> {thread}, - template => $param -> {tree}, - start => $param -> {posting}, - cgi => $cgi - }; - - my $parent_pars; - - $parent_pars = { - $assign->{parentTitle} => plain(defined $pheader->{subject} ? $pheader->{subject} : ''), - $assign->{parentCat} => plain(defined $pheader->{category} ? $pheader->{category} : ''), - $assign->{parentName} => plain(defined $pheader->{name} ? $pheader->{name} : ''), - $assign->{parentTime} => plain(hr_time($pheader->{time})), - $assign->{parentLink} => query_string ( - { $cgi -> {thread} => $param -> {thread}, - $cgi -> {posting} => ($pnode -> getAttribute ('id') =~ /(\d+)/)[0] - }) - } if (%$pheader); - - print ${$template -> scrap ( - $assign->{mainDoc}, - { $assign->{name} => plain(defined $header->{name} ? $header->{name} : ''), - $assign->{email} => plain(defined $header->{email} ? $header->{email} : ''), - $assign->{home} => plain(defined $header->{home} ? $header->{home} : ''), - $assign->{image} => plain(defined $header->{image} ? $header->{image} : ''), - $assign->{time} => plain(hr_time($header->{time})), - $assign->{message} => $text, - $assign->{messageTitle} => plain(defined $header->{subject} ? $header->{subject} : ''), - $assign->{messageCat} => plain(defined $header->{category} ? $header->{category} : ''), - $param->{tree}->{main} => html_thread ($msg, $template, $tpar), - $formact->{post}->{assign} => $formact->{post}->{url}, - $formact->{vote}->{assign} => $formact->{vote}->{url}, - $formdata->{posterBody}->{assign}->{value} => $area, - $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id), - $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}), - $formdata->{quoteChar} ->{assign}->{value} => "ÿ".plain(defined $view -> {quoteChars} ? $view -> {quoteChars} : ''), - $formdata->{userID} ->{assign}->{value} => '', - $assign->{firsttime} => $param->{firsttime} ? $param->{firsttime} : '', - $assign->{voted} => $param->{voted} ? $param->{voted} : '' - }, - $pars, - $parent_pars - )}; - - # all output done - # - close STDOUT; - - if ($param->{firsttime}) { - my $cache = new Posting::Cache ($param->{cachepath}); - $cache -> add_view ( - { thread => $param -> {thread}, - posting => $param -> {posting} + else { + my $pnode = $mnode -> getParentNode; + my $header = get_message_header ($mnode); + my $msg = parse_single_thread ($tnode, $param -> {showDeleted}, $view -> {sortedMsg}); + my $pheader = ($pnode -> getNodeName eq 'Message')?get_message_header ($pnode):{}; + + my $formdata = $param -> {form} -> {data}; + my $formact = $param -> {form} -> {action}; + + my $body = get_message_body ($xml, 'm'.$param -> {posting}); + + my $text = message_field ( + $body, + { quoteChars => plain($view -> {quoteChars}), + quoting => $view -> {quoting}, + startCite => ${$template -> scrap ($assign -> {startCite})}, + endCite => ${$template -> scrap ($assign -> {endCite})} + } + ); + + my $area = answer_field ( + $body, + { quoteArea => 1, + quoteChars => plain($view -> {quoteChars}), + messages => $param -> {messages} + } + ); + + my $pars = {}; + + $pars -> {$formdata -> {$_} -> {assign} -> {name}} = plain($formdata -> {$_} -> {name}) + for (qw( + posterBody + uniqueID + followUp + quoteChar + userID + posterName + posterEmail + posterURL + posterImage + ) + ); + + my $cgi = $param -> {cgi}; + + my $tpar = { + thread => $param -> {thread}, + template => $param -> {tree}, + start => $param -> {posting}, + cgi => $cgi + }; + + my $parent_pars; + + $parent_pars = { + $assign->{parentTitle} => plain(defined $pheader->{subject} ? $pheader->{subject} : ''), + $assign->{parentCat} => plain(defined $pheader->{category} ? $pheader->{category} : ''), + $assign->{parentName} => plain(defined $pheader->{name} ? $pheader->{name} : ''), + $assign->{parentTime} => plain(hr_time($pheader->{time})), + $assign->{parentLink} => query_string ( + { $cgi -> {thread} => $param -> {thread}, + $cgi -> {posting} => ($pnode -> getAttribute ('id') =~ /(\d+)/)[0] + }) + } if (%$pheader); + + print ${$template -> scrap ( + $assign->{mainDoc}, + { $assign->{name} => plain(defined $header->{name} ? $header->{name} : ''), + $assign->{email} => plain(defined $header->{email} ? $header->{email} : ''), + $assign->{home} => plain(defined $header->{home} ? $header->{home} : ''), + $assign->{image} => plain(defined $header->{image} ? $header->{image} : ''), + $assign->{time} => plain(hr_time($header->{time})), + $assign->{message} => $text, + $assign->{messageTitle} => plain(defined $header->{subject} ? $header->{subject} : ''), + $assign->{messageCat} => plain(defined $header->{category} ? $header->{category} : ''), + $param->{tree}->{main} => html_thread ($msg, $template, $tpar), + $formact->{post}->{assign} => $formact->{post}->{url}, + $formact->{vote}->{assign} => $formact->{vote}->{url}, + $formdata->{posterBody}->{assign}->{value} => $area, + $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id), + $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}), + $formdata->{quoteChar} ->{assign}->{value} => "ÿ".plain(defined $view -> {quoteChars} ? $view -> {quoteChars} : ''), + $formdata->{userID} ->{assign}->{value} => '', + $assign->{firsttime} => $param->{firsttime} ? $param->{firsttime} : '', + $assign->{voted} => $param->{voted} ? $param->{voted} : '' + }, + $pars, + $parent_pars + )}; + + # all output done + # + close STDOUT; + + if ($param->{firsttime}) { + my $cache = new Posting::Cache ($param->{cachepath}); + $cache -> add_view ( + { thread => $param -> {thread}, + posting => $param -> {posting} + } + ); } - ); + } } } }