PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.7
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 / settings / class-wpsc-settings.php

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

275 lines 7.7 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_Settings' ) ) :
7
8 final class WPSC_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
51 /**
52 * Load sections of this setting
53 *
54 * @return void
55 */
56 public static function load_sections() {
57
58 self::$is_current_page = isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'wpsc-settings' ? true : false; //phpcs:ignore
59
60 if ( ! self::$is_current_page ) {
61 return;
62 }
63
64 self::$sections = apply_filters(
65 'wpsc_settings_page_sections',
66 array(
67 'general-settings' => array(
68 'slug' => 'general_settings',
69 'icon' => 'control',
70 'label' => esc_attr__( 'General Settings', 'supportcandy' ),
71 'callback' => 'wpsc_get_general_settings',
72 ),
73 'dashboard-settings' => array(
74 'slug' => 'dashboard_settings',
75 'icon' => 'dashboard',
76 'label' => esc_attr__( 'Dashboard', 'supportcandy' ),
77 'callback' => 'wpsc_get_dashboard_settings',
78 ),
79 'ticket-categories' => array(
80 'slug' => 'ticket_categories',
81 'icon' => 'subfolder',
82 'label' => esc_attr__( 'Ticket Categories', 'supportcandy' ),
83 'callback' => 'wpsc_get_ticket_categories',
84 ),
85 'ticket-statuses' => array(
86 'slug' => 'ticket_statuses',
87 'icon' => 'gps-navigation',
88 'label' => esc_attr__( 'Ticket Statuses', 'supportcandy' ),
89 'callback' => 'wpsc_get_ticket_statuses',
90 ),
91 'ticket-priorities' => array(
92 'slug' => 'ticket_priorities',
93 'icon' => 'prioritize',
94 'label' => esc_attr__( 'Ticket Priorities', 'supportcandy' ),
95 'callback' => 'wpsc_get_ticket_priorities',
96 ),
97 'miscellaneous-settings' => array(
98 'slug' => 'miscellaneous_settings',
99 'icon' => 'cogs',
100 'label' => esc_attr__( 'Miscellaneous', 'supportcandy' ),
101 'callback' => 'wpsc_get_miscellaneous_settings',
102 ),
103 'ticket-widgets' => array(
104 'slug' => 'ticket_widgets',
105 'icon' => 'widget',
106 'label' => esc_attr__( 'Ticket Widgets', 'supportcandy' ),
107 'callback' => 'wpsc_get_ticket_widget',
108 ),
109 'rich-text-editor' => array(
110 'slug' => 'rich_text_editor',
111 'icon' => 'font',
112 'label' => esc_attr__( 'Rich Text Editor', 'supportcandy' ),
113 'callback' => 'wpsc_get_rich_text_editor',
114 ),
115 'working-hrs' => array(
116 'slug' => 'working_hrs',
117 'icon' => 'clock',
118 'label' => esc_attr__( 'Working Hours', 'supportcandy' ),
119 'callback' => 'wpsc_get_working_hrs_settings',
120 ),
121 'appearence' => array(
122 'slug' => 'appearence',
123 'icon' => 'palette',
124 'label' => esc_attr__( 'Appearance', 'supportcandy' ),
125 'callback' => 'wpsc_get_appearence_settings',
126 ),
127 'ticket-tags' => array(
128 'slug' => 'ticket_tags',
129 'icon' => 'tags',
130 'label' => esc_attr__( 'Ticket Tags', 'supportcandy' ),
131 'callback' => 'wpsc_get_ticket_tags_settings',
132 ),
133 )
134 );
135
136 self::$current_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : 'general-settings'; //phpcs:ignore
137 }
138
139 /**
140 * Add localizations to local JS
141 *
142 * @param array $localizations - localization.
143 * @return array
144 */
145 public static function localizations( $localizations ) {
146
147 if ( ! self::$is_current_page ) {
148 return $localizations;
149 }
150
151 // Humbargar Titles.
152 $localizations['humbargar_titles'] = self::get_humbargar_titles();
153
154 // Current section.
155 $localizations['current_section'] = self::$current_section;
156
157 return $localizations;
158 }
159
160 /**
161 * Render settings to admin
162 *
163 * @return void
164 */
165 public static function layout() {
166 ?>
167 <div class="wrap">
168 <hr class="wp-header-end">
169 <div id="wpsc-container" style="display:none;">
170 <div class="wpsc-header wpsc-setting-header-xs wpsc-visible-xs">
171 <div class="wpsc-humbargar-title">
172 <?php WPSC_Icons::get( self::$sections[ self::$current_section ]['icon'] ); ?>
173 <label><?php echo esc_attr( self::$sections[ self::$current_section ]['label'] ); ?></label>
174 </div>
175 <div class="wpsc-humbargar" onclick="wpsc_toggle_humbargar();">
176 <?php WPSC_Icons::get( 'bars' ); ?>
177 </div>
178 </div>
179 <div class="wpsc-settings-page">
180 <div class="wpsc-setting-section-container wpsc-hidden-xs">
181 <h2><?php esc_attr_e( 'Settings', 'supportcandy' ); ?></h2>
182 <?php
183 foreach ( self::$sections as $key => $section ) {
184 $active = self::$current_section === $key ? 'active' : '';
185 ?>
186 <div
187 class="wpsc-setting-nav <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
188 onclick="<?php echo esc_attr( $section['callback'] ) . '();'; ?>">
189 <?php WPSC_Icons::get( $section['icon'] ); ?>
190 <label><?php echo esc_attr( $section['label'] ); ?></label>
191 </div>
192 <?php
193 }
194 ?>
195 </div>
196 <div class="wpsc-setting-body"></div>
197 </div>
198 </div>
199 </div>
200 <?php
201 }
202
203 /**
204 * Humbargar mobile titles to be used in localizations
205 *
206 * @return array
207 */
208 private static function get_humbargar_titles() {
209
210 $titles = array();
211 foreach ( self::$sections as $section ) {
212
213 ob_start();
214 WPSC_Icons::get( $section['icon'] );
215 echo '<label>' . esc_attr( $section['label'] ) . '</label>';
216 $titles[ $section['slug'] ] = ob_get_clean();
217 }
218 return $titles;
219 }
220
221 /**
222 * Print humbargar menu in footer
223 *
224 * @return void
225 */
226 public static function humbargar_menu() {
227
228 if ( ! self::$is_current_page ) {
229 return;
230 }
231 ?>
232
233 <div class="wpsc-humbargar-overlay" onclick="wpsc_toggle_humbargar();" style="display:none"></div>
234 <div class="wpsc-humbargar-menu" style="display:none">
235 <div class="box-inner">
236 <div class="wpsc-humbargar-close" onclick="wpsc_toggle_humbargar();">
237 <?php WPSC_Icons::get( 'times' ); ?>
238 </div>
239 <?php
240 foreach ( self::$sections as $key => $section ) :
241
242 $active = self::$current_section === $key ? 'active' : '';
243 ?>
244 <div
245 class="wpsc-humbargar-menu-item <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
246 onclick="<?php echo esc_attr( $section['callback'] ) . '(true);'; ?>">
247 <?php WPSC_Icons::get( $section['icon'] ); ?>
248 <label><?php echo esc_attr( $section['label'] ); ?></label>
249 </div>
250 <?php
251 endforeach;
252 ?>
253 </div>
254 </div>
255 <?php
256 }
257
258 /**
259 * Register JS functions to call on document ready
260 *
261 * @return void
262 */
263 public static function register_js_ready_function() {
264
265 if ( ! self::$is_current_page ) {
266 return;
267 }
268 echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL;
269 }
270 }
271 endif;
272
273 WPSC_Settings::init();
274
275