/**handles:kenit-style**/
<?php
define("THEME_PREFIX", "wptube_");

add_action('after_setup_theme', 'kenit_setup');
if (!function_exists('kenit_setup')):
    function kenit_setup() {
        register_nav_menu('menu-top', __('Menu Top'));
        register_nav_menu('menu-res', __('Menu Responsive'));
        add_theme_support('post-thumbnails');
    }
endif;

add_action('after_switch_theme', 'xvideonew_setup_options');
if (!function_exists('xvideonew_setup_options')):
    function xvideonew_setup_options() {
        $args = array(
            'xvideonew_player_width' => '745',
            'xvideonew_player_height' => '500',
            'xvideonew_import_customfield_link' => 'link',
            'xvideonew_import_customfield_guid' => 'xvideonew_guid',
            'xvideonew_import_customfield_duration' => 'duration',
            'xvideonew_import_customfield_rate' => 'rate',
            'xvideonew_import_customfield_thumb' => 'thumb',
            'xvideonew_import_customfield_embed_code' => 'video_code',
            'xvideonew_import_title_template' => '{title}',
            'xvideonew_import_content_template' => '{title} - {duration}',
            'xvideonew_get_thumb' => '1',
        );
        foreach ($args as $k => $v) {
            update_option($k, $v);
        }
    }
endif;

function home_page_menu_args($args) {
    $args['show_home'] = true;
    return $args;
}
add_filter('wp_page_menu_args', 'home_page_menu_args');

function kenit_site_title() {
    global $page, $paged;
    wp_title('|', true, 'right');
    bloginfo('name');
    $site_description = get_bloginfo('description', 'display');
    if ($site_description && (is_home() || is_front_page())) {
        echo " | $site_description";
    }
    if ($paged >= 2 || $page >= 2) {
        echo ' | ' . sprintf(__('Trang %s', 'kenit'), max($paged, $page));
    }
}

function kenit_widgets_init() {
    register_sidebar(array(
        'name' => __('Widget trang chủ', 'kenit'),
        'id' => 'home-page',
        'description' => __('Vùng hiển thị widget ở trang chủ', 'kenit'),
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => '',
    ));
    register_sidebar(array(
        'name' => __('Single Sidebar', 'kenit'),
        'id' => 'sidebar',
        'description' => __('Single Sidebar', 'kenit'),
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h2 class="main-title"><span>',
        'after_title' => '</span></h2>',
    ));
}
add_action('widgets_init', 'kenit_widgets_init');

function kenit_limit_words($string, $word_limit) {
    $words = explode(' ', $string, ($word_limit + 1));
    if (count($words) > $word_limit) {
        array_pop($words);
        echo implode(' ', $words) . "...";
    } else {
        echo implode(' ', $words);
    }
}

function get_thumb_image() {
    $thumb = "";
    if (is_single() || is_page()) {
        $thumb = tube_getcustomfield('thumb', get_the_ID());
        if (empty($thumb)) {
            $thumb = qt_get_thumbnail();
        }
        if (empty($thumb)) {
            $thumb = get_first_image();
        }
    } elseif (get_option(THEME_PREFIX . "logo")) {
        $thumb = get_option(THEME_PREFIX . 'logo');
    } else {
        $thumb = get_bloginfo('template_url') . '/images/logo.png';
    }
    return $thumb;
}

function unregister_default_wp_widgets() {
    unregister_widget('WP_Widget_Calendar');
    unregister_widget('WP_Widget_Meta');
    unregister_widget('WP_Widget_Search');
    unregister_widget('WP_Widget_Tag_Cloud');
    unregister_widget('WP_Widget_RSS');
    unregister_widget('WP_Widget_Akismet');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1);

// Chỉ include, KHÔNG khai báo lại các hàm view/AJAX popular ở đây!
include_once get_template_directory() . '/inc/functions.php';
include 'widgets/widget-1.php';
include 'widgets/widget-2.php';
include 'widgets/widget-3.php';
include 'widgets/widget-popular.php';
require_once('libs/transform.php');

