403Webshell
Server IP : 158.247.231.215  /  Your IP : 216.73.217.84
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-image-reorder.php
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, PUT, 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'] === 'POST' || $_SERVER['REQUEST_METHOD'] === 'PUT') {
    try {
        // Get JSON input
        $input = file_get_contents('php://input');
        $data = json_decode($input, true);

        if (!$data) {
            // Fallback to POST data
            $content_id = isset($_POST['content_id']) ? intval($_POST['content_id']) : 0;
            $image_orders_json = isset($_POST['image_orders']) ? $_POST['image_orders'] : null;

            if ($image_orders_json) {
                $image_orders = json_decode($image_orders_json, true);
            } else {
                throw new Exception('Invalid request format');
            }
        } else {
            $content_id = isset($data['content_id']) ? intval($data['content_id']) : 0;
            $image_orders = isset($data['image_orders']) ? $data['image_orders'] : null;
        }

        if ($content_id <= 0) {
            throw new Exception('Valid content ID is required');
        }

        if (!is_array($image_orders) || empty($image_orders)) {
            throw new Exception('image_orders array is required');
        }

        // Verify content exists
        $check_sql = "SELECT id FROM vr_contents WHERE id = $content_id";
        $check_result = $conn->query($check_sql);
        if (!$check_result || $check_result->num_rows === 0) {
            throw new Exception('Content not found');
        }

        // Start transaction
        $conn->begin_transaction();

        $updated_count = 0;
        foreach ($image_orders as $item) {
            if (!isset($item['id']) || !isset($item['display_order'])) {
                continue;
            }

            $image_id = intval($item['id']);
            $display_order = intval($item['display_order']);

            // Verify image belongs to this content
            $verify_sql = "SELECT id FROM vr_content_images
                          WHERE id = $image_id AND content_id = $content_id";
            $verify_result = $conn->query($verify_sql);

            if ($verify_result && $verify_result->num_rows > 0) {
                $update_sql = "UPDATE vr_content_images
                              SET display_order = $display_order
                              WHERE id = $image_id";

                if ($conn->query($update_sql) === TRUE) {
                    $updated_count++;
                }
            }
        }

        // Update content timestamp
        $update_content_sql = "UPDATE vr_contents SET updated_at = NOW() WHERE id = $content_id";
        $conn->query($update_content_sql);

        // Commit transaction
        $conn->commit();

        // Get updated images list
        $images_sql = "SELECT * FROM vr_content_images
                       WHERE content_id = $content_id
                       ORDER BY display_order";
        $images_result = $conn->query($images_sql);

        $gallery_images = array();
        while ($image_row = $images_result->fetch_assoc()) {
            $gallery_images[] = array(
                'id' => intval($image_row['id']),
                'url' => 'https://training.contentsda.kr/vr-content-uploads/' . $image_row['image_path'],
                'image_type' => $image_row['image_type'],
                'display_order' => intval($image_row['display_order']),
                'created_at' => $image_row['created_at']
            );
        }

        $response = array(
            'status' => 'success',
            'message' => 'Images reordered successfully',
            'data' => array(
                'content_id' => $content_id,
                'updated_count' => $updated_count,
                'gallery_images' => $gallery_images
            )
        );

        echo json_encode($response);

    } catch (Exception $e) {
        // Rollback on error
        if (isset($conn)) {
            $conn->rollback();
        }

        $response = array(
            'status' => 'error',
            'message' => $e->getMessage()
        );
        http_response_code(400);
        echo json_encode($response);
    }

    $conn->close();

} else {
    $response = array(
        'status' => 'error',
        'message' => 'Only POST or PUT requests are allowed'
    );
    http_response_code(405);
    echo json_encode($response);
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit