(' . sprintf( __( 'Allowed file types: %s', INCSUB_SUPPORT_LANG_DOMAIN ), $allowed_mimes ) . ')
'
78 | );
79 |
80 | wp_localize_script( 'support-system-init', 'support_system_i18n', $l10n );
81 | }
82 |
83 | public function _allowed_mimes( $element ) {
84 | return str_replace( '|', ', *.', $element );
85 | }
86 |
87 |
88 | public function enqueue_scripts() {
89 | if ( is_support_system() ) {
90 | wp_enqueue_script( 'support-system-init' );
91 | wp_enqueue_style( 'support-system' );
92 | wp_enqueue_style( 'support-system-adminbar' );
93 | }
94 | }
95 |
96 | protected function enqueue_custom_scripts() {}
97 |
98 | public function register_shortcodes() {
99 | foreach ( $this->shortcodes as $shortcode => $classname ) {
100 | if ( class_exists( $classname ) ) {
101 | $r = new ReflectionClass( $classname );
102 | $r->newInstanceArgs();
103 | }
104 |
105 | }
106 | }
107 |
108 | // TinyMCE buttons ( Thanks to Woocommerce Shortcodes plugin: https://wordpress.org/plugins/woocommerce-shortcodes/)
109 | function init_tiny_mce_button() {
110 | if ( apply_filters( 'support_system_add_editor_shortcodes', true ) ) {
111 | add_action( 'admin_head', array( $this, 'add_shortcode_button' ) );
112 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_editor_admin_scripts' ) );
113 | }
114 | }
115 |
116 | function add_shortcode_button() {
117 | if ( 'true' == get_user_option( 'rich_editing' ) ) {
118 | add_filter( 'mce_external_plugins', array( $this, 'add_shortcode_tinymce_plugin' ) );
119 | add_filter( 'mce_buttons', array( $this, 'register_shortcode_button' ) );
120 | add_filter( 'mce_external_languages', array( $this, 'add_tinymce_i18n' ) );
121 | }
122 | }
123 |
124 | public function add_shortcode_tinymce_plugin( $plugins ) {
125 | $plugins['incsub_support_shortcodes'] = INCSUB_SUPPORT_PLUGIN_URL . 'admin/assets/js/editor-shortcodes.js';
126 | return $plugins;
127 | }
128 |
129 | public function register_shortcode_button( $buttons ) {
130 | array_push( $buttons, '|', 'incsub_support_shortcodes' );
131 | return $buttons;
132 | }
133 |
134 | public function enqueue_editor_admin_scripts() {
135 | wp_enqueue_style( 'incsub-support-shortcodes', INCSUB_SUPPORT_PLUGIN_URL . 'admin/assets/css/editor-shortcodes.css' );
136 | }
137 |
138 | public function add_tinymce_i18n( $i18n ) {
139 | $i18n['support_system_shortcodes'] = INCSUB_SUPPORT_PLUGIN_DIR . '/admin/inc/tinymce-shortcodes-i18n.php';
140 |
141 | return $i18n;
142 | }
143 |
144 | }
--------------------------------------------------------------------------------
/inc/classes/class-ticket-category.php:
--------------------------------------------------------------------------------
1 | model->tickets_cats_table;
25 | $current_site_id = ! empty ( $current_site ) ? $current_site->id : 1;
26 |
27 | $_cat = wp_cache_get( $cat_id, 'support_system_ticket_categories' );
28 |
29 | if ( ! $_cat ) {
30 | $_cat = $wpdb->get_row(
31 | $wpdb->prepare(
32 | "SELECT *
33 | FROM $table
34 | WHERE cat_id = %d
35 | AND site_id = %d
36 | LIMIT 1",
37 | $cat_id,
38 | $current_site_id
39 | )
40 | );
41 |
42 | if ( ! $_cat )
43 | return false;
44 |
45 | }
46 | }
47 | else {
48 | // Looking for name
49 |
50 | $table = incsub_support()->model->tickets_cats_table;
51 | $current_site_id = ! empty ( $current_site ) ? $current_site->id : 1;
52 |
53 | $_cat = $wpdb->get_row(
54 | $wpdb->prepare(
55 | "SELECT *
56 | FROM $table
57 | WHERE cat_name = %s
58 | AND site_id = %d
59 | LIMIT 1",
60 | $ticket_category,
61 | $current_site_id
62 | )
63 | );
64 |
65 | if ( ! $_cat )
66 | return false;
67 |
68 | }
69 |
70 | wp_cache_add( $_cat->cat_id, $_cat, 'support_system_ticket_categories' );
71 |
72 | $_cat = new self( $_cat );
73 |
74 | $_cat = incsub_support_sanitize_ticket_category_fields( $_cat );
75 |
76 | return $_cat;
77 |
78 | }
79 |
80 | public function __construct( $cat ) {
81 | foreach ( get_object_vars( $cat ) as $key => $value )
82 | $this->$key = $value;
83 | }
84 |
85 | public function __get( $name ) {
86 | if ( $name === 'defcat' ) {
87 | return ( ! empty( $this->defcat ) ) ? true : false;
88 | }
89 |
90 | return false;
91 | }
92 |
93 | public function get_tickets_count() {
94 | global $wpdb;
95 |
96 | $table = incsub_support()->model->tickets_table;
97 |
98 | $counts = wp_cache_get( $this->cat_id, 'support_system_ticket_categories_counts' );
99 | if ( false === $counts ) {
100 | $counts = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ticket_id ) FROM $table WHERE cat_id = %d", $this->cat_id ) );
101 | wp_cache_add( $this->cat_id, $counts, 'support_system_ticket_categories_counts' );
102 | }
103 |
104 | return absint( $counts );
105 |
106 | }
107 | }
--------------------------------------------------------------------------------
/inc/classes/class-ticket-reply.php:
--------------------------------------------------------------------------------
1 | model->tickets_messages_table;
36 |
37 | $_reply = $wpdb->get_row(
38 | $wpdb->prepare(
39 | "SELECT * FROM $tickets_replies_table
40 | WHERE message_id = %d
41 | LIMIT 1",
42 | $ticket_reply_id
43 | )
44 | );
45 |
46 | if ( ! $_reply )
47 | return false;
48 |
49 | $_reply = new self( $_reply );
50 |
51 | return $_reply;
52 |
53 | }
54 |
55 | public function __construct( $ticket ) {
56 | foreach ( get_object_vars( $ticket ) as $key => $value ) {
57 | if ( $key === 'attachments' ) {
58 | $value = maybe_unserialize( $value );
59 | }
60 |
61 | $this->$key = $value;
62 | }
63 | }
64 |
65 | public function __get( $name ) {
66 | if ( $name == 'message' ) {
67 | return apply_filters( 'the_content', $this->message, 0 );
68 | }
69 | }
70 |
71 | public function get_poster_id() {
72 | if ( $this->user_id )
73 | return absint( $this->user_id );
74 |
75 | if ( $this->admin_id )
76 | return absint( $this->admin_id );
77 |
78 | return 0;
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/inc/classes/class-ticket.php:
--------------------------------------------------------------------------------
1 | model->tickets_table;
58 |
59 | $_ticket = wp_cache_get( $ticket_id, 'support_system_tickets' );
60 |
61 | if ( ! $_ticket ) {
62 |
63 | $_ticket = $wpdb->get_row(
64 | $wpdb->prepare(
65 | "SELECT * FROM $tickets_table
66 | WHERE ticket_id = %d
67 | LIMIT 1",
68 | $ticket_id
69 | )
70 | );
71 |
72 | if ( ! $_ticket )
73 | return false;
74 |
75 | wp_cache_add( $_ticket->ticket_id, $_ticket, 'support_system_tickets' );
76 | }
77 |
78 | if ( ! $_ticket )
79 | return false;
80 |
81 | $_ticket = new self( $_ticket );
82 |
83 | $_ticket = incsub_support_sanitize_ticket_fields( $_ticket );
84 |
85 | return $_ticket;
86 |
87 | }
88 |
89 | public function __construct( $ticket ) {
90 | foreach ( get_object_vars( $ticket ) as $key => $value ) {
91 | $this->$key = $value;
92 | }
93 |
94 | if ( $this->cat_id )
95 | $this->category = incsub_support_get_ticket_category( $this->cat_id );
96 | }
97 |
98 | public function __get( $name ) {
99 | if ( 'last_reply_user_id' === $name ) {
100 | $replies = $this->get_replies();
101 | end( $replies );
102 | $last_reply = current( $replies );
103 | if ( ! $last_reply->user_id && ! $last_reply->admin_id ) {
104 | return false;
105 | }
106 | elseif( $last_reply->user_id ) {
107 | return $last_reply->user_id;
108 | }
109 | elseif( $last_reply->admin_id ) {
110 | return $last_reply->admin_id;
111 | }
112 | }
113 |
114 | if ( 'message' === $name ) {
115 | if ( ! empty( $this->message ) )
116 | return $this->message;
117 |
118 | $replies = $this->get_replies();
119 | if ( ! empty( $replies ) )
120 | $this->message = $this->replies[0]->message;
121 |
122 | return $this->message;
123 |
124 | }
125 |
126 | if ( 'last_reply_id' === $name ) {
127 | $replies = $this->get_replies();
128 | unset( $replies[0] );
129 | if ( ! empty( $replies ) ) {
130 | $this->last_reply_id = end( $replies )->message_id;
131 | reset( $this->replies );
132 | }
133 |
134 | return $this->last_reply_id;
135 | }
136 |
137 | return false;
138 | }
139 |
140 | public function get_replies() {
141 | $this->replies = incsub_support_get_ticket_replies( $this->ticket_id );
142 |
143 | return $this->replies;
144 | }
145 |
146 | public function get_staff_name() {
147 | $user = get_userdata( $this->admin_id );
148 |
149 | if ( ! $user )
150 | return __( 'Not yet assigned', INCSUB_SUPPORT_LANG_DOMAIN );
151 |
152 | return $user->display_name;
153 | }
154 |
155 | public function get_staff_login() {
156 | $user = get_userdata( $this->admin_id );
157 |
158 | if ( ! $user )
159 | return __( 'Not yet assigned', INCSUB_SUPPORT_LANG_DOMAIN );
160 |
161 | return $user->user_login;
162 | }
163 |
164 |
165 | public function get_user_name() {
166 | $user = get_userdata( $this->user_id );
167 |
168 | if ( ! $user )
169 | return __( 'User not found', INCSUB_SUPPORT_LANG_DOMAIN );
170 |
171 | return $user->display_name;
172 | }
173 |
174 | public function get_category_name() {
175 | if ( ! is_object( $this->category ) )
176 | return false;
177 |
178 | return $this->category->cat_name;
179 | }
180 |
181 |
182 | public function is_closed() {
183 | return $this->ticket_status == 5;
184 | }
185 |
186 | }
--------------------------------------------------------------------------------
/inc/classes/shortcodes/class-abstract-shortcode.php:
--------------------------------------------------------------------------------
1 | ';
13 | ob_start();
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/inc/classes/shortcodes/class-shortcode-faqs.php:
--------------------------------------------------------------------------------
1 | start();
12 |
13 | if ( ! incsub_support_current_user_can( 'read_faq' ) ) {
14 | if ( ! is_user_logged_in() )
15 | $message = sprintf( __( 'You must
log in to get support', INCSUB_SUPPORT_LANG_DOMAIN ), wp_login_url( get_permalink() ) );
16 | else
17 | $message = __( 'You don\'t have enough permissions to get support', INCSUB_SUPPORT_LANG_DOMAIN );
18 |
19 | $message = apply_filters( 'support_system_not_allowed_faqs_list_message', $message, 'faq-list' );
20 | ?>
21 |
22 |
23 |
24 | end();
26 | }
27 |
28 | incsub_support_get_template( 'index', 'faqs' );
29 |
30 | add_action( 'wp_footer', array( &$this, 'enqueue_custom_scripts' ) );
31 |
32 | return $this->end();
33 | }
34 |
35 | public function enqueue_custom_scripts() {
36 | incsub_support_enqueue_foundation_scripts();
37 | wp_enqueue_script( 'support-system-foundation-init', INCSUB_SUPPORT_PLUGIN_URL . 'assets/js/foundation-init.js', array( 'support-system-foundation-js' ), incsub_support_get_version(), true );
38 | }
39 | }
--------------------------------------------------------------------------------
/inc/classes/shortcodes/class-shortcode-submit-ticket-form.php:
--------------------------------------------------------------------------------
1 | $subject,
37 | 'message' => $message,
38 | 'ticket_priority' => $priority
39 | );
40 |
41 | if ( ! empty( $_FILES['support-attachment'] ) ) {
42 | $files_uploaded = incsub_support_upload_ticket_attachments( $_FILES['support-attachment'] );
43 |
44 | if ( ! $files_uploaded['error'] && ! empty( $files_uploaded['result'] ) ) {
45 | $args['attachments'] = wp_list_pluck( $files_uploaded['result'], 'url' );
46 | }
47 | elseif ( $files_uploaded['error'] && ! empty( $files_uploaded['result'] ) ) {
48 | $error_message = '
';
49 | foreach ( $files_uploaded['result'] as $error ) {
50 | $error_message .= '- ' . $error . '
';
51 | }
52 | $error_message .= '
';
53 | wp_die( $error_message );
54 | }
55 | }
56 |
57 | if ( isset( $_POST['support-system-ticket-category'] ) && absint( $_POST['support-system-ticket-category'] ) ) {
58 | $args['cat_id'] = absint( $_POST['support-system-ticket-category'] );
59 | }
60 |
61 | $args['blog_id'] = $blog_id;
62 | if ( ! empty( $_POST['support-system-ticket-blog'] ) ) {
63 | $blog_id = absint( $_POST['support-system-ticket-blog'] );
64 | $list = wp_list_pluck( get_blogs_of_user( $user_id ), 'userblog_id' );
65 | if ( in_array( $blog_id, $list ) )
66 | $args['blog_id'] = $blog_id;
67 | }
68 |
69 | $ticket_id = incsub_support_insert_ticket( $args );
70 |
71 | if ( is_wp_error( $ticket_id ) )
72 | wp_die( $ticket_id->get_error_message() );
73 |
74 | $redirect_to = incsub_support_get_support_page_url();
75 | if ( $redirect_to ) {
76 | wp_redirect( add_query_arg( 'tid', $ticket_id, $redirect_to ) );
77 | exit;
78 | }
79 |
80 | }
81 | }
82 |
83 | public function render( $atts ) {
84 | $this->start();
85 |
86 | if ( ! incsub_support_current_user_can( 'insert_ticket' ) ) {
87 | if ( ! is_user_logged_in() )
88 | $message = sprintf( __( 'You must
log in to submit a new ticket', INCSUB_SUPPORT_LANG_DOMAIN ), wp_login_url( get_permalink() ) );
89 | else
90 | $message = __( 'You don\'t have enough permissions to submit a new ticket', INCSUB_SUPPORT_LANG_DOMAIN );
91 |
92 | $message = apply_filters( 'support_system_not_allowed_submit_ticket_form_message', $message, 'ticket-form' );
93 | ?>
94 |
95 |
96 |
97 | end();
99 | }
100 |
101 | $defaults = array(
102 | 'blog_field' => true,
103 | 'priority_field' => true,
104 | 'category_field' => true
105 | );
106 |
107 | $atts = wp_parse_args( $atts, $defaults );
108 | extract( $atts );
109 |
110 | $blog_field = (bool)$blog_field;
111 |
112 | if ( ! incsub_support()->query->is_single_ticket ) {
113 | ?>
114 |
115 |
145 |
146 | end();
149 | }
150 | }
--------------------------------------------------------------------------------
/inc/classes/shortcodes/class-shortcode-tickets-index.php:
--------------------------------------------------------------------------------
1 | $category,
27 | 'ticket_priority' => $priority
28 | );
29 |
30 | $staff_name = $_POST['ticket-staff'];
31 | $possible_users = MU_Support_System::get_super_admins();
32 | if ( in_array( $staff_name, $possible_users ) ) {
33 | $user = get_user_by( 'login', $staff_name );
34 | if ( $user )
35 | $args['admin_id'] = $user->data->ID;
36 | }
37 |
38 | if ( empty( $staff_name ) )
39 | $args['admin_id'] = 0;
40 |
41 | $result = incsub_support_update_ticket( $ticket_id, $args );
42 |
43 | if ( $result ) {
44 | $url = add_query_arg( 'ticket-details-updated', 'true' );
45 | wp_redirect( $url );
46 | exit;
47 | }
48 |
49 |
50 | }
51 |
52 | if ( isset( $_POST['submit-close-ticket'] ) && incsub_support_current_user_can( 'close_ticket', incsub_support_get_the_ticket_id() ) ) {
53 | $ticket_id = absint( $_POST['ticket_id'] );
54 | $ticket = incsub_support_get_ticket( $ticket_id );
55 | if ( ! $ticket )
56 | return;
57 |
58 | $action = 'submit-close-ticket-' . $ticket_id;
59 | if ( ! wp_verify_nonce( $_POST['_wpnonce'], $action ) )
60 | wp_die( __( 'Security check error', INCSUB_SUPPORT_LANG_DOMAIN ) );
61 |
62 | if ( empty( $_POST['close-ticket'] ) )
63 | incsub_support_restore_ticket_previous_status( $ticket_id );
64 | else
65 | incsub_support_close_ticket( $ticket_id );
66 |
67 | $url = add_query_arg( 'ticket-closed-updated', 'true' );
68 | wp_redirect( $url );
69 | exit;
70 | }
71 |
72 | if ( isset( $_POST['support-system-submit-reply'] ) && incsub_support_current_user_can( 'insert_reply' ) ) {
73 |
74 | // Submitting a new reply from the front
75 | $fields = array_map( 'absint', $_POST['support-system-reply-fields'] );
76 |
77 | $ticket_id = $fields['ticket'];
78 | $user_id = $fields['user'];
79 | $blog_id = $fields['blog'];
80 |
81 | $action = 'support-system-submit-reply-' . $ticket_id . '-' . $user_id . '-' . $blog_id;
82 | if ( ! wp_verify_nonce( $_POST['_wpnonce'], $action ) )
83 | wp_die( __( 'Security check error', INCSUB_SUPPORT_LANG_DOMAIN ) );
84 |
85 | $message = $_POST['support-system-reply-message'];
86 |
87 | if ( empty( $message ) )
88 | wp_die( __( 'The reply message cannot be empty', INCSUB_SUPPORT_LANG_DOMAIN ) );
89 |
90 | $ticket = incsub_support_get_ticket( $ticket_id );
91 |
92 | if ( ! $ticket )
93 | wp_die( __( 'The ticket does not exist', INCSUB_SUPPORT_LANG_DOMAIN ) );
94 |
95 | if ( $user_id != get_current_user_id() )
96 | wp_die( __( 'Security check error', INCSUB_SUPPORT_LANG_DOMAIN ) );
97 |
98 | $args = array(
99 | 'poster_id' => get_current_user_id(),
100 | 'message' => $message
101 | );
102 |
103 | if ( ! empty( $_FILES['support-attachment'] ) ) {
104 | $files_uploaded = incsub_support_upload_ticket_attachments( $_FILES['support-attachment'] );
105 |
106 | if ( ! $files_uploaded['error'] && ! empty( $files_uploaded['result'] ) ) {
107 | $args['attachments'] = wp_list_pluck( $files_uploaded['result'], 'url' );
108 | }
109 | elseif ( $files_uploaded['error'] && ! empty( $files_uploaded['result'] ) ) {
110 | $error_message = '
';
111 | foreach ( $files_uploaded['result'] as $error ) {
112 | $error_message .= '- ' . $error . '
';
113 | }
114 | $error_message .= '
';
115 | wp_die( $error_message );
116 | }
117 | }
118 |
119 | $result = incsub_support_insert_ticket_reply( $ticket_id, $args );
120 |
121 | if ( ! $result )
122 | wp_die( __( 'There was an error while processing the form, please try again later', INCSUB_SUPPORT_LANG_DOMAIN ) );
123 |
124 | $ticket = incsub_support_get_ticket( $ticket_id );
125 |
126 | if ( $ticket->admin_id && $ticket->admin_id === get_current_user_id() && $ticket->user_id != $ticket->admin_id ) {
127 | $status = 2;
128 | }
129 | elseif ( ! $ticket->admin_id && $ticket->user_id === get_current_user_id() && $ticket->ticket_status != 0 ) {
130 | $status = 1;
131 | }
132 | elseif ( ! $ticket->admin_id && $ticket->user_id === get_current_user_id() && $ticket->ticket_status == 0 ) {
133 | $status = 0;
134 | }
135 | elseif ( $ticket->admin_id && $ticket->user_id === get_current_user_id() && $ticket->user_id != $ticket->admin_id ) {
136 | $status = 3;
137 | }
138 | elseif ( $ticket->admin_id && $ticket->admin_id === get_current_user_id() ) {
139 | $status = 1;
140 | }
141 | else {
142 | $status = $ticket->ticket_status;
143 | }
144 |
145 |
146 | if ( $status != $ticket->ticket_status )
147 | incsub_support_ticket_transition_status( $ticket->ticket_id, $status );
148 |
149 |
150 | $url = add_query_arg( 'support-system-reply-added', 'true' );
151 | $url = preg_replace( '/\#[a-zA-Z0-9\-]*$/', '', $url );
152 | $url .= '#support-system-reply-' . $result;
153 | wp_safe_redirect( $url );
154 | exit;
155 |
156 |
157 | }
158 | }
159 |
160 | public function render( $atts ) {
161 | $this->start();
162 |
163 | if ( ! incsub_support_current_user_can( 'read_ticket' ) ) {
164 | if ( ! is_user_logged_in() )
165 | $message = sprintf( __( 'You must
log in to get support', INCSUB_SUPPORT_LANG_DOMAIN ), wp_login_url( get_permalink() ) );
166 | else
167 | $message = __( 'You don\'t have enough permissions to get support', INCSUB_SUPPORT_LANG_DOMAIN );
168 |
169 | $message = apply_filters( 'support_system_not_allowed_tickets_list_message', $message, 'ticket-index' );
170 | ?>
171 |
172 |
173 |
174 | end();
176 | }
177 |
178 | if ( incsub_support_is_tickets_page() )
179 | incsub_support_get_template( 'index', 'tickets' );
180 | elseif ( incsub_support_is_single_ticket() )
181 | incsub_support_get_template( 'single', 'ticket' );
182 |
183 | return $this->end();
184 | }
185 | }
--------------------------------------------------------------------------------
/inc/helpers/capabilities.php:
--------------------------------------------------------------------------------
1 | roles[0] ) ? $user->roles[0] : '';
31 | if ( is_multisite() ) {
32 | // The user has not enough role in the Support blog.
33 | // Let's see if he has enough roles in other sites
34 | // This needs to be improved though
35 | $user_blogs = get_blogs_of_user( $user_id );
36 | $current_blog_id = get_current_blog_id();
37 | foreach ( $user_blogs as $blog ) {
38 | switch_to_blog( $blog->userblog_id );
39 | $user = get_userdata( $user_id );
40 | if ( isset( $user->roles[0] ) ) {
41 | $user_role = $user->roles[0];
42 | break;
43 | }
44 | }
45 |
46 | switch_to_blog( $current_blog_id );
47 | $GLOBALS['switched'] = false;
48 | $GLOBALS['_wp_switched_stack'] = array();
49 | }
50 |
51 | }
52 |
53 | wp_cache_set( $cache_key, $user_role, 'support_system_user_role' );
54 |
55 | }
56 |
57 | switch ( $cap ) {
58 | case 'insert_ticket':
59 | case 'read_ticket':
60 | case 'insert_reply': {
61 | if ( in_array( $user_role, $settings['incsub_support_tickets_role'] ) )
62 | $user_can = true;
63 | break;
64 | }
65 |
66 | case 'update_reply': { $user_can = false; break; }
67 |
68 | case 'insert_ticket_category':
69 | case 'update_ticket_category':
70 | case 'delete_ticket_category': {
71 | $user_can = false;
72 | break;
73 | }
74 |
75 | case 'read_faq': {
76 | if ( in_array( $user_role, $settings['incsub_support_faqs_role'] ) )
77 | $user_can = true;
78 | break;
79 | }
80 |
81 | case 'open_ticket':
82 | case 'close_ticket': {
83 | $user_can = false;
84 |
85 | if ( user_can( $user_id, 'manage_options' ) ) {
86 | $user_can = true;
87 | break;
88 | }
89 |
90 | $args = array_slice( func_get_args(), 2 );
91 | if ( isset( $args[0] ) ) {
92 | $ticket = incsub_support_get_ticket( $args[0] );
93 | if ( $ticket ) {
94 | $user_can = ( $ticket->user_id === $user_id || $ticket->admin_id === $user_id ) ? true : false;
95 | }
96 | }
97 | break;
98 | }
99 |
100 | case 'delete_ticket':
101 | case 'update_ticket': {
102 | $user_can = false;
103 | break;
104 | }
105 |
106 | case 'manage_options': { $user_can = false; break;}
107 |
108 | default: { $user_can = false; break; }
109 | }
110 | }
111 |
112 | /**
113 | * Filters the permissions for a user
114 | *
115 | * @param Boolean $user_can If the user is allowed to do something for a given capability
116 | * @param Integer $user_id User ID
117 | * @param String $cap Capability
118 | * @param Array $args Extra arguments passed to the function
119 | */
120 | return apply_filters( 'support_system_user_can', $user_can, $user_id, $cap, func_get_args() );
121 |
122 | }
123 |
124 | function incsub_support_is_staff( $user_id = false ) {
125 | if ( $user_id === false )
126 | $user_id = get_current_user_id();
127 |
128 | $is_staff = false;
129 |
130 | if ( incsub_support_user_can( $user_id, 'manage_options' ) )
131 | $is_staff = true;
132 |
133 | $is_staff = apply_filters( 'support_system_is_staff', $is_staff, $user_id );
134 |
135 | return $is_staff;
136 |
137 | }
138 |
139 | function incsub_support_get_capabilities() {
140 | return array(
141 | 'insert_ticket',
142 | 'delete_ticket',
143 | 'update_ticket',
144 | 'open_ticket',
145 | 'close_ticket',
146 | 'read_ticket',
147 |
148 | 'insert_reply',
149 | 'update_reply',
150 | 'delete_reply',
151 |
152 | 'insert_ticket_category',
153 | 'update_ticket_category',
154 | 'delete_ticket_category',
155 |
156 | 'manage_options',
157 |
158 | 'insert_faq',
159 | 'delete_faq',
160 | 'update_faq',
161 | 'read_faq'
162 | );
163 | }
--------------------------------------------------------------------------------
/inc/helpers/general.php:
--------------------------------------------------------------------------------
1 | 'ticket-priority',
36 | 'id' => false,
37 | 'show_empty' => __( '-- Select a priority --', INCSUB_SUPPORT_LANG_DOMAIN ),
38 | 'selected' => null,
39 | 'echo' => true
40 | );
41 | $args = wp_parse_args( $args, $defaults );
42 |
43 | extract( $args );
44 |
45 | if ( ! $id )
46 | $id = $name;
47 |
48 | if ( ! $echo )
49 | ob_start();
50 |
51 | $plugin_class = incsub_support();
52 | $priorities = $plugin_class::$ticket_priority;
53 | ?>
54 |
64 | 'super-admins',
73 | 'id' => false,
74 | 'show_empty' => __( 'Select a staff', INCSUB_SUPPORT_LANG_DOMAIN ),
75 | 'selected' => null,
76 | 'echo' => true,
77 | 'value' => 'username' // Or integer
78 | );
79 | $args = wp_parse_args( $args, $defaults );
80 |
81 | $plugin = incsub_support();
82 | $super_admins = MU_Support_System::get_super_admins();
83 |
84 | extract( $args );
85 |
86 | if ( ! $id )
87 | $id = $name;
88 |
89 | if ( ! $echo )
90 | ob_start();
91 | ?>
92 |
103 | $details ) {
118 | if ( $setting == $details['setting'] )
119 | $setting_errors[] = $support_system_errors[ $key ];
120 | }
121 | return $setting_errors;
122 | }
123 |
124 | return $support_system_errors;
125 | }
126 |
127 | function incsub_support_add_error( $setting, $code, $message ) {
128 | global $support_system_errors;
129 |
130 | $support_system_errors[] = array(
131 | 'setting' => $setting,
132 | 'code' => $code,
133 | 'message' => $message,
134 | );
135 | }
136 |
137 | function incsub_support_get_version() {
138 | return INCSUB_SUPPORT_PLUGIN_VERSION;
139 | }
140 |
141 |
142 | function incsub_support_register_main_script() {
143 | $suffix = '.min';
144 | if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
145 | $suffix = '';
146 |
147 | wp_register_script( 'support-system', INCSUB_SUPPORT_PLUGIN_URL . 'assets/js/support-system' . $suffix . '.js', array( 'jquery' ), incsub_support_get_version(), true );
148 |
149 | $l10n = array(
150 | 'ajaxurl' => admin_url( 'admin-ajax.php' )
151 | );
152 | wp_localize_script( 'support-system', 'support_system_strings', $l10n );
153 | }
154 |
155 | function incsub_support_enqueue_main_script() {
156 | if ( ! wp_script_is( 'support-system', 'registered' ) )
157 | incsub_support_register_main_script();
158 |
159 | wp_enqueue_script( 'support-system' );
160 |
161 | }
162 |
163 | function incsub_support_enqueue_foundation_scripts( $in_footer = true ) {
164 | $suffix = '.min';
165 | if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
166 | $suffix = '';
167 |
168 | wp_enqueue_script( 'support-system-foundation-js', INCSUB_SUPPORT_PLUGIN_URL . 'assets/js/foundation' . $suffix . '.js', array( 'jquery' ), incsub_support_get_version(), $in_footer );
169 | }
170 |
171 |
172 | /**
173 | * Adds an integration class to Support System
174 | *
175 | * @param $classname The class name of the integrator
176 | */
177 | function incsub_support_add_integrator( $classname ) {
178 | if ( class_exists( $classname ) ) {
179 | $plugin = incsub_support();
180 | $r = new ReflectionClass( $classname );
181 | $plugin->add_integrator( $r->newInstance() );
182 | }
183 | }
184 |
185 |
--------------------------------------------------------------------------------
/inc/helpers/settings.php:
--------------------------------------------------------------------------------
1 | settings->get_all();
5 | }
6 |
7 | function incsub_support_get_setting( $name ) {
8 | return incsub_support()->settings->get( $name );
9 | }
10 |
11 | function incsub_support_get_default_settings() {
12 | return incsub_support()->settings->get_default_settings();
13 | }
14 |
15 | function incsub_support_update_setting( $name, $value ) {
16 | incsub_support()->settings->set( $name, $value );
17 | }
18 |
19 | function incsub_support_update_settings( $value ) {
20 | incsub_support()->settings->update( $value );
21 | }
22 |
23 | function incsub_support_get_support_page_url() {
24 | $page = incsub_support_get_support_page_id();
25 | if ( 'page' === get_post_type( $page ) )
26 | return get_permalink( $page );
27 |
28 | return false;
29 | }
30 |
31 | function incsub_support_get_faqs_page_id() {
32 | return apply_filters( 'support_system_faqs_page_id', incsub_support()->settings->get( 'incsub_support_faqs_page' ) );
33 | }
34 |
35 | function incsub_support_get_support_page_id() {
36 | return apply_filters( 'support_system_support_page_id', incsub_support()->settings->get( 'incsub_support_support_page' ) );
37 | }
38 |
39 | function incsub_support_get_new_ticket_page_id() {
40 | return apply_filters( 'support_system_new_ticket_page_id', incsub_support()->settings->get( 'incsub_support_create_new_ticket_page' ) );
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/inc/helpers/ticket-reply.php:
--------------------------------------------------------------------------------
1 | id : 1;
13 | $tickets_replies_table = incsub_support()->model->tickets_messages_table;
14 |
15 | $query = $wpdb->prepare(
16 | "SELECT * FROM $tickets_replies_table
17 | WHERE ticket_id = %d
18 | ORDER BY message_id ASC",
19 | $ticket_id
20 | );
21 |
22 | $results = wp_cache_get( 'support-ticket-' . $ticket_id, 'support_system_ticket_replies' );
23 |
24 | if ( $results === false ){
25 | $results = $wpdb->get_results( $query );
26 | wp_cache_set( 'support-ticket-' . $ticket_id, $results, 'support_system_ticket_replies' );
27 | }
28 |
29 | if ( $results )
30 | $_replies = $results;
31 |
32 | $replies = array();
33 | $i = 0;
34 | foreach ( $_replies as $_reply ) {
35 | $reply = incsub_support_get_ticket_reply( $_reply );
36 |
37 | if ( $i === 0 )
38 | $reply->is_main_reply = true;
39 |
40 | $replies[] = $reply;
41 | $i++;
42 | }
43 |
44 | $replies = apply_filters( 'support_system_get_ticket_replies', $replies, $ticket_id );
45 | return $replies;
46 |
47 | }
48 |
49 | function incsub_support_get_ticket_reply( $ticket_reply ) {
50 | $ticket_reply = Incsub_Support_Ticket_Reply::get_instance( $ticket_reply );
51 | $ticket_reply = apply_filters( 'support_system_get_ticket_reply', $ticket_reply );
52 | return $ticket_reply;
53 | }
54 |
55 | /**
56 | * Insert a new reply for a ticket
57 | *
58 | * @param int $ticket_id
59 | * @param array $args
60 | * @return int|boolean
61 | */
62 | function incsub_support_insert_ticket_reply( $ticket_id, $args = array() ) {
63 | global $wpdb, $current_site;
64 |
65 | $current_site_id = ! empty ( $current_site ) ? $current_site->id : 1;
66 |
67 | $ticket = incsub_support_get_ticket( absint( $ticket_id ) );
68 |
69 | if ( ! $ticket )
70 | return false;
71 |
72 | wp_cache_delete( 'support-ticket-' . $ticket_id, 'support_system_ticket_replies' );
73 | wp_cache_delete( $ticket_id, 'support_system_tickets' );
74 |
75 | $defaults = array(
76 | 'site_id' => $current_site_id,
77 | 'poster_id' => 0,
78 | 'subject' => 'Re: ' . wp_unslash( $ticket->title ),
79 | 'message' => '',
80 | 'message_date' => current_time( 'mysql', 1 ),
81 | 'attachments' => array(),
82 | 'send_emails' => true
83 | );
84 |
85 | $args = wp_parse_args( $args, $defaults );
86 | extract( $args );
87 |
88 | $plugin = incsub_support();
89 | $tickets_replies_table = $plugin->model->tickets_messages_table;
90 |
91 | $message = wp_kses_post( wp_unslash( $message ) );
92 |
93 | $result = $wpdb->insert(
94 | $tickets_replies_table,
95 | array(
96 | 'site_id' => $site_id,
97 | 'ticket_id' => absint( $ticket_id ),
98 | 'admin_id' => is_super_admin( $poster_id ) ? absint( $poster_id ) : 0,
99 | 'user_id' => is_super_admin( $poster_id ) ? 0 : absint( $poster_id ),
100 | 'subject' => $subject,
101 | 'message' => $message,
102 | 'message_date' => $message_date,
103 | 'attachments' => maybe_serialize( $attachments )
104 | ),
105 | array( '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )
106 | );
107 |
108 | if ( ! $result )
109 | return false;
110 |
111 | $reply_id = $wpdb->insert_id;
112 |
113 | if ( ! $reply_id )
114 | return false;
115 |
116 | $reply = incsub_support_get_ticket_reply( $reply_id );
117 | incsub_support_recount_ticket_replies( $reply->ticket_id );
118 |
119 | $users_tagged = incsub_support_get_ticket_meta( $ticket_id, 'tagged_users', array() );
120 | if ( ! in_array( $poster_id, $users_tagged ) ) {
121 | $users_tagged[] = $poster_id;
122 | incsub_support_update_ticket_meta( $ticket_id, 'tagged_users', $users_tagged );
123 | }
124 |
125 | do_action( 'support_system_insert_ticket_reply', $reply_id, $send_emails );
126 |
127 | return $reply_id;
128 |
129 | }
130 |
131 |
132 | function incsub_support_delete_ticket_reply( $reply_id ) {
133 | global $wpdb, $current_site;
134 |
135 | $ticket_reply = incsub_support_get_ticket_reply( $reply_id );
136 | if ( ! $ticket_reply )
137 | return false;
138 |
139 | $ticket = incsub_support_get_ticket( $ticket_reply->ticket_id );
140 | if ( ! $ticket )
141 | return false;
142 |
143 | wp_cache_delete( 'support-ticket-' . $ticket->ticket_id, 'support_system_ticket_replies' );
144 | wp_cache_delete( $ticket->ticket_id, 'support_system_tickets' );
145 |
146 | $replies = $ticket->get_replies();
147 |
148 | $main_reply = wp_list_filter( $replies, array( 'is_main_reply' => true ) );
149 | $main_reply = $main_reply[0];
150 | if ( $main_reply->message_id == $reply_id ) {
151 | // Do not allow to delete the main reply
152 | return false;
153 | }
154 |
155 | $tickets_replies_table = incsub_support()->model->tickets_messages_table;
156 |
157 | $wpdb->query( $wpdb->prepare( "DELETE FROM $tickets_replies_table WHERE message_id = %d", $reply_id ) );
158 | incsub_support_recount_ticket_replies( $ticket_reply->ticket_id );
159 |
160 | $old_ticket_reply = $ticket_reply;
161 | do_action( 'support_system_delete_ticket_reply', $reply_id, $old_ticket_reply );
162 |
163 | return true;
164 | }
--------------------------------------------------------------------------------
/inc/support-menu.php:
--------------------------------------------------------------------------------
1 | is_network = $network;
43 | if ( ! $just_object ) {
44 | if ( $network ) {
45 | add_action( 'network_admin_menu', array( &$this, 'add_menu' ) );
46 | }
47 | else {
48 | add_action( 'admin_menu', array( &$this, 'add_menu' ) );
49 | }
50 | }
51 | }
52 |
53 | /**
54 | * Adds the menu to the Admin Panel
55 | *
56 | * @since 1.8
57 | */
58 | public function add_menu() {
59 |
60 | if ( ( ! $this->submenu ) ) {
61 | $menu_title = $this->menu_title;
62 |
63 | if ( $this->count_update )
64 | $menu_title .= '
' . $this->count_update . '';
65 |
66 | $this->page_id = add_menu_page(
67 | $this->page_title,
68 | $menu_title,
69 | $this->capability,
70 | $this->menu_slug,
71 | array( &$this, 'render_page' ),
72 | $this->icon_url,
73 | $this->position
74 | );
75 | }
76 | else {
77 | $this->page_id = add_submenu_page(
78 | $this->parent,
79 | $this->page_title,
80 | $this->menu_title,
81 | $this->capability,
82 | $this->menu_slug,
83 | array( &$this, 'render_page' )
84 | );
85 | }
86 |
87 | }
88 |
89 | /**
90 | * Renders the page
91 | *
92 | * @since 1.8
93 | */
94 | public function render_page() {
95 |
96 | if ( ! current_user_can( $this->capability ) )
97 | wp_die( __( 'You are not allowed to view this page.', INCSUB_SUPPORT_LANG_DOMAIN ) );
98 |
99 | ?>
100 |
101 | tabs ) ): ?>
102 |
103 | tabs as $tab ): ?>
104 |
105 |
106 |
107 |
108 |
109 | page_title; ?>
110 | add_new_link ): ?>
111 | add_new_link['label']; ?>
112 |
113 |
114 |
115 |
116 |
117 | render_content(); ?>
118 |
119 | is_network )
138 | return network_admin_url( 'admin.php?page=' . $this->menu_slug );
139 | else
140 | return admin_url( 'admin.php?page=' . $this->menu_slug );
141 | }
142 |
143 | /**
144 | * Retrieves a row in WP format
145 | *
146 | * @since 1.8
147 | *
148 | * @param String title Title of the row
149 | * @param String markup Content of the row
150 | */
151 | public function render_row( $title, $markup ) {
152 | ?>
153 |
154 | |
155 |
156 |
157 | |
158 |
159 | errors ) )
171 | $this->errors = array();
172 |
173 | $this->errors[ $slug ] = $message;
174 | }
175 |
176 | /**
177 | * Checks if there are errors
178 | *
179 | * @since 1.8
180 | *
181 | */
182 | public function is_error( $slug = null ) {
183 |
184 | if ( ! empty( $slug ) && isset( $this->errors[ $slug ] ) )
185 | return true;
186 | elseif ( empty( $slug ) ) {
187 | if ( $this->errors != false )
188 | return true;
189 | else
190 | return false;
191 | }
192 | }
193 |
194 | /**
195 | * Gets the errors list
196 | *
197 | * @since 1.8
198 | *
199 | */
200 | public function get_errors() {
201 | return $this->errors;
202 | }
203 |
204 | public function render_errors() {
205 | ?>
206 |
207 |
208 | get_errors() as $error ): ?>
209 |
210 |
211 |
212 |
213 | menu_slug ) ;
221 | }
222 |
223 | }
224 |
225 | }
--------------------------------------------------------------------------------
/inc/templates/faqs-nav.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/inc/templates/index-faqs.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/inc/templates/index-tickets.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 | 'label',
26 | 'replies_badge_class' => 'secondary',
27 | 'status_badge_class' => 'success'
28 | )
29 | );
30 | ?>
31 |
32 |
33 |
34 |
35 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 'pagination right',
54 | 'current_class' => 'current',
55 | 'disabled_class' => 'unavailable',
56 | 'arrow_class' => 'arrow'
57 | )
58 | );
59 | ?>
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/inc/templates/single-ticket.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | -
14 |
15 |
16 | -
17 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | 'panel support-system-ticket-details large-12 columns', 'title' => __( 'Ticket Details', INCSUB_SUPPORT_LANG_DOMAIN ) ),
55 | 'incsub_support_the_ticket_details_box'
56 | );
57 | ?>
58 |
59 | 'panel support-system-ticket-details support-system-staff-box large-12 columns', 'title' => __( 'Edit Ticket Details', INCSUB_SUPPORT_LANG_DOMAIN ) ),
62 | 'incsub_support_the_staff_box',
63 | array( 'submit_class' => 'button expand' )
64 | );
65 | ?>
66 |
67 |
68 |
69 | 'panel support-system-close-ticket large-12 columns' ),
72 | 'incsub_support_the_open_close_box',
73 | array( 'submit_class' => 'button tiny' )
74 | );
75 | ?>
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/inc/templates/ticket-replies.php:
--------------------------------------------------------------------------------
1 |
2 | 'row',
5 | 'author_class' => '',
6 | 'message_class' => '',
7 | 'date_class' => ''
8 | )
9 | ); ?>
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/inc/templates/ticket-reply.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/inc/templates/tickets-nav.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/inc/upgrades.php:
--------------------------------------------------------------------------------
1 | settings->get_default_settings();
15 | $old_settings = array(
16 | 'incsub_support_menu_name' => get_site_option( 'incsub_support_menu_name', $default_settings['incsub_support_menu_name'] ),
17 | 'incsub_support_from_name' => get_site_option( 'incsub_support_from_name', $default_settings['incsub_support_from_name'] ),
18 | 'incsub_support_from_mail' => get_site_option( 'incsub_support_from_mail', $default_settings['incsub_support_from_mail'] ),
19 | 'incsub_support_fetch_imap' => get_site_option('incsub_support_fetch_imap', $default_settings['incsub_support_fetch_imap'] ),
20 | 'incsub_support_imap_frequency' => get_site_option('incsub_support_imap_frequency', $default_settings['incsub_support_imap_frequency'] ),
21 | 'incsub_allow_only_pro_sites' => get_site_option( 'incsub_allow_only_pro_sites', $default_settings['incsub_allow_only_pro_sites'] ),
22 | 'incsub_pro_sites_level' => get_site_option( 'incsub_pro_sites_level', $default_settings['incsub_pro_sites_level'] ),
23 | 'incsub_allow_only_pro_sites_faq' => get_site_option( 'incsub_allow_only_pro_sites_faq', $default_settings['incsub_allow_only_pro_sites_faq'] ),
24 | 'incsub_pro_sites_faq_level' => get_site_option( 'incsub_pro_sites_faq_level', $default_settings['incsub_pro_sites_faq_level'] ),
25 | 'incsub_ticket_privacy' => get_site_option( 'incsub_ticket_privacy', $default_settings['incsub_ticket_privacy'] ),
26 | 'incsub_support_faq_enabled' => get_site_option( 'incsub_support_faq_enabled', false ),
27 | 'incsub_support_tickets_role' => get_site_option( 'incsub_support_tickets_role', $default_settings['incsub_support_tickets_role'] ),
28 | 'incsub_support_faqs_role' => get_site_option( 'incsub_support_faqs_role', $default_settings['incsub_support_faqs_role'] )
29 | );
30 | update_site_option( 'incsub_support_settings', $old_settings );
31 |
32 | foreach ( $old_settings as $key => $value ) {
33 | delete_site_option( $key );
34 | }
35 | }
36 | }
37 |
38 |
39 | /**
40 | * Upgrades the plugin
41 | *
42 | * @since 1.8
43 | *
44 | */
45 | function incsub_support_check_for_upgrades() {
46 |
47 | $saved_version = get_site_option( 'incsub_support_version', false );
48 |
49 | if ( $saved_version === false ) {
50 | incsub_support()->activate();
51 | }
52 |
53 | if ( ! $saved_version || version_compare( $saved_version, INCSUB_SUPPORT_PLUGIN_VERSION ) < 0 ) {
54 |
55 | $model = MU_Support_System_Model::get_instance();
56 |
57 | if ( version_compare( $saved_version, '1.7.2.2' ) < 0 )
58 | $model->upgrade_1722();
59 |
60 | if ( version_compare( $saved_version, '1.8' ) < 0 )
61 | $model->upgrade_18();
62 |
63 | if ( version_compare( $saved_version, '1.8.1' ) < 0 )
64 | $model->upgrade_181();
65 |
66 | if ( version_compare( $saved_version, '1.9.1' ) < 0 ) {
67 | incsub_support_set_new_roles();
68 | }
69 |
70 | if ( version_compare( $saved_version, '1.9.6' ) < 0 ) {
71 | $model->upgrade_196();
72 | }
73 |
74 | if ( version_compare( $saved_version, '1.9.8' ) < 0 ) {
75 | $model->upgrade_198();
76 | }
77 |
78 | if ( version_compare( $saved_version, '1.9.8.1' ) < 0 ) {
79 | $model->upgrade_1981();
80 | }
81 |
82 | if ( version_compare( $saved_version, '2.0beta4' ) < 0 ) {
83 | incsub_support_upgrade_20beta4();
84 | }
85 |
86 | if ( version_compare( $saved_version, '2.1' ) < 0 ) {
87 | incsub_support()->model->create_tables();
88 | }
89 |
90 | if ( version_compare( $saved_version, '2.1.8' ) < 0 ) {
91 | incsub_support()->model->create_tables();
92 | }
93 |
94 | update_site_option( 'incsub_support_version', INCSUB_SUPPORT_PLUGIN_VERSION );
95 |
96 | set_transient( 'incsub_support_welcome', true );
97 | }
98 |
99 | }
100 |
101 | function incsub_support_upgrade_20beta4() {
102 | $settings = incsub_support_get_settings();
103 | $super_admin = $settings['incsub_support_main_super_admin'];
104 |
105 | if ( ! is_numeric( $super_admin ) ) {
106 | $user = get_user_by( 'login', $super_admin );
107 | $super_admins = MU_Support_System::get_super_admins();
108 | if ( $user ) {
109 | $user_id = $user->ID;
110 | $found = false;
111 | foreach ( $super_admins as $key => $value ) {
112 | if ( $value === $super_admin )
113 | $found = $key;
114 | }
115 |
116 | if ( $found !== false ) {
117 | $settings['incsub_support_main_super_admin'] = $found;
118 | }
119 |
120 | }
121 | else {
122 | $settings['incsub_support_main_super_admin'] = key( $super_admins );
123 | }
124 | }
125 |
126 | incsub_support_update_settings( $settings );
127 | }
128 |
129 |
130 | /**
131 | * Sets a new system based on roles instead of capabilities
132 | *
133 | * @since 1.9.1
134 | */
135 | function incsub_support_set_new_roles() {
136 | global $wp_roles;
137 |
138 | $roles_settings = array(
139 | 'incsub_support_tickets_role' => incsub_support_get_setting( 'incsub_support_tickets_role' ),
140 | 'incsub_support_faqs_role' => incsub_support_get_setting( 'incsub_support_faqs_role' )
141 | );
142 |
143 | /**
144 | foreach ( $roles_settings as $key => $value ) {
145 | switch ( $value ) {
146 | case 'manage_options':
147 | incsub_support_get_setting( $key ) = array( 'administrator' );
148 | break;
149 | case 'publish_pages':
150 | incsub_support_get_setting( $key ) = array( 'administrator', 'editor' );
151 | break;
152 | case 'publish_posts':
153 | incsub_support_get_setting( $key ) = array( 'administrator', 'editor', 'author' );
154 | break;
155 | case 'edit_posts':
156 | incsub_support_get_setting( $key ) = array( 'administrator', 'editor', 'author', 'contributor' );
157 | break;
158 | case 'read':
159 | incsub_support_get_setting( $key ) = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
160 | break;
161 | }
162 | }
163 | **/
164 | }
--------------------------------------------------------------------------------
/license-foundation.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013-2015 ZURB, inc.
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "incsub-support",
3 | "main": "incsub-support.php",
4 | "version": "1.0.0",
5 | "pluginVersion": "2.1.9.4",
6 | "private": true,
7 | "description": "Set up an awesome support ticket system on any WordPress site, complete with FAQ.",
8 | "projectEditUrl": "https://premium.wpmudev.org/wp-admin/edit.php?post_type=project&page=projects-manage&manage_files=36",
9 | "directories": {
10 | "test": "tests"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+ssh://git@bitbucket.org/incsub/incsub-support.git"
15 | },
16 | "scripts": {
17 | "build": "grunt build",
18 | "release": "grunt version-compare && git-branch-is master && git submodule update --remote && grunt build && grunt finish"
19 | },
20 | "author": "WPMU DEV",
21 | "license": "GPL-2.0",
22 | "homepage": "https://premium.wpmudev.org/project/support-system/",
23 | "devDependencies": {
24 | "bower": "*",
25 | "del": "1.2.0",
26 | "git-branch-is": "^0.1.0",
27 | "grunt": "~0.4.5",
28 | "grunt-checktextdomain": "^0.1.1",
29 | "grunt-contrib-clean": "~0.5.0",
30 | "grunt-contrib-compress": "~0.8.0",
31 | "grunt-contrib-copy": "~0.5.0",
32 | "grunt-contrib-jshint": "^1.0.0",
33 | "grunt-contrib-uglify": "^1.0.1",
34 | "grunt-contrib-watch": "^1.0.0",
35 | "grunt-exec": "~0.4.5",
36 | "grunt-open": "^0.2.3",
37 | "grunt-phpunit": "^0.3.6",
38 | "grunt-potomo": "~2.1.0",
39 | "grunt-search": "^0.1.8",
40 | "grunt-wp-i18n": "~0.5.0",
41 | "gulp": "3.9.0",
42 | "gulp-bower": "0.0.10",
43 | "gulp-clean": "^0.3.2",
44 | "gulp-compass": "2.1.0",
45 | "gulp-rename": "1.2.2",
46 | "gulp-rm": "^1.0.2",
47 | "gulp-uglify": "1.2.0",
48 | "load-grunt-tasks": "~0.2.0"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 | ./tests/
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | activate();
20 | }
21 |
22 | function tearDown() {
23 | global $wpdb;
24 |
25 | parent::tearDown();
26 |
27 | $model = incsub_support_get_model();
28 | $wpdb->query( "DROP TABLE IF EXISTS $model->tickets_messages_table;" );
29 | $wpdb->query( "DROP TABLE IF EXISTS $model->ticketmeta;" );
30 | $wpdb->query( "DROP TABLE IF EXISTS $model->faq_table;" );
31 | $wpdb->query( "DROP TABLE IF EXISTS $model->faq_cats_table;" );
32 | $wpdb->query( "DROP TABLE IF EXISTS $model->tickets_table;" );
33 | $wpdb->query( "DROP TABLE IF EXISTS $model->tickets_cats_table;" );
34 | delete_site_option( 'incsub_support_version' );
35 |
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/tests/lib/pro-sites.php:
--------------------------------------------------------------------------------
1 | markTestSkipped( 'Support plugin is not installed.' );
20 | }
21 |
22 | $_SERVER['SERVER_NAME'] = 'example.com';
23 | $_SERVER['REMOTE_ADDR'] = '';
24 |
25 | incsub_support()->activate();
26 | incsub_support()->init_plugin();
27 |
28 |
29 | } // end setup
30 |
31 | function tearDown() {
32 | parent::tearDown();
33 | }
34 |
35 | function test_insert_ticket() {
36 |
37 | // Login a user
38 | $user_id = $this->factory->user->create_object(
39 | $this->factory->user->generate_args()
40 | );
41 | wp_set_current_user( $user_id );
42 |
43 | // Create a new blog
44 | $blog_id = $this->factory->blog->create_object(
45 | $this->factory->blog->generate_args()
46 | );
47 |
48 | switch_to_blog( $blog_id );
49 |
50 | $args = array(
51 | 'ticket_priority' => 2,
52 | 'admin_id' => 1,
53 | 'site_id' => 2,
54 | 'view_by_superadmin' => 1,
55 | 'title' => 'Ticket title',
56 | 'message' => 'Ticket message',
57 | );
58 |
59 | $time = current_time( 'mysql' );
60 | $ticket_id = incsub_support_insert_ticket( $args );
61 |
62 | $this->assertNotInstanceOf( 'WP_Error', $ticket_id );
63 |
64 | $ticket = incsub_support_get_ticket( $ticket_id );
65 |
66 | $this->assertContains( $args['message'], $ticket->message );
67 | $this->assertEquals( $ticket->cat_id, incsub_support_get_default_ticket_category()->cat_id );
68 | $this->assertEquals( $ticket->user_id, get_current_user_id() );
69 | $this->assertEquals( $ticket->admin_id, $args['admin_id'] );
70 | $this->assertEquals( $ticket->last_reply_id, 0 );
71 | $this->assertEquals( $ticket->blog_id, $blog_id );
72 | $this->assertEquals( $ticket->site_id, $args['site_id'] );
73 | $this->assertEquals( $ticket->ticket_status, 0 );
74 | $this->assertEquals( $ticket->num_replies, 0 );
75 | $this->assertEquals( $ticket->title, $args['title'] );
76 | $this->assertEquals( $ticket->ticket_opened, $time );
77 | $this->assertEquals( $ticket->ticket_updated, $ticket->ticket_opened );
78 | $this->assertEquals( $ticket->ticket_updated, $ticket->ticket_opened );
79 | $this->assertCount( 1, $ticket->get_replies() );
80 |
81 | $staff = get_userdata( $args['admin_id'] );
82 | $this->assertEquals( $staff->data->display_name, $ticket->get_staff_name() );
83 | $this->assertEquals( $staff->data->user_login, $ticket->get_staff_login() );
84 | $this->assertFalse( $ticket->is_closed() );
85 |
86 | restore_current_blog();
87 | }
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/tests/test-empty.php:
--------------------------------------------------------------------------------
1 | assertEquals( $cat->cat_name, 'A category' );
15 |
16 | }
17 |
18 | function test_update_faq_category() {
19 |
20 | $cat_id = incsub_support_insert_faq_category( 'A category' );
21 |
22 | $cat = incsub_support_get_faq_category( $cat_id );
23 |
24 | incsub_support_update_faq_category( $cat_id, array( 'cat_name' => 'New category name' ) );
25 |
26 | $cat = incsub_support_get_faq_category( $cat_id );
27 |
28 | $this->assertEquals( $cat->cat_name, 'New category name' );
29 | }
30 |
31 | function test_delete_faq_category() {
32 | $cat_id = incsub_support_insert_faq_category( 'A category' );
33 | incsub_support_delete_faq_category( $cat_id );
34 |
35 | $cat = incsub_support_get_faq_category( $cat_id );
36 | $this->assertFalse( $cat );
37 | }
38 |
39 | function test_set_default_faq_category() {
40 | $default = incsub_support_get_default_faq_category();
41 |
42 | $cat_id = incsub_support_insert_faq_category( 'A category' );
43 |
44 | incsub_support_set_default_faq_category( $cat_id );
45 |
46 | $cat = incsub_support_get_default_faq_category( $cat_id );
47 | $this->assertEquals( $cat->cat_name, 'A category' );
48 | }
49 |
50 | function test_delete_default_category() {
51 | $first_default_category = incsub_support_get_default_faq_category();
52 |
53 | $cat_id = incsub_support_insert_faq_category( 'A category' );
54 |
55 | incsub_support_set_default_faq_category( $cat_id );
56 |
57 | // We cannot delete the default category
58 | $result = incsub_support_delete_faq_category( $cat_id );
59 | $this->assertFalse( $result );
60 | }
61 |
62 |
63 | function test_get_faq_categories() {
64 |
65 | $cat_id_1 = incsub_support_insert_faq_category( 'A category 1' );
66 | $cat_id_2 = incsub_support_insert_faq_category( 'A category 2' );
67 | $cat_id_3 = incsub_support_insert_faq_category( 'A category 3' );
68 |
69 | $cats = incsub_support_get_faq_categories();
70 |
71 | $this->assertCount( 4, $cats );
72 |
73 | incsub_support_delete_faq_category( $cat_id_2 );
74 |
75 | $cats = incsub_support_get_faq_categories();
76 |
77 | $this->assertCount( 3, $cats );
78 | }
79 |
80 | function test_count_faqs_for_category() {
81 | $cat_id = incsub_support_insert_faq_category( 'A category' );
82 | $cat = incsub_support_get_faq_category( $cat_id );
83 |
84 | $args = array(
85 | 'cat_id' => $cat_id,
86 | 'question' => 'A question',
87 | 'answer' => 'An answer'
88 | );
89 | $faq_1 = incsub_support_insert_faq( $args );
90 | $faq_2 = incsub_support_insert_faq( $args );
91 |
92 | $this->assertEquals( 2, $cat->get_faqs_count() );
93 |
94 | $faq_3 = incsub_support_insert_faq( $args );
95 | $this->assertEquals( 3, $cat->get_faqs_count() );
96 |
97 | $new_cat_id = incsub_support_insert_faq_category( 'A category 2' );
98 | $args = array( 'cat_id' => $new_cat_id );
99 | incsub_support_update_faq( $faq_3, $args );
100 |
101 | $this->assertEquals( 2, $cat->get_faqs_count() );
102 |
103 | incsub_support_delete_faq( $faq_1 );
104 |
105 | $this->assertEquals( 1, $cat->get_faqs_count() );
106 | }
107 |
108 | function test_reassign_faqs_to_default_category() {
109 | $cat_id = incsub_support_insert_faq_category( 'A category' );
110 | $cat = incsub_support_get_faq_category( $cat_id );
111 |
112 | $default_category = incsub_support_get_default_faq_category();
113 |
114 | $this->assertEquals( 0, $default_category->get_faqs_count() );
115 |
116 | $args = array(
117 | 'cat_id' => $cat_id,
118 | 'question' => 'A question',
119 | 'answer' => 'An answer'
120 | );
121 | $faq_1 = incsub_support_insert_faq( $args );
122 | $faq_2 = incsub_support_insert_faq( $args );
123 |
124 | incsub_support_delete_faq_category( $cat_id );
125 |
126 | $this->assertEquals( 2, $default_category->get_faqs_count() );
127 | }
128 |
129 | function test_insert_duplicated_faq_category() {
130 | $cat_id = incsub_support_insert_faq_category( 'A category' );
131 | $cat_id = incsub_support_insert_faq_category( 'A category' );
132 |
133 | $this->assertFalse( $cat_id );
134 | }
135 |
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/tests/test-faq.php:
--------------------------------------------------------------------------------
1 | 'The question',
12 | 'answer' => 'The answer',
13 | );
14 |
15 | $faq_id = incsub_support_insert_faq( $args );
16 | $faq = incsub_support_get_faq( $faq_id );
17 |
18 | $this->assertEquals( $faq->question, $args['question'] );
19 | $this->assertEquals( $faq->answer, $args['answer'] );
20 | $this->assertEquals( $faq->help_views, 0 );
21 | $this->assertEquals( $faq->help_count, 0 );
22 | $this->assertEquals( $faq->help_yes, 0 );
23 | $this->assertEquals( $faq->help_no, 0 );
24 | }
25 |
26 | function test_update_faq() {
27 | $args = array(
28 | 'question' => 'The question',
29 | 'answer' => 'The answer',
30 | );
31 |
32 | $faq_id = incsub_support_insert_faq( $args );
33 |
34 | $new_answer = "The new answer";
35 |
36 | incsub_support_update_faq( $faq_id, array( 'answer' => $new_answer ) );
37 |
38 | $faq = incsub_support_get_faq( $faq_id );
39 |
40 | $this->assertEquals( $faq->answer, $new_answer );
41 | }
42 |
43 | function test_vote_faq() {
44 | $args = array(
45 | 'question' => 'The question',
46 | 'answer' => 'The answer',
47 | );
48 |
49 | $faq_id = incsub_support_insert_faq( $args );
50 |
51 | incsub_support_vote_faq( $faq_id, true );
52 |
53 | $faq = incsub_support_get_faq( $faq_id );
54 | $this->assertEquals( $faq->help_yes, 1 );
55 | $this->assertEquals( $faq->help_no, 0 );
56 |
57 | incsub_support_vote_faq( $faq_id, true );
58 |
59 | $faq = incsub_support_get_faq( $faq_id );
60 | $this->assertEquals( $faq->help_yes, 2 );
61 | $this->assertEquals( $faq->help_no, 0 );
62 |
63 | incsub_support_vote_faq( $faq_id, false );
64 |
65 | $faq = incsub_support_get_faq( $faq_id );
66 | $this->assertEquals( $faq->help_yes, 2 );
67 | $this->assertEquals( $faq->help_no, 1 );
68 | }
69 |
70 | function test_delete_faq() {
71 | $args = array(
72 | 'question' => 'The question',
73 | 'answer' => 'The answer',
74 | );
75 |
76 | $faq_id = incsub_support_insert_faq( $args );
77 |
78 | incsub_support_delete_faq( $faq_id );
79 |
80 | $this->assertFalse( incsub_support_get_faq( $faq_id ) );
81 | }
82 |
83 | function test_get_faqs() {
84 | $args = array(
85 | 'question' => 'The question',
86 | 'answer' => 'The answer',
87 | );
88 | $faq_id_1 = incsub_support_insert_faq( $args );
89 | $faq_id_2 = incsub_support_insert_faq( $args );
90 | $faq_id_3 = incsub_support_insert_faq( $args );
91 |
92 | $faq_1 = incsub_support_get_faq( $faq_id_1 );
93 |
94 | $faqs = incsub_support_get_faqs();
95 | $this->assertCount( 3, $faqs );
96 |
97 | incsub_support_delete_faq( $faq_id_2 );
98 |
99 | $faqs = incsub_support_get_faqs();
100 | $this->assertCount( 2, $faqs );
101 |
102 | $args = array( 'answer' => 'New answer' );
103 | incsub_support_update_faq( $faq_id_1, $args );
104 |
105 | $faqs = incsub_support_get_faqs();
106 | $this->assertCount( 2, $faqs );
107 | $faqs = wp_list_filter( $faqs, array( 'faq_id' => $faq_id_1 ) );
108 | $new_faq_1 = $faqs[0];
109 |
110 | $this->assertEquals( $new_faq_1->answer, 'New answer' );
111 | }
112 |
113 | function test_search_faqs() {
114 | $args = array(
115 | 'question' => 'The question',
116 | 'answer' => 'The answer',
117 | );
118 |
119 | $faq_id = incsub_support_insert_faq( $args );
120 |
121 | $args = array(
122 | 's' => 'qqqqq'
123 | );
124 | $faqs = incsub_support_get_faqs( $args );
125 | $this->assertEmpty( $faqs );
126 |
127 | $args = array(
128 | 's' => 'an'
129 | );
130 | $faqs = incsub_support_get_faqs( $args );
131 | $this->assertCount( 1, $faqs );
132 | }
133 |
134 | function test_get_faqs_by_category() {
135 | $cat_id_1 = incsub_support_insert_faq_category( 'A category 1' );
136 | $cat_id_2 = incsub_support_insert_faq_category( 'A category 2' );
137 |
138 | $args = array(
139 | 'question' => 'The question',
140 | 'answer' => 'The answer',
141 | 'cat_id' => $cat_id_1
142 | );
143 |
144 | $faq_id_1 = incsub_support_insert_faq( $args );
145 |
146 | $args = array(
147 | 'question' => 'The question 2',
148 | 'answer' => 'The answer 2',
149 | 'cat_id' => $cat_id_1
150 | );
151 |
152 | $faq_id_2 = incsub_support_insert_faq( $args );
153 |
154 | $args = array(
155 | 'question' => 'The question 3',
156 | 'answer' => 'The answer 3',
157 | 'cat_id' => $cat_id_2
158 | );
159 |
160 | $faq_id_3= incsub_support_insert_faq( $args );
161 |
162 | $args = array(
163 | 'question' => 'The question 4',
164 | 'answer' => 'The answer 4'
165 | );
166 |
167 | $faq_id_4= incsub_support_insert_faq( $args );
168 |
169 | $faqs = incsub_support_get_faqs( array( 'category' => $cat_id_1 ) );
170 | $this->assertCount( 2, $faqs );
171 |
172 | $faqs = incsub_support_get_faqs( array( 'category' => $cat_id_2 ) );
173 | $this->assertCount( 1, $faqs );
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/tests/test-integration.php:
--------------------------------------------------------------------------------
1 | integrators as $integrator ) {
18 | if ( $integrator instanceof Support_System_Pro_Sites_Integration )
19 | $found = true;
20 | }
21 |
22 | $this->assertTrue( $found );
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/tests/test-ticket-category.php:
--------------------------------------------------------------------------------
1 | factory->user->create_object(
12 | $this->factory->user->generate_args()
13 | );
14 | wp_set_current_user( $user_id );
15 |
16 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
17 |
18 | $cat = incsub_support_get_ticket_category( $cat_id );
19 |
20 | $this->assertEquals( $cat->cat_name, 'A category' );
21 | $this->assertEquals( $cat->user_id, get_current_user_id() );
22 |
23 | }
24 |
25 | function test_update_ticket_category() {
26 | $user_id = $this->factory->user->create_object(
27 | $this->factory->user->generate_args()
28 | );
29 | wp_set_current_user( $user_id );
30 |
31 | $user_id_2 = $this->factory->user->create_object(
32 | $this->factory->user->generate_args()
33 | );
34 |
35 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
36 |
37 | $cat = incsub_support_get_ticket_category( $cat_id );
38 |
39 | incsub_support_update_ticket_category( $cat_id, array( 'cat_name' => 'New category name', 'user_id' => $user_id_2 ) );
40 |
41 | $cat = incsub_support_get_ticket_category( $cat_id );
42 |
43 | $this->assertEquals( $cat->cat_name, 'New category name' );
44 | $this->assertEquals( $cat->user_id, $user_id_2 );
45 | }
46 |
47 | function test_delete_ticket_category() {
48 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
49 | incsub_support_delete_ticket_category( $cat_id );
50 |
51 | $cat = incsub_support_get_ticket_category( $cat_id );
52 | $this->assertFalse( $cat );
53 | }
54 |
55 | function test_set_default_ticket_category() {
56 | $default = incsub_support_get_default_ticket_category();
57 |
58 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
59 |
60 | incsub_support_set_default_ticket_category( $cat_id );
61 |
62 | $cat = incsub_support_get_default_ticket_category( $cat_id );
63 | $this->assertEquals( $cat->cat_name, 'A category' );
64 | }
65 |
66 | function test_delete_default_category() {
67 | $first_default_category = incsub_support_get_default_ticket_category();
68 |
69 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
70 |
71 | incsub_support_set_default_ticket_category( $cat_id );
72 |
73 | // We cannot delete the default category
74 | $result = incsub_support_delete_ticket_category( $cat_id );
75 | $this->assertFalse( $result );
76 | }
77 |
78 | function test_get_ticket_categories() {
79 |
80 | $cat_id_1 = incsub_support_insert_ticket_category( 'A category 1' );
81 | $cat_id_2 = incsub_support_insert_ticket_category( 'A category 2' );
82 | $cat_id_3 = incsub_support_insert_ticket_category( 'A category 3' );
83 |
84 | $cats = incsub_support_get_ticket_categories();
85 |
86 | $this->assertCount( 4, $cats );
87 |
88 | incsub_support_delete_ticket_category( $cat_id_2 );
89 |
90 | $cats = incsub_support_get_ticket_categories();
91 |
92 | $this->assertCount( 3, $cats );
93 | }
94 |
95 | function test_count_tickets_for_category() {
96 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
97 | $cat = incsub_support_get_ticket_category( $cat_id );
98 |
99 | $args = array(
100 | 'cat_id' => $cat_id,
101 | 'title' => 'A ticket',
102 | 'message' => 'A ticket message'
103 | );
104 | $ticket_1 = incsub_support_insert_ticket( $args );
105 | $ticket_2 = incsub_support_insert_ticket( $args );
106 |
107 | $this->assertEquals( 2, $cat->get_tickets_count() );
108 |
109 | $ticket_3 = incsub_support_insert_ticket( $args );
110 | $this->assertEquals( 3, $cat->get_tickets_count() );
111 |
112 | $new_cat_id = incsub_support_insert_ticket_category( 'A category 2' );
113 | $args = array( 'cat_id' => $new_cat_id );
114 | incsub_support_update_ticket( $ticket_3, $args );
115 |
116 | $this->assertEquals( 2, $cat->get_tickets_count() );
117 |
118 | incsub_support_delete_ticket( $ticket_1 );
119 |
120 | $this->assertEquals( 1, $cat->get_tickets_count() );
121 | }
122 |
123 | function test_reassign_tickets_to_default_category() {
124 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
125 | $cat = incsub_support_get_ticket_category( $cat_id );
126 |
127 | $default_category = incsub_support_get_default_ticket_category();
128 | $this->assertEquals( 0, $default_category->get_tickets_count() );
129 |
130 | $args = array(
131 | 'cat_id' => $cat_id,
132 | 'title' => 'A ticket',
133 | 'message' => 'A ticket message'
134 | );
135 | $ticket_1 = incsub_support_insert_ticket( $args );
136 | $ticket_2 = incsub_support_insert_ticket( $args );
137 |
138 | incsub_support_delete_ticket_category( $cat_id );
139 |
140 | $this->assertEquals( 2, $default_category->get_tickets_count() );
141 | }
142 |
143 | function test_insert_duplicated_ticket_category() {
144 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
145 | $cat_id = incsub_support_insert_ticket_category( 'A category' );
146 |
147 | $this->assertFalse( $cat_id );
148 | }
149 |
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/tests/test-ticket-reply.php:
--------------------------------------------------------------------------------
1 | factory->user->create_object(
13 | $this->factory->user->generate_args()
14 | );
15 |
16 | $args = array(
17 | 'title' => 'Ticket title',
18 | 'message' => 'Ticket message',
19 | );
20 |
21 | $ticket_id = incsub_support_insert_ticket( $args );
22 |
23 | $reply_args = array(
24 | 'poster_id' => $user_id,
25 | 'message' => 'This is a ticket reply',
26 | );
27 | $reply_id = incsub_support_insert_ticket_reply( $ticket_id, $reply_args );
28 |
29 | $ticket = incsub_support_get_ticket( $ticket_id );
30 |
31 | $this->assertEquals( $ticket->last_reply_id, $reply_id );
32 | $this->assertEquals( $ticket->num_replies, 1 );
33 |
34 | $reply = incsub_support_get_ticket_reply( $reply_id );
35 | $this->assertEquals( $reply->get_poster_id(), $reply_args['poster_id'] );
36 | $this->assertContains( $reply_args['message'], $reply->message );
37 | }
38 |
39 | function test_delete_ticket_reply() {
40 | $args = array(
41 | 'title' => 'Ticket title',
42 | 'message' => 'Ticket message',
43 | );
44 |
45 | $ticket_id = incsub_support_insert_ticket( $args );
46 |
47 | $reply_args = array(
48 | 'message' => 'This is a ticket reply',
49 | );
50 | $reply_id = incsub_support_insert_ticket_reply( $ticket_id, $reply_args );
51 |
52 | $result = incsub_support_delete_ticket_reply( $reply_id );
53 | $this->assertTrue( $result );
54 |
55 | $ticket = incsub_support_get_ticket( $ticket_id );
56 |
57 | $this->assertEquals( $ticket->last_reply_id, $reply_id );
58 | $this->assertEquals( $ticket->num_replies, 1 );
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/tmp/log-search.log:
--------------------------------------------------------------------------------
1 | {
2 | "numResults": 1,
3 | "creationDate": "2017-07-24 07:35:14",
4 | "results": {
5 | "incsub-support.php": [
6 | {
7 | "line": 9,
8 | "match": "Version: 2.1.9.4"
9 | }
10 | ]
11 | }
12 | }
--------------------------------------------------------------------------------