2026-10-08 14:29:15 +00:00

239 lines
7.7 KiB
PHP

<?php
// Schema.org @graph (WebPage / BreadcrumbList / Organization / FAQPage)
if (! defined('ABSPATH')) {
exit;
}
$f_city = get_option('branch_city') ?: carbon_get_theme_option('site_city');
$f_h1 = 'Семейные классы' . ($f_city ? ' в ' . $f_city : '');
$f_url = get_permalink();
$f_graph = array();
$f_graph[] = array(
'@type' => 'WebPage',
'@id' => $f_url . '#webpage',
'url' => $f_url,
'name' => $f_h1,
'inLanguage' => 'ru-RU',
'mainEntity' => array( '@id' => $f_url . '#course' ),
);
$f_graph[] = array(
'@type' => 'BreadcrumbList',
'@id' => $f_url . '#breadcrumb',
'itemListElement' => array(
array(
'@type' => 'ListItem',
'position' => 1,
'name' => 'Главная',
'item' => home_url('/'),
),
array(
'@type' => 'ListItem',
'position' => 2,
'name' => $f_h1,
'item' => $f_url,
),
),
);
// Организация/филиал — из общих хелперов (данные филиала)
if (function_exists('dekart_schema_organization')) {
$f_org = dekart_schema_organization();
if ($f_org) {
$f_graph[] = $f_org;
}
}
if (function_exists('dekart_schema_local_business')) {
$f_lb = dekart_schema_local_business();
if ($f_lb) {
$f_graph[] = $f_lb;
}
}
// Course + Offer (цены из CF школы), CourseInstance (Onsite, адрес филиала)
$f_price_cards = array();
$f_school_id = function_exists('dekart_page_id_by_template') ? dekart_page_id_by_template('page-elementary-school.php') : 0;
if ($f_school_id) {
$f_price_cards = (array) carbon_get_post_meta($f_school_id, 'price_cards');
}
if (! $f_price_cards) {
$f_home = (int) get_option('page_on_front');
if ($f_home) {
$f_price_cards = (array) carbon_get_post_meta($f_home, 'price_cards');
}
}
$f_offers = array();
foreach ($f_price_cards as $f_pc) {
$f_num = (int) preg_replace('/[^0-9]/', '', (string) ( $f_pc['price'] ?? '' ));
if ($f_num <= 0) {
continue;
}
$f_offer = array(
'@type' => 'Offer',
'price' => $f_num,
'priceCurrency' => 'RUB',
'availability' => 'https://schema.org/InStock',
'url' => $f_url,
'priceSpecification' => array(
'@type' => 'PriceSpecification',
'price' => $f_num,
'priceCurrency' => 'RUB',
'valueAddedTaxIncluded' => true,
),
);
if (! empty($f_pc['class_name'])) {
$f_offer['name'] = wp_strip_all_tags($f_pc['class_name']);
}
$f_offers[] = $f_offer;
}
$f_org_id = null;
if (function_exists('dekart_schema_organization')) {
$f_org = dekart_schema_organization();
if (! empty($f_org['@id'])) {
$f_org_id = $f_org['@id'];
}
}
$f_addr = get_option('branch_address') ?: carbon_get_theme_option('site_address');
$f_course_instance = array(
'@type' => 'CourseInstance',
'courseMode' => 'Onsite',
'name' => $f_h1,
);
if ($f_addr || $f_city) {
$f_course_instance['location'] = array(
'@type' => 'Place',
'name' => get_option('branch_name') ?: carbon_get_theme_option('site_name') ?: 'Частная школа «Декарт»',
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => $f_addr,
'addressLocality' => $f_city,
'addressCountry' => 'RU',
),
);
}
$f_course_id = $f_url . '#course';
$f_course = array(
'@type' => 'Course',
'@id' => $f_course_id,
'name' => $f_h1,
'description' => wp_strip_all_tags((string) dekart_family_get('family_what_is_text')) ?: $f_h1,
'inLanguage' => 'ru-RU',
'hasCourseInstance' => array( $f_course_instance ),
);
if ($f_org_id) {
$f_course['provider'] = array( '@id' => $f_org_id );
}
if ($f_offers) {
$f_course['offers'] = $f_offers;
}
// Отзывы — те же, что видны на странице (CF лендинга или школьные)
$f_reviews = array();
$f_review_ids = function_exists('dekart_assoc_ids') ? dekart_assoc_ids(dekart_family_get('family_review_ids')) : array();
if ($f_review_ids) {
foreach ($f_review_ids as $f_rid) {
if (get_post_status($f_rid) !== 'publish') {
continue;
}
$f_reviews[] = array(
'author' => get_the_title($f_rid),
'body' => (string) carbon_get_post_meta($f_rid, 'review_text'),
'date' => get_the_date('c', $f_rid),
'rating' => (int) carbon_get_post_meta($f_rid, 'review_star'),
);
}
} else {
$f_school_cards = carbon_get_post_meta(91, 'reviews_cards');
if (is_array($f_school_cards) && $f_school_cards) {
// Тот же набор, что виден в блоке: сортировка по дате + лимит 3
if (function_exists('dekart_reviews_sort_desc')) {
$f_school_cards = dekart_reviews_sort_desc($f_school_cards);
}
$f_school_cards = array_slice($f_school_cards, 0, 3);
foreach ($f_school_cards as $f_rc_item) {
$f_reviews[] = array(
'author' => $f_rc_item['review_author'] ?? '',
'body' => $f_rc_item['review_text'] ?? '',
'date' => ! empty($f_rc_item['review_date']) ? date('c', strtotime($f_rc_item['review_date'])) : '',
'rating' => (int) ( $f_rc_item['review_rating'] ?? 0 ),
);
}
}
}
$f_review_items = array();
$f_rc_count = 0;
$f_rc_sum = 0;
foreach ($f_reviews as $f_rev) {
if (($f_rev['body'] ?? '') === '') {
continue;
}
$f_item = array(
'@type' => 'Review',
'reviewBody' => wp_strip_all_tags($f_rev['body']),
);
if (! empty($f_rev['author'])) {
$f_item['author'] = array( '@type' => 'Person', 'name' => wp_strip_all_tags($f_rev['author']) );
}
if (! empty($f_rev['date'])) {
$f_item['datePublished'] = $f_rev['date'];
}
if (! empty($f_rev['rating']) && $f_rev['rating'] > 0) {
$f_item['reviewRating'] = array( '@type' => 'Rating', 'ratingValue' => (int) $f_rev['rating'], 'bestRating' => 5, 'worstRating' => 1 );
$f_rc_count++;
$f_rc_sum += (int) $f_rev['rating'];
}
$f_review_items[] = $f_item;
}
if ($f_review_items) {
$f_course['review'] = $f_review_items;
if ($f_rc_count > 0) {
$f_course['aggregateRating'] = array(
'@type' => 'AggregateRating',
'ratingValue' => round($f_rc_sum / $f_rc_count, 1),
'reviewCount' => count($f_review_items),
'bestRating' => 5,
'worstRating' => 1,
);
}
}
$f_graph[] = $f_course;
// FAQPage
$f_faq = (array) dekart_family_get('family_faq');
$f_q = array();
foreach ($f_faq as $f_it) {
if (! empty($f_it['question']) && ! empty($f_it['answer'])) {
$f_q[] = array(
'@type' => 'Question',
'name' => wp_strip_all_tags($f_it['question']),
'acceptedAnswer' => array(
'@type' => 'Answer',
'text' => wp_strip_all_tags($f_it['answer']),
),
);
}
}
if ($f_q) {
$f_graph[] = array(
'@type' => 'FAQPage',
'@id' => $f_url . '#faq',
'mainEntity' => $f_q,
);
}
?>
<script type="application/ld+json"><?php
echo wp_json_encode(
array( '@context' => 'https://schema.org', '@graph' => $f_graph ),
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG
);
?></script>