Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/RenderListPlugin.pm |
Statements | Executed 23 statements in 1.75ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 32µs | 32µs | preRenderingHandler | Foswiki::Plugins::RenderListPlugin::
1 | 1 | 1 | 22µs | 72µs | initPlugin | Foswiki::Plugins::RenderListPlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@7 | Foswiki::Plugins::RenderListPlugin::
1 | 1 | 1 | 9µs | 14µs | BEGIN@8 | Foswiki::Plugins::RenderListPlugin::
1 | 1 | 1 | 9µs | 54µs | BEGIN@11 | Foswiki::Plugins::RenderListPlugin::
0 | 0 | 0 | 0s | 0s | fixImageTag | Foswiki::Plugins::RenderListPlugin::
0 | 0 | 0 | 0s | 0s | handleRenderList | Foswiki::Plugins::RenderListPlugin::
0 | 0 | 0 | 0s | 0s | renderIconList | Foswiki::Plugins::RenderListPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||||
3 | # ========================= | ||||
4 | package Foswiki::Plugins::RenderListPlugin | ||||
5 | ; # change the package name and $pluginName!!! | ||||
6 | |||||
7 | 2 | 28µs | 2 | 41µs | # spent 27µs (14+13) within Foswiki::Plugins::RenderListPlugin::BEGIN@7 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.30 at line 7 # spent 27µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@7
# spent 13µs making 1 call to strict::import |
8 | 2 | 32µs | 2 | 18µs | # spent 14µs (9+4) within Foswiki::Plugins::RenderListPlugin::BEGIN@8 which was called:
# once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.30 at line 8 # spent 14µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@8
# spent 4µs making 1 call to warnings::import |
9 | |||||
10 | # ========================= | ||||
11 | 1 | 6µs | 1 | 45µs | # spent 54µs (9+45) within Foswiki::Plugins::RenderListPlugin::BEGIN@11 which was called:
# once (9µs+45µs) by Foswiki::Plugin::BEGIN@2.30 at line 14 # spent 45µs making 1 call to vars::import |
12 | $web $topic $user $installWeb | ||||
13 | $pubUrl $attachUrl | ||||
14 | 1 | 1.62ms | 1 | 54µs | ); # spent 54µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@11 |
15 | |||||
16 | 1 | 600ns | our $VERSION = '2.27'; | ||
17 | 1 | 200ns | our $RELEASE = '2.27'; | ||
18 | 1 | 200ns | our $pluginName = 'RenderListPlugin'; # Name of this Plugin | ||
19 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
20 | 1 | 200ns | our $SHORTDESCRIPTION = 'Render bullet lists in a variety of formats'; | ||
21 | |||||
22 | 1 | 6µs | our %defaultThemes = ( | ||
23 | THREAD => 'tree, 1', | ||||
24 | HOME => | ||||
25 | 'icon, 1, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/home.gif', | ||||
26 | ORG => | ||||
27 | 'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/home.gif', | ||||
28 | GROUP => | ||||
29 | 'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/group.gif', | ||||
30 | EMAIL => | ||||
31 | 'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/email.gif', | ||||
32 | TREND => | ||||
33 | 'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/trend.gif', | ||||
34 | FILE => | ||||
35 | 'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/file.gif', | ||||
36 | ); | ||||
37 | |||||
38 | # ========================= | ||||
39 | # spent 72µs (22+50) within Foswiki::Plugins::RenderListPlugin::initPlugin which was called:
# once (22µs+50µs) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm | ||||
40 | 1 | 2µs | ( $topic, $web, $user, $installWeb ) = @_; | ||
41 | |||||
42 | # check for Plugins.pm versions | ||||
43 | 1 | 11µs | 1 | 5µs | if ( $Foswiki::Plugins::VERSION < 1 ) { # spent 5µs making 1 call to version::vxs::VCMP |
44 | Foswiki::Func::writeWarning( | ||||
45 | "Version mismatch between $pluginName and Plugins.pm"); | ||||
46 | return 0; | ||||
47 | } | ||||
48 | |||||
49 | # one time initialization | ||||
50 | 1 | 6µs | 2 | 45µs | $pubUrl = Foswiki::Func::getUrlHost() . Foswiki::Func::getPubUrlPath(); # spent 41µs making 1 call to Foswiki::Func::getPubUrlPath
# spent 3µs making 1 call to Foswiki::Func::getUrlHost |
51 | 1 | 2µs | $attachUrl = "$pubUrl/$installWeb/$pluginName"; | ||
52 | |||||
53 | # Plugin correctly initialized | ||||
54 | 1 | 4µs | return 1; | ||
55 | } | ||||
56 | |||||
57 | # ========================= | ||||
58 | # spent 32µs within Foswiki::Plugins::RenderListPlugin::preRenderingHandler which was called 5 times, avg 6µs/call:
# 5 times (32µs+0s) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 6µs/call | ||||
59 | ### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead | ||||
60 | |||||
61 | # This handler is called by getRenderedVersion just before the line loop | ||||
62 | |||||
63 | # Render here, not in commonTagsHandler so that lists produced by | ||||
64 | # Plugins, TOC and SEARCH can be rendered | ||||
65 | 5 | 27µs | if ( $_[0] =~ m/%RENDERLIST/ ) { | ||
66 | unless ( $_[0] =~ | ||||
67 | s/%RENDERLIST\{(.*?)\}%\s*(([\n\r]+[^ ]{3}[^\n\r]*)*?)(([\n\r]+ {3}[^\n\r]*)+)/&handleRenderList($1, $2, $4)/ges | ||||
68 | ) | ||||
69 | { | ||||
70 | |||||
71 | # Cairo compatibility fallback | ||||
72 | $_[0] =~ | ||||
73 | s/%RENDERLIST\{(.*?)\}%\s*(([\n\r]+[^\t]{1}[^\n\r]*)*?)(([\n\r]+\t[^\n\r]*)+)/&handleRenderList($1, $2, $4)/ges; | ||||
74 | } | ||||
75 | } | ||||
76 | } | ||||
77 | |||||
78 | # ========================= | ||||
79 | sub handleRenderList { | ||||
80 | my ( $theAttr, $thePre, $theList ) = @_; | ||||
81 | |||||
82 | $theAttr =~ s/ {3}/\t/gs; | ||||
83 | $thePre =~ s/ {3}/\t/gs; | ||||
84 | $theList =~ s/ {3}/\t/gs; | ||||
85 | |||||
86 | my $focus = &Foswiki::Func::extractNameValuePair( $theAttr, "focus" ); | ||||
87 | my $depth = &Foswiki::Func::extractNameValuePair( $theAttr, "depth" ); | ||||
88 | my $theme = &Foswiki::Func::extractNameValuePair( $theAttr, "theme" ) | ||||
89 | || &Foswiki::Func::extractNameValuePair($theAttr); | ||||
90 | $theme = uc( $theme || '' ); | ||||
91 | if ( defined $defaultThemes{$theme} ) { | ||||
92 | $theme = $defaultThemes{$theme}; | ||||
93 | } | ||||
94 | else { | ||||
95 | $theme = "RENDERLISTPLUGIN_${theme}_THEME"; | ||||
96 | $theme = &Foswiki::Func::getPreferencesValue($theme) | ||||
97 | || "unrecognized theme type"; | ||||
98 | } | ||||
99 | my ( $type, $params ) = split( /, */, $theme, 2 ); | ||||
100 | $type = lc($type); | ||||
101 | |||||
102 | if ( $type eq "tree" || $type eq "icon" ) { | ||||
103 | return $thePre | ||||
104 | . renderIconList( $type, $params, $focus, $depth, $theList ); | ||||
105 | } | ||||
106 | else { | ||||
107 | return "$thePre$theList"; | ||||
108 | } | ||||
109 | } | ||||
110 | |||||
111 | # ========================= | ||||
112 | sub renderIconList { | ||||
113 | my ( $theType, $theParams, $theFocus, $theDepth, $theText ) = @_; | ||||
114 | |||||
115 | $theText =~ s/^[\n\r]*//s; | ||||
116 | my @tree = (); | ||||
117 | my $level = 0; | ||||
118 | my $type = ""; | ||||
119 | my $text = ""; | ||||
120 | my $focusIndex = -1; | ||||
121 | foreach ( split( /[\n\r]+/, $theText ) ) { | ||||
122 | m/^(\t+)(.) *(.*)/; | ||||
123 | $level = length($1); | ||||
124 | $type = $2; | ||||
125 | $text = $3; | ||||
126 | if ( ($theFocus) && ( $focusIndex < 0 ) && ( $text =~ m/$theFocus/ ) ) { | ||||
127 | $focusIndex = scalar(@tree); | ||||
128 | } | ||||
129 | push( @tree, { level => $level, type => $type, text => $text } ); | ||||
130 | } | ||||
131 | |||||
132 | # reduce tree to relatives around focus | ||||
133 | if ( $focusIndex >= 0 ) { | ||||
134 | |||||
135 | # splice tree into before, current node and after parts | ||||
136 | my @after = splice( @tree, $focusIndex + 1 ); | ||||
137 | my $nref = pop(@tree); | ||||
138 | |||||
139 | # highlight node with focus and remove links | ||||
140 | $text = $nref->{'text'}; | ||||
141 | $text =~ | ||||
142 | s/^([^\-]*)\[\[.*?\]\[(.*?)\]\]/$1$2/; # remove [[...][...]] link | ||||
143 | $text =~ s/^([^\-]*)\[\[(.*?)\]\]/$1$2/; # remove [[...]] link | ||||
144 | $text = "<b> $text </b>"; # bold focus text | ||||
145 | $nref->{'text'} = $text; | ||||
146 | |||||
147 | # remove uncles and siblings below current node | ||||
148 | $level = $nref->{'level'}; | ||||
149 | for ( my $i = 0 ; $i < scalar(@after) ; $i++ ) { | ||||
150 | if ( | ||||
151 | ( $after[$i]->{'level'} < $level ) | ||||
152 | || ( $after[$i]->{'level'} <= $level | ||||
153 | && $after[$i]->{'type'} ne " " ) | ||||
154 | ) | ||||
155 | { | ||||
156 | splice( @after, $i ); | ||||
157 | last; | ||||
158 | } | ||||
159 | } | ||||
160 | |||||
161 | # remove uncles and siblings above current node | ||||
162 | my @before = (); | ||||
163 | for ( my $i = scalar(@tree) - 1 ; $i >= 0 ; $i-- ) { | ||||
164 | if ( $tree[$i]->{'level'} < $level ) { | ||||
165 | push( @before, $tree[$i] ); | ||||
166 | $level = $tree[$i]->{'level'}; | ||||
167 | } | ||||
168 | } | ||||
169 | @tree = reverse(@before); | ||||
170 | $focusIndex = scalar(@tree); | ||||
171 | push( @tree, $nref ); | ||||
172 | push( @tree, @after ); | ||||
173 | } | ||||
174 | |||||
175 | # limit depth of tree | ||||
176 | my $depth = $theDepth; | ||||
177 | unless ( $depth =~ s/.*?([0-9]+).*/$1/ ) { | ||||
178 | $depth = 0; | ||||
179 | } | ||||
180 | if ($theFocus) { | ||||
181 | if ( $theDepth eq "" ) { | ||||
182 | $depth = $focusIndex + 3; | ||||
183 | } | ||||
184 | else { | ||||
185 | $depth += $focusIndex + 1; | ||||
186 | } | ||||
187 | } | ||||
188 | if ( $depth > 0 ) { | ||||
189 | my @tmp = (); | ||||
190 | foreach my $ref (@tree) { | ||||
191 | push( @tmp, $ref ) if ( $ref->{'level'} <= $depth ); | ||||
192 | } | ||||
193 | @tree = @tmp; | ||||
194 | } | ||||
195 | |||||
196 | $theParams =~ s/%PUBURL%/$pubUrl/g; | ||||
197 | $theParams =~ s/%ATTACHURL%/$attachUrl/g; | ||||
198 | $theParams =~ s/%WEB%/$installWeb/g; | ||||
199 | $theParams =~ s/%MAINWEB%/Foswiki::Func::getMainWebname()/ge; | ||||
200 | $theParams =~ s/%TWIKIWEB%/$Foswiki::cfg{SystemWebName}/ge; | ||||
201 | $theParams =~ s/%SYSTEMWEB%/$Foswiki::cfg{SystemWebName}/ge; | ||||
202 | my ( $showLead, $width, $height, $iconSp, $iconT, $iconI, $iconL, $iconImg ) | ||||
203 | = split( /, */, $theParams ); | ||||
204 | $width = 16 unless ($width); | ||||
205 | $height = 16 unless ($height); | ||||
206 | $iconSp = "empty.gif" unless ($iconSp); | ||||
207 | $iconSp = fixImageTag( $iconSp, $width, $height ); | ||||
208 | $iconT = "dot_udr.gif" unless ($iconT); | ||||
209 | $iconT = fixImageTag( $iconT, $width, $height ); | ||||
210 | $iconI = "dot_ud.gif" unless ($iconI); | ||||
211 | $iconI = fixImageTag( $iconI, $width, $height ); | ||||
212 | $iconL = "dot_ur.gif" unless ($iconL); | ||||
213 | $iconL = fixImageTag( $iconL, $width, $height ); | ||||
214 | $iconImg = "home.gif" unless ($iconImg); | ||||
215 | $iconImg = fixImageTag( $iconImg, $width, $height ); | ||||
216 | |||||
217 | $text = ""; | ||||
218 | my $start = 0; | ||||
219 | $start = 1 unless ($showLead); | ||||
220 | my @listIcon = (); | ||||
221 | for ( my $i = 0 ; $i < scalar(@tree) ; $i++ ) { | ||||
222 | $text .= | ||||
223 | '<table border="0" cellspacing="0" cellpadding="0"><tr>' . "\n"; | ||||
224 | $level = $tree[$i]->{'level'}; | ||||
225 | for ( my $l = $start ; $l < $level ; $l++ ) { | ||||
226 | if ( $l == $level - 1 ) { | ||||
227 | $listIcon[$l] = $iconSp; | ||||
228 | for ( my $x = $i + 1 ; $x < scalar(@tree) ; $x++ ) { | ||||
229 | last if ( $tree[$x]->{'level'} < $level ); | ||||
230 | if ( $tree[$x]->{'level'} <= $level | ||||
231 | && $tree[$x]->{'type'} ne " " ) | ||||
232 | { | ||||
233 | $listIcon[$l] = $iconI; | ||||
234 | last; | ||||
235 | } | ||||
236 | } | ||||
237 | if ( $tree[$i]->{'type'} eq " " ) { | ||||
238 | $text .= "<td valign=\"top\">$listIcon[$l]</td>\n"; | ||||
239 | } | ||||
240 | elsif ( $listIcon[$l] eq $iconSp ) { | ||||
241 | $text .= "<td valign=\"top\">$iconL</td>\n"; | ||||
242 | } | ||||
243 | else { | ||||
244 | $text .= "<td valign=\"top\">$iconT</td>\n"; | ||||
245 | } | ||||
246 | } | ||||
247 | else { | ||||
248 | $text .= | ||||
249 | "<td valign=\"top\">" . ( $listIcon[$l] || '' ) . "</td>\n"; | ||||
250 | } | ||||
251 | } | ||||
252 | if ( $theType eq "icon" ) { | ||||
253 | |||||
254 | # icon theme type | ||||
255 | if ( $tree[$i]->{'type'} eq " " ) { | ||||
256 | |||||
257 | # continuation line | ||||
258 | $text .= "<td valign=\"top\">$iconSp</td>\n"; | ||||
259 | } | ||||
260 | elsif ( $tree[$i]->{'text'} =~ | ||||
261 | m/^\s*(<b>)?\s*((icon\:)?<img[^>]+>|icon\:[^\s]+)\s*(.*)/ ) | ||||
262 | { | ||||
263 | |||||
264 | # specific icon | ||||
265 | $tree[$i]->{'text'} = $4; | ||||
266 | $tree[$i]->{'text'} = "$1 $4" if ($1); | ||||
267 | my $icon = $2; | ||||
268 | $icon =~ s/^icon\://; | ||||
269 | $icon = fixImageTag( $icon, $width, $height ); | ||||
270 | $text .= "<td valign=\"top\">$icon</td>\n"; | ||||
271 | } | ||||
272 | else { | ||||
273 | |||||
274 | # default icon | ||||
275 | $text .= "<td valign=\"top\">$iconImg</td>\n"; | ||||
276 | } | ||||
277 | $text .= | ||||
278 | "<td valign=\"top\" class=\"foswikiNoBreak\" > $tree[$i]->{'text'} </td>\n"; | ||||
279 | |||||
280 | } | ||||
281 | else { | ||||
282 | |||||
283 | # tree theme type | ||||
284 | if ( $tree[$i]->{'text'} =~ | ||||
285 | m/^\s*(<b>)?\s*((icon\:)?<img[^>]+>|icon\:[^\s]+)\s*(.*)/ ) | ||||
286 | { | ||||
287 | |||||
288 | # specific icon | ||||
289 | $tree[$i]->{'text'} = $4; | ||||
290 | $tree[$i]->{'text'} = "$1 $4" if ($1); | ||||
291 | my $icon = $2; | ||||
292 | $icon =~ s/^icon\://; | ||||
293 | $icon = fixImageTag( $icon, $width, $height ); | ||||
294 | $text .= "<td valign=\"top\">$icon</td>\n"; | ||||
295 | $text .= | ||||
296 | "<td valign=\"top\" class=\"foswikiNoBreak\" > $tree[$i]->{'text'} </td>\n"; | ||||
297 | } | ||||
298 | else { | ||||
299 | $text .= | ||||
300 | "<td valign=\"top\" class=\"foswikiNoBreak\" > $tree[$i]->{'text'} </td>\n"; | ||||
301 | } | ||||
302 | } | ||||
303 | $text .= '</tr></table>' . "\n"; | ||||
304 | } | ||||
305 | return $text; | ||||
306 | } | ||||
307 | |||||
308 | # ========================= | ||||
309 | sub fixImageTag { | ||||
310 | my ( $theIcon, $theWidth, $theHeight ) = @_; | ||||
311 | |||||
312 | if ( $theIcon !~ /^<img/i ) { | ||||
313 | $theIcon .= '.gif' if ( $theIcon !~ /\.(png|gif|jpeg|jpg)$/i ); | ||||
314 | $theIcon = "$attachUrl/$theIcon" if ( $theIcon !~ /^(\/|https?\:)/ ); | ||||
315 | $theIcon = | ||||
316 | "<img src=\"$theIcon\" width=\"$theWidth\" height=\"$theHeight\"" | ||||
317 | . " alt=\"\" border=\"0\" />"; | ||||
318 | } | ||||
319 | return $theIcon; | ||||
320 | } | ||||
321 | |||||
322 | # ========================= | ||||
323 | |||||
324 | 1 | 6µs | 1; | ||
325 | __END__ |