PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.7
3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / frontend / class-wpsc-shortcode-two.php

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

162 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Shortcode_Two' ) ) :
7
8 final class WPSC_Shortcode_Two {
9
10 /**
11 * Initialize this class
12 */
13 public static function init() {
14
15 // register shortcode.
16 add_shortcode( 'wpsc_create_ticket', array( __CLASS__, 'layout' ) );
17 }
18
19 /**
20 * Layout for this shortcode
21 *
22 * @param array $attrs - Shortcode attributes.
23 * @return string
24 */
25 public static function layout( $attrs ) {
26
27 $current_user = WPSC_Current_User::$current_user;
28 $gs = get_option( 'wpsc-gs-general' );
29
30 // logout if guest login is open-ticket.
31 if ( WPSC_Current_User::$login_type == 'guest' && WPSC_Current_User::$guest_login_type == 'open-ticket' ) {
32 $current_user->logout();
33 }
34
35 ob_start();?>
36 <div id="wpsc-container" style="display:none;">
37 <div class="wpsc-shortcode-container" style="border: none !important;">
38 <?php
39
40 if (
41 ! $current_user->is_guest ||
42 $current_user->is_customer ||
43 ( $current_user->is_guest && in_array( 'guest', $gs['allow-create-ticket'] ) )
44 ) {
45
46 // js ready function.
47 add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) );
48 ?>
49 <div class="wpsc-body"></div>
50 <?php
51
52 } else {
53
54 WPSC_Frontend::load_authentication_screen();
55 }
56 ?>
57
58 </div>
59 </div>
60 <?php
61 WPSC_Frontend::load_html_snippets();
62 self::load_js_functions();
63 return ob_get_clean();
64 }
65
66 /**
67 * Load js functions for this shortcode
68 *
69 * @return void
70 */
71 public static function load_js_functions() {
72 ?>
73
74 <script type="text/javascript">
75 /**
76 * Get create ticket form
77 */
78 function wpsc_get_ticket_form() {
79
80 if (wpsc_is_description_text()) {
81 if ( confirm(supportcandy.translations.warning_message)) {
82 current_ticket = jQuery('#wpsc-current-ticket').val();
83 wpsc_clear_saved_draft_reply( current_ticket );
84 }else{
85 return;
86 }
87 }
88
89 jQuery('.wpsc-body').html(supportcandy.loader_html);
90
91 if (supportcandy.is_reload != 1) {
92 wpsc_scroll_top();
93 } else { supportcandy.is_reload = 0 }
94
95 var url = new URL(window.location.href);
96 var search_params = url.searchParams;
97
98 var data = {
99 action: 'wpsc_get_ticket_form',
100 _ajax_nonce: supportcandy.nonce
101 };
102 search_params.forEach(function(value, key) {
103 data[key] = value;
104 });
105 jQuery.post(supportcandy.ajax_url, data, function (response) {
106 jQuery('.wpsc-body').html(response);
107 wpsc_reset_responsive_style();
108 });
109 }
110
111 /**
112 * Get individual ticket
113 */
114 function wpsc_get_individual_ticket(id) {
115
116 jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active');
117 jQuery('.wpsc-tickets-nav.ticket-list, .wpsc-humbargar-menu-item.ticket-list').addClass('active');
118 jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.ticket_list);
119
120 // set url
121 var url = new URL(window.location.href);
122 var search_params = url.searchParams;
123 search_params.set('wpsc-section', 'ticket-list');
124 search_params.set('ticket-id', id);
125 url.search = search_params.toString();
126 window.history.replaceState({}, null, url.toString());
127
128 jQuery('.wpsc-body').html(supportcandy.loader_html);
129
130 // set flag to differenciate between ticket list and individual ticket
131 supportcandy.ticketListIsIndividual = true;
132
133 var data = {
134 action: 'wpsc_get_individual_ticket',
135 ticket_id: id,
136 };
137 search_params.forEach(function(value, key) {
138 data[key] = value;
139 });
140 jQuery.post(supportcandy.ajax_url, data, function (response) {
141 jQuery('.wpsc-body').html(response);
142 wpsc_reset_responsive_style();
143 });
144 }
145 </script>
146 <?php
147 }
148
149 /**
150 * JS ready function
151 *
152 * @return void
153 */
154 public static function register_js_ready_function() {
155
156 echo 'wpsc_get_ticket_form();' . PHP_EOL;
157 }
158 }
159 endif;
160
161 WPSC_Shortcode_Two::init();
162