| 1 |
3 |
ahitrov@rambler.ru |
<% $body %> |
| 2 |
|
|
<%args> |
| 3 |
|
|
|
| 4 |
|
|
$doc => undef |
| 5 |
|
|
$field => 'body' |
| 6 |
|
|
$text => undef |
| 7 |
|
|
$imagefield => 'pictures' |
| 8 |
|
|
$imageclass => '' |
| 9 |
|
|
$rel => undef |
| 10 |
|
|
$target => undef |
| 11 |
|
|
$onclick => undef |
| 12 |
|
|
|
| 13 |
|
|
</%args> |
| 14 |
|
|
<%init> |
| 15 |
|
|
|
| 16 |
|
|
return unless ref $doc || $text; |
| 17 |
|
|
use locale; |
| 18 |
|
|
my $body = $text || $doc->$field; |
| 19 |
|
|
$body =~ s/\r//sgi; |
| 20 |
|
|
$body =~ s/[\n\t\ ]*$//sgi; |
| 21 |
|
|
if ($body !~ /(<br|<p)/i) { |
| 22 |
|
|
$body =~ s/([^\n])\n([^\n])/$1<br>\n$2/gi; |
| 23 |
|
|
$body =~ s/\n{2,}/<\/p>\n\n<p>/gi; |
| 24 |
|
|
} |
| 25 |
|
|
$body =~ s/\[br\]/<br>/gi; |
| 26 |
|
|
if ( ref $doc ) { |
| 27 |
|
|
my $iclass = $imageclass ? ' class="'.$imageclass.'"' : ''; |
| 28 |
|
|
while ( $body =~ /\[%\ *(\w+)\ *%\]/gi ){ |
| 29 |
|
|
my $img_id = $1; |
| 30 |
|
|
my $images = $doc->get_image($img_id); |
| 31 |
|
|
if ( !(ref $images && exists $images->{filename} ) && $img_id =~ /^([a-z]+)_(\d+)$/i ) { |
| 32 |
|
|
my $iid = $2; |
| 33 |
|
|
$images = $doc->get_image($1); |
| 34 |
|
|
$images = exists $images->{"image_$iid"} ? $images->{"image_$iid"} : undef; |
| 35 |
|
|
} |
| 36 |
|
|
if ( !(ref $images && exists $images->{filename}) && $imagefield && $img_id =~ /^$imagefield\_(\d+)$/ ) { |
| 37 |
|
|
$images = $doc->get_image($imagefield); |
| 38 |
|
|
my $iid = $img_id; |
| 39 |
|
|
$iid =~ s/$imagefield/image/; |
| 40 |
|
|
$images = exists $images->{$iid} ? $images->{$iid} : undef; |
| 41 |
|
|
} |
| 42 |
|
|
my $IMG = ''; |
| 43 |
|
|
if ( ref $images && exists $images->{filename} ) { |
| 44 |
|
|
if ( $rel || $target || $onclick ) { |
| 45 |
|
|
my ($a1,$a2) = defined $rel ? ('<a href="'.$images->{filename}.'" target="_blank" rel="'.$rel.'">','</a>') |
| 46 |
|
|
: defined $onclick ? ('<a href="'.$images->{filename}.'" target="_blank" onclick="'.$onclick.'(\''.$images->{filename}.'\')">','</a>') |
| 47 |
|
|
: defined $target ? ('<a href="'.$images->{filename}.'" target="'.$target.'">','</a>') |
| 48 |
|
|
: ('',''); |
| 49 |
|
|
$IMG = $a1.'<img src="'.$images->{mini}{filename}.'" width="'.$images->{mini}{width}.'" height="'.$images->{mini}{height}.'" border="0"'.$iclass.'>'.$a2; |
| 50 |
|
|
} else { |
| 51 |
|
|
$IMG = '<img src="'.$images->{filename}.'" width="'.$images->{width}.'" height="'.$images->{height}.'" border="0"'.$iclass.'>'; |
| 52 |
|
|
} |
| 53 |
|
|
$body =~ s/\[%\ *$img_id\ *%\]/$IMG/si; |
| 54 |
|
|
} |
| 55 |
|
|
} |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
</%init> |