← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Plugins/RenderListPlugin.pm
StatementsExecuted 25 statements in 1.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
51151µs51µsFoswiki::Plugins::RenderListPlugin::::preRenderingHandlerFoswiki::Plugins::RenderListPlugin::preRenderingHandler
11131µs49µsFoswiki::Plugins::RenderListPlugin::::initPluginFoswiki::Plugins::RenderListPlugin::initPlugin
11113µs27µsFoswiki::Plugins::RenderListPlugin::::BEGIN@24Foswiki::Plugins::RenderListPlugin::BEGIN@24
11110µs16µsFoswiki::Plugins::RenderListPlugin::::BEGIN@25Foswiki::Plugins::RenderListPlugin::BEGIN@25
11110µs29µsFoswiki::Plugins::RenderListPlugin::::BEGIN@33Foswiki::Plugins::RenderListPlugin::BEGIN@33
1119µs55µsFoswiki::Plugins::RenderListPlugin::::BEGIN@28Foswiki::Plugins::RenderListPlugin::BEGIN@28
0000s0sFoswiki::Plugins::RenderListPlugin::::fixImageTagFoswiki::Plugins::RenderListPlugin::fixImageTag
0000s0sFoswiki::Plugins::RenderListPlugin::::handleRenderListFoswiki::Plugins::RenderListPlugin::handleRenderList
0000s0sFoswiki::Plugins::RenderListPlugin::::renderIconListFoswiki::Plugins::RenderListPlugin::renderIconList
Call graph for these subroutines as a Graphviz dot language file.
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# Copyright (C) 2001-2007 Peter Thoeny, peter@thoeny.org
5# Copyright (C) 2008 Foswiki Contributors
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version. For
11# more details read LICENSE in the root of this distribution.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16#
17# As per the GPL, removal of this notice is prohibited.
18# =========================
19
20# =========================
21package Foswiki::Plugins::RenderListPlugin
22 ; # change the package name and $pluginName!!!
23
24232µs240µs
# spent 27µs (13+13) within Foswiki::Plugins::RenderListPlugin::BEGIN@24 which was called: # once (13µs+13µs) by Foswiki::Plugin::BEGIN@2.26 at line 24
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@24 # spent 13µs making 1 call to strict::import
25236µs221µs
# spent 16µs (10+6) within Foswiki::Plugins::RenderListPlugin::BEGIN@25 which was called: # once (10µs+6µs) by Foswiki::Plugin::BEGIN@2.26 at line 25
use warnings;
# spent 16µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@25 # spent 6µs making 1 call to warnings::import
26
27# =========================
2816µs146µs
# spent 55µs (9+46) within Foswiki::Plugins::RenderListPlugin::BEGIN@28 which was called: # once (9µs+46µs) by Foswiki::Plugin::BEGIN@2.26 at line 31
use vars qw(
# spent 46µs making 1 call to vars::import
29 $web $topic $user $installWeb
30 $pubUrl $attachUrl
31123µs155µs);
# spent 55µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@28
32
3331.63ms353µs
# spent 29µs (10+19) within Foswiki::Plugins::RenderListPlugin::BEGIN@33 which was called: # once (10µs+19µs) by Foswiki::Plugin::BEGIN@2.26 at line 33
use version; our $VERSION = version->declare("v2.2.7");
# spent 29µs making 1 call to Foswiki::Plugins::RenderListPlugin::BEGIN@33 # spent 19µs making 1 call to version::import # spent 5µs making 1 call to version::vxs::declare
341300nsour $RELEASE = '2.2.7';
351200nsour $pluginName = 'RenderListPlugin'; # Name of this Plugin
361200nsour $NO_PREFS_IN_TOPIC = 1;
371200nsour $SHORTDESCRIPTION = 'Render bullet lists in a variety of formats';
38
3914µsour %defaultThemes = (
40 THREAD => 'tree, 1',
41 HOME =>
42'icon, 1, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/home.gif',
43 ORG =>
44'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/home.gif',
45 GROUP =>
46'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/group.gif',
47 EMAIL =>
48'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/email.gif',
49 TREND =>
50'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/trend.gif',
51 FILE =>
52'icon, 0, 16, 16, %ATTACHURL%/empty.gif, %ATTACHURL%/dot_udr.gif, %ATTACHURL%/dot_ud.gif, %ATTACHURL%/dot_ur.gif, %ATTACHURL%/file.gif',
53);
54
55# =========================
56
# spent 49µs (31+18) within Foswiki::Plugins::RenderListPlugin::initPlugin which was called: # once (31µs+18µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
sub initPlugin {
5715µs ( $topic, $web, $user, $installWeb ) = @_;
58
59 # check for Plugins.pm versions
60113µs16µs if ( $Foswiki::Plugins::VERSION < 1 ) {
# spent 6µs making 1 call to version::vxs::VCMP
61 Foswiki::Func::writeWarning(
62 "Version mismatch between $pluginName and Plugins.pm");
63 return 0;
64 }
65
66 # one time initialization
6716µs212µs $pubUrl = Foswiki::Func::getUrlHost() . Foswiki::Func::getPubUrlPath();
# spent 10µs making 1 call to Foswiki::Func::getUrlHost # spent 2µs making 1 call to Foswiki::Func::getPubUrlPath
6812µs $attachUrl = "$pubUrl/$installWeb/$pluginName";
69
70 # Plugin correctly initialized
7116µs return 1;
72}
73
74# =========================
75
# spent 51µs within Foswiki::Plugins::RenderListPlugin::preRenderingHandler which was called 5 times, avg 10µs/call: # 5 times (51µs+0s) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 10µs/call
sub preRenderingHandler {
76### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead
77
78 # This handler is called by getRenderedVersion just before the line loop
79
80 # Render here, not in commonTagsHandler so that lists produced by
81 # Plugins, TOC and SEARCH can be rendered
82539µs if ( $_[0] =~ /%RENDERLIST/o ) {
83 unless ( $_[0] =~
84s/%RENDERLIST{(.*?)}%\s*(([\n\r]+[^ ]{3}[^\n\r]*)*?)(([\n\r]+ {3}[^\n\r]*)+)/&handleRenderList($1, $2, $4)/ges
85 )
86 {
87
88 # Cairo compatibility fallback
89 $_[0] =~
90s/%RENDERLIST{(.*?)}%\s*(([\n\r]+[^\t]{1}[^\n\r]*)*?)(([\n\r]+\t[^\n\r]*)+)/&handleRenderList($1, $2, $4)/ges;
91 }
92 }
93}
94
95# =========================
96sub handleRenderList {
97 my ( $theAttr, $thePre, $theList ) = @_;
98
99 $theAttr =~ s/ {3}/\t/gs;
100 $thePre =~ s/ {3}/\t/gs;
101 $theList =~ s/ {3}/\t/gs;
102
103 my $focus = &Foswiki::Func::extractNameValuePair( $theAttr, "focus" );
104 my $depth = &Foswiki::Func::extractNameValuePair( $theAttr, "depth" );
105 my $theme = &Foswiki::Func::extractNameValuePair( $theAttr, "theme" )
106 || &Foswiki::Func::extractNameValuePair($theAttr);
107 $theme = uc( $theme || '' );
108 if ( defined $defaultThemes{$theme} ) {
109 $theme = $defaultThemes{$theme};
110 }
111 else {
112 $theme = "RENDERLISTPLUGIN_${theme}_THEME";
113 $theme = &Foswiki::Func::getPreferencesValue($theme)
114 || "unrecognized theme type";
115 }
116 my ( $type, $params ) = split( /, */, $theme, 2 );
117 $type = lc($type);
118
119 if ( $type eq "tree" || $type eq "icon" ) {
120 return $thePre
121 . renderIconList( $type, $params, $focus, $depth, $theList );
122 }
123 else {
124 return "$thePre$theList";
125 }
126}
127
128# =========================
129sub renderIconList {
130 my ( $theType, $theParams, $theFocus, $theDepth, $theText ) = @_;
131
132 $theText =~ s/^[\n\r]*//os;
133 my @tree = ();
134 my $level = 0;
135 my $type = "";
136 my $text = "";
137 my $focusIndex = -1;
138 foreach ( split( /[\n\r]+/, $theText ) ) {
139 m/^(\t+)(.) *(.*)/;
140 $level = length($1);
141 $type = $2;
142 $text = $3;
143 if ( ($theFocus) && ( $focusIndex < 0 ) && ( $text =~ /$theFocus/ ) ) {
144 $focusIndex = scalar(@tree);
145 }
146 push( @tree, { level => $level, type => $type, text => $text } );
147 }
148
149 # reduce tree to relatives around focus
150 if ( $focusIndex >= 0 ) {
151
152 # splice tree into before, current node and after parts
153 my @after = splice( @tree, $focusIndex + 1 );
154 my $nref = pop(@tree);
155
156 # highlight node with focus and remove links
157 $text = $nref->{'text'};
158 $text =~
159 s/^([^\-]*)\[\[.*?\]\[(.*?)\]\]/$1$2/o; # remove [[...][...]] link
160 $text =~ s/^([^\-]*)\[\[(.*?)\]\]/$1$2/o; # remove [[...]] link
161 $text = "<b> $text </b>"; # bold focus text
162 $nref->{'text'} = $text;
163
164 # remove uncles and siblings below current node
165 $level = $nref->{'level'};
166 for ( my $i = 0 ; $i < scalar(@after) ; $i++ ) {
167 if (
168 ( $after[$i]->{'level'} < $level )
169 || ( $after[$i]->{'level'} <= $level
170 && $after[$i]->{'type'} ne " " )
171 )
172 {
173 splice( @after, $i );
174 last;
175 }
176 }
177
178 # remove uncles and siblings above current node
179 my @before = ();
180 for ( my $i = scalar(@tree) - 1 ; $i >= 0 ; $i-- ) {
181 if ( $tree[$i]->{'level'} < $level ) {
182 push( @before, $tree[$i] );
183 $level = $tree[$i]->{'level'};
184 }
185 }
186 @tree = reverse(@before);
187 $focusIndex = scalar(@tree);
188 push( @tree, $nref );
189 push( @tree, @after );
190 }
191
192 # limit depth of tree
193 my $depth = $theDepth;
194 unless ( $depth =~ s/.*?([0-9]+).*/$1/o ) {
195 $depth = 0;
196 }
197 if ($theFocus) {
198 if ( $theDepth eq "" ) {
199 $depth = $focusIndex + 3;
200 }
201 else {
202 $depth += $focusIndex + 1;
203 }
204 }
205 if ( $depth > 0 ) {
206 my @tmp = ();
207 foreach my $ref (@tree) {
208 push( @tmp, $ref ) if ( $ref->{'level'} <= $depth );
209 }
210 @tree = @tmp;
211 }
212
213 $theParams =~ s/%PUBURL%/$pubUrl/go;
214 $theParams =~ s/%ATTACHURL%/$attachUrl/go;
215 $theParams =~ s/%WEB%/$installWeb/go;
216 $theParams =~ s/%MAINWEB%/Foswiki::Func::getMainWebname()/geo;
217 $theParams =~ s/%TWIKIWEB%/$Foswiki::cfg{SystemWebName}/geo;
218 $theParams =~ s/%SYSTEMWEB%/$Foswiki::cfg{SystemWebName}/geo;
219 my ( $showLead, $width, $height, $iconSp, $iconT, $iconI, $iconL, $iconImg )
220 = split( /, */, $theParams );
221 $width = 16 unless ($width);
222 $height = 16 unless ($height);
223 $iconSp = "empty.gif" unless ($iconSp);
224 $iconSp = fixImageTag( $iconSp, $width, $height );
225 $iconT = "dot_udr.gif" unless ($iconT);
226 $iconT = fixImageTag( $iconT, $width, $height );
227 $iconI = "dot_ud.gif" unless ($iconI);
228 $iconI = fixImageTag( $iconI, $width, $height );
229 $iconL = "dot_ur.gif" unless ($iconL);
230 $iconL = fixImageTag( $iconL, $width, $height );
231 $iconImg = "home.gif" unless ($iconImg);
232 $iconImg = fixImageTag( $iconImg, $width, $height );
233
234 $text = "";
235 my $start = 0;
236 $start = 1 unless ($showLead);
237 my @listIcon = ();
238 for ( my $i = 0 ; $i < scalar(@tree) ; $i++ ) {
239 $text .=
240 '<table border="0" cellspacing="0" cellpadding="0"><tr>' . "\n";
241 $level = $tree[$i]->{'level'};
242 for ( my $l = $start ; $l < $level ; $l++ ) {
243 if ( $l == $level - 1 ) {
244 $listIcon[$l] = $iconSp;
245 for ( my $x = $i + 1 ; $x < scalar(@tree) ; $x++ ) {
246 last if ( $tree[$x]->{'level'} < $level );
247 if ( $tree[$x]->{'level'} <= $level
248 && $tree[$x]->{'type'} ne " " )
249 {
250 $listIcon[$l] = $iconI;
251 last;
252 }
253 }
254 if ( $tree[$i]->{'type'} eq " " ) {
255 $text .= "<td valign=\"top\">$listIcon[$l]</td>\n";
256 }
257 elsif ( $listIcon[$l] eq $iconSp ) {
258 $text .= "<td valign=\"top\">$iconL</td>\n";
259 }
260 else {
261 $text .= "<td valign=\"top\">$iconT</td>\n";
262 }
263 }
264 else {
265 $text .=
266 "<td valign=\"top\">" . ( $listIcon[$l] || '' ) . "</td>\n";
267 }
268 }
269 if ( $theType eq "icon" ) {
270
271 # icon theme type
272 if ( $tree[$i]->{'type'} eq " " ) {
273
274 # continuation line
275 $text .= "<td valign=\"top\">$iconSp</td>\n";
276 }
277 elsif ( $tree[$i]->{'text'} =~
278 /^\s*(<b>)?\s*((icon\:)?<img[^>]+>|icon\:[^\s]+)\s*(.*)/ )
279 {
280
281 # specific icon
282 $tree[$i]->{'text'} = $4;
283 $tree[$i]->{'text'} = "$1 $4" if ($1);
284 my $icon = $2;
285 $icon =~ s/^icon\://o;
286 $icon = fixImageTag( $icon, $width, $height );
287 $text .= "<td valign=\"top\">$icon</td>\n";
288 }
289 else {
290
291 # default icon
292 $text .= "<td valign=\"top\">$iconImg</td>\n";
293 }
294 $text .=
295"<td valign=\"top\" class=\"foswikiNoBreak\" >&nbsp; $tree[$i]->{'text'} </td>\n";
296
297 }
298 else {
299
300 # tree theme type
301 if ( $tree[$i]->{'text'} =~
302 /^\s*(<b>)?\s*((icon\:)?<img[^>]+>|icon\:[^\s]+)\s*(.*)/ )
303 {
304
305 # specific icon
306 $tree[$i]->{'text'} = $4;
307 $tree[$i]->{'text'} = "$1 $4" if ($1);
308 my $icon = $2;
309 $icon =~ s/^icon\://o;
310 $icon = fixImageTag( $icon, $width, $height );
311 $text .= "<td valign=\"top\">$icon</td>\n";
312 $text .=
313"<td valign=\"top\" class=\"foswikiNoBreak\" >&nbsp; $tree[$i]->{'text'} </td>\n";
314 }
315 else {
316 $text .=
317"<td valign=\"top\" class=\"foswikiNoBreak\" > $tree[$i]->{'text'} </td>\n";
318 }
319 }
320 $text .= '</tr></table>' . "\n";
321 }
322 return $text;
323}
324
325# =========================
326sub fixImageTag {
327 my ( $theIcon, $theWidth, $theHeight ) = @_;
328
329 if ( $theIcon !~ /^<img/i ) {
330 $theIcon .= '.gif' if ( $theIcon !~ /\.(png|gif|jpeg|jpg)$/i );
331 $theIcon = "$attachUrl/$theIcon" if ( $theIcon !~ /^(\/|https?\:)/ );
332 $theIcon =
333 "<img src=\"$theIcon\" width=\"$theWidth\" height=\"$theHeight\""
334 . " alt=\"\" border=\"0\" />";
335 }
336 return $theIcon;
337}
338
339# =========================
340
34116µs1;
342__END__