Files
hantico/wp-content/themes/hantico/single-article.php
T

192 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php get_header(); ?>
<main class="main">
<?php
$post_id = get_the_ID();
$views = (int) get_field('viewers', $post_id);
if (!current_user_can('manage_options')) {
$views++;
update_field('viewers', $views, $post_id);
}
$parent_id = is_singular('news') ? 82 : 42;
$terms = get_the_terms(get_the_ID(), 'article_category');
$article_blocks = get_field('new_blocks') ?: [];
$article_content = get_field('article_content') ?: '';
$reading_parts = [$article_content];
foreach ($article_blocks as $block) {
$layout = $block['acf_fc_layout'] ?? '';
if ($layout === 'text') {
$reading_parts[] = $block['content'] ?? '';
} elseif (in_array($layout, ['attention_block', 'attention_blocks', 'quote'], true)) {
$reading_parts[] = $block['text'] ?? '';
} elseif ($layout === 'block_main') {
foreach (($block['cards'] ?? []) as $card) {
$reading_parts[] = $card['text_card'] ?? '';
}
}
}
// Разделяем HTML-элементы пробелами, чтобы соседние абзацы не склеивались.
$reading_text = strip_shortcodes(implode(' ', $reading_parts));
$reading_text = preg_replace('@<(script|style)\b[^>]*>.*?</\1>@si', ' ', $reading_text);
$reading_text = preg_replace('/<[^>]*>/', ' ', $reading_text);
$reading_text = html_entity_decode(wp_strip_all_tags($reading_text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
$word_count = preg_match_all("/[\p{L}\p{N}]+(?:[’'\x{002D}][\p{L}\p{N}]+)*/u", $reading_text);
$reading_minutes = $word_count ? max(1, (int) ceil($word_count / 200)) : 0;
$generated = generate_toc($article_content, 'article-content');
$content = $generated['content'];
$toc_items = $generated['toc_items'];
$footer_socials = get_field('socials', 'option');
foreach ($article_blocks as $block_index => &$block) {
if (($block['acf_fc_layout'] ?? '') !== 'text') {
continue;
}
$generated = generate_toc($block['content'] ?? '', 'article-block-' . ($block_index + 1));
$block['content'] = $generated['content'];
$toc_items = array_merge($toc_items, $generated['toc_items']);
}
unset($block);
if ($article_content || $article_blocks) :
?>
<section class="article">
<div class="container">
<div class="article-intro__breadcrumb">
<?php get_breadcrumbs(); ?>
</div>
<article class="article-intro" aria-labelledby="article-title">
<div class="article-intro__topline">
<span class="article-intro__author" id="article-author"><svg class="article-intro__icon" width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="5.5" r="3.5" fill="currentColor"/><path d="M3 17v-2a7 7 0 0 1 14 0v2H3Z" fill="currentColor"/></svg> <?php echo esc_html(get_the_author_meta('display_name', (int) get_post_field('post_author', $post_id))); ?></span>
<div class="article-intro__stats" aria-label="Статистика статьи">
<span class="article-intro__stat" aria-label="Просмотры"><svg class="article-intro__icon" width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><path d="M1.5 10s3-6 8.5-6 8.5 6 8.5 6-3 6-8.5 6-8.5-6-8.5-6Z" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="10" cy="10" r="2.8" fill="currentColor"/></svg> <?php echo esc_html(number_format_i18n($views)); ?></span>
</div>
</div>
<div class="article-intro__hero">
<?php the_post_thumbnail('extra_large', ['class' => 'article-intro__image', 'fetchpriority' => 'high', 'loading' => 'eager']); ?>
<div class="article-intro__heading">
<?php get_breadcrumbs(); ?>
<?php if ($terms && !is_wp_error($terms)) : ?>
<ul class="article-intro__tags" aria-label="Темы статьи">
<?php foreach ($terms as $term) : ?>
<li><?php echo esc_html($term->name); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<h1 class="article-intro__title" id="article-title"><?php the_title(); ?></h1>
<div class="article-intro__meta">
<span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none"> <path d="M6.34369 2.31299C6.34369 2.18867 6.29431 2.06944 6.2064 1.98153C6.11849 1.89362 5.99926 1.84424 5.87494 1.84424C5.75062 1.84424 5.63139 1.89362 5.54349 1.98153C5.45558 2.06944 5.40619 2.18867 5.40619 2.31299V3.30049C4.50619 3.37236 3.91619 3.54861 3.48244 3.98299C3.04807 4.41674 2.87182 5.00736 2.79932 5.90674H15.2006C15.1281 5.00674 14.9518 4.41674 14.5174 3.98299C14.0837 3.54861 13.4931 3.37236 12.5937 3.29986V2.31299C12.5937 2.18867 12.5443 2.06944 12.4564 1.98153C12.3685 1.89362 12.2493 1.84424 12.1249 1.84424C12.0006 1.84424 11.8814 1.89362 11.7935 1.98153C11.7056 2.06944 11.6562 2.18867 11.6562 2.31299V3.25861C11.2406 3.25049 10.7743 3.25049 10.2499 3.25049H7.74994C7.22557 3.25049 6.75932 3.25049 6.34369 3.25861V2.31299Z" fill="#DADBDF"/> <path d="M2.75006 8.25C2.75006 7.72563 2.75006 7.25938 2.75819 6.84375H15.2419C15.2501 7.25938 15.2501 7.72563 15.2501 8.25V9.5C15.2501 11.8569 15.2501 13.0356 14.5176 13.7675C13.7851 14.4994 12.6069 14.5 10.2501 14.5H7.75006C5.39319 14.5 4.21444 14.5 3.48256 13.7675C2.75069 13.035 2.75006 11.8569 2.75006 9.5V8.25ZM12.1251 9.5C12.2908 9.5 12.4498 9.43415 12.567 9.31694C12.6842 9.19973 12.7501 9.04076 12.7501 8.875C12.7501 8.70924 12.6842 8.55027 12.567 8.43306C12.4498 8.31585 12.2908 8.25 12.1251 8.25C11.9593 8.25 11.8003 8.31585 11.6831 8.43306C11.5659 8.55027 11.5001 8.70924 11.5001 8.875C11.5001 9.04076 11.5659 9.19973 11.6831 9.31694C11.8003 9.43415 11.9593 9.5 12.1251 9.5ZM12.1251 12C12.2908 12 12.4498 11.9342 12.567 11.8169C12.6842 11.6997 12.7501 11.5408 12.7501 11.375C12.7501 11.2092 12.6842 11.0503 12.567 10.9331C12.4498 10.8158 12.2908 10.75 12.1251 10.75C11.9593 10.75 11.8003 10.8158 11.6831 10.9331C11.5659 11.0503 11.5001 11.2092 11.5001 11.375C11.5001 11.5408 11.5659 11.6997 11.6831 11.8169C11.8003 11.9342 11.9593 12 12.1251 12ZM9.62506 8.875C9.62506 9.04076 9.55921 9.19973 9.442 9.31694C9.32479 9.43415 9.16582 9.5 9.00006 9.5C8.8343 9.5 8.67533 9.43415 8.55812 9.31694C8.44091 9.19973 8.37506 9.04076 8.37506 8.875C8.37506 8.70924 8.44091 8.55027 8.55812 8.43306C8.67533 8.31585 8.8343 8.25 9.00006 8.25C9.16582 8.25 9.32479 8.31585 9.442 8.43306C9.55921 8.55027 9.62506 8.70924 9.62506 8.875ZM9.62506 11.375C9.62506 11.5408 9.55921 11.6997 9.442 11.8169C9.32479 11.9342 9.16582 12 9.00006 12C8.8343 12 8.67533 11.9342 8.55812 11.8169C8.44091 11.6997 8.37506 11.5408 8.37506 11.375C8.37506 11.2092 8.44091 11.0503 8.55812 10.9331C8.67533 10.8158 8.8343 10.75 9.00006 10.75C9.16582 10.75 9.32479 10.8158 9.442 10.9331C9.55921 11.0503 9.62506 11.2092 9.62506 11.375ZM5.87506 9.5C6.04082 9.5 6.19979 9.43415 6.317 9.31694C6.43421 9.19973 6.50006 9.04076 6.50006 8.875C6.50006 8.70924 6.43421 8.55027 6.317 8.43306C6.19979 8.31585 6.04082 8.25 5.87506 8.25C5.7093 8.25 5.55033 8.31585 5.43312 8.43306C5.31591 8.55027 5.25006 8.70924 5.25006 8.875C5.25006 9.04076 5.31591 9.19973 5.43312 9.31694C5.55033 9.43415 5.7093 9.5 5.87506 9.5ZM5.87506 12C6.04082 12 6.19979 11.9342 6.317 11.8169C6.43421 11.6997 6.50006 11.5408 6.50006 11.375C6.50006 11.2092 6.43421 11.0503 6.317 10.9331C6.19979 10.8158 6.04082 10.75 5.87506 10.75C5.7093 10.75 5.55033 10.8158 5.43312 10.9331C5.31591 11.0503 5.25006 11.2092 5.25006 11.375C5.25006 11.5408 5.31591 11.6997 5.43312 11.8169C5.55033 11.9342 5.7093 12 5.87506 12Z" fill-rule="evenodd" clip-rule="evenodd" fill="#DADBDF"/> </svg> <time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('d.m.Y')); ?></time></span>
<?php if ($reading_minutes) : ?>
<span><svg class="article-intro__icon" width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="8.5" fill="currentColor"/><path d="M10 5v5l2.5 2" fill="none" stroke="#f6f6f6" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg> Время чтения <?php echo esc_html($reading_minutes); ?> мин</span>
<?php endif; ?>
</div>
</div>
</div>
<?php $brief_description = get_field('brief_description'); ?>
<?php if ($brief_description) : ?>
<section class="article-intro__summary" aria-labelledby="summary-title">
<h2 id="summary-title">Кратко</h2>
<p><?php echo nl2br(esc_html($brief_description)); ?></p>
</section>
<?php endif; ?>
<footer class="article-intro__credit">Материал подготовлен <a href="/about/">редакцией Hantico</a></footer>
</article>
<div class="article-body<?php if (!$toc_items) echo ' no-toc'; ?>">
<div class="article-main">
<?php if ($content) : ?>
<div class="article-content content"><?php echo wrap_tables($content); ?></div>
<?php endif; ?>
<?php
if ($article_blocks) {
foreach ($article_blocks as $block) {
$layout = $block['acf_fc_layout'] ?? '';
if ($layout === 'attention_block') {
$layout = 'attention_blocks';
}
$allowedLayouts = [
'attention_block',
'attention_blocks',
'text',
'block_main',
'quote',
'cta_1',
'cta_2',
'plaque_authorship',
];
if (in_array($layout, $allowedLayouts, true)) {
get_template_part(
'template-parts/article-blocks/' . $layout,
null,
[
'fields' => $block,
]
);
}
}
}
?>
</div>
<div class="article-sidebar">
<?php if ($toc_items) : ?>
<div class="article-toc">
<div class="article-toc__title">Содержание</div>
<ul class="article-toc__list is-scrollable">
<?php foreach ($toc_items as $item) : ?>
<li class="article-toc__item">
<a href="#<?php echo $item['id']; ?>" class="article-toc__link">
<?php echo $item['title']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="article-social">
<p class="article-social__title">
Работайте <span>проще</span> <br>и зарабатывайте <span>больше!</span>
</p>
<p class="article-social__text">
Лайфхаки, полезные инструкции, изменения в правилах и важные новости для водителей и курьеров — в каналах Hantico.
</p>
<div class="article-social__list">
<span>
Подписаться
</span>
<a href="<?php echo $footer_socials['vk']; ?>" target="_blank" rel="noopener">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" fill="none">
<rect width="40" height="40" rx="12" fill="white"/>
<path d="M12.9336 12.933C11.8184 14.0588 11.8184 15.859 11.8184 19.4646V20.1019C11.8184 23.7022 11.8184 25.5024 12.9336 26.6335C14.0593 27.7486 15.8595 27.7486 19.4652 27.7486H20.1024C23.7027 27.7486 25.5029 27.7486 26.634 26.6335C27.7491 25.5077 27.7491 23.7075 27.7491 20.1019V19.4646C27.7491 15.8643 27.7491 14.0641 26.634 12.933C25.5082 11.8179 23.708 11.8179 20.1024 11.8179H19.4652C15.8648 11.8179 14.0646 11.8179 12.9336 12.933ZM14.5054 16.6661H16.3321C16.3905 19.7036 17.7287 20.9887 18.7908 21.2542V16.6661H20.506V19.2841C21.5521 19.1726 22.6566 17.9778 23.0283 16.6608H24.7382C24.5987 17.3425 24.3202 17.9881 23.92 18.5573C23.5198 19.1265 23.0066 19.6071 22.4124 19.9691C23.0756 20.2991 23.6614 20.766 24.131 21.339C24.6005 21.912 24.9433 22.5781 25.1365 23.2933H23.2514C22.8478 22.0348 21.8388 21.0577 20.506 20.9249V23.2933H20.2936C16.6614 23.2933 14.5904 20.8081 14.5054 16.6661Z" fill="#215CFE"/>
</svg>
</a>
<a href="<?php echo $footer_socials['telegram']; ?>" target="_blank" rel="noopener">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" fill="none">
<rect width="40" height="40" rx="12" fill="white"/>
<path d="M11.3057 19.5545L15.4477 20.8499L25.2824 15.3131C25.4252 15.2331 25.5712 15.4114 25.4484 15.5157L18.003 21.8266L17.7265 25.3597C17.7219 25.4188 17.7371 25.4779 17.7698 25.529C17.8026 25.5801 17.8514 25.6208 17.9099 25.6457C17.9684 25.6706 18.0337 25.6786 18.0972 25.6686C18.1607 25.6585 18.2193 25.6309 18.2654 25.5895L20.5577 23.5135L24.7486 26.4347C25.2001 26.7498 25.8542 26.5277 25.9758 26.0183L28.8938 13.8169C29.0604 13.121 28.3195 12.5334 27.5972 12.7881L11.2851 18.5405C10.7731 18.7212 10.7873 19.3923 11.3057 19.5545Z" fill="#3292DD"/>
</svg>
</a>
</div>
</div>
</div>
</div>
</div>
</section>
<?php endif; ?>
<?php get_template_part('template-parts/faq'); ?>
<?php get_template_part('template-parts/app-steps'); ?>
<?php get_template_part('template-parts/related'); ?>
<?php get_template_part('template-parts/socials'); ?>
<?php get_template_part('template-parts/getapp'); ?>
</main>
<?php get_footer(); ?>