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

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