From 5a5f7c73e2a82b476a7b01f669bf5e1892ea10f1 Mon Sep 17 00:00:00 2001 From: Dekart Deploy Bot Date: Mon, 12 Oct 2026 18:01:33 +0000 Subject: [PATCH] fix(pksh): parse external platforms from raw CF meta (any key layout) --- wp-content/themes/dekart/functions.php | 88 +++++++++++++++++++ .../template-parts/pksh/external-reviews.php | 19 +--- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/wp-content/themes/dekart/functions.php b/wp-content/themes/dekart/functions.php index 74a0c32..dae4a2e 100644 --- a/wp-content/themes/dekart/functions.php +++ b/wp-content/themes/dekart/functions.php @@ -5934,6 +5934,94 @@ function dekart_branch_add_menu() add_action('admin_init', 'dekart_branch_register_settings'); +// Внешние площадки ПКШ: собираем из сырой меты (любая схема ключей CF) +function dekart_pksh_external_platforms(int $post_id): array +{ + if (! $post_id) { + return array(); + } + + global $wpdb; + $like = $wpdb->esc_like('_pksh_external_platforms') . '%'; + $rows = $wpdb->get_results($wpdb->prepare( + "SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key LIKE %s", + $post_id, + $like + )); + if (empty($rows)) { + return array(); + } + + $sub_names = array( 'name', 'icon', 'rating', 'url' ); // порядок подполей в CF + $items = array(); + + foreach ($rows as $r) { + $parts = explode('|', (string) $r->meta_key); + array_shift($parts); // имя поля + if (end($parts) === 'value') { + array_pop($parts); // хвост 'value' + } + if (empty($parts)) { + continue; + } + + // строка = первый числовой сегмент + $row_pos = null; + foreach ($parts as $i => $seg) { + if (ctype_digit((string) $seg)) { + $row_pos = $i; + break; + } + } + if (null === $row_pos) { + continue; + } + $row = (int) $parts[ $row_pos ]; + $rest = $parts; + unset($rest[ $row_pos ]); + + // имя подполя: известное имя сегмента или числовой индекс по порядку + $sub = ''; + foreach ($rest as $seg) { + $cand = preg_replace('/^platform_/', '', (string) $seg); + if (in_array($cand, $sub_names, true)) { + $sub = $cand; + break; + } + } + if ('' === $sub) { + foreach ($rest as $seg) { + if (ctype_digit((string) $seg) && isset($sub_names[ (int) $seg ])) { + $sub = $sub_names[ (int) $seg ]; + break; + } + } + } + if ('' === $sub) { + continue; + } + + $items[ $row ][ $sub ] = (string) $r->meta_value; + } + + $out = array(); + foreach ($items as $item) { + $url = trim((string) ( $item['url'] ?? '' )); + if ('' === $url) { + continue; + } + $out[] = array( + 'url' => $url, + 'icon' => (string) ( $item['icon'] ?? '' ), + 'name' => (string) ( $item['name'] ?? '' ), + 'rating' => (string) ( $item['rating'] ?? '' ), + ); + } + + return $out; +} + + function dekart_post_author(int $post_id = 0): array { $post_id = $post_id ?: (int) get_the_ID(); diff --git a/wp-content/themes/dekart/template-parts/pksh/external-reviews.php b/wp-content/themes/dekart/template-parts/pksh/external-reviews.php index 7b77b55..832adae 100644 --- a/wp-content/themes/dekart/template-parts/pksh/external-reviews.php +++ b/wp-content/themes/dekart/template-parts/pksh/external-reviews.php @@ -11,23 +11,8 @@ $city_prep = $data->get_city_prep(); $platforms = array(); -$cf_platforms = carbon_get_post_meta(get_the_ID(), 'pksh_external_platforms'); -if (is_array($cf_platforms)) { - foreach ($cf_platforms as $row) { - if (! is_array($row)) { - continue; - } - $url = trim((string) ( $row['platform_url'] ?? $row['url'] ?? '' )); - if ('' === $url) { - continue; - } - $platforms[] = array( - 'url' => $url, - 'icon' => (string) ( $row['platform_icon'] ?? $row['icon'] ?? '' ), - 'name' => (string) ( $row['platform_name'] ?? $row['name'] ?? '' ), - 'rating' => (string) ( $row['platform_rating'] ?? $row['rating'] ?? '' ), - ); - } +if (function_exists('dekart_pksh_external_platforms')) { + $platforms = dekart_pksh_external_platforms((int) get_the_ID()); } if (empty($platforms)) {