← 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/TwistyPlugin.pm
StatementsExecuted 40 statements in 2.24ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.47ms1.65msFoswiki::Plugins::TwistyPlugin::::BEGIN@12Foswiki::Plugins::TwistyPlugin::BEGIN@12
11164µs350µsFoswiki::Plugins::TwistyPlugin::::initPluginFoswiki::Plugins::TwistyPlugin::initPlugin
11117µs125µsFoswiki::Plugins::TwistyPlugin::::_exportAnimationSpeedFoswiki::Plugins::TwistyPlugin::_exportAnimationSpeed
11110µs10µsFoswiki::Plugins::TwistyPlugin::::BEGIN@11Foswiki::Plugins::TwistyPlugin::BEGIN@11
11110µs29µsFoswiki::Plugins::TwistyPlugin::::BEGIN@20Foswiki::Plugins::TwistyPlugin::BEGIN@20
1119µs64µsFoswiki::Plugins::TwistyPlugin::::BEGIN@17Foswiki::Plugins::TwistyPlugin::BEGIN@17
1118µs20µsFoswiki::Plugins::TwistyPlugin::::BEGIN@14Foswiki::Plugins::TwistyPlugin::BEGIN@14
1118µs13µsFoswiki::Plugins::TwistyPlugin::::BEGIN@15Foswiki::Plugins::TwistyPlugin::BEGIN@15
1115µs5µsFoswiki::Plugins::TwistyPlugin::::BEGIN@13Foswiki::Plugins::TwistyPlugin::BEGIN@13
0000s0sFoswiki::Plugins::TwistyPlugin::::_ENDTWISTYTOGGLEFoswiki::Plugins::TwistyPlugin::_ENDTWISTYTOGGLE
0000s0sFoswiki::Plugins::TwistyPlugin::::_TWISTYFoswiki::Plugins::TwistyPlugin::_TWISTY
0000s0sFoswiki::Plugins::TwistyPlugin::::_TWISTYBUTTONFoswiki::Plugins::TwistyPlugin::_TWISTYBUTTON
0000s0sFoswiki::Plugins::TwistyPlugin::::_TWISTYHIDEFoswiki::Plugins::TwistyPlugin::_TWISTYHIDE
0000s0sFoswiki::Plugins::TwistyPlugin::::_TWISTYSHOWFoswiki::Plugins::TwistyPlugin::_TWISTYSHOW
0000s0sFoswiki::Plugins::TwistyPlugin::::_TWISTYTOGGLEFoswiki::Plugins::TwistyPlugin::_TWISTYTOGGLE
0000s0sFoswiki::Plugins::TwistyPlugin::::_addHeaderFoswiki::Plugins::TwistyPlugin::_addHeader
0000s0sFoswiki::Plugins::TwistyPlugin::::_createHtmlPropertiesFoswiki::Plugins::TwistyPlugin::_createHtmlProperties
0000s0sFoswiki::Plugins::TwistyPlugin::::_createIdFoswiki::Plugins::TwistyPlugin::_createId
0000s0sFoswiki::Plugins::TwistyPlugin::::_readCookieFoswiki::Plugins::TwistyPlugin::_readCookie
0000s0sFoswiki::Plugins::TwistyPlugin::::_setDefaultsFoswiki::Plugins::TwistyPlugin::_setDefaults
0000s0sFoswiki::Plugins::TwistyPlugin::::_twistyBtnFoswiki::Plugins::TwistyPlugin::_twistyBtn
0000s0sFoswiki::Plugins::TwistyPlugin::::_wrapInButtonHtmlFoswiki::Plugins::TwistyPlugin::_wrapInButtonHtml
0000s0sFoswiki::Plugins::TwistyPlugin::::_wrapInContainerDivIfNoJavascripCloseFoswiki::Plugins::TwistyPlugin::_wrapInContainerDivIfNoJavascripClose
0000s0sFoswiki::Plugins::TwistyPlugin::::_wrapInContainerHideIfNoJavascripOpenFoswiki::Plugins::TwistyPlugin::_wrapInContainerHideIfNoJavascripOpen
0000s0sFoswiki::Plugins::TwistyPlugin::::_wrapInContentHtmlCloseFoswiki::Plugins::TwistyPlugin::_wrapInContentHtmlClose
0000s0sFoswiki::Plugins::TwistyPlugin::::_wrapInContentHtmlOpenFoswiki::Plugins::TwistyPlugin::_wrapInContentHtmlOpen
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
3=begin TML
4
5---+ package TwistyPlugin
6
7=cut
8
9package Foswiki::Plugins::TwistyPlugin;
10
11226µs110µs
# spent 10µs within Foswiki::Plugins::TwistyPlugin::BEGIN@11 which was called: # once (10µs+0s) by Foswiki::Plugin::BEGIN@2.36 at line 11
use Foswiki::Func ();
# spent 10µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@11
122100µs11.65ms
# spent 1.65ms (1.47+177µs) within Foswiki::Plugins::TwistyPlugin::BEGIN@12 which was called: # once (1.47ms+177µs) by Foswiki::Plugin::BEGIN@2.36 at line 12
use CGI::Cookie ();
# spent 1.65ms making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@12
13222µs15µs
# spent 5µs within Foswiki::Plugins::TwistyPlugin::BEGIN@13 which was called: # once (5µs+0s) by Foswiki::Plugin::BEGIN@2.36 at line 13
use CGI ();
# spent 5µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@13
14224µs232µs
# spent 20µs (8+12) within Foswiki::Plugins::TwistyPlugin::BEGIN@14 which was called: # once (8µs+12µs) by Foswiki::Plugin::BEGIN@2.36 at line 14
use strict;
# spent 20µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@14 # spent 12µs making 1 call to strict::import
15230µs218µs
# spent 13µs (8+5) within Foswiki::Plugins::TwistyPlugin::BEGIN@15 which was called: # once (8µs+5µs) by Foswiki::Plugin::BEGIN@2.36 at line 15
use warnings;
# spent 13µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@15 # spent 5µs making 1 call to warnings::import
16
1716µs156µs
# spent 64µs (9+56) within Foswiki::Plugins::TwistyPlugin::BEGIN@17 which was called: # once (9µs+56µs) by Foswiki::Plugin::BEGIN@2.36 at line 18
use vars qw( @twistystack $doneHeader $doneDefaults $twistyCount
# spent 56µs making 1 call to vars::import
18128µs164µs $prefMode $prefShowLink $prefHideLink $prefRemember);
# spent 64µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@17
19
2031.93ms394µs
# spent 29µs (10+19) within Foswiki::Plugins::TwistyPlugin::BEGIN@20 which was called: # once (10µs+19µs) by Foswiki::Plugin::BEGIN@2.36 at line 20
use version; our $VERSION = version->declare("v1.6.18");
# spent 47µs making 1 call to version::vxs::declare # spent 29µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@20 # spent 19µs making 1 call to version::import
211300nsour $RELEASE = '1.6.18';
221200nsour $SHORTDESCRIPTION =
23 'Twisty section Javascript library to open/close content dynamically';
241200nsour $NO_PREFS_IN_TOPIC = 1;
25
261400nsmy $TWISTYPLUGIN_COOKIE_PREFIX = "TwistyPlugin_";
271100nsmy $TWISTYPLUGIN_CONTENT_HIDDEN = 0;
281100nsmy $TWISTYPLUGIN_CONTENT_SHOWN = 1;
29
30#there is no need to document this.
31
# spent 350µs (64+286) within Foswiki::Plugins::TwistyPlugin::initPlugin which was called: # once (64µs+286µ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 {
3212µs my ( $topic, $web, $user, $installWeb ) = @_;
33
34 # check for Plugins.pm versions
35115µs19µs if ( $Foswiki::Plugins::VERSION < 1.1 ) {
# spent 9µs making 1 call to version::vxs::VCMP
36 Foswiki::Func::writeWarning(
37 "Version mismatch between TwistyPlugin and Plugins.pm");
38 return 0;
39 }
40
4112µs $doneDefaults = 0;
421600ns $doneHeader = 0;
431300ns $twistyCount = 0;
44
4513µs1125µs _exportAnimationSpeed();
46
4713µs119µs Foswiki::Plugins::JQueryPlugin::registerPlugin( 'twisty',
# spent 19µs making 1 call to Foswiki::Plugins::JQueryPlugin::registerPlugin
48 'Foswiki::Plugins::TwistyPlugin::TWISTY' );
4914µs124µs Foswiki::Func::registerTagHandler( 'TWISTYSHOW', \&_TWISTYSHOW );
# spent 24µs making 1 call to Foswiki::Func::registerTagHandler
5012µs118µs Foswiki::Func::registerTagHandler( 'TWISTYHIDE', \&_TWISTYHIDE );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
5114µs119µs Foswiki::Func::registerTagHandler( 'TWISTYBUTTON', \&_TWISTYBUTTON );
# spent 19µs making 1 call to Foswiki::Func::registerTagHandler
5212µs118µs Foswiki::Func::registerTagHandler( 'TWISTY', \&_TWISTY );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
5314µs118µs Foswiki::Func::registerTagHandler( 'ENDTWISTY', \&_ENDTWISTYTOGGLE );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
5412µs118µs Foswiki::Func::registerTagHandler( 'TWISTYTOGGLE', \&_TWISTYTOGGLE );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
5511µs118µs Foswiki::Func::registerTagHandler( 'ENDTWISTYTOGGLE', \&_ENDTWISTYTOGGLE );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
56
5716µs return 1;
58}
59
60
# spent 125µs (17+108) within Foswiki::Plugins::TwistyPlugin::_exportAnimationSpeed which was called: # once (17µs+108µs) by Foswiki::Plugins::TwistyPlugin::initPlugin at line 45
sub _exportAnimationSpeed {
61
6214µs288µs my $pref =
# spent 56µs making 1 call to Foswiki::Func::getPluginPreferencesValue # spent 31µs making 1 call to Foswiki::Func::getPreferencesValue
63 Foswiki::Func::getPreferencesValue('TWISTYANIMATIONSPEED')
64 || Foswiki::Func::getPluginPreferencesValue('TWISTYANIMATIONSPEED')
65 || '0';
66
67 # add TWISTYANIMATIONSPEED to the html head so
68 # that it may be used in the client JS with
69 # foswiki.getPreference('TWISTYANIMATIONSPEED')
7013µs121µs Foswiki::Func::addToZone( "script", "TWISTYPLUGIN::META",
# spent 21µs making 1 call to Foswiki::Func::addToZone
71 <<"HERE", "JQUERYPLUGIN::FOSWIKI::PREFERENCES" );
72<script type='text/javascript'>jQuery.extend(foswiki.preferences, { TWISTYANIMATIONSPEED: '$pref' });</script>
73HERE
74
7515µs return;
76}
77
78sub _setDefaults {
79 return if $doneDefaults;
80 $doneDefaults = 1;
81
82 $prefMode =
83 Foswiki::Func::getPreferencesValue('TWISTYMODE')
84 || Foswiki::Func::getPluginPreferencesValue('TWISTYMODE')
85 || 'div';
86 $prefShowLink =
87 Foswiki::Func::getPreferencesValue('TWISTYSHOWLINK')
88 || Foswiki::Func::getPluginPreferencesValue('TWISTYSHOWLINK')
89 || '%MAKETEXT{"More..."}%';
90 $prefHideLink =
91 Foswiki::Func::getPreferencesValue('TWISTYHIDELINK')
92 || Foswiki::Func::getPluginPreferencesValue('TWISTYHIDELINK')
93 || '%MAKETEXT{"Close"}%';
94 $prefRemember =
95 Foswiki::Func::getPreferencesValue('TWISTYREMEMBER')
96 || Foswiki::Func::getPluginPreferencesValue('TWISTYREMEMBER')
97 || '';
98
99 return;
100}
101
102sub _addHeader {
103 return if $doneHeader;
104 $doneHeader = 1;
105
106 if ( Foswiki::Func::getContext()->{JQueryPluginEnabled} ) {
107 Foswiki::Plugins::JQueryPlugin::createPlugin('twisty');
108 }
109 else {
110 my $header;
111 Foswiki::Func::loadTemplate('twistyplugin');
112
113 $header =
114 Foswiki::Func::expandTemplate("TwistyPlugin/twisty")
115 . Foswiki::Func::expandTemplate("TwistyPlugin/twisty.css");
116 Foswiki::Func::expandCommonVariables($header);
117 }
118
119 return;
120}
121
122sub _TWISTYSHOW {
123 my ( $session, $params, $theTopic, $theWeb ) = @_;
124 _setDefaults();
125
126 my $mode = $params->{'mode'} || $prefMode;
127 my $btn = _twistyBtn( 'show', $session, $params, $theTopic, $theWeb );
128 return Foswiki::Func::decodeFormatTokens(
129 _wrapInButtonHtml( $btn, $mode ) );
130}
131
132sub _TWISTYHIDE {
133 my ( $session, $params, $theTopic, $theWeb ) = @_;
134 _setDefaults();
135 my $mode = $params->{'mode'} || $prefMode;
136 my $btn = _twistyBtn( 'hide', $session, $params, $theTopic, $theWeb );
137 return Foswiki::Func::decodeFormatTokens(
138 _wrapInButtonHtml( $btn, $mode ) );
139}
140
141sub _TWISTYBUTTON {
142 my ( $session, $params, $theTopic, $theWeb ) = @_;
143 _setDefaults();
144
145 my $mode = $params->{'mode'} || $prefMode;
146 my $btnShow = _twistyBtn( 'show', $session, $params, $theTopic, $theWeb );
147 my $btnHide = _twistyBtn( 'hide', $session, $params, $theTopic, $theWeb );
148 my $prefix = $params->{'prefix'} || '';
149 my $suffix = $params->{'suffix'} || '';
150 my $btn = $prefix . $btnShow . $btnHide . $suffix;
151 return Foswiki::Func::decodeFormatTokens(
152 _wrapInButtonHtml( $btn, $mode ) );
153}
154
155=pod
156
157If no ID is passed, creates a new unique id based on web and topic.
158
159=cut
160
161sub _TWISTY {
162 my ( $session, $params, $theTopic, $theWeb ) = @_;
163
164 _addHeader();
165 $params->{'id'} = _createId( $params, $theWeb, $theTopic );
166 return _TWISTYBUTTON( $session, $params, $theTopic, $theWeb )
167 . _TWISTYTOGGLE( $session, $params, $theTopic, $theWeb );
168}
169
170sub _TWISTYTOGGLE {
171 my ( $session, $params, $theTopic, $theWeb ) = @_;
172 my $id = $params->{'id'};
173 if ( !defined $id || $id eq '' ) {
174 return '';
175 }
176 _setDefaults();
177 my $idTag = $id . 'toggle';
178 my $mode = $params->{'mode'} || $prefMode;
179 push( @twistystack, { mode => $mode, id => $idTag } );
180
181 my $isTrigger = 0;
182 my $cookieState = _readCookie( $session, $idTag );
183 my @propList =
184 _createHtmlProperties( undef, $idTag, $mode, $params, $isTrigger,
185 $cookieState );
186 my $props = @propList ? " " . join( " ", @propList ) : '';
187 my $modeTag = '<' . $mode . $props . '>';
188 return Foswiki::Func::decodeFormatTokens(
189 _wrapInContentHtmlOpen($mode) . $modeTag );
190}
191
192sub _ENDTWISTYTOGGLE {
193 my ( $session, $params, $theTopic, $theWeb ) = @_;
194 my $twisty = pop @twistystack;
195
196 return
197"<div class='foswikiAlert'>woops, ordering error: got an ENDTWISTY before seeing a TWISTY</div>"
198 unless $twisty->{mode};
199
200 my $modeTag = ( $twisty->{mode} ) ? '</' . $twisty->{mode} . '>' : '';
201 return $modeTag . _wrapInContentHtmlClose($twisty);
202}
203
204sub _createId {
205 my ( $params, $inWeb, $inTopic ) = @_;
206
207 my $id = $params->{'id'} || "twistyId$inWeb$inTopic";
208 $id =~ s/\//subweb/go;
209
210 # Ensure uniqueness, or at least try to
211 my $remember = $params->{'remember'} || $prefRemember;
212 if ( Foswiki::Func::isTrue($remember) ) {
213 $id .= ++$twistyCount; # For remember
214 }
215 else { # 100 is the number of remembered cookies to avoid clashes
216 $id .= int( rand(10000) ) + 100; # For AJAX
217 }
218 return $id;
219}
220
221sub _twistyBtn {
222 my ( $twistyControlState, $session, $params, $theTopic, $theWeb ) = @_;
223
224 _addHeader();
225
226 # not used yet:
227 #my $triangle_right = '&#9658;';
228 #my $triangle_down = '&#9660;';
229
230 my $id = $params->{'id'};
231 if ( !defined $id || $id eq '' ) {
232 return '';
233 }
234 my $idTag;
235 if ($twistyControlState) {
236 $idTag = $id . $twistyControlState;
237 }
238 else {
239 $idTag = '';
240 }
241
242 my $defaultLink =
243 ( $twistyControlState eq 'show' ) ? $prefShowLink : $prefHideLink;
244
245 # link="" takes precedence over showlink="" and hidelink=""
246 my $link = $params->{'link'};
247
248 if ( !defined $link ) {
249
250 # if 'link' is not set, try 'showlink' / 'hidelink'
251 $link = $params->{ $twistyControlState . 'link' };
252 }
253 if ( !defined $link ) {
254 $link = $defaultLink || '';
255 }
256 my $img =
257 $params->{ $twistyControlState . 'img' }
258 || $params->{'img'}
259 || '';
260 my $imgright =
261 $params->{ $twistyControlState . 'imgright' }
262 || $params->{'imgright'}
263 || '';
264 my $imgleft =
265 $params->{ $twistyControlState . 'imgleft' }
266 || $params->{'imgleft'}
267 || '';
268 $img =~ s/['\"]//go;
269 $imgright =~ s/['\"]//go;
270 $imgleft =~ s/['\"]//go;
271 my $imgTag =
272 ( $img ne '' ) ? '<img src="' . $img . '" border="0" alt="" />' : '';
273 my $imgRightTag =
274 ( $imgright ne '' )
275 ? '<img src="' . $imgright . '" border="0" alt="" />'
276 : '';
277 my $imgLeftTag =
278 ( $imgleft ne '' )
279 ? '<img src="' . $imgleft . '" border="0" alt="" />'
280 : '';
281
282 my @linkClasses;
283 push( @linkClasses, $params->{'linkclass'} ) if $params->{'linkclass'};
284
285 my $imgLinkTag = CGI::a(
286 {
287 href => '#',
288 class => join( ' ', @linkClasses )
289 },
290 $imgLeftTag
291 . CGI::span( { class => 'foswikiLinkLabel foswikiUnvisited' }, $link )
292 . $imgTag
293 . $imgRightTag
294 );
295
296 my $isTrigger = 1;
297 my $props = '';
298
299 if ( $idTag && $params ) {
300 my $cookieState = _readCookie( $session, $idTag );
301 my @propList =
302 _createHtmlProperties( $twistyControlState, $idTag, undef, $params,
303 $isTrigger, $cookieState );
304 $props = @propList ? " " . join( " ", @propList ) : '';
305 }
306 my $triggerTag = '<span' . $props . '>' . $imgLinkTag . '</span>';
307 return $triggerTag;
308}
309
310sub _createHtmlProperties {
311 my ( $twistyControlState, $idTag, $mode, $params, $isTrigger, $cookie ) =
312 @_;
313 my $class = $params->{'class'} || '';
314 my $firststart = $params->{'firststart'} || '';
315 my $firstStartHidden;
316 $firstStartHidden = 1 if ( $firststart eq 'hide' );
317 my $firstStartShown;
318 $firstStartShown = 1 if ( $firststart eq 'show' );
319 my $cookieShow;
320 $cookieShow = 1 if defined $cookie && $cookie == 1;
321 my $cookieHide;
322 $cookieHide = 1 if defined $cookie && $cookie == 0;
323 my $start = $params->{start} || '';
324 my $startHidden;
325 $startHidden = 1 if ( $start eq 'hide' );
326 my $startShown;
327 $startShown = 1 if ( $start eq 'show' );
328 my @propList = ();
329
330 _setDefaults();
331 my $remember = $params->{'remember'} || $prefRemember;
332 my $noscript = $params->{'noscript'} || '';
333 my $noscriptHide = ( $noscript eq 'hide' ) ? 1 : 0;
334 $mode ||= $prefMode;
335
336 my @classList = ();
337 my @styleList = ();
338 push( @classList, $class ) if $class && !$isTrigger;
339 push( @classList, 'twistyRememberSetting' )
340 if Foswiki::Func::isTrue($remember);
341 push( @classList, 'twistyForgetSetting' ) if $remember eq 'off';
342 push( @classList, 'twistyStartHide' ) if $startHidden;
343 push( @classList, 'twistyStartShow' ) if $startShown;
344 push( @classList, 'twistyFirstStartHide' ) if $firstStartHidden;
345 push( @classList, 'twistyFirstStartShow' ) if $firstStartShown;
346
347 # Mimic the rules in twist.js, function _update()
348 my $state = '';
349 $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $firstStartHidden;
350 $state = $TWISTYPLUGIN_CONTENT_SHOWN if $firstStartShown;
351
352 # cookie setting may override firstStartHidden and firstStartShown
353 $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $cookieHide;
354 $state = $TWISTYPLUGIN_CONTENT_SHOWN if $cookieShow;
355
356 # startHidden and startShown may override cookie
357 $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $startHidden;
358 $state = $TWISTYPLUGIN_CONTENT_SHOWN if $startShown;
359
360 # assume trigger should be hidden
361 # unless explicitly said otherwise
362 my $shouldHideTrigger = 1;
363 if ($isTrigger) {
364 push( @classList, 'twistyTrigger foswikiUnvisited' );
365
366 if ( $state eq $TWISTYPLUGIN_CONTENT_SHOWN
367 && $twistyControlState eq 'hide' )
368 {
369 $shouldHideTrigger = 0;
370 }
371 if ( $state eq $TWISTYPLUGIN_CONTENT_HIDDEN
372 && $twistyControlState eq 'show' )
373 {
374 $shouldHideTrigger = 0;
375 }
376 push( @styleList, 'display:none' ) if $shouldHideTrigger;
377 }
378
379 # assume content should be hidden
380 # unless explicitly said otherwise
381 if ( !$isTrigger ) {
382 push( @classList, 'twistyContent' );
383 }
384
385 # deprecated
386 # should be done by Foswiki template scripts instead
387 if ( !$isTrigger && $noscriptHide ) {
388 push( @classList, 'foswikiMakeVisible' );
389 }
390
391 # let javascript know we have set the state already
392 push( @classList, 'twistyInited' . $state );
393
394 push( @propList, 'id="' . $idTag . '"' );
395
396 my $styleListString = join( ", ", @styleList );
397 push( @propList, 'style="' . $styleListString . '"' );
398
399 my $classListString = join( " ", @classList );
400 push( @propList, 'class="' . $classListString . '"' );
401
402 return @propList;
403}
404
405=begin TML
406
407Reads a setting from the FOSWIKIPREF cookie.
408Returns:
409 * 1 if the cookie has been set (meaning: show content)
410 * 0 if the cookie is '0' (meaning: hide content)
411 * undef if no cookie has been set
412
413=cut
414
415sub _readCookie {
416 my ( $session, $idTag ) = @_;
417
418 return '' if !$idTag;
419
420 # which state do we use?
421 my $cgi = CGI->new();
422 my $cookie = $cgi->cookie('FOSWIKIPREF');
423 my $tag = $idTag;
424 $tag =~ s/^(.*)(hide|show|toggle)$/$1/go;
425 my $key = $TWISTYPLUGIN_COOKIE_PREFIX . $tag;
426
427 return unless ( defined($key) && defined($cookie) );
428
429 my $value = '';
430 if ( $cookie =~ m/\b\Q$key=\E(.+?)\b/gi ) {
431 $value = $1;
432 }
433
434 return if $value eq '';
435 return ( $value eq '1' ) ? 1 : 0;
436}
437
438sub _wrapInButtonHtml {
439 my ( $text, $mode ) = @_;
440 return _wrapInContainerHideIfNoJavascripOpen($mode) . $text
441 . _wrapInContainerDivIfNoJavascripClose($mode);
442}
443
444sub _wrapInContentHtmlOpen {
445 my ($mode) = @_;
446 return "<$mode class=\"twistyPlugin\">";
447}
448
449sub _wrapInContentHtmlClose {
450 my ($twisty) = @_;
451 my $closeTag = "</$twisty->{mode}>";
452
453 return $closeTag;
454}
455
456sub _wrapInContainerHideIfNoJavascripOpen {
457 my ($mode) = @_;
458
459 return '<' . $mode . ' class="twistyPlugin foswikiMakeVisible">';
460}
461
462sub _wrapInContainerDivIfNoJavascripClose {
463 my ($mode) = @_;
464
465 return '</' . $mode . '>';
466}
467
46815µs1;
469__END__