Filename | /var/www/foswiki11/lib/Foswiki/Plugins/RenderPlugin.pm |
Statements | Executed 23 statements in 1.05ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 36µs | 143µs | initPlugin | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@18 | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 10µs | 16µs | BEGIN@19 | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 9µs | 43µs | BEGIN@30 | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@22 | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@21 | Foswiki::Plugins::RenderPlugin::
1 | 1 | 1 | 3µs | 3µs | BEGIN@23 | Foswiki::Plugins::RenderPlugin::
0 | 0 | 0 | 0s | 0s | restExpand | Foswiki::Plugins::RenderPlugin::
0 | 0 | 0 | 0s | 0s | restRender | Foswiki::Plugins::RenderPlugin::
0 | 0 | 0 | 0s | 0s | restTag | Foswiki::Plugins::RenderPlugin::
0 | 0 | 0 | 0s | 0s | restTemplate | Foswiki::Plugins::RenderPlugin::
0 | 0 | 0 | 0s | 0s | writeDebug | Foswiki::Plugins::RenderPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||||
2 | # | ||||
3 | # Copyright (C) 2008-2014 Michael Daum http://michaeldaumconsulting.com | ||||
4 | # | ||||
5 | # This program is free software; you can redistribute it and/or | ||||
6 | # modify it under the terms of the GNU General Public License | ||||
7 | # as published by the Free Software Foundation; either version 2 | ||||
8 | # of the License, or (at your option) any later version. | ||||
9 | # | ||||
10 | # This program is distributed in the hope that it will be useful, | ||||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | # GNU General Public License for more details, published at | ||||
14 | # http://www.gnu.org/copyleft/gpl.html | ||||
15 | |||||
16 | package Foswiki::Plugins::RenderPlugin; | ||||
17 | |||||
18 | 2 | 30µs | 2 | 40µs | # spent 27µs (14+13) within Foswiki::Plugins::RenderPlugin::BEGIN@18 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.27 at line 18 # spent 27µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@18
# spent 13µs making 1 call to strict::import |
19 | 2 | 25µs | 2 | 21µs | # spent 16µs (10+6) within Foswiki::Plugins::RenderPlugin::BEGIN@19 which was called:
# once (10µs+6µs) by Foswiki::Plugin::BEGIN@2.27 at line 19 # spent 16µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@19
# spent 6µs making 1 call to warnings::import |
20 | |||||
21 | 2 | 20µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::RenderPlugin::BEGIN@21 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.27 at line 21 # spent 4µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@21 |
22 | 2 | 19µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::RenderPlugin::BEGIN@22 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.27 at line 22 # spent 4µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@22 |
23 | 2 | 67µs | 1 | 3µs | # spent 3µs within Foswiki::Plugins::RenderPlugin::BEGIN@23 which was called:
# once (3µs+0s) by Foswiki::Plugin::BEGIN@2.27 at line 23 # spent 3µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@23 |
24 | |||||
25 | 1 | 500ns | our $VERSION = '3.21'; | ||
26 | 1 | 300ns | our $RELEASE = '3.21'; | ||
27 | 1 | 200ns | our $SHORTDESCRIPTION = 'Render <nop>WikiApplications asynchronously'; | ||
28 | 1 | 100ns | our $NO_PREFS_IN_TOPIC = 1; | ||
29 | |||||
30 | 2 | 854µs | 2 | 77µs | # spent 43µs (9+34) within Foswiki::Plugins::RenderPlugin::BEGIN@30 which was called:
# once (9µs+34µs) by Foswiki::Plugin::BEGIN@2.27 at line 30 # spent 43µs making 1 call to Foswiki::Plugins::RenderPlugin::BEGIN@30
# spent 34µs making 1 call to constant::import |
31 | |||||
32 | ############################################################################### | ||||
33 | sub writeDebug { | ||||
34 | print STDERR '- RenderPlugin - '.$_[0]."\n" if TRACE; | ||||
35 | } | ||||
36 | |||||
37 | |||||
38 | ############################################################################### | ||||
39 | # spent 143µs (36+107) within Foswiki::Plugins::RenderPlugin::initPlugin which was called:
# once (36µs+107µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
40 | 1 | 2µs | my ($topic, $web, $user, $installWeb) = @_; | ||
41 | |||||
42 | 1 | 4µs | 1 | 30µs | Foswiki::Func::registerRESTHandler('tag', \&restTag, # spent 30µs making 1 call to Foswiki::Func::registerRESTHandler |
43 | authenticate => 0, | ||||
44 | validate => 0, | ||||
45 | http_allow => 'GET,POST', | ||||
46 | ); | ||||
47 | |||||
48 | 1 | 4µs | 1 | 24µs | Foswiki::Func::registerRESTHandler('template', \&restTemplate, # spent 24µs making 1 call to Foswiki::Func::registerRESTHandler |
49 | authenticate => 0, | ||||
50 | validate => 0, | ||||
51 | http_allow => 'GET,POST', | ||||
52 | ); | ||||
53 | |||||
54 | 1 | 4µs | 1 | 28µs | Foswiki::Func::registerRESTHandler('expand', \&restExpand, # spent 28µs making 1 call to Foswiki::Func::registerRESTHandler |
55 | authenticate => 0, | ||||
56 | validate => 0, | ||||
57 | http_allow => 'GET,POST', | ||||
58 | ); | ||||
59 | |||||
60 | 1 | 4µs | 1 | 26µs | Foswiki::Func::registerRESTHandler('render', \&restRender, # spent 26µs making 1 call to Foswiki::Func::registerRESTHandler |
61 | authenticate => 0, | ||||
62 | validate => 0, | ||||
63 | http_allow => 'GET,POST', | ||||
64 | ); | ||||
65 | |||||
66 | 1 | 6µs | return 1; | ||
67 | } | ||||
68 | |||||
69 | ############################################################################### | ||||
70 | sub restRender { | ||||
71 | my ($session, $subject, $verb) = @_; | ||||
72 | |||||
73 | my $query = Foswiki::Func::getCgiQuery(); | ||||
74 | my $theText = $query->param('text') || ''; | ||||
75 | |||||
76 | return ' ' unless $theText; # must return at least on char as we get a | ||||
77 | # premature end of script otherwise | ||||
78 | |||||
79 | my $theTopic = $query->param('topic') || $session->{topicName}; | ||||
80 | my $theWeb = $query->param('web') || $session->{webName}; | ||||
81 | my ($web, $topic) = Foswiki::Func::normalizeWebTopicName($theWeb, $theTopic); | ||||
82 | $web = Foswiki::Sandbox::untaint($web, \&Foswiki::Sandbox::validateWebName); | ||||
83 | $topic = Foswiki::Sandbox::untaint($topic, \&Foswiki::Sandbox::validateTopicName); | ||||
84 | |||||
85 | my $result = Foswiki::Func::expandCommonVariables($theText, $topic, $web) || ' '; | ||||
86 | $result = Foswiki::Func::renderText($result, $web); | ||||
87 | |||||
88 | my $contentType = $query->param("contenttype"); | ||||
89 | $session->writeCompletePage($result, undef, $contentType); | ||||
90 | |||||
91 | return; | ||||
92 | } | ||||
93 | |||||
94 | ############################################################################### | ||||
95 | sub restExpand { | ||||
96 | my ($session, $subject, $verb) = @_; | ||||
97 | |||||
98 | # get params | ||||
99 | my $query = Foswiki::Func::getCgiQuery(); | ||||
100 | my $theText = $query->param('text') || ''; | ||||
101 | |||||
102 | return ' ' unless $theText; # must return at least on char as we get a | ||||
103 | # premature end of script otherwise | ||||
104 | |||||
105 | my $theTopic = $query->param('topic') || $session->{topicName}; | ||||
106 | my $theWeb = $query->param('web') || $session->{webName}; | ||||
107 | my ($web, $topic) = Foswiki::Func::normalizeWebTopicName($theWeb, $theTopic); | ||||
108 | $web = Foswiki::Sandbox::untaint($web, \&Foswiki::Sandbox::validateWebName); | ||||
109 | $topic = Foswiki::Sandbox::untaint($topic, \&Foswiki::Sandbox::validateTopicName); | ||||
110 | |||||
111 | # and render it | ||||
112 | my $result = Foswiki::Func::expandCommonVariables($theText, $topic, $web) || ' '; | ||||
113 | |||||
114 | my $contentType = $query->param("contenttype"); | ||||
115 | $session->writeCompletePage($result, undef, $contentType); | ||||
116 | |||||
117 | return; | ||||
118 | } | ||||
119 | |||||
120 | ############################################################################### | ||||
121 | sub restTemplate { | ||||
122 | my ($session, $subject, $verb) = @_; | ||||
123 | |||||
124 | my $query = Foswiki::Func::getCgiQuery(); | ||||
125 | my $theTemplate = $query->param('name'); | ||||
126 | return '' unless $theTemplate; | ||||
127 | |||||
128 | my $theExpand = $query->param('expand'); | ||||
129 | return '' unless $theExpand; | ||||
130 | |||||
131 | my $theTopic = $query->param('topic') || $session->{topicName}; | ||||
132 | my $theWeb = $query->param('web') || $session->{webName}; | ||||
133 | my ($web, $topic) = Foswiki::Func::normalizeWebTopicName($theWeb, $theTopic); | ||||
134 | $web = Foswiki::Sandbox::untaint($web, \&Foswiki::Sandbox::validateWebName); | ||||
135 | $topic = Foswiki::Sandbox::untaint($topic, \&Foswiki::Sandbox::validateTopicName); | ||||
136 | |||||
137 | Foswiki::Func::loadTemplate($theTemplate); | ||||
138 | |||||
139 | require Foswiki::Attrs; | ||||
140 | my $attrs = new Foswiki::Attrs($theExpand); | ||||
141 | |||||
142 | my $tmpl = $session->templates->tmplP($attrs); | ||||
143 | |||||
144 | # and render it | ||||
145 | my $result = Foswiki::Func::expandCommonVariables($tmpl, $topic, $web) || ' '; | ||||
146 | |||||
147 | my $theRender = Foswiki::Func::isTrue(scalar $query->param('render'), 0); | ||||
148 | if ($theRender) { | ||||
149 | $result = Foswiki::Func::renderText($result, $web); | ||||
150 | } | ||||
151 | |||||
152 | my $contentType = $query->param("contenttype"); | ||||
153 | $session->writeCompletePage($result, undef, $contentType); | ||||
154 | |||||
155 | return; | ||||
156 | } | ||||
157 | |||||
158 | ############################################################################### | ||||
159 | sub restTag { | ||||
160 | my ($session, $subject, $verb) = @_; | ||||
161 | |||||
162 | #writeDebug("called restTag($subject, $verb)"); | ||||
163 | |||||
164 | # get params | ||||
165 | my $query = Foswiki::Func::getCgiQuery(); | ||||
166 | |||||
167 | my $theTag = $query->param('name') || 'INCLUDE'; | ||||
168 | my $theDefault = $query->param('param') || ''; | ||||
169 | my $theRender = $query->param('render') || 0; | ||||
170 | |||||
171 | $theRender = ($theRender =~ /^\s*(1|on|yes|true)\s*$/) ? 1:0; | ||||
172 | |||||
173 | my $theTopic = $query->param('topic') || $session->{topicName}; | ||||
174 | my $theWeb = $query->param('web') || $session->{webName}; | ||||
175 | my ($web, $topic) = Foswiki::Func::normalizeWebTopicName($theWeb, $theTopic); | ||||
176 | $web = Foswiki::Sandbox::untaint($web, \&Foswiki::Sandbox::validateWebName); | ||||
177 | $topic = Foswiki::Sandbox::untaint($topic, \&Foswiki::Sandbox::validateTopicName); | ||||
178 | |||||
179 | # construct parameters for tag | ||||
180 | my $params = $theDefault?'"'.$theDefault.'"':''; | ||||
181 | foreach my $key ($query->param()) { | ||||
182 | next if $key =~ /^(name|param|render|topic|XForms:Model)$/; | ||||
183 | my $value = $query->param($key); | ||||
184 | $params .= ' '.$key.'="'.$value.'" '; | ||||
185 | } | ||||
186 | |||||
187 | # create TML expression | ||||
188 | my $tml = '%'.$theTag; | ||||
189 | $tml .= '{'.$params.'}' if $params; | ||||
190 | $tml .= '%'; | ||||
191 | |||||
192 | #writeDebug("tml=$tml"); | ||||
193 | |||||
194 | # and render it | ||||
195 | my $result = Foswiki::Func::expandCommonVariables($tml, $topic, $web) || ' '; | ||||
196 | if ($theRender) { | ||||
197 | $result = Foswiki::Func::renderText($result, $web); | ||||
198 | } | ||||
199 | |||||
200 | #writeDebug("result=$result"); | ||||
201 | |||||
202 | my $contentType = $query->param("contenttype"); | ||||
203 | $session->writeCompletePage($result, undef, $contentType); | ||||
204 | |||||
205 | return; | ||||
206 | } | ||||
207 | |||||
208 | 1 | 4µs | 1; |