PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.8.0
Tracking Code Manager v2.8.0
2.8.0 2.7.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 / classes / ui / Form.php
tracking-code-manager / includes / classes / ui Last commit date
Check.php 1 month ago Form.php 1 month ago Tabs.php 1 month ago
Form.php
490 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class TCMP_Form {
8 var $prefix = 'Form';
9 var $labels = true;
10 var $left_labels = true;
11 var $newline;
12
13 var $tags = true;
14 var $only_premium = true;
15 var $left_tags = false;
16 var $premium = false;
17 var $tag_new = false;
18
19 public function __construct() {
20 }
21
22 //args can be a string or an associative array if you want
23 private function get_text_args( $args, $defaults, $excludes = array() ) {
24 $result = $args;
25
26 if ( is_string( $excludes ) ) {
27 $excludes = explode( ',', $excludes );
28 }
29
30 if ( is_array( $result ) && count( $result ) > 0 ) {
31 $result = '';
32 foreach ( $args as $k => $v ) {
33 if ( 0 == count( $excludes ) || ! in_array( $k, $excludes, false ) ) {
34 $result .= ' ' . $k . '="' . $v . '"';
35 }
36 }
37 } elseif ( ! $args ) {
38 $result = '';
39 }
40 if ( is_array( $defaults ) && count( $defaults ) > 0 ) {
41 foreach ( $defaults as $k => $v ) {
42 if ( 0 == count( $excludes ) || ! in_array( $k, $excludes, false ) ) {
43 if ( false == stripos( $result, $k . '=' ) ) {
44 $result .= ' ' . $k . '="' . $v . '"';
45 }
46 }
47 }
48 }
49 return $result;
50 }
51
52 public function tag( $override_premium = false ) {
53 if ( ! $this->tags || ! $this->tag_new ) {
54 return;
55 }
56 ?>
57 <div style="float:left;" class="tcmp-tag tcmp-tag-free">NEW!</div>
58 <?php
59 }
60
61 public function label( $name, $options = '' ) {
62 global $tcmp;
63 $defaults = array( 'class' => '' );
64 $other_text = $this->get_text_args( $options, $defaults, array( 'label', 'id' ) );
65
66 $k = $this->prefix . '.' . $name;
67 if ( ! is_array( $options ) ) {
68 $options = array();
69 }
70 if ( isset( $options['label'] ) && $options['label'] ) {
71 $k = $options['label'];
72 }
73
74 $label = $tcmp->lang->L( $k );
75 $for = ( isset( $options['id'] ) ? $options['id'] : $name );
76
77 //check if is a mandatory field by checking the .txt language file
78 $k = $this->prefix . '.' . $name . '.check';
79 if ( $tcmp->lang->H( $k ) ) {
80 $label .= ' (*)';
81 }
82
83 $a_class = '';
84
85 ?>
86 <label for="<?php echo esc_attr( $for ); ?>" <?php echo wp_kses_post( $other_text ); ?> >
87 <?php
88 if ( $this->left_tags ) {
89 $this->tag();
90 }
91 ?>
92 <span style="float:left; margin-right:5px;" class="<?php echo esc_attr( $a_class ); ?>"><?php echo wp_kses_post( $label ); ?></span>
93 <?php
94 if ( ! $this->left_tags ) {
95 $this->tag();
96 }
97 ?>
98 </label>
99 <?php
100 }
101
102 public function left_input( $name, $options = '' ) {
103 if ( ! $this->labels ) {
104 return;
105 }
106 if ( $this->left_labels ) {
107 $this->label( $name, $options );
108 }
109
110 if ( $this->newline ) {
111 $this->newline();
112 }
113 }
114
115 public function newline() {
116 ?>
117 <div class="tcmp-form-newline"></div>
118 <?php
119 }
120
121 public function right_input( $name, $args = '' ) {
122 if ( ! $this->labels ) {
123 return;
124 }
125 if ( ! $this->left_labels ) {
126 $this->label( $name, $args );
127 }
128 $this->newline();
129 }
130
131 public function form_starts( $method = 'post', $action = '', $args = null ) {
132 $defaults = array( 'class' => 'tcmp-form' );
133 $other = $this->get_text_args( $args, $defaults );
134 ?>
135 <form method="<?php echo esc_attr( $method ); ?>" action="<?php echo esc_attr( $action ); ?>" <?php echo wp_kses( $other, array() ); ?> >
136 <?php
137 }
138
139 public function form_ends() {
140 ?>
141 </form>
142 <?php
143 }
144
145 public function div_starts( $args = array() ) {
146 $defaults = array();
147 $other = $this->get_text_args( $args, $defaults );
148 ?>
149 <div <?php echo wp_kses( $other, array() ); ?>>
150 <?php
151 }
152 public function div_ends() {
153 ?>
154 </div>
155 <div style="clear:both;"></div>
156 <?php
157 }
158
159 public function p( $message, $v1 = null, $v2 = null, $v3 = null, $v4 = null, $v5 = null ) {
160 global $tcmp;
161 ?>
162 <p style="font-weight:bold;">
163 <?php
164 $tcmp->lang->P( $message, $v1, $v2, $v3, $v4, $v5 );
165 if ( $tcmp->lang->H( $message . 'Subtitle' ) ) {
166 ?>
167 <br/>
168 <span style="font-weight:normal;">
169 <?php $tcmp->lang->P( $message . 'Subtitle', $v1, $v2, $v3, $v4, $v5 ); ?>
170 </span>
171 <?php } ?>
172 </p>
173 <?php
174 }
175 public function i( $message, $v1 = null, $v2 = null, $v3 = null, $v4 = null, $v5 = null ) {
176 global $tcmp;
177 ?>
178 <i><?php $tcmp->lang->P( $message, $v1, $v2, $v3, $v4, $v5 ); ?></i>
179 <?php
180 }
181
182 public function editor( $name, $value = '', $options = null ) {
183 global $tcmp;
184
185 $defaults = array(
186 'editor' => 'html',
187 'theme' => 'monokai',
188 'ui-visible' => '',
189 'height' => 350,
190 'width' => 700,
191 );
192 $options = $tcmp->utils->parseArgs( $options, $defaults );
193 $value = $tcmp->utils->get( $value, $name, $value );
194
195 $args = array(
196 'class' => 'tcmp-label',
197 'style' => 'width:auto;',
198 );
199 $this->newline = true;
200 $this->left_input( $name, $args );
201
202 $id = $name;
203 switch ( $options['editor'] ) {
204 case 'wp':
205 case 'WordPress':
206 $settings = array(
207 'wpautop' => true,
208 'media_buttons' => true,
209 'drag_drop_upload' => false,
210 'editor_height' => $options['height'],
211 );
212 wp_editor( $value, $id, $settings );
213 break;
214 case 'html':
215 case 'text':
216 case 'javascript':
217 case 'css':
218 $ace = 'ACE_' . $id;
219 $text = $value;
220 $text = str_replace( '<', '&lt;', $text );
221 $text = str_replace( '>', '&gt;', $text );
222 ?>
223 <div id="<?php echo esc_attr( $id ); ?>Ace" style="height:<?php echo esc_attr( $options['height'] ) + 50; ?>px; width: <?php echo esc_attr( $options['width'] ); ?>px;"><?php echo esc_html( $text ); ?></div>
224 <textarea id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $id ); ?>" ui-visible="<?php echo esc_attr( $options['ui-visible'] ); ?>" style="display: none;"></textarea>
225
226 <?php
227 break;
228 }
229 $this->newline = false;
230 $this->right_input( $name, $args );
231 }
232
233 public function textarea( $name, $value = '', $args = null ) {
234 if ( is_array( $value ) && isset( $value[ $name ] ) ) {
235 $value = $value[ $name ];
236 }
237 $defaults = array(
238 'rows' => 10,
239 'class' => 'tcmp-textarea',
240 );
241 $other = $this->get_text_args( $args, $defaults );
242
243 $args = array(
244 'class' => 'tcmp-label',
245 'style' => 'width:auto;',
246 );
247 $this->newline = true;
248 $this->left_input( $name, $args );
249 ?>
250 <textarea dir="ltr" dirname="ltr" id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php echo wp_kses( $other, array() ); ?> ><?php echo wp_kses_post( $value ); ?></textarea>
251 <?php
252 $this->newline = false;
253 $this->right_input( $name, $args );
254 }
255
256 public function number( $name, $value = '', $options = null ) {
257 if ( ! $options ) {
258 $options = array();
259 }
260 $options['type'] = 'number';
261 $options['autocomplete'] = 'off';
262 $options['style'] = 'width:100px;';
263 if ( ! isset( $options['min'] ) ) {
264 $options['min'] = 0;
265 }
266
267 return $this->text( $name, $value, $options );
268 }
269
270 public function text( $name, $value = '', $options = null ) {
271 if ( is_array( $value ) && isset( $value[ $name ] ) ) {
272 $value = $value[ $name ];
273 }
274
275 $type = 'text';
276 if ( isset( $options['type'] ) ) {
277 $type = $options['type'];
278 }
279
280 $defaults = array( 'class' => 'tcmp-' . $type );
281 $other = $this->get_text_args( $options, $defaults, 'type' );
282
283 $args = array( 'class' => 'tcmp-label' );
284 $this->left_input( $name, $args );
285 ?>
286 <input type="<?php echo esc_attr( $type ); ?>" id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php echo wp_kses( $other, array() ); ?> />
287 <?php
288 $this->right_input( $name, $args );
289 }
290
291 public function hidden( $name, $value = '', $args = null ) {
292 if ( is_array( $value ) && isset( $value[ $name ] ) ) {
293 $value = $value[ $name ];
294 }
295 $defaults = array();
296 $other = $this->get_text_args( $args, $defaults );
297 ?>
298 <input type="hidden" id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php echo wp_kses( $other, array() ); ?> />
299 <?php
300 }
301
302 public function nonce( $action = -1, $name = '_wpnonce', $referer = true, $echo = true ) {
303 wp_nonce_field( $action, $name, $referer, $echo );
304 }
305
306 public function dropdown( $name, $value, $options, $multiple = false, $args = null ) {
307 global $tcmp;
308 if ( is_array( $value ) && isset( $value[ $name ] ) ) {
309 $value = $value[ $name ];
310 }
311 $defaults = array( 'class' => 'tcmp-select tcmTags tcmp-dropdown' );
312 $other = $this->get_text_args( $args, $defaults );
313
314 if ( ! is_array( $value ) ) {
315 $value = array( $value );
316 }
317 if ( is_string( $options ) ) {
318 $options = explode( ',', $options );
319 }
320 if ( is_array( $options ) && count( $options ) > 0 ) {
321 if ( ! isset( $options[0]['id'] ) ) {
322 //this is a normal array so I use the values for "id" field and the "name" into the txt file
323 $temp = array();
324 foreach ( $options as $v ) {
325 $temp[] = array(
326 'id' => $v,
327 'name' => $tcmp->lang->L( $this->prefix . '.' . $name . '.' . $v ),
328 );
329 }
330 $options = $temp;
331 }
332 }
333
334 echo '<div id="' . esc_attr( $name ) . '-box">';
335 $args = array( 'class' => 'tcmp-label' );
336 $this->left_input( $name, $args );
337 ?>
338 <select id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?><?php echo ( $multiple ? '[]' : '' ); ?>" <?php echo ( $multiple ? 'multiple' : '' ); ?> <?php echo wp_kses( $other, array() ); ?> >
339 <?php
340 foreach ( $options as $v ) {
341 $selected = '';
342 if ( in_array( $v['id'], $value, false ) ) {
343 $selected = ' selected="selected"';
344 }
345 ?>
346 <option value="<?php echo esc_attr( $v['id'] ); ?>" <?php echo wp_kses( $selected, array() ); ?>><?php echo esc_html( $v['name'] ); ?></option>
347 <?php } ?>
348 </select>
349 <?php
350 $this->right_input( $name, $args );
351 echo '</div>';
352 }
353
354 public function br() {
355 ?>
356 <br/>
357 <?php
358 }
359
360 public function submit( $value = '', $args = null ) {
361 global $tcmp;
362 $defaults = array();
363 $other = $this->get_text_args( $args, $defaults );
364 if ( '' == $value ) {
365 $value = 'Send';
366 }
367 $this->newline();
368 ?>
369 <input type="submit" class="button-primary tcmp-button tcmp-submit" value="<?php $tcmp->lang->P( $value ); ?>" <?php echo wp_kses( $other, array() ); ?>/>
370 <?php
371 }
372
373 public function delete( $id, $action = 'delete', $args = null ) {
374 global $tcmp;
375 $defaults = array();
376 $other = $this->get_text_args( $args, $defaults );
377 ?>
378 <?php $delete_url = TCMP_TAB_MANAGER_URI . '&action=' . rawurlencode( $action ) . '&id=' . rawurlencode( $id ) . '&tcmp_nonce=' . wp_create_nonce( 'tcmp_delete' ); ?>
379 <input type="button" class="button tcmp-button" value="<?php $tcmp->lang->P( 'Delete?' ); ?>" onclick="if (confirm('<?php $tcmp->lang->P( 'Question.DeleteQuestion' ); ?>') ) window.location='<?php echo esc_url( $delete_url ); ?>';" <?php echo wp_kses( $other, array() ); ?> />
380 &nbsp;
381 <?php
382 }
383
384 public function radio( $name, $current = 1, $value = 1, $options = null ) {
385 if ( ! is_array( $options ) ) {
386 $options = array();
387 }
388 $options['radio'] = true;
389 $options['id'] = $name . '_' . $value;
390 return $this->checkbox( $name, $current, $value, $options );
391 }
392 public function checkbox( $name, $current = 1, $value = 1, $options = null ) {
393 global $tcmp;
394 if ( is_array( $current ) && isset( $current[ $name ] ) ) {
395 $current = $current[ $name ];
396 }
397
398 if ( ! is_array( $options ) ) {
399 $options = array();
400 }
401
402 $label = $name;
403 $type = 'checkbox';
404 if ( isset( $options['radio'] ) && $options['radio'] ) {
405 $type = 'radio';
406 $label .= '_' . $value;
407 }
408
409 $defaults = array(
410 'class' => 'tcmp-checkbox',
411 'style' => 'margin:0px; margin-right:4px;',
412 'id' => $name,
413 );
414 $other = $this->get_text_args( $options, $defaults, array( 'radio', 'label' ) );
415 $prev = $this->left_labels;
416 $this->left_labels = false;
417
418 $label = ( isset( $options['label'] ) ? $options['label'] : $this->prefix . '.' . $label );
419 $id = ( isset( $options['id'] ) ? $options['id'] : $name );
420 $options = array(
421 'class' => '',
422 'style' => 'margin-top:-1px;',
423 'label' => $label,
424 'id' => $id,
425 );
426 $this->left_input( $name, $options );
427 ?>
428 <input type="<?php echo esc_attr( $type ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php echo( $current == $value ? 'checked="checked"' : '' ); ?> <?php echo wp_kses( $other, array() ); ?> >
429 <?php
430 $this->right_input( $name, $options );
431 $this->left_labels = $prev;
432 }
433
434 public function check_text( $name_active, $name_text, $value ) {
435 global $tcmp;
436
437 $args = array(
438 'class' => 'tcmp-hideShow tcmp-checkbox',
439 'tcmp-hideIfTrue' => 'false',
440 'tcmp-hideShow' => $name_text . 'Text',
441 );
442 $this->checkbox( $name_active, $value, 1, $args );
443 if ( $this->premium ) {
444 return;
445 }
446 ?>
447 <div id="<?php echo esc_attr( $name_text ); ?>Text" style="float:left;">
448 <?php
449 $prev = $this->labels;
450 $this->labels = false;
451 $args = array();
452 $this->text( $name_text, $value, $args );
453 $this->labels = $prev;
454 ?>
455 </div>
456 <?php
457 }
458
459 //create a checkbox with a left select visible only when the checkbox is selected
460 public function check_select( $name_active, $name_array, $value, $values, $options = null ) {
461 global $tcmp;
462 ?>
463 <div id="<?php echo esc_attr( $name_array ); ?>Box" style="float:left;">
464 <?php
465 $defaults = array(
466 'class' => 'tcmp-hideShow tcmp-checkbox',
467 'tcmp-hideIfTrue' => 'false',
468 'tcmp-hideShow' => $name_array . 'Tags',
469 );
470 $options = $tcmp->utils->parseArgs( $options, $defaults );
471 $this->checkbox( $name_active, $value, 1, $options );
472 /*if(!$this->premium || $tcmp->License->hasPremium()) { ?>*/
473 if ( true ) {
474 ?>
475 <div id="<?php echo esc_attr( $name_array ); ?>Tags" style="float:left;">
476 <?php
477 $prev = $this->labels;
478 $this->labels = false;
479 $options = array( 'class' => 'tcmp-select tcmLineTags' );
480 $this->dropdown( $name_array, $value, $values, true, $options );
481 $this->labels = $prev;
482 ?>
483 </div>
484 <?php } ?>
485 </div>
486 <?php
487 $this->newline();
488 }
489 }
490