<?php
if (!defined('ABSPATH')) exit;

global $wpdb;
$id = get_the_ID();
$post_extend = get_post_meta($id, 'luntan_views', true);
update_post_meta($id, 'luntan_views',  (int)$post_extend + 1);
$detail = get_post($id);

$detail->nickname = get_userdata($detail->post_author)->nickname ? get_userdata($detail->post_author)->nickname : '用户' . $detail->post_author;

$avatar = get_user_meta($detail->post_author, 'luntan_avatar', true);

$luntan_img = get_post_meta($id, 'luntan_img', true);
if ($luntan_img) {
  $luntan_img = explode(',', $luntan_img);
} else {
  $luntan_img = [];
}
$jing = (int)get_post_meta($id, 'luntan_jing', true);

$cate_id = get_the_terms($id, 'luntan_cate') ? get_the_terms($id, 'luntan_cate')[0]->term_id : 0;

$args = array(
  'post_id' => $id,
  'order' => 'ASC',
  'hierarchical' => true,
  'status' => 'approve',
  'parent' => 0
);


// 创建评论查询对象
$comments_query = new WP_Comment_Query;

// 执行评论查询 
$pl = $comments_query->query($args);




$categories = get_terms(array(
  'taxonomy'   => 'luntan_cate', // 自定义分类法的名称
  'hide_empty' => false,         // 是否隐藏没有关联文章的分类项
));
if (wp_cache_get('luntan_news') === false) {
  // 执行 SQL 查询
  $news = $wpdb->get_results(" 
        SELECT p.*, MAX(c.comment_date) as latest_comment_date
        FROM {$wpdb->posts} p
        LEFT JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
        WHERE p.post_type = 'luntan'
        AND p.post_status = 'publish'
         AND c.comment_approved = '1'
        GROUP BY p.ID
        ORDER BY latest_comment_date DESC
        LIMIT 5
    ");
  wp_cache_set('luntan_news', $news, '', 3600);
} else {
  $news = wp_cache_get('luntan_news');
}
$hot = get_posts(array(
  'numberposts' => 5,
  'orderby'     => 'meta_value_num',
  'order'       => 'luntan_views',
  'post_type' => 'luntan',
  'post_status' => 'publish',
));


$luntan_url_guanli = get_option('luntan_url_guanli');
if (isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']) {
  $luntan_url = $luntan_url_guanli['list'];
  $luntan_url_zx = $luntan_url_guanli['zhongxin'];
} else {
  $luntan_url = 'ltwdsqht';
  $luntan_url_zx = 'ltwdsqht_zx';
}


if (luntan_is_block_theme()) {
?>

  <!DOCTYPE html>
  <html <?php language_attributes(); ?>>

  <head>
    <?php wp_head(); ?>
  </head>

  <body <?php body_class(); ?>>
    <?php wp_body_open();
    block_template_part('header');
    ?>
    <!-- 最大盒子 -->
    <div id="wzt_luantan_detail_box" data-id="">
      <!-- 左边 -->
      <div class="fb_left">
        <!-- 帖子主体 -->
        <div class="tz_content">
          <!-- 帖子顶部  -->
          <div class="tzc_top">
            <div class="tzct_left">
              <!-- 此处需要判断个人信息是否存在！！！ -->
              <!-- 发帖人头像 -->
              <div class="tz_avatar">
                <img src="<?php echo $avatar ? esc_url($avatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" onerror="this.onerror=null;this.src='<?php echo esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>'" />
              </div>
              <!-- 数据 -->
              <div class="tz_data">
                <!-- @用户名 -->
                <div class="nick"><?php echo get_userdata($detail->post_author)->nickname ? esc_attr(get_userdata($detail->post_author)->nickname) : '用户' . esc_attr($detail->post_author); ?></div>
                <div class="tzd_bom">
                  <div class="time">
                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/time.png', LUNTAN_FILE)); ?>" alt="" />
                    <!-- @发帖时间 -->
                    <span><?php echo esc_attr($detail->post_date); ?></span>
                  </div>
                  <div class="view">
                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                    <!-- @浏览人数 -->
                    <span><?php echo (int)$post_extend; ?></span>
                  </div>
                </div>
              </div>
            </div>
            <div class="tzct_right">
              <div class="tag">

                <?php if (is_sticky($id)) { ?>
                  <div class="zhiding">
                    置顶
                  </div>
                <?php } ?>

                <?php if ($jing) { ?>
                  <div class="jing">
                    精
                  </div>
                <?php } ?>
              </div>
              <!-- 权限判断 -->
              <?php if (current_user_can('administrator')) { ?>
                <div class="service">
                  <span class="dropdown">管理</span>

                  <!-- @点击管理后弹出 -->
                  <div class="menu-detail">
                    <div class="edit">编辑</div>
                    <div class="top">置顶帖子</div>
                    <div class="untop">取消置顶</div>
                    <div class="hot">设为精华</div>
                    <div class="unhot">取消精华</div>
                    <div class="cancel">删除</div>
                  </div>
                </div>
              <?php } ?>
            </div>
          </div>

          <!-- 帖子内容 -->
          <div class="tzc_con">
            <!-- @帖子标题 -->
            <h1 class="title"><?php echo esc_attr($detail->post_title); ?></h1>
            <!-- @帖子正文 -->
            <p class="content">
              <?php echo wp_kses_post($detail->post_content) ?>
              </p>

            <!-- @帖子图片 -->
            <div class="imgs">
              <?php if (!empty($luntan_img)) {
                foreach ($luntan_img as $k => $v) {
              ?>
                  <!-- @图片1 -->
                  <img data-watch="1" src="<?php echo esc_url($v); ?>" alt="" />

              <?php }
              } ?>
            </div>
          </div>
          <?php if ($cate_id) { ?>
            <!-- 帖子底部 -->
            <div class="tzc_bom">
              <!-- @文章分类 -->
              <?php $term_cate = get_term($cate_id, 'luntan_cate');
              if ($term_cate) {
              ?>
                <a href="<?php echo esc_url(get_term_link($term_cate)); ?>" class="tag_item"><?php echo esc_attr($term_cate->name); ?></a>
              <?php } ?>
            </div>
          <?php } ?>
        </div>
        <!-- 帖子评论 -->

        <div class="tz_pl_box">
          <!-- 回复以及评论按钮 -->
          <div class="tools">
            <div class="t_left">
              <div class="title">回复</div>
              <div class="border"></div>
              <!-- @回复数量 -->
              <div class="num">共<?php echo count($pl); ?>条回复</div>
            </div>
            <?php if (is_user_logged_in()) { //登录判断 
            ?>
              <div class="t_right">
                <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_white.png', LUNTAN_FILE)); ?>" alt="" />


                <!-- @需要登录判断 -->
                <span>评论</span>
              </div>
            <?php } ?>
          </div>
          <?php if (is_user_logged_in()) { //登录判断 
          ?>
            <!-- 评论输入框 -->
            <div class="pinglun_box">
              <div class="pinglun_input">

                <!-- @文本域 -->
                <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>
              </div>

              <div class="pinglun_c_bom">
                <!-- 照片列表 -->
                <div class="imgBox">

                  <!-- @上传图片 -->
                  <div class="addImg" data-id="0">
                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />
                  </div>

                </div>
                <!-- @需要登录判断 -->
                <div class="submit" data-id="0">发布</div>
              </div>
            </div>
          <?php } ?>


          <!-- 评论列表 -->
          <div class="pinglunlist">
            <?php if ($pl) {
              foreach ($pl as $k => $comment) {

                if ($comment->comment_parent == 0) {
            ?>
                  <div class="pinglun_item" data-id="<?php echo intval($comment->comment_ID); ?>">

                    <div class="pi_avatar">
                      <!-- 头像 -->
                      <img src="<?php echo get_user_meta($comment->user_id, 'luntan_avatar', true) ? esc_url(get_user_meta($comment->user_id, 'luntan_avatar', true)) : esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" onerror="this.onerror=null;this.src='<?php echo esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>'"/>
                    </div>

                    <div class="pi_data">
                      <div class="pid_top">

                        <!-- @用户名 -->
                        <div class="nick"><?php echo get_userdata($comment->user_id)->nickname ? esc_attr(get_userdata($comment->user_id)->nickname) : '用户' . intval($comment->user_id); ?></div>

                        <div class="pi_action">
                          <!-- @点赞 -->
                          <!-- @需要登录判断 -->
                          <div class="dianzan" data-id="<?php echo intval($comment->comment_ID); ?>">
                            <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                              <path d="M27.6002 18.5998V11.3998C27.6002 8.41743 25.1826 5.99977 22.2002 5.99977L15.0002 22.1998V41.9998H35.9162C37.7113 42.0201 39.2471 40.7147 39.5162 38.9398L42.0002 22.7398C42.1587 21.6955 41.8506 20.6343 41.1576 19.8373C40.4645 19.0403 39.4564 18.5878 38.4002 18.5998H27.6002Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                              <path d="M15 22.0001H10.194C8.08532 21.9628 6.2827 23.7095 6 25.7994V38.3994C6.2827 40.4894 8.08532 42.0367 10.194 41.9994H15V22.0001Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                            </svg>

                            <span><?php echo (int)get_comment_meta($comment->comment_ID, 'luntan_likes_count', true); ?></span>

                          </div>

                          <!-- @点踩 -->
                          <!-- @需要登录判断 -->
                          <div class="cai" data-id="<?php echo intval($comment->comment_ID); ?>">
                            <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                              <path d="M20.3793 29.4002V36.6002C20.3793 39.5826 22.7969 42.0002 25.7793 42.0002L32.9793 25.8002V6.00023H12.0633C10.2682 5.97994 8.73244 7.2853 8.46327 9.06023L5.97927 25.2602C5.82077 26.3045 6.12885 27.3657 6.82192 28.1627C7.51499 28.9597 8.52311 29.4122 9.57927 29.4002H20.3793Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                              <path d="M32.9795 6.00017H37.7855C39.8942 5.96288 41.6968 7.51019 41.9795 9.60017V22.2002C41.6968 24.2901 39.8942 26.0375 37.7855 26.0002H32.9795V6.00017Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                            </svg>
                            <span><?php echo  (int)get_comment_meta($comment->comment_ID, 'luntan_cai_count', true); ?></span>
                          </div>

                          <?php if (is_user_logged_in()) {
                            $current_user = wp_get_current_user();
                            if ($current_user->ID == $comment->user_id) {
                          ?>
                              <!-- @如果是自己评论的，可以删除 -->
                              <div class="delete" data-id="<?php echo intval($comment->comment_ID); ?>">
                                <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/del_red.png', LUNTAN_FILE)); ?>" alt="" />
                                <span>删除</span>
                              </div>
                            <?php } ?>

                            <!-- @需要登录判断 -->
                            <div class="open" data-id="<?php echo intval($comment->comment_ID); ?>">
                              <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_blue.png', LUNTAN_FILE)); ?>" alt="" />
                              <span>评论</span>
                            </div>
                          <?php } ?>
                        </div>
                      </div>
                      <div class="pid_con">

                        <!-- @评论正文 -->
                        <p class="text"><?php echo nl2br(esc_html($comment->comment_content)); ?></p>
                        <?php $img = get_comment_meta($comment->comment_ID, 'luntan_pl_img', true);
                        if ($img) {
                          $img = explode(',', $img);

                        ?>
                          <!-- @评论图片 -->
                          <div class="imgs">
                            <?php foreach ($img as $k => $v) { ?>
                              <img data-watch="1" src="<?php echo esc_url($v); ?>" alt="" />
                            <?php } ?>
                          </div>
                        <?php } ?>
                      </div>

                      <!-- @评论时间 -->
                      <div class="pid_bom"><?php echo esc_attr($comment->comment_date); ?></div>

                      <!-- 评论内容 -->
                      <div class="pid_edit" data-id="<?php echo intval($comment->comment_ID); ?>">
                        <div class="pinglun_input">

                          <!-- @文本域 -->
                          <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>

                        </div>

                        <div class="pinglun_c_bom">
                          <!-- 照片列表 -->
                          <div class="imgBox">

                            <!-- @上传图片 -->
                            <div class="addImg" data-id="<?php echo intval($comment->comment_ID); ?>">
                              <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />

                              <input type="file" name="img" multiple="multiple" accept=".jpg, .png, .webp, .gif, .jpeg" class="el-upload__input">
                            </div>

                          </div>

                          <div class="submit" data-id="<?php echo intval($comment->comment_ID); ?>">发布</div>
                        </div>
                      </div>

                      <!-- 评论的回复 -->
                      <div class="pid_list">
                        <!-- 评论的盒子 -->
                        <?php $child = luntan_post::luntan_get_comment_with_children($comment, $id, []);
                        if (!empty($child)) {
                          foreach ($child as $key => $val) {
                        ?>
                            <div class="pid_item">
                              <div class="pidi_top">
                                <div class="people">
                                  <div class="hfr">
                                    <div class="avatar">
                                      <img src="<?php echo $val->avatar ? esc_url($val->avatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                                    </div>

                                    <!-- @回复的人 -->
                                    <div class="nick">
                                      <?php echo esc_attr($val->nickname); ?>
                                    </div>
                                  </div>
                                  <div class="right_icon">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none">
                                      <path d="M4.125 2.70711C4.125 2.26165 4.66357 2.03857 4.97855 2.35355L8.27145 5.64645C8.46671 5.84171 8.46671 6.15829 8.27145 6.35355L4.97855 9.64645C4.66357 9.96143 4.125 9.73835 4.125 9.29289L4.125 2.70711Z" fill="#777777" />
                                    </svg>
                                  </div>

                                  <div class="bhfr">
                                    <div class="avatar">
                                      <img src="<?php echo $val->cavatar ? esc_url($val->cavatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                                    </div>

                                    <!-- @原评论人 -->
                                    <div class="nick">
                                      <?php echo esc_attr($val->cnickname); ?>
                                    </div>
                                  </div>
                                </div>

                                <!-- 回复时间 -->
                                <div class="time"><?php echo esc_attr($val->comment_date); ?></div>
                              </div>
                              <div class="pidi_con">

                                <!-- 回复内容 -->
                              <div class="text"><?php echo esc_attr($val->comment_content); ?></div>
                                <?php if ($val->img) { ?>
                                  <!-- 回复图片 -->
                                  <div class="imgs">
                                    <?php $img = explode(',', $val->img);
                                    if (!empty($img)) {
                                      foreach ($img as $imgs) {
                                    ?>
                                        <img data-watch="1" src="<?php echo esc_url($imgs); ?>" alt="" />
                                    <?php }
                                    } ?>


                                  </div>
                                <?php } ?>
                              </div>
                              <div class="pidi_bom">
                                <div class="mb_time"><?php echo esc_attr($val->comment_date); ?></div>

                                <!-- @点赞 -->
                                <!-- @需要登录判断 -->
                                <div class="zan" data-id="<?php echo intval($val->comment_ID); ?>">
                                  <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                                    <path d="M27.6002 18.5998V11.3998C27.6002 8.41743 25.1826 5.99977 22.2002 5.99977L15.0002 22.1998V41.9998H35.9162C37.7113 42.0201 39.2471 40.7147 39.5162 38.9398L42.0002 22.7398C42.1587 21.6955 41.8506 20.6343 41.1576 19.8373C40.4645 19.0403 39.4564 18.5878 38.4002 18.5998H27.6002Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                    <path d="M15 22.0001H10.194C8.08532 21.9628 6.2827 23.7095 6 25.7994V38.3994C6.2827 40.4894 8.08532 42.0367 10.194 41.9994H15V22.0001Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                  </svg>
                                  <span><?php echo (int)$val->likes; ?></span>
                                </div>

                                <!-- @点踩 -->
                                <!-- @需要登录判断 -->
                                <div class="cai" data-id="<?php echo intval($val->comment_ID); ?>">
                                  <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                                    <path d="M20.3793 29.4002V36.6002C20.3793 39.5826 22.7969 42.0002 25.7793 42.0002L32.9793 25.8002V6.00023H12.0633C10.2682 5.97994 8.73244 7.2853 8.46327 9.06023L5.97927 25.2602C5.82077 26.3045 6.12885 27.3657 6.82192 28.1627C7.51499 28.9597 8.52311 29.4122 9.57927 29.4002H20.3793Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                    <path d="M32.9795 6.00017H37.7855C39.8942 5.96288 41.6968 7.51019 41.9795 9.60017V22.2002C41.6968 24.2901 39.8942 26.0375 37.7855 26.0002H32.9795V6.00017Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                  </svg>
                                  <span><?php echo (int)$val->cai; ?></span>
                                </div>


                                <?php if (is_user_logged_in()) {
                                  $current_user = wp_get_current_user();
                                  if ($current_user->ID == $val->user_id) {
                                ?>
                                    <!-- 只有是自己回复的才能删除 -->
                                    <div class="delete" data-id="<?php echo intval($val->comment_ID); ?>">
                                      <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/del_red.png', LUNTAN_FILE)); ?>" alt="" />
                                      <span>删除</span>
                                    </div>
                                  <?php } ?>

                                  <div class="pinglun" data-id="<?php echo intval($val->comment_ID); ?>">
                                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_blue.png', LUNTAN_FILE)); ?>" alt="" />
                                    <span>评论</span>
                                  </div>
                                <?php } ?>
                              </div>

                              <!-- 点击评论后出现 -->
                              <div class="pidi_pinglun" data-id="<?php echo intval($val->comment_ID); ?>">

                                <div class="pinglun_input">

                                  <!-- @文本域 -->
                                  <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>

                                </div>

                                <div class="pinglun_c_bom">

                                  <!-- 照片列表 -->
                                  <div class="imgBox">

                                    <!-- @上传图片 -->
                                    <div class="addImg" data-id="<?php echo intval($val->comment_ID); ?>">
                                      <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />
                                      <input type="file" name="img" multiple="multiple" accept=".jpg, .png, .webp, .gif, .jpeg" class="el-upload__input">
                                    </div>

                                  </div>

                                  <div class="submit" data-id="<?php echo intval($val->comment_ID); ?>">发布</div>
                                </div>
                              </div>
                            </div>
                        <?php }
                        } ?>
                      </div>
                    </div>
                  </div>
            <?php }
              }
            } ?>
          </div>
        </div>
      </div>

      <!-- 右 -->
      <div class="fb_right">
        <!-- 个人信息栏 -->
        <div class="fbr_userInfo">
          <?php if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            //"您已登录！";
          ?>
            <div class="fbr_u_top">
              <div class="fbr_u_t_left">
                <div class="fbr_u_t_l_avatar">

                  <!-- 默认头像 -->
                  <img src="<?php echo  get_user_meta($current_user->ID, 'luntan_avatar', true) ? esc_attr(get_user_meta($current_user->ID, 'luntan_avatar', true)) : esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                </div>
                <div class="fbr_u_t_l_info">
                  <!-- 已经登录 -->
                  <div class="fbr_u_t_l_i_nick"><?php if (isset($current_user->nickname)) {
                                                  echo esc_attr($current_user->nickname);
                                                } ?></div>

                  <!-- 已经登录 -->
                  <div class="fbr_u_t_l_i_id">ID：<?php if (isset($current_user->ID)) {
                                                    echo intval($current_user->ID);
                                                  } ?></div>
                </div>
              </div>
              <!-- 已经登录 -->
              <div class="fbr_u_t_right">
                <?php $pub_num = count(get_posts(array(
                  'author' => $current_user->ID,
                  'numberposts' => -1, // 获取所有符合条件的文章，-1表示无限制数量
                  'post_type' => 'luntan',
                )));
                ?>
                <div class="fbr_u_t_r_num"><?php echo (int)$pub_num; ?></div>
                <div class="fbr_u_t_r_text">帖子</div>
              </div>
            </div>
            <div class="fbr_u_bom">

              <!-- 已经登录 -->
              <div class="fbr_u_true">
                <div class="fbr_u_b_t_left">
                  <a href="/<?php echo esc_attr($luntan_url_zx); ?>">
                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/user.png', LUNTAN_FILE)); ?>" alt="" />
                    <span>个人中心</span>
                  </a>
                </div>
                <div class="fbr_u_b_t_right">
                  <a href="<?php echo esc_url(wp_logout_url()); ?>">
                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/goout.png', LUNTAN_FILE)); ?>" alt="" />
                    <span>退出登录</span>
                  </a>
                </div>
              </div>

            </div>

          <?php } else { ?>
            <?php // "您未登录，请先登录。";
            ?>
            <div class="fbr_u_top">
              <div class="fbr_u_t_left">
                <div class="fbr_u_t_l_avatar">

                  <!-- 默认头像 -->
                  <img src="<?php echo  esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                </div>
                <div class="fbr_u_t_l_info">

                  <!-- 未登录 -->
                  <div class="fbr_u_t_l_i_nick">请先登录</div>
                  <!-- 已经登录 -->

                </div>
              </div>

            </div>
            <div class="fbr_u_bom">
              <!-- 未登录 -->
              <a href="<?php echo esc_url(wp_login_url()); ?>" class="fbr_u_false">
                <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/user.png', LUNTAN_FILE)); ?>" alt="" />
                <span>请先登录</span>
              </a>
            </div>

          <?php } ?>

        </div>

        <!-- 搜索 -->
        <div class="fbr_search">
          <form action="/<?php echo esc_attr($luntan_url); ?>/" method="get">
            <input type="text" type="text" class="el-input__inner" placeholder="请输入搜索内容" style="padding: 0 10px 0 25px  !important; border: 1px solid #DCDFE6 !important;" name="s">
            <button class="el-button" style="background-color: #2281ff !important;">
              搜索
            </button>
            <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/search.png', LUNTAN_FILE)); ?>" alt="" />
          </form>
        </div>

        <!-- 热门 -->
        <div class="fbr_hot">
          <!-- 热门标题 -->
          <div class="h_tit">热门帖子11</div>
          <!-- 热门帖子列表 -->
          <div class="h_list">
            <!-- 热门帖子盒子 -->
            <?php if (!empty($hot)) {
              foreach ($hot as $k => $v) {
            ?>
                <div class="h_item">
                  <?php
                  // 定义对应关系
                  $xuhao_classes = ['one', 'two', 'three', 'four', 'five'];
                  // 根据索引循环取对应的类
                  $xuhao_class = $xuhao_classes[$k % 5];
                  ?>
                  <a href="<?php if (isset($v->ID)) {
                              the_permalink($v->ID);
                            } ?>">
                    <!-- 头部 -->
                    <div class="hi_top">
                      <div class="'xuhao <?php echo esc_attr($xuhao_class); ?>">
                        <?php echo (int)$k + 1; ?>
                      </div>
                      <div class="title"><?php echo esc_attr($v->post_title); ?></div>
                    </div>
                    <!-- 底部 -->
                    <div class="hi_bom">
                      <!-- 相关数据 -->
                      <div class="hb_left">
                        <!-- 浏览 -->
                        <div class="view">
                          <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                          <div class="num"><?php echo get_post_meta($v->ID, 'luntan_views', true) ? (int)get_post_meta($v->ID, 'luntan_views', true) : 0; ?></div>
                        </div>
                        <!-- 评论 -->
                        <div class="pinglun">
                          <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark.png', LUNTAN_FILE)); ?>" alt="" />
                          <div class="num"><?php echo get_post_meta($v->ID, 'luntan_replay_num', true) ? (int)get_post_meta($v->ID, 'luntan_replay_num', true) : 0; ?></div>
                        </div>
                      </div>
                      <!-- 时间 -->
                      <div class="time"><?php if (isset($v->post_date)) {
                                          echo esc_attr($v->post_date);
                                        } ?></div>
                    </div>
                    <!-- 边框线条 -->
                    <div class="hi_border"></div>
                  </a>
                </div>
            <?php }
            } ?>
          </div>
        </div>

        <!-- 最新 -->
        <div class="fbr_new">
          <!-- 最新标题 -->
          <div class="n_tit">最新回复</div>
          <!-- 热门帖子列表 -->
          <div class="n_list">
            <!-- 热门帖子盒子 -->
            <?php if (!empty($news)) {
              foreach ($news as $k => $v) {
            ?>
                <div class="n_item">
                  <?php
                  // 定义对应关系
                  $xuhao_classes = ['one', 'two', 'three', 'four', 'five'];
                  // 根据索引循环取对应的类
                  $xuhao_class = $xuhao_classes[$k % 5];
                  ?>
                  <a href="<?php if (isset($v->ID)) {
                              the_permalink($v->ID);
                            } ?>">
                    <!-- 头部 -->
                    <div class="ni_top">
                      <div class="xuhao <?php echo esc_attr($xuhao_class); ?>">
                        <?php echo (int)$k + 1; ?>
                      </div>
                      <div class="title"><?php echo esc_attr($v->post_title); ?></div>
                    </div>
                    <!-- 底部 -->
                    <div class="ni_bom">
                      <!-- 相关数据 -->
                      <div class="nb_left">
                        <!-- 浏览 -->
                        <div class="view">
                          <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                          <div class="num"><?php echo get_post_meta($v->ID, 'luntan_views', true) ? (int)get_post_meta($v->ID, 'luntan_views', true) : 0; ?></div>
                        </div>
                        <!-- 评论 -->
                        <div class="pinglun">
                          <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark.png', LUNTAN_FILE)); ?>" alt="" />
                          <div class="num"><?php echo get_post_meta($v->ID, 'luntan_replay_num', true) ? (int)get_post_meta($v->ID, 'luntan_replay_num', true) : 0; ?></div>
                        </div>
                      </div>
                      <!-- 时间 -->
                      <div class="time"><?php if (isset($v->post_date)) {
                                          echo esc_attr($v->post_date);
                                        } ?></div>
                    </div>
                    <!-- 边框线条 -->
                    <div class="ni_border"></div>
                  </a>
                </div>
            <?php }
            } ?>
          </div>
        </div>

        <!-- 其他 -->
        <div class="fbr_other">
          <div class="o_tit">其他板块</div>


          <div class="o_type">
            <?php if (!empty($categories)) {
              foreach ($categories as $k => $v) {
                $term = get_term($v->term_id, 'luntan_cate');
            ?>
                <a href="/<?php echo esc_attr($luntan_url); ?>/">
                  <div class="ot_item" :class="ot_item ot_item_act" data-id="<?php echo intval($v->term_id); ?>">
                    <?php echo esc_attr($v->name); ?>
                  </div>
                </a>
            <?php }
            } ?>
          </div>

        </div>
      </div>

      <!-- 弹窗 -->


      <!-- 编辑帖子弹出框 -->
      <div class="fbDialogBox">
        <div class="dialog-header">
          <span>编辑帖子</span>
          <div class="close-btn">&times;</div>
        </div>

        <div class="dialog-body">
          <div class="form-item">
            <div class="bold_text">标题</div>
            <input type="text" class="title_input" placeholder="请输入标题" style="padding: 10px  !important; border: 1px solid #DCDFE6 !important;" value="<?php echo esc_attr($detail->post_title); ?>">
          </div>
          <div class="form-item">
            <div class="bold_text">内容</div>
            <textarea class="content_input" placeholder="请输入内容" id="pc_fbContent"></textarea>
          </div>

          <div class="form-item">
            <div class="bold_text">添加照片</div>
            <div class="imgBox">

              <?php if (!empty($luntan_img)) {
                foreach ($luntan_img as $k => $v) {
              ?>
                  <div class="uploaded-img">
                    <img src="<?php echo esc_url($v); ?>" alt="">
                    <div class="remove-img">×</div>
                  </div>
              <?php }
              } ?>


              <div class="addImg-btn">
                <img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxsaW5lIHgxPSIxMiIgeTE9IjUiIHgyPSIxMiIgeTI9IjE5Ij48L2xpbmU+PGxpbmUgeDE9IjUiIHkxPSIxMiIgeDI9IjE5IiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=" alt="添加图片">
              </div>
            </div>
          </div>

          <div class="form-item">
            <div class="bold_text">板块分类</div>
            <div class="typeTab">
              <?php if (!empty($categories)) {
                foreach ($categories as $k => $v) {
              ?>
                  <div class="typeTab_item" data-id="<?php echo intval($v->term_id); ?>"><?php echo esc_attr($v->name); ?></div>

              <?php }
              } ?>
            </div>
          </div>


        </div>

        <div class="dialog-footer">
          <button class="btn btn-cancel">取 消</button>
          <button class="btn btn-primary">确 定</button>
        </div>
      </div>

      <div class="preview-dialog">
        <span class="preview-close">&times;</span>
        <img class="preview-img" src="" alt="图片预览">
      </div>

      <!-- 2025/2/24 更改登录注册弹窗 -->
      <div class="login_Dialog" style="display: none;">
        <div class="el-dialog">
          <span class="new_l_tit">欢迎使用论坛！</span>
          <span class="new_l_tip">提示：部分邮箱收不到注册邮件，请注册后通过忘记密码重置账号密码</span>
          <div class="new_l_top">
            <div class="l_t_item new_l_top_login">
              点我登录
            </div>
            <div class="l_t_item new_l_top_register">
              点我注册
            </div>
          </div>
        </div>
      </div>

    </div>
    <?php
    block_template_part('footer');
    wp_footer();
    ?>
  </body>

  </html>
