Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin/Plugins.pm |
Statements | Executed 822 statements in 3.03ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
14 | 1 | 1 | 589µs | 4.37ms | load | Foswiki::Plugins::JQueryPlugin::Plugins::
64 | 2 | 2 | 450µs | 504µs | registerPlugin | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 296µs | 2.63ms | init | Foswiki::Plugins::JQueryPlugin::Plugins::
9 | 1 | 1 | 204µs | 425µs | getIconUrlPath | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 157µs | 157µs | finish | Foswiki::Plugins::JQueryPlugin::Plugins::
14 | 4 | 3 | 141µs | 5.68ms | createPlugin (recurses: max depth 2, inclusive time 2.85ms) | Foswiki::Plugins::JQueryPlugin::Plugins::
6 | 1 | 1 | 23µs | 23µs | registerTheme | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 15µs | 27µs | BEGIN@4 | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 12µs | 37µs | createTheme | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 9µs | 13µs | BEGIN@5 | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 4µs | 4µs | BEGIN@6 | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | expandVariables | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | getPlugins | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | getRandom | Foswiki::Plugins::JQueryPlugin::Plugins::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Plugins::JQueryPlugin::Plugins; | ||||
3 | |||||
4 | 2 | 26µs | 2 | 39µs | # spent 27µs (15+12) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 which was called:
# once (15µs+12µs) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 4 # spent 27µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4
# spent 12µs making 1 call to strict::import |
5 | 2 | 23µs | 2 | 17µs | # spent 13µs (9+4) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 which was called:
# once (9µs+4µs) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 5 # spent 13µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 1.25ms | 1 | 4µs | # spent 4µs within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 which was called:
# once (4µs+0s) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 6 # spent 4µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 |
7 | |||||
8 | 1 | 300ns | my @iconSearchPath; | ||
9 | 1 | 200ns | my %iconCache; | ||
10 | 1 | 100ns | my %plugins; | ||
11 | 1 | 100ns | my %themes; | ||
12 | 1 | 100ns | my $debug; | ||
13 | 1 | 0s | my $currentTheme; | ||
14 | |||||
15 | =begin TML | ||||
16 | |||||
17 | ---+ package Foswiki::Plugins::JQueryPlugin | ||||
18 | |||||
19 | Container for jQuery and plugins | ||||
20 | |||||
21 | =cut | ||||
22 | |||||
23 | =begin TML | ||||
24 | |||||
25 | ---++ init() | ||||
26 | |||||
27 | initialize plugin container | ||||
28 | |||||
29 | =cut | ||||
30 | |||||
31 | # spent 2.63ms (296µs+2.33) within Foswiki::Plugins::JQueryPlugin::Plugins::init which was called:
# once (296µs+2.33ms) by Foswiki::Plugins::JQueryPlugin::initPlugin at line 68 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm | ||||
32 | |||||
33 | 1 | 2µs | $debug = $Foswiki::cfg{JQueryPlugin}{Debug} || 0; | ||
34 | |||||
35 | # get all plugins | ||||
36 | 1 | 33µs | foreach | ||
37 | my $pluginName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Plugins} } ) | ||||
38 | { | ||||
39 | 68 | 122µs | 58 | 445µs | registerPlugin($pluginName) # spent 445µs making 58 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin, avg 8µs/call |
40 | if $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Enabled}; | ||||
41 | } | ||||
42 | |||||
43 | # get all themes | ||||
44 | 1 | 6µs | foreach my $themeName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Themes} } ) | ||
45 | { | ||||
46 | 6 | 13µs | 6 | 23µs | registerTheme($themeName) # spent 23µs making 6 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme, avg 4µs/call |
47 | if $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Enabled}; | ||||
48 | } | ||||
49 | 1 | 800ns | $currentTheme = $Foswiki::cfg{JQueryPlugin}{JQueryTheme}; | ||
50 | |||||
51 | # load jquery | ||||
52 | 1 | 600ns | my $jQuery = $Foswiki::cfg{JQueryPlugin}{JQueryVersion} | ||
53 | || "jquery-2.1.0"; | ||||
54 | |||||
55 | # test for the jquery library to be present | ||||
56 | 1 | 18µs | unless ( -e $Foswiki::cfg{PubDir} . '/' | ||
57 | . $Foswiki::cfg{SystemWebName} | ||||
58 | . '/JQueryPlugin/' | ||||
59 | . $jQuery | ||||
60 | . '.js' ) | ||||
61 | { | ||||
62 | Foswiki::Func::writeWarning( | ||||
63 | "CAUTION: jQuery $jQuery not found. please fix the {JQueryPlugin}{JQueryVersion} settings." | ||||
64 | ); | ||||
65 | $jQuery = "jquery-2.1.3"; | ||||
66 | } | ||||
67 | |||||
68 | 1 | 300ns | $jQuery .= ".uncompressed" if $debug; | ||
69 | |||||
70 | 1 | 1µs | my $jQueryIE = $Foswiki::cfg{JQueryPlugin}{JQueryVersionForOldIEs}; | ||
71 | 1 | 300ns | $jQueryIE = "jquery-1.11.2" unless defined $jQueryIE; | ||
72 | |||||
73 | 1 | 400ns | my $code; | ||
74 | 1 | 700ns | if ($jQueryIE) { | ||
75 | |||||
76 | # test for the jquery library to be present | ||||
77 | 1 | 6µs | unless ( -e $Foswiki::cfg{PubDir} . '/' | ||
78 | . $Foswiki::cfg{SystemWebName} | ||||
79 | . '/JQueryPlugin/' | ||||
80 | . $jQueryIE | ||||
81 | . '.js' ) | ||||
82 | { | ||||
83 | Foswiki::Func::writeWarning( | ||||
84 | "CAUTION: jQuery $jQueryIE not found. please fix the {JQueryPlugin}{JQueryVersionForOldIEs} settings." | ||||
85 | ); | ||||
86 | $jQuery = "jquery-1.11.2"; | ||||
87 | } | ||||
88 | |||||
89 | 1 | 300ns | $jQueryIE .= ".uncompressed" if $debug; | ||
90 | |||||
91 | 1 | 2µs | $code = <<"HERE"; | ||
92 | <literal><!--[if lte IE 9]> | ||||
93 | <script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQueryIE.js'></script> | ||||
94 | <![endif]--> | ||||
95 | <!--[if gt IE 9]><!--> | ||||
96 | <script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script> | ||||
97 | <!--<![endif]--> | ||||
98 | </literal> | ||||
99 | HERE | ||||
100 | } | ||||
101 | else { | ||||
102 | $code = <<"HERE"; | ||||
103 | <script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script> | ||||
104 | HERE | ||||
105 | } | ||||
106 | |||||
107 | # switch on noconflict mode | ||||
108 | 1 | 1µs | if ( $Foswiki::cfg{JQueryPlugin}{NoConflict} ) { | ||
109 | my $noConflict = 'noconflict'; | ||||
110 | $noConflict .= ".uncompressed" if $debug; | ||||
111 | |||||
112 | $code .= <<"HERE"; | ||||
113 | <script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$noConflict.js'></script> | ||||
114 | HERE | ||||
115 | } | ||||
116 | |||||
117 | 1 | 2µs | 1 | 33µs | Foswiki::Func::addToZone( 'script', 'JQUERYPLUGIN', $code ); # spent 33µs making 1 call to Foswiki::Func::addToZone |
118 | |||||
119 | # initial plugins | ||||
120 | 1 | 1µs | 1 | 1.41ms | createPlugin('Foswiki'); # this one is needed anyway # spent 1.41ms making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin |
121 | |||||
122 | 1 | 2µs | my $defaultPlugins = $Foswiki::cfg{JQueryPlugin}{DefaultPlugins}; | ||
123 | 1 | 300ns | if ($defaultPlugins) { | ||
124 | foreach my $pluginName ( split( /\s*,\s*/, $defaultPlugins ) ) { | ||||
125 | createPlugin($pluginName); | ||||
126 | } | ||||
127 | } | ||||
128 | |||||
129 | # enable migrate for jQuery > 1.9.x as long as we still have 3rd party plugins | ||||
130 | # making use of deprecated and removed features | ||||
131 | 1 | 4µs | unless ( $defaultPlugins && $defaultPlugins =~ /\bmigrate\b/i ) { | ||
132 | 1 | 3µs | if ( $jQuery =~ /^jquery-(\d+)\.(\d+)\.(\d+)/ ) { | ||
133 | 1 | 4µs | my $jqVersion = $1 * 10000 + $2 * 100 + $3; | ||
134 | 1 | 2µs | 1 | 421µs | if ( $jqVersion > 10900 ) { # spent 421µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin |
135 | createPlugin("Migrate"); | ||||
136 | } | ||||
137 | } | ||||
138 | } | ||||
139 | } | ||||
140 | |||||
141 | =begin TML | ||||
142 | |||||
143 | ---++ ObjectMethod createPlugin( $pluginName, ... ) -> $plugin | ||||
144 | |||||
145 | Helper method to establish plugin dependencies. See =load()=. | ||||
146 | |||||
147 | =cut | ||||
148 | |||||
149 | # spent 5.68ms (141µs+5.54) within Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin which was called 14 times, avg 406µs/call:
# 6 times (66µs+3.79ms) by Foswiki::Plugins::JQueryPlugin::createPlugin at line 109 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 642µs/call
# 6 times (51µs+-51µs) by Foswiki::Plugins::JQueryPlugin::Plugin::init at line 124 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm, avg 0s/call
# once (10µs+1.40ms) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 120
# once (14µs+407µs) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 134 | ||||
150 | 14 | 22µs | 14 | 4.37ms | my $plugin = load(@_); # spent 4.37ms making 14 calls to Foswiki::Plugins::JQueryPlugin::Plugins::load, avg 312µs/call |
151 | 14 | 64µs | 14 | 3.80ms | $plugin->init() if $plugin; # spent 2.23ms making 11 calls to Foswiki::Plugins::JQueryPlugin::Plugin::init, avg 202µs/call, recursion: max depth 2, sum of overlapping time 226µs
# spent 1.03ms making 1 call to Foswiki::Plugins::JQueryPlugin::UI::init
# spent 771µs making 2 calls to Foswiki::Plugins::JQueryPlugin::FOSWIKI::init, avg 385µs/call |
152 | 14 | 35µs | return $plugin; | ||
153 | } | ||||
154 | |||||
155 | =begin TML | ||||
156 | |||||
157 | ---++ ObjectMethd createTheme ($themeName, $url) -> $boolean | ||||
158 | |||||
159 | Helper method to switch on a theme. Returns true | ||||
160 | if =$themeName= has been loaded successfully. Note that a previously | ||||
161 | loaded theme will be replaced with the new one as there can only | ||||
162 | be one theme per html page. The $url parameter optionally specifies | ||||
163 | from where to load the theme. It defaults to the url registered | ||||
164 | in =configure= for the named theme. | ||||
165 | |||||
166 | =cut | ||||
167 | |||||
168 | # spent 37µs (12+25) within Foswiki::Plugins::JQueryPlugin::Plugins::createTheme which was called:
# once (12µs+25µs) by Foswiki::Plugins::JQueryPlugin::createTheme at line 122 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm | ||||
169 | 1 | 900ns | my ( $themeName, $url ) = @_; | ||
170 | |||||
171 | 1 | 800ns | $themeName ||= $currentTheme; | ||
172 | 1 | 200ns | return 0 unless $themeName; | ||
173 | |||||
174 | 1 | 700ns | my $normalizedName = lc($themeName); | ||
175 | |||||
176 | 1 | 600ns | unless ($url) { | ||
177 | 1 | 1µs | my $themeDesc = $themes{$normalizedName}; | ||
178 | 1 | 100ns | return 0 unless defined $themeDesc; | ||
179 | 1 | 1µs | $url = $themeDesc->{url}; | ||
180 | } | ||||
181 | |||||
182 | # remember last choice | ||||
183 | 1 | 200ns | $currentTheme = $themeName; | ||
184 | |||||
185 | 1 | 2µs | 1 | 25µs | Foswiki::Func::addToZone( "head", "JQUERYPLUGIN::THEME", # spent 25µs making 1 call to Foswiki::Func::addToZone |
186 | <<HERE, "JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::UI" ); | ||||
187 | <link rel="stylesheet" href="$url" type="text/css" media="all" /> | ||||
188 | HERE | ||||
189 | |||||
190 | 1 | 3µs | return 1; | ||
191 | } | ||||
192 | |||||
193 | =begin TML | ||||
194 | |||||
195 | ---++ ObjectMethod registerPlugin( $pluginName, $class ) -> $descriptor | ||||
196 | |||||
197 | Helper method to register a plugin. | ||||
198 | |||||
199 | =cut | ||||
200 | |||||
201 | # spent 504µs (450+55) within Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin which was called 64 times, avg 8µs/call:
# 58 times (398µs+47µs) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 39, avg 8µs/call
# 6 times (52µs+7µs) by Foswiki::Plugins::JQueryPlugin::registerPlugin at line 140 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 10µs/call | ||||
202 | 64 | 27µs | my ( $pluginName, $class ) = @_; | ||
203 | |||||
204 | 64 | 46µs | $class ||= $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Module} | ||
205 | || 'Foswiki::Plugins::JQueryPlugin::' . uc($pluginName); | ||||
206 | |||||
207 | 64 | 18µs | my $contextID = $pluginName . 'Registered'; | ||
208 | 64 | 33µs | $contextID =~ s/\W//g; | ||
209 | 64 | 93µs | 64 | 55µs | Foswiki::Func::getContext()->{$contextID} = 1; # spent 55µs making 64 calls to Foswiki::Func::getContext, avg 855ns/call |
210 | |||||
211 | 64 | 226µs | return $plugins{ lc($pluginName) } = { | ||
212 | 'class' => $class, | ||||
213 | 'name' => $pluginName, | ||||
214 | 'instance' => undef, | ||||
215 | }; | ||||
216 | } | ||||
217 | |||||
218 | =begin TML | ||||
219 | |||||
220 | ---++ ObjectMethod registerTheme( $themeName, $url ) -> $descriptor | ||||
221 | |||||
222 | Helper method to register a theme. | ||||
223 | |||||
224 | =cut | ||||
225 | |||||
226 | # spent 23µs within Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme which was called 6 times, avg 4µs/call:
# 6 times (23µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 46, avg 4µs/call | ||||
227 | 6 | 3µs | my ( $themeName, $url ) = @_; | ||
228 | |||||
229 | 6 | 2µs | my $normalizedName = lc($themeName); | ||
230 | |||||
231 | 6 | 5µs | $url ||= $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Url} | ||
232 | || '%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/themes/' | ||||
233 | . $normalizedName | ||||
234 | . '/jquery-ui.css'; | ||||
235 | |||||
236 | 6 | 20µs | return $themes{$normalizedName} = { | ||
237 | 'url' => $url, | ||||
238 | 'name' => $themeName, | ||||
239 | }; | ||||
240 | } | ||||
241 | |||||
242 | =begin TML | ||||
243 | |||||
244 | finalizer | ||||
245 | |||||
246 | =cut | ||||
247 | |||||
248 | # spent 157µs within Foswiki::Plugins::JQueryPlugin::Plugins::finish which was called:
# once (157µs+0s) by Foswiki::Plugins::JQueryPlugin::finishPlugin at line 96 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm | ||||
249 | |||||
250 | 1 | 145µs | undef %plugins; | ||
251 | 1 | 6µs | undef %themes; | ||
252 | 1 | 2µs | undef @iconSearchPath; | ||
253 | 1 | 2µs | undef %iconCache; | ||
254 | 1 | 7µs | undef $currentTheme; | ||
255 | } | ||||
256 | |||||
257 | =begin TML | ||||
258 | |||||
259 | ---++ ObjectMethod load ( $pluginName ) -> $plugin | ||||
260 | |||||
261 | Loads a plugin and runs its initializer. | ||||
262 | |||||
263 | parameters | ||||
264 | * =$pluginName=: name of plugin | ||||
265 | |||||
266 | returns | ||||
267 | * =$plugin=: returns the plugin object or false if instantiating | ||||
268 | the plugin failed | ||||
269 | |||||
270 | =cut | ||||
271 | |||||
272 | # spent 4.37ms (589µs+3.78) within Foswiki::Plugins::JQueryPlugin::Plugins::load which was called 14 times, avg 312µs/call:
# 14 times (589µs+3.78ms) by Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin at line 150, avg 312µs/call | ||||
273 | 14 | 6µs | my $pluginName = shift; | ||
274 | |||||
275 | 14 | 5µs | my $normalizedName = lc($pluginName); | ||
276 | 14 | 11µs | my $pluginDesc = $plugins{$normalizedName}; | ||
277 | |||||
278 | 14 | 3µs | return unless $pluginDesc; | ||
279 | |||||
280 | 14 | 9µs | unless ( defined $pluginDesc->{instance} ) { | ||
281 | |||||
282 | 11 | 412µs | eval "use $pluginDesc->{class};"; # spent 94µs executing statements in string eval # includes 238µs spent executing 1 call to 1 sub defined therein. # spent 89µs executing statements in string eval # includes 222µs spent executing 1 call to 1 sub defined therein. # spent 88µs executing statements in string eval # includes 478µs spent executing 1 call to 1 sub defined therein. # spent 88µs executing statements in string eval # includes 446µs spent executing 1 call to 1 sub defined therein. # spent 87µs executing statements in string eval # includes 209µs spent executing 1 call to 1 sub defined therein. # spent 85µs executing statements in string eval # includes 218µs spent executing 1 call to 1 sub defined therein. # spent 85µs executing statements in string eval # includes 214µs spent executing 1 call to 1 sub defined therein. # spent 84µs executing statements in string eval # includes 343µs spent executing 1 call to 1 sub defined therein. # spent 83µs executing statements in string eval # includes 206µs spent executing 1 call to 1 sub defined therein. # spent 78µs executing statements in string eval # includes 200µs spent executing 1 call to 1 sub defined therein. # spent 20µs executing statements in string eval # includes 15µs spent executing 1 call to 1 sub defined therein. | ||
283 | |||||
284 | 11 | 7µs | if ($@) { | ||
285 | Foswiki::Func::writeDebug( | ||||
286 | "ERROR: can't load jQuery plugin $pluginName: $@"); | ||||
287 | $pluginDesc->{instance} = 0; | ||||
288 | } | ||||
289 | else { | ||||
290 | 11 | 47µs | 11 | 508µs | $pluginDesc->{instance} = $pluginDesc->{class}->new(); # spent 63µs making 1 call to Foswiki::Plugins::SubscribePlugin::JQuery::new
# spent 55µs making 1 call to Foswiki::Contrib::JEditableContrib::JEDITABLE::new
# spent 55µs making 1 call to Foswiki::Plugins::CommentPlugin::JQuery::new
# spent 48µs making 1 call to Foswiki::Plugins::JQueryPlugin::RENDER::new
# spent 45µs making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::new
# spent 43µs making 1 call to Foswiki::Plugins::JQueryPlugin::COOKIE::new
# spent 42µs making 1 call to Foswiki::Plugins::JQueryPlugin::LIVEQUERY::new
# spent 41µs making 1 call to Foswiki::Plugins::JQueryPlugin::UI::new
# spent 40µs making 1 call to Foswiki::Plugins::JQueryPlugin::METADATA::new
# spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::MIGRATE::new
# spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::EASING::new |
291 | } | ||||
292 | } | ||||
293 | |||||
294 | 14 | 41µs | return $pluginDesc->{instance}; | ||
295 | } | ||||
296 | |||||
297 | =begin TML | ||||
298 | |||||
299 | ---++ ObjectMethod expandVariables( $format, %params) -> $string | ||||
300 | |||||
301 | Helper function to expand standard escape sequences =$percnt=, =$nop=, | ||||
302 | =$n= and =$dollar=. | ||||
303 | |||||
304 | * =$format=: format string to be expaneded | ||||
305 | * =%params=: optional hash array containing further key-value pairs to be | ||||
306 | expanded as well, that is all occurences of =$key= will | ||||
307 | be replaced by its =value= as defined in %params | ||||
308 | * =$string=: returns the resulting text | ||||
309 | |||||
310 | =cut | ||||
311 | |||||
312 | sub expandVariables { | ||||
313 | my ( $format, %params ) = @_; | ||||
314 | |||||
315 | return '' unless $format; | ||||
316 | |||||
317 | foreach my $key ( keys %params ) { | ||||
318 | my $val = $params{$key}; | ||||
319 | $val = '' unless defined $val; | ||||
320 | $format =~ s/\$$key\b/$val/g; | ||||
321 | } | ||||
322 | $format = Foswiki::Func::decodeFormatTokens($format); | ||||
323 | |||||
324 | return $format; | ||||
325 | } | ||||
326 | |||||
327 | =begin TML | ||||
328 | |||||
329 | ---++ ObjectMethod getIconUrlPath ( $iconName ) -> $pubUrlPath | ||||
330 | |||||
331 | Returns the path to the named icon searching along a given icon search path. | ||||
332 | This path can be in =$Foswiki::cfg{JQueryPlugin}{IconSearchPath}= or will fall | ||||
333 | back to =FamFamFamSilkIcons=, =FamFamFamSilkCompanion1Icons=, | ||||
334 | =FamFamFamFlagIcons=, =FamFamFamMiniIcons=, =FamFamFamMintIcons= As you see | ||||
335 | installing Foswiki:Extensions/FamFamFamContrib would be nice to have. | ||||
336 | |||||
337 | = =$iconName=: name of icon; you will have to know the icon name by heart as listed in your | ||||
338 | favorite icon set, meaning there's no mapping between something like "semantic" and "physical" icons | ||||
339 | = =$pubUrlPath=: the path to the icon as it is attached somewhere in your wiki or the empty | ||||
340 | string if the icon was not found | ||||
341 | |||||
342 | =cut | ||||
343 | |||||
344 | # spent 425µs (204+221) within Foswiki::Plugins::JQueryPlugin::Plugins::getIconUrlPath which was called 9 times, avg 47µs/call:
# 9 times (204µs+221µs) by Foswiki::Plugins::JQueryPlugin::handleJQueryIcon at line 379 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 47µs/call | ||||
345 | 9 | 4µs | my ($iconName) = @_; | ||
346 | |||||
347 | 9 | 1µs | return '' unless $iconName; | ||
348 | |||||
349 | 9 | 4µs | unless (@iconSearchPath) { | ||
350 | 1 | 2µs | my $iconSearchPath = $Foswiki::cfg{JQueryPlugin}{IconSearchPath} | ||
351 | || 'FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamSilkCompanion2Icons, FamFamFamSilkGeoSilkIcons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons'; | ||||
352 | 1 | 10µs | @iconSearchPath = split( /\s*,\s*/, $iconSearchPath ); | ||
353 | } | ||||
354 | |||||
355 | 9 | 8µs | $iconName =~ s/^.*\.(.*?)$/$1/; # strip file extension | ||
356 | |||||
357 | 9 | 5µs | my $iconPath = $iconCache{$iconName}; | ||
358 | |||||
359 | 9 | 3µs | unless ($iconPath) { | ||
360 | 8 | 5µs | foreach my $item (@iconSearchPath) { | ||
361 | 8 | 17µs | 8 | 74µs | my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( # spent 74µs making 8 calls to Foswiki::Func::normalizeWebTopicName, avg 9µs/call |
362 | $Foswiki::cfg{SystemWebName}, $item ); | ||||
363 | |||||
364 | # SMELL: store violation assumes the we have got file-level access | ||||
365 | # better use store api | ||||
366 | 8 | 17µs | my $iconDir = | ||
367 | $Foswiki::cfg{PubDir} . '/' | ||||
368 | . $web . '/' | ||||
369 | . $topic . '/' | ||||
370 | . $iconName . '.png'; | ||||
371 | 8 | 59µs | if ( -f $iconDir ) { | ||
372 | 8 | 23µs | 8 | 146µs | $iconPath = # spent 146µs making 8 calls to Foswiki::Func::getPubUrlPath, avg 18µs/call |
373 | Foswiki::Func::getPubUrlPath() . '/' | ||||
374 | . $web . '/' | ||||
375 | . $topic . '/' | ||||
376 | . $iconName . '.png'; | ||||
377 | 8 | 6µs | last; # first come first serve | ||
378 | } | ||||
379 | } | ||||
380 | |||||
381 | 8 | 1µs | $iconPath ||= ''; | ||
382 | 8 | 13µs | $iconCache{$iconName} = $iconPath; | ||
383 | } | ||||
384 | |||||
385 | 9 | 22µs | return $iconPath; | ||
386 | } | ||||
387 | |||||
388 | =begin TML | ||||
389 | |||||
390 | ---++ ClassMethod getPlugins () -> @plugins | ||||
391 | |||||
392 | returns a list of all known plugins | ||||
393 | |||||
394 | =cut | ||||
395 | |||||
396 | sub getPlugins { | ||||
397 | my ($include) = @_; | ||||
398 | |||||
399 | my @plugins = (); | ||||
400 | foreach my $key ( sort keys %plugins ) { | ||||
401 | next if $key eq 'empty'; | ||||
402 | next if $include && $key !~ /^($include)$/; | ||||
403 | my $pluginDesc = $plugins{$key}; | ||||
404 | my $plugin = load( $pluginDesc->{name} ); | ||||
405 | push @plugins, $plugin if $plugin; | ||||
406 | } | ||||
407 | |||||
408 | return @plugins; | ||||
409 | } | ||||
410 | |||||
411 | =begin TML | ||||
412 | |||||
413 | ---++ ClassMethod getRandom () -> $integer | ||||
414 | |||||
415 | returns a random positive integer between 1 and 10000. | ||||
416 | this can be used to | ||||
417 | generate html element IDs which are not | ||||
418 | allowed to clash within the same html page, | ||||
419 | even not when it got extended via ajax. | ||||
420 | |||||
421 | =cut | ||||
422 | |||||
423 | sub getRandom { | ||||
424 | return int( rand(10000) ) + 1; | ||||
425 | } | ||||
426 | |||||
427 | 1 | 3µs | 1; | ||
428 | __END__ |