Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Embedder/PHP.pm |
Statements | Executed 15 statements in 5.71ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 18.1ms | 21.0ms | BEGIN@20 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 96µs | 372µs | BEGIN@8 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 62µs | 243µs | BEGIN@23 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 55µs | 88µs | BEGIN@10 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 54µs | 282µs | BEGIN@26 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 53µs | 143µs | BEGIN@9 | RTP::Webmerge::Embedder::PHP::
1 | 1 | 1 | 27µs | 27µs | BEGIN@15 | RTP::Webmerge::Embedder::PHP::
0 | 0 | 0 | 0s | 0s | embedder | RTP::Webmerge::Embedder::PHP::
0 | 0 | 0 | 0s | 0s | is_enabled | RTP::Webmerge::Embedder::PHP::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ################################################################################################### | ||||
2 | # Copyright 2013 by Marcel Greter | ||||
3 | # This file is part of Webmerge (GPL3) | ||||
4 | ################################################################################################### | ||||
5 | package RTP::Webmerge::Embedder::PHP; | ||||
6 | ################################################################################################### | ||||
7 | |||||
8 | 2 | 170µs | 2 | 649µs | # spent 372µs (96+276) within RTP::Webmerge::Embedder::PHP::BEGIN@8 which was called:
# once (96µs+276µs) by RTP::Webmerge::Embedder::BEGIN@253 at line 8 # spent 372µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@8
# spent 276µs making 1 call to Exporter::import |
9 | 2 | 144µs | 2 | 233µs | # spent 143µs (53+90) within RTP::Webmerge::Embedder::PHP::BEGIN@9 which was called:
# once (53µs+90µs) by RTP::Webmerge::Embedder::BEGIN@253 at line 9 # spent 143µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@9
# spent 90µs making 1 call to strict::import |
10 | 2 | 196µs | 2 | 122µs | # spent 88µs (55+33) within RTP::Webmerge::Embedder::PHP::BEGIN@10 which was called:
# once (55µs+33µs) by RTP::Webmerge::Embedder::BEGIN@253 at line 10 # spent 88µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@10
# spent 34µs making 1 call to warnings::import |
11 | |||||
12 | ################################################################################################### | ||||
13 | |||||
14 | # define our version string | ||||
15 | 1 | 504µs | 1 | 27µs | # spent 27µs within RTP::Webmerge::Embedder::PHP::BEGIN@15 which was called:
# once (27µs+0s) by RTP::Webmerge::Embedder::BEGIN@253 at line 15 # spent 27µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@15 |
16 | |||||
17 | ################################################################################################### | ||||
18 | |||||
19 | # use module to dump php data | ||||
20 | 2 | 716µs | 2 | 21.3ms | # spent 21.0ms (18.1+2.91) within RTP::Webmerge::Embedder::PHP::BEGIN@20 which was called:
# once (18.1ms+2.91ms) by RTP::Webmerge::Embedder::BEGIN@253 at line 20 # spent 21.0ms making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@20
# spent 311µs making 1 call to Exporter::import |
21 | |||||
22 | # load our local modules | ||||
23 | 2 | 287µs | 2 | 424µs | # spent 243µs (62+181) within RTP::Webmerge::Embedder::PHP::BEGIN@23 which was called:
# once (62µs+181µs) by RTP::Webmerge::Embedder::BEGIN@253 at line 23 # spent 243µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@23
# spent 181µs making 1 call to Exporter::import |
24 | |||||
25 | # end of line in code | ||||
26 | 2 | 3.66ms | 2 | 510µs | # spent 282µs (54+228) within RTP::Webmerge::Embedder::PHP::BEGIN@26 which was called:
# once (54µs+228µs) by RTP::Webmerge::Embedder::BEGIN@253 at line 26 # spent 282µs making 1 call to RTP::Webmerge::Embedder::PHP::BEGIN@26
# spent 228µs making 1 call to constant::import |
27 | |||||
28 | ################################################################################################### | ||||
29 | |||||
30 | sub is_enabled ($) | ||||
31 | { | ||||
32 | return 0 unless (defined $_[0]); | ||||
33 | return 1 if (lc $_[0] eq 'true'); | ||||
34 | return 1 if (lc $_[0] eq 'enabled'); | ||||
35 | return 0; | ||||
36 | } | ||||
37 | |||||
38 | sub embedder | ||||
39 | { | ||||
40 | |||||
41 | # get variables and collections from parent | ||||
42 | my ($domains, $contents, $features, $detects, $config) = @_; | ||||
43 | |||||
44 | # create switcher code | ||||
45 | my $switcher = ''; | ||||
46 | |||||
47 | # process all header detect entries | ||||
48 | foreach my $detect (@{$detects || [] }) | ||||
49 | { | ||||
50 | |||||
51 | # get options for this detection | ||||
52 | my $target = $detect->{'target'}; | ||||
53 | my $enabled = $detect->{'enabled'}; | ||||
54 | my $disabled = $detect->{'disabled'}; | ||||
55 | |||||
56 | unless ( defined $detect->{'feature'} ) | ||||
57 | { die 'detect without feature id found'; } | ||||
58 | |||||
59 | my $id = $detect->{'feature'}; | ||||
60 | my $feature = $features->{$id}; | ||||
61 | |||||
62 | unless ($feature || is_enabled($detect->{'optional'})) | ||||
63 | { die "feature detection <$id> not available"; } | ||||
64 | |||||
65 | $switcher .= ' ' . ' // default feature setting' . EOL; | ||||
66 | $switcher .= ' ' . '$enabled = NULL;' . EOL; | ||||
67 | |||||
68 | # process all header detect entries | ||||
69 | foreach my $test (@{$feature->{'test'} || [] }) | ||||
70 | { | ||||
71 | |||||
72 | my $types = lc $test->{'type'}; | ||||
73 | |||||
74 | foreach my $type (split(/\s*,\s*/, $types)) | ||||
75 | { | ||||
76 | |||||
77 | my $var; | ||||
78 | |||||
79 | unless (defined $type) { $var = '$_SERVER'; } | ||||
80 | elsif ($type eq 'env') { $var = '$_ENV'; } | ||||
81 | elsif ($type eq 'get') { $var = '$_GET'; } | ||||
82 | elsif ($type eq 'post') { $var = '$_POST'; } | ||||
83 | elsif ($type eq 'server') { $var = '$_SERVER'; } | ||||
84 | elsif ($type eq 'cookie') { $var = '$_COOKIE'; } | ||||
85 | elsif ($type eq 'session') { $var = '$_SESSION'; } | ||||
86 | elsif ($type eq 'request') { $var = '$_REQUEST'; } | ||||
87 | else { die "Fatal: unknown test type <$type>"; } | ||||
88 | |||||
89 | my ($enabled, $disabled) = ('true', 'false'); | ||||
90 | |||||
91 | if (exists $test->{'enable'} && scalar(@{$test->{'enable'}})) | ||||
92 | { | ||||
93 | $enabled = 'preg_match(\'/^(?:' | ||||
94 | . join( '|', @{$test->{'enable'}} ) | ||||
95 | . ')$/\', ' . $var . '[\'' . $test->{'key'} . '\'])'; | ||||
96 | } | ||||
97 | |||||
98 | if (exists $test->{'disable'} && scalar(@{$test->{'disable'}})) | ||||
99 | { | ||||
100 | $disabled = 'preg_match(\'/^(?:' | ||||
101 | . join( '|', @{$test->{'disable'}} ) | ||||
102 | . ')$/\', ' . $var . '[\'' . $test->{'key'} . '\'])'; | ||||
103 | } | ||||
104 | |||||
105 | $switcher .= EOL; | ||||
106 | $switcher .= ' ' . ' // sniff for useragent' . EOL; | ||||
107 | $switcher .= ' ' . 'if (array_key_exists(\'' . $test->{'key'} . '\', ' . $var . ')) {' . EOL; | ||||
108 | $switcher .= ' ' . '$enabled = ( $enabled || ( ' . $enabled . ' )) && ! ' . $disabled . ';' . EOL; | ||||
109 | $switcher .= ' ' . '}' . EOL; | ||||
110 | |||||
111 | } | ||||
112 | |||||
113 | } | ||||
114 | |||||
115 | $switcher .= EOL; | ||||
116 | $switcher .= ' ' . ' // change ' . $target . ' if feature is enabled' . EOL; | ||||
117 | $switcher .= ' ' . 'if ($enabled === TRUE) { $' . $target .' = \'' . $enabled . '\'; }'. EOL if (defined $enabled); | ||||
118 | $switcher .= ' ' . 'if ($enabled === FALSE) { $' . $target .' = \'' . $disabled . '\'; }'. EOL if (defined $disabled); | ||||
119 | |||||
120 | }; | ||||
121 | # EO each detect | ||||
122 | |||||
123 | # load the template (readfile will resolve path) | ||||
124 | my $tmpl = readfile($config->{'tmpl-embed-php'}); | ||||
125 | |||||
126 | # create data for template | ||||
127 | my %data = | ||||
128 | ( | ||||
129 | 'switcher' => $switcher, | ||||
130 | 'includes' => dump_php($domains), | ||||
131 | ); | ||||
132 | |||||
133 | # insert data into loaded template | ||||
134 | ${$tmpl} =~ s/%%([a-z]+)%%/$data{$1}/eg; | ||||
135 | |||||
136 | # return tmpl pointer | ||||
137 | return $tmpl; | ||||
138 | |||||
139 | } | ||||
140 | # EO sub embedder | ||||
141 | |||||
142 | ################################################################################################### | ||||
143 | |||||
144 | # register this embedder type to parent module | ||||
145 | 1 | 20µs | 1 | 33µs | RTP::Webmerge::Embedder::register('php', \&embedder); # spent 33µs making 1 call to RTP::Webmerge::Embedder::register |
146 | |||||
147 | ################################################################################################### | ||||
148 | ################################################################################################### | ||||
149 | 1 | 17µs | 1; |