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 / admin / ticket-list / class-wpsc-ticket-list-settings.php

class-wpsc-ticket-list-settings.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.7, at includes/admin/ticket-list/class-wpsc-ticket-list-settings.php

257 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Ticket_List_Settings' ) ) :
7
8 final class WPSC_Ticket_List_Settings {
9
10 /**
11 * Set if current screen is settings page
12 *
13 * @var boolean
14 */
15 public static $is_current_page;
16
17 /**
18 * Sections for this view
19 *
20 * @var array
21 */
22 private static $sections = array();
23
24 /**
25 * Current section to load
26 *
27 * @var string
28 */
29 public static $current_section;
30
31 /**
32 * Initialize this class
33 *
34 * @return void
35 */
36 public static function init() {
37
38 // Load sections for this screen.
39 add_action( 'admin_init', array( __CLASS__, 'load_sections' ), 1 );
40
41 // Humbargar modal.
42 add_action( 'admin_footer', array( __CLASS__, 'humbargar_menu' ) );
43
44 // Add current section to admin localization data.
45 add_filter( 'wpsc_admin_localizations', array( __CLASS__, 'localizations' ) );
46
47 // Register ready function.
48 add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) );
49
50 // default filter conditions.
51 add_filter( 'wpsc_default_filter_conditions', array( __CLASS__, 'default_filter_conditions' ) );
52 }
53
54 /**
55 * Load sections of this setting
56 *
57 * @return void
58 */
59 public static function load_sections() {
60
61 self::$is_current_page = isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'wpsc-ticket-list' ? true : false; // phpcs:ignore
62
63 if ( ! self::$is_current_page ) {
64 return;
65 }
66
67 self::$sections = apply_filters(
68 'wpsc_ticket_list_sections',
69 array(
70 'agent-ticket-list' => array(
71 'slug' => 'agent_ticket_list',
72 'icon' => 'headset',
73 'label' => esc_attr__( 'Agent ticket list', 'supportcandy' ),
74 'callback' => 'wpsc_get_agent_tl_settings',
75 ),
76 'customer-ticket-list' => array(
77 'slug' => 'customer_ticket_list',
78 'icon' => 'user-tie',
79 'label' => esc_attr__( 'Customer ticket list', 'supportcandy' ),
80 'callback' => 'wpsc_get_customer_tl_settings',
81 ),
82 'more-settings' => array(
83 'slug' => 'more_settings',
84 'icon' => 'cogs',
85 'label' => esc_attr__( 'More settings', 'supportcandy' ),
86 'callback' => 'wpsc_get_tl_more_settigns',
87 ),
88 )
89 );
90 self::$current_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : 'agent-ticket-list'; // phpcs:ignore
91 }
92
93 /**
94 * Add localizations to local JS
95 *
96 * @param array $localizations - localization list.
97 * @return array
98 */
99 public static function localizations( $localizations ) {
100
101 if ( ! self::$is_current_page ) {
102 return $localizations;
103 }
104
105 // Humbargar Titles.
106 $localizations['humbargar_titles'] = self::get_humbargar_titles();
107
108 // Current section.
109 $localizations['current_section'] = self::$current_section;
110
111 return $localizations;
112 }
113
114 /**
115 * Render settings to admin
116 *
117 * @return void
118 */
119 public static function layout() {
120 ?>
121 <div class="wrap">
122 <hr class="wp-header-end">
123 <div id="wpsc-container" style="display:none;">
124 <div class="wpsc-header wpsc-setting-header-xs wpsc-visible-xs">
125 <div class="wpsc-humbargar-title">
126 <?php WPSC_Icons::get( self::$sections[ self::$current_section ]['icon'] ); ?>
127 <label><?php echo esc_attr( self::$sections[ self::$current_section ]['label'] ); ?></label>
128 </div>
129 <div class="wpsc-humbargar" onclick="wpsc_toggle_humbargar();">
130 <?php WPSC_Icons::get( 'bars' ); ?>
131 </div>
132 </div>
133 <div class="wpsc-settings-page">
134 <div class="wpsc-setting-section-container wpsc-hidden-xs">
135 <h2><?php esc_attr_e( 'Ticket List', 'supportcandy' ); ?></h2>
136 <?php
137 foreach ( self::$sections as $key => $section ) :
138
139 $active = self::$current_section === $key ? 'active' : '';
140 ?>
141 <div
142 class="wpsc-setting-nav <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
143 onclick="<?php echo esc_attr( $section['callback'] ) . '();'; ?>">
144 <?php WPSC_Icons::get( $section['icon'] ); ?>
145 <label><?php echo esc_attr( $section['label'] ); ?></label>
146 </div>
147 <?php
148 endforeach;
149 ?>
150 </div>
151 <div class="wpsc-setting-body"></div>
152 </div>
153 </div>
154 </div>
155 <?php
156 }
157
158 /**
159 * Humbargar mobile titles to be used in localizations
160 *
161 * @return string
162 */
163 private static function get_humbargar_titles() {
164
165 $titles = array();
166 foreach ( self::$sections as $section ) {
167
168 ob_start();
169 WPSC_Icons::get( $section['icon'] );
170 echo '<label>' . esc_attr( $section['label'] ) . '</label>';
171 $titles[ $section['slug'] ] = ob_get_clean();
172 }
173 return $titles;
174 }
175
176 /**
177 * Print humbargar menu in footer
178 *
179 * @return void
180 */
181 public static function humbargar_menu() {
182
183 if ( ! self::$is_current_page ) {
184 return;
185 }
186 ?>
187
188 <div class="wpsc-humbargar-overlay" onclick="wpsc_toggle_humbargar();" style="display:none"></div>
189 <div class="wpsc-humbargar-menu" style="display:none">
190 <div class="box-inner">
191 <div class="wpsc-humbargar-close" onclick="wpsc_toggle_humbargar();">
192 <?php WPSC_Icons::get( 'times' ); ?>
193 </div>
194 <?php
195 foreach ( self::$sections as $key => $section ) :
196
197 $active = self::$current_section === $key ? 'active' : '';
198 ?>
199 <div
200 class="wpsc-humbargar-menu-item <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
201 onclick="<?php echo esc_attr( $section['callback'] ) . '(true);'; ?>">
202 <?php WPSC_Icons::get( $section['icon'] ); ?>
203 <label><?php echo esc_attr( $section['label'] ); ?></label>
204 </div>
205 <?php
206 endforeach;
207 ?>
208 </div>
209 </div>
210 <?php
211 }
212
213 /**
214 * Register JS functions to call on document ready
215 *
216 * @return void
217 */
218 public static function register_js_ready_function() {
219
220 if ( ! self::$is_current_page ) {
221 return;
222 }
223 echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL;
224 }
225
226 /**
227 * Default filter conditions
228 *
229 * @param array $conditions - conditions array.
230 * @return array
231 */
232 public static function default_filter_conditions( $conditions ) {
233
234 foreach ( $conditions as $slug => $item ) {
235
236 if ( $item['type'] == 'cf' ) {
237
238 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
239 if (
240 ! $cf->type::$is_filter ||
241 ! in_array( $cf->field, array( 'ticket', 'customer', 'agentonly' ) )
242 ) {
243 unset( $conditions[ $slug ] );
244 }
245 } else { // not custom field type.
246
247 unset( $conditions[ $slug ] );
248 }
249 }
250
251 return $conditions;
252 }
253 }
254 endif;
255
256 WPSC_Ticket_List_Settings::init();
257