]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Posting.pm
1 package Template
::Posting
;
3 ################################################################################
5 # File: shared/Template/Posting.pm #
7 # Authors: André Malo <nd@o3media.de> #
9 # Description: show HTML formatted posting #
11 ################################################################################
19 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
34 use Template
::_thread
;
38 ################################################################################
46 sub VERSION
{(q
$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
48 ################################################################################
52 use base
qw(Exporter);
58 ### print_posting_as_HTML () ###################################################
60 # print HTML formatted Posting to STDOUT
62 # Params: $threadpath - /path/to/thread_files
63 # $tempfile - template file
64 # $param - Hash-Reference (see doc for details)
68 sub print_posting_as_HTML
($$$;$) {
69 my ($threadpath, $tempfile, $param) = @_;
71 my $template = new Template
$tempfile;
72 my $assign = $param -> {assign
};
73 my $show_deleted = $param->{showDeleted
};
75 my $view = get_view_params
({
76 adminDefault
=> $param -> {adminDefault
}
79 my $fh = new Lock
($threadpath.'t'.$param -> {thread
}.'.xml');
81 unless ($fh -> lock (LH_SHARED
)) {
82 print ${$template -> scrap
(
83 $assign -> {errorDoc
},
84 { $assign -> {errorText
} => $template -> insert
(
95 unless (-f
$fh -> filename
) {
97 print ${$template -> scrap
($assign -> {errorDoc
}, {$assign -> {errorText
} => $template -> insert
($assign->{notAvailable
})})};
100 my $xml = parse_xml_file
($fh -> filename
); #...
104 print ${$template -> scrap
($assign -> {errorDoc
}, {$assign -> {errorText
} => $template -> insert
($assign->{corrupt
})})};
107 my ($mnode, $tnode) = get_message_node
($xml, 't'.$param -> {thread
}, 'm'.$param -> {posting
});
109 # do not show if not wanted
110 if(!$mnode || ($mnode->getAttribute('invisible') && !$show_deleted)) { # and not $mnode->getAttribute('invisible')) {
111 print ${$template -> scrap
(
112 $assign -> {errorDoc
},
113 { $assign -> {errorText
} => $template -> insert
($assign -> {'notAvailable'}) }
117 my $pnode = $mnode -> getParentNode
;
118 my $header = get_message_header
($mnode);
119 my $msg = parse_single_thread
($tnode, $param -> {showDeleted
}, $view -> {sortedMsg
});
120 my $pheader = ($pnode -> getNodeName
eq 'Message')?get_message_header
($pnode):{};
122 my $formdata = $param -> {form
} -> {data
};
123 my $formact = $param -> {form
} -> {action
};
125 my $body = get_message_body
($xml, 'm'.$param -> {posting
});
127 my $text = message_field
(
129 { quoteChars
=> plain
($view -> {quoteChars
}),
130 quoting
=> $view -> {quoting
},
131 startCite
=> ${$template -> scrap
($assign -> {startCite
})},
132 endCite
=> ${$template -> scrap
($assign -> {endCite
})}
136 my $area = answer_field
(
139 quoteChars
=> plain
($view -> {quoteChars
}),
140 messages
=> $param -> {messages
}
146 $pars -> {$formdata -> {$_} -> {assign
} -> {name
}} = plain
($formdata -> {$_} -> {name
})
160 my $cgi = $param -> {cgi
};
163 thread
=> $param -> {thread
},
164 template
=> $param -> {tree
},
165 start
=> $param -> {posting
},
172 $assign->{parentTitle
} => plain
(defined $pheader->{subject
} ?
$pheader->{subject
} : ''),
173 $assign->{parentCat
} => plain
(defined $pheader->{category
} ?
$pheader->{category
} : ''),
174 $assign->{parentName
} => plain
(defined $pheader->{name
} ?
$pheader->{name
} : ''),
175 $assign->{parentTime
} => plain
(hr_time
($pheader->{time})),
176 $assign->{parentLink
} => query_string
(
177 { $cgi -> {thread
} => $param -> {thread
},
178 $cgi -> {posting
} => ($pnode -> getAttribute
('id') =~ /(\d+)/)[0]
182 print ${$template -> scrap
(
184 { $assign->{name
} => plain
(defined $header->{name
} ?
$header->{name
} : ''),
185 $assign->{email
} => plain
(defined $header->{email
} ?
$header->{email
} : ''),
186 $assign->{home
} => plain
(defined $header->{home
} ?
$header->{home
} : ''),
187 $assign->{image
} => plain
(defined $header->{image
} ?
$header->{image
} : ''),
188 $assign->{time} => plain
(hr_time
($header->{time})),
189 $assign->{message
} => $text,
190 $assign->{messageTitle
} => plain
(defined $header->{subject
} ?
$header->{subject
} : ''),
191 $assign->{messageCat
} => plain
(defined $header->{category
} ?
$header->{category
} : ''),
192 $param->{tree
}->{main
} => html_thread
($msg, $template, $tpar),
193 $formact->{post
}->{assign
} => $formact->{post
}->{url
},
194 $formact->{vote
}->{assign
} => $formact->{vote
}->{url
},
195 $formdata->{posterBody
}->{assign
}->{value
} => $area,
196 $formdata->{uniqueID
} ->{assign
}->{value
} => plain
(unique_id
),
197 $formdata->{followUp
} ->{assign
}->{value
} => plain
($param -> {thread
}.';'.$param -> {posting
}),
198 $formdata->{quoteChar
} ->{assign
}->{value
} => "ÿ".plain
(defined $view -> {quoteChars
} ?
$view -> {quoteChars
} : ''),
199 $formdata->{userID
} ->{assign
}->{value
} => '',
200 $assign->{firsttime
} => $param->{firsttime
} ?
$param->{firsttime
} : '',
201 $assign->{voted
} => $param->{voted
} ?
$param->{voted
} : ''
211 if ($param->{firsttime
}) {
212 my $cache = new Posting
::Cache
($param->{cachepath
});
214 { thread
=> $param -> {thread
},
215 posting
=> $param -> {posting
}
227 ### message_as_HTML () #########################################################
229 # create HTML String for the Messagetext
231 # Params: $xml - XML::DOM::Document object
232 # $template - Template object
233 # $param - Hash reference
234 # (assign, posting, quoteChars, quoting)
236 # Return: HTML String
238 sub message_as_HTML
($$$) {
239 my ($xml, $template, $param) = @_;
241 my $assign = $param -> {assign
};
242 my $body = get_message_body
($xml, $param -> {posting
});
244 my $text = message_field
(
246 { quoteChars
=> plain
($param -> {quoteChars
}),
247 quoting
=> $param -> {quoting
},
248 startCite
=> ${$template -> scrap
($assign -> {startCite
})},
249 endCite
=> ${$template -> scrap
($assign -> {endCite
})}
257 # keep 'require' happy
262 ### end of Template::Posting ###################################################
patrick-canterino.de