| Server IP : 158.247.231.215 / Your IP : 216.73.216.32 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/api/custom-api/ |
Upload File : |
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, OPTIONS');
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization");
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
// Load WordPress and auth helper
require_once('/mnt/blockstorage/ctms/wp-load.php');
require_once('auth-helper.php');
include('../database.php');
// Verify JWT token
$user_id = verify_jwt_token();
if (!$user_id) {
send_error_response('User not authenticated', 401);
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
try {
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id <= 0) {
throw new Exception('Valid content ID is required');
}
// Get content
$sql = "SELECT * FROM vr_contents WHERE id = $id";
$result = $conn->query($sql);
if (!$result || $result->num_rows === 0) {
throw new Exception('Content not found');
}
$content = $result->fetch_assoc();
// Get versions
$versions_sql = "SELECT * FROM vr_content_versions
WHERE content_id = $id
ORDER BY created_at DESC";
$versions_result = $conn->query($versions_sql);
$versions = array();
while ($version_row = $versions_result->fetch_assoc()) {
$pico_url = null;
if ($version_row['pico_apk_path']) {
$pico_url = 'https://training.contentsda.kr/vr-content-uploads/' . $version_row['pico_apk_path'];
}
$quest_url = null;
if ($version_row['quest_apk_path']) {
$quest_url = 'https://training.contentsda.kr/vr-content-uploads/' . $version_row['quest_apk_path'];
}
$versions[] = array(
'id' => intval($version_row['id']),
'version_number' => $version_row['version_number'],
'pico_apk_url' => $pico_url,
'pico_apk_size' => $version_row['pico_apk_size'] ? intval($version_row['pico_apk_size']) : null,
'quest_apk_url' => $quest_url,
'quest_apk_size' => $version_row['quest_apk_size'] ? intval($version_row['quest_apk_size']) : null,
'release_notes' => $version_row['release_notes'],
'status' => $version_row['status'],
'created_at' => $version_row['created_at'],
'updated_at' => $version_row['updated_at']
);
}
$video_url = null;
if ($content['video_path']) {
$video_url = 'https://training.contentsda.kr/vr-content-uploads/' . $content['video_path'];
}
// Get all images (thumbnail + gallery)
$images_sql = "SELECT * FROM vr_content_images
WHERE content_id = $id
ORDER BY display_order";
$images_result = $conn->query($images_sql);
$all_images = array();
if ($images_result) {
while ($image_row = $images_result->fetch_assoc()) {
$image_url = null;
if ($image_row['image_path']) {
$image_url = 'https://training.contentsda.kr/vr-content-uploads/' . $image_row['image_path'];
}
$all_images[] = array(
'id' => intval($image_row['id']),
'url' => $image_url,
'image_type' => $image_row['image_type'],
'display_order' => intval($image_row['display_order']),
'created_at' => $image_row['created_at']
);
}
}
$response = array(
'status' => 'success',
'data' => array(
'id' => intval($content['id']),
'title' => $content['title'],
'description' => $content['description'],
'video_url' => $video_url,
'all_images' => $all_images,
'images_count' => count($all_images),
'status' => $content['status'],
'created_by' => intval($content['created_by']),
'created_at' => $content['created_at'],
'updated_at' => $content['updated_at'],
'versions' => $versions
)
);
echo json_encode($response);
} catch (Exception $e) {
$response = array(
'status' => 'error',
'message' => $e->getMessage()
);
http_response_code(404);
echo json_encode($response);
}
$conn->close();
} else {
$response = array(
'status' => 'error',
'message' => 'Only GET requests are allowed'
);
http_response_code(405);
echo json_encode($response);
}
?>