212 lines
9.7 KiB
PHP
212 lines
9.7 KiB
PHP
<?php get_header(); ?>
|
||
|
||
<main class="main">
|
||
|
||
<?php get_breadcrumbs(); ?>
|
||
|
||
<?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-goback">
|
||
<a href="<?php echo get_permalink($parent_id); ?>" class="article-goback__btn">Назад</a>
|
||
</div>
|
||
|
||
<div class="h-article-hero" aria-labelledby="h-article-hero-title">
|
||
<div class="h-article-hero__container">
|
||
<div class="h-article-hero__picture">
|
||
<?php the_post_thumbnail('extra_large', array('class' => 'h-article-hero__image')); ?>
|
||
</div>
|
||
|
||
<div class="h-article-hero__content">
|
||
<?php if ($terms && !is_wp_error($terms)) : ?>
|
||
<div class="h-article-hero__categories">
|
||
<?php foreach ($terms as $term) : ?>
|
||
<span class="h-article-hero__category"><?php echo esc_html($term->name); ?></span>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<h1 class="h-article-hero__title" id="h-article-hero-title">
|
||
<?php the_title(); ?>
|
||
</h1>
|
||
|
||
<?php $brief_description = get_field('brief_description'); ?>
|
||
<?php if ($brief_description) : ?>
|
||
<p class="h-article-hero__description"><?php echo nl2br(esc_html($brief_description)); ?></p>
|
||
<?php endif; ?>
|
||
|
||
<div class="h-article-hero__meta" aria-label="Информация о статье">
|
||
<div class="h-article-hero__meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<rect x="3" y="5" width="18" height="16" rx="2"></rect>
|
||
<path d="M7 3v4M17 3v4M3 10h18"></path>
|
||
</svg>
|
||
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('d.m.Y')); ?></time>
|
||
</div>
|
||
|
||
<?php if ($reading_minutes) : ?>
|
||
<div class="h-article-hero__meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<circle cx="12" cy="13" r="9"></circle>
|
||
<path d="M12 8v5l3 2M9 2h6"></path>
|
||
</svg>
|
||
<span>Время чтения: <strong>≈ <?php echo esc_html($reading_minutes); ?> мин</strong></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="h-article-hero__meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<path d="M2.2 12s3.7-6 9.8-6 9.8 6 9.8 6-3.7 6-9.8 6-9.8-6-9.8-6Z"></path>
|
||
<circle cx="12" cy="12" r="2.8"></circle>
|
||
</svg>
|
||
<span>Просмотры: <strong><?php echo esc_html(number_format_i18n($views)); ?></strong></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<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">
|
||
<?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(); ?>
|