Skip to content

Commit 6dc6e4c

Browse files
committed
asana code review changes
1 parent e4ccbc4 commit 6dc6e4c

9 files changed

+148
-91
lines changed

admin-settings.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function create_admin_page(){
5151
</div>
5252

5353
<h2 class="nav-tab-wrapper">
54-
<a href="javascript:void(0);" id="tab-api" class="nav-tab nav-tab-active">General Configuration</a>
55-
<a href="javascript:void(0);" id="tab-shortcode" class="nav-tab">Shortcode</a>
56-
<a href="javascript:void(0);" id="tab-url" class="nav-tab">Freshdesk SSO</a>
57-
<a href="javascript:void(0);" id="tab-display" class="nav-tab">Display Settings</a>
54+
<a href="javascript:void(0);" id="tab-api" class="nav-tab nav-tab-active"><?php echo __( 'General Configuration' ); ?></a>
55+
<a href="javascript:void(0);" id="tab-shortcode" class="nav-tab"><?php echo __( 'Shortcode' ); ?></a>
56+
<a href="javascript:void(0);" id="tab-url" class="nav-tab"><?php echo __( 'Freshdesk SSO' ); ?></a>
57+
<a href="javascript:void(0);" id="tab-display" class="nav-tab"><?php echo __( 'Display Settings' ); ?></a>
5858
</h2>
5959
<div id="api-tab" class="tabs">
6060
<form method="post" action="options.php" autocomplete="off">
@@ -66,37 +66,37 @@ public function create_admin_page(){
6666
</form>
6767
</div>
6868
<div id="shortcode-tab" style="display:none;" class="tabs">
69-
<p class="description1">Paste the below shortcode on your page.</p>
70-
<code>[fetch_tickets]</code>
71-
<p>This shortcode will display all the tickets on your page. It also provides filter options and search options. You can filter tickets with respect to:</p>
69+
<p class="description1"><?php echo __( 'Paste the below shortcode on your page.' ); ?></p>
70+
<code>[fd_fetch_tickets]</code>
71+
<p><?php echo __( 'This shortcode will display all the tickets on your page. It also provides filter options and search options. You can filter tickets with respect to:'); ?></p>
7272
<table>
7373
<tr>
74-
<td>All tickets</td>
75-
<td><code>[fetch_tickets]</code></td>
74+
<td><?php echo __( 'All tickets' ); ?></td>
75+
<td><code><?php echo __( '[fd_fetch_tickets]' ); ?></code></td>
7676
</tr>
7777
<tr>
78-
<td>Open</td>
79-
<td><code>[fetch_tickets filter="Open"]</code></td>
78+
<td><?php echo __( 'Open' ); ?></td>
79+
<td><code><?php echo __( '[fd_fetch_tickets filter="Open"]' ); ?></code></td>
8080
</tr>
8181
<tr>
82-
<td>Resolved</td>
83-
<td><code>[fetch_tickets filter="Resolved"]</code></td>
82+
<td><?php echo __( 'Resolved' ); ?></td>
83+
<td><code><?php echo __( '[fd_fetch_tickets filter="Resolved"]' ); ?></code></td>
8484
</tr>
8585
<tr>
86-
<td>Closed</td>
87-
<td><code>[fetch_tickets filter="Closed"]</code></td>
86+
<td><?php echo __( 'Closed'); ?></td>
87+
<td><code><?php echo __( '[fd_fetch_tickets filter="Closed"]' ); ?></code></td>
8888
</tr>
8989
<tr>
90-
<td>Pending</td>
91-
<td><code>[fetch_tickets filter="Pending"]</code></td>
90+
<td><?php echo __( 'Pending' ); ?></td>
91+
<td><code><?php echo __( '[fd_fetch_tickets filter="Pending"]' ); ?></code></td>
9292
</tr>
9393
<tr>
94-
<td>Waiting on Customer</td>
95-
<td><code>[fetch_tickets filter="Waiting on Customer"]</code></td>
94+
<td><?php echo __( 'Waiting on Customer' ); ?></td>
95+
<td><code><?php echo __( '[fd_fetch_tickets filter="Waiting on Customer"]' ); ?></code></td>
9696
</tr>
9797
<tr>
98-
<td>Waiting on Third Party</td>
99-
<td><code>[fetch_tickets filter="Waiting on Third Party"]</code></td>
98+
<td><?php echo __( 'Waiting on Third Party' ); ?></td>
99+
<td><code><?php echo __( '[fd_fetch_tickets filter="Waiting on Third Party"]' ); ?></code></td>
100100
</tr>
101101
</table>
102102
</div>

css/index.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//Silence is golden

css/style.css

+37-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,40 @@ table.lic-table-list tr td a {
3636
}
3737

3838
.dark-bg{background:none repeat scroll 0 0 #0B0B0B;height:100%;left:0;opacity:0.8;overflow:hidden;position:fixed;top:0;width:100%;z-index:1042;}
39-
#loading{left: 47%;margin: 30px;padding: 0;position: fixed;top: 40%;width: 3%;z-index: 56456;}
39+
#loading{left: 47%;margin: 30px;padding: 0;position: fixed;top: 40%;width: 3%;z-index: 56456;}
40+
41+
@media screen and (max-width: 767px) {
42+
.fwt-table-responsive {
43+
width: 100%;
44+
margin-bottom: 15px;
45+
overflow-x: auto;
46+
overflow-y: hidden;
47+
-webkit-overflow-scrolling: touch;
48+
-ms-overflow-style: -ms-autohiding-scrollbar;
49+
border: 1px solid #ddd
50+
}
51+
52+
.fwt-table-responsive > .table {
53+
margin-bottom: 0
54+
}
55+
56+
.fwt-table-responsive > .table > thead > tr > th, .fwt-table-responsive > .table > tbody > tr > th, .fwt-table-responsive > .table > tfoot > tr > th, .fwt-table-responsive > .table > thead > tr > td, .fwt-table-responsive > .table > tbody > tr > td, .fwt-table-responsive > .table > tfoot > tr > td {
57+
white-space: nowrap
58+
}
59+
60+
.fwt-table-responsive > .table-bordered {
61+
border: 0
62+
}
63+
64+
.fwt-table-responsive > .table-bordered > thead > tr > th:first-child, .fwt-table-responsive > .table-bordered > tbody > tr > th:first-child, .fwt-table-responsive > .table-bordered > tfoot > tr > th:first-child, .fwt-table-responsive > .table-bordered > thead > tr > td:first-child, .fwt-table-responsive > .table-bordered > tbody > tr > td:first-child, .fwt-table-responsive > .table-bordered > tfoot > tr > td:first-child {
65+
border-left: 0
66+
}
67+
68+
.fwt-table-responsive > .table-bordered > thead > tr > th:last-child, .fwt-table-responsive > .table-bordered > tbody > tr > th:last-child, .fwt-table-responsive > .table-bordered > tfoot > tr > th:last-child, .fwt-table-responsive > .table-bordered > thead > tr > td:last-child, .fwt-table-responsive > .table-bordered > tbody > tr > td:last-child, .fwt-table-responsive > .table-bordered > tfoot > tr > td:last-child {
69+
border-right: 0
70+
}
71+
72+
.fwt-table-responsive > .table-bordered > tbody > tr:last-child > th, .fwt-table-responsive > .table-bordered > tfoot > tr:last-child > th, .fwt-table-responsive > .table-bordered > tbody > tr:last-child > td, .fwt-table-responsive > .table-bordered > tfoot > tr:last-child > td {
73+
border-bottom: 0
74+
}
75+
}

freshdesk-api.php

+43-67
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
* License:
1010
*/
1111

12-
include_once( ABSPATH . 'wp-load.php' );
12+
13+
//Block direct access to plugin files
14+
defined( 'ABSPATH' ) or die();
15+
1316
if(!class_exists("FreshDeskAPI")){
1417
class FreshDeskAPI{
1518

@@ -28,7 +31,7 @@ function __construct(){
2831
add_action( 'init', array( $this, 'init' ) );
2932
//add_action( 'admin_init', array( $this, 'ajax_init' ) );
3033
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"));
3235
include_once( 'admin-settings.php' );
3336
$this->options = get_option( 'fd_url' );
3437
$this->opt = get_option( 'fd_apikey' );
@@ -45,6 +48,8 @@ function __construct(){
4548
function enqueue_scripts() {
4649
wp_register_style( 'style', plugins_url('css/style.css', __FILE__) );
4750
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' );
4853
}
4954

5055

@@ -70,23 +75,23 @@ function process_filter_tickets(){
7075
}
7176
//echo '<xmp>'; print_r($filteredTickets); echo '</xmp>';
7277
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>';
7479
} else {
7580
$returnArray = $this->get_html( $filteredTickets );
7681
}
7782
} else {
7883
if( isset( $tickets->require_login ) ) {
79-
$msg = 'Invalid Credentials';
84+
$msg = __( 'Invalid Credentials' );
8085
} else if( isset( $tickets->errors ) ) {
8186
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' );
8388
} else {
84-
$msg = 'Invalid Freshdesk URL';
89+
$msg = __( 'Invalid Freshdesk URL' );
8590
}
8691
} 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' );
8893
}else {
89-
$msg = 'Error!';
94+
$msg = __( 'Error!' );
9095
}
9196
$returnArray = '<div id="tickets_html"><p>' . $msg . '</p></div>';
9297
}
@@ -243,106 +248,77 @@ public function fetch_tickets( $atts ){
243248
if( isset( $_POST["filter_dropdown"] ) ) {
244249
$result .= ( $_POST["filter_dropdown"] == "all_tickets" ) ? 'selected="selected"' : '';
245250
}
246-
$result .= '>----All Tickets----</option>
251+
$result .= '>' . __( '----All Tickets----' ) . '</option>
247252
<option value="Open" ';
248253
if( isset( $_POST["filter_dropdown"] ) ) {
249254
$result .= ( $_POST["filter_dropdown"] == "Open" ) ? 'selected="selected"' : '';
250255
}
251-
$result .= '>Open</option>
256+
$result .= '>' . __( 'Open' ) . '</option>
252257
<option value="Pending" ';
253258
if( isset( $_POST["filter_dropdown"] ) ) {
254259
$result .= ( $_POST["filter_dropdown"] == "Pending" ) ? 'selected="selected"' : '';
255260
}
256-
$result .= '>Pending</option>
261+
$result .= '>' . __( 'Pending' ) . '</option>
257262
<option value="Resolved" ';
258263
if( isset( $_POST["filter_dropdown"] ) ) {
259264
$result .= ( $_POST["filter_dropdown"] == "Resolved" ) ? 'selected="selected"' : '';
260265
}
261-
$result .= '>Resolved</option>
266+
$result .= '>' . __( 'Resolved' ) . '</option>
262267
<option value="Closed" ';
263268
if( isset( $_POST["filter_dropdown"] ) ) {
264269
$result .= ( $_POST["filter_dropdown"] == "Closed" ) ? 'selected="selected"' : '';
265270
}
266-
$result .= '>Closed</option>
271+
$result .= '>' . __( 'Closed' ) . '</option>
267272
<option value="Waiting on Customer" ';
268273
if( isset( $_POST["filter_dropdown"] ) ) {
269274
$result .= ( $_POST["filter_dropdown"] == "Waiting on Customer" ) ? 'selected="selected"' : '';
270275
}
271-
$result .= '>Waiting on Customer</option>
276+
$result .= '>' . __( 'Waiting on Customer' ) . '</option>
272277
<option value="Waiting on Third Party" ';
273278
if( isset( $_POST["filter_dropdown"] ) ) {
274279
$result .= ( $_POST["filter_dropdown"] == "Waiting on Third Party" ) ? 'selected="selected"' : '';
275280
}
276281
$txt = ( isset( $_POST['search_txt'] ) ) ? $_POST['search_txt'] : '';
277-
$result .= '>Waiting on Third Party</option>
282+
$result .= '>' . __( 'Waiting on Third Party' ) . '</option>
278283
</select>
279284
280285
</div>
281286
<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...' ) . '"/>
283288
</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 .= '
285292
<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 . '"/>
286294
</form>';
295+
287296
$result .= '<section id="dark-bg" style="display:none;" class="dark-bg">
288297
<section id="loading"><img src="' . plugins_url("images/loading.gif",__FILE__) . '"></section>
289298
</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+
330306
//echo '<xmp>'; print_r( $tickets ); echo '</xmp>';
331307
if( !isset( $tickets->require_login ) && $tickets != '' && !isset( $tickets->errors ) && !empty( $tickets ) ) {
332308
$result .= $this->get_html( $tickets );
333309
} else {
334310
if( isset( $tickets->require_login ) ) {
335-
$msg = 'Invalid Credentials';
311+
$msg = __( 'Invalid Credentials' );
336312
} else if( isset( $tickets->errors ) ) {
337313
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' );
339315
} else {
340-
$msg = 'Invalid Freshdesk URL';
316+
$msg = __( 'Invalid Freshdesk URL' );
341317
}
342318
} 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' );
344320
}else {
345-
$msg = 'Error!';
321+
$msg = __( 'Error!' );
346322
}
347323
$result = '<div id="tickets_html"><p>' . $msg . '</p></div>';
348324
}
@@ -417,21 +393,21 @@ public function get_html( $tickets = '' ){
417393

418394
//if( !isset( $tickets->require_login ) && $tickets != '' && !isset( $tickets->errors ) && !empty( $tickets ) ) {
419395
//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">
421397
<div><p>Total Tickets: ' . count( $tickets ) . '</p></div>
422398
<table class="lic-table-list">
423399
<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>';
427403
if( isset( $this->display_option ) ) {
428404
if( $this->display_option != '' ) {
429405
foreach( $this->display_option as $key=>$value ){
430406
switch( $key ){
431407
case 'fd_display_description':
432408
case 'fd_display_priority_name':
433409
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>';
435411
break;
436412
case 'no_tickets_msg':
437413
default:

images/index.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//Silence is golden

index.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//Silence is golden

js/fd-script-frontend.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// JavaScript Document
2+
function ajaxcall( action, key ) {
3+
var data = jQuery("#filter_form").serialize();
4+
jQuery.ajax({
5+
type : "post",
6+
dataType : "html",
7+
url : ajaxurl,
8+
data : data,
9+
success: function(response) {
10+
jQuery("#tickets_html").html( response );
11+
jQuery("#dark-bg").hide();
12+
}
13+
});
14+
//jQuery("#dark-bg").hide();
15+
}
16+
jQuery(document).ready(function(){
17+
var call_ajax_flag = jQuery('#call_ajax_flag').val();
18+
jQuery("#filter_dropdown").change(function(){
19+
//jQuery("#filter_form").submit();
20+
if( call_ajax_flag == 1 ) {
21+
jQuery("#dark-bg").show();
22+
ajaxcall( "filter", this.value );
23+
}
24+
});
25+
jQuery("#search_txt").on( "keyup keypress", function(e) {
26+
// Enter pressed?
27+
if( e.keyCode == 10 || e.keyCode == 13 ) {
28+
//alert("enter");
29+
e.preventDefault();
30+
return false;
31+
}
32+
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) {
33+
if( call_ajax_flag == 1 ) {
34+
ajaxcall( "search", this.value );
35+
}
36+
}
37+
});
38+
});

js/fd-script.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@
4242
jQuery( this ).addClass( "nav-tab-active" );
4343
jQuery( '.tabs' ).hide();
4444
jQuery( '#display-tab' ).show();
45-
});
46-
45+
});
4746
});

js/index.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//Silence is golden

0 commit comments

Comments
 (0)