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-df-description.php

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

766 lines 22.9 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_DF_Description' ) ) :
7
8 final class WPSC_DF_Description {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_description';
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 * Set whether this custom field type has reference to other class
40 *
41 * @var boolean
42 */
43 public static $has_ref = false;
44
45 /**
46 * 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.
47 *
48 * @var string
49 */
50 public static $ref_class = '';
51
52 /**
53 * Set whether this custom field field type is system default (no fields can be created from it).
54 *
55 * @var boolean
56 */
57 public static $is_default = true;
58
59 /**
60 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
61 *
62 * @var boolean
63 */
64 public static $has_extra_info = true;
65
66 /**
67 * Set whether this custom field type can accept personal info.
68 *
69 * @var boolean
70 */
71 public static $has_personal_info = false;
72
73 /**
74 * Set whether fields created from this custom field type is allowed in create ticket form
75 *
76 * @var boolean
77 */
78 public static $is_ctf = true;
79
80 /**
81 * Set whether fields created from this custom field type is allowed in ticket list
82 *
83 * @var boolean
84 */
85 public static $is_list = false;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket filter
89 *
90 * @var boolean
91 */
92 public static $is_filter = true;
93
94 /**
95 * Set whether fields created from this custom field type can be given character limits
96 *
97 * @var boolean
98 */
99 public static $has_char_limit = false;
100
101 /**
102 * Set whether fields created from this custom field type has custom options set in options table
103 *
104 * @var boolean
105 */
106 public static $has_options = false;
107
108 /**
109 * Set whether fields created from this custom field type can be auto-filled
110 *
111 * @var boolean
112 */
113 public static $is_auto_fill = true;
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 have placeholder
124 *
125 * @var boolean
126 */
127 public static $is_placeholder = false;
128
129 /**
130 * Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form
131 *
132 * @var boolean
133 */
134 public static $is_visibility_conditions = true;
135
136 /**
137 * Set whether fields created from this custom field type is applicable for macros
138 *
139 * @var boolean
140 */
141 public static $has_macro = true;
142
143 /**
144 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
145 * threads type is already available, no need to use this specific type.
146 *
147 * @var boolean
148 */
149 public static $is_search = false;
150
151 /**
152 * Initialize the class
153 *
154 * @return void
155 */
156 public static function init() {
157
158 // Get object of this class.
159 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
160
161 // JS events.
162 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
163 add_action( 'wpsc_js_create_ticket_formdata', array( __CLASS__, 'js_create_ticket_formdata' ) );
164 add_action( 'wpsc_js_clear_value_hidden_fields', array( __CLASS__, 'js_clear_value_hidden_fields' ) );
165
166 // create ticket form.
167 add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 );
168
169 // create ticket data for rest api.
170 add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 );
171
172 // Add ticket id to description attachments.
173 add_action( 'wpsc_create_new_ticket', array( __CLASS__, 'add_attachment_ticket_id' ), 1 );
174
175 // Set custom field type.
176 add_filter( 'wpsc_default_cf_types', array( __CLASS__, 'default_cf_types' ), 4 );
177 }
178
179 /**
180 * Load current class to reference classes
181 *
182 * @param array $classes - Associative array of class names indexed by its slug.
183 * @return array
184 */
185 public static function load_ref_class( $classes ) {
186
187 $classes[ self::$slug ] = array(
188 'class' => __CLASS__,
189 'save-key' => 'id',
190 );
191 return $classes;
192 }
193
194 /**
195 * Add default custom field type to list
196 *
197 * @param array $default_cf_types - default custom field types array.
198 * @return array
199 */
200 public static function default_cf_types( $default_cf_types ) {
201 $default_cf_types[ self::$slug ] = array(
202 'label' => esc_attr__( 'Description', 'supportcandy' ),
203 'class' => __CLASS__,
204 );
205 return $default_cf_types;
206 }
207
208 /**
209 * Print operators for ticket form filter
210 *
211 * @param WPSC_Custom_Field $cf - custom field object.
212 * @param array $filter - Existing filters (if any).
213 * @return void
214 */
215 public static function get_operators( $cf, $filter = array() ) {
216 ?>
217
218 <div class="item conditional">
219 <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' ) ); ?>');">
220 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
221 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
222 </select>
223 </div>
224 <?php
225 }
226
227 /**
228 * Print operators for ticket form filter
229 *
230 * @param string $operator - condition operator on which operands should be returned.
231 * @param WPSC_Custom_Field $cf - custom field object.
232 * @param array $filter - Exising functions (if any).
233 * @return void
234 */
235 public static function get_operands( $operator, $cf, $filter = array() ) {
236
237 $value = isset( $filter['operand_val_1'] ) ? stripslashes( $filter['operand_val_1'] ) : ''
238 ?>
239 <div class="item conditional operand single">
240 <textarea class="operand_val_1" placeholder="<?php esc_attr_e( 'One condition per line!', 'supportcandy' ); ?>" style="width: 100%;"><?php echo esc_attr( $value ); ?></textarea>
241 </div>
242 <?php
243 }
244
245 /**
246 * Check condition for this type
247 *
248 * @param array $condition - condition data.
249 * @param WPSC_Custom_Field $cf - custom field object.
250 * @param mixed $value - value to compare.
251 * @return boolean
252 */
253 public static function is_valid( $condition, $cf, $value ) {
254
255 $response = false;
256 $value = stripslashes( $value );
257 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
258 $response = false;
259 foreach ( $terms as $term ) {
260 $index = strpos( $value, trim( stripslashes( $term ) ) );
261 if ( is_numeric( $index ) ) {
262 $response = true;
263 break;
264 }
265 }
266 return $response;
267 }
268
269 /**
270 * Parse filter and return sql query to be merged in ticket model query builder
271 *
272 * @param WPSC_Custom_Field $cf - custom field of this type.
273 * @param mixed $compare - comparison operator.
274 * @param mixed $val - value to compare.
275 * @return string
276 */
277 public static function parse_filter( $cf, $compare, $val ) {
278
279 if ( $compare !== 'LIKE' || empty( $val ) ) {
280 return '1=1';
281 }
282
283 global $wpdb;
284 $column = 'CONVERT(th.body USING utf8)';
285 $terms = preg_split( '/\R/', (string) $val );
286 $likes = array();
287
288 foreach ( $terms as $term ) {
289
290 $term = trim( $term );
291 if ( $term === '' ) {
292 continue;
293 }
294
295 $term = str_replace( '*', '%', $term );
296 $term = $wpdb->esc_like( $term );
297
298 $likes[] = $wpdb->prepare(
299 "$column LIKE %s",
300 '%' . $term . '%'
301 );
302 }
303
304 return empty( $likes )
305 ? '1=0'
306 : '(' . implode( ' OR ', $likes ) . ')';
307 }
308
309 /**
310 * Check ticket condition
311 *
312 * @param array $condition - array with condition data.
313 * @param WPSC_Custom_Field $cf - custom field object.
314 * @param WPSC_Ticket $ticket - ticket object.
315 * @return boolean
316 */
317 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
318
319 $filters = array(
320 'meta_query' => array(
321 'relation' => 'AND',
322 array(
323 'slug' => 'ticket',
324 'compare' => '=',
325 'val' => $ticket->id,
326 ),
327 array(
328 'slug' => 'type',
329 'compare' => '=',
330 'val' => 'report',
331 ),
332 ),
333 );
334 $threads = WPSC_Thread::find( $filters );
335 $thread = isset( $threads['results'][0] ) ? $threads['results'][0] : array();
336
337 if ( $thread && $thread->is_active ) {
338
339 $value = stripslashes( $thread->body );
340 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
341 $response = false;
342 foreach ( $terms as $term ) {
343 $index = strpos( $value, trim( stripslashes( $term ) ) );
344 if ( is_numeric( $index ) ) {
345 $response = true;
346 break;
347 }
348 }
349 return $response;
350
351 } else {
352
353 return false;
354 }
355 }
356
357 /**
358 * Print ticket form field
359 *
360 * @param WPSC_Custom_Field $cf - Custom field object.
361 * @param array $tff - Array of ticket form field settings for this field.
362 * @return string
363 */
364 public static function print_tff( $cf, $tff ) {
365
366 $unique_id = uniqid( 'wpsc_' );
367 $val = $cf->is_auto_fill && $cf->default_value ? stripslashes( htmlspecialchars( $cf->default_value[0] ) ) : '';
368 $current_user = WPSC_Current_User::$current_user;
369
370 ob_start();
371 ?>
372 <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 ); ?>">
373 <div class="wpsc-tff-label">
374 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
375 <?php
376 if ( $tff['is-required'] ) {
377 ?>
378 <span class="required-indicator">*</span>
379 <?php
380 }
381 ?>
382 </div>
383 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
384 <textarea name="<?php echo esc_attr( $cf->slug ); ?>" id="description" class="wpsc_textarea" onchange="wpsc_check_tff_visibility();"><?php echo esc_attr( $val ); ?></textarea>
385 <input
386 class="<?php echo esc_attr( $unique_id ); ?>"
387 type="file"
388 onchange="wpsc_set_attach_multiple(this, '<?php echo esc_attr( $unique_id ); ?>', 'description_attachments')"
389 multiple
390 style="display: none;"/>
391 <div class="wpsc-it-editor-action-container">
392 <div class="actions">
393 <div class="wpsc-editor-actions">
394 <?php
395
396 if ( WPSC_Text_Editor::is_allow_attachments() ) {
397 ?>
398 <span class="wpsc-link wpsc-ct-attach" onclick="wpsc_trigger_desc_attachments('<?php echo esc_attr( $unique_id ); ?>');"><?php esc_attr_e( 'Attach Files', 'supportcandy' ); ?></span>
399 <?php
400 }
401
402 if ( $current_user->is_agent ) {
403 ?>
404 <span class="wpsc-link wpsc-ct-macro" onclick="wpsc_get_macros()"><?php esc_attr_e( 'Insert Macro', 'supportcandy' ); ?></span>
405 <?php
406 }
407
408 do_action( 'wpsc_tff_editor_actions' );
409
410 ?>
411 </div>
412
413 <?php
414 if ( WPSC_Text_Editor::is_attachment_notice() && WPSC_Text_Editor::is_allow_attachments() ) {
415 ?>
416 <div class="wpsc-file-attachment-notice"><?php echo esc_html( WPSC_Text_Editor::file_attachment_notice_text() ); ?></div>
417 <?php
418 }
419 ?>
420
421 <div class="<?php echo esc_attr( $unique_id ); ?> wpsc-editor-attachment-container"></div>
422
423 </div>
424 </div>
425 <script>
426 <?php WPSC_Text_Editor::print_editor_init_scripts( 'description', 'wpsc-description' ); ?>
427 </script>
428 </div>
429 <?php
430 return ob_get_clean();
431 }
432
433 /**
434 * Validate this type field in create ticket
435 *
436 * @return void
437 */
438 public static function js_validate_ticket_form() {
439 ?>
440
441 case '<?php echo esc_attr( self::$slug ); ?>':
442 var is_tinymce = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden();
443 var val = '';
444
445 if (is_tinymce && tinymce.get('description')) {
446 val = tinyMCE.get('description').getContent();
447 } else {
448 val = jQuery('#description').val().trim();
449 }
450
451 if (isRequired && !val) {
452 isValid = false;
453 }
454 break;
455 <?php
456 echo PHP_EOL;
457 }
458
459 /**
460 * Submit ticket FormData append of description
461 *
462 * @return void
463 */
464 public static function js_create_ticket_formdata() {
465
466 $cf = WPSC_Custom_Field::get_cf_by_slug( 'description' );
467
468 $tff = get_option( 'wpsc-tff', array() );
469 if ( array_key_exists( $cf->slug, $tff ) ) {
470 ?>
471 var is_tinymce = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden();
472 if (is_tinymce && tinymce.get('description')){
473 var description = tinyMCE.get('description').getContent();
474 } else {
475 var description = jQuery('#description').val().trim();
476 }
477 dataform.append('description', description);
478 <?php
479 echo PHP_EOL;
480 }
481 }
482
483 /**
484 * Return default value for custom field of this type
485 *
486 * @param WPSC_Custom_Field $cf - custom field object.
487 * @return mixed
488 */
489 public static function get_default_value( $cf ) {
490
491 return $cf->default_value ? stripslashes( $cf->default_value[0] ) : '';
492 }
493
494 /**
495 * Return custom field value in $_POST
496 * Ignore phpcs nonce issue as we already checked where it is called from.
497 *
498 * @param string $slug - Custom field slug.
499 * @param mixed $cf - Custom field object or false.
500 * @return mixed
501 */
502 public static function get_tff_value( $slug, $cf = false ) {
503
504 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
505 $default_val = self::get_default_value( $cf );
506 $description = isset( $_POST[ $slug ] ) ? wp_kses_post( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
507
508 // replace new line with br if no text editor.
509 $is_editor = isset( $_POST['is_editor'] ) ? intval( $_POST['is_editor'] ) : 0; // phpcs:ignore
510 if ( $description && ! $is_editor ) {
511 $description = nl2br( $description );
512 }
513
514 return $description ? $description : $default_val;
515 }
516
517 /**
518 * Check and return custom field value for new ticket to be created.
519 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
520 * Ignore phpcs nonce issue as we already checked where it is called from.
521 *
522 * @param array $data - Array of values to to stored in ticket in an insert function.
523 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
524 * @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.
525 * @return array
526 */
527 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
528
529 $data['description'] = self::get_tff_value( 'description' );
530 $description_attachments = isset( $_POST['description_attachments'] ) ? array_filter( array_map( 'intval', $_POST['description_attachments'] ) ) : array(); // phpcs:ignore
531 foreach ( $description_attachments as $key => $id ) {
532 $attachment = new WPSC_Attachment( $id );
533 // Only the uploader may bind their own, not-yet-bound attachment.
534 if ( ! WPSC_Attachment::can_claim( $attachment ) ) {
535 unset( $description_attachments[ $key ] );
536 continue;
537 }
538 $attachment->is_active = 1;
539 $attachment->save();
540 }
541 $data['description_attachments'] = $description_attachments ? implode( '|', $description_attachments ) : '';
542 return $data;
543 }
544
545 /**
546 * Set create ticket data for rest api request
547 *
548 * @param array $data - create ticket data array.
549 * @param WP_REST_Request $request - rest request object.
550 * @param array $custom_fields - custom field objects indexed by unique custom field types.
551 * @return array
552 */
553 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
554
555 $cf = WPSC_Custom_Field::get_cf_by_slug( 'description' );
556 $description = $request->get_param( 'description' );
557 $is_html = $description != wp_strip_all_tags( $description ) ? true : false;
558 $description = $is_html ? wp_kses_post( $description ) : str_replace( PHP_EOL, '<br />', $description );
559 $description = $description ? $description : self::get_default_value( $cf );
560
561 // check description is present.
562 if ( ! $description ) {
563 $data['errors']->add( 'req_fields_missing', 'description is missing!', 'description' );
564 return $data;
565 }
566
567 $data['description'] = $description;
568
569 // description attachments.
570 $attachments = sanitize_text_field( $request->get_param( 'description_attachments' ) );
571 if ( $attachments ) {
572 $attachments = implode(
573 '|',
574 array_filter(
575 array_map(
576 function ( $id ) {
577 $attachment = new WPSC_Attachment( intval( $id ) );
578 // Only the uploader may bind their own,
579 // not-yet-bound attachment.
580 if ( ! WPSC_Attachment::can_claim( $attachment ) ) {
581 return false;
582 }
583 $attachment->is_active = 1;
584 $attachment->save();
585 return $attachment->id;
586 },
587 explode( ',', $attachments )
588 )
589 )
590 );
591 }
592
593 $data['description_attachments'] = $attachments;
594 return $data;
595 }
596
597 /**
598 * Return val field for meta query of this type of custom field
599 *
600 * @param array $condition - condition data.
601 * @return mixed
602 */
603 public static function get_meta_value( $condition ) {
604
605 $operator = $condition['operator'];
606 switch ( $operator ) {
607
608 case 'LIKE':
609 return $condition['operand_val_1'];
610 }
611 return false;
612 }
613
614 /**
615 * Add ticket id to description attachments
616 *
617 * @param WPSC_Ticket $ticket - ticket object.
618 * @return void
619 */
620 public static function add_attachment_ticket_id( $ticket ) {
621
622 $thread = $ticket->get_description_thread();
623 foreach ( $thread->attachments as $attachment ) {
624 $attachment->ticket_id = $ticket->id;
625 $attachment->source = 'report';
626 $attachment->source_id = $thread->id;
627 $attachment->save();
628 }
629 }
630
631 /**
632 * Print edit custom field properties
633 *
634 * @param WPSC_Custom_Fields $cf - custom field object.
635 * @param string $field_class - class name of field category.
636 * @return void
637 */
638 public static function get_edit_custom_field_properties( $cf, $field_class ) {
639
640 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
641 ?>
642 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
643 <div class="label-container">
644 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
645 </div>
646 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
647 </div>
648 <?php
649 endif;
650
651 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
652 $default_val = $cf->default_value ? $cf->default_value[0] : '';
653 ?>
654 <div data-type="textarea" data-required="false" class="wpsc-input-group default_value">
655 <div class="label-container">
656 <label for="">
657 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
658 </label>
659 </div>
660 <textarea name="default_value" rows="5"><?php echo esc_attr( $default_val ); ?></textarea>
661 </div>
662 <?php
663 endif;
664
665 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
666 ?>
667 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
668 <div class="label-container">
669 <label for="">
670 <?php esc_html_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
671 </label>
672 </div>
673 <select name="is_auto_fill">
674 <option <?php selected( $cf->is_auto_fill, '0' ); ?> value="0"><?php esc_html_e( 'No', 'supportcandy' ); ?></option>
675 <option <?php selected( $cf->is_auto_fill, '1' ); ?> value="1"><?php esc_html_e( 'Yes', 'supportcandy' ); ?></option>
676 </select>
677 </div>
678 <?php
679 endif;
680 }
681
682 /**
683 * Set custom field properties. Can be used by add/edit custom field.
684 * Ignore phpcs nonce issue as we already checked where it is called from.
685 *
686 * @param WPSC_Custom_Field $cf - custom field object.
687 * @param string $field_class - class of field category.
688 * @return void
689 */
690 public static function set_cf_properties( $cf, $field_class ) {
691
692 // extra info.
693 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
694 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
695 }
696
697 // default value.
698 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
699 $default_value = isset( $_POST['default_value'] ) ? wp_kses_post( wp_unslash( $_POST['default_value'] ) ) : ''; // phpcs:ignore
700 $cf->default_value = $default_value ? array( $default_value ) : array();
701 }
702
703 // auto fill.
704 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) {
705 $cf->is_auto_fill = isset( $_POST['is_auto_fill'] ) ? sanitize_text_field( wp_unslash( $_POST['is_auto_fill'] ) ) : ''; // phpcs:ignore
706 }
707
708 // save!
709 $cf->save();
710 }
711
712 /**
713 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
714 *
715 * @param WPSC_Custom_Field $cf - custom field object.
716 * @param WPSC_Ticket $ticket - ticket object.
717 * @param string $module - module name.
718 * @return string
719 */
720 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
721
722 $filters = array(
723 'meta_query' => array(
724 'relation' => 'AND',
725 array(
726 'slug' => 'ticket',
727 'compare' => '=',
728 'val' => $ticket->id,
729 ),
730 array(
731 'slug' => 'type',
732 'compare' => '=',
733 'val' => 'report',
734 ),
735 ),
736 );
737
738 $class_name = is_a( $ticket, 'WPSC_Ticket' ) ? 'WPSC_Thread' : 'WPSC_Archive_Thread';
739 $threads = $class_name::find( $filters );
740 $thread = isset( $threads['results'][0] ) ? $threads['results'][0] : array();
741 return $thread && $thread->is_active ? $thread->get_printable_string() : '';
742 }
743
744 /**
745 * Clear value of hidden fields
746 *
747 * @return void
748 */
749 public static function js_clear_value_hidden_fields() {
750 ?>
751 case '<?php echo esc_attr( self::$slug ); ?>':
752 var is_tinymce = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden();
753 if (is_tinymce && tinymce.get('description')){
754 tinyMCE.get('description').setContent('');
755 } else {
756 jQuery('#description').val('');
757 }
758 break;
759 <?php
760 echo PHP_EOL;
761 }
762 }
763 endif;
764
765 WPSC_DF_Description::init();
766