PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.7
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.3.7, at includes/custom-field-types/class-wpsc-cf-url.php

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