| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Admin' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Admin { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize the class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
|
| 17 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ) ); |
| 18 |
add_action( 'admin_menu', array( __CLASS__, 'load_admin_menus' ), 10 ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Load JS and CSS scripts |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public static function load_scripts() { |
| 27 |
|
| 28 |
if ( ! WPSC_Functions::is_wpsc_page() ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
// jquery. |
| 33 |
wp_enqueue_script( 'jquery' ); |
| 34 |
wp_enqueue_script( 'jquery-ui-core' ); |
| 35 |
wp_enqueue_style( 'wpsc-jquery-ui', WPSC_PLUGIN_URL . 'asset/css/jquery-ui.css', array(), WPSC_VERSION ); |
| 36 |
|
| 37 |
// TinyMCE. |
| 38 |
wp_enqueue_editor(); |
| 39 |
|
| 40 |
// jQuery UI Effects. |
| 41 |
wp_enqueue_script( 'jquery-effects-core' ); |
| 42 |
wp_enqueue_script( 'jquery-effects-slide' ); |
| 43 |
|
| 44 |
// color picker. |
| 45 |
wp_enqueue_script( 'wp-color-picker' ); |
| 46 |
wp_enqueue_style( 'wp-color-picker' ); |
| 47 |
|
| 48 |
// Sortable. |
| 49 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 50 |
|
| 51 |
// Accordion. |
| 52 |
wp_enqueue_script( 'jquery-ui-accordion' ); |
| 53 |
|
| 54 |
// Progrss bar. |
| 55 |
wp_enqueue_script( 'jquery-ui-progressbar' ); |
| 56 |
|
| 57 |
// WPSC Scripts. |
| 58 |
wp_enqueue_script( 'wpsc-admin', WPSC_PLUGIN_URL . 'asset/js/admin.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 59 |
wp_localize_script( 'wpsc-admin', 'supportcandy', self::get_localization_data() ); |
| 60 |
|
| 61 |
// WPSC Framework. |
| 62 |
wp_enqueue_script( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/scripts.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 63 |
|
| 64 |
if ( is_rtl() ) { |
| 65 |
wp_enqueue_style( 'wpsc-admin', WPSC_PLUGIN_URL . 'asset/css/admin-rtl.css', array(), WPSC_VERSION ); |
| 66 |
wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style-rtl.css', array(), WPSC_VERSION ); |
| 67 |
} else { |
| 68 |
wp_enqueue_style( 'wpsc-admin', WPSC_PLUGIN_URL . 'asset/css/admin.css', array(), WPSC_VERSION ); |
| 69 |
wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style.css', array(), WPSC_VERSION ); |
| 70 |
} |
| 71 |
|
| 72 |
// selectWoo. |
| 73 |
wp_enqueue_script( 'selectWoo', WPSC_PLUGIN_URL . 'asset/js/selectWoo/selectWoo.full.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 74 |
if ( file_exists( WPSC_ABSPATH . 'asset/js/selectWoo/i18n/' . get_locale() . '.js' ) ) { |
| 75 |
wp_enqueue_script( 'selectWoo-lang', WPSC_PLUGIN_URL . 'asset/js/selectWoo/i18n/' . get_locale() . '.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 76 |
} |
| 77 |
wp_enqueue_style( 'select2', WPSC_PLUGIN_URL . 'asset/css/select2.css', array(), WPSC_VERSION ); |
| 78 |
|
| 79 |
// gpopover. |
| 80 |
wp_enqueue_script( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 81 |
wp_enqueue_style( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.css', array(), WPSC_VERSION ); |
| 82 |
|
| 83 |
// jquery circle progress. |
| 84 |
wp_enqueue_script( 'jquery-circle-progress', WPSC_PLUGIN_URL . 'asset/libs/jquery-circle-progress/circle-progress.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 85 |
|
| 86 |
// flatpickr. |
| 87 |
wp_enqueue_script( 'flatpickr', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 88 |
wp_enqueue_style( 'flatpickr', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.min.css', array(), WPSC_VERSION ); |
| 89 |
|
| 90 |
if ( file_exists( WPSC_ABSPATH . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js' ) ) { |
| 91 |
wp_enqueue_script( 'flatpickr-lang', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 92 |
} |
| 93 |
|
| 94 |
// fullcalendar. |
| 95 |
wp_enqueue_script( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 96 |
wp_enqueue_script( 'fullcalendar-locales', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/locales-all.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 97 |
wp_enqueue_style( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.css', array(), WPSC_VERSION ); |
| 98 |
|
| 99 |
// DataTables. |
| 100 |
wp_enqueue_script( 'wpsc-datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 101 |
wp_enqueue_style( 'wpsc-datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.css', array(), WPSC_VERSION ); |
| 102 |
|
| 103 |
// ChartJs. |
| 104 |
wp_enqueue_script( 'chartjs', WPSC_PLUGIN_URL . 'asset/libs/chartjs/dist/chart.min.js', array( 'jquery' ), WPSC_VERSION, true ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Load admin/dashboard menus |
| 109 |
* |
| 110 |
* @return void |
| 111 |
*/ |
| 112 |
public static function load_admin_menus() { |
| 113 |
|
| 114 |
$current_user = WPSC_Current_User::$current_user; |
| 115 |
$count_str = ''; |
| 116 |
if ( $current_user->is_agent && $current_user->agent->unresolved_count > 0 ) { |
| 117 |
$count_str = ' <span class="update-plugins wpsc-uc"><span class="plugin-count">' . $current_user->agent->unresolved_count . '</span></span>'; |
| 118 |
} |
| 119 |
|
| 120 |
add_menu_page( |
| 121 |
esc_attr__( 'Support', 'supportcandy' ), |
| 122 |
esc_attr__( 'Support', 'supportcandy' ) . $count_str, |
| 123 |
'wpsc_agent', |
| 124 |
'wpsc-tickets', |
| 125 |
array( 'WPSC_Tickets', 'layout' ), |
| 126 |
'dashicons-sos', |
| 127 |
25 |
| 128 |
); |
| 129 |
|
| 130 |
add_submenu_page( |
| 131 |
'wpsc-tickets', |
| 132 |
esc_attr__( 'Ticket List', 'supportcandy' ), |
| 133 |
esc_attr__( 'Tickets', 'supportcandy' ), |
| 134 |
'wpsc_agent', |
| 135 |
'wpsc-tickets', |
| 136 |
array( 'WPSC_Tickets', 'layout' ) |
| 137 |
); |
| 138 |
|
| 139 |
if ( $current_user->is_agent && $current_user->agent->has_cap( 'at-access' ) ) { |
| 140 |
add_submenu_page( |
| 141 |
'wpsc-tickets', |
| 142 |
esc_attr__( 'Archived', 'supportcandy' ), |
| 143 |
esc_attr__( 'Archived', 'supportcandy' ), |
| 144 |
'wpsc_agent', |
| 145 |
'wpsc-archive-tickets', |
| 146 |
array( 'WPSC_Archive_Ticket_List', 'layout' ) |
| 147 |
); |
| 148 |
} |
| 149 |
|
| 150 |
add_submenu_page( |
| 151 |
'wpsc-tickets', |
| 152 |
esc_attr__( 'Customers', 'supportcandy' ), |
| 153 |
esc_attr__( 'Customers', 'supportcandy' ), |
| 154 |
'manage_options', |
| 155 |
'wpsc-customers', |
| 156 |
array( 'WPSC_Customers', 'layout' ) |
| 157 |
); |
| 158 |
|
| 159 |
add_submenu_page( |
| 160 |
'wpsc-tickets', |
| 161 |
esc_attr__( 'Support Agents', 'supportcandy' ), |
| 162 |
esc_attr__( 'Support Agents', 'supportcandy' ), |
| 163 |
'manage_options', |
| 164 |
'wpsc-support-agents', |
| 165 |
array( 'WPSC_Support_Agents', 'layout' ) |
| 166 |
); |
| 167 |
|
| 168 |
add_submenu_page( |
| 169 |
'wpsc-tickets', |
| 170 |
esc_attr__( 'Custom Fields', 'supportcandy' ), |
| 171 |
esc_attr__( 'Custom Fields', 'supportcandy' ), |
| 172 |
'manage_options', |
| 173 |
'wpsc-ticket-form', |
| 174 |
array( 'WPSC_CF_Settings', 'layout' ) |
| 175 |
); |
| 176 |
|
| 177 |
add_submenu_page( |
| 178 |
'wpsc-tickets', |
| 179 |
esc_attr__( 'Ticket List', 'supportcandy' ), |
| 180 |
esc_attr__( 'Ticket List', 'supportcandy' ), |
| 181 |
'manage_options', |
| 182 |
'wpsc-ticket-list', |
| 183 |
array( 'WPSC_Ticket_List_Settings', 'layout' ) |
| 184 |
); |
| 185 |
|
| 186 |
add_submenu_page( |
| 187 |
'wpsc-tickets', |
| 188 |
esc_attr__( 'Email Notifications', 'supportcandy' ), |
| 189 |
esc_attr__( 'Email Notifications', 'supportcandy' ), |
| 190 |
'manage_options', |
| 191 |
'wpsc-email-notifications', |
| 192 |
array( 'WPSC_EN_Settings', 'layout' ) |
| 193 |
); |
| 194 |
|
| 195 |
do_action( 'wpsc_before_setting_admin_menu' ); |
| 196 |
|
| 197 |
add_submenu_page( |
| 198 |
'wpsc-tickets', |
| 199 |
esc_attr__( 'Settings', 'supportcandy' ), |
| 200 |
esc_attr__( 'Settings', 'supportcandy' ), |
| 201 |
'manage_options', |
| 202 |
'wpsc-settings', |
| 203 |
array( 'WPSC_Settings', 'layout' ) |
| 204 |
); |
| 205 |
|
| 206 |
add_submenu_page( |
| 207 |
'wpsc-tickets', |
| 208 |
esc_attr__( 'Licenses', 'supportcandy' ), |
| 209 |
esc_attr__( 'Licenses', 'supportcandy' ), |
| 210 |
'manage_options', |
| 211 |
'wpsc-license', |
| 212 |
array( 'WPSC_License', 'layout' ) |
| 213 |
); |
| 214 |
|
| 215 |
add_submenu_page( |
| 216 |
'wpsc-tickets', |
| 217 |
esc_attr__( 'Pro Features', 'supportcandy' ), |
| 218 |
'<strong style="color: #F1C40F;">' . esc_attr__( 'Pro Features', 'supportcandy' ) . '</strong>', |
| 219 |
'manage_options', |
| 220 |
'wpsc-add-ons', |
| 221 |
array( 'WPSC_Addons', 'layout' ) |
| 222 |
); |
| 223 |
|
| 224 |
add_submenu_page( |
| 225 |
'wpsc-tickets', |
| 226 |
esc_attr__( 'Other Plugins', 'supportcandy' ), |
| 227 |
'<strong style="color: #F1C40F;">' . esc_attr__( 'Other Plugins', 'supportcandy' ) . '</strong>', |
| 228 |
'manage_options', |
| 229 |
'wpsc-other-plugins', |
| 230 |
array( 'WPSC_Other_Plugins', 'layout' ) |
| 231 |
); |
| 232 |
|
| 233 |
// hidden submenu page for manual scheduled tasks. |
| 234 |
add_submenu_page( |
| 235 |
' ', |
| 236 |
esc_attr__( 'Task Manager', 'supportcandy' ), |
| 237 |
'', |
| 238 |
'manage_options', |
| 239 |
'wpsc-task-manager', |
| 240 |
array( 'WPSC_Task_Scheduler', 'perform_manual_scheduler' ) |
| 241 |
); |
| 242 |
|
| 243 |
// hidden submenu page for recent activity. |
| 244 |
add_submenu_page( |
| 245 |
' ', |
| 246 |
esc_attr__( 'Recent Activites', 'supportcandy' ), |
| 247 |
'', |
| 248 |
'manage_options', |
| 249 |
'wpsc-recent-activities', |
| 250 |
array( 'WPSC_RA_Logs', 'layout' ) |
| 251 |
); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* Get localization data for the admin scripts |
| 256 |
* |
| 257 |
* @return string |
| 258 |
*/ |
| 259 |
private static function get_localization_data() { |
| 260 |
|
| 261 |
$gs = get_option( 'wpsc-gs-general' ); |
| 262 |
$file_settings = get_option( 'wpsc-gs-file-attachments' ); |
| 263 |
$localizations = array( |
| 264 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 265 |
'plugin_url' => WPSC_PLUGIN_URL, |
| 266 |
'version' => WPSC_VERSION, |
| 267 |
'loader_html' => WPSC_Framework::loader_html(), |
| 268 |
'inline_loader' => WPSC_Framework::inline_loader(), |
| 269 |
'is_frontend' => 0, |
| 270 |
'reply_form_position' => $gs['reply-form-position'], |
| 271 |
'allowed_file_extensions' => array_map( 'trim', array_map( 'strtolower', explode( ',', $file_settings['allowed-file-extensions'] ) ) ), |
| 272 |
'nonce' => wp_create_nonce( 'general' ), |
| 273 |
'translations' => array( |
| 274 |
'req_fields_error' => esc_attr__( 'Required fields can not be empty!', 'supportcandy' ), |
| 275 |
'submit_option_error' => esc_attr__( 'Please submit the option!', 'supportcandy' ), |
| 276 |
'datatables' => array( |
| 277 |
'emptyTable' => esc_attr__( 'No Records', 'supportcandy' ), |
| 278 |
'zeroRecords' => esc_attr__( 'No Records', 'supportcandy' ), |
| 279 |
'info' => sprintf( |
| 280 |
/* translators: e.g. Showing 1 to 20 of 300 records */ |
| 281 |
esc_attr__( 'Showing %1$s to %2$s of %3$s records', 'supportcandy' ), |
| 282 |
'_START_', |
| 283 |
'_END_', |
| 284 |
'_TOTAL_' |
| 285 |
), |
| 286 |
'infoEmpty' => '', |
| 287 |
'loadingRecords' => '', |
| 288 |
'processing' => '', |
| 289 |
'infoFiltered' => '', |
| 290 |
'search' => esc_attr__( 'Search:', 'supportcandy' ), |
| 291 |
'paginate' => array( |
| 292 |
'first' => esc_attr__( 'First', 'supportcandy' ), |
| 293 |
'previous' => esc_attr__( 'Previous', 'supportcandy' ), |
| 294 |
'next' => esc_attr__( 'Next', 'supportcandy' ), |
| 295 |
'last' => esc_attr__( 'Last', 'supportcandy' ), |
| 296 |
), |
| 297 |
), |
| 298 |
), |
| 299 |
'temp' => array(), |
| 300 |
'home_url' => home_url(), |
| 301 |
); |
| 302 |
|
| 303 |
return apply_filters( 'wpsc_admin_localizations', $localizations ); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
endif; |
| 308 |
|
| 309 |
WPSC_Admin::init(); |
| 310 |
|