GLOBAL
This commit is contained in:
parent
dbe600783c
commit
82b5cd0d49
@ -31,6 +31,7 @@ function dekart_normalize_jsonld(string $html): string
|
||||
return $m[0];
|
||||
}
|
||||
dekart_normalize_jsonld_node($json, $type);
|
||||
dekart_dedupe_jsonld_graph($json);
|
||||
|
||||
return $m[1] . wp_json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG) . $m[3];
|
||||
},
|
||||
@ -125,6 +126,45 @@ function dekart_jsonld_inject_fallback(string $out, string $type): string
|
||||
return $out . $script;
|
||||
}
|
||||
|
||||
// один узел на тип и id: дубли и узлы без id рядом с id-версией убираем
|
||||
function dekart_dedupe_jsonld_graph(array &$data): void
|
||||
{
|
||||
if (! isset($data['@graph']) || ! is_array($data['@graph'])) {
|
||||
return;
|
||||
}
|
||||
$nodes = array();
|
||||
$keyed = array();
|
||||
$typed = array();
|
||||
foreach ($data['@graph'] as $node) {
|
||||
if (! is_array($node)) {
|
||||
continue;
|
||||
}
|
||||
$type = $node['@type'] ?? '';
|
||||
$type = is_array($type) ? implode('+', $type) : (string) $type;
|
||||
$id = isset($node['@id']) && is_string($node['@id']) ? $node['@id'] : '';
|
||||
if ('' !== $id) {
|
||||
$key = $type . '|' . $id;
|
||||
if (isset($keyed[ $key ])) {
|
||||
continue;
|
||||
}
|
||||
$keyed[ $key ] = true;
|
||||
$typed[ $type ] = true;
|
||||
}
|
||||
$nodes[] = $node;
|
||||
}
|
||||
$out = array();
|
||||
foreach ($nodes as $node) {
|
||||
$type = $node['@type'] ?? '';
|
||||
$type = is_array($type) ? implode('+', $type) : (string) $type;
|
||||
$id = isset($node['@id']) && is_string($node['@id']) ? $node['@id'] : '';
|
||||
if ('' === $id && ! empty($typed[ $type ])) {
|
||||
continue; // уже есть версия с id
|
||||
}
|
||||
$out[] = $node;
|
||||
}
|
||||
$data['@graph'] = array_values($out);
|
||||
}
|
||||
|
||||
function dekart_normalize_jsonld_node(array &$node, string $type): void
|
||||
{
|
||||
if (isset($node['@id']) && is_string($node['@id']) && '#organization' === substr($node['@id'], -13)) {
|
||||
|
||||
@ -145,7 +145,21 @@ if (empty($segments) || ! is_array($segments)) {
|
||||
array( 'segment_title' => 'Хотите больше школьной программы', 'segment_text' => 'Углубляем знания, учим думать, а не запоминать. Мини-группа держит темп и азарт.' ),
|
||||
);
|
||||
}
|
||||
$segment_4_title = 'Уже занимались с репетитором, но нет результата?';
|
||||
// старые тексты из CF заменяем на нейтральные при выводе
|
||||
function dekart_teacher_neutral_text(string $text): string
|
||||
{
|
||||
$map = array(
|
||||
'Чем мини-группа лучше репетитора?' => 'Чем мини-группа лучше индивидуальных занятий?',
|
||||
'Стоимость ниже репетитора, а дисциплина выше — пропускать занятия не хочется.' => 'Стоимость ниже индивидуальных занятий, а дисциплина выше — пропускать занятия не хочется.',
|
||||
'человек в мини-группе — внимание как на репетиторе' => 'человек в мини-группе — внимание к каждому',
|
||||
'Уже занимались с репетитором, но нет результата?' => 'Уже занимались дополнительно, но нет результата?',
|
||||
);
|
||||
$text = str_replace(array_keys($map), array_values($map), $text);
|
||||
|
||||
return str_ireplace('репетитор', 'индивидуальные занятия', $text);
|
||||
}
|
||||
|
||||
$segment_4_title = 'Уже занимались дополнительно, но нет результата?';
|
||||
$segment_4_text = 'Частая ситуация: деньги потрачены, а результата нет. В мини-группе другой механизм — соревнование, методика и куратор. Приходите на бесплатную диагностику и сравните сами.';
|
||||
|
||||
$cases = (array) carbon_get_post_meta($tid, 'teacher_cases');
|
||||
@ -154,8 +168,8 @@ $faq_extra = (array) carbon_get_post_meta($tid, 'teacher_faq_extra');
|
||||
$faq_items = array();
|
||||
if (empty($faq_extra)) {
|
||||
$faq_items[] = array(
|
||||
'q' => 'Чем мини-группа лучше репетитора?',
|
||||
'a' => 'В мини-группе 2–6 человек преподаватель видит каждого, но у детей появляется азарт, здоровая конкуренция и живое обсуждение. Стоимость ниже репетитора, а дисциплина выше — пропускать занятия не хочется.',
|
||||
'q' => 'Чем мини-группа лучше индивидуальных занятий?',
|
||||
'a' => 'В мини-группе 2–6 человек преподаватель видит каждого, но у детей появляется азарт, здоровая конкуренция и живое обсуждение. Стоимость ниже индивидуальных занятий, а дисциплина выше — пропускать занятия не хочется.',
|
||||
);
|
||||
$faq_items[] = array(
|
||||
'q' => 'Что если ребёнок стесняется заниматься с другими?',
|
||||
@ -164,14 +178,20 @@ if (empty($faq_extra)) {
|
||||
} else {
|
||||
foreach ($faq_extra as $fx) {
|
||||
if (! empty($fx['faq_q']) && ! empty($fx['faq_a'])) {
|
||||
$faq_items[] = array( 'q' => $fx['faq_q'], 'a' => $fx['faq_a'] );
|
||||
$faq_items[] = array(
|
||||
'q' => dekart_teacher_neutral_text((string) $fx['faq_q']),
|
||||
'a' => dekart_teacher_neutral_text((string) $fx['faq_a']),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$legacy_questions = (array) carbon_get_post_meta($tid, 'questions');
|
||||
foreach ($legacy_questions as $lq) {
|
||||
if (! empty($lq['questions_question']) && ! empty($lq['questions_answer'])) {
|
||||
$faq_items[] = array( 'q' => $lq['questions_question'], 'a' => $lq['questions_answer'] );
|
||||
$faq_items[] = array(
|
||||
'q' => dekart_teacher_neutral_text((string) $lq['questions_question']),
|
||||
'a' => dekart_teacher_neutral_text((string) $lq['questions_answer']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +209,7 @@ if ($exam_date && preg_match('/^\d{4}-\d{2}-\d{2}$/', $exam_date)) {
|
||||
$teachers_page = get_page_by_path('our-teachers');
|
||||
|
||||
$page_url = get_permalink($tid);
|
||||
$org_id = home_url('/') . '#org';
|
||||
$org_id = home_url('/') . '#organization';
|
||||
$person_id = $page_url . '#person';
|
||||
|
||||
$org_logo = '';
|
||||
@ -342,7 +362,10 @@ if ($avatar_url) {
|
||||
$person['image'] = $avatar_url;
|
||||
}
|
||||
if ($about_text) {
|
||||
$person['description'] = wp_strip_all_tags($about_text);
|
||||
// заголовок и текст не слипаются: блочные теги дают разделитель
|
||||
$about_plain = preg_replace('~</(?:h[1-6]|p|div|li)>~iu', '. ', (string) $about_text);
|
||||
$about_plain = trim((string) preg_replace('~\s+~u', ' ', wp_strip_all_tags((string) $about_plain)));
|
||||
$person['description'] = $about_plain;
|
||||
}
|
||||
if (! empty($subject_names)) {
|
||||
$person['knowsAbout'] = $subject_names;
|
||||
@ -460,35 +483,55 @@ if (! empty($subject_items)) {
|
||||
$courses[] = $build_course('Занятия в мини-группе ' . $group_size . ' чел.', 1);
|
||||
}
|
||||
|
||||
if ($sp_avg_num > 0 && $review_count > 0 && ! empty($courses)) {
|
||||
$courses[0]['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => $sp_avg,
|
||||
'ratingCount' => (string) $review_count,
|
||||
'bestRating' => '5',
|
||||
);
|
||||
|
||||
|
||||
$teacher_reviews = function_exists('dekart_teacher_review_ids') ? dekart_teacher_review_ids($tid) : array();
|
||||
$review_items = array();
|
||||
foreach ($teacher_reviews as $rid) {
|
||||
$star = (int) ( carbon_get_post_meta($rid, 'review_star') ?: 5 );
|
||||
$star = min(5, max(1, $star));
|
||||
$item = array(
|
||||
'@type' => 'Review',
|
||||
'author' => array( '@type' => 'Person', 'name' => wp_strip_all_tags(get_the_title($rid)) ),
|
||||
'reviewRating' => array( '@type' => 'Rating', 'ratingValue' => (string) $star, 'bestRating' => '5' ),
|
||||
);
|
||||
$rtext = wp_strip_all_tags((string) carbon_get_post_meta($rid, 'review_text'));
|
||||
if ('' !== $rtext) {
|
||||
$item['reviewBody'] = $rtext;
|
||||
}
|
||||
$item['datePublished'] = get_the_date('c', $rid);
|
||||
$review_items[] = $item;
|
||||
// отзывы только этого преподавателя; среднее и количество — из них же
|
||||
$teacher_reviews = function_exists('dekart_teacher_review_ids') ? dekart_teacher_review_ids($tid) : array();
|
||||
$review_items = array();
|
||||
$review_stars = array();
|
||||
foreach ($teacher_reviews as $rid) {
|
||||
$own = 0;
|
||||
$raw_own = function_exists('carbon_get_post_meta') ? carbon_get_post_meta($rid, 'review_teacher') : '';
|
||||
if (is_array($raw_own)) {
|
||||
$first = $raw_own[0] ?? null;
|
||||
$own = is_array($first) ? (int) ( $first['id'] ?? 0 ) : (int) $first;
|
||||
} elseif (is_string($raw_own) && preg_match('/:(\d+)$/', $raw_own, $mm)) {
|
||||
$own = (int) $mm[1];
|
||||
} elseif (is_numeric($raw_own)) {
|
||||
$own = (int) $raw_own;
|
||||
}
|
||||
if ($own > 0 && $own !== $tid) {
|
||||
continue;
|
||||
}
|
||||
$star = (int) ( carbon_get_post_meta($rid, 'review_star') ?: 0 );
|
||||
$item = array(
|
||||
'@type' => 'Review',
|
||||
'author' => array( '@type' => 'Person', 'name' => wp_strip_all_tags(get_the_title($rid)) ),
|
||||
);
|
||||
if ($star >= 1 && $star <= 5) {
|
||||
$item['reviewRating'] = array( '@type' => 'Rating', 'ratingValue' => (string) $star, 'bestRating' => '5' );
|
||||
$review_stars[] = $star;
|
||||
}
|
||||
$rtext = wp_strip_all_tags((string) carbon_get_post_meta($rid, 'review_text'));
|
||||
if ('' !== $rtext) {
|
||||
$item['reviewBody'] = $rtext;
|
||||
}
|
||||
$item['datePublished'] = get_the_date('c', $rid);
|
||||
$review_items[] = $item;
|
||||
}
|
||||
|
||||
if (! empty($courses)) {
|
||||
if (! empty($review_items)) {
|
||||
$courses[0]['review'] = $review_items;
|
||||
}
|
||||
if (! empty($review_stars)) {
|
||||
$courses[0]['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => round(array_sum($review_stars) / count($review_stars), 1),
|
||||
'reviewCount' => count($review_items),
|
||||
'ratingCount' => count($review_items),
|
||||
'bestRating' => '5',
|
||||
'worstRating' => '1',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$schema_faq = array();
|
||||
@ -515,14 +558,23 @@ foreach ($crumb_parents as $i => $p) {
|
||||
}
|
||||
|
||||
$org['employee'] = array(array('@id' => $person_id));
|
||||
$schema_graph = array($org, $person);
|
||||
$webpage = array(
|
||||
'@type' => 'WebPage',
|
||||
'@id' => $page_url . '#webpage',
|
||||
'url' => $page_url,
|
||||
'name' => wp_strip_all_tags($full_name),
|
||||
'inLanguage' => 'ru-RU',
|
||||
'isPartOf' => array( '@id' => $org_id ),
|
||||
'about' => array( '@id' => $person_id ),
|
||||
);
|
||||
$schema_graph = array($org, $webpage, $person);
|
||||
foreach ($courses as $c) {
|
||||
$schema_graph[] = $c;
|
||||
}
|
||||
if (! empty($schema_faq)) {
|
||||
$schema_graph[] = array('@type' => 'FAQPage', 'mainEntity' => $schema_faq);
|
||||
$schema_graph[] = array('@type' => 'FAQPage', '@id' => $page_url . '#faq', 'mainEntity' => $schema_faq);
|
||||
}
|
||||
$schema_graph[] = array('@type' => 'BreadcrumbList', 'itemListElement' => $breadcrumbs);
|
||||
$schema_graph[] = array('@type' => 'BreadcrumbList', '@id' => $page_url . '#breadcrumb', 'itemListElement' => $breadcrumbs);
|
||||
?>
|
||||
<main class="teacher-single">
|
||||
|
||||
@ -632,7 +684,7 @@ $schema_graph[] = array('@type' => 'BreadcrumbList', 'itemListElement' => $bread
|
||||
}
|
||||
$metrics[] = array(
|
||||
'num' => $mn,
|
||||
'label' => trim((string) ( $mc['metric_text'] ?? '' )),
|
||||
'label' => dekart_teacher_neutral_text(trim((string) ( $mc['metric_text'] ?? '' ))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ if (empty($trust_items)) {
|
||||
if ($avg_years) {
|
||||
$trust_items[] = array( 'num' => $avg_years, 'label' => 'лет — средний педагогический стаж' );
|
||||
}
|
||||
$trust_items[] = array( 'num' => $group, 'label' => 'человек в мини-группе — внимание как на репетиторе' );
|
||||
$trust_items[] = array( 'num' => $group, 'label' => 'человек в мини-группе — внимание к каждому' );
|
||||
}
|
||||
|
||||
if (empty($trust_items)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user