Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/SmiliesPlugin.pm |
Statements | Executed 4275 statements in 8.81ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 4.59ms | 6.07ms | preRenderingHandler | Foswiki::Plugins::SmiliesPlugin::
1 | 1 | 1 | 1.77ms | 14.9ms | _loadSmilies | Foswiki::Plugins::SmiliesPlugin::
896 | 1 | 1 | 1.44ms | 1.44ms | _renderSmily | Foswiki::Plugins::SmiliesPlugin::
1 | 1 | 1 | 21µs | 15.0ms | initPlugin | Foswiki::Plugins::SmiliesPlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@7 | Foswiki::Plugins::SmiliesPlugin::
5 | 1 | 1 | 13µs | 36µs | _addToZone | Foswiki::Plugins::SmiliesPlugin::
1 | 1 | 1 | 9µs | 13µs | BEGIN@8 | Foswiki::Plugins::SmiliesPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@10 | Foswiki::Plugins::SmiliesPlugin::
0 | 0 | 0 | 0s | 0s | _formatSmily | Foswiki::Plugins::SmiliesPlugin::
0 | 0 | 0 | 0s | 0s | _renderSmilies | Foswiki::Plugins::SmiliesPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | # | ||||
3 | # This plugin replaces smilies with small smilies bitmaps | ||||
4 | |||||
5 | package Foswiki::Plugins::SmiliesPlugin; | ||||
6 | |||||
7 | 2 | 28µs | 2 | 41µs | # spent 27µs (14+13) within Foswiki::Plugins::SmiliesPlugin::BEGIN@7 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.35 at line 7 # spent 27µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@7
# spent 13µs making 1 call to strict::import |
8 | 2 | 28µs | 2 | 17µs | # spent 13µs (9+4) within Foswiki::Plugins::SmiliesPlugin::BEGIN@8 which was called:
# once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.35 at line 8 # spent 13µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@8
# spent 4µs making 1 call to warnings::import |
9 | |||||
10 | 2 | 939µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::SmiliesPlugin::BEGIN@10 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.35 at line 10 # spent 4µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@10 |
11 | |||||
12 | 1 | 1µs | our %cache = (); | ||
13 | 1 | 0s | our $current; | ||
14 | |||||
15 | 1 | 500ns | our $VERSION = '2.02'; | ||
16 | 1 | 200ns | our $RELEASE = '25 Jun 2015'; | ||
17 | 1 | 100ns | our $NO_PREFS_IN_TOPIC = 1; | ||
18 | 1 | 200ns | our $SHORTDESCRIPTION = 'Render smilies like :-) as icons'; | ||
19 | 1 | 100ns | our $doneHeader = 0; | ||
20 | |||||
21 | # spent 15.0ms (21µs+14.9) within Foswiki::Plugins::SmiliesPlugin::initPlugin which was called:
# once (21µs+14.9ms) 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 | ||||
22 | |||||
23 | 1 | 2µs | 1 | 15µs | Foswiki::Func::registerTagHandler( 'SMILIES', \&_renderSmilies ); # spent 15µs making 1 call to Foswiki::Func::registerTagHandler |
24 | |||||
25 | 1 | 2µs | my $web = $Foswiki::cfg{SystemWebName}; | ||
26 | 1 | 2µs | 1 | 23µs | my $topic = Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_TOPIC') # spent 23µs making 1 call to Foswiki::Func::getPreferencesValue |
27 | || "SmiliesPlugin"; | ||||
28 | |||||
29 | 1 | 700ns | $doneHeader = 0; | ||
30 | |||||
31 | 1 | 3µs | 1 | 14.9ms | _loadSmilies( $web, $topic ); # spent 14.9ms making 1 call to Foswiki::Plugins::SmiliesPlugin::_loadSmilies |
32 | |||||
33 | 1 | 4µs | return 1; | ||
34 | } | ||||
35 | |||||
36 | # spent 6.07ms (4.59+1.48) within Foswiki::Plugins::SmiliesPlugin::preRenderingHandler which was called 5 times, avg 1.21ms/call:
# 5 times (4.59ms+1.48ms) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 1.21ms/call | ||||
37 | |||||
38 | 901 | 3.60ms | 901 | 1.48ms | if ( $_[0] =~ # spent 1.44ms making 896 calls to Foswiki::Plugins::SmiliesPlugin::_renderSmily, avg 2µs/call
# spent 36µs making 5 calls to Foswiki::Plugins::SmiliesPlugin::_addToZone, avg 7µs/call |
39 | s/(\s|^)$cache{$current}{pattern}(?=\s|$)/_renderSmily($1,$2)/ge ) | ||||
40 | { | ||||
41 | _addToZone(); | ||||
42 | } | ||||
43 | } | ||||
44 | |||||
45 | # spent 36µs (13+23) within Foswiki::Plugins::SmiliesPlugin::_addToZone which was called 5 times, avg 7µs/call:
# 5 times (13µs+23µs) by Foswiki::Plugins::SmiliesPlugin::preRenderingHandler at line 38, avg 7µs/call | ||||
46 | 5 | 12µs | return if $doneHeader; | ||
47 | 1 | 400ns | $doneHeader = 1; | ||
48 | 1 | 5µs | 1 | 23µs | Foswiki::Func::addToZone( "head", "SMILIESPLUGIN", # spent 23µs making 1 call to Foswiki::Func::addToZone |
49 | "<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/SmiliesPlugin/smilies.css' type='text/css' media='all' />" | ||||
50 | ); | ||||
51 | } | ||||
52 | |||||
53 | # spent 14.9ms (1.77+13.1) within Foswiki::Plugins::SmiliesPlugin::_loadSmilies which was called:
# once (1.77ms+13.1ms) by Foswiki::Plugins::SmiliesPlugin::initPlugin at line 31 | ||||
54 | 1 | 1µs | my ( $web, $topic, $force ) = @_; | ||
55 | |||||
56 | 1 | 2µs | 1 | 10µs | ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic ); # spent 10µs making 1 call to Foswiki::Func::normalizeWebTopicName |
57 | |||||
58 | 1 | 2µs | $current = "$web.$topic"; | ||
59 | 1 | 800ns | return if !$force && defined $cache{$current}; | ||
60 | |||||
61 | 1 | 1µs | $cache{$current} = (); | ||
62 | |||||
63 | 1 | 3µs | 1 | 20µs | $cache{$current}{format} = # spent 20µs making 1 call to Foswiki::Func::getPreferencesValue |
64 | Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_FORMAT') | ||||
65 | || '<img class=\'smily\' src=\'$url\' alt=\'$tooltip\' title=\'$tooltip\' />'; | ||||
66 | |||||
67 | 1 | 1µs | $cache{$current}{pattern} = "("; | ||
68 | 1 | 300ns | my $state = 0; | ||
69 | 1 | 2µs | 1 | 13.1ms | my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); # spent 13.1ms making 1 call to Foswiki::Func::readTopic |
70 | 1 | 74µs | foreach my $line ( split( /\n/, $text || '' ) ) { | ||
71 | |||||
72 | # | smily | image | description | | ||||
73 | 104 | 521µs | if ( $line =~ m/^\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*$/ ) { | ||
74 | |||||
75 | 91 | 44µs | my $alternatives = $1; | ||
76 | 91 | 24µs | my $image = $2; | ||
77 | 91 | 22µs | my $desc = $3; | ||
78 | |||||
79 | 91 | 37µs | if ( $alternatives =~ m/^\*/ ) { | ||
80 | 1 | 400ns | $state = 1; | ||
81 | 1 | 500ns | next; | ||
82 | } | ||||
83 | |||||
84 | 90 | 32µs | $image =~ s/%ATTACHURL(PATH)?%//g; | ||
85 | 90 | 20µs | $desc =~ s/"//g; | ||
86 | |||||
87 | 90 | 9µs | next unless $alternatives && $image; | ||
88 | |||||
89 | 90 | 130µs | foreach my $key ( split( /\s+/, $alternatives ) ) { | ||
90 | 140 | 241µs | $key =~ s/<nop>|\ //g; | ||
91 | 140 | 131µs | $cache{$current}{pattern} .= "\Q$key\E|"; | ||
92 | 140 | 147µs | $cache{$current}{image}{$key} = $image; | ||
93 | 140 | 92µs | $cache{$current}{desc}{$key} = $desc; | ||
94 | 140 | 154µs | $cache{$current}{alts}{$key} = $alternatives; | ||
95 | } | ||||
96 | } | ||||
97 | else { | ||||
98 | 13 | 9µs | last if $state == 1; | ||
99 | } | ||||
100 | } | ||||
101 | |||||
102 | #$cache{$current}{pattern} =~ s/\|$//; | ||||
103 | 1 | 1µs | $cache{$current}{pattern} .= ")"; | ||
104 | 1 | 60µs | 1 | 21µs | $cache{$current}{pubUrl} = Foswiki::Func::getPubUrlPath() . "/$web/$topic"; # spent 21µs making 1 call to Foswiki::Func::getPubUrlPath |
105 | |||||
106 | } | ||||
107 | |||||
108 | # spent 1.44ms within Foswiki::Plugins::SmiliesPlugin::_renderSmily which was called 896 times, avg 2µs/call:
# 896 times (1.44ms+0s) by Foswiki::Plugins::SmiliesPlugin::preRenderingHandler at line 38, avg 2µs/call | ||||
109 | 896 | 625µs | my ( $pre, $smily ) = @_; | ||
110 | |||||
111 | 896 | 1.79ms | return $pre unless $smily; | ||
112 | return $pre . _formatSmily( $cache{$current}{format}, $smily ); | ||||
113 | } | ||||
114 | |||||
115 | sub _formatSmily { | ||||
116 | my ( $format, $smily ) = @_; | ||||
117 | |||||
118 | my $text = $format; | ||||
119 | |||||
120 | $text =~ s/\$key/<nop>$smily/g; | ||||
121 | $text =~ s/\$alternatives/$cache{$current}{alts}{$smily}/g; | ||||
122 | $text =~ s/\$emoticon/$smily/g; | ||||
123 | $text =~ s/\$tooltip/$cache{$current}{desc}{$smily}/g; | ||||
124 | $text =~ | ||||
125 | s/\$url/$cache{$current}{pubUrl}\/$cache{$current}{image}{$smily}/g; | ||||
126 | |||||
127 | return $text; | ||||
128 | } | ||||
129 | |||||
130 | sub _renderSmilies { | ||||
131 | my ( $session, $params ) = @_; | ||||
132 | |||||
133 | my $smily = $params->{_DEFAULT}; | ||||
134 | my $header = $params->{header}; | ||||
135 | my $format = $params->{format}; | ||||
136 | my $footer = $params->{footer} || ''; | ||||
137 | my $separator = $params->{separator} || '$n'; | ||||
138 | |||||
139 | $header = | ||||
140 | '| *%MAKETEXT{"Notation"}%* | *%MAKETEXT{"Image"}%* | *%MAKETEXT{"Description"}%* |$n' | ||||
141 | unless defined $header; | ||||
142 | |||||
143 | $format = '| $alternatives | $emoticon | $tooltip |' unless defined $format; | ||||
144 | |||||
145 | my @smilies = (); | ||||
146 | if ( defined $smily ) { | ||||
147 | push @smilies, $smily; | ||||
148 | } | ||||
149 | else { | ||||
150 | @smilies = | ||||
151 | sort { | ||||
152 | lc( $cache{$current}{image}{$a} ) cmp | ||||
153 | lc( $cache{$current}{image}{$b} ) | ||||
154 | } | ||||
155 | keys %{ $cache{$current}{alts} }; | ||||
156 | } | ||||
157 | |||||
158 | my @result = (); | ||||
159 | my %seen = (); | ||||
160 | foreach my $smily (@smilies) { | ||||
161 | next if $seen{ $cache{$current}{alts}{$smily} }; | ||||
162 | push @result, _formatSmily( $format, $smily ); | ||||
163 | $seen{ $cache{$current}{alts}{$smily} } = 1; | ||||
164 | } | ||||
165 | |||||
166 | return '' unless @result; | ||||
167 | |||||
168 | _addToZone(); | ||||
169 | |||||
170 | return Foswiki::Func::decodeFormatTokens( | ||||
171 | $header . join( $separator, @result ) . $footer ); | ||||
172 | } | ||||
173 | |||||
174 | 1 | 4µs | 1; | ||
175 | __END__ |