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