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-html.php

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

305 lines 7.3 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_HTML' ) ) :
7
8 final class WPSC_CF_HTML {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'cf_html';
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 = false;
72
73 /**
74 * Set whether this custom field type can accept personal info.
75 *
76 * @var boolean
77 */
78 public static $has_personal_info = false;
79
80 /**
81 * Set whether fields created from this custom field type is allowed in create ticket form
82 *
83 * @var boolean
84 */
85 public static $is_ctf = true;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket list
89 *
90 * @var boolean
91 */
92 public static $is_list = false;
93
94 /**
95 * Set whether fields created from this custom field type is allowed in ticket filter
96 *
97 * @var boolean
98 */
99 public static $is_filter = false;
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 = false;
128
129 /**
130 * Set whether fields created from this custom field type can have placeholder
131 *
132 * @var boolean
133 */
134 public static $is_placeholder = false;
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 = false;
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 = false;
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 = false;
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' ), 12 );
169
170 // Avoid being listed on ticket list or agentonly widgets.
171 add_filter( 'wpsc_it_widget_exclude_cft', array( __CLASS__, 'exclude_wdget_cft' ) );
172 }
173
174 /**
175 * Load current class to reference classes
176 *
177 * @param array $classes - Associative array of class names indexed by its slug.
178 * @return array
179 */
180 public static function load_ref_class( $classes ) {
181
182 $classes[ self::$slug ] = array(
183 'class' => __CLASS__,
184 'save-key' => 'id',
185 );
186 return $classes;
187 }
188
189 /**
190 * Add custom field type to list
191 *
192 * @param array $cf_types - custom field types array.
193 * @return array
194 */
195 public static function add_cf_type( $cf_types ) {
196
197 $cf_types[ self::$slug ] = array(
198 'label' => esc_attr__( 'HTML', 'supportcandy' ),
199 'class' => __CLASS__,
200 );
201 return $cf_types;
202 }
203
204 /**
205 * Print ticket form field
206 *
207 * @param WPSC_Custom_Field $cf - Custom field object.
208 * @param array $tff - Array of ticket form field settings for this field.
209 * @return string
210 */
211 public static function print_tff( $cf, $tff ) {
212
213 if ( ! $cf->default_value ) {
214 return '';
215 }
216
217 ob_start();?>
218 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
219 <?php
220 echo do_shortcode( wp_kses_post( $cf->default_value[0] ) );
221 ?>
222 </div>
223 <?php
224 return ob_get_clean();
225 }
226
227 /**
228 * Exclude this custom field type being listed in ticket fields or agentonly widgets
229 *
230 * @param array $slug_arr - exclude list.
231 * @return array
232 */
233 public static function exclude_wdget_cft( $slug_arr ) {
234
235 $slug_arr[] = self::$slug;
236 return $slug_arr;
237 }
238
239 /**
240 * Print add new custom field setting properties
241 *
242 * @param string $field_class - Class name of the field.
243 * @return void
244 */
245 public static function get_add_new_custom_field_properties( $field_class ) {
246 ?>
247
248 <div data-type="textarea" data-required="true" class="wpsc-input-group html_text">
249 <div class="label-container">
250 <label for="">
251 <?php esc_html_e( 'HTML Content', 'supportcandy' ); ?>
252 <span class="required-char">*</span>
253 </label>
254 </div>
255 <textarea name="html_text" rows="5"></textarea>
256 </div>
257 <?php
258 }
259
260 /**
261 * Print edit custom field properties
262 *
263 * @param WPSC_Custom_Fields $cf - custom field object.
264 * @param string $field_class - class name of field category.
265 * @return void
266 */
267 public static function get_edit_custom_field_properties( $cf, $field_class ) {
268 ?>
269
270 <div class="wpsc-input-group html_text">
271 <div class="label-container">
272 <label for="">
273 <?php esc_html_e( 'HTML Content', 'supportcandy' ); ?>
274 <span class="required-char">*</span>
275 </label>
276 </div>
277 <textarea name="html_text" rows="5"><?php echo esc_attr( $cf->default_value[0] ); ?></textarea>
278 </div>
279 <?php
280 }
281
282 /**
283 * Set custom field properties. Can be used by add/edit custom field.
284 * Ignore phpcs nonce issue as we already checked where it is called from.
285 *
286 * @param WPSC_Custom_Field $cf - custom field object.
287 * @param string $field_class - class of field category.
288 * @return void
289 */
290 public static function set_cf_properties( $cf, $field_class ) {
291
292 // default value.
293 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
294 $default_value = isset( $_POST['html_text'] ) ? wp_kses_post( wp_unslash( $_POST['html_text'] ) ) : ''; // phpcs:ignore
295 $cf->default_value = $default_value ? array( $default_value ) : array();
296 }
297
298 // save!
299 $cf->save();
300 }
301 }
302 endif;
303
304 WPSC_CF_HTML::init();
305