function kenit_scripts() {
    wp_enqueue_style('kenit-style', get_stylesheet_uri());
    wp_enqueue_style('animate', get_template_directory_uri() . '/css/responsive.css', array(), '');
    wp_enqueue_style('font-google', 'http://fonts.googleapis.com/css?family=Roboto+Condensed|Roboto|Source+Sans+Pro&subset=latin,vietnamese,cyrillic-ext,latin-ext,cyrillic,greek-ext,greek');
    wp_enqueue_script('jquery.min', get_template_directory_uri() . '/js/jquery-1.10.2.js', array(), '', false);
    wp_enqueue_script('bootstrap.min', get_template_directory_uri() . '/libs/bootstrap/js/bootstrap.min.js', array(), '');
    wp_enqueue_script('carousel.min', get_template_directory_uri() . '/libs/owl.carousel/owl.carousel.min.js', array(), '', true);
    wp_enqueue_script('kenit-main', get_template_directory_uri() . '/js/main.js', array(), '', true);
    wp_enqueue_script('kenit-custom', get_template_directory_uri() . '/js/custom.js', array(), '', true);
    wp_enqueue_script('ajax-top-view', get_template_directory_uri() . '/js/top-view.js', array(), '', true);
    wp_localize_script('ajax-top-view', 'ajax_var', array(
        'url' => admin_url('https://asiangay.tv/wp-content/themes/yolotube-mod-v2/admin-ajax.php'),
        'nonce' => wp_create_nonce('ajax-nonce'),
    ));
}
add_action('wp_enqueue_scripts', 'kenit_scripts');

remove_filter('term_description', 'wpautop');

function kenit_plugin_facebook() { ?>
    <div class="like-click clearfix">
        <div class="fb-btn fb-send" data-href="<?php the_permalink(); ?>"></div>
        <div class="fb-btn fb-like" data-href="<?php the_permalink(); ?>" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
    </div>
    <div class="alert alert-success notice text-center" role="alert">Give this video a comment</div>
    <div class="fb-comments" data-href="<?php the_permalink(); ?>" data-numposts="15" data-colorscheme="light"></div>
<?php }

remove_filter('the_content', 'easy_image_gallery_append_to_content');

function xwpthemes_pagenavi($args = array()) {
    global $wp_query;
    $defaults = array(
        'big_number' => 999999999,
        'base' => str_replace(999999999, '%#%', get_pagenum_link(999999999)),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'total' => $wp_query->max_num_pages,
        'prev_next' => true,
        'end_size' => 0,
        'mid_size' => 7,
        'next_text' => 'Next',
        'prev_text' => 'Prev',
        'type' => 'list'
    );
    $args = wp_parse_args($args, $defaults);
    if ($args['total'] == 1) return;
    $paginate_links = paginate_links($args);
    echo '<div class="pagination-site">';
    echo $paginate_links;
    echo '</div>';
}

function qt_get_thumbnail($postid = 0, $size = 'thumbnail', $attributes = '') {
    if ($postid == 0) {
        global $post;
        $postid = $post->ID ?? 0;
    }
    if (has_post_thumbnail($postid)) {
        $image = wp_get_attachment_image_src(get_post_thumbnail_id($postid), 'single-post-thumbnail');
        $ketqua = $image[0] ?? '';
    } else {
        $ketqua = '';
    }
    return $ketqua;
}

function get_first_image() {
    global $post;
    $first_img = '';
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content ?? '', $matches);
    $first_img = $matches[1][0] ?? '';
    return $first_img;
}

function time_ago($type = 'post') {
    $d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
    return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago');
}

add_action('admin_menu', "wptube_admin_init");
require_once('libs/create_tag_func.php');

function dc_add_img_upload_filter($option_name, $handler) {
    add_filter('pre_update_option_' . $option_name, $handler, 10, 2);
}

function dc_handle_favicon_upload($new_value, $old_value) {
    return dc_handle_img_upload($new_value, $old_value, THEME_PREFIX . 'favicon_upload', THEME_PREFIX . 'delete_favicon');
}

function dc_handle_logo_upload($new_value, $old_value) {
    return dc_handle_img_upload($new_value, $old_value, THEME_PREFIX . 'logo_upload', THEME_PREFIX . 'delete_logo');
}

function dc_handle_headerad_img_upload($new_value, $old_value) {
    return dc_handle_img_upload($new_value, $old_value, THEME_PREFIX . 'headerad_img_upload', THEME_PREFIX . 'delete_headerad_img');
}

function dc_handle_footerad_img_upload($new_value, $old_value) {
    return dc_handle_img_upload($new_value, $old_value, THEME_PREFIX . 'footerad_img_upload', THEME_PREFIX . 'delete_footerad_img');
}

