9
9
* License:
10
10
*/
11
11
12
- include_once ( ABSPATH . 'wp-load.php ' );
12
+
13
+ //Block direct access to plugin files
14
+ defined ( 'ABSPATH ' ) or die ();
15
+
13
16
if (!class_exists ("FreshDeskAPI " )){
14
17
class FreshDeskAPI{
15
18
@@ -28,7 +31,7 @@ function __construct(){
28
31
add_action ( 'init ' , array ( $ this , 'init ' ) );
29
32
//add_action( 'admin_init', array( $this, 'ajax_init' ) );
30
33
add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ) );
31
- add_shortcode ( "fetch_tickets " , array ($ this , "fetch_tickets " ));
34
+ add_shortcode ( "fd_fetch_tickets " , array ($ this , "fetch_tickets " ));
32
35
include_once ( 'admin-settings.php ' );
33
36
$ this ->options = get_option ( 'fd_url ' );
34
37
$ this ->opt = get_option ( 'fd_apikey ' );
@@ -45,6 +48,8 @@ function __construct(){
45
48
function enqueue_scripts () {
46
49
wp_register_style ( 'style ' , plugins_url ('css/style.css ' , __FILE__ ) );
47
50
wp_enqueue_style ( 'style ' );
51
+ wp_register_script ( 'fd-script-frontend ' , plugins_url ('js/fd-script-frontend.js ' , __FILE__ ), array ('jquery ' ), '1.1 ' , true );
52
+ wp_enqueue_script ( 'fd-script-frontend ' );
48
53
}
49
54
50
55
@@ -70,23 +75,23 @@ function process_filter_tickets(){
70
75
}
71
76
//echo '<xmp>'; print_r($filteredTickets); echo '</xmp>';
72
77
if ( empty ( $ filteredTickets ) ) {
73
- $ returnArray = '<div id="tickets_html"><p>No tickets for " ' . $ postArray ['filter_dropdown ' ] . '" category.</p></div> ' ;
78
+ $ returnArray = '<div id="tickets_html"><p> ' . __ ( ' No tickets for " ' . strtoupper ( str_replace ( ' _ ' , ' ' , $ postArray ['filter_dropdown ' ] ) ) . '" category. ' ) . ' </p></div> ' ;
74
79
} else {
75
80
$ returnArray = $ this ->get_html ( $ filteredTickets );
76
81
}
77
82
} else {
78
83
if ( isset ( $ tickets ->require_login ) ) {
79
- $ msg = 'Invalid Credentials ' ;
84
+ $ msg = __ ( 'Invalid Credentials ' ) ;
80
85
} else if ( isset ( $ tickets ->errors ) ) {
81
86
if ( isset ( $ tickets ->errors ->no_email ) ){
82
- $ msg = ( isset ( $ this ->display_option ['invalid_user_msg ' ] ) && $ this ->display_option ['invalid_user_msg ' ] != '' ) ? $ this ->display_option ['invalid_user_msg ' ] : 'Invalid User ' ;
87
+ $ msg = ( isset ( $ this ->display_option ['invalid_user_msg ' ] ) && $ this ->display_option ['invalid_user_msg ' ] != '' ) ? $ this ->display_option ['invalid_user_msg ' ] : __ ( 'Invalid User ' ) ;
83
88
} else {
84
- $ msg = 'Invalid Freshdesk URL ' ;
89
+ $ msg = __ ( 'Invalid Freshdesk URL ' ) ;
85
90
}
86
91
} else if ( empty ( $ tickets ) ){
87
- $ msg = ( isset ( $ this ->display_option ['no_tickets_msg ' ] ) && $ this ->display_option ['no_tickets_msg ' ] != '' ) ? $ this ->display_option ['no_tickets_msg ' ] : 'No tickets ' ;
92
+ $ msg = ( isset ( $ this ->display_option ['no_tickets_msg ' ] ) && $ this ->display_option ['no_tickets_msg ' ] != '' ) ? $ this ->display_option ['no_tickets_msg ' ] : __ ( 'No tickets ' ) ;
88
93
}else {
89
- $ msg = 'Error! ' ;
94
+ $ msg = __ ( 'Error! ' ) ;
90
95
}
91
96
$ returnArray = '<div id="tickets_html"><p> ' . $ msg . '</p></div> ' ;
92
97
}
@@ -243,106 +248,77 @@ public function fetch_tickets( $atts ){
243
248
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
244
249
$ result .= ( $ _POST ["filter_dropdown " ] == "all_tickets " ) ? 'selected="selected" ' : '' ;
245
250
}
246
- $ result .= '>----All Tickets----</option>
251
+ $ result .= '> ' . __ ( ' ----All Tickets---- ' ) . ' </option>
247
252
<option value="Open" ' ;
248
253
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
249
254
$ result .= ( $ _POST ["filter_dropdown " ] == "Open " ) ? 'selected="selected" ' : '' ;
250
255
}
251
- $ result .= '>Open</option>
256
+ $ result .= '> ' . __ ( ' Open ' ) . ' </option>
252
257
<option value="Pending" ' ;
253
258
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
254
259
$ result .= ( $ _POST ["filter_dropdown " ] == "Pending " ) ? 'selected="selected" ' : '' ;
255
260
}
256
- $ result .= '>Pending</option>
261
+ $ result .= '> ' . __ ( ' Pending ' ) . ' </option>
257
262
<option value="Resolved" ' ;
258
263
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
259
264
$ result .= ( $ _POST ["filter_dropdown " ] == "Resolved " ) ? 'selected="selected" ' : '' ;
260
265
}
261
- $ result .= '>Resolved</option>
266
+ $ result .= '> ' . __ ( ' Resolved ' ) . ' </option>
262
267
<option value="Closed" ' ;
263
268
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
264
269
$ result .= ( $ _POST ["filter_dropdown " ] == "Closed " ) ? 'selected="selected" ' : '' ;
265
270
}
266
- $ result .= '>Closed</option>
271
+ $ result .= '> ' . __ ( ' Closed ' ) . ' </option>
267
272
<option value="Waiting on Customer" ' ;
268
273
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
269
274
$ result .= ( $ _POST ["filter_dropdown " ] == "Waiting on Customer " ) ? 'selected="selected" ' : '' ;
270
275
}
271
- $ result .= '>Waiting on Customer</option>
276
+ $ result .= '> ' . __ ( ' Waiting on Customer ' ) . ' </option>
272
277
<option value="Waiting on Third Party" ' ;
273
278
if ( isset ( $ _POST ["filter_dropdown " ] ) ) {
274
279
$ result .= ( $ _POST ["filter_dropdown " ] == "Waiting on Third Party " ) ? 'selected="selected" ' : '' ;
275
280
}
276
281
$ txt = ( isset ( $ _POST ['search_txt ' ] ) ) ? $ _POST ['search_txt ' ] : '' ;
277
- $ result .= '>Waiting on Third Party</option>
282
+ $ result .= '> ' . __ ( ' Waiting on Third Party ' ) . ' </option>
278
283
</select>
279
284
280
285
</div>
281
286
<div style="float:right;">
282
- <input type="text" value=" ' . $ txt . '" id="search_txt" name="search_txt" placeholder="Search..."/>
287
+ <input type="text" value=" ' . $ txt . '" id="search_txt" name="search_txt" placeholder=" ' . __ ( ' Search... ' ) . ' "/>
283
288
</div>
284
- <div style="clear:both;"></div>
289
+ <div style="clear:both;"></div> ' ;
290
+ $ is_call_ajax_flag = ( !isset ( $ tickets ->require_login ) && $ tickets != '' && !isset ( $ tickets ->errors ) ) ? '1 ' : '0 ' ;
291
+ $ result .= '
285
292
<input type="hidden" id="action" name="action" value="filter_tickets"/>
293
+ <input type="hidden" id="call_ajax_flag" name="call_ajax_flag" value=" ' . $ is_call_ajax_flag . '"/>
286
294
</form> ' ;
295
+
287
296
$ result .= '<section id="dark-bg" style="display:none;" class="dark-bg">
288
297
<section id="loading"><img src=" ' . plugins_url ("images/loading.gif " ,__FILE__ ) . '"></section>
289
298
</section> ' ;
290
-
291
- if ( !isset ( $ tickets ->require_login ) && $ tickets != '' && !isset ( $ tickets ->errors ) ) {
292
- $ result .=
293
- '<script type="text/javascript">
294
- jQuery(document).ready(function(){
295
- tickets = ' . json_encode ( $ ajaxTickets , false ) . ';
296
- jQuery("#filter_dropdown").change(function(){
297
- //jQuery("#filter_form").submit();
298
- jQuery("#dark-bg").show();
299
- ajaxcall( "filter", tickets, this.value );
300
- });
301
- jQuery("#search_txt").on( "keyup keypress", function(e) {
302
- // Enter pressed?
303
- if( e.keyCode == 10 || e.keyCode == 13 ) {
304
- //alert("enter");
305
- e.preventDefault();
306
- return false;
307
- }
308
- if( e.which != 9 && e.which != 10 && e.which != 13 && e.which != 37 && e.which != 38 && e.which != 39 && e.which != 40 && this.value.length >= 2) {
309
- ajaxcall( "search", tickets, this.value );
310
- }
311
- });
312
- });
313
- function ajaxcall( action, tickets, key ) {
314
- var data = jQuery("#filter_form").serialize();
315
- jQuery.ajax({
316
- type : "post",
317
- dataType : "html",
318
- url : " ' . admin_url ('admin-ajax.php ' ) . '",
319
- data : data,
320
- success: function(response) {
321
- jQuery("#tickets_html").html( response );
322
- jQuery("#dark-bg").hide();
323
- }
324
- });
325
- //jQuery("#dark-bg").hide();
326
- }
327
- </script>
328
- ' ;
329
- }
299
+
300
+ $ result .=
301
+ '<script type="text/javascript">
302
+ ajaxurl = " ' . admin_url ('admin-ajax.php ' ) . '";
303
+ </script>
304
+ ' ;
305
+
330
306
//echo '<xmp>'; print_r( $tickets ); echo '</xmp>';
331
307
if ( !isset ( $ tickets ->require_login ) && $ tickets != '' && !isset ( $ tickets ->errors ) && !empty ( $ tickets ) ) {
332
308
$ result .= $ this ->get_html ( $ tickets );
333
309
} else {
334
310
if ( isset ( $ tickets ->require_login ) ) {
335
- $ msg = 'Invalid Credentials ' ;
311
+ $ msg = __ ( 'Invalid Credentials ' ) ;
336
312
} else if ( isset ( $ tickets ->errors ) ) {
337
313
if ( isset ( $ tickets ->errors ->no_email ) ){
338
- $ msg = ( isset ( $ this ->display_option ['invalid_user_msg ' ] ) && $ this ->display_option ['invalid_user_msg ' ] != '' ) ? $ this ->display_option ['invalid_user_msg ' ] : 'Invalid User ' ;
314
+ $ msg = ( isset ( $ this ->display_option ['invalid_user_msg ' ] ) && $ this ->display_option ['invalid_user_msg ' ] != '' ) ? $ this ->display_option ['invalid_user_msg ' ] : __ ( 'Invalid User ' ) ;
339
315
} else {
340
- $ msg = 'Invalid Freshdesk URL ' ;
316
+ $ msg = __ ( 'Invalid Freshdesk URL ' ) ;
341
317
}
342
318
} else if ( empty ( $ tickets ) ) {
343
- $ msg = ( isset ( $ this ->display_option ['no_tickets_msg ' ] ) && $ this ->display_option ['no_tickets_msg ' ] != '' ) ? $ this ->display_option ['no_tickets_msg ' ] : 'No tickets ' ;
319
+ $ msg = ( isset ( $ this ->display_option ['no_tickets_msg ' ] ) && $ this ->display_option ['no_tickets_msg ' ] != '' ) ? $ this ->display_option ['no_tickets_msg ' ] : __ ( 'No tickets ' ) ;
344
320
}else {
345
- $ msg = 'Error! ' ;
321
+ $ msg = __ ( 'Error! ' ) ;
346
322
}
347
323
$ result = '<div id="tickets_html"><p> ' . $ msg . '</p></div> ' ;
348
324
}
@@ -417,21 +393,21 @@ public function get_html( $tickets = '' ){
417
393
418
394
//if( !isset( $tickets->require_login ) && $tickets != '' && !isset( $tickets->errors ) && !empty( $tickets ) ) {
419
395
//echo '<xmp>'; print_r($this->display_option); echo '</xmp>';
420
- $ html .= '<div id="tickets_html" class="lic-table">
396
+ $ html .= '<div id="tickets_html" class="lic-table fwt-table-responsive ">
421
397
<div><p>Total Tickets: ' . count ( $ tickets ) . '</p></div>
422
398
<table class="lic-table-list">
423
399
<tr>
424
- <th width="10%">ID </th>
425
- <th>Subject</th>
426
- <th>Status</th> ' ;
400
+ <th width="10%"> ' . strtoupper ( __ ( ' ID ' ) ). ' </th>
401
+ <th> ' . strtoupper ( __ ( ' Subject ' ) ) . ' </th>
402
+ <th> ' . strtoupper ( __ ( ' Status ' ) ) . ' </th> ' ;
427
403
if ( isset ( $ this ->display_option ) ) {
428
404
if ( $ this ->display_option != '' ) {
429
405
foreach ( $ this ->display_option as $ key =>$ value ){
430
406
switch ( $ key ){
431
407
case 'fd_display_description ' :
432
408
case 'fd_display_priority_name ' :
433
409
case 'fd_display_updated_at ' :
434
- $ html .= '<th> ' . str_replace ( "_ " , " " , str_replace ( "fd_display_ " , "" , $ key ) ) . '</th> ' ;
410
+ $ html .= '<th> ' . strtoupper ( __ ( str_replace ( "_ " , " " , str_replace ( "fd_display_ " , "" , $ key ) ) ) ) . '</th> ' ;
435
411
break ;
436
412
case 'no_tickets_msg ' :
437
413
default :
0 commit comments