<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Template::Archive;

################################################################################
#                                                                              #
# File:        shared/Template/Archive.pm                                      #
#                                                                              #
# Authors:     Frank Schoenmann &lt;fs@tower.de&gt;, 2001-06-04                      #
#                                                                              #
# Description: archive display                                                 #
#                                                                              #
################################################################################

use strict;

use Lock qw(:READ);
use Encode::Posting;
use Encode::Plain; $Encode::Plain::utf8 = 1;
use Posting::_lib qw(
    get_message_node
    get_message_header
    get_message_body

    get_all_threads
    parse_single_thread
    parse_xml_file

    very_short_hr_time
    short_hr_time
    hr_time
    month

    KILL_DELETED
);
use Template;
use Template::_conf;
use Template::_thread;

################################################################################
#
# Export
#
use base qw(Exporter);
@Template::Archive::EXPORT = qw(
    print_month_as_HTML
    print_thread_as_HTML
);


### print_year_as_HTML () ######################################################
#
# yearly overview over months
#
# Params:
#         $tempfile   template filename
#         $param      hash reference
# Return: -none-
#


### print_month_as_HTML () #####################################################
#
# monthly overview over threads
#
# Params: $mainfile   XML file on a per-month base
#         $tempfile   template filename
#         $param      hash reference
# Return: -none-
#
sub print_month_as_HTML($$$) {
    my ($mainfile, $tempfile, $param) = @_;

    my $assign = $param-&gt;{'assign'};

    my $template = new Template $tempfile;

    #
    # check if XML file exists
    #
    unless (-e $mainfile) {
        print ${$template-&gt;scrap(
            $assign-&gt;{'error'},
            {
                $assign-&gt;{'errorText'}  =&gt; "Es existieren keine Nachrichten für diesen Monat."
            }
        )};
        return;
    }

    #
    # try locking and read/parse threads
    #
    my ($threads, $locked);
    unless ($locked = lock_file($mainfile) and $threads = get_all_threads($mainfile, KILL_DELETED)) {
        print ${$template-&gt;scrap(
            $assign-&gt;{'error'},
            {
                $assign-&gt;{'errorText'}  =&gt; "Fehler beim Locking."
            }
        )};
        return;
    }
    unlock_file($mainfile);

    my $tmplparam = {
            $assign-&gt;{'year'}           =&gt; $param-&gt;{'year'},
            $assign-&gt;{'month'}          =&gt; $param-&gt;{'month'},
            $assign-&gt;{'monthName'}      =&gt; month($param-&gt;{'month'})
    };

    #
    # monthDocStart
    #
    print ${$template-&gt;scrap(
        $assign-&gt;{'monthDocStart'},
        $tmplparam
    )};

    #
    # thread overview
    #
    for (sort keys %$threads) {
        print ${$template-&gt;scrap(
            $assign-&gt;{'monthThreadEntry'},
            {
                $assign-&gt;{'threadID'}       =&gt; $_,
                $assign-&gt;{'threadCategory'} =&gt; $threads-&gt;{$_}-&gt;[0]-&gt;{'cat'},
                $assign-&gt;{'threadTitle'}    =&gt; $threads-&gt;{$_}-&gt;[0]-&gt;{'subject'},
                $assign-&gt;{'threadTime'}     =&gt; short_hr_time($threads-&gt;{$_}-&gt;[0]-&gt;{'time'}),
                $assign-&gt;{'threadDate'}     =&gt; very_short_hr_time($threads-&gt;{$_}-&gt;[0]-&gt;{'time'}),
                $assign-&gt;{'year'}           =&gt; $param-&gt;{'year'},
                $assign-&gt;{'month'}          =&gt; $param-&gt;{'month'}
            }
        )};
    }

    #
    # monthDocEnd
    #
    print ${$template-&gt;scrap(
        $assign-&gt;{'monthDocEnd'},
        $tmplparam
    )};


}

