<% $body %> <%args> $doc => undef $field => 'body' $text => undef $imagefield => 'pictures' $imageclass => '' $rel => undef $target => undef $onclick => undef <%init> return unless ref $doc || $text; use locale; my $body = $text || $doc->$field; $body =~ s/\r//sgi; $body =~ s/[\n\t\ ]*$//sgi; if ($body !~ /(\n$2/gi; $body =~ s/\n{2,}/<\/p>\n\n

/gi; } $body =~ s/\[br\]/
/gi; if ( ref $doc ) { my $iclass = $imageclass ? ' class="'.$imageclass.'"' : ''; while ( $body =~ /\[%\ *(\w+)\ *%\]/gi ){ my $img_id = $1; my $images = $doc->get_image($img_id); if ( !(ref $images && exists $images->{filename} ) && $img_id =~ /^([a-z]+)_(\d+)$/i ) { my $iid = $2; $images = $doc->get_image($1); $images = exists $images->{"image_$iid"} ? $images->{"image_$iid"} : undef; } if ( !(ref $images && exists $images->{filename}) && $imagefield && $img_id =~ /^$imagefield\_(\d+)$/ ) { $images = $doc->get_image($imagefield); my $iid = $img_id; $iid =~ s/$imagefield/image/; $images = exists $images->{$iid} ? $images->{$iid} : undef; } my $IMG = ''; if ( ref $images && exists $images->{filename} ) { if ( $rel || $target || $onclick ) { my ($a1,$a2) = defined $rel ? ('','') : defined $onclick ? ('','') : defined $target ? ('','') : ('',''); $IMG = $a1.''.$a2; } else { $IMG = ''; } $body =~ s/\[%\ *$img_id\ *%\]/$IMG/si; } } }