-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsource-support.php
465 lines (370 loc) · 15.5 KB
/
psource-support.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?php
/*
Plugin Name: PS Support System
Plugin URI: https://cp-psource.github.io/ps-support/
Description: Richte auf jeder ClassicPress-Seite ein fantastisches Support-Ticket-System mit häufig gestellten Fragen ein.
Author: PSOURCE
Network: true
Version: 2.2.5
License: GPLv2
Author URI: https://github.com/cp-psource/
Domain Path: languages
Text Domain: psource-support
*/
/*
Copyright 2018-2024 PSOURCE (https://github.com/cp-psource/)
Author DerN3rd
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 � GPLv2) as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @@@@@@@@@@@@@@@@@ PS UPDATER 1.3 @@@@@@@@@@@
**/
require 'psource/psource-plugin-update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/cp-psource/ps-support',
__FILE__,
'ps-support'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');
/**
* @@@@@@@@@@@@@@@@@ ENDE PS UPDATER 1.3 @@@@@@@@@@@
**/
define( 'PSOURCE_SUPPORT_PLUGIN_VERSION', '2.2.5' );
if ( ! defined( 'PSOURCE_SUPPORT_LANG_DOMAIN' ) )
define('PSOURCE_SUPPORT_LANG_DOMAIN', 'psource-support');
define( 'PSOURCE_SUPPORT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'PSOURCE_SUPPORT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'PSOURCE_SUPPORT_ASSETS_URL', PSOURCE_SUPPORT_PLUGIN_URL . 'assets/' );
if ( ! class_exists( 'MU_Support_System') ) {
class MU_Support_System {
// Current version of the plugin
public static $version = PSOURCE_SUPPORT_PLUGIN_VERSION;
// Sets of valid values like status, or privacy options
public static $ticket_status;
public static $ticket_priority;
public static $responsibilities;
public static $privacy;
public static $fetch_imap;
public static $psource_support_imap_ssl;
// Plugin settings
public $settings = array();
// Network menus
public static $network_main_menu;
public static $network_single_ticket_menu;
public static $network_faq_manager_menu;
public static $network_ticket_categories;
public static $network_single_faq_question_menu;
public static $network_faq_categories_menu;
public static $network_support_settings_menu;
// Blogs menus
public static $admin_main_menu;
public static $admin_new_ticket_menu;
public static $admin_single_ticket_menu;
public static $admin_faq_menu;
public $admin;
public $shortcodes = null;
public $integrators = array();
private static $instance = null;
public $model;
public $query;
public static function get_instance() {
if ( ! self::$instance )
self::$instance = new self();
return self::$instance;
}
/**
* Constructor: Initializes the plugin
*
* @since 1.8
*/
public function __construct() {
// Include needed files
$this->includes();
// Initializes plugin
add_action( 'init', array( &$this, 'init_plugin' ), 1 );
// Activation/Upgrades
register_activation_hook( __FILE__, array( &$this, 'activate' ) );
register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
// Is this an upgrade?
add_action( 'init', 'psource_support_check_for_upgrades' );
add_action( 'plugins_loaded', array( &$this, 'load_text_domain' ), 100 );
// Create Admin menus
//add_action( 'init', array( &$this, 'admin_menus' ) );
}
public function init_plugin() {
$this->model = psource_support_get_model();
$this->settings = new PSource_Support_Settings();
$this->query = new PSource_Support_Query();
if ( is_admin() )
$this->admin = new PSource_Support_Admin();
// Setting properties
self::$ticket_status = array(
0 => __( 'Neu', 'psource-support' ),
1 => __( 'In Bearbeitung', 'psource-support' ),
2 => __( 'Warten auf die Antwort des Benutzers', 'psource-support' ),
3 => __( 'Warten auf Admin, um zu antworten', 'psource-support' ),
4 => __( 'Eingestellt', 'psource-support' ),
5 => __( 'Geschlossen', 'psource-support' )
);
self::$ticket_priority = array(
0 => __( 'Niedrig', 'psource-support' ),
1 => __( 'Normal', 'psource-support' ),
2 => __( 'Hoch', 'psource-support' ),
3 => __( 'Eilt', 'psource-support' ),
4 => __( 'Dringend', 'psource-support' )
);
self::$responsibilities = array(
'keep',
'punt',
'accept',
'help'
);
self::$privacy = array(
'all' => is_multisite() ? __( 'Erlaube allen Benutzern, alle Tickets auf einer Seite zu sehen', 'psource-support' ) : __( 'Allen Benutzern erlauben, alle Tickets zu sehen', 'psource-support' ),
'requestor' => __( 'Erlaube nur Ticketerstellern, ihre eigenen Tickets zu sehen', 'psource-support' )
);
if ( ( is_multisite() && $this->settings->get( 'psource_support_blog_id' ) == get_current_blog_id() ) || ! is_multisite() )
$this->shortcodes = new PSource_Support_Shortcodes();
}
public function load_text_domain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'psource-support' );
load_textdomain( PSOURCE_SUPPORT_LANG_DOMAIN, WP_LANG_DIR . '/' . PSOURCE_SUPPORT_LANG_DOMAIN . '/' . PSOURCE_SUPPORT_LANG_DOMAIN . '-' . $locale . '.mo' );
load_plugin_textdomain( PSOURCE_SUPPORT_LANG_DOMAIN, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Includes needed files
*
* @since 1.8
*/
private function includes() {
// Model
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'model/model.php');
if ( is_admin() ) {
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'admin/class-psource-support-admin.php' );
}
// Classes
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-ticket.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-ticket-category.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-ticket-reply.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-shortcodes.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-query.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-faq.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-faq-category.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/classes/class-settings.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/general.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/ticket.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/ticket-category.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/ticket-reply.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/template.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/settings.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/capabilities.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/faq.php');
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/helpers/faq-category.php');
// Integration
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/integration/pro-sites.php');
// Mail templates
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/mail-contents.php');
// Upgrades
require_once( PSOURCE_SUPPORT_PLUGIN_DIR . 'inc/upgrades.php');
}
/**
* Activates the plugin
*
* @since 1.8
*/
public function activate() {
$model = psource_support_get_model();
$model->create_tables();
$settings = new PSource_Support_Settings();
update_site_option( 'psource_support_version', self::$version );
update_site_option( 'psource_support_settings', $settings->get_all() );
set_transient( 'psource_support_welcome', true );
}
/**
* Deactivates the plugin
*
* @since 1.8
*/
public function deactivate() {
//delete_site_option( 'psource_support_version' );
//delete_site_option( 'psource_support_settings' );
}
/**
* Add actions for admin menus
*/
public function admin_menus() {
if ( is_multisite() ) {
if ( is_network_admin() ) {
// Order is important
self::$network_main_menu = new MU_Support_Network_Main_Menu();
self::$network_single_ticket_menu = new MU_Support_Network_Single_Ticket_Menu();
self::$network_ticket_categories = new MU_Support_Network_Ticket_Categories();
self::$network_single_faq_question_menu = new MU_Support_Network_Single_FAQ_Question_Menu();
self::$network_faq_manager_menu = new MU_Support_Network_FAQ_Manager_Menu();
self::$network_faq_categories_menu = new MU_Support_Network_FAQ_Categories();
self::$network_support_settings_menu = new MU_Support_Network_Support_settings();
}
elseif ( is_admin() ) {
$user = get_userdata( get_current_user_id() );
$user_role = isset( $user->roles[0] ) ? $user->roles[0] : ( is_super_admin() ? 'administrator' : '' );
$admin_ticket_menu_allowed = false;
// Tickets allowed?
foreach ( $this->settings->get( 'psource_support_tickets_role' ) as $ticket_role ) {
if ( $user_role == $ticket_role ) {
$admin_ticket_menu_allowed = true;
break;
}
}
if ( (boolean)$this->settings->get( 'psource_allow_only_pro_sites' ) && $admin_ticket_menu_allowed )
$admin_ticket_menu_allowed = function_exists( 'is_pro_site' ) && is_pro_site( get_current_blog_id(), absint( $this->settings->get( 'psource_pro_sites_level' ) ) );
// FAQs allowed?
$admin_faq_menu_allowed = false;
foreach ( $this->settings->get( 'psource_support_faqs_role' ) as $faq_role ) {
if ( $user_role == $faq_role ) {
$admin_faq_menu_allowed = true;
break;
}
}
if ( $this->settings->get( 'psource_allow_only_pro_sites_faq' ) && $admin_faq_menu_allowed )
$admin_faq_menu_allowed = function_exists( 'is_pro_site' ) && is_pro_site( get_current_blog_id(), absint( $this->settings->get( 'psource_pro_sites_faq_level' ) ) );
// If is not a Pro site we will not create the menu
if ( $admin_ticket_menu_allowed ) {
self::$admin_single_ticket_menu = new MU_Support_Admin_Single_Ticket_Menu();
self::$admin_new_ticket_menu = new MU_Support_Admin_New_Ticket_Menu();
self::$admin_main_menu = new MU_Support_Admin_Main_Menu();
}
if ( ! $admin_ticket_menu_allowed && $admin_faq_menu_allowed )
self::$admin_faq_menu = new MU_Support_Admin_FAQ_Menu( true );
elseif ( $admin_ticket_menu_allowed && $admin_faq_menu_allowed )
self::$admin_faq_menu = new MU_Support_Admin_FAQ_Menu( false );
}
}
elseif ( ! is_multisite() && is_admin() ) {
if ( current_user_can( 'administrator' ) ) {
self::$network_main_menu = new MU_Support_Network_Main_Menu( false, 'manage_options' );
self::$network_single_ticket_menu = new MU_Support_Network_Single_Ticket_Menu( false, false, 'manage_options' );
self::$network_ticket_categories = new MU_Support_Network_Ticket_Categories( false, 'manage_options' );
self::$network_single_faq_question_menu = new MU_Support_Network_Single_FAQ_Question_Menu( false, 'manage_options' );
self::$network_faq_manager_menu = new MU_Support_Network_FAQ_Manager_Menu( false, 'manage_options' );
self::$network_faq_categories_menu = new MU_Support_Network_FAQ_Categories( false, 'manage_options' );
self::$network_support_settings_menu = new MU_Support_Network_Support_settings( false, 'manage_options' );
}
else {
$user = get_userdata( get_current_user_id() );
$user_role = $user->roles[0];
// Tickets allowed?
$admin_ticket_menu_allowed = false;
foreach ( $this->settings->get( 'psource_support_tickets_role' ) as $ticket_role ) {
if ( $user_role == $ticket_role ) {
$admin_ticket_menu_allowed = true;
break;
}
}
if ( $admin_ticket_menu_allowed ) {
self::$admin_single_ticket_menu = new MU_Support_Admin_Single_Ticket_Menu();
self::$admin_new_ticket_menu = new MU_Support_Admin_New_Ticket_Menu();
self::$admin_main_menu = new MU_Support_Admin_Main_Menu();
}
// FAQs allowed?
$admin_faq_menu_allowed = false;
foreach ( $this->settings->get( 'psource_support_faqs_role' ) as $faq_role ) {
if ( $user_role == $faq_role ) {
$admin_faq_menu_allowed = true;
break;
}
}
if ( ! $admin_ticket_menu_allowed && $admin_faq_menu_allowed )
self::$admin_faq_menu = new MU_Support_Admin_FAQ_Menu( true );
elseif ( $admin_ticket_menu_allowed && $admin_faq_menu_allowed )
self::$admin_faq_menu = new MU_Support_Admin_FAQ_Menu( false );
}
}
}
/**
* Sets HTML content for mails
*
* @return String Content type
*/
public function set_mail_content_type() {
return 'text/html';
}
/**
* Return all roles depending on multisite or not
*
* @since 1.9
*/
public static function get_roles() {
global $wp_roles;
$just_roles = $wp_roles->roles;
if ( ! is_multisite() )
unset( $just_roles['administrator'] );
$support_roles = array();
foreach ( $just_roles as $key => $role ) {
$support_roles[ $key ] = translate_user_role( $role['name'] );
}
$support_roles['support-guest'] = __( 'Besucher', 'psource-support' );
return $support_roles;
}
/**
* Return a ist of Super Admins for multisites or Admins for single sites
*
* @since 1.9.5
*
* @return Array of Super Admins/Admins
*/
public static function get_super_admins() {
if ( is_multisite() ) {
$super_admins = get_super_admins();
}
else {
$admins = get_users(
array(
'role' => 'administrator',
'fields' => array( 'ID', 'user_login' )
)
);
$super_admins = array();
foreach ( $admins as $admin ) {
$super_admins[ $admin->ID ] = $admin->user_login;
}
}
return apply_filters( 'psource_support_get_super_admins', $super_admins );
}
public static function get_main_admin_email() {
$administrator = psource_support_get_setting( 'psource_support_main_super_admin' );
$super_admins = MU_Support_System::get_super_admins();
$admin_login = $super_admins[ $administrator ];
$admin_user = get_user_by( 'login', $admin_login );
return $admin_user->user_email;
}
public static function get_main_admin_details() {
$administrator = psource_support_get_setting( 'psource_support_main_super_admin' );
$super_admins = MU_Support_System::get_super_admins();
$admin_login = $super_admins[ $administrator ];
$admin_user = get_user_by( 'login', $admin_login );
return $admin_user;
}
public function add_integrator( $integrator ) {
$this->integrators[] = $integrator;
}
}
}
function psource_support() {
return MU_Support_System::get_instance();
}
add_action( 'plugins_loaded', 'support_system_init' );
function support_system_init() {
global $mu_support_system;
$mu_support_system = psource_support();
}