<?php } else {
  get_header();

?>
  <!-- 最大盒子 -->
  <div id="wzt_luantan_detail_box" data-id="">
    <!-- 左边 -->
    <div class="fb_left">
      <!-- 帖子主体 -->
      <div class="tz_content">
        <!-- 帖子顶部  -->
        <div class="tzc_top">
          <div class="tzct_left">
            <!-- 此处需要判断个人信息是否存在！！！ -->
            <!-- 发帖人头像 -->
            <div class="tz_avatar">
              <img src="<?php echo $avatar ? esc_url($avatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" onerror="this.onerror=null;this.src='<?php echo esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>'" />
            </div>
            <!-- 数据 -->
            <div class="tz_data">
              <!-- @用户名 -->
              <div class="nick"><?php echo get_userdata($detail->post_author)->nickname ? esc_attr(get_userdata($detail->post_author)->nickname) : '用户' . intval($detail->post_author); ?></div>
              <div class="tzd_bom">
                <div class="time">
                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/time.png', LUNTAN_FILE)); ?>" alt="" />
                  <!-- @发帖时间 -->
                  <span><?php echo esc_attr($detail->post_date); ?></span>
                </div>
                <div class="view">
                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                  <!-- @浏览人数 -->
                  <span><?php echo intval($post_extend); ?></span>
                </div>
              </div>
            </div>
          </div>
          <div class="tzct_right">
            <div class="tag">

              <?php if (is_sticky($id)) { ?>
                <div class="zhiding">
                  置顶
                </div>
              <?php } ?>

              <?php if ($jing) { ?>
                <div class="jing">
                  精
                </div>
              <?php } ?>
            </div>
            <!-- 权限判断 -->
            <?php if (current_user_can('administrator')) { ?>
              <div class="service">
                <span class="dropdown">管理</span>

                <!-- @点击管理后弹出 -->
                <div class="menu-detail">
                  <div class="edit">编辑</div>
                  <div class="top">置顶</div>
                  <div class="untop">取消置顶</div>
                  <div class="hot">精华</div>
                  <div class="unhot">取消精华</div>
                  <div class="cancel">删除</div>
                </div>
              </div>
            <?php } ?>
          </div>
        </div>

        <!-- 帖子内容 -->
        <div class="tzc_con">
          <!-- @帖子标题 -->
          <h1 class="title"><?php echo esc_attr($detail->post_title); ?></h1>
          <!-- @帖子正文 -->
          <p class="content">
            <?php echo wp_kses_post($detail->post_content); ?>
          </p>

          <!-- @帖子图片 -->
          <div class="imgs">
            <?php if (!empty($luntan_img)) {
              foreach ($luntan_img as $k => $v) {
            ?>
                <!-- @图片1 -->
                <img data-watch="1" src="<?php echo esc_url($v); ?>" alt="" />

            <?php }
            } ?>
          </div>
        </div>
        <?php if ($cate_id) { ?>
          <!-- 帖子底部 -->
          <div class="tzc_bom">
            <!-- @文章分类 -->
            <?php $term_cate = get_term($cate_id, 'luntan_cate');
            if ($term_cate) {
            ?>
              <a href="<?php echo esc_url(get_term_link($term_cate)); ?>" class="tag_item"><?php echo esc_attr($term_cate->name); ?></a>
            <?php } ?>
          </div>
        <?php } ?>
      </div>
      <!-- 帖子评论 -->

      <div class="tz_pl_box">
        <!-- 回复以及评论按钮 -->
        <div class="tools">
          <div class="t_left">
            <div class="title">回复</div>
            <div class="border"></div>
            <!-- @回复数量 -->
            <div class="num">共<?php echo count($pl); ?>条回复</div>
          </div>
          <?php if (is_user_logged_in()) { //登录判断 
          ?>
            <div class="t_right">
              <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_white.png', LUNTAN_FILE)); ?>" alt="" />


              <!-- @需要登录判断 -->
              <span>评论</span>
            </div>
          <?php } ?>
        </div>
        <?php if (is_user_logged_in()) { //登录判断 
        ?>
          <!-- 评论输入框 -->
          <div class="pinglun_box">
            <div class="pinglun_input">

              <!-- @文本域 -->
              <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>
            </div>

            <div class="pinglun_c_bom">
              <!-- 照片列表 -->
              <div class="imgBox">

                <!-- @上传图片 -->
                <div class="addImg" data-id="0">
                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />
                </div>

              </div>
              <!-- @需要登录判断 -->
              <div class="submit" data-id="0">发布</div>
            </div>
          </div>
        <?php } ?>


        <!-- 评论列表 -->
        <div class="pinglunlist">
          <?php if ($pl) {
            foreach ($pl as $k => $comment) {
              if ($comment->comment_parent == 0) {
          ?>
                <div class="pinglun_item" data-id="<?php echo intval($comment->comment_ID); ?>">

                  <div class="pi_avatar">
                    <!-- 头像 -->
                    <img src="<?php echo get_user_meta($comment->user_id, 'luntan_avatar', true) ? esc_url(get_user_meta($comment->user_id, 'luntan_avatar', true)) : esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" onerror="this.onerror=null;this.src='<?php echo esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>'" />
                  </div>

                  <div class="pi_data">
                    <div class="pid_top">

                      <!-- @用户名 -->
                      <div class="nick"><?php echo get_userdata($comment->user_id)->nickname ? esc_attr(get_userdata($comment->user_id)->nickname) : '用户' . intval($comment->user_id); ?></div>

                      <div class="pi_action">
                        <!-- @点赞 -->
                        <!-- @需要登录判断 -->
                        <div class="dianzan" data-id="<?php echo intval($comment->comment_ID); ?>">
                          <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M27.6002 18.5998V11.3998C27.6002 8.41743 25.1826 5.99977 22.2002 5.99977L15.0002 22.1998V41.9998H35.9162C37.7113 42.0201 39.2471 40.7147 39.5162 38.9398L42.0002 22.7398C42.1587 21.6955 41.8506 20.6343 41.1576 19.8373C40.4645 19.0403 39.4564 18.5878 38.4002 18.5998H27.6002Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                            <path d="M15 22.0001H10.194C8.08532 21.9628 6.2827 23.7095 6 25.7994V38.3994C6.2827 40.4894 8.08532 42.0367 10.194 41.9994H15V22.0001Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                          </svg>

                          <span><?php echo (int)get_comment_meta($comment->comment_ID, 'luntan_likes_count', true); ?></span>

                        </div>

                        <!-- @点踩 -->
                        <!-- @需要登录判断 -->
                        <div class="cai" data-id="<?php echo intval($comment->comment_ID); ?>">
                          <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M20.3793 29.4002V36.6002C20.3793 39.5826 22.7969 42.0002 25.7793 42.0002L32.9793 25.8002V6.00023H12.0633C10.2682 5.97994 8.73244 7.2853 8.46327 9.06023L5.97927 25.2602C5.82077 26.3045 6.12885 27.3657 6.82192 28.1627C7.51499 28.9597 8.52311 29.4122 9.57927 29.4002H20.3793Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                            <path d="M32.9795 6.00017H37.7855C39.8942 5.96288 41.6968 7.51019 41.9795 9.60017V22.2002C41.6968 24.2901 39.8942 26.0375 37.7855 26.0002H32.9795V6.00017Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                          </svg>
                          <span><?php echo  (int)get_comment_meta($comment->comment_ID, 'luntan_cai_count', true); ?></span>
                        </div>

                        <?php if (is_user_logged_in()) {
                          $current_user = wp_get_current_user();
                          if ($current_user->ID == $comment->user_id) {
                        ?>
                            <!-- @如果是自己评论的，可以删除 -->
                            <div class="delete" data-id="<?php echo intval($comment->comment_ID); ?>">
                              <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/del_red.png', LUNTAN_FILE)); ?>" alt="" />
                              <span>删除</span>
                            </div>
                          <?php } ?>

                          <!-- @需要登录判断 -->
                          <div class="open" data-id="<?php echo intval($comment->comment_ID); ?>">
                            <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_blue.png', LUNTAN_FILE)); ?>" alt="" />
                            <span>评论</span>
                          </div>
                        <?php } ?>
                      </div>
                    </div>
                    <div class="pid_con">

                      <!-- @评论正文 -->
                      <p class="text"><?php echo wp_kses_post($comment->comment_content); ?></p>
                      <?php $img = get_comment_meta($comment->comment_ID, 'luntan_pl_img', true);
                      if ($img) {
                        $img = explode(',', $img);

                      ?>
                        <!-- @评论图片 -->
                        <div class="imgs">
                          <?php foreach ($img as $k => $v) { ?>
                            <img data-watch="1" src="<?php echo esc_url($v); ?>" alt="" />
                          <?php } ?>
                        </div>
                      <?php } ?>
                    </div>

                    <!-- @评论时间 -->
                    <div class="pid_bom"><?php echo esc_attr($comment->comment_date); ?></div>

                    <!-- 评论内容 -->
                    <div class="pid_edit" data-id="<?php echo intval($comment->comment_ID); ?>">
                      <div class="pinglun_input">

                        <!-- @文本域 -->
                        <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>

                      </div>

                      <div class="pinglun_c_bom">
                        <!-- 照片列表 -->
                        <div class="imgBox">

                          <!-- @上传图片 -->
                          <div class="addImg" data-id="<?php echo intval($comment->comment_ID); ?>">
                            <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />

                            <input type="file" name="img" multiple="multiple" accept=".jpg, .png, .webp, .gif, .jpeg" class="el-upload__input">
                          </div>

                        </div>

                        <div class="submit" data-id="<?php echo intval($comment->comment_ID); ?>">发布</div>
                      </div>
                    </div>

                    <!-- 评论的回复 -->
                    <div class="pid_list">
                      <!-- 评论的盒子 -->
                      <?php $child = luntan_post::luntan_get_comment_with_children($comment, $id, []);
                      if (!empty($child)) {
                        foreach ($child as $key => $val) {
                      ?>
                          <div class="pid_item">
                            <div class="pidi_top">
                              <div class="people">
                                <div class="hfr">
                                  <div class="avatar">
                                    <img src="<?php echo $val->avatar ? esc_url($val->avatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                                  </div>

                                  <!-- @回复的人 -->
                                  <div class="nick">
                                    <?php echo esc_attr($val->nickname); ?>
                                  </div>
                                </div>
                                <div class="right_icon">
                                  <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none">
                                    <path d="M4.125 2.70711C4.125 2.26165 4.66357 2.03857 4.97855 2.35355L8.27145 5.64645C8.46671 5.84171 8.46671 6.15829 8.27145 6.35355L4.97855 9.64645C4.66357 9.96143 4.125 9.73835 4.125 9.29289L4.125 2.70711Z" fill="#777777" />
                                  </svg>
                                </div>

                                <div class="bhfr">
                                  <div class="avatar">
                                    <img src="<?php echo $val->cavatar ? esc_url($val->cavatar) : esc_url(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
                                  </div>

                                  <!-- @原评论人 -->
                                  <div class="nick">
                                    <?php echo esc_attr($val->cnickname); ?>
                                  </div>
                                </div>
                              </div>

                              <!-- 回复时间 -->
                              <div class="time"><?php echo esc_attr($val->comment_date); ?></div>
                            </div>
                            <div class="pidi_con">

                              <!-- 回复内容 -->
                              <div class="text"><?php echo nl2br(esc_html($val->comment_content)); ?></div>
                              <?php if ($val->img) { ?>
                                <!-- 回复图片 -->
                                <div class="imgs">
                                  <?php $img = explode(',', $val->img);
                                  if (!empty($img)) {
                                    foreach ($img as $imgs) {
                                  ?>
                                      <img data-watch="1" src="<?php echo esc_url($imgs); ?>" alt="" />
                                  <?php }
                                  } ?>


                                </div>
                              <?php } ?>
                            </div>
                            <div class="pidi_bom">
                              <div class="mb_time"><?php echo esc_attr($val->comment_date); ?></div>

                              <!-- @点赞 -->
                              <!-- @需要登录判断 -->
                              <div class="zan" data-id="<?php echo intval($val->comment_ID); ?>">
                                <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                                  <path d="M27.6002 18.5998V11.3998C27.6002 8.41743 25.1826 5.99977 22.2002 5.99977L15.0002 22.1998V41.9998H35.9162C37.7113 42.0201 39.2471 40.7147 39.5162 38.9398L42.0002 22.7398C42.1587 21.6955 41.8506 20.6343 41.1576 19.8373C40.4645 19.0403 39.4564 18.5878 38.4002 18.5998H27.6002Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                  <path d="M15 22.0001H10.194C8.08532 21.9628 6.2827 23.7095 6 25.7994V38.3994C6.2827 40.4894 8.08532 42.0367 10.194 41.9994H15V22.0001Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                </svg>
                                <span><?php echo (int)$val->likes; ?></span>
                              </div>

                              <!-- @点踩 -->
                              <!-- @需要登录判断 -->
                              <div class="cai" data-id="<?php echo intval($val->comment_ID); ?>">
                                <svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                                  <path d="M20.3793 29.4002V36.6002C20.3793 39.5826 22.7969 42.0002 25.7793 42.0002L32.9793 25.8002V6.00023H12.0633C10.2682 5.97994 8.73244 7.2853 8.46327 9.06023L5.97927 25.2602C5.82077 26.3045 6.12885 27.3657 6.82192 28.1627C7.51499 28.9597 8.52311 29.4122 9.57927 29.4002H20.3793Z" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                  <path d="M32.9795 6.00017H37.7855C39.8942 5.96288 41.6968 7.51019 41.9795 9.60017V22.2002C41.6968 24.2901 39.8942 26.0375 37.7855 26.0002H32.9795V6.00017Z" fill="none" stroke="#666" stroke-width="4" stroke-linejoin="round" />
                                </svg>
                                <span><?php echo (int)$val->cai; ?></span>
                              </div>


                              <?php if (is_user_logged_in()) {
                                $current_user = wp_get_current_user();
                                if ($current_user->ID == $val->user_id) {
                              ?>
                                  <!-- 只有是自己回复的才能删除 -->
                                  <div class="delete" data-id="<?php echo intval($val->comment_ID); ?>">
                                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/del_red.png', LUNTAN_FILE)); ?>" alt="" />
                                    <span>删除</span>
                                  </div>
                                <?php } ?>

                                <div class="pinglun" data-id="<?php echo intval($val->comment_ID); ?>">
                                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark_blue.png', LUNTAN_FILE)); ?>" alt="" />
                                  <span>评论</span>
                                </div>
                              <?php } ?>
                            </div>

                            <!-- 点击评论后出现 -->
                            <div class="pidi_pinglun" data-id="<?php echo intval($val->comment_ID); ?>">

                              <div class="pinglun_input">

                                <!-- @文本域 -->
                                <textarea autocomplete="off" rows="4" placeholder="请输入评论内容" class="el-textarea__inner" style="min-height: 43px;border: none;resize: vertical;outline: none;"></textarea>

                              </div>

                              <div class="pinglun_c_bom">

                                <!-- 照片列表 -->
                                <div class="imgBox">

                                  <!-- @上传图片 -->
                                  <div class="addImg" data-id="<?php echo intval($val->comment_ID); ?>">
                                    <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/addImg.png', LUNTAN_FILE)); ?>" alt="" />
                                    <input type="file" name="img" multiple="multiple" accept=".jpg, .png, .webp, .gif, .jpeg" class="el-upload__input">
                                  </div>

                                </div>

                                <div class="submit" data-id="<?php echo intval($val->comment_ID); ?>">发布</div>
                              </div>
                            </div>
                          </div>
                      <?php }
                      } ?>
                    </div>
                  </div>
                </div>
          <?php }
            }
          } ?>
        </div>
      </div>
    </div>

    <!-- 右 -->
    <div class="fb_right">
      <!-- 个人信息栏 -->
      <div class="fbr_userInfo">
        <?php if (is_user_logged_in()) {
          $current_user = wp_get_current_user();
          //"您已登录！";
        ?>
          <div class="fbr_u_top">
            <div class="fbr_u_t_left">
              <div class="fbr_u_t_l_avatar">

                <!-- 默认头像 -->
                <img src="<?php echo  get_user_meta($current_user->ID, 'luntan_avatar', true) ? esc_attr(get_user_meta($current_user->ID, 'luntan_avatar', true)) : esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
              </div>
              <div class="fbr_u_t_l_info">
                <!-- 已经登录 -->
                <div class="fbr_u_t_l_i_nick"><?php if (isset($current_user->nickname)) {
                                                echo esc_attr($current_user->nickname);
                                              } ?></div>

                <!-- 已经登录 -->
                <div class="fbr_u_t_l_i_id">ID：<?php if (isset($current_user->ID)) {
                                                  echo intval($current_user->ID);
                                                } ?></div>
              </div>
            </div>
            <!-- 已经登录 -->
            <div class="fbr_u_t_right">
              <?php $pub_num = count(get_posts(array(
                'author' => $current_user->ID,
                'numberposts' => -1, // 获取所有符合条件的文章，-1表示无限制数量
                'post_type' => 'luntan',
              )));
              ?>
              <div class="fbr_u_t_r_num"><?php echo (int)$pub_num; ?></div>
              <div class="fbr_u_t_r_text">帖子</div>
            </div>
          </div>
          <div class="fbr_u_bom">

            <!-- 已经登录 -->
            <div class="fbr_u_true">
              <div class="fbr_u_b_t_left">
                <a href="/<?php echo esc_attr($luntan_url_zx); ?>">
                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/user.png', LUNTAN_FILE)); ?>" alt="" />
                  <span>个人中心</span>
                </a>
              </div>
              <div class="fbr_u_b_t_right">
                <a href="<?php echo esc_url(wp_logout_url()); ?>">
                  <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/goout.png', LUNTAN_FILE)); ?>" alt="" />
                  <span>退出登录</span>
                </a>
              </div>
            </div>

          </div>

        <?php } else { ?>
          <?php // "您未登录，请先登录。";
          ?>
          <div class="fbr_u_top">
            <div class="fbr_u_t_left">
              <div class="fbr_u_t_l_avatar">

                <!-- 默认头像 -->
                <img src="<?php echo  esc_attr(plugins_url('inc/index/assets/img/avatar_default.png', LUNTAN_FILE)); ?>" alt="" />
              </div>
              <div class="fbr_u_t_l_info">

                <!-- 未登录 -->
                <div class="fbr_u_t_l_i_nick">请先登录</div>
                <!-- 已经登录 -->

              </div>
            </div>

          </div>
          <div class="fbr_u_bom">
            <!-- 未登录 -->
            <a href="<?php echo esc_url(wp_login_url()); ?>" class="fbr_u_false">
              <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/user.png', LUNTAN_FILE)); ?>" alt="" />
              <span>请先登录</span>
            </a>
          </div>

        <?php } ?>

      </div>

      <!-- 搜索 -->
      <div class="fbr_search">
        <form action="/<?php echo esc_attr($luntan_url); ?>" method="get">
          <input type="text" type="text" class="el-input__inner" placeholder="请输入搜索内容" style="padding: 0 10px 0 25px  !important; border: 1px solid #DCDFE6 !important;" name="s">
          <button class="el-button" style="background-color: #2281ff !important;">
            搜索
          </button>
          <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/search.png', LUNTAN_FILE)); ?>" alt="" />
        </form>
      </div>

      <!-- 热门 -->
      <div class="fbr_hot">
        <!-- 热门标题 -->
        <div class="h_tit">热门帖子22</div>
        <!-- 热门帖子列表 -->
        <div class="h_list">
          <!-- 热门帖子盒子 -->
          <?php if (!empty($hot)) {
            foreach ($hot as $k => $v) {
          ?>
              <div class="h_item">
                <?php
                // 定义对应关系
                $xuhao_classes = ['one', 'two', 'three', 'four', 'five'];
                // 根据索引循环取对应的类
                $xuhao_class = $xuhao_classes[$k % 5];
                ?>
                <a href="<?php if (isset($v->ID)) {
                            the_permalink($v->ID);
                          } ?>">
                  <!-- 头部 -->
                  <div class="hi_top">
                    <div class="xuhao <?php echo esc_attr($xuhao_class); ?>">
                      <?php echo (int)$k + 1; ?>
                    </div>
                    <div class="title"><?php echo esc_attr($v->post_title); ?></div>
                  </div>
                  <!-- 底部 -->
                  <div class="hi_bom">
                    <!-- 相关数据 -->
                    <div class="hb_left">
                      <!-- 浏览 -->
                      <div class="view">
                        <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                        <div class="num"><?php echo get_post_meta($v->ID, 'luntan_views', true) ? (int)get_post_meta($v->ID, 'luntan_views', true) : 0; ?></div>
                      </div>
                      <!-- 评论 -->
                      <div class="pinglun">
                        <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark.png', LUNTAN_FILE)); ?>" alt="" />
                        <div class="num"><?php echo get_post_meta($v->ID, 'luntan_replay_num', true) ? (int)get_post_meta($v->ID, 'luntan_replay_num', true) : 0; ?></div>
                      </div>
                    </div>
                    <!-- 时间 -->
                    <div class="time">
                      <?php if (isset($v->post_date)) {
                        echo esc_html($v->post_date);
                      } ?>
                    </div>
                  </div>
                  <!-- 边框线条 -->
                  <div class="hi_border"></div>
                </a>

              </div>
          <?php }
          } ?>
        </div>
      </div>

      <!-- 最新 -->
      <div class="fbr_new">
        <!-- 最新标题 -->
        <div class="n_tit">最新回复</div>
        <!-- 热门帖子列表 -->
        <div class="n_list">
          <!-- 热门帖子盒子 -->
          <?php if (!empty($news)) {
            foreach ($news as $k => $v) {
          ?>
              <div class="n_item">
                <?php
                // 定义对应关系
                $xuhao_classes = ['one', 'two', 'three', 'four', 'five'];
                // 根据索引循环取对应的类
                $xuhao_class = $xuhao_classes[$k % 5];
                ?>

                <a href="<?php if (isset($v->ID)) {
                            the_permalink($v->ID);
                          } ?>">
                  <!-- 头部 -->
                  <div class="ni_top">
                    <div class="xuhao <?php echo esc_attr($xuhao_class); ?>">
                      <?php echo (int)$k + 1; ?>
                    </div>
                    <div class="title"><?php echo esc_attr($v->post_title); ?></div>
                  </div>
                  <!-- 底部 -->
                  <div class="ni_bom">
                    <!-- 相关数据 -->
                    <div class="nb_left">
                      <!-- 浏览 -->
                      <div class="view">
                        <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/view.png', LUNTAN_FILE)); ?>" alt="" />
                        <div class="num"><?php echo get_post_meta($v->ID, 'luntan_views', true) ? (int)get_post_meta($v->ID, 'luntan_views', true) : 0; ?></div>
                      </div>
                      <!-- 评论 -->
                      <div class="pinglun">
                        <img src="<?php echo esc_attr(plugins_url('inc/index/assets/img/remark.png', LUNTAN_FILE)); ?>" alt="" />
                        <div class="num"><?php echo get_post_meta($v->ID, 'luntan_replay_num', true) ? (int)get_post_meta($v->ID, 'luntan_replay_num', true) : 0; ?></div>
                      </div>
                    </div>
                    <!-- 时间 -->
                    <div class="time"><?php if (isset($v->post_date)) {
                                        echo esc_attr($v->post_date);
                                      } ?></div>
                  </div>
                  <!-- 边框线条 -->
                  <div class="ni_border"></div>
                </a>
              </div>
          <?php }
          } ?>
        </div>
      </div>

      <!-- 其他 -->
      <div class="fbr_other">
        <div class="o_tit">其他板块</div>


        <div class="o_type">
          <?php if (!empty($categories)) {
            foreach ($categories as $k => $v) {
              $term = get_term($v->term_id, 'luntan_cate');
          ?>
              <a href="<?php echo esc_url(get_term_link($v->term_id)); ?>" data-id="<?php echo intval($v->term_id); ?>">
                <div class="ot_item" class="ot_item ot_item_act">
                  <?php echo esc_attr($v->name); ?>
                </div>
              </a>
          <?php }
          } ?>
        </div>

      </div>
    </div>

    <!-- 弹窗 -->


    <!-- 编辑帖子弹出框 -->
    <div class="fbDialogBox">
      <div class="dialog-header">
        <span>编辑帖子</span>
        <div class="close-btn">&times;</div>
      </div>

      <div class="dialog-body">
        <div class="form-item">
          <div class="bold_text">标题</div>
          <input type="text" class="title_input" placeholder="请输入标题" style="padding: 10px  !important; border: 1px solid #DCDFE6 !important;" value="<?php echo esc_attr($detail->post_title); ?>">
        </div>
        <div class="form-item">
          <div class="bold_text">内容</div>
          <textarea class="content_input" placeholder="请输入内容" id="mo_fbContent"></textarea>
        </div>

        <div class="form-item">
          <div class="bold_text">添加照片</div>
          <div class="imgBox">

            <?php if (!empty($luntan_img)) {
              foreach ($luntan_img as $k => $v) {
            ?>
                <div class="uploaded-img">
                  <img src="<?php echo esc_url($v); ?>" alt="">
                  <div class="remove-img">×</div>
                </div>
            <?php }
            } ?>


            <div class="addImg-btn">
              <img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxsaW5lIHgxPSIxMiIgeTE9IjUiIHgyPSIxMiIgeTI9IjE5Ij48L2xpbmU+PGxpbmUgeDE9IjUiIHkxPSIxMiIgeDI9IjE5IiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=" alt="添加图片">
            </div>
          </div>
        </div>

        <div class="form-item">
          <div class="bold_text">板块分类</div>
          <div class="typeTab">
            <?php if (!empty($categories)) {
              foreach ($categories as $k => $v) {
            ?>
                <div class="typeTab_item" data-id="<?php echo intval($v->term_id); ?>"><?php echo esc_attr($v->name); ?></div>

            <?php }
            } ?>
          </div>
        </div>


      </div>

      <div class="dialog-footer">
        <button class="btn btn-cancel">取 消</button>
        <button class="btn btn-primary">确 定</button>
      </div>
    </div>

    <div class="preview-dialog">
      <span class="preview-close">&times;</span>
      <img class="preview-img" src="" alt="图片预览">
    </div>

    <!-- 2025/2/24 更改登录注册弹窗 -->
    <div class="login_Dialog" style="display: none;">
      <div class="el-dialog">
        <span class="new_l_tit">欢迎使用论坛！</span>
        <span class="new_l_tip">提示：部分邮箱收不到注册邮件，请注册后通过忘记密码重置账号密码</span>
        <div class="new_l_top">
          <div class="l_t_item new_l_top_login">
            点我登录
          </div>
          <div class="l_t_item new_l_top_register">
            点我注册
          </div>
        </div>
      </div>
    </div>

  </div>

<?php
  get_footer();
}
?>