]> git.p6c8.net - selfforum.git/blobdiff - selfforum-cgi/shared/Template/Posting.pm
support for fo_delete.pl
[selfforum.git] / selfforum-cgi / shared / Template / Posting.pm
index 5081a1a9a8b182e7ace6c793bfac89d73775b606..3f75b8bccaab18c0df689f0ce1843fe352d0ebda 100644 (file)
@@ -4,18 +4,21 @@ package Template::Posting;
 #                                                                              #
 # File:        shared/Template/Posting.pm                                      #
 #                                                                              #
 #                                                                              #
 # File:        shared/Template/Posting.pm                                      #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-04-01                    #
+# Authors:     André Malo <nd@o3media.de>                                      #
 #                                                                              #
 # Description: show HTML formatted posting                                     #
 #                                                                              #
 ################################################################################
 
 use strict;
 #                                                                              #
 # Description: show HTML formatted posting                                     #
 #                                                                              #
 ################################################################################
 
 use strict;
+use vars qw(
+  @EXPORT
+);
 
 use Encode::Posting;
 use Encode::Plain; $Encode::Plain::utf8 = 1;
 use Id;
 
 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
 use Posting::_lib qw(
   get_message_node
   get_message_header
@@ -24,6 +27,7 @@ use Posting::_lib qw(
   parse_xml_file
   hr_time
 );
   parse_xml_file
   hr_time
 );
+use Posting::Cache;
 use Template;
 use Template::_conf;
 use Template::_query;
 use Template;
 use Template::_conf;
 use Template::_query;
@@ -31,17 +35,27 @@ use Template::_thread;
 
 use XML::DOM;
 
 
 use XML::DOM;
 
+################################################################################
+#
+# Version check
+#
+# last modified:
+#    $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
+
 ################################################################################
 #
 # Export
 #
 use base qw(Exporter);
 ################################################################################
 #
 # Export
 #
 use base qw(Exporter);
-@Template::Posting::EXPORT = qw(
+@EXPORT = qw(
   print_posting_as_HTML
   message_as_HTML
 );
 
   print_posting_as_HTML
   message_as_HTML
 );
 
-### sub print_posting_as_HTML ($$$) ############################################
+### print_posting_as_HTML () ###################################################
 #
 # print HTML formatted Posting to STDOUT
 #
 #
 # print HTML formatted Posting to STDOUT
 #
@@ -51,111 +65,166 @@ use base qw(Exporter);
 #
 # Return: -none-
 #
 #
 # Return: -none-
 #
-sub print_posting_as_HTML ($$$) {
+sub print_posting_as_HTML ($$$;$) {
   my ($threadpath, $tempfile, $param) = @_;
 
   my $template = new Template $tempfile;
   my ($threadpath, $tempfile, $param) = @_;
 
   my $template = new Template $tempfile;
+  my $assign = $param -> {assign};
+  my $show_deleted = $param->{showDeleted};
 
 
-  # Datei sperren... (eigentlich)
   my $view = get_view_params ({
     adminDefault => $param -> {adminDefault}
   });
 
   my $view = get_view_params ({
     adminDefault => $param -> {adminDefault}
   });
 
-  my $xml = parse_xml_file ($threadpath.'t'.$param -> {thread}.'.xml');
+  my $fh = new Lock ($threadpath.'t'.$param -> {thread}.'.xml');
 
 
-  my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting});
-  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):{};
+  unless ($fh -> lock (LH_SHARED)) {
+    print ${$template -> scrap (
+      $assign -> {errorDoc},
+      { $assign -> {errorText} => $template -> insert (
+          $assign -> {
+            $fh -> masterlocked
+            ? 'notAvailable'
+            : 'occupied'
+          }
+        )
+      }
+    )};
+  }
+  else {
+    unless (-f $fh -> filename) {
+      $fh -> unlock;
+      print ${$template -> scrap ($assign -> {errorDoc}, {$assign -> {errorText} => $template -> insert ($assign->{notAvailable})})};
+    }
+    else {
+      my $xml = parse_xml_file ($fh -> filename); #...
+      $fh -> unlock;
 
 
-  my $assign = $param -> {assign};
-  my $formdata = $param -> {form} -> {data};
-  my $formact = $param -> {form} -> {action};
+      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});
 
 
-  my $body = get_message_body ($xml, 'm'.$param -> {posting});
+        # do not show if not wanted
+        if(!$mnode || ($mnode->getAttribute('invisible') && !$show_deleted)) { # and not $mnode->getAttribute('invisible')) {
+          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 $text = message_field (
-    $body,
-    { quoteChars => plain($view -> {quoteChars}),
-      quoting    => 1,
-      startCite  => ${$template -> scrap ($assign -> {startCite})},
-      endCite    => ${$template -> scrap ($assign -> {endCite})}
-    }
-  );
+          my $formdata = $param -> {form} -> {data};
+          my $formact = $param -> {form} -> {action};
 
 
-  my $area = answer_field (
-    $body,
-    { quoteArea  => 1,
-      quoteChars => plain($view -> {quoteChars}),
-      messages   => $param -> {messages}
-    }
-  );
+          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 $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($pheader->{subject}),
-    $assign->{parentCat}   => plain($pheader->{category}),
-    $assign->{parentName}  => plain($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($header->{name}),
-      $assign->{email}                           => plain($header->{email}),
-      $assign->{home}                            => plain($header->{home}),
-      $assign->{image}                           => plain($header->{image}),
-      $assign->{time}                            => plain(hr_time($header->{time})),
-      $assign->{message}                         => $text,
-      $assign->{messageTitle}                    => plain($header->{subject}),
-      $assign->{messageCat}                      => plain($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} => "&#255;".plain($view -> {quoteChars}),
-      $formdata->{userID}    ->{assign}->{value} => ''
-    },
-    $pars,
-    $parent_pars
-  )};
+          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} => "&#255;".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}
+              }
+            );
+          }
+        }
+      }
+    }
+  }
 
   return;
 }
 
 
   return;
 }
 
-### sub message_as_HTML ($$$) ##################################################
+### message_as_HTML () #########################################################
 #
 # create HTML String for the Messagetext
 #
 #
 # create HTML String for the Messagetext
 #
@@ -185,10 +254,9 @@ sub message_as_HTML ($$$) {
   $text;
 }
 
   $text;
 }
 
-# keep require happy
+# keep 'require' happy
 1;
 
 #
 #
 ### end of Template::Posting ###################################################
 1;
 
 #
 #
 ### end of Template::Posting ###################################################
-

patrick-canterino.de