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