X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/50e18aa2c9ae7c3bcc78d533a03a21338c94e006..f4e905b815a97cc195eb8b8ab4703d15122ab443:/selfforum-cgi/shared/Posting/_lib.pm?ds=inline diff --git a/selfforum-cgi/shared/Posting/_lib.pm b/selfforum-cgi/shared/Posting/_lib.pm index 3d082ac..0f3f015 100644 --- a/selfforum-cgi/shared/Posting/_lib.pm +++ b/selfforum-cgi/shared/Posting/_lib.pm @@ -5,7 +5,7 @@ package Posting::_lib; # File: shared/Posting/_lib.pm # # # # Authors: André Malo , 2001-03-03 # -# Frank Schoenmann , 2001-03-02 # +# Frank Schoenmann , 2001-03-13 # # # # Description: Message access interface, time format routines # # # @@ -13,9 +13,6 @@ package Posting::_lib; use strict; -use vars qw(@EXPORT_OK); -use base qw(Exporter); - use Encode::Plain; $Encode::Plain::utf8 = 1; use XML::DOM; @@ -24,10 +21,19 @@ use XML::DOM; # Export # ==================================================== -@EXPORT_OK = qw(get_message_header get_message_body get_message_node get_body_node parse_single_thread - hr_time short_hr_time long_hr_time - get_all_threads create_forum_xml_string - save_file); +use constant SORT_ASCENT => 0; # (young postings first) +use constant SORT_DESCENT => 1; +use constant KEEP_DELETED => 1; +use constant KILL_DELETED => 0; + +use base qw(Exporter); +@Posting::_lib::EXPORT_OK = qw( + get_message_header get_message_body get_message_node get_body_node parse_single_thread parse_xml_file + hr_time short_hr_time long_hr_time + get_all_threads create_forum_xml_string + save_file + SORT_ASCENT SORT_DESCENT KEEP_DELETED KILL_DELETED +); # ==================================================== # Access via XML::DOM @@ -140,6 +146,26 @@ sub get_message_node ($$$) wantarray ? ($mnode, $tnode) : $mnode; } +### sub parse_xml_file ($) ##################################################### +# +# load the specified XML-File and create the DOM tree +# this sub is only to avoid errors and to centralize the parse process +# +# Params: $file filename +# Return: XML::DOM::Document Object (Document Node) or false +# +sub parse_xml_file ($) { + my $file = shift; + my $xml = eval { + local $SIG{__DIE__}; + new XML::DOM::Parser (KeepCDATA => 1) -> parsefile ($file); + }; + + return if ($@); + + $xml; +} + ########################### # sub parse_single_thread # @@ -273,7 +299,7 @@ sub sort_thread ($$) { \@smsg; } -### delete_messages () ########################################################## +### delete_messages () ######################################################### # # Filter out deleted messages # @@ -318,7 +344,7 @@ sub delete_messages ($) return; } -### get_all_threads () ########################################################## +### get_all_threads () ######################################################### # # Read and Parse the main file (without any XML-module, they are too slow) # @@ -326,12 +352,12 @@ sub delete_messages ($) # $deleted hold deleted (invisible) messages in result (1) oder not (0) # $sorted direction of message sort: descending (0) (default) or ascending (1) # Return: scalar context: hash reference -# list context: list (\%threads, $last_thread, $last_message, \@unids) +# list context: list (\%threads, $last_thread, $last_message, $dtd, \@unids) # sub get_all_threads ($$;$) { my ($file, $deleted, $sorted) = @_; - my ($last_thread, $last_message, @unids, %threads); + my ($last_thread, $last_message, $dtd, @unids, %threads); local (*FILE, $/); open FILE, $file or return undef; @@ -340,6 +366,7 @@ sub get_all_threads ($$;$) if (wantarray) { + ($dtd) = $xml =~ //; ($last_thread) = map {/(\d+)/} $xml =~ /]*>/; ($last_message) = map {/(\d+)/} $xml =~ /]*>/; } @@ -439,9 +466,9 @@ sub get_all_threads ($$;$) $threads{$tid} = $smsg if (@$smsg); } - wantarray ? - (\%threads, $last_thread, $last_message, \@unids) - : \%threads; + wantarray + ? (\%threads, $last_thread, $last_message, $dtd, \@unids) + : \%threads; } ###########################