| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $wpscfunction, $current_user; |
| 7 |
|
| 8 |
// Get tiket id |
| 9 |
$ticket_id = isset($_POST['ticket_id']) ? intval($_POST['ticket_id']) : 0; |
| 10 |
if(!$ticket_id) die(); |
| 11 |
|
| 12 |
$wpsc_allow_rich_text_editor = get_option('wpsc_allow_rich_text_editor'); |
| 13 |
|
| 14 |
// Check nonce |
| 15 |
if( !isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'],$ticket_id) ){ |
| 16 |
die(__('Cheating huh?', 'supportcandy')); |
| 17 |
} |
| 18 |
|
| 19 |
if ($current_user->ID) { |
| 20 |
$customer_name = $current_user->display_name; |
| 21 |
$customer_email = $current_user->user_email; |
| 22 |
} |
| 23 |
else { |
| 24 |
$customer_name = isset($_POST['customer_name']) ? sanitize_text_field($_POST['customer_name']) : ''; |
| 25 |
$customer_email = isset($_POST['customer_email']) ? sanitize_email($_POST['customer_email']) : ''; |
| 26 |
} |
| 27 |
|
| 28 |
// Get reply body |
| 29 |
$rich_editing = $wpscfunction->rich_editing_status($current_user); |
| 30 |
|
| 31 |
$flag = false; |
| 32 |
if((in_array('register_user',$wpsc_allow_rich_text_editor) && !$current_user->has_cap('wpsc_agent')) && $rich_editing){ |
| 33 |
$flag = true; |
| 34 |
}elseif($current_user->has_cap('wpsc_agent') && $rich_editing){ |
| 35 |
$flag = true; |
| 36 |
} |
| 37 |
|
| 38 |
if ($flag) { |
| 39 |
$reply_body = isset($_POST['reply_body']) ? wp_kses_post(htmlspecialchars_decode($_POST['reply_body'], ENT_QUOTES)) : ''; |
| 40 |
} else { |
| 41 |
$reply_body = isset($_POST['reply_body']) ? sanitize_textarea_field($_POST['reply_body']) : ''; |
| 42 |
} |
| 43 |
|
| 44 |
// Get reply attachments |
| 45 |
$description_attachment = isset($_POST['desc_attachment']) ? $wpscfunction->sanitize_array($_POST['desc_attachment']) : array(); |
| 46 |
$attachments = array(); |
| 47 |
foreach ($description_attachment as $key => $value) { |
| 48 |
$attachment_id = intval($value); |
| 49 |
$attachments[] = $attachment_id; |
| 50 |
update_term_meta ($attachment_id, 'active', '1'); |
| 51 |
} |
| 52 |
|
| 53 |
$ip_address = isset($_SERVER) && isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:''; |
| 54 |
if (strlen($ip_address)>28) { |
| 55 |
$ip_address = ''; |
| 56 |
} |
| 57 |
$os_platform = $wpscfunction->get_os(); |
| 58 |
$browser = $wpscfunction->get_browser(); |
| 59 |
// Prepare arguments |
| 60 |
$args = array( |
| 61 |
'ticket_id' => $ticket_id, |
| 62 |
'reply_body' => $wpscfunction->replace_macro($reply_body,$ticket_id), |
| 63 |
'customer_name' => $customer_name, |
| 64 |
'customer_email' => $customer_email, |
| 65 |
'attachments' => $attachments, |
| 66 |
'thread_type' => 'note', |
| 67 |
'ip_address' => $ip_address, |
| 68 |
'reply_source' => 'browser', |
| 69 |
'os' => $os_platform, |
| 70 |
'browser' => $browser |
| 71 |
); |
| 72 |
$args = apply_filters( 'wpsc_thread_args', $args ); |
| 73 |
$thread_id = $wpscfunction->submit_ticket_thread($args); |
| 74 |
|
| 75 |
do_action( 'wpsc_after_submit_note', $thread_id, $ticket_id ); |
| 76 |
|