]> git.p6c8.net - selfforum.git/blobdiff - selfforum-cgi/shared/Posting/Handle.pm
change_posting_visibility(): works now recursive, todo: delete 'invisible'
[selfforum.git] / selfforum-cgi / shared / Posting / Handle.pm
index dd05a40b4341e96bbe66cf1b8c4f77e42971b72f..11ec9aa6d8960ee8d39e64b011ccf8e577b0dd50 100644 (file)
@@ -1,5 +1,4 @@
-package Handle;
-#package Posting::Handle;
+package Posting::Handle;
 
 ################################################################################
 #                                                                              #
@@ -16,9 +15,9 @@ use strict;
 use vars qw(@EXPORT);
 use base qw(Exporter);
 
-@EXPORT = qw(hide_posting);
+@EXPORT = qw(hide_posting recover_posting);
 
-use Posting::_lib;
+use Posting::_lib qw(get_message_node);
 
 use XML::DOM;
 
@@ -29,7 +28,7 @@ use XML::DOM;
 # Params: $forum     Path and filename of forum
 #         $tpath     Path to thread files
 #         \%hashref  Reference: 'thread', 'posting', 'indexFile'
-# Return: Boolean
+# Return: -none-
 #
 sub hide_posting($$$)
 {
@@ -43,9 +42,30 @@ sub hide_posting($$$)
     change_posting_visibility($forum, $tid, $mid, 1);
 }
 
+### recover_posting() ##########################################################
+#
+# Recover a posting: delete 'invisible' flag
+#
+# Params: $forum     Path and filename of forum
+#         $tpath     Path to thread files
+#         \%hashref  Reference: 'thread', 'posting', 'indexFile'
+# Return: -none-
+#
+sub recover_posting($$$)
+{
+    my ($forum, $tpath, $info) = @_;
+    my ($tid, $mid, $indexFile) = ('t' . $info->{'thread'},
+                                   'm' . $info->{'posting'},
+                                   $info->{'indexFile'});
+
+    my $tfile = $tpath . '/' . $tid . '.xml';
+    change_posting_visibility($tfile, $tid, $mid, 0);
+    change_posting_visibility($forum, $tid, $mid, 0);
+}
+
 ### change_posting_visibility () ###############################################
 #
-# -desc-
+# Set a postings visibility flag to $invisible
 #
 # Params: $fname      Filename
 #         $tid        Thread ID
@@ -60,9 +80,16 @@ sub change_posting_visibility($$$)
     my $parser = new XML::DOM::Parser;
     my $xml = $parser->parsefile($fname);
 
+    # Set flag in given msg
     my $mnode = get_message_node($xml, $tid, $mid);
     $mnode->setAttribute('invisible', $invisible);
 
+    # Set flag in sub nodes
+    for ($mnode->getElementsByTagName('Message'))
+    {
+        $_->setAttribute('invisible', $invisible);
+    }
+
     $xml->printToFile($fname.'.temp');
     rename $fname.'.temp', $fname;
 }

patrick-canterino.de