Implementation of master template: just create template html file in
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Nov 2003 16:14:37 +0000 (16:14 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Nov 2003 16:14:37 +0000 (16:14 +0000)
public_html and insert ##webpac## where you want output of webpac.
Then define template to full path to that template, and you are ready to go.

git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@147 13eb9ef6-21d5-0310-b721-a9d68796d827

WebPac.pm

index 4852325..a9aef81 100644 (file)
--- a/WebPac.pm
+++ b/WebPac.pm
@@ -27,6 +27,7 @@ my $INDEX = $cfg_global->val('webpac', 'index') || die "need index in global.con
 my $MAX_HITS = $cfg_global->val('webpac', 'max_hits') || 0;
 my $ON_PAGE =$cfg_global->val('webpac', 'on_page') || 10;
 my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1;
+my $TEMPLATE =$cfg_global->val('webpac', 'template');
 
 
 Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
@@ -49,6 +50,19 @@ sub setup {
        $self->header_props(-charset=>$CHARSET);
 }
 
+sub in_template {
+       my $html = shift || "This page is left unintentionally blank";
+       return $html if (! defined($TEMPLATE));
+       if (open(T, $TEMPLATE)) {
+               my $template_html = join("\n",<T>);
+               close(T);
+               $template_html =~ s/##webpac##/$html/gsi;
+               return $template_html;
+       } else {
+               return "Can't read template '$TEMPLATE'";
+       }
+}
+
 sub show_search_form {
        my $self = shift;
 
@@ -60,8 +74,8 @@ sub show_search_form {
 
        my $fif = new HTML::FillInForm;
 
-       return $fif->fill(scalarref => \$html, fobject => $q,
-               target => 'search');
+       return in_template($fif->fill(scalarref => \$html, fobject => $q,
+               target => 'search'));
 }
  
 sub show_results_list {
@@ -214,7 +228,7 @@ sub show_results_list {
 
        my $html = $pager->output;
 
-       return $html;
+       return in_template($html);
 }
  
 sub show_index {
@@ -272,7 +286,7 @@ sub show_index {
                template => $tmpl,
        );
 
-       return $pager->output;
+       return in_template($pager->output);
 }
 
 1;