]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Forum.pm
sort threads by number, not alphabetically
[selfforum.git] / selfforum-cgi / shared / Template / Forum.pm
1 package Template::Forum;
2
3 ################################################################################
4 # #
5 # File: shared/Template/Forum.pm #
6 # #
7 # Authors: André Malo <nd@o3media.de> #
8 # #
9 # Description: print Forum main file to STDOUT #
10 # #
11 ################################################################################
12
13 use strict;
14 use vars qw(
15 @EXPORT
16 );
17
18 use Lock;
19 use Encode::Plain; $Encode::Plain::utf8 = 1;
20 use Posting::_lib qw(
21 get_all_threads
22 long_hr_time
23 );
24 use Template;
25 use Template::_conf;
26 use Template::_thread;
27
28 ################################################################################
29 #
30 # Version check
31 #
32 # last modified:
33 # $Date$ (GMT)
34 # by $Author$
35 #
36 sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
37
38 ################################################################################
39 #
40 # Export
41 #
42 use base qw(Exporter);
43 @EXPORT = qw(print_forum_as_HTML);
44
45 ### print_forum_as_HTML () #####################################################
46 #
47 # print Forum main file to STDOUT
48 #
49 # Params: $mainfile - main xml file name
50 # $tempfile - template file name
51 # $param - hash reference (see doc for details)
52 #
53 # Return: ~none~
54 #
55 sub print_forum_as_HTML ($$$) {
56 my ($mainfile, $tempfile, $param) = @_;
57 my $assign = $param -> {assign};
58
59 my $template = new Template $tempfile;
60
61 my ($threads, $stat);
62 my $main = new Lock ($mainfile);
63
64 unless ($main -> lock (LH_SHARED)) {
65 unless ($main -> masterlocked) {
66 print ${$template -> scrap (
67 $assign -> {errorDoc},
68 { $assign -> {errorText} => $template -> insert ($assign -> {'occupied'}) }
69 )};
70 }
71 else {
72 print ${$template -> scrap (
73 $assign -> {errorDoc},
74 { $assign -> {errorText} => $template -> insert ($assign -> {'notAvailable'}) }
75 )};
76 }}
77
78 else {
79 my $view = get_view_params (
80 { adminDefault => $param -> {adminDefault} }
81 );
82
83 # set process priority, remove if you don't need...
84 #
85 eval {setpriority 0,0,1};
86
87 $threads = get_all_threads ($main -> filename, $param -> {showDeleted}, $view -> {sortedMsg});
88 $main -> unlock;
89
90 print ${$template -> scrap (
91 $assign -> {mainDocStart},
92 { $assign -> {loadingTime} => plain (long_hr_time (time)) }
93 )
94 },"\n<dl>";
95
96 my $tpar = {
97 template => $param -> {tree},
98 cgi => $param -> {cgi},
99 start => -1
100 };
101
102 my @threads;
103
104 unless ($view -> {sortedThreads}) {
105 @threads = sort {$b <=> $a} keys %$threads;}
106 else {
107 @threads = sort {$a <=> $b} keys %$threads;}
108
109 for (@threads) {
110 $tpar -> {thread} = "$_";
111 print ${html_thread ($threads -> {$_}, $template, $tpar)},"\n",'<dd>&nbsp;</dd>',"\n";}
112
113 print "</dl>\n",${$template -> scrap ($assign -> {mainDocEnd})};}
114
115 return;
116 }
117
118 # keep 'require' happy
119 1;
120
121 #
122 #
123 ### end of Template::Forum #####################################################

patrick-canterino.de