403Webshell
Server IP : 158.247.231.215  /  Your IP : 216.73.216.217
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /mnt/blockstorage/ctms/api/custom-api/vr-content-list.php
<?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 {
        // Get query parameters
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
        $limit = isset($_GET['limit']) ? intval($_GET['limit']) : 20;
        $search = isset($_GET['search']) ? $conn->real_escape_string(trim($_GET['search'])) : '';
        $status = isset($_GET['status']) ? $conn->real_escape_string($_GET['status']) : '';

        $page = max(1, $page);
        $limit = min(100, max(1, $limit));
        $offset = ($page - 1) * $limit;

        // Build WHERE clause
        $where_clauses = array();
        if (!empty($search)) {
            $where_clauses[] = "(c.title LIKE '%$search%' OR c.description LIKE '%$search%')";
        }
        if (!empty($status) && in_array($status, array('active', 'inactive'))) {
            $where_clauses[] = "c.status = '$status'";
        }

        $where_sql = !empty($where_clauses) ? 'WHERE ' . implode(' AND ', $where_clauses) : '';

        // Get total count
        $count_sql = "SELECT COUNT(*) as total FROM vr_contents c $where_sql";
        $count_result = $conn->query($count_sql);

        if (!$count_result) {
            throw new Exception('Database query failed: ' . $conn->error);
        }

        $total = $count_result->fetch_assoc()['total'];

        // Get contents with version count and thumbnail from vr_content_images
        $sql = "SELECT
                    c.id,
                    c.title,
                    c.description,
                    c.video_path,
                    c.status,
                    c.created_by,
                    c.created_at,
                    c.updated_at,
                    thumb.image_path as thumbnail_path,
                    COUNT(DISTINCT v.id) as version_count
                FROM vr_contents c
                LEFT JOIN vr_content_versions v ON c.id = v.content_id AND v.status = 'active'
                LEFT JOIN vr_content_images thumb ON c.id = thumb.content_id AND thumb.image_type = 'thumbnail'
                $where_sql
                GROUP BY c.id, c.title, c.description, c.video_path, c.status, c.created_by, c.created_at, c.updated_at, thumb.image_path
                ORDER BY c.created_at DESC
                LIMIT $limit OFFSET $offset";

        $result = $conn->query($sql);

        if (!$result) {
            throw new Exception('Database query failed: ' . $conn->error);
        }

        $contents = array();
        while ($row = $result->fetch_assoc()) {
            $thumbnail_url = null;
            if ($row['thumbnail_path']) {
                $thumbnail_url = 'https://training.contentsda.kr/vr-content-uploads/' . $row['thumbnail_path'];
            }

            $video_url = null;
            if ($row['video_path']) {
                $video_url = 'https://training.contentsda.kr/vr-content-uploads/' . $row['video_path'];
            }

            $contents[] = array(
                'id' => intval($row['id']),
                'title' => $row['title'],
                'description' => $row['description'],
                'thumbnail_url' => $thumbnail_url,
                'video_url' => $video_url,
                'status' => $row['status'],
                'version_count' => intval($row['version_count']),
                'created_at' => $row['created_at'],
                'updated_at' => $row['updated_at']
            );
        }

        $response = array(
            'status' => 'success',
            'data' => array(
                'contents' => $contents,
                'pagination' => array(
                    'page' => $page,
                    'limit' => $limit,
                    'total' => intval($total),
                    'total_pages' => ceil($total / $limit)
                )
            )
        );

        echo json_encode($response);

    } catch (Exception $e) {
        $response = array(
            'status' => 'error',
            'message' => $e->getMessage()
        );
        http_response_code(400);
        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);
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit