/**
 * 无人机之窗 - 子主题功能增强
 */

// ========== 覆盖 JNews 日期函数 ==========
if ( ! function_exists( 'jeg_get_post_date' ) ) {
    function jeg_get_post_date( $format = '', $post = null ) {
        $publish_date                = get_post_time( $format ?: 'Y-m-d', false, $post );
        $modified_date               = get_the_modified_date( $format ?: 'Y-m-d', $post );
        $publish_date_number_format  = get_post_time( 'Y-m-d', false, $post );
        $modified_date_number_format = get_the_modified_date( 'Y-m-d', $post );
        if ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'publish' ) {
            return $publish_date;
        } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'both' ) {
            if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
                return $publish_date;
            } else {
                return $publish_date . ' - ' . jnews_return_translation( 'Updated on', 'jnews', 'updated_on' ) . ' ' . $modified_date;
            }
        } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'modified' ) {
            if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
                return $publish_date;
            } else {
                return $modified_date;
            }
        }
        return $publish_date;
    }
}

// ========== 加载父主题样式 ==========
add_action( 'wp_enqueue_scripts', 'jnews_child_enqueue_parent_style' );
function jnews_child_enqueue_parent_style() {
    wp_enqueue_style( 'jnews-parent-style', get_parent_theme_file_uri('/style.css') );
}

// Yoast 优化
add_filter( 'wpseo_premium_load_emoji_picker', '__return_false' );

// ========== 输出缓冲修复（所有页面） ==========
add_action( 'template_redirect', function () {
    ob_start( function ( $buffer ) {
        // Fix 1: 修复垃圾日期字符串
        $buffer = preg_replace(
            '/202\d+Asia\/Shanghai\d+/',
            date_i18n( 'Y年m月d日' ),
            $buffer
        );

        // Fix 2: 修复反斜杠前缀中文字符
        // 匹配 \厂 这样的模式
        $buffer = preg_replace(
            '/\\\\([\x{4e00}-\x{9fff}])/u',
            '$1',
            $buffer
        );

        // Fix 3: 解码 \uXXXX Unicode 转义序列为实际字符
        // 用于 JS 数据块中的 "first_title":"\u5382\u5bb6..."
        $buffer = preg_replace_callback(
            '/\\\\u([0-9a-fA-F]{4})/',
            function ( $m ) {
                return html_entity_decode( '&#x' . $m[1] . ';', ENT_NOQUOTES, 'UTF-8' );
            },
            $buffer
        );

        return $buffer;
    });
}, -1000 );

// ========== 内联 CSS 修复 ==========
add_action( 'wp_head', function () {
    echo '<style>
    /* 隐藏顶栏多余横幅（header_top_ads） */
    .jnews_header_top_ads,
    .jeg_ad.jnews_header_top_ads {
        display: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    /* 隐藏底栏横幅 */
    .jnews_header_bottom_ads,
    .jeg_ad.jnews_header_bottom_ads {
        display: none !important;
    }
    /* 右侧广告位隐藏 */
    .jeg_ad.jnews_article_ads {
        display: none !important;
    }
    </style>';
}, 99 );
// Fix: Prevent Unicode escaping in JSON output for Elementor ads
});
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//www.drone-window.com/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://www.drone-window.com/post-sitemap.xml</loc>
		<lastmod>2026-04-27T12:46:28+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.drone-window.com/page-sitemap.xml</loc>
		<lastmod>2026-04-25T22:11:19+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.drone-window.com/footer-sitemap.xml</loc>
		<lastmod>2025-09-23T01:42:11+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.drone-window.com/category-sitemap.xml</loc>
		<lastmod>2026-04-27T12:46:28+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.drone-window.com/post_tag-sitemap.xml</loc>
		<lastmod>2026-04-27T12:46:28+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.drone-window.com/author-sitemap.xml</loc>
		<lastmod>2026-04-23T13:13:37+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->