<?php namespace core_next;
global $core_next_set;
?>
<div class="post-warp">
    <div class="crumbs-warp">
        <?php
        $crumbs_list = WordPress::getCrumbsList();
        $target = '_self';
        if ($core_next_set['post_list_url_new_window'] === true) {
            $target = '_blank';
        }
        $is_first = true;
        foreach ($crumbs_list as $item) {
            if ($is_first) {
                $html = '<div><i class="czs-home"></i> <a target="' . $target . '" href="' . $item['url'] . '">' . $item['name'] . '</a></div>';
            } else {
                $html = '<div><a target="' . $target . '" href="' . $item['url'] . '">' . $item['name'] . '</a></div>';
            }
            $is_first = false;
            print_r($html);
        }
        ?>
    </div>
    <div class="title-warp">
        <h1 class="post-title"><?php the_title() ?></h1>
    </div>
    <?php
    $post_info = [];
    $post_info['author'] = WordPress::getUserDisplayName();
    $user_id = get_post_field('post_author', get_the_ID());
    $post_info['author_url'] = get_author_posts_url($user_id);
    $post_info['time'] = get_the_time('Y-n-j');
    $post_info['cat_html'] = '<div><i class="czs-folder-l"></i> ';
    $category = get_the_category();
    $post_id = get_the_ID();
    if (!empty($category)) {
        $i = 0;
        foreach ($category as $cat) {
            $i++;
            if ($i <= 2) {
                $cat_link = get_category_link($cat->term_id);
                $cat_name = $cat->name;
                $post_info['cat_html'] .= '<a href="' . $cat_link . '">' . $cat_name . '</a> ';
            }
        }
    }
    $post_info['cat_html'] .= '</div>';
    if (current_user_can('edit_post', $post_id)) {
        $edit_post_link = get_edit_post_link($post_id);
        $post_info['edit_url'] = '<div><i class="czs-pen-write"></i> <a href="' . $edit_post_link . '">编辑</a></div>';
    } else {
        $post_info['edit_url'] = '';
    }
    echo Template::getTemplateHtml('post-info-warp', $post_info);

    ?>
    <div class="content-warp<?php if ($core_next_set['read_more_content']) {
        echo ' read-more-content';
    } ?>">
        <?php do_action('core_next_ad', 'post2', 10, 10); ?>
        <?php
        the_content();
        if ($core_next_set['read_more_content']) {
            echo '<div class="load-all-content-warp"><div class="load-all-content-btn">阅读剩余</div></div>';
        }
        if (is_child_theme()) {
            if (file_exists(Config::$child_theme_path . "/template/single.php")) {
                require_once Config::$child_theme_path . "/template/single.php";
            }
        }
        ?>
        <?php do_action('core_next_ad', 'post3', 10, 10); ?>
    </div>
    <?php
    if ($core_next_set['single_copyright_open'] === true) {
        $user_id = get_post_field('post_author', get_the_ID());
        $user = get_user_by('ID', $user_id);
        $display_name = $user->display_name;
        $default_copyright = '<div>版权声明：</div>';
        $default_copyright .= "<div>作者：$display_name</div>";
        $default_copyright .= "<div>链接：" . get_permalink() . "</div>";
        $default_copyright .= "<div>文章版权归作者所有，未经允许请勿转载。</div>";
        $copyright = $default_copyright;
        if ($core_next_set['single_copyright_custom']) {
            $copyright = $core_next_set['single_copyright_text'];
        }
        ?>
        <div class="single-copyright">
            <?php echo Theme::parseCopyrightStr($copyright); ?>
        </div>
        <?php
    }
    ?>
    <div class="post-end-dividing">
        THE END
    </div>
    <?php get_template_part('template/module/post-tag-list'); ?>
    <app-single-btns id="app-single-btns"></app-single-btns>
    <?php
    if ($core_next_set['open_post_page_card']) {
        ?>
        <div class="post-page-card">
            <?php
            $next_post = get_adjacent_post(false, '', false);
            $previous_post = get_adjacent_post(false, '', true);
            if ($previous_post != null) {
                $data['title'] = $previous_post->post_title;
                $data['url'] = get_permalink($previous_post->ID);
                $data['thumbnail'] = WordPress::getThumbnail($previous_post);
                $data['name'] = '<<上一篇';
                $data['hide_class'] = '';
            } else {
                $data['title'] = '';
                $data['url'] = '';
                $data['name'] = '';
                $data['thumbnail'] = '';
                $data['hide_class'] = 'hide';
            }
            echo Template::getTemplateHtml('post-page-card', $data);
            if ($next_post != null) {
                $data['title'] = $next_post->post_title;
                $data['url'] = get_permalink($next_post->ID);
                $data['thumbnail'] = WordPress::getThumbnail($next_post);
                $data['name'] = '下一篇>>';
                $data['hide_class'] = '';
            } else {
                $data['title'] = '';
                $data['url'] = '';
                $data['name'] = '';
                $data['thumbnail'] = '';
                $data['hide_class'] = 'hide';
            }
            echo Template::getTemplateHtml('post-page-card', $data);
            ?>
        </div>
        <?php
    }
    ?>
</div>
