From: fox_two <> Date: Fri, 2 Mar 2001 23:20:05 +0000 (+0000) Subject: _lib.pm: style changes X-Git-Url: https://git.p6c8.net/selfforum.git/commitdiff_plain/1ba7ec317a9899f4b2201d02ffc9e93bd6cf46cc _lib.pm: style changes Handle.pm: hide_posting() and recover_posting() prepared to use _lib.pm routines for changing the main forum xml. --- diff --git a/selfforum-cgi/shared/Posting/Handle.pm b/selfforum-cgi/shared/Posting/Handle.pm index 41bb500..5ca6556 100644 --- a/selfforum-cgi/shared/Posting/Handle.pm +++ b/selfforum-cgi/shared/Posting/Handle.pm @@ -17,7 +17,8 @@ use base qw(Exporter); @EXPORT = qw(hide_posting recover_posting modify_posting); -use Posting::_lib qw(get_message_node save_file); +use Posting::_lib qw(get_message_node save_file get_all_threads + create_forum_xml_string); use XML::DOM; @@ -33,13 +34,27 @@ use XML::DOM; sub hide_posting($$$) { my ($forum, $tpath, $info) = @_; - my ($tid, $mid, $indexFile) = ('t' . $info->{'thread'}, - 'm' . $info->{'posting'}, + my ($tid, $mid, $indexFile) = ($info->{'thread'}, + $info->{'posting'}, $info->{'indexFile'}); - my $tfile = $tpath . '/' . $tid . '.xml'; - change_posting_visibility($tfile, $tid, $mid, 1); - change_posting_visibility($forum, $tid, $mid, 1); + # Thread + my $tfile = $tpath . '/t' . $tid . '.xml'; + change_posting_visibility($tfile, 't'.$tid, 'm'.$mid, 1); + + # Forum + change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 1); + + #my $f = get_all_threads($forum, 1, 0); + #for (@{f->{$tid}}) + #{ + # if ($_->{'mid'} == $mid) + # { + # $_->{'deleted'} = 1; + # } + #} + # + #create_forum_xml_string($f, ); } ### recover_posting() ########################################################## @@ -54,13 +69,27 @@ sub hide_posting($$$) sub recover_posting($$$) { my ($forum, $tpath, $info) = @_; - my ($tid, $mid, $indexFile) = ('t' . $info->{'thread'}, - 'm' . $info->{'posting'}, + my ($tid, $mid, $indexFile) = ($info->{'thread'}, + $info->{'posting'}, $info->{'indexFile'}); - my $tfile = $tpath . '/' . $tid . '.xml'; - change_posting_visibility($tfile, $tid, $mid, 0); - change_posting_visibility($forum, $tid, $mid, 0); + # Thread + my $tfile = $tpath . '/t' . $tid . '.xml'; + change_posting_visibility($tfile, 't'.$tid, 'm'.$mid, 0); + + # Forum + change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); + + #my $f = get_all_threads($forum, 1, 0); + #for (@{f->{$tid}}) + #{ + # if ($_->{'mid'} == $mid) + # { + # $_->{'deleted'} = 0; + # } + #} + # + #create_forum_xml_string($f, ); } ### change_posting_visibility () ############################################### @@ -155,4 +184,5 @@ sub change_posting_value($$$$) } +# Let it be true 1; diff --git a/selfforum-cgi/shared/Posting/_lib.pm b/selfforum-cgi/shared/Posting/_lib.pm index 5136b21..7143f6e 100644 --- a/selfforum-cgi/shared/Posting/_lib.pm +++ b/selfforum-cgi/shared/Posting/_lib.pm @@ -1,18 +1,18 @@ -# Posting/_lib.pm +package Posting::_lib; -# ==================================================== -# Autor: n.d.p. / 2001-01-07 -# lm : n.d.p. / 2001-02-25 -# ==================================================== -# Funktion: -# * Schnittstellen fuer den Zugriff auf Messages -# * Zeitdarstellung -# ==================================================== +################################################################################ +# # +# File: shared/Posting/_lib.pm # +# # +# Authors: André Malo , 2001-02-25 # +# Frank Schoenmann , 2001-03-02 # +# # +# Description: Message access interface, time format routines # +# # +################################################################################ use strict; -package Posting::_lib; - use vars qw(@EXPORT_OK); use base qw(Exporter); @@ -26,21 +26,22 @@ use XML::DOM; @EXPORT_OK = qw(get_message_header get_message_body get_message_node parse_single_thread hr_time short_hr_time long_hr_time - get_all_threads - create_forum_xml_string + get_all_threads create_forum_xml_string save_file); # ==================================================== # Zugriff uebers DOM # ==================================================== -########################### -# sub get_message_header +### get_message_header () ###################################################### # -# Messageheader auslesen -########################### - -sub get_message_header ($) { +# Read message header, return as a hash +# +# Params: $node XML message node +# Return: Hash reference (name, category, subject, email, home, image, time) +# +sub get_message_header ($) +{ my $node = shift; my %conf; @@ -54,28 +55,33 @@ sub get_message_header ($) { my $subject = $header -> getElementsByTagName ('Subject', 0) -> item (0); my $date = $header -> getElementsByTagName ('Date', 0) -> item (0); - %conf = (name => ($name -> hasChildNodes)?$name -> getFirstChild -> getData:undef, - category => ($cat -> hasChildNodes)?$cat -> getFirstChild -> getData:undef, - subject => ($subject -> hasChildNodes)?$subject -> getFirstChild -> getData:undef, - email => (defined ($email) and $email -> hasChildNodes)?$email -> getFirstChild -> getData:undef, - home => (defined ($home) and $home -> hasChildNodes)?$home -> getFirstChild -> getData:undef, - image => (defined ($image) and $image -> hasChildNodes)?$image -> getFirstChild -> getData:undef, - time => $date -> getAttribute ('longSec')); + %conf = ( + name => ($name -> hasChildNodes)?$name -> getFirstChild -> getData:undef, + category => ($cat -> hasChildNodes)?$cat -> getFirstChild -> getData:undef, + subject => ($subject -> hasChildNodes)?$subject -> getFirstChild -> getData:undef, + email => (defined ($email) and $email -> hasChildNodes)?$email -> getFirstChild -> getData:undef, + home => (defined ($home) and $home -> hasChildNodes)?$home -> getFirstChild -> getData:undef, + image => (defined ($image) and $image -> hasChildNodes)?$image -> getFirstChild - >getData:undef, + time => $date -> getAttribute ('longSec') + ); + \%conf; } -########################### -# sub get_message_header +### get_message_body () ######################################################## +# +# Read message body +# +# Params: $xml XML tree +# $mid Message ID +# Return: Scalar reference # -# Messagebody auslesen -########################### - sub get_message_body ($$) { my ($xml, $mid) = @_; my $body; - foreach ($xml -> getElementsByTagName ('ContentList', 1) -> item (0) -> getElementsByTagName ('MessageContent', 0)) + foreach ($xml->getElementsByTagName ('ContentList', 1)->item (0)->getElementsByTagName ('MessageContent', 0)) { if ($_ -> getAttribute ('mid') eq $mid) { @@ -87,26 +93,38 @@ sub get_message_body ($$) \$body; } -########################### -# sub get_message_header +### get_message_node () ######################################################## # -# Messagenode bestimmen -########################### - -sub get_message_node ($$$) { - my ($xml,$tid,$mid) = @_; - my ($mnode,$tnode); +# Search a specific message in a XML tree +# +# Params: $xml XML tree +# $tid Thread ID +# $mid Message ID +# Return: Message XML node, Thread XML node +# +sub get_message_node ($$$) +{ + my ($xml, $tid, $mid) = @_; + my ($mnode, $tnode); - for ( $xml -> getElementsByTagName ('Thread')) { - if ($_ -> getAttribute ('id') eq $tid) { + for ($xml->getElementsByTagName ('Thread')) + { + if ($_->getAttribute ('id') eq $tid) + { $tnode = $_; - for ($tnode -> getElementsByTagName ('Message')) { - if ($_ -> getAttribute ('id') eq $mid) { + for ($tnode -> getElementsByTagName ('Message')) + { + if ($_ -> getAttribute ('id') eq $mid) + { $mnode = $_; - last;}} - last;}} + last; + } + } + last; + } + } - wantarray?($mnode, $tnode):$mnode; + wantarray ? ($mnode, $tnode) : $mnode; } ########################### @@ -242,36 +260,50 @@ sub sort_thread ($$) { \@smsg; } -########################### -# sub delete_messages +### delete_message () ########################################################## # -# geoeschte Nachrichten -# herausfiltern -########################### - -sub delete_messages ($) { +# Filter out deleted messages +# +# Params: $smsg Reference of array of references of hashs +# Return: -none- +# +sub delete_messages ($) +{ my $smsg = shift; my ($z, $oldlevel, @path) = (0,0,0); - for (@$smsg) { - if ($_ -> {deleted}) { - my $n = $_ -> {answers}+1; - for (@path) {$smsg -> [$_] -> {answers} -= $n;} - splice @$smsg,$z,$n;} - - else { - if ($_ -> {level} > $oldlevel) { + for (@$smsg) + { + if ($_ -> {'deleted'}) + { + my $n = $_ -> {'answers'} + 1; + for (@path) + { + $smsg -> [$_] -> {'answers'} -= $n; + } + splice @$smsg,$z,$n; + } + else + { + if ($_ -> {'level'} > $oldlevel) + { push @path,$z; - $oldlevel = $_ -> {level};} - - elsif ($_ -> {level} < $oldlevel) { - splice @path,$_ -> {level}-$oldlevel; - $oldlevel = $_ -> {level};} - - else { $path[-1] = $z; } - - $z++;}} + $oldlevel = $_ -> {'level'}; + } + elsif ($_ -> {'level'} < $oldlevel) + { + splice @path,$_ -> {'level'} - $oldlevel; + $oldlevel = $_ -> {'level'}; + } + else + { + $path[-1] = $z; + } + + $z++; + } + } return; } @@ -283,7 +315,8 @@ sub delete_messages ($) { # parsen ########################### -sub get_all_threads ($$;$) { +sub get_all_threads ($$;$) +{ my ($file, $deleted, $sorted) = @_; my ($last_thread, $last_message, @unids, %threads); local *FILE; @@ -389,7 +422,7 @@ sub get_all_threads ($$;$) { $threads{$tid} = $smsg if (@$smsg); } - wantarray?(\%threads, $last_thread, $last_message, \@unids): \%threads; + wantarray ? (\%threads, $last_thread, $last_message, \@unids) : \%threads; } ########################### @@ -444,21 +477,26 @@ sub create_forum_xml_string ($$) { \$xml; } -########################### -# sub save_file +### save_file () ############################################################### # -# Datei speichern -########################### - -sub save_file ($$) { - my ($filename,$content) = @_; +# Save a file +# +# Params: $filename Filename +# $content File content as scalar reference +# Return: Status (1 - ok, 0 - error) +# +sub save_file ($$) +{ + my ($filename, $content) = @_; local *FILE; - open FILE,">$filename.temp" or return; + open FILE, ">$filename.temp" or return; - unless (print FILE $$content) { + unless (print FILE $$content) + { close FILE; - return;}; + return; + } close FILE or return; @@ -515,7 +553,3 @@ sub long_hr_time ($) { # making require happy 1; - -# ==================================================== -# end of Posting::_lib -# ==================================================== \ No newline at end of file