This commit is contained in:
Dekart Deploy Bot 2026-11-14 20:27:25 +00:00
parent 82b5cd0d49
commit dd28466b25
2 changed files with 26 additions and 12 deletions

View File

@ -5502,6 +5502,26 @@ function dekart_teacher_review_counts(): array
}
// отзыв принадлежит преподавателю, если привязка явная и совпадает
function dekart_teacher_owns_review(int $review_id, int $teacher_id): bool
{
if ($review_id <= 0 || $teacher_id <= 0 || ! function_exists('carbon_get_post_meta')) {
return false;
}
$raw = carbon_get_post_meta($review_id, 'review_teacher');
$own = 0;
if (is_array($raw)) {
$first = $raw[0] ?? null;
$own = is_array($first) ? (int) ( $first['id'] ?? 0 ) : (int) $first;
} elseif (is_string($raw) && preg_match('/:(\d+)$/', $raw, $mm)) {
$own = (int) $mm[1];
} elseif (is_numeric($raw)) {
$own = (int) $raw;
}
return $own > 0 && $own === $teacher_id;
}
function dekart_teacher_review_ids(int $teacher_id): array
{
$map = dekart_teacher_review_map();

View File

@ -363,8 +363,11 @@ if ($avatar_url) {
}
if ($about_text) {
// заголовок и текст не слипаются: блочные теги дают разделитель
$about_plain = preg_replace('~</(?:h[1-6]|p|div|li)>~iu', '. ', (string) $about_text);
$about_plain = preg_replace('~<br\s*/?>~iu', ' ', (string) $about_text);
$about_plain = preg_replace('~</(?:h[1-6]|p|div|li|ul|ol|blockquote|td|th|tr)>~iu', '. ', (string) $about_plain);
$about_plain = trim((string) preg_replace('~\s+~u', ' ', wp_strip_all_tags((string) $about_plain)));
$about_plain = trim((string) preg_replace('~([.!?…])\s*\.\s+~u', '$1 ', $about_plain));
$about_plain = trim((string) preg_replace('~\s*\.{2,}\s*$~u', '.', $about_plain));
$person['description'] = $about_plain;
}
if (! empty($subject_names)) {
@ -488,17 +491,8 @@ $teacher_reviews = function_exists('dekart_teacher_review_ids') ? dekart_teacher
$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) {
// берём только отзывы с явной привязкой к этому преподавателю
if (! dekart_teacher_owns_review((int) $rid, (int) $tid)) {
continue;
}
$star = (int) ( carbon_get_post_meta($rid, 'review_star') ?: 0 );