### print_thread_as_HTML () ####################################################
#
# print a complete thread
#
# Params: $mainfile   thread XML file
#         $tempfile   template filename
#         $param      hash reference
# Return: -none-
#
sub print_thread_as_HTML($$$) {
    my ($mainfile, $tempfile, $param) = @_;

    my $assign = $param-&gt;{'assign'};
    my $tree = $param-&gt;{'tree'};
    my $tid = $param-&gt;{'thread'};

    my $template = new Template $tempfile;

    #
    # check if XML file exists
    #
    unless (-e $mainfile) {
        print ${$template-&gt;scrap(
            $assign-&gt;{'error'},
            {
                $assign-&gt;{'errorText'}  =&gt; "Der gewünschte Thread existiert nicht."
            }
        )};
        return;
    }

    my $view = get_view_params ({
        'adminDefault'  =&gt; $param-&gt;{'adminDefault'}
    });
    my $xml = parse_xml_file($mainfile);
    my $tnode = $xml-&gt;getElementsByTagName('Thread', 1)-&gt;item(0);
    my $thread = parse_single_thread($tnode, KILL_DELETED);

    my $addparam = {
        $tree-&gt;{'year'}   =&gt; $param-&gt;{'year'},
        $tree-&gt;{'month'}  =&gt; $param-&gt;{'month'}
    };

    #
    # used to print the thread view
    #
    my $tpar = {
        'thread'    =&gt; $param-&gt;{'thread'},
        'template'  =&gt; $param-&gt;{'tree'},
        'start'     =&gt; '-1',
        'cgi'       =&gt; $param-&gt;{'cgi'},
        'addParam'  =&gt; $addparam
    };

    #
    # threadDocStart
    #
    my $tmplparam = {
            $assign-&gt;{'threadCategory'} =&gt; $thread-&gt;[0]-&gt;{'cat'},
            $assign-&gt;{'threadTitle'}    =&gt; $thread-&gt;[0]-&gt;{'subject'},
            $assign-&gt;{'year'}           =&gt; $param-&gt;{'year'},
            $assign-&gt;{'month'}          =&gt; $param-&gt;{'month'},
            $assign-&gt;{'monthName'}      =&gt; month($param-&gt;{'month'}),
            $param-&gt;{'tree'}-&gt;{'main'}  =&gt; html_thread($thread, $template, $tpar)
    };

    print ${$template-&gt;scrap(
        $assign-&gt;{'threadDocStart'},
        $tmplparam,
        1
    )};

    #
    # print thread msgs
    #
    for (@$thread) {
        my $mnode = get_message_node($xml, 't'.$tid, 'm'.$_-&gt;{'mid'});
        my $header = get_message_header($mnode);
        my $body = get_message_body($xml, 'm'.$_-&gt;{'mid'});

        my $text = message_field(
            $body,
            {
                'quoteChars'    =&gt; plain($view-&gt;{'quoteChars'}),
                'quoting'       =&gt; $view-&gt;{'quoting'},
                'startCite'     =&gt; ${$template-&gt;scrap($assign-&gt;{'startCite'})},
                'endCite'       =&gt; ${$template-&gt;scrap($assign-&gt;{'endCite'})}
            }
        );


        print ${$template-&gt;scrap(
            $assign-&gt;{'posting'},
            {
                $assign-&gt;{'msgID'}          =&gt; $_-&gt;{'mid'},
                $assign-&gt;{'msgAuthor'}      =&gt; $_-&gt;{'name'},
                $assign-&gt;{'msgMail'}        =&gt; $header-&gt;{'email'},
                $assign-&gt;{'msgHomepage'}    =&gt; $header-&gt;{'home'},
                $assign-&gt;{'msgTime'}        =&gt; hr_time($header-&gt;{'time'}),
                $assign-&gt;{'msgCategory'}    =&gt; plain($header-&gt;{'category'}),
                $assign-&gt;{'msgSubject'}     =&gt; plain($header-&gt;{'subject'}),
                $assign-&gt;{'msgBody'}        =&gt; $text
            },
            1
        )};
    }

    #
    # threadDocEnd
    #
    print ${$template-&gt;scrap(
        $assign-&gt;{'threadDocEnd'},
        $tmplparam,
        1
    )};
}


# keep require happy
1;

#
#
### end of Template::Archive ###################################################
</pre></body></html>