function dc_handle_img_upload($new_value, $old_value, $file_index, $delete_field) {
    if (isset($_POST[$delete_field]) && $_POST[$delete_field] == 'true') {
        return '';
    }
    if (empty($_FILES) || !isset($_FILES[$file_index]) || $_FILES[$file_index]['size'] == 0) {
        return $old_value;
    }
    $overrides = array('test_form' => false);
    $file = wp_handle_upload($_FILES[$file_index], $overrides);
    if (isset($file['error'])) {
        wp_die($file['error']);
    }
    $url = $file['url'];
    $type = $file['type'];
    $file = $file['file'];
    $filename = basename($file);
    $object = array(
        'post_title' => $filename,
        'post_content' => $url,
        'post_mime_type' => $type,
        'guid' => $url
    );
    $id = wp_insert_attachment($object, $file);
    wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
    do_action('wp_create_file_in_uploads', $file, $id);
    return esc_url(https://asiangay.tv/wp-content/themes/yolotube-mod-v2/$url);
}

add_action('parse_request', 'my_custom_css');
function my_custom_css($wp) {
    if (!empty($_GET['custom-content']) && $_GET['custom-content'] == 'css') {
        header('Content-Type: text/css');
        require dirname(__FILE__) . '/style-custom.php';
        exit;
    }
}

function wptube_admin() {
    $option_fields = array();
    if (isset($_GET['updated'])) {
        echo '<div id="message" class="updated fade"><p>WP-YoloTube Theme Options Saved.</p></div>';
    }
    ?>
    <style type="text/css">
        .container {width:635px;margin:60px 10px}
        ul.tabs {margin:0;padding:0;float:left;list-style:none;height:32px;border-bottom:1px solid #DFDFDF;border-left:1px solid #DFDFDF;width:100%}
        ul.tabs li {float:left;margin:0;padding:0;height:31px;line-height:31px;border:1px solid #DFDFDF;border-left:none;margin-bottom:-1px;background:#ECECEC;overflow:hidden;position:relative}
        ul.tabs li a {text-decoration:none;color:#999;display:block;font:bold 14px/32px Arial, Helvetica, sans-serif;text-shadow:1px 1px 0 #fff;padding:0 20px;border:1px solid #fff;outline:0}
        ul.tabs li a:hover {background:#e5e5e5}
        html ul.tabs li.active, html ul.tabs li.active a:hover {background:#fff;border-bottom:1px solid #fff}
        .tab_container {border:1px solid #DFDFDF;border-top:0;clear:both;float:left;width:100%;background:#fff;-moz-border-radius-bottomright:5px;-khtml-border-radius-bottomright:5px;-webkit-border-bottom-right-radius:5px;-moz-border-radius-bottomleft:5px;-khtml-border-radius-bottomleft:5px;-webkit-border-bottom-left-radius:5px}
        .tab_content {padding:20px;font-size:1.2em}
        .tab_content h2 {padding-bottom:10px;border-bottom:1px dashed #ddd}
        .tab_content h3 a {color:#254588}
        .tab_container textarea, .tab_container input {background:#f7f7f7;font-size:14px !important}
        .clear {clear:both}
        ul.tabs li.active a {color:#000}
        .tab_container textarea:focus, .tab_container input:focus {border:#e7e7e7 1px solid;box-shadow: 0 0 5px #e7e7e7;-webkit-box-shadow: 0 0 5px #e7e7e7;-moz-box-shadow: 0 0 5px #e7e7e7;}
        .tab_container p {font-size:14px}
        .tab_container input {padding:7px}
    </style>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery(".tab_content").hide();
            jQuery("ul.tabs li:first").addClass("active").show();
            jQuery(".tab_content:first").show();
            jQuery("ul.tabs li").click(function() {
                jQuery("ul.tabs li").removeClass("active");
                jQuery(this).addClass("active");
                jQuery(".tab_content").hide();
                var activeTab = jQuery(this).find("a").attr("href");
                jQuery(activeTab).fadeIn();
                return false;
            });
        });
    </script>
    <div class="wrap">
        <div id="icon-options-general" class="icon32"><br/></div>
        <h2>Pro WP-YoloTube Theme Options</h2>
        <div class="metabox-holder">
            <form method="post" action="options.php" enctype="multipart/form-data">
                <?php wp_nonce_field('update-options'); ?>
                <div id="theme-options">
                    <ul class="tabs">
                        <li><a href="#tab1">General Theme Options</a></li>
                        <li><a href="#tab2">Header customization</a></li>
                        <li><a href="#tab3">Footer customization</a></li>
                        <li><a href="#tab4">Advertising Spot</a></li>
                    </ul>
                    <div class="tab_container">
                        <?php
                        include("options/generals.php");
                        include("options/header-customization.php");
                        include("options/footer-customization.php");
                        include("options/video-player-adsense.php");
                        ?>
                    </div>
                </div>
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="page_options" value="<?php echo implode(",", $option_fields); ?>" />
            </form>
            <script type="text/javascript" language="javascript">SI.Files.stylizeAll();</script>
        </div>
    </div>
    Brought to you by <a href="http://kenthemes.com" target="blank">KenThemes<img src="<?php bloginfo('template_directory'); ?>/images/logo_xwp.jpg" /></a>
    <?php
}

function tube_getcustomfield($filedname, $page_current_id = NULL) {
    if ($page_current_id == NULL) {
        $page_current_id = get_the_ID();
    }
    $value = get_post_meta($page_current_id, $filedname, true);
    return $value;
}

add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
function tcb_add_post_thumbnail_column($cols) {
    $cols['tcb_post_thumb'] = __('Featured');
    return $cols;
}

add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
function tcb_display_post_thumbnail_column($col, $id) {
    if ($col == 'tcb_post_thumb') {
        $thumb = tube_getcustomfield('thumb', $id);
        if (!empty($thumb)) {
            echo '<img src="' . esc_url(https://asiangay.tv/wp-content/themes/yolotube-mod-v2/$thumb) . '" width="100" height="80" />';
        } elseif (qt_get_thumbnail($id) != "") {
            echo '<img src="' . esc_url(https://asiangay.tv/wp-content/themes/yolotube-mod-v2/qt_get_thumbnail($id)) . '" width="100" height="80" />';
        } else {
            echo '<img src="' . esc_url(https://asiangay.tv/wp-content/themes/yolotube-mod-v2/get_first_image()) . '" width="100" height="80" />';
        }
    }
}

function other_system_status_code() {
    if (is_404()) {
        status_header(200);
    }
}
add_action('template_redirect', 'other_system_status_code');

function remove_cssjs_ver($src) {
    if (strpos($src, '?ver=')) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('style_loader_src', 'remove_cssjs_ver', 10, 2);
add_filter('script_loader_src', 'remove_cssjs_ver', 10, 2);

function resizeEmbedded($subject) {
    $subject = preg_replace('/(width|height)(=|:)("|\'|)([\d]+)("|\'|)/', '${1}${2}${3}100%${3}', $subject);
    return $subject;
}

function rewrite_search_query() {
    global $wp_post_types;
    $wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'rewrite_search_query');

function remove_first_image($content) {
    if (!is_page() && !is_feed() && !is_home()) {
        $content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
    }
    return $content;
}
add_filter('the_content', 'remove_first_image');


/*
================================================================================
== BỘ CODE GOM NHÓM META BOX VÀ TÍCH HỢP REMOTE UPLOAD VÀO QUICK EDIT
================================================================================
*/

// --- 1. CONFIG API KEYS ---
$mhru_config = [
    'hydrax_key'      => '30a7a14de65deefd9220093e5a3aa1e7', // Thay key của bạn
    'hydrax_domain'   => 'gaybb.net',
    'dood_key'        => '204936hck7bjv63ovp1n22',       // Thay key của bạn
    'voe_key'         => '8Nj1xBzcPj5YRjncZQ9VevyebCqfeX84M65kIksCyN5ZOLl4koyfDEJlMbFzS9ZN',          // Thay key của bạn
    'mixdrop_email'   => 'samguku05@gmail.com',  // Thay email của bạn
    'mixdrop_key'     => 'nJZU2JaGJHMANjc7j2iz'           // Thay key của bạn
];


// --- 2. HÀM XỬ LÝ UPLOAD CHÍNH ---
function yolo_handle_multihost_upload($mp4_url, $post_id) {
    global $mhru_config;

    if (empty($mp4_url) || empty($post_id)) {
        return false;
    }

    // A. Doodstream
    if (!empty($mhru_config['dood_key'])) {
        $endpoint = 'https://doodapi.com/api/upload/url?key=' . urlencode($mhru_config['dood_key']) . '&url=' . urlencode($mp4_url);
        $response = wp_remote_get($endpoint, ['timeout' => 45]);
        if (!is_wp_error($response) && ($data = json_decode($response['body'], true)) && isset($data['result']['filecode'])) {
            update_post_meta($post_id, 'doodstream_url', 'https://dood.la/e/' . $data['result']['filecode']);
        }
    }

    // B. Hydrax
    if (!empty($mhru_config['hydrax_key'])) {
        $endpoint = 'https://up.hydrax.net/' . $mhru_config['hydrax_key'] . '/remote';
        $response = wp_remote_post($endpoint, ['body' => ['url' => $mp4_url], 'timeout' => 45]);
        if (!is_wp_error($response) && ($data = json_decode($response['body'], true)) && isset($data['slug'])) {
            update_post_meta($post_id, 'hydrax_slug', $data['slug']);
        }
    }

    // C. Voe
    if (!empty($mhru_config['voe_key'])) {
        $endpoint = 'https://voe.sx/api/upload/url';
        $response = wp_remote_post($endpoint, ['body' => ['key' => $mhru_config['voe_key'], 'url' => $mp4_url], 'timeout' => 45]);
        if (!is_wp_error($response) && ($data = json_decode($response['body'], true)) && isset($data['result']['id'])) {
            update_post_meta($post_id, 'voe_url', 'https://voe.sx/e/' . $data['result']['id']);
        }
    }
    
    // D. Mixdrop
    if (!empty($mhru_config['mixdrop_key'])) {
        $endpoint = 'https://api.mixdrop.ag/remoteupload?email=' . urlencode($mhru_config['mixdrop_email']) . '&key=' . urlencode($mhru_config['mixdrop_key']) . '&url=' . urlencode($mp4_url);
        $response = wp_remote_get($endpoint, ['timeout' => 45]);
        if (!is_wp_error($response) && ($data = json_decode($response['body'], true)) && isset($data['result']['embedurl'])) {
            $iframe_code = '<iframe src="' . esc_url(https://asiangay.tv/wp-content/themes/yolotube-mod-v2/$data['result']['embedurl']) . '" width="640" height="360" scrolling="no" frameborder="0" allowfullscreen="true"></iframe>';
            update_post_meta($post_id, 'video_code', $iframe_code);
        }
    }

    return true;
}


// --- 3. GOM NHÓM META BOX CHO GỌN GÀNG ---
// Gỡ bỏ meta box gốc của theme để thay bằng meta box mới của chúng ta
add_action('admin_menu', function() {
    remove_meta_box('portfolio_details', 'post', 'normal');
});

// Tạo meta box mới, gom tất cả các trường vào một chỗ
add_action('add_meta_boxes', 'yolo_add_consolidated_metabox');
function yolo_add_consolidated_metabox() {
    add_meta_box(
        'yolo_video_details_metabox',
        'Video Details & Servers',
        'yolo_consolidated_metabox_callback',
        'post',
        'normal',
        'high'
    );
}

// Nội dung của meta box mới
function yolo_consolidated_metabox_callback($post) {
    // Lấy tất cả giá trị meta
    $video_code     = get_post_meta($post->ID, 'video_code', true);
    $thumb          = get_post_meta($post->ID, 'thumb', true);
    $duration       = get_post_meta($post->ID, 'duration', true);
    $doodstream_url = get_post_meta($post->ID, 'doodstream_url', true);
    $hydrax_slug    = get_post_meta($post->ID, 'hydrax_slug', true);
    $voe_url        = get_post_meta($post->ID, 'voe_url', true);

    // Dùng nonce để bảo mật
    wp_nonce_field('yolo_save_meta_box_data', 'yolo_meta_box_nonce');
    
    // Hiển thị các trường
    ?>
    <style> .yolo-meta-field { margin-bottom: 15px; } .yolo-meta-field label { font-weight: bold; display: block; margin-bottom: 5px; } .yolo-meta-field input, .yolo-meta-field textarea { width: 100%; } </style>
    <div class="yolo-meta-field">
        <label for="video_code">Embed Code (iframe)</label>
        <textarea name="video_code" id="video_code" rows="3"><?php echo esc_textarea($video_code); ?></textarea>
    </div>
    <div class="yolo-meta-field">
        <label for="thumb">Thumbnail URL</label>
        <input type="text" name="thumb" id="thumb" value="<?php echo esc_attr($thumb); ?>">
    </div>
    <div class="yolo-meta-field">
        <label for="duration">Duration</label>
        <input type="text" name="duration" id="duration" value="<?php echo esc_attr($duration); ?>" placeholder="e.g., 15:30">
    </div>
    <hr>
    <h4>Server Links (Auto-filled by Quick Edit)</h4>
    <div class="yolo-meta-field">
        <label for="doodstream_url">DoodStream URL</label>
        <input type="text" name="doodstream_url" id="doodstream_url" value="<?php echo esc_attr($doodstream_url); ?>">
    </div>
    <div class="yolo-meta-field">
        <label for="hydrax_slug">Hydrax Slug</label>
        <input type="text" name="hydrax_slug" id="hydrax_slug" value="<?php echo esc_attr($hydrax_slug); ?>">
    </div>
    <div class="yolo-meta-field">
        <label for="voe_url">Voe.sx URL</label>
        <input type="text" name="voe_url" id="voe_url" value="<?php echo esc_attr($voe_url); ?>">
    </div>
    <?php
}

// Lưu dữ liệu từ meta box mới
add_action('save_post', 'yolo_save_consolidated_metabox_data');
function yolo_save_consolidated_metabox_data($post_id) {
    if (!isset($_POST['yolo_meta_box_nonce']) || !wp_verify_nonce($_POST['yolo_meta_box_nonce'], 'yolo_save_meta_box_data')) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    
    $fields_to_save = ['video_code', 'thumb', 'duration', 'doodstream_url', 'hydrax_slug', 'voe_url'];
    
    foreach ($fields_to_save as $field) {
        if (isset($_POST[$field])) {
            update_post_meta($post_id, $field, sanitize_text_field($_POST[$field]));
        }
    }
}


// --- 4. TÍCH HỢP UPLOAD VÀO QUICK EDIT ---
// Thêm cột mới
add_filter('manage_posts_columns', 'yolo_add_quick_edit_column');
function yolo_add_quick_edit_column($columns) {
    $columns['remote_upload'] = 'Remote Upload';
    return $columns;
}

// Thêm ô input vào khung Quick Edit
add_action('quick_edit_custom_box', 'yolo_add_quick_edit_field', 10, 2);
function yolo_add_quick_edit_field($column_name, $post_type) {
    if ($column_name != 'remote_upload' || $post_type != 'post') {
        return;
    }
    wp_nonce_field('yolo_quick_edit_nonce', 'yolo_quick_edit_nonce_field');
    ?>
    <fieldset class="inline-edit-col-right" style="margin-top: 10px;">
        <div class="inline-edit-col">
            <label class="alignleft">
                <span class="title"><strong>Remote Upload MP4</strong></span>
                <span class="input-text-wrap">
                    <input type="url" name="yolo_quick_edit_mp4_url" value="" placeholder="Dán link .mp4 vào đây và bấm Update" style="width: 100%;">
                </span>
            </label>
            <p class="description">Chỉ cần dán link vào đây, các server sẽ được tự động cập nhật.</p>
        </div>
    </fieldset>
    <?php
}

// Kích hoạt upload khi lưu Quick Edit
add_action('save_post', 'yolo_trigger_upload_on_quick_edit_save');
function yolo_trigger_upload_on_quick_edit_save($post_id) {
    // Hook này sẽ chạy sau hook lưu meta box ở trên
    if (!current_user_can('edit_post', $post_id)) return;
    if (!isset($_POST['yolo_quick_edit_nonce_field']) || !wp_verify_nonce($_POST['yolo_quick_edit_nonce_field'], 'yolo_quick_edit_nonce')) return;
    
    if (isset($_POST['yolo_quick_edit_mp4_url'])) {
        $mp4_url = esc_url_raw(trim($_POST['yolo_quick_edit_mp4_url']));
        if (!empty($mp4_url)) {
            yolo_handle_multihost_upload($mp4_url, $post_id);
        }
    }
}

/*
================================================================================
== BỘ CODE TÍCH HỢP - KẾT THÚC
================================================================================
*/