| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpscfunction; |
| 7 |
|
| 8 |
$ticket_id = get_post_meta( $thread->ID, 'ticket_id', true); |
| 9 |
$auth_id = $wpscfunction->get_ticket_fields($ticket_id,'ticket_auth_code'); |
| 10 |
|
| 11 |
$attachments = get_post_meta( $thread->ID, 'attachments', true); |
| 12 |
$attachments = is_array($attachments) ? $attachments : array(); |
| 13 |
$response_attachments = array(); |
| 14 |
foreach ($attachments as $attachment) { |
| 15 |
|
| 16 |
$attach = array(); |
| 17 |
$attach_meta = get_term_meta($attachment); |
| 18 |
foreach ($attach_meta as $key => $value) { |
| 19 |
$attach[$key] = $value[0]; |
| 20 |
} |
| 21 |
$upload_dir = wp_upload_dir(); |
| 22 |
$file_url = $upload_dir['baseurl'] . '/wpsc/'.$attach['save_file_name']; |
| 23 |
$download_url = $attach['is_image'] ? $file_url : home_url('/').'?wpsc_attachment='.$attachment.'&tid='.$ticket_id.'&tac='.$auth_id; |
| 24 |
|
| 25 |
$response_attachments[] = array( |
| 26 |
'filename' => $attach['filename'], |
| 27 |
'is_image' => $attach['is_image'], |
| 28 |
'download_url' => $download_url, |
| 29 |
); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
$response = array( |
| 34 |
'id' => $thread->ID, |
| 35 |
'ticket_id' => $ticket_id, |
| 36 |
'thread_type' => get_post_meta( $thread->ID, 'thread_type', true), |
| 37 |
'user_name' => get_post_meta( $thread->ID, 'customer_name', true), |
| 38 |
'user_email' => get_post_meta( $thread->ID, 'customer_email', true), |
| 39 |
'thread_body' => $thread->post_content, |
| 40 |
'attachments' => $response_attachments, |
| 41 |
'date' => $thread->post_date_gmt, |
| 42 |
); |
| 43 |
|