PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.6.0
Tracking Code Manager v2.6.0
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / admin / editor.php
tracking-code-manager / includes / admin Last commit date
AdminOptions.php 1 month ago editor.php 1 month ago manager.php 1 month ago metabox.php 1 month ago settings.php 1 month ago whatsnew.php 1 month ago
editor.php
317 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 function tcmp_notice_pro_features() {
4 global $tcmp;
5 ?>
6 <br/>
7 <div class="message updated below-h2 iwp">
8 <div style="height:10px;"></div>
9 <?php
10 $i = 1;
11 while ( $tcmp->lang->H( 'Notice.ProHeader' . $i ) ) {
12 $tcmp->lang->P( 'Notice.ProHeader' . $i );
13 echo '<br/>';
14 ++$i;
15 }
16 $i = 1;
17 ?>
18 <br/>
19 <?php
20
21 /*$options = array('public' => TRUE, '_builtin' => FALSE);
22 $q=get_post_types($options, 'names');
23 if(is_array($q) && count($q)>0) {
24 sort($q);
25 $q=implode(', ', $q);
26 $q='(<b>'.$q.'</b>)';
27 } else {
28 $q='';
29 }*/
30 $q = '';
31 while ( $tcmp->lang->H( 'Notice.ProFeature' . $i ) ) {
32 ?>
33 <div style="clear:both; margin-top: 2px;"></div>
34 <div style="float:left; vertical-align:middle; height:24px; margin-right:5px; margin-top:-5px;">
35 <img src="<?php echo TCMP_PLUGIN_IMAGES_URI; ?>tick.png" />
36 </div>
37 <div style="float:left; vertical-align:middle; height:24px;">
38 <?php $tcmp->lang->P( 'Notice.ProFeature' . $i, $q ); ?>
39 </div>
40 <?php
41 ++$i;
42 }
43 ?>
44 <div style="clear:both;"></div>
45 <div style="height:10px;"></div>
46 <div style="float:right;">
47 <?php
48 $url = TCMP_PAGE_PREMIUM . '?utm_source=free-users&utm_medium=wp-cta&utm_campaign=wp-plugin';
49 ?>
50 <a href="<?php echo esc_url( $url ); ?>" target="_blank">
51 <b><?php esc_html( $tcmp->lang->P( 'Notice.ProCTA' ) ); ?></b>
52 </a>
53 </div>
54 <div style="height:10px; clear:both;"></div>
55 </div>
56 <br/>
57 <?php
58 }
59 function tcmp_ui_editor_check( $snippet ) {
60 global $tcmp;
61
62 $snippet['trackMode'] = intval( $snippet['trackMode'] );
63 $snippet['trackPage'] = intval( $snippet['trackPage'] );
64
65 $snippet['includeEverywhereActive'] = 0;
66 if ( TCMP_TRACK_PAGE_ALL === $snippet['trackPage'] ) {
67 $snippet['includeEverywhereActive'] = 1;
68 }
69 $snippet = $tcmp->manager->sanitize( $snippet['id'], $snippet );
70
71 if ( '' === $snippet['name'] ) {
72 $tcmp->options->pushErrorMessage( 'Please enter a unique name' );
73 } else {
74 $exist = $tcmp->manager->exists( $snippet['name'] );
75 if ( $exist && $exist['id'] !== $snippet['id'] ) {
76 //nonostante il tutto il nome deve essee univoco
77 $tcmp->options->pushErrorMessage( 'You have entered a name that already exists. IDs are NOT case-sensitive' );
78 }
79 }
80 if ( '' === $snippet['code'] ) {
81 $tcmp->options->pushErrorMessage( 'Paste your HTML Tracking Code into the textarea' );
82 }
83
84 if ( TCMP_TRACK_MODE_CODE === $snippet['trackMode'] ) {
85
86 $types = $tcmp->utils->query( TCMP_QUERY_POST_TYPES );
87 if ( TCMP_TRACK_PAGE_SPECIFIC === $snippet['trackPage'] ) {
88 foreach ( $types as $v ) {
89 $include_active_key = 'includePostsOfType_' . $v['id'] . '_Active';
90 $include_array_key = 'includePostsOfType_' . $v['id'];
91 $except_active_key = 'exceptPostsOfType_' . $v['id'] . '_Active';
92 $except_array_key = 'exceptPostsOfType_' . $v['id'];
93
94 if ( 1 === $snippet[ $include_active_key ] && 1 === $snippet[ $except_active_key ] ) {
95 if ( in_array( -1, $snippet[ $include_array_key ] ) && in_array( -1, $snippet[ $except_array_key ] ) ) {
96 $tcmp->options->pushErrorMessage( 'Error.IncludeExcludeAll', $v['name'] );
97 }
98 }
99 if ( 1 === $snippet[ $include_active_key ] && 0 === count( $snippet[ $include_array_key ] ) ) {
100 $tcmp->options->pushErrorMessage( 'Error.IncludeSelectAtLeastOne', $v['name'] );
101 }
102 }
103
104 //second loop to respect the display order
105 foreach ( $types as $v ) {
106 $include_active_key = 'includePostsOfType_' . $v['id'] . '_Active';
107 $include_array_key = 'includePostsOfType_' . $v['id'];
108 $except_active_key = 'exceptPostsOfType_' . $v['id'] . '_Active';
109 $except_array_key = 'exceptPostsOfType_' . $v['id'];
110
111 if ( 1 === $snippet[ $include_active_key ] && in_array( -1, $snippet[ $include_array_key ] ) ) {
112 if ( 1 === $snippet[ $except_active_key ] && 0 === count( $snippet[ $except_array_key ] ) ) {
113 $tcmp->options->pushErrorMessage( 'Error.ExcludeSelectAtLeastOne', $v['name'] );
114 }
115 }
116 }
117 } else {
118 foreach ( $types as $v ) {
119 $except_active_key = 'exceptPostsOfType_' . $v['id'] . '_Active';
120 $except_array_key = 'exceptPostsOfType_' . $v['id'];
121
122 if ( isset( $snippet[ $except_active_key ] )
123 && 1 === $snippet[ $except_active_key ]
124 && 0 === count( $snippet[ $except_array_key ] ) ) {
125 $tcmp->options->pushErrorMessage( 'Error.ExcludeSelectAtLeastOne', $v['name'] );
126 }
127 }
128 }
129 }
130 }
131 function tcmp_ui_editor() {
132 global $tcmp;
133
134 $tcmp->form->prefix = 'Editor';
135 $id = tcmp_isqs( 'id', 0 );
136 if ( 0 === $id && $tcmp->manager->is_limit_reached( false ) ) {
137 $tcmp->utils->redirect( TCMP_TAB_MANAGER_URI );
138 }
139
140 $snippet = $tcmp->manager->get( $id, true );
141 if ( wp_verify_nonce( tcmp_qs( 'tcmp_nonce' ), 'tcmp_nonce' ) ) {
142 foreach ( $snippet as $k => $v ) {
143 $snippet[ $k ] = tcmp_qs( $k );
144 if ( is_string( $snippet[ $k ] ) ) {
145 $snippet[ $k ] = stripslashes( $snippet[ $k ] );
146 }
147 }
148
149 tcmp_ui_editor_check( $snippet );
150 if ( ! $tcmp->options->hasErrorMessages() ) {
151 $snippet = $tcmp->manager->put( $snippet['id'], $snippet );
152 $id = $snippet['id'];
153 $tcmp->utils->redirect( TCMP_PAGE_MANAGER . '&id=' . $id ); }
154 }
155 $tcmp->options->writeMessages();
156
157 $tcmp->form->form_starts();
158 $tcmp->form->hidden( 'id', $snippet );
159 $tcmp->form->hidden( 'order', $snippet );
160
161 $tcmp->form->checkbox( 'active', $snippet );
162 $tcmp->form->text( 'name', $snippet );
163 $tcmp->form->editor( 'code', $snippet );
164
165 $values = array( TCMP_POSITION_HEAD, TCMP_POSITION_BODY, TCMP_POSITION_FOOTER );
166 $tcmp->form->dropdown( 'position', $snippet, $values, false );
167 $values = array( TCMP_DEVICE_TYPE_ALL, TCMP_DEVICE_TYPE_DESKTOP, TCMP_DEVICE_TYPE_MOBILE, TCMP_DEVICE_TYPE_TABLET );
168 $tcmp->form->dropdown( 'deviceType', $snippet, $values, true );
169
170 $args = array( 'id' => 'box-track-mode' );
171 $tcmp->form->div_starts( $args );
172 {
173 $tcmp->form->p( 'Where do you want to add this code?' );
174 $tcmp->form->radio( 'trackMode', $snippet['trackMode'], TCMP_TRACK_MODE_CODE );
175 $plugins = $tcmp->ecommerce->getActivePlugins();
176 if ( 0 === count( $plugins ) ) {
177 $plugins = array(
178 'Ecommerce' => array(
179 'name' => 'Ecommerce',
180 'id' => TCMP_PLUGINS_NO_PLUGINS,
181 'version' => '',
182 ),
183 );
184 }
185 $tcmp->form->tag_new = true;
186 foreach ( $plugins as $k => $v ) {
187 $ecommerce = $v['name'];
188 if ( isset( $v['version'] ) && '' !== $v['version'] ) {
189 $ecommerce .= ' (v.' . $v['version'] . ')';
190 }
191 $args = array( 'label' => $tcmp->lang->L( 'Editor.trackMode_1', $ecommerce ) );
192 $tcmp->form->radio( 'trackMode', $snippet['trackMode'], $v['id'], $args );
193 }
194 $tcmp->form->tag_new = false;
195
196 }
197 $tcmp->form->div_ends();
198
199 $args = array( 'id' => 'box-track-conversion' );
200 $tcmp->form->div_starts( $args );
201 {
202 $tcmp->form->p( 'ConversionProductQuestion' );
203 ?>
204 <p style="font-style: italic;"><?php $tcmp->lang->P( 'Editor.PositionBlocked' ); ?></p>
205 <?php
206 foreach ( $plugins as $k => $v ) {
207 $args = array(
208 'id' => 'box-track-conversion-' . $v['id'],
209 'class' => 'box-track-conversion',
210 );
211 $tcmp->form->div_starts( $args );
212 {
213 if ( TCMP_PLUGINS_NO_PLUGINS === $v['id'] ) {
214 $plugins = $tcmp->ecommerce->getPlugins( false );
215 $ecommerce = '';
216 foreach ( $plugins as $k => $v ) {
217 if ( '' !== $ecommerce ) {
218 $ecommerce .= ', ';
219 }
220 $ecommerce .= $k;
221 }
222 $tcmp->options->pushErrorMessage( 'Editor.NoEcommerceFound', $ecommerce );
223 $tcmp->options->writeMessages();
224 } else {
225 $post_type = $tcmp->ecommerce->getCustomPostType( $v['id'] );
226 $key_active = 'CTC_' . $v['id'] . '_Active';
227 $label = $tcmp->lang->L( 'Editor.EcommerceCheck', $v['name'], $v['version'] );
228
229 if ( '' != $post_type ) {
230 $args = array(
231 'post_type' => $post_type,
232 'all' => true,
233 );
234 $values = $tcmp->utils->query( TCMP_QUERY_POSTS_OF_TYPE, $args );
235 $key_array = 'CTC_' . $v['id'] . '_ProductsIds';
236 if ( 0 === count( $snippet[ $key_array ] ) ) {
237 //when enabled default selected -1
238 $snippet[ $key_array ] = array( -1 );
239 }
240
241 $args = array(
242 'label' => $label,
243 'class' => 'tcmp-select tcmLineTags',
244 );
245 $tcmp->form->labels = false;
246 $tcmp->form->dropdown( $key_array, $snippet[ $key_array ], $values, true, $args );
247 $tcmp->form->labels = true;
248 } else {
249 $args = array( 'label' => $label );
250 $tcmp->form->checkbox( $key_active, $snippet[ $key_active ], 1, $args );
251 }
252 }
253 }
254 $tcmp->form->div_ends();
255
256 $tcmp->form->br();
257 $tcmp->form->i( 'ConversionDynamicFields' );
258 $tcmp->form->br();
259 $tcmp->form->br();
260 }
261 }
262 $tcmp->form->div_ends();
263
264 $args = array( 'id' => 'box-track-code' );
265 $tcmp->form->div_starts( $args );
266 {
267 $tcmp->form->p( 'In which page do you want to insert this code?' );
268 $tcmp->form->radio( 'trackPage', $snippet['trackPage'], TCMP_TRACK_PAGE_ALL );
269 $tcmp->form->radio( 'trackPage', $snippet['trackPage'], TCMP_TRACK_PAGE_SPECIFIC );
270
271 //, 'style'=>'margin-top:10px;'
272 $args = array( 'id' => 'tcmp-include-div' );
273 $tcmp->form->div_starts( $args );
274 {
275 $tcmp->form->p( 'Include tracking code in which pages?' );
276 tcmp_form_options( 'include', $snippet );
277 }
278 $tcmp->form->div_ends();
279
280 $args = array( 'id' => 'tcmp-except-div' );
281 $tcmp->form->div_starts( $args );
282 {
283 $tcmp->form->p( 'Do you want to exclude some specific pages?' );
284 tcmp_form_options( 'except', $snippet );
285 }
286 $tcmp->form->div_ends();
287 }
288 $tcmp->form->div_ends();
289
290 $tcmp->form->nonce( 'tcmp_nonce', 'tcmp_nonce' );
291 tcmp_notice_pro_features();
292 $tcmp->form->submit( 'Save' );
293 $tcmp->form->form_ends();
294 }
295
296 function tcmp_form_options( $prefix, $snippet ) {
297 global $tcmp;
298
299 $types = $tcmp->utils->query( TCMP_QUERY_POST_TYPES );
300 foreach ( $types as $v ) {
301 $args = array(
302 'post_type' => $v['id'],
303 'all' => true,
304 );
305 $values = $tcmp->utils->query( TCMP_QUERY_POSTS_OF_TYPE, $args );
306 //$tcmp->form->premium=!in_array($v['name'], array('post', 'page'));
307
308 $key_active = $prefix . 'PostsOfType_' . $v['id'] . '_Active';
309 $key_array = $prefix . 'PostsOfType_' . $v['id'];
310 if ( 0 === $snippet[ $key_active ] && 0 === count( $snippet[ $key_array ] ) && 'except' != $prefix ) {
311 //when enabled default selected -1
312 $snippet[ $key_array ] = array( -1 );
313 }
314 $tcmp->form->check_select( $key_active, $key_array, $snippet, $values );
315 }
316 }
317