1 package BSE::Formatter;
6 use base 'DevHelp::Formatter';
8 my $pop_nameid = 'AAAAAA';
22 my $self = $class->SUPER::new;
24 $self->{gen} = $opts{gen};
25 $self->{acts} = $opts{acts};
26 $self->{articles} = $opts{articles};
27 $self->{abs_urls} = $opts{abs_urls};
29 $self->{auto_images} = $opts{auto_images} || \$dummy;
30 $self->{images} = $opts{images};
31 $self->{files} = $opts{files};
32 $self->{templater} = $opts{templater};
34 my $cfg = $self->{gen}->{cfg};
35 if ($cfg->entry('html', 'mbcs', 0)) {
36 $self->{conservative_escape} = 1;
38 elsif ($cfg->entry('html', 'msentify', 0)) {
39 $self->{msentify} = 1;
41 $self->{xhtml} = $cfg->entry('basic', 'xhtml', 1);
43 $self->{redirect_links} = $cfg->entry('html', 'redirect_links', '');
44 $self->{redirect_salt} = $cfg->entry('html', 'redirect_salt', '');
52 $im->{src} || "/images/$im->{image}"
56 my ($self, $im, $align, $url, $style) = @_;
61 push @classes, "bse_image_inline";
64 if ($style =~ /^\d/) {
65 $extras .= qq! style="padding: $style"!;
67 elsif ($style =~ /^\w[\w-]*$/) {
68 push @classes, $style;
71 $extras .= qq! style="$style"!;
75 $extras .= qq! class="@classes"!;
80 cfg => $self->{gen}{cfg},
81 class => "bse_image_inline",
84 $url ? ( url => unescape_html($url) ) : (),
89 my ($self, $args) = @_;
91 my ($name, $align, $url, $style) = split /\|/, $args, 4;
92 my $im = $self->{gen}->get_gimage($name);
94 $self->_image($im, $align, $url, $style);
102 my ($self, $args) = @_;
104 my $images = $self->{images};
105 my ($index, $align, $url, $style) = split /\|/, $args, 4;
108 if ($index =~ /^\d+$/) {
109 if ($index >=1 && $index <= @$images) {
110 $im = $images->[$index-1];
111 ${$self->{auto_images}} = 0;
114 elsif ($index =~ /^[a-z]\w*$/i){
116 for my $image (@$images) {
117 if ($image->{name} && lc $image->{name} eq lc $index) {
124 return $self->_image($im, $align, $url, $style);
132 my ($self, $name, $templateid, $maxdepth) = @_;
134 $self->{gen}->_embed_low($self->{acts}, $self->{articles}, $name,
135 $templateid, $maxdepth, $self->{templater});
139 my ($self, $id, $error) = @_;
141 my $cfg = $self->{gen}->{cfg}
142 or confess "cfg not set in acts";
145 if ($id =~ /^\d+$/) {
147 $art = $self->{articles}->getByPkey($id);
149 elsif (my $work = $cfg->entry('articles', $id)) {
150 # try to find it in the config
151 $dispid = "$id ($work)";
153 $art = $self->{articles}->getByPkey($id);
156 ($art) = $self->{articles}->getBy(linkAlias => $id);
158 $$error = "** No article name '".escape_html($id)."' found **";
164 $$error = "** Cannot find article id $dispid **";
172 my ($self, $id, $title, $target, $type) = @_;
175 my $art = $self->_get_article($id, \$error)
178 my $cfg = $self->{gen}->{cfg}
179 or confess "cfg not set in acts";
181 # make the URL absolute if necessary
182 my $admin = $self->{gen}{admin_links};
185 $url = $art->{admin};
186 if (!$self->{gen}{admin}) {
187 $url .= $url =~ /\?/ ? "&" : "?";
188 $url .= "admin=0&admin_links=1";
192 $url = $art->link($self->{gen}{cfg});
194 if ($self->{abs_urls}) {
195 $url = $cfg->entryErr('site', 'url') . $url
196 unless $url =~ /^\w+:/;
198 $url = escape_html($url);
201 $title = escape_html($art->{title});
204 $target = $target ? qq! target="$target"! : '';
205 my $title_attrib = escape_html($art->{title});
208 my $class = $self->tag_class($type);
210 $class_text = qq/ class="$class"/;
214 return qq!<a href="$url" title="$title_attrib"$target$class_text>$title</a>!;
218 my ($self, $args) = @_;
220 my ($image_id, $class) = split /\|/, $args;
222 return $self->{gen}->do_popimage($image_id, $class, $self->{images});
226 my ($self, $args) = @_;
228 my ($image_id, $class) = split /\|/, $args;
230 return $self->{gen}->do_gpopimage($image_id, $class, $self->{images});
234 my ($self, $file, $text, $type) = @_;
236 my $title = defined $text ? $text : escape_html($file->{displayName});
237 if ($file->{forSale}) {
238 return escape_html($title);
241 my $title_attrib = "Filename: " . escape_html($file->{displayName});
244 my $class = $self->tag_class($type);
246 $class_text = qq/ class="$class"/;
249 my $url = "/cgi-bin/user.pl?download_file=1&file=$file->{id}";
250 return qq!<a href="! . escape_html($url) . qq!" title="$title_attrib"$class_text>! .
256 my ($self, $fileid, $text, $type) = @_;
258 my ($file) = grep $_->{name} eq $fileid, @{$self->{files}}
259 or return "** unknown file $fileid **";
261 return $self->_file($file, $text, $type);
265 my ($self, $fileid, $text, $type) = @_;
267 unless ($self->{gfiles}) {
268 $self->{gfiles} = [ Articles->global_files ];
270 my ($file) = grep $_->{name} eq $fileid, @{$self->{gfiles}}
271 or return "** unknown file $fileid **";
273 return $self->_file($file, $text, $type);
277 my ($self, $fileid, $field, $type) = @_;
279 my ($file) = grep $_->{name} eq $fileid, @{$self->{files}}
280 or return "* unknown file $fileid *";
285 cfg => $self->{gen}->cfg,
290 my ($self, $geo_id, $image_id) = @_;
292 return $self->{gen}->do_thumbimage($geo_id, $image_id, '', $self->{images});
296 my ($self, $geo_id, $image_id) = @_;
298 return $self->{gen}->do_gthumbimage($geo_id, $image_id, '');
302 my ($self, $rpart) = @_;
304 $$rpart =~ s#gthumbimage\[([^\]\[|]+)\|([^\]\[|]+)\]# $self->gthumbimage($1, $2) #ge
306 $$rpart =~ s#thumbimage\[([^\]\[|]+)\|([^\]\[|]+)\]# $self->thumbimage($1, $2) #ge
308 $$rpart =~ s#gimage\[([^\]\[]+)\]# $self->gimage($1) #ige
310 $$rpart =~ s#popdoclink\[(\w+)\|([^\]\[]+)\]# $self->doclink($1, $2, "_blank", 'popdoclink') #ige
312 $$rpart =~ s#popdoclink\[(\w+)\]# $self->doclink($1, undef, "_blank", 'popdoclink') #ige
314 $$rpart =~ s#doclink\[(\w+)\|([^\]\[]+)\]# $self->doclink($1, $2, undef, 'doclink') #ige
316 $$rpart =~ s#doclink\[(\w+)\]# $self->doclink($1, undef, undef, 'doclink') #ige
319 $$rpart =~ s#popformlink\[(\w+)\|([^\]\[]+)\]#
320 $self->formlink($1, 'popformlink', $2, '_blank') #ige
322 $$rpart =~ s#popformlink\[(\w+)\]#
323 $self->formlink($1, 'popformlink', undef, '_blank') #ige
325 $$rpart =~ s#formlink\[(\w+)\|([^\]\[]+)\]#
326 $self->formlink($1, 'formlink', $2) #ige
328 $$rpart =~ s#formlink\[(\w+)\]# $self->formlink($1, 'formlink', undef) #ige
330 $$rpart =~ s#gfilelink\[\s*(\w+)\s*\|([^\]\[]+)\]# $self->gfilelink($1, $2, 'gfilelink') #ige
332 $$rpart =~ s#gfilelink\[\s*(\w+)\s*\]# $self->gfilelink($1, undef, 'gfilelink') #ige
334 $$rpart =~ s#filelink\[\s*(\w+)\s*\|([^\]\[]+)\]# $self->filelink($1, $2, 'filelink') #ige
336 $$rpart =~ s#filelink\[\s*(\w+)\s*\]# $self->filelink($1, undef, 'filelink') #ige
338 $$rpart =~ s#file\[(\w+)(?:\|([\w.]*))?\]# $self->file($1, $2, 'file') #ige
340 $$rpart =~ s#gpopimage\[([^\[\]]+)\]# $self->gpopimage($1) #ige
342 $$rpart =~ s#popimage\[([^\[\]]+)\]# $self->popimage($1) #ige
345 return $self->SUPER::replace($rpart);
349 my ($self, $id, $type, $text, $target) = @_;
351 my $cfg = $self->{gen}{cfg};
352 my $section = "$id form";
353 my $title = escape_html($cfg->entry($section, 'title', "Send us a comment"));
355 my $secure = $cfg->entry($section, 'secure', 0);
356 my $abs_url = $self->{abs_urls} || $secure;
360 $prefix = $cfg->entryVar('site', $secure ? 'secureurl' : 'url');
365 my $class = $self->tag_class($type);
367 $extras .= qq/ class="$class"/;
371 $extras .= qq/ target="$target"/;
374 return qq!<a href="$prefix/cgi-bin/fmail.pl?form=$id" title="$title"$extras>$text</a>!;
378 my ($self, $id) = @_;
381 my $art = $self->_get_article ($id, \$error)
384 return $art->{title};
387 sub remove_formlink {
388 my ($self, $id) = @_;
390 return $self->{gen}{cfg}->entry("$id form", 'title', "Send us a comment");
393 sub remove_popimage {
394 my ($self, $args) = @_;
396 my ($image1, $class) = split /\|/, $args;
398 my $images = $self->{images};
399 if ($image1 =~ /^\d+$/) { # image index
400 if ($image1 >= 1 and $image1 <= @$images) {
401 return $images->[$image1-1]{alt};
404 elsif ($image1 =~ /^\w+$/) { # image name
405 my ($image) = grep $_->{name} eq $image1, @$images;
406 return $image ? $image->{alt} : '';
413 sub remove_gpopimage {
414 my ($self, $args) = @_;
416 my ($image1, $class) = split /\|/, $args;
418 my $im = $self->{gen}->get_gimage($image1);
427 sub remove_filelink {
428 my ($self, $fileid, $text) = @_;
430 my ($file) = grep $_->{name} eq $fileid, @{$self->{files}}
431 or return "** unknown file $fileid **";
433 return defined $text ? $text : $file->{displayName};
436 sub remove_gfilelink {
437 my ($self, $fileid, $text, $type) = @_;
439 unless ($self->{gfiles}) {
440 $self->{gfiles} = [ Articles->global_files ];
442 my ($file) = grep $_->{name} eq $fileid, @{$self->{gfiles}}
443 or return "** unknown file $fileid **";
445 return defined $text ? $text : $file->{displayName};
449 my ($self, $rpart) = @_;
451 $$rpart =~ s#g?thumbimage\[([^\]\[|]+)\|([^\]\[|]+)\]##g
453 $$rpart =~ s#gimage\[([^\]\[]+)\]##ig
455 $$rpart =~ s#popdoclink\[(\w+)\|([^\]\[]*)\]#$2#ig
457 $$rpart =~ s#popdoclink\[(\w+)\]# $self->remove_doclink($1) #ige
459 $$rpart =~ s#doclink\[(\w+)\|([^\]\[]*)\]#$2#ig
461 $$rpart =~ s#doclink\[(\w+)\]# $self->remove_doclink($1) #ige
464 $$rpart =~ s#popformlink\[(\w+)\|([^\]\[]*)\]#$2#ig
466 $$rpart =~ s#popformlink\[(\w+)\]# $self->remove_formlink($1) #ige
469 $$rpart =~ s#gfilelink\[\s*(\w+)\s*\|([^\]\[]+)\]# $self->remove_gfilelink($1, $2) #ige
471 $$rpart =~ s#gfilelink\[\s*(\w+)\s*\]# $self->remove_gfilelink($1) #ige
474 $$rpart =~ s#filelink\[\s*(\w+)\s*\|([^\]\[]+)\]# $self->remove_filelink($1, $2) #ige
476 $$rpart =~ s#filelink\[\s*(\w+)\s*\]# $self->remove_filelink($1) #ige
479 $$rpart =~ s#formlink\[(\w+)\|([^\]\[]*)\]#$2#ig
481 $$rpart =~ s#formlink\[(\w+)\]# $self->remove_formlink($1) #ige
483 $$rpart =~ s#gpopimage\[([^\[\]]+)\]# $self->remove_gpopimage($1) #ige
485 $$rpart =~ s#popimage\[([^\[\]]+)\]# $self->remove_popimage($1) #ige
491 my ($self, $type) = @_;
493 my $default = $type eq 'p' ? '' : $type;
495 return $self->{gen}{cfg}->entry('body class', $type, $default);