Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/TinyMCEPlugin.pm |
Statements | Executed 19 statements in 724µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 28µs | BEGIN@5 | Foswiki::Plugins::TinyMCEPlugin::
1 | 1 | 1 | 11µs | 15µs | initPlugin | Foswiki::Plugins::TinyMCEPlugin::
1 | 1 | 1 | 9µs | 14µs | BEGIN@6 | Foswiki::Plugins::TinyMCEPlugin::
1 | 1 | 1 | 9µs | 35µs | BEGIN@8 | Foswiki::Plugins::TinyMCEPlugin::
1 | 1 | 1 | 5µs | 5µs | BEGIN@15 | Foswiki::Plugins::TinyMCEPlugin::
0 | 0 | 0 | 0s | 0s | _notAvailable | Foswiki::Plugins::TinyMCEPlugin::
0 | 0 | 0 | 0s | 0s | beforeEditHandler | Foswiki::Plugins::TinyMCEPlugin::
0 | 0 | 0 | 0s | 0s | installTinyMCE | Foswiki::Plugins::TinyMCEPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | package Foswiki::Plugins::TinyMCEPlugin; | ||||
4 | |||||
5 | 2 | 28µs | 2 | 42µs | # spent 28µs (14+14) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@5 which was called:
# once (14µs+14µs) by Foswiki::Plugin::BEGIN@2.39 at line 5 # spent 28µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@5
# spent 14µs making 1 call to strict::import |
6 | 2 | 24µs | 2 | 18µs | # spent 14µs (9+4) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@6 which was called:
# once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.39 at line 6 # spent 14µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@6
# spent 4µs making 1 call to warnings::import |
7 | |||||
8 | 2 | 61µs | 2 | 61µs | # spent 35µs (9+26) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@8 which was called:
# once (9µs+26µs) by Foswiki::Plugin::BEGIN@2.39 at line 8 # spent 35µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@8
# spent 26µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 700ns | our $VERSION = '1.30'; | ||
11 | 1 | 200ns | our $RELEASE = '1.30'; | ||
12 | 1 | 200ns | our $SHORTDESCRIPTION = 'Integration of the Tiny MCE WYSIWYG Editor'; | ||
13 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
14 | |||||
15 | 2 | 598µs | 1 | 5µs | # spent 5µs within Foswiki::Plugins::TinyMCEPlugin::BEGIN@15 which was called:
# once (5µs+0s) by Foswiki::Plugin::BEGIN@2.39 at line 15 # spent 5µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@15 |
16 | 1 | 200ns | my $query; | ||
17 | |||||
18 | # spent 15µs (11+4) within Foswiki::Plugins::TinyMCEPlugin::initPlugin which was called:
# once (11µs+4µ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 | ||||
19 | 1 | 2µs | 1 | 4µs | $query = Foswiki::Func::getCgiQuery(); # spent 4µs making 1 call to Foswiki::Func::getCgiQuery |
20 | 1 | 500ns | return 0 unless $query; | ||
21 | |||||
22 | 1 | 2µs | unless ( $Foswiki::cfg{Plugins}{WysiwygPlugin}{Enabled} ) { | ||
23 | Foswiki::Func::writeWarning( | ||||
24 | "TinyMCEPlugin is enabled but WysiwygPlugin is not. Both must be installed and enabled for TinyMCE." | ||||
25 | ); | ||||
26 | return 0; | ||||
27 | } | ||||
28 | 1 | 1µs | unless ( $Foswiki::cfg{Plugins}{JQueryPlugin}{Enabled} ) { | ||
29 | Foswiki::Func::writeWarning( | ||||
30 | "TinyMCEPlugin is enabled but JQueryPlugin is not. Both must be installed and enabled for TinyMCE." | ||||
31 | ); | ||||
32 | return 0; | ||||
33 | } | ||||
34 | |||||
35 | 1 | 3µs | return 1; | ||
36 | } | ||||
37 | |||||
38 | sub _notAvailable { | ||||
39 | for my $c (qw(TINYMCEPLUGIN_DISABLE NOWYSIWYG)) { | ||||
40 | return "Disabled by * Set $c = " | ||||
41 | . Foswiki::Func::getPreferencesValue($c) | ||||
42 | if Foswiki::Func::getPreferencesFlag($c); | ||||
43 | } | ||||
44 | |||||
45 | # Disable TinyMCE if we are on a specialised edit skin | ||||
46 | my $skin = Foswiki::Func::getPreferencesValue('WYSIWYGPLUGIN_WYSIWYGSKIN'); | ||||
47 | return "$skin is active" | ||||
48 | if ( $skin && Foswiki::Func::getSkin() =~ m/\b$skin\b/ ); | ||||
49 | |||||
50 | return "No browser" unless $query; | ||||
51 | |||||
52 | return "Disabled by URL parameter" if $query->param('nowysiwyg'); | ||||
53 | |||||
54 | # Check the client browser to see if it is blacklisted | ||||
55 | my $ua = Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_BAD_BROWSERS') | ||||
56 | || '(?i-xsm:Konqueror)'; | ||||
57 | return 'Unsupported browser: ' . $query->user_agent() | ||||
58 | if $ua && $query->user_agent() && $query->user_agent() =~ m/$ua/; | ||||
59 | |||||
60 | # This should only ever happen on Foswiki 1.0.9 and earlier | ||||
61 | return 'TinyMCEPlugin requires ZonePlugin to be installed and enabled' | ||||
62 | unless ( defined &Foswiki::Func::addToZone ); | ||||
63 | |||||
64 | return 0; | ||||
65 | } | ||||
66 | |||||
67 | sub beforeEditHandler { | ||||
68 | my ( $text, $topic, $web ) = @_; | ||||
69 | |||||
70 | my $mess = _notAvailable(); | ||||
71 | if ($mess) { | ||||
72 | my $disabled = ( $mess !~ /^Disabled/ ); | ||||
73 | $mess = 'WYSIWYG could not be started: ' . $mess; | ||||
74 | if ( ( $disabled || DEBUG ) | ||||
75 | && defined &Foswiki::Func::setPreferencesValue ) | ||||
76 | { | ||||
77 | Foswiki::Func::setPreferencesValue( 'EDITOR_MESSAGE', $mess ); | ||||
78 | } | ||||
79 | Foswiki::Func::writeDebug($mess) if DEBUG; | ||||
80 | return; | ||||
81 | } | ||||
82 | if ( defined &Foswiki::Func::setPreferencesValue ) { | ||||
83 | Foswiki::Func::setPreferencesValue( 'EDITOR_HELP', 'TinyMCEQuickHelp' ); | ||||
84 | } | ||||
85 | |||||
86 | my $initTopic = | ||||
87 | Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_INIT_TOPIC') | ||||
88 | || $Foswiki::cfg{SystemWebName} . '.TinyMCEPlugin'; | ||||
89 | my $init = Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_INIT') | ||||
90 | || Foswiki::Func::expandCommonVariables( | ||||
91 | '%INCLUDE{"' | ||||
92 | . $initTopic | ||||
93 | . '" section="TINYMCEPLUGIN_INIT" warn="off"}%', | ||||
94 | $topic, $web | ||||
95 | ); | ||||
96 | |||||
97 | require Foswiki::Plugins::WysiwygPlugin; | ||||
98 | my ( $browser, $defaultINIT_BROWSER ) = | ||||
99 | Foswiki::Plugins::WysiwygPlugin::getBrowserName(); | ||||
100 | |||||
101 | if ($browser) { | ||||
102 | my $settings = | ||||
103 | Foswiki::Func::getPreferencesValue( 'TINYMCEPLUGIN_INIT_' . $browser ) | ||||
104 | || $defaultINIT_BROWSER; | ||||
105 | if ($settings) { | ||||
106 | $init = | ||||
107 | join( ',', ( split( ',', $init ), split( ',', $settings ) ) ); | ||||
108 | } | ||||
109 | } | ||||
110 | |||||
111 | $mess = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable($text); | ||||
112 | if ($mess) { | ||||
113 | $mess = 'WYSIWYG could not be started: ' . $mess; | ||||
114 | if ( defined &Foswiki::Func::setPreferencesValue ) { | ||||
115 | Foswiki::Func::setPreferencesValue( 'EDITOR_MESSAGE', $mess ); | ||||
116 | Foswiki::Func::setPreferencesValue( 'EDITOR_HELP', undef ); | ||||
117 | } | ||||
118 | Foswiki::Func::writeDebug($mess) if DEBUG; | ||||
119 | return; | ||||
120 | } | ||||
121 | |||||
122 | installTinyMCE( 'TinyMCEPluginTextArea', $init ); | ||||
123 | |||||
124 | return; | ||||
125 | } | ||||
126 | |||||
127 | sub installTinyMCE { | ||||
128 | my $sectionName = shift; | ||||
129 | my $init = shift; | ||||
130 | |||||
131 | require Foswiki::Plugins::JQueryPlugin; | ||||
132 | Foswiki::Plugins::JQueryPlugin::createPlugin("tinymce"); | ||||
133 | |||||
134 | my $scripts = <<"SCRIPT"; | ||||
135 | <script type="text/javascript"> | ||||
136 | jQuery(function(\$) { FoswikiTiny.install(); }); | ||||
137 | FoswikiTiny.init = {$init}; | ||||
138 | </script> | ||||
139 | SCRIPT | ||||
140 | |||||
141 | Foswiki::Func::addToZone( 'script', $sectionName, | ||||
142 | Foswiki::Func::expandCommonVariables($scripts), | ||||
143 | 'JQUERYPLUGIN::TINYMCE' ); | ||||
144 | |||||
145 | # See %SYSTEMWEB%.IfStatements for a description of this context id. | ||||
146 | Foswiki::Func::getContext()->{textareas_hijacked} = 1; | ||||
147 | } | ||||
148 | |||||
149 | 1 | 4µs | 1; | ||
150 | |||||
151 | __END__ |