PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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-textarea.php

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

1,430 lines 42.6 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_Textarea' ) ) :
7
8 final class WPSC_CF_Textarea {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'cf_textarea';
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 = 'LONGTEXT 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 = false;
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 = true;
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 auto-filled
117 *
118 * @var boolean
119 */
120 public static $is_auto_fill = true;
121
122 /**
123 * Set whether fields created from this custom field type can be available for ticket list sorting
124 *
125 * @var boolean
126 */
127 public static $is_sort = false;
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' ), 5 );
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' => esc_attr__( 'Textarea', 'supportcandy' ),
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'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
227 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'NOT IN' ); ?> value="NOT IN"><?php esc_attr_e( 'Not Matches', 'supportcandy' ); ?></option>
228 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
229 </select>
230 </div>
231 <?php
232 }
233
234 /**
235 * Print operators for ticket form filter
236 *
237 * @param string $operator - condition operator on which operands should be returned.
238 * @param WPSC_Custom_Field $cf - custom field object.
239 * @param array $filter - Exising functions (if any).
240 * @return void
241 */
242 public static function get_operands( $operator, $cf, $filter = array() ) {
243
244 $value = isset( $filter['operand_val_1'] ) ? stripslashes( $filter['operand_val_1'] ) : ''
245 ?>
246 <div class="item conditional operand single">
247 <textarea class="operand_val_1" placeholder="<?php esc_attr_e( 'One condition per line!', 'supportcandy' ); ?>" style="width: 100%;"><?php echo esc_attr( $value ); ?></textarea>
248 </div>
249 <?php
250 }
251
252 /**
253 * Check condition for this type
254 *
255 * @param array $condition - condition data.
256 * @param WPSC_Custom_Field $cf - custom field object.
257 * @param mixed $value - value to compare.
258 * @return boolean
259 */
260 public static function is_valid( $condition, $cf, $value ) {
261
262 $response = false;
263 $value = stripslashes( $value );
264 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
265
266 switch ( $condition['operator'] ) {
267
268 case 'IN':
269 foreach ( $terms as $term ) {
270 $term = trim( $term );
271 if ( $term == $value ) {
272 $response = true;
273 break;
274 }
275 }
276 break;
277
278 case 'NOT IN':
279 $response = true;
280 foreach ( $terms as $term ) {
281 $term = trim( $term );
282 if ( $term == $value ) {
283 $response = false;
284 break;
285 }
286 }
287 break;
288
289 case 'LIKE':
290 $response = false;
291 foreach ( $terms as $term ) {
292 $index = strpos( $value, trim( stripslashes( $term ) ) );
293 if ( is_numeric( $index ) ) {
294 $response = true;
295 break;
296 }
297 }
298 break;
299 }
300 return $response;
301 }
302
303 /**
304 * Parse filter and return sql query to be merged in ticket model query builder
305 *
306 * @param WPSC_Custom_Field $cf - custom field of this type.
307 * @param mixed $compare - comparison operator.
308 * @param mixed $val - value to compare.
309 * @return string
310 */
311 public static function parse_filter( $cf, $compare, $val ) {
312
313 global $wpdb;
314 $column = self::get_sql_slug( $cf );
315 switch ( $compare ) {
316
317 case 'IN':
318 case 'NOT IN':
319 if ( ! is_array( $val ) || empty( $val ) ) {
320 return '1=0';
321 }
322
323 $values = array();
324
325 foreach ( $val as $item ) {
326 if ( is_string( $item ) && $item !== '' ) {
327 $values[] = wp_strip_all_tags( $item );
328 }
329 }
330
331 if ( empty( $values ) ) {
332 return '1=0';
333 }
334
335 $placeholders = implode( ', ', array_fill( 0, count( $values ), '%s' ) );
336 $operator = ( $compare === 'IN' ) ? 'IN' : 'NOT IN';
337
338 return $wpdb->prepare(
339 "CONVERT({$column} USING utf8) {$operator} ({$placeholders})",
340 $values
341 );
342
343 case 'LIKE':
344 if ( ! is_string( $val ) ) {
345 return '1=0';
346 }
347
348 $terms = array_filter(
349 array_map( 'trim', explode( PHP_EOL, $val ) )
350 );
351
352 $likes = array();
353 $args = array();
354
355 foreach ( $terms as $term ) {
356
357 $term = str_replace( '*', '%', $term );
358 $term = $wpdb->esc_like( $term );
359
360 if ( $term === '' ) {
361 continue;
362 }
363
364 $likes[] = "CONVERT({$column} USING utf8) LIKE %s";
365 $args[] = '%' . $term . '%';
366 }
367
368 if ( empty( $likes ) ) {
369 return '1=0';
370 }
371
372 return $wpdb->prepare(
373 '(' . implode( ' OR ', $likes ) . ')',
374 $args
375 );
376
377 default:
378 return '1=1';
379 }
380 }
381
382 /**
383 * Check ticket condition
384 *
385 * @param array $condition - array with condition data.
386 * @param WPSC_Custom_Field $cf - custom field object.
387 * @param WPSC_Ticket $ticket - ticket object.
388 * @return boolean
389 */
390 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
391
392 $flag = true;
393 $value = stripslashes( $ticket->{$cf->slug} );
394 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
395
396 switch ( $condition['operator'] ) {
397
398 case 'IN':
399 $flag = false;
400 foreach ( $terms as $term ) {
401 $term = trim( $term );
402 if ( $term == $value ) {
403 $flag = true;
404 break;
405 }
406 }
407 break;
408
409 case 'NOT IN':
410 foreach ( $terms as $term ) {
411 $term = trim( $term );
412 if ( $term == $value ) {
413 $flag = false;
414 break;
415 }
416 }
417 break;
418
419 case 'LIKE':
420 $flag = false;
421 foreach ( $terms as $term ) {
422 $index = strpos( $value, trim( stripslashes( $term ) ) );
423 if ( is_numeric( $index ) ) {
424 $flag = true;
425 break;
426 }
427 }
428 break;
429
430 default:
431 $flag = true;
432 }
433
434 return $flag;
435 }
436
437 /**
438 * Check customer condition
439 *
440 * @param array $condition - array with condition data.
441 * @param WPSC_Custom_Field $cf - custom field object.
442 * @param WPSC_Customer $customer - customer object.
443 * @return boolean
444 */
445 public static function is_valid_customer_condition( $condition, $cf, $customer ) {
446
447 $flag = true;
448 $value = stripslashes( $customer->{$cf->slug} );
449 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
450
451 switch ( $condition['operator'] ) {
452
453 case 'IN':
454 $flag = false;
455 foreach ( $terms as $term ) {
456 $term = trim( $term );
457 if ( $term == $value ) {
458 $flag = true;
459 break;
460 }
461 }
462 break;
463
464 case 'NOT IN':
465 foreach ( $terms as $term ) {
466 $term = trim( $term );
467 if ( $term == $value ) {
468 $flag = false;
469 break;
470 }
471 }
472 break;
473
474 case 'LIKE':
475 $flag = false;
476 foreach ( $terms as $term ) {
477 $index = strpos( $value, trim( stripslashes( $term ) ) );
478 if ( is_numeric( $index ) ) {
479 $flag = true;
480 break;
481 }
482 }
483 break;
484
485 default:
486 $flag = true;
487 }
488
489 return $flag;
490 }
491
492 /**
493 * Print ticket form field
494 *
495 * @param WPSC_Custom_Field $cf - Custom field object.
496 * @param array $tff - Array of ticket form field settings for this field.
497 * @return string
498 */
499 public static function print_tff( $cf, $tff ) {
500
501 $val = '';
502 if ( $cf->field == 'ticket' ) {
503 $val = $cf->is_auto_fill && $cf->default_value ? $cf->default_value[0] : '';
504 } else {
505 $current_user = WPSC_Current_User::$current_user;
506 $val = $current_user->is_customer && $current_user->customer->{$cf->slug} ? $current_user->customer->{$cf->slug} : '';
507 }
508
509 ob_start();
510 ?>
511 <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 ); ?>">
512 <div class="wpsc-tff-label">
513 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
514 <?php
515 if ( $tff['is-required'] ) {
516 ?>
517 <span class="required-indicator">*</span>
518 <?php
519 }
520 ?>
521 </div>
522 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
523 <textarea
524 type="text"
525 name="<?php echo esc_attr( $cf->slug ); ?>"
526 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
527 onchange="wpsc_check_tff_visibility()"
528 maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>"
529 autocomplete="off"><?php echo esc_attr( $val ); ?></textarea>
530 </div>
531 <?php
532 return ob_get_clean();
533 }
534
535 /**
536 * Validate this type field in create ticket
537 *
538 * @return void
539 */
540 public static function js_validate_ticket_form() {
541 ?>
542
543 case '<?php echo esc_attr( self::$slug ); ?>':
544 var val = customField.find('textarea').first().val().trim();
545 if (isRequired && !val) {
546 isValid = false;
547 }
548 break;
549 <?php
550 echo PHP_EOL;
551 }
552
553 /**
554 * Return custom field value in $_POST
555 * Ignore phpcs nonce issue as we already checked where it is called from.
556 *
557 * @param string $slug - Custom field slug.
558 * @param mixed $cf - Custom field object or false.
559 * @return mixed
560 */
561 public static function get_tff_value( $slug, $cf = false ) {
562
563 return isset( $_POST[ $slug ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
564 }
565
566 /**
567 * Return default value for custom field of this type
568 *
569 * @param WPSC_Custom_Field $cf - custom field object.
570 * @return mixed
571 */
572 public static function get_default_value( $cf ) {
573
574 return $cf->default_value ? $cf->default_value[0] : '';
575 }
576
577 /**
578 * Check and return custom field value for new ticket to be created.
579 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
580 * Ignore phpcs nonce issue as we already checked where it is called from.
581 *
582 * @param array $data - Array of values to to stored in ticket in an insert function.
583 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
584 * @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.
585 * @return array
586 */
587 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
588
589 if ( isset( $custom_fields[ self::$slug ] ) ) {
590 foreach ( $custom_fields[ self::$slug ] as $cf ) {
591 $value = self::get_tff_value( $cf->slug );
592
593 if (
594 $cf->char_limit && mb_strlen( $value ) > $cf->char_limit
595 ) {
596 wp_send_json_error( new WP_Error( 'WPSC_CF_Textarea', 'Character limit exceed!!' ), 400 );
597 }
598
599 if ( $cf->field == 'ticket' ) {
600
601 $default_val = self::get_default_value( $cf );
602 $data[ $cf->slug ] = $value ? $value : $default_val;
603
604 } elseif ( $cf->field == 'agentonly' ) {
605
606 $data[ $cf->slug ] = self::get_default_value( $cf );
607
608 } elseif ( $cf->field == 'customer' && $data['customer'] != 0 ) {
609
610 $tff = get_option( 'wpsc-tff' );
611 if ( ! $is_my_profile && ! isset( $tff[ $cf->slug ] ) ) {
612 continue;
613 }
614
615 $customer = new WPSC_Customer( $data['customer'] );
616 $prev_val = $customer->{$cf->slug};
617
618 if ( $customer->{$cf->slug} != $value ) {
619 $customer->{$cf->slug} = $value;
620 $customer->save();
621
622 // Set log for this change.
623 WPSC_Log::insert(
624 array(
625 'type' => 'customer',
626 'ref_id' => $customer->id,
627 'modified_by' => WPSC_Current_User::$current_user->customer->id,
628 'body' => wp_json_encode(
629 array(
630 'slug' => $cf->slug,
631 'prev' => $prev_val,
632 'new' => $value,
633 )
634 ),
635 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
636 )
637 );
638 }
639 }
640 }
641 }
642 return $data;
643 }
644
645 /**
646 * Set create ticket data for rest api request
647 *
648 * @param array $data - create ticket data array.
649 * @param WP_REST_Request $request - rest request object.
650 * @param array $custom_fields - custom field objects indexed by unique custom field types.
651 * @return array
652 */
653 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
654
655 $current_user = WPSC_Current_User::$current_user;
656 $tff = get_option( 'wpsc-tff' );
657
658 if ( isset( $custom_fields[ self::$slug ] ) ) {
659 foreach ( $custom_fields[ self::$slug ] as $cf ) {
660
661 if (
662 ! in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) ||
663 ( $cf->field == 'customer' && ! isset( $tff[ $cf->slug ] ) )
664 ) {
665 continue;
666 }
667
668 $value = sanitize_textarea_field( $request->get_param( $cf->slug ) );
669
670 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ) {
671
672 $data[ $cf->slug ] = $cf->field == 'ticket' && $value ? $value : self::get_default_value( $cf );
673
674 } else {
675
676 $customer = new WPSC_Customer( $data['customer'] );
677 $existing_val = $customer->{$cf->slug};
678
679 if ( $value && $value != $existing_val ) {
680
681 $customer->{$cf->slug} = $value;
682 $customer->save();
683
684 // Set log for this change.
685 WPSC_Log::insert(
686 array(
687 'type' => 'customer',
688 'ref_id' => $customer->id,
689 'modified_by' => $current_user->customer->id,
690 'body' => wp_json_encode(
691 array(
692 'slug' => $cf->slug,
693 'prev' => $existing_val,
694 'new' => $value,
695 )
696 ),
697 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
698 )
699 );
700 }
701 }
702 }
703 }
704
705 return $data;
706 }
707
708 /**
709 * Return slug string to be used in where condition of ticket model for this type of field
710 *
711 * @param WPSC_Custom_Field $cf - custom field object.
712 * @return string
713 */
714 public static function get_sql_slug( $cf ) {
715
716 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
717 return $join_char . $cf->slug;
718 }
719
720 /**
721 * Add ticket search compatibility for fields of this custom field type.
722 *
723 * @param array $sql - Array of sql peices that can be joined later.
724 * @param array $filter - User filter.
725 * @param array $custom_fields - Custom fields array applicable for search.
726 * @param string $search - search string.
727 * @param array $allowed_search_fields - Allowed search fields.
728 * @return array
729 */
730 public static function ticket_search( $sql, $filter, $custom_fields, $search, $allowed_search_fields ) {
731
732 if ( isset( $custom_fields[ self::$slug ] ) ) {
733 foreach ( $custom_fields[ self::$slug ] as $cf ) {
734 if ( in_array( $cf->slug, $allowed_search_fields ) ) {
735
736 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
737 $sql[] = 'CONVERT(' . $join_char . $cf->slug . ' USING utf8) LIKE \'%' . $search . '%\'';
738 }
739 }
740 }
741
742 return $sql;
743 }
744
745 /**
746 * Return val field for meta query of this type of custom field
747 *
748 * @param array $condition - condition data.
749 * @return mixed
750 */
751 public static function get_meta_value( $condition ) {
752
753 $operator = $condition['operator'];
754 switch ( $operator ) {
755
756 case 'IN':
757 case 'NOT IN':
758 $val = explode( PHP_EOL, $condition['operand_val_1'] );
759 $temp_val = array();
760 foreach ( $val as $value ) {
761 $value = trim( $value );
762 if ( $value ) {
763 $temp_val[] = $value;
764 }
765 }
766 return $temp_val ? $temp_val : false;
767
768 case 'LIKE':
769 return trim( $condition['operand_val_1'] );
770 }
771 return false;
772 }
773
774 /**
775 * Print generic input field for this type.
776 *
777 * @param WPSC_Custom_Field $cf - Custom field object.
778 * @param mixed $value - optional. Input field will be printed with given value if given.
779 * @return void
780 */
781 public static function print_cf_input( $cf, $value = '' ) {
782
783 ?>
784 <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 ); ?>">
785 <div class="wpsc-tff-label">
786 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
787 </div>
788 <?php
789 $extra_info = stripslashes( $cf->extra_info );
790 if ( $extra_info ) :
791 ?>
792 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
793 <?php
794 endif
795 ?>
796 <textarea
797 type="text"
798 name="<?php echo esc_attr( $cf->slug ); ?>"
799 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
800 maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>"
801 autocomplete="off"><?php echo esc_attr( $value ); ?></textarea>
802 </div>
803 <?php
804 }
805
806 /**
807 * Get value for generic field from post.
808 * Ignore phpcs nonce issue as we already checked where it is called from.
809 *
810 * @param WPSC_Custom_Field $cf - custom field object.
811 * @return string
812 */
813 public static function get_cf_input_val( $cf ) {
814
815 return isset( $_POST[ $cf->slug ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
816 }
817
818 /**
819 * Print edit ticket custom field in individual ticket
820 *
821 * @param WPSC_Custom_Field $cf - custom field object.
822 * @param WPSC_Ticket $ticket - ticket object.
823 * @return void
824 */
825 public static function print_edit_ticket_cf( $cf, $ticket ) {
826
827 ?>
828 <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 ); ?>">
829 <div class="wpsc-tff-label">
830 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
831 </div>
832 <?php
833 $extra_info = stripslashes( $cf->extra_info );
834 if ( $extra_info ) :
835 ?>
836 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
837 <?php
838 endif
839 ?>
840 <textarea
841 type="text"
842 name="<?php echo esc_attr( $cf->slug ); ?>"
843 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
844 maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>"
845 autocomplete="off"><?php echo esc_attr( $ticket->{$cf->slug} ); ?></textarea>
846 </div>
847 <?php
848 }
849
850 /**
851 * Set edit individual ticket for this custom field type.
852 * Ignore phpcs nonce issue as we already checked where it is called from.
853 *
854 * @param WPSC_Custom_Field $cf - custom field object.
855 * @param WPSC_Ticket $ticket - ticket object.
856 * @return WPSC_Ticket
857 */
858 public static function set_edit_ticket_cf( $cf, $ticket ) {
859
860 $prev = $ticket->{$cf->slug} ? $ticket->{$cf->slug} : '';
861 $new = isset( $_POST[ $cf->slug ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
862
863 // Exit if there is no change.
864 if ( $prev == $new ) {
865 return $ticket;
866 }
867
868 // Change value.
869 $ticket->{$cf->slug} = $new;
870 $ticket->save();
871
872 return $ticket;
873 }
874
875 /**
876 * Modify ticket field value of this custom field type using rest api
877 *
878 * @param WPSC_Ticket $ticket - ticket object.
879 * @param WPSC_Custom_Field $cf - custom field.
880 * @param mixed $value - value to be set.
881 * @return void
882 */
883 public static function set_rest_edit_ticket_cf( $ticket, $cf, $value ) {
884
885 $value = sanitize_textarea_field( $value );
886 if ( $ticket->{$cf->slug} != $value ) {
887 $ticket->{$cf->slug} = $value;
888 }
889 }
890
891 /**
892 * Insert log thread for this custom field type change
893 *
894 * @param WPSC_Custom_Field $cf - current custom field of this type.
895 * @param WPSC_Ticket $prev - ticket object before making any changes.
896 * @param WPSC_Ticket $new - ticket object after making changes.
897 * @param string $current_date - date string to be stored as create time.
898 * @param int $customer_id - current user customer id for blame.
899 * @return void
900 */
901 public static function insert_ticket_log( $cf, $prev, $new, $current_date, $customer_id ) {
902
903 // Exit if there is no change.
904 if ( $prev->{$cf->slug} == $new->{$cf->slug} ) {
905 return;
906 }
907
908 $prev_val = htmlspecialchars( $prev->{$cf->slug}, ENT_QUOTES );
909 $new_val = htmlspecialchars( $new->{$cf->slug}, ENT_QUOTES );
910
911 $thread = WPSC_Thread::insert(
912 array(
913 'ticket' => $prev->id,
914 'customer' => $customer_id,
915 'type' => 'log',
916 'body' => wp_json_encode(
917 array(
918 'slug' => $cf->slug,
919 'prev' => $prev_val,
920 'new' => $new_val,
921 )
922 ),
923 'date_created' => $current_date,
924 'date_updated' => $current_date,
925 )
926 );
927 }
928
929 /**
930 * Return data for this custom field while creating duplicate ticket
931 *
932 * @param WPSC_Custom_Field $cf - custom field object.
933 * @param WPSC_Ticket $ticket - ticket object.
934 * @return mixed
935 */
936 public static function get_duplicate_ticket_data( $cf, $ticket ) {
937
938 return $ticket->{$cf->slug};
939 }
940
941 /**
942 * Print edit field for this type in edit customer info
943 *
944 * @param WPSC_Custom_field $cf - custom field object.
945 * @param WPSC_Customer $customer - customer object.
946 * @param array $tff - ticket form field data.
947 * @return string
948 */
949 public static function print_edit_customer_info( $cf, $customer, $tff ) {
950
951 $val = $customer->id && $customer->{$cf->slug} ? stripslashes( htmlspecialchars( $customer->{$cf->slug} ) ) : '';
952
953 ob_start();
954 ?>
955 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
956 <div class="wpsc-tff-label">
957 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
958 </div>
959 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
960 <textarea
961 type="text"
962 name="<?php echo esc_attr( $cf->slug ); ?>"
963 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
964 maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>"
965 autocomplete="off"><?php echo esc_attr( $val ); ?></textarea>
966 </div>
967 <?php
968 return ob_get_clean();
969 }
970
971 /**
972 * Print add new custom field setting properties
973 *
974 * @param string $field_class - Class name of the field.
975 * @return void
976 */
977 public static function get_add_new_custom_field_properties( $field_class ) {
978
979 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
980 ?>
981 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
982 <div class="label-container">
983 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
984 </div>
985 <input name="extra_info" type="text" autocomplete="off" />
986 </div>
987 <?php
988 endif;
989
990 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
991 ?>
992 <div data-type="textarea" data-required="false" class="wpsc-input-group default_value">
993 <div class="label-container">
994 <label for="">
995 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
996 </label>
997 </div>
998 <textarea name="default_value" autocomplete="off"></textarea>
999 </div>
1000 <?php
1001 endif;
1002
1003 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1004 ?>
1005 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1006 <div class="label-container">
1007 <label for="">
1008 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1009 </label>
1010 </div>
1011 <select name="is_auto_fill">
1012 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1013 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1014 </select>
1015 </div>
1016 <?php
1017 endif;
1018
1019 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) :
1020 ?>
1021 <div data-type="number" data-required="false" class="wpsc-input-group char_limit">
1022 <div class="label-container">
1023 <label for="">
1024 <?php esc_attr_e( 'Character limit', 'supportcandy' ); ?>
1025 </label>
1026 </div>
1027 <input type="number" name="char_limit" autocomplete="off">
1028 </div>
1029 <?php
1030 endif;
1031
1032 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1033 ?>
1034 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1035 <div class="label-container">
1036 <label for="">
1037 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1038 </label>
1039 </div>
1040 <input type="text" name="placeholder_text" autocomplete="off">
1041 </div>
1042 <?php
1043 endif;
1044
1045 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1046 ?>
1047 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1048 <div class="label-container">
1049 <label for="">
1050 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1051 </label>
1052 </div>
1053 <select name="is_personal_info">
1054 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1055 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1056 </select>
1057 </div>
1058 <?php
1059 endif;
1060
1061 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1062 ?>
1063 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1064 <div class="label-container">
1065 <label for="">
1066 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1067 </label>
1068 </div>
1069 <select name="allow_my_profile">
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_ticket_form', $field_class::$allowed_properties ) ) :
1078 ?>
1079 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1080 <div class="label-container">
1081 <label for="">
1082 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1083 </label>
1084 </div>
1085 <select name="allow_ticket_form">
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
1094 /**
1095 * Print edit custom field properties
1096 *
1097 * @param WPSC_Custom_Fields $cf - custom field object.
1098 * @param string $field_class - class name of field category.
1099 * @return void
1100 */
1101 public static function get_edit_custom_field_properties( $cf, $field_class ) {
1102
1103 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
1104 ?>
1105 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
1106 <div class="label-container">
1107 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
1108 </div>
1109 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
1110 </div>
1111 <?php
1112 endif;
1113
1114 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
1115 $default_val = $cf->default_value ? $cf->default_value[0] : '';
1116 ?>
1117 <div data-type="textarea" data-required="false" class="wpsc-input-group default_value">
1118 <div class="label-container">
1119 <label for="">
1120 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
1121 </label>
1122 </div>
1123 <textarea name="default_value" autocomplete="off"><?php echo $default_val ? esc_attr( $default_val ) : ''; ?></textarea>
1124 </div>
1125 <?php
1126 endif;
1127
1128 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1129 ?>
1130 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1131 <div class="label-container">
1132 <label for="">
1133 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1134 </label>
1135 </div>
1136 <select name="is_auto_fill">
1137 <option <?php selected( $cf->is_auto_fill, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1138 <option <?php selected( $cf->is_auto_fill, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1139 </select>
1140 </div>
1141 <?php
1142 endif;
1143
1144 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) :
1145 ?>
1146 <div data-type="number" data-required="false" class="wpsc-input-group char_limit">
1147 <div class="label-container">
1148 <label for="">
1149 <?php esc_attr_e( 'Character limit', 'supportcandy' ); ?>
1150 </label>
1151 </div>
1152 <input type="number" name="char_limit" value="<?php echo intval( $cf->char_limit ); ?>" autocomplete="off">
1153 </div>
1154 <?php
1155 endif;
1156
1157 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1158 ?>
1159 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1160 <div class="label-container">
1161 <label for="">
1162 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1163 </label>
1164 </div>
1165 <input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off">
1166 </div>
1167 <?php
1168 endif;
1169
1170 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1171 ?>
1172 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1173 <div class="label-container">
1174 <label for="">
1175 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1176 </label>
1177 </div>
1178 <select name="is_personal_info">
1179 <option <?php selected( $cf->is_personal_info, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1180 <option <?php selected( $cf->is_personal_info, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1181 </select>
1182 </div>
1183 <?php
1184 endif;
1185
1186 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1187 ?>
1188 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1189 <div class="label-container">
1190 <label for="">
1191 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1192 </label>
1193 </div>
1194 <select name="allow_my_profile">
1195 <option <?php selected( $cf->allow_my_profile, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1196 <option <?php selected( $cf->allow_my_profile, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1197 </select>
1198 </div>
1199 <?php
1200 endif;
1201
1202 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) :
1203 ?>
1204 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1205 <div class="label-container">
1206 <label for="">
1207 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1208 </label>
1209 </div>
1210 <select name="allow_ticket_form">
1211 <option <?php selected( $cf->allow_ticket_form, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1212 <option <?php selected( $cf->allow_ticket_form, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1213 </select>
1214 </div>
1215 <?php
1216 endif;
1217 }
1218
1219 /**
1220 * Set custom field properties. Can be used by add/edit custom field.
1221 * Ignore phpcs nonce issue as we already checked where it is called from.
1222 *
1223 * @param WPSC_Custom_Field $cf - custom field object.
1224 * @param string $field_class - class of field category.
1225 * @return void
1226 */
1227 public static function set_cf_properties( $cf, $field_class ) {
1228
1229 // extra info.
1230 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
1231 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
1232 }
1233
1234 // default value.
1235 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
1236 $default_value = isset( $_POST['default_value'] ) ? sanitize_textarea_field( wp_unslash( $_POST['default_value'] ) ) : ''; // phpcs:ignore
1237 $cf->default_value = $default_value ? array( $default_value ) : array();
1238 }
1239
1240 // auto fill.
1241 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) {
1242 $cf->is_auto_fill = isset( $_POST['is_auto_fill'] ) ? sanitize_text_field( wp_unslash( $_POST['is_auto_fill'] ) ) : ''; // phpcs:ignore
1243 }
1244
1245 // char limit.
1246 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) {
1247 $cf->char_limit = isset( $_POST['char_limit'] ) ? intval( $_POST['char_limit'] ) : 0; //phpcs:ignore
1248 }
1249
1250 // check whether char limit is honored by default value.
1251 if ( $cf->default_value && $cf->char_limit && count( $cf->default_value ) > $cf->char_limit ) {
1252 wp_send_json_error( 'Incorrect request!', 400 );
1253 }
1254
1255 // placeholder!
1256 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) {
1257 $cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore
1258 }
1259
1260 // personal info.
1261 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) {
1262 $cf->is_personal_info = isset( $_POST['is_personal_info'] ) ? intval( $_POST['is_personal_info'] ) : 0; // phpcs:ignore
1263 }
1264
1265 // my-profile.
1266 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) {
1267 $cf->allow_my_profile = isset( $_POST['allow_my_profile'] ) ? intval( $_POST['allow_my_profile'] ) : 0; // phpcs:ignore
1268 }
1269
1270 // ticket form.
1271 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) {
1272 $cf->allow_ticket_form = isset( $_POST['allow_ticket_form'] ) ? intval( $_POST['allow_ticket_form'] ) : 0; // phpcs:ignore
1273 }
1274
1275 // save!
1276 $cf->save();
1277 }
1278
1279 /**
1280 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
1281 *
1282 * @param WPSC_Custom_Field $cf - custom field object.
1283 * @param WPSC_Ticket $ticket - ticket object.
1284 * @param string $module - module name.
1285 * @return string
1286 */
1287 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
1288
1289 return apply_filters( 'wpsc_ticket_field_val_textarea', $ticket->{$cf->slug}, $cf, $ticket, $module );
1290 }
1291
1292 /**
1293 * Print ticket value for given custom field on widget
1294 *
1295 * @param WPSC_Custom_Field $cf - custom field object.
1296 * @param WPSC_Ticket $ticket - ticket object.
1297 * @return void
1298 */
1299 public static function print_widget_ticket_field_val( $cf, $ticket ) {
1300
1301 $val = $ticket->{$cf->slug};
1302 if ( ! $val ) {
1303 return;
1304 }
1305
1306 $unique_id = uniqid( 'wpsc_' );
1307
1308 ?>
1309 <div class="<?php echo esc_attr( $unique_id ); ?>">
1310 <?php echo wp_kses_post( str_replace( PHP_EOL, '<br/>', esc_html( $val ) ) ); ?>
1311 </div>
1312 <script>jQuery('.<?php echo esc_attr( $unique_id ); ?>').parent().addClass('fullwidth');</script>
1313 <?php
1314 }
1315
1316 /**
1317 * Returns printable customer value for custom field. Can be used in export tickets, replace macros etc.
1318 *
1319 * @param WPSC_Custom_Field $cf - custom field object.
1320 * @param WPSC_Customer $customer - customer object.
1321 * @return string
1322 */
1323 public static function get_customer_field_val( $cf, $customer ) {
1324
1325 return $customer->{$cf->slug};
1326 }
1327
1328 /**
1329 * Print customer value for given custom field on widget
1330 *
1331 * @param WPSC_Custom_Field $cf - custom field object.
1332 * @param WPSC_Customer $customer - customer object.
1333 * @return void
1334 */
1335 public static function print_widget_customer_field_val( $cf, $customer ) {
1336
1337 $val = $customer->{$cf->slug};
1338 if ( ! $val ) {
1339 return;
1340 }
1341
1342 $unique_id = uniqid( 'wpsc_' );
1343
1344 ?>
1345 <div class="<?php echo esc_attr( $unique_id ); ?>">
1346 <?php echo wp_kses_post( str_replace( PHP_EOL, '<br/>', esc_html( $val ) ) ); ?>
1347 </div>
1348 <script>jQuery('.<?php echo esc_attr( $unique_id ); ?>').parent().addClass('fullwidth');</script>
1349 <?php
1350 }
1351
1352 /**
1353 * Print given value for custom field
1354 *
1355 * @param WPSC_Custom_Field $cf - custom field object.
1356 * @param mixed $val - value to convert and print.
1357 * @return void
1358 */
1359 public static function print_val( $cf, $val ) {
1360
1361 if ( ! $val ) {
1362 esc_attr_e( 'None', 'supportcandy' );
1363 return;
1364 }
1365
1366 echo wp_kses_post( str_replace( PHP_EOL, '<br/>', esc_html( $val ) ) );
1367 }
1368
1369 /**
1370 * Return printable value for history log macro
1371 *
1372 * @param WPSC_Custom_Field $cf - custom field object.
1373 * @param mixed $val - value to convert and return.
1374 * @return string
1375 */
1376 public static function get_history_log_val( $cf, $val ) {
1377
1378 return $val ? str_replace( PHP_EOL, '<br/>', esc_html( $val ) ) : esc_attr__( 'None', 'supportcandy' );
1379 }
1380
1381 /**
1382 * Print dashboard activity function
1383 *
1384 * @param WPSC_Custom_Field $cf - custom field object.
1385 * @param array $recent_logs - recent_logs object.
1386 * @param array $body - body object.
1387 * @param int $view - check if frontend.
1388 * @return string
1389 */
1390 public static function print_activity( $cf, $recent_logs, $body, $view ) {
1391
1392 $url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view );
1393 if ( $body->new ) {
1394 $ta_value = $body->new;
1395 } else {
1396 $ta_value = 'None';
1397 }
1398 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 ' . esc_attr( $ta_value );
1399 }
1400
1401 /**
1402 * Return given value for custom field
1403 *
1404 * @param WPSC_Custom_Field $cf - custom field object.
1405 * @param mixed $val - value to convert and print.
1406 * @return string
1407 */
1408 public static function get_field_value( $cf, $val ) {
1409
1410 return $val ? wp_kses_post( str_replace( PHP_EOL, '<br/>', esc_html( $val ) ) ) : esc_attr__( 'None', 'supportcandy' );
1411 }
1412
1413 /**
1414 * Clear value of hidden fields
1415 *
1416 * @return void
1417 */
1418 public static function js_clear_value_hidden_fields() {
1419 ?>
1420 case '<?php echo esc_attr( self::$slug ); ?>':
1421 customField.find('textarea').first().val('');
1422 break;
1423 <?php
1424 echo PHP_EOL;
1425 }
1426 }
1427 endif;
1428
1429 WPSC_CF_Textarea::init();
1430