PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.2
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / custom-field-types / class-wpsc-cf-url.php

class-wpsc-cf-url.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.2, at includes/custom-field-types/class-wpsc-cf-url.php

1,456 lines 43.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_CF_URL' ) ) :
7
8 final class WPSC_CF_URL {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'cf_url';
16
17 /**
18 * Set whether this custom field type is of type date
19 *
20 * @var boolean
21 */
22 public static $is_date = false;
23
24 /**
25 * Set whether this custom field type has applicable to date range
26 *
27 * @var boolean
28 */
29 public static $has_date_range = false;
30
31 /**
32 * Set whether this custom field type has multiple values
33 *
34 * @var boolean
35 */
36 public static $has_multiple_val = false;
37
38 /**
39 * Data type for column created in tickets table
40 *
41 * @var string
42 */
43 public static $data_type = 'TEXT NULL DEFAULT NULL';
44
45 /**
46 * Set whether this custom field type has reference to other class
47 *
48 * @var boolean
49 */
50 public static $has_ref = false;
51
52 /**
53 * Reference class for this custom field type so that its value(s) return with object or array of objects automatically. Empty string indicate no reference.
54 *
55 * @var string
56 */
57 public static $ref_class = '';
58
59 /**
60 * Set whether this custom field field type is system default (no fields can be created from it).
61 *
62 * @var boolean
63 */
64 public static $is_default = false;
65
66 /**
67 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
68 *
69 * @var boolean
70 */
71 public static $has_extra_info = true;
72
73 /**
74 * Set whether this custom field type can accept personal info.
75 *
76 * @var boolean
77 */
78 public static $has_personal_info = true;
79
80 /**
81 * Set whether fields created from this custom field type is allowed in create ticket form
82 *
83 * @var boolean
84 */
85 public static $is_ctf = true;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket list
89 *
90 * @var boolean
91 */
92 public static $is_list = true;
93
94 /**
95 * Set whether fields created from this custom field type is allowed in ticket filter
96 *
97 * @var boolean
98 */
99 public static $is_filter = true;
100
101 /**
102 * Set whether fields created from this custom field type can be given character limits
103 *
104 * @var boolean
105 */
106 public static $has_char_limit = false;
107
108 /**
109 * Set whether fields created from this custom field type has custom options set in options table
110 *
111 * @var boolean
112 */
113 public static $has_options = false;
114
115 /**
116 * Set whether fields created from this custom field type can be available for ticket list sorting
117 *
118 * @var boolean
119 */
120 public static $is_sort = false;
121
122 /**
123 * Set whether fields created from this custom field type can be auto-filled
124 *
125 * @var boolean
126 */
127 public static $is_auto_fill = true;
128
129 /**
130 * Set whether fields created from this custom field type can have placeholder
131 *
132 * @var boolean
133 */
134 public static $is_placeholder = true;
135
136 /**
137 * Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form
138 *
139 * @var boolean
140 */
141 public static $is_visibility_conditions = true;
142
143 /**
144 * Set whether fields created from this custom field type is applicable for macros
145 *
146 * @var boolean
147 */
148 public static $has_macro = true;
149
150 /**
151 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
152 *
153 * @var boolean
154 */
155 public static $is_search = true;
156
157 /**
158 * Initialize the class
159 *
160 * @return void
161 */
162 public static function init() {
163
164 // Get object of this class.
165 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
166
167 // Set custom field type.
168 add_filter( 'wpsc_cf_types', array( __CLASS__, 'add_cf_type' ), 10 );
169
170 // ticket form.
171 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
172 add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 );
173 add_action( 'wpsc_js_clear_value_hidden_fields', array( __CLASS__, 'js_clear_value_hidden_fields' ) );
174
175 // create ticket data for rest api.
176 add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 );
177
178 // Ticket model.
179 add_filter( 'wpsc_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 );
180 add_filter( 'wpsc_archive_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 );
181 }
182
183 /**
184 * Load current class to reference classes
185 *
186 * @param array $classes - Associative array of class names indexed by its slug.
187 * @return array
188 */
189 public static function load_ref_class( $classes ) {
190
191 $classes[ self::$slug ] = array(
192 'class' => __CLASS__,
193 'save-key' => 'id',
194 );
195 return $classes;
196 }
197
198 /**
199 * Add custom field type to list
200 *
201 * @param array $cf_types - custom field types array.
202 * @return array
203 */
204 public static function add_cf_type( $cf_types ) {
205
206 $cf_types[ self::$slug ] = array(
207 'label' => 'URL',
208 'class' => __CLASS__,
209 );
210 return $cf_types;
211 }
212
213 /**
214 * Print operators for ticket form filter
215 *
216 * @param WPSC_Custom_Field $cf - custom field object.
217 * @param array $filter - Existing filters (if any).
218 * @return void
219 */
220 public static function get_operators( $cf, $filter = array() ) {
221 ?>
222
223 <div class="item conditional">
224 <select class="operator" onchange="wpsc_tc_get_operand(this, '<?php echo esc_attr( $cf->slug ); ?>', '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operand' ) ); ?>');">
225 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
226 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
227 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
228 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'NOT IN' ); ?> value="NOT IN"><?php esc_attr_e( 'Not Matches', 'supportcandy' ); ?></option>
229 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
230 </select>
231 </div>
232 <?php
233 }
234
235 /**
236 * Print operators for ticket form filter
237 *
238 * @param string $operator - condition operator on which operands should be returned.
239 * @param WPSC_Custom_Field $cf - custom field object.
240 * @param array $filter - Exising functions (if any).
241 * @return void
242 */
243 public static function get_operands( $operator, $cf, $filter = array() ) {
244
245 $value = isset( $filter['operand_val_1'] ) ? stripslashes( $filter['operand_val_1'] ) : '';
246 if ( in_array( $operator, array( 'IN', 'NOT IN', 'LIKE' ) ) ) {
247 ?>
248
249 <div class="item conditional operand single">
250 <textarea class="operand_val_1" placeholder="<?php esc_attr_e( 'One condition per line!', 'supportcandy' ); ?>" style="width: 100%;"><?php echo esc_attr( $value ); ?></textarea>
251 </div>
252 <?php
253
254 } else {
255 ?>
256
257 <div class="item conditional operand single">
258 <input
259 type="text"
260 class="operand_val_1"
261 value="<?php echo esc_attr( $value ); ?>"
262 autocomplete="off"/>
263 </div>
264 <?php
265 }
266 }
267
268 /**
269 * Check condition for this type
270 *
271 * @param array $condition - condition data.
272 * @param WPSC_Custom_Field $cf - custom field object.
273 * @param mixed $value - value to compare.
274 * @return boolean
275 */
276 public static function is_valid( $condition, $cf, $value ) {
277
278 $response = false;
279 $value = stripslashes( $value );
280 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
281 switch ( $condition['operator'] ) {
282
283 case '=':
284 $response = $condition['operand_val_1'] == $value ? true : false;
285 break;
286
287 case 'IN':
288 foreach ( $terms as $term ) {
289 $term = trim( $term );
290 if ( $term == $value ) {
291 $response = true;
292 break;
293 }
294 }
295 break;
296
297 case 'NOT IN':
298 $response = true;
299 foreach ( $terms as $term ) {
300 $term = trim( $term );
301 if ( $term == $value ) {
302 $response = false;
303 break;
304 }
305 }
306 break;
307
308 case 'LIKE':
309 $response = false;
310 foreach ( $terms as $term ) {
311 $index = strpos( $value, trim( stripslashes( $term ) ) );
312 if ( is_numeric( $index ) ) {
313 $response = true;
314 break;
315 }
316 }
317 break;
318 }
319 return $response;
320 }
321
322 /**
323 * Parse filter and return sql query to be merged in ticket model query builder
324 *
325 * @param WPSC_Custom_Field $cf - custom field of this type.
326 * @param mixed $compare - comparison operator.
327 * @param mixed $val - value to compare.
328 * @return string
329 */
330 public static function parse_filter( $cf, $compare, $val ) {
331
332 global $wpdb;
333 $column = self::get_sql_slug( $cf );
334
335 switch ( $compare ) {
336
337 case '=':
338 if ( ! filter_var( $val, FILTER_VALIDATE_URL ) ) {
339 return '1=0';
340 }
341
342 return $wpdb->prepare(
343 "{$column} = %s",
344 $val
345 );
346
347 case 'LIKE':
348 if ( ! is_string( $val ) || trim( $val ) === '' ) {
349 return '1=0';
350 }
351
352 $term = $wpdb->esc_like( trim( $val ) );
353
354 return $wpdb->prepare(
355 "{$column} LIKE %s",
356 '%' . $term . '%'
357 );
358
359 case 'IN':
360 case 'NOT IN':
361 if ( ! is_array( $val ) || empty( $val ) ) {
362 return '1=0';
363 }
364
365 $urls = array_filter(
366 $val,
367 static fn( $u ) => filter_var( $u, FILTER_VALIDATE_URL )
368 );
369
370 if ( empty( $urls ) ) {
371 return '1=0';
372 }
373
374 $placeholders = implode( ',', array_fill( 0, count( $urls ), '%s' ) );
375 $operator = ( $compare === 'IN' ) ? 'IN' : 'NOT IN';
376
377 return $wpdb->prepare(
378 "{$column} {$operator} ({$placeholders})",
379 ...$urls
380 );
381
382 default:
383 return '1=1';
384 }
385 }
386
387 /**
388 * Check ticket condition
389 *
390 * @param array $condition - array with condition data.
391 * @param WPSC_Custom_Field $cf - custom field object.
392 * @param WPSC_Ticket $ticket - ticket object.
393 * @return boolean
394 */
395 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
396
397 $flag = true;
398 $value = stripslashes( $ticket->{$cf->slug} );
399 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
400
401 switch ( $condition['operator'] ) {
402
403 case '=':
404 $flag = $condition['operand_val_1'] == $value ? true : false;
405 break;
406
407 case 'IN':
408 $flag = false;
409 foreach ( $terms as $term ) {
410 $term = trim( $term );
411 if ( $term == $value ) {
412 $flag = true;
413 break;
414 }
415 }
416 break;
417
418 case 'NOT IN':
419 foreach ( $terms as $term ) {
420 $term = trim( $term );
421 if ( $term == $value ) {
422 $flag = false;
423 break;
424 }
425 }
426 break;
427
428 case 'LIKE':
429 $flag = false;
430 foreach ( $terms as $term ) {
431 $index = strpos( $value, trim( stripslashes( $term ) ) );
432 if ( is_numeric( $index ) ) {
433 $flag = true;
434 break;
435 }
436 }
437 break;
438
439 default:
440 $flag = true;
441 }
442
443 return $flag;
444 }
445
446 /**
447 * Check customer condition
448 *
449 * @param array $condition - array with condition data.
450 * @param WPSC_Custom_Field $cf - custom field object.
451 * @param WPSC_Customer $customer - customer object.
452 * @return boolean
453 */
454 public static function is_valid_customer_condition( $condition, $cf, $customer ) {
455
456 $flag = true;
457 $value = stripslashes( $customer->{$cf->slug} );
458 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
459
460 switch ( $condition['operator'] ) {
461
462 case '=':
463 $flag = $condition['operand_val_1'] == $value ? true : false;
464 break;
465
466 case 'IN':
467 $flag = false;
468 foreach ( $terms as $term ) {
469 $term = trim( $term );
470 if ( $term == $value ) {
471 $flag = true;
472 break;
473 }
474 }
475 break;
476
477 case 'NOT IN':
478 foreach ( $terms as $term ) {
479 $term = trim( $term );
480 if ( $term == $value ) {
481 $flag = false;
482 break;
483 }
484 }
485 break;
486
487 case 'LIKE':
488 $flag = false;
489 foreach ( $terms as $term ) {
490 $index = strpos( $value, trim( stripslashes( $term ) ) );
491 if ( is_numeric( $index ) ) {
492 $flag = true;
493 break;
494 }
495 }
496 break;
497
498 default:
499 $flag = true;
500 }
501
502 return $flag;
503 }
504
505 /**
506 * Print ticket form field
507 *
508 * @param WPSC_Custom_Field $cf - Custom field object.
509 * @param array $tff - Array of ticket form field settings for this field.
510 * @return string
511 */
512 public static function print_tff( $cf, $tff ) {
513
514 $val = '';
515 if ( $cf->field == 'ticket' ) {
516 $val = $cf->is_auto_fill && $cf->default_value ? $cf->default_value[0] : '';
517 } else {
518 $current_user = WPSC_Current_User::$current_user;
519 $val = $current_user->is_customer && $current_user->customer->{$cf->slug} ? $current_user->customer->{$cf->slug} : '';
520 }
521
522 ob_start();
523 ?>
524 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>" data-slug="<?php echo esc_attr( $cf->slug ); ?>">
525 <div class="wpsc-tff-label">
526 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
527 <?php
528 if ( $tff['is-required'] ) {
529 ?>
530 <span class="required-indicator">*</span>
531 <?php
532 }
533 ?>
534 </div>
535 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
536 <input
537 type="text"
538 name="<?php echo esc_attr( $cf->slug ); ?>"
539 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
540 onchange="wpsc_check_tff_visibility()"
541 value="<?php echo esc_attr( $val ); ?>"
542 autocomplete="off"/>
543 </div>
544 <?php
545 return ob_get_clean();
546 }
547
548 /**
549 * Validate this type field in create ticket
550 *
551 * @return void
552 */
553 public static function js_validate_ticket_form() {
554 ?>
555
556 case '<?php echo esc_attr( self::$slug ); ?>':
557 var val = customField.find('input').first().val().trim();
558 if (isRequired && !val) {
559 isValid = false;
560 } else if (val && !validateURL(val)) {
561 showFieldError(customField, 'Invalid URL');
562 isValid = false;
563 }
564 break;
565 <?php
566 echo PHP_EOL;
567 }
568
569 /**
570 * Return custom field value in $_POST
571 * Ignore phpcs nonce issue as we already checked where it is called from.
572 *
573 * @param string $slug - Custom field slug.
574 * @param mixed $cf - Custom field object or false.
575 * @return mixed
576 */
577 public static function get_tff_value( $slug, $cf = false ) {
578
579 $url = isset( $_POST[ $slug ] ) ? esc_url_raw( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
580 $url = filter_var( $url, FILTER_VALIDATE_URL );
581 return $url ? $url : '';
582 }
583
584 /**
585 * Return default value for custom field of this type
586 *
587 * @param WPSC_Custom_Field $cf - custom field object.
588 * @return mixed
589 */
590 public static function get_default_value( $cf ) {
591
592 return $cf->default_value ? $cf->default_value[0] : '';
593 }
594
595 /**
596 * Check and return custom field value for new ticket to be created.
597 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
598 * Ignore phpcs nonce issue as we already checked where it is called from.
599 *
600 * @param array $data - Array of values to to stored in ticket in an insert function.
601 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
602 * @param boolean $is_my_profile - Whether it or not it is created from my-profile. This function is used by create ticket as well as my-profile. Due to customer fields handling is done same way, this flag gives apportunity to identify where it being called.
603 * @return array
604 */
605 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
606
607 if ( isset( $custom_fields[ self::$slug ] ) ) {
608 foreach ( $custom_fields[ self::$slug ] as $cf ) {
609 $value = self::get_tff_value( $cf->slug );
610 if ( $cf->field == 'ticket' ) {
611
612 $default_val = self::get_default_value( $cf );
613 $data[ $cf->slug ] = $value ? $value : $default_val;
614
615 } elseif ( $cf->field == 'agentonly' ) {
616
617 $data[ $cf->slug ] = self::get_default_value( $cf );
618
619 } elseif ( $cf->field == 'customer' && $data['customer'] != 0 ) {
620
621 $tff = get_option( 'wpsc-tff' );
622 if ( ! $is_my_profile && ! isset( $tff[ $cf->slug ] ) ) {
623 continue;
624 }
625 $customer = new WPSC_Customer( $data['customer'] );
626 $prev_val = $customer->{$cf->slug} ? $customer->{$cf->slug} : '';
627 if ( $customer->{$cf->slug} != $value ) {
628 $customer->{$cf->slug} = $value;
629 $customer->save();
630
631 // Set log for this change.
632 WPSC_Log::insert(
633 array(
634 'type' => 'customer',
635 'ref_id' => $customer->id,
636 'modified_by' => WPSC_Current_User::$current_user->customer->id,
637 'body' => wp_json_encode(
638 array(
639 'slug' => $cf->slug,
640 'prev' => $prev_val,
641 'new' => $value,
642 )
643 ),
644 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
645 )
646 );
647 }
648 }
649 }
650 }
651 return $data;
652 }
653
654 /**
655 * Set create ticket data for rest api request
656 *
657 * @param array $data - create ticket data array.
658 * @param WP_REST_Request $request - rest request object.
659 * @param array $custom_fields - custom field objects indexed by unique custom field types.
660 * @return array
661 */
662 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
663
664 $current_user = WPSC_Current_User::$current_user;
665 $tff = get_option( 'wpsc-tff' );
666
667 if ( isset( $custom_fields[ self::$slug ] ) ) {
668 foreach ( $custom_fields[ self::$slug ] as $cf ) {
669
670 if (
671 ! in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) ||
672 ( $cf->field == 'customer' && ! isset( $tff[ $cf->slug ] ) )
673 ) {
674 continue;
675 }
676
677 $url = WPSC_Functions::sanitize_url( sanitize_text_field( $request->get_param( $cf->slug ) ) );
678
679 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ) {
680
681 $data[ $cf->slug ] = $cf->field == 'ticket' && $url ? $url : self::get_default_value( $cf );
682
683 } else {
684
685 $customer = new WPSC_Customer( $data['customer'] );
686 $existing_val = $customer->{$cf->slug};
687
688 if ( $url && $url != $existing_val ) {
689
690 $customer->{$cf->slug} = $url;
691 $customer->save();
692
693 // Set log for this change.
694 WPSC_Log::insert(
695 array(
696 'type' => 'customer',
697 'ref_id' => $customer->id,
698 'modified_by' => $current_user->customer->id,
699 'body' => wp_json_encode(
700 array(
701 'slug' => $cf->slug,
702 'prev' => $existing_val,
703 'new' => $url,
704 )
705 ),
706 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
707 )
708 );
709 }
710 }
711 }
712 }
713
714 return $data;
715 }
716
717 /**
718 * Return slug string to be used in where condition of ticket model for this type of field
719 *
720 * @param WPSC_Custom_Field $cf - custom field object.
721 * @return string
722 */
723 public static function get_sql_slug( $cf ) {
724
725 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
726 return $join_char . $cf->slug;
727 }
728
729 /**
730 * Add ticket search compatibility for fields of this custom field type.
731 *
732 * @param array $sql - Array of sql peices that can be joined later.
733 * @param array $filter - User filter.
734 * @param array $custom_fields - Custom fields array applicable for search.
735 * @param string $search - search string.
736 * @param array $allowed_search_fields - Allowed search fields.
737 * @return array
738 */
739 public static function ticket_search( $sql, $filter, $custom_fields, $search, $allowed_search_fields ) {
740
741 if ( isset( $custom_fields[ self::$slug ] ) ) {
742 foreach ( $custom_fields[ self::$slug ] as $cf ) {
743 if ( in_array( $cf->slug, $allowed_search_fields ) ) {
744
745 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
746 $sql[] = 'CONVERT(' . $join_char . $cf->slug . ' USING utf8) LIKE \'%' . $search . '%\'';
747 }
748 }
749 }
750
751 return $sql;
752 }
753
754 /**
755 * Return val field for meta query of this type of custom field
756 *
757 * @param array $condition - condition data.
758 * @return mixed
759 */
760 public static function get_meta_value( $condition ) {
761
762 $operator = $condition['operator'];
763 switch ( $operator ) {
764
765 case '=':
766 return $condition['operand_val_1'];
767
768 case 'IN':
769 case 'NOT IN':
770 $val = explode( PHP_EOL, $condition['operand_val_1'] );
771 $temp_val = array();
772 foreach ( $val as $value ) {
773 $value = trim( $value );
774 if ( $value ) {
775 $temp_val[] = $value;
776 }
777 }
778 return $temp_val ? $temp_val : false;
779
780 case 'LIKE':
781 return trim( $condition['operand_val_1'] );
782 }
783 return false;
784 }
785
786 /**
787 * Print generic input field for this type.
788 *
789 * @param WPSC_Custom_Field $cf - Custom field object.
790 * @param mixed $value - optional. Input field will be printed with given value if given.
791 * @return void
792 */
793 public static function print_cf_input( $cf, $value = '' ) {
794
795 ?>
796 <div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>">
797 <div class="wpsc-tff-label">
798 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
799 </div>
800 <?php
801 $extra_info = stripslashes( $cf->extra_info );
802 if ( $extra_info ) :
803 ?>
804 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
805 <?php
806 endif
807 ?>
808 <input
809 type="text"
810 name="<?php echo esc_attr( $cf->slug ); ?>"
811 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
812 value="<?php echo esc_attr( $value ); ?>"
813 autocomplete="off"/>
814 </div>
815 <?php
816 }
817
818 /**
819 * Get value for generic field from post.
820 * Ignore phpcs nonce issue as we already checked where it is called from.
821 *
822 * @param WPSC_Custom_Field $cf - custom field object.
823 * @return string
824 */
825 public static function get_cf_input_val( $cf ) {
826
827 $url = isset( $_POST[ $cf->slug ] ) ? esc_url_raw( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
828 $url = filter_var( $url, FILTER_VALIDATE_URL );
829 return $url ? $url : '';
830 }
831
832 /**
833 * Print edit ticket custom field in individual ticket
834 *
835 * @param WPSC_Custom_Field $cf - custom field object.
836 * @param WPSC_Ticket $ticket - ticket object.
837 * @return void
838 */
839 public static function print_edit_ticket_cf( $cf, $ticket ) {
840
841 ?>
842 <div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>">
843 <div class="wpsc-tff-label">
844 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
845 </div>
846 <?php
847 $extra_info = stripslashes( $cf->extra_info );
848 if ( $extra_info ) :
849 ?>
850 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
851 <?php
852 endif
853 ?>
854 <input
855 type="text"
856 name="<?php echo esc_attr( $cf->slug ); ?>"
857 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
858 value="<?php echo esc_attr( $ticket->{$cf->slug} ); ?>"
859 autocomplete="off"/>
860 </div>
861 <?php
862 }
863
864 /**
865 * Set edit individual ticket for this custom field type.
866 * Ignore phpcs nonce issue as we already checked where it is called from.
867 *
868 * @param WPSC_Custom_Field $cf - custom field object.
869 * @param WPSC_Ticket $ticket - ticket object.
870 * @return WPSC_Ticket
871 */
872 public static function set_edit_ticket_cf( $cf, $ticket ) {
873
874 $prev = $ticket->{$cf->slug} ? $ticket->{$cf->slug} : '';
875
876 $new = isset( $_POST[ $cf->slug ] ) ? esc_url_raw( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
877 $new = filter_var( $new, FILTER_VALIDATE_URL ) ? $new : '';
878
879 // Exit if there is no change.
880 if ( $prev == $new ) {
881 return $ticket;
882 }
883
884 // Change value.
885 $ticket->{$cf->slug} = $new;
886 $ticket->save();
887
888 return $ticket;
889 }
890
891 /**
892 * Modify ticket field value of this custom field type using rest api
893 *
894 * @param WPSC_Ticket $ticket - ticket object.
895 * @param WPSC_Custom_Field $cf - custom field.
896 * @param mixed $value - value to be set.
897 * @return void
898 */
899 public static function set_rest_edit_ticket_cf( $ticket, $cf, $value ) {
900
901 $url = WPSC_Functions::sanitize_url( sanitize_text_field( $value ) );
902 if ( $ticket->{$cf->slug} != $url ) {
903 $ticket->{$cf->slug} = $url;
904 }
905 }
906
907 /**
908 * Insert log thread for this custom field type change
909 *
910 * @param WPSC_Custom_Field $cf - current custom field of this type.
911 * @param WPSC_Ticket $prev - ticket object before making any changes.
912 * @param WPSC_Ticket $new - ticket object after making changes.
913 * @param string $current_date - date string to be stored as create time.
914 * @param int $customer_id - current user customer id for blame.
915 * @return void
916 */
917 public static function insert_ticket_log( $cf, $prev, $new, $current_date, $customer_id ) {
918
919 // Exit if there is no change.
920 if ( $prev->{$cf->slug} == $new->{$cf->slug} ) {
921 return;
922 }
923
924 $prev_val = $prev->{$cf->slug};
925 $new_val = $new->{$cf->slug};
926
927 $thread = WPSC_Thread::insert(
928 array(
929 'ticket' => $prev->id,
930 'customer' => $customer_id,
931 'type' => 'log',
932 'body' => wp_json_encode(
933 array(
934 'slug' => $cf->slug,
935 'prev' => $prev_val,
936 'new' => $new_val,
937 )
938 ),
939 'date_created' => $current_date,
940 'date_updated' => $current_date,
941 )
942 );
943 }
944
945 /**
946 * Return data for this custom field while creating duplicate ticket
947 *
948 * @param WPSC_Custom_Field $cf - custom field object.
949 * @param WPSC_Ticket $ticket - ticket object.
950 * @return mixed
951 */
952 public static function get_duplicate_ticket_data( $cf, $ticket ) {
953
954 return $ticket->{$cf->slug};
955 }
956
957 /**
958 * Print edit field for this type in edit customer info
959 *
960 * @param WPSC_Custom_field $cf - custom field object.
961 * @param WPSC_Customer $customer - customer object.
962 * @param array $tff - ticket form field data.
963 * @return string
964 */
965 public static function print_edit_customer_info( $cf, $customer, $tff ) {
966
967 $val = $customer->id && $customer->{$cf->slug} ? htmlspecialchars( $customer->{$cf->slug} ) : '';
968
969 ob_start();
970 ?>
971 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
972 <div class="wpsc-tff-label">
973 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
974 </div>
975 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
976 <input
977 type="text"
978 name="<?php echo esc_attr( $cf->slug ); ?>"
979 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
980 value="<?php echo esc_attr( $val ); ?>"
981 autocomplete="off"/>
982 </div>
983 <?php
984 return ob_get_clean();
985 }
986
987 /**
988 * Print add new custom field setting properties
989 *
990 * @param string $field_class - Class name of the field.
991 * @return void
992 */
993 public static function get_add_new_custom_field_properties( $field_class ) {
994
995 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
996 ?>
997 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
998 <div class="label-container">
999 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
1000 </div>
1001 <input name="extra_info" type="text" autocomplete="off" />
1002 </div>
1003 <?php
1004 endif;
1005
1006 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
1007 ?>
1008 <div data-type="url" data-required="false" class="wpsc-input-group default_value">
1009 <div class="label-container">
1010 <label for="">
1011 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
1012 </label>
1013 </div>
1014 <input type="text" name="default_value" autocomplete="off">
1015 </div>
1016 <?php
1017 endif;
1018
1019 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1020 ?>
1021 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1022 <div class="label-container">
1023 <label for="">
1024 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1025 </label>
1026 </div>
1027 <select name="is_auto_fill">
1028 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1029 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1030 </select>
1031 </div>
1032 <?php
1033 endif;
1034
1035 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1036 ?>
1037 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1038 <div class="label-container">
1039 <label for="">
1040 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1041 </label>
1042 </div>
1043 <input type="text" name="placeholder_text" autocomplete="off">
1044 </div>
1045 <?php
1046 endif;
1047
1048 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
1049 ?>
1050 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
1051 <div class="label-container">
1052 <label for="">
1053 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
1054 </label>
1055 </div>
1056 <input type="number" name="tl_width" autocomplete="off">
1057 </div>
1058 <?php
1059 endif;
1060
1061 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1062 ?>
1063 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1064 <div class="label-container">
1065 <label for="">
1066 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1067 </label>
1068 </div>
1069 <select name="is_personal_info">
1070 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1071 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1072 </select>
1073 </div>
1074 <?php
1075 endif;
1076
1077 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1078 ?>
1079 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1080 <div class="label-container">
1081 <label for="">
1082 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1083 </label>
1084 </div>
1085 <select name="allow_my_profile">
1086 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1087 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1088 </select>
1089 </div>
1090 <?php
1091 endif;
1092
1093 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) :
1094 ?>
1095 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1096 <div class="label-container">
1097 <label for="">
1098 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1099 </label>
1100 </div>
1101 <select name="allow_ticket_form">
1102 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1103 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1104 </select>
1105 </div>
1106 <?php
1107 endif;
1108 }
1109
1110 /**
1111 * Print edit custom field properties
1112 *
1113 * @param WPSC_Custom_Fields $cf - custom field object.
1114 * @param string $field_class - class name of field category.
1115 * @return void
1116 */
1117 public static function get_edit_custom_field_properties( $cf, $field_class ) {
1118
1119 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
1120 ?>
1121 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
1122 <div class="label-container">
1123 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
1124 </div>
1125 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
1126 </div>
1127 <?php
1128 endif;
1129
1130 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
1131 $default_val = $cf->default_value ? $cf->default_value[0] : '';
1132 ?>
1133 <div data-type="url" data-required="false" class="wpsc-input-group default_value">
1134 <div class="label-container">
1135 <label for="">
1136 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
1137 </label>
1138 </div>
1139 <input type="text" name="default_value" value="<?php echo esc_attr( $default_val ); ?>" autocomplete="off">
1140 </div>
1141 <?php
1142 endif;
1143
1144 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1145 ?>
1146 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1147 <div class="label-container">
1148 <label for="">
1149 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1150 </label>
1151 </div>
1152 <select name="is_auto_fill">
1153 <option <?php selected( $cf->is_auto_fill, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1154 <option <?php selected( $cf->is_auto_fill, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1155 </select>
1156 </div>
1157 <?php
1158 endif;
1159
1160 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1161 ?>
1162 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1163 <div class="label-container">
1164 <label for="">
1165 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1166 </label>
1167 </div>
1168 <input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off">
1169 </div>
1170 <?php
1171 endif;
1172
1173 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
1174 ?>
1175 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
1176 <div class="label-container">
1177 <label for="">
1178 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
1179 </label>
1180 </div>
1181 <input type="number" name="tl_width" value="<?php echo intval( $cf->tl_width ); ?>" autocomplete="off">
1182 </div>
1183 <?php
1184 endif;
1185
1186 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1187 ?>
1188 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1189 <div class="label-container">
1190 <label for="">
1191 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1192 </label>
1193 </div>
1194 <select name="is_personal_info">
1195 <option <?php selected( $cf->is_personal_info, 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1196 <option <?php selected( $cf->is_personal_info, 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1197 </select>
1198 </div>
1199 <?php
1200 endif;
1201
1202 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1203 ?>
1204 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1205 <div class="label-container">
1206 <label for="">
1207 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1208 </label>
1209 </div>
1210 <select name="allow_my_profile">
1211 <option <?php selected( $cf->allow_my_profile, 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1212 <option <?php selected( $cf->allow_my_profile, 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1213 </select>
1214 </div>
1215 <?php
1216 endif;
1217
1218 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) :
1219 ?>
1220 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1221 <div class="label-container">
1222 <label for="">
1223 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1224 </label>
1225 </div>
1226 <select name="allow_ticket_form">
1227 <option <?php selected( $cf->allow_ticket_form, 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1228 <option <?php selected( $cf->allow_ticket_form, 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1229 </select>
1230 </div>
1231 <?php
1232 endif;
1233 }
1234
1235 /**
1236 * Set custom field properties. Can be used by add/edit custom field.
1237 * Ignore phpcs nonce issue as we already checked where it is called from.
1238 *
1239 * @param WPSC_Custom_Field $cf - custom field object.
1240 * @param string $field_class - class of field category.
1241 * @return void
1242 */
1243 public static function set_cf_properties( $cf, $field_class ) {
1244
1245 // extra info.
1246 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
1247 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
1248 }
1249
1250 // default value.
1251 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
1252 $default_value = isset( $_POST['default_value'] ) ? esc_url_raw( wp_unslash( $_POST['default_value'] ) ) : ''; // phpcs:ignore
1253 $default_value = filter_var( $default_value, FILTER_VALIDATE_URL );
1254 $cf->default_value = $default_value ? array( $default_value ) : array();
1255 }
1256
1257 // auto fill.
1258 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) {
1259 $cf->is_auto_fill = isset( $_POST['is_auto_fill'] ) ? sanitize_text_field( wp_unslash( $_POST['is_auto_fill'] ) ) : ''; // phpcs:ignore
1260 }
1261
1262 // placeholder!
1263 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) {
1264 $cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore
1265 }
1266
1267 // personal info.
1268 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) {
1269 $cf->is_personal_info = isset( $_POST['is_personal_info'] ) ? intval( $_POST['is_personal_info'] ) : 0; // phpcs:ignore
1270 }
1271
1272 // my-profile.
1273 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) {
1274 $cf->allow_my_profile = isset( $_POST['allow_my_profile'] ) ? intval( $_POST['allow_my_profile'] ) : 0; // phpcs:ignore
1275 }
1276
1277 // ticket form.
1278 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) {
1279 $cf->allow_ticket_form = isset( $_POST['allow_ticket_form'] ) ? intval( $_POST['allow_ticket_form'] ) : 0; // phpcs:ignore
1280 }
1281
1282 // tl_width!
1283 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
1284 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
1285 $cf->tl_width = $tl_width ? $tl_width : 100;
1286 }
1287
1288 // save!
1289 $cf->save();
1290 }
1291
1292 /**
1293 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
1294 *
1295 * @param WPSC_Custom_Field $cf - custom field object.
1296 * @param WPSC_Ticket $ticket - ticket object.
1297 * @param string $module - module name.
1298 * @return string
1299 */
1300 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
1301
1302 return apply_filters( 'wpsc_ticket_field_val_url', $ticket->{$cf->slug}, $cf, $ticket, $module );
1303 }
1304
1305 /**
1306 * Print ticket value for given custom field on ticket list
1307 *
1308 * @param WPSC_Custom_Field $cf - custom field object.
1309 * @param WPSC_Ticket $ticket - ticket object.
1310 * @return void
1311 */
1312 public static function print_tl_ticket_field_val( $cf, $ticket ) {
1313
1314 echo esc_attr( self::get_ticket_field_val( $cf, $ticket ) );
1315 }
1316
1317 /**
1318 * Print ticket value for given custom field on widget
1319 *
1320 * @param WPSC_Custom_Field $cf - custom field object.
1321 * @param WPSC_Ticket $ticket - ticket object.
1322 * @return void
1323 */
1324 public static function print_widget_ticket_field_val( $cf, $ticket ) {
1325
1326 $url = $ticket->{$cf->slug};
1327 if ( ! $url ) {
1328 return;
1329 }
1330 ?>
1331 <a class="wpsc-link" href="<?php echo esc_url_raw( $url ); ?>" target="_blank"><?php esc_attr_e( 'Click Here', 'supportcandy' ); ?></a>
1332 <?php
1333 }
1334
1335 /**
1336 * Returns printable customer value for custom field. Can be used in export tickets, replace macros etc.
1337 *
1338 * @param WPSC_Custom_Field $cf - custom field object.
1339 * @param WPSC_Customer $customer - customer object.
1340 * @return string
1341 */
1342 public static function get_customer_field_val( $cf, $customer ) {
1343
1344 return $customer->{$cf->slug};
1345 }
1346
1347 /**
1348 * Print customer value for given custom field on ticket list
1349 *
1350 * @param WPSC_Custom_Field $cf - custom field object.
1351 * @param WPSC_Customer $customer - customer object.
1352 * @return void
1353 */
1354 public static function print_tl_customer_field_val( $cf, $customer ) {
1355
1356 echo esc_attr( self::get_customer_field_val( $cf, $customer ) );
1357 }
1358
1359 /**
1360 * Print customer value for given custom field on widget
1361 *
1362 * @param WPSC_Custom_Field $cf - custom field object.
1363 * @param WPSC_Customer $customer - customer object.
1364 * @return void
1365 */
1366 public static function print_widget_customer_field_val( $cf, $customer ) {
1367
1368 $url = $customer->{$cf->slug};
1369 if ( ! $url ) {
1370 return;
1371 }
1372 ?>
1373 <a class="wpsc-link" href="<?php echo esc_url_raw( $url ); ?>" target="_blank"><?php esc_attr_e( 'Click Here', 'supportcandy' ); ?></a>
1374 <?php
1375 }
1376
1377 /**
1378 * Print given value for custom field
1379 *
1380 * @param WPSC_Custom_Field $cf - custom field object.
1381 * @param mixed $val - value to convert and print.
1382 * @return void
1383 */
1384 public static function print_val( $cf, $val ) {
1385
1386 if ( ! $val ) {
1387 esc_attr_e( 'None', 'supportcandy' );
1388 return;
1389 }
1390 ?>
1391 <a class="wpsc-link" href="<?php echo esc_url_raw( $val ); ?>" target="_blank"><?php echo esc_url_raw( $val ); ?></a>
1392 <?php
1393 }
1394
1395 /**
1396 * Return printable value for history log macro
1397 *
1398 * @param WPSC_Custom_Field $cf - custom field object.
1399 * @param mixed $val - value to convert and return.
1400 * @return string
1401 */
1402 public static function get_history_log_val( $cf, $val ) {
1403
1404 return $val ? esc_url_raw( $val ) : esc_attr__( 'None', 'supportcandy' );
1405 }
1406
1407 /**
1408 * Print dashboard activity function
1409 *
1410 * @param WPSC_Custom_Field $cf - custom field object.
1411 * @param array $recent_logs - recent_logs object.
1412 * @param array $body - body object.
1413 * @param int $view - check if frontend.
1414 * @return string
1415 */
1416 public static function print_activity( $cf, $recent_logs, $body, $view ) {
1417
1418 $url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view );
1419 if ( $body->new ) {
1420 $url_value = $body->new;
1421 } else {
1422 $url_value = 'None';
1423 }
1424 return esc_attr( $recent_logs->customer->name ) . ' updated the ' . esc_attr( $cf->name ) . ' value of <a href="' . esc_attr( $url ) . '" target="_blank">#' . esc_attr( $recent_logs->ticket->id ) . '</a> to <a href="' . esc_attr( $url_value ) . '">' . esc_attr( $url_value ) . '</a>';
1425 }
1426
1427 /**
1428 * Return given value for custom field
1429 *
1430 * @param WPSC_Custom_Field $cf - custom field object.
1431 * @param mixed $val - value to convert and print.
1432 * @return string
1433 */
1434 public static function get_field_value( $cf, $val ) {
1435
1436 return $val ? '<a href="' . esc_url_raw( $val ) . '" target="__blank">' . esc_url_raw( $val ) . '</a>' : esc_attr__( 'None', 'supportcandy' );
1437 }
1438
1439 /**
1440 * Clear value of hidden fields
1441 *
1442 * @return void
1443 */
1444 public static function js_clear_value_hidden_fields() {
1445 ?>
1446 case '<?php echo esc_attr( self::$slug ); ?>':
1447 customField.find('input').first().val('');
1448 break;
1449 <?php
1450 echo PHP_EOL;
1451 }
1452 }
1453 endif;
1454
1455 WPSC_CF_URL::init();
1456