diff --git a/class/comment.php b/class/comment.php index 71ec488..2045438 100644 --- a/class/comment.php +++ b/class/comment.php @@ -1501,37 +1501,92 @@ function commentAdminDelete($comment_id) * * @param string $tpl_dir - путь к шаблонам модуля */ - function commentPostInfoShow($tpl_dir) - { - global $AVE_DB, $AVE_Template; - - $comment_id = (int)($_REQUEST['Id'] ?? 0); +function commentPostInfoShow($tpl_dir) +{ + global $AVE_DB, $AVE_Template; + + $comment_id = (int)($_REQUEST['Id'] ?? 0); - // Получаем полную информацию о комментарии - $row = $AVE_DB->Query(" - SELECT * - FROM " . PREFIX . "_module_comment_info - WHERE Id = '" . $comment_id . "' - ")->FetchAssocArray(); + // 1. Получаем данные комментария и настройки заголовков + $row = $AVE_DB->Query(" + SELECT c.*, m.comment_name_f1, m.comment_name_f2 + FROM " . PREFIX . "_module_comment_info AS c + LEFT JOIN " . PREFIX . "_module_comments AS m ON 1=1 + WHERE c.Id = '$comment_id' + LIMIT 1 + ")->FetchAssocArray(); - // Преобразуем адрес сайта к формату ссылки - $row['comment_author_website'] = str_replace('http://', '', $row['comment_author_website']); - $row['comment_author_website'] = ($row['comment_author_website'] != '') - ? '' . $row['comment_author_website'] .'' - : ''; + if (!$row) exit('Данные не найдены'); - // Выполняем запрос к БД на получение количества всех комментариев, оставленных данным пользователем - $row['num'] = $AVE_DB->Query(" - SELECT COUNT(*) - FROM " . PREFIX . "_module_comment_info - WHERE comment_author_id = '" . $row['comment_author_id'] . "' - AND comment_author_id != 0 - ")->GetCell(); + $author_id = (int)($row['comment_author_id'] ?? 0); + $a_key = $row['anon_key'] ?? ''; - // Отображаем окно с информацией - $AVE_Template->assign('c', $row); - $AVE_Template->display($tpl_dir . $this->_postinfo_tpl); - } + // --- ЛОГИКА ДАТ --- + if ($author_id > 0) { + $user_data = $AVE_DB->Query("SELECT reg_time, last_visit FROM " . PREFIX . "_users WHERE Id = '$author_id' LIMIT 1")->FetchAssocArray(); + $row['date_label'] = 'Дата регистрации'; + $row['date_value'] = $user_data['reg_time'] ?? 0; + $row['last_visit'] = $user_data['last_visit'] ?? 0; + } else { + $first_time = ($a_key != '') ? $AVE_DB->Query("SELECT MIN(comment_published) FROM " . PREFIX . "_module_comment_info WHERE anon_key = '" . addslashes($a_key) . "'")->GetCell() : 0; + $row['date_label'] = 'Дата первого комментария'; + $row['date_value'] = $first_time; + $row['last_visit'] = 0; + } + + // --- ПОДСЧЕТ КОММЕНТАРИЕВ И СУММАРНОГО РЕЙТИНГА --- + if ($author_id > 0) { + $where = "comment_author_id = '$author_id'"; + } elseif ($a_key != '') { + $where = "anon_key = '" . addslashes($a_key) . "'"; + } else { + $where = "Id = '$comment_id'"; // Крайний случай + } + + // Считаем всё одним запросом: количество, сумму звезд и сумму голосов + $stats = $AVE_DB->Query(" + SELECT + COUNT(*) as total_cnt, + SUM(rating_sum) as sum_stars, + SUM(rating_count) as sum_votes + FROM " . PREFIX . "_module_comment_info + WHERE $where + ")->FetchAssocArray(); + + $row['num'] = $stats['total_cnt'] ?? 1; + + // Вычисляем средний рейтинг (от 1 до 5) + $avg_rating = 0; + if (!empty($stats['sum_votes'])) { + $avg_rating = round($stats['sum_stars'] / $stats['sum_votes']); + } + $row['avg_rating'] = $avg_rating; + $row['total_votes'] = $stats['sum_votes']; + + // --- ОБРАБОТКА ДОП. ПОЛЕЙ (F1, F2) --- + $custom_fields = []; + $fields_to_check = [ + ['val' => $row['comment_author_website'], 'title' => $row['comment_name_f1'], 'default' => 'Личный сайт'], + ['val' => $row['comment_author_city'], 'title' => $row['comment_name_f2'], 'default' => 'Откуда'] + ]; + foreach ($fields_to_check as $f) { + $val = trim($f['val'] ?? ''); + if ($val != '') { + $title = (!empty($f['title'])) ? $f['title'] : $f['default']; + $value = (preg_match('/^(http|https|www\.)/i', $val)) + ? '' . str_replace(['http://', 'https://'], '', $val) . '' + : htmlspecialchars($val); + $custom_fields[] = ['title' => $title, 'value' => $value]; + } + } + + $AVE_Template->assign('c', $row); + $AVE_Template->assign('custom_fields', $custom_fields); + + header('Content-Type: text/html; charset=utf-8'); + $AVE_Template->display($tpl_dir . $this->_postinfo_tpl); + exit; +} /** * Метод, предназначенный для управления запретом или разрешением отвечать на комментарии diff --git a/templates/comment_info.tpl b/templates/comment_info.tpl index 86a5777..85b3807 100644 --- a/templates/comment_info.tpl +++ b/templates/comment_info.tpl @@ -1,54 +1,47 @@ - - +
\ No newline at end of file diff --git a/templates/comments_tree_sub.tpl b/templates/comments_tree_sub.tpl index 92771c1..bfa26c4 100644 --- a/templates/comments_tree_sub.tpl +++ b/templates/comments_tree_sub.tpl @@ -1,3 +1,41 @@ +{literal} + +{/literal} {foreach from=$subcomments item=c name=sub_loop} {* ОПРЕДЕЛЯЕМ СТАТУС УДАЛЕНИЯ *} {assign var="is_deleted" value=false} @@ -60,7 +98,13 @@ {if !$is_deleted} - {$c.comment_author_name|stripslashes|escape} + + {$c.comment_author_name|stripslashes|escape} + {* ПРОВЕРКА ИСТОРИИ ИМЕН АНОНИМА *} {if !empty($c.past_names)} {/if} -{/foreach} \ No newline at end of file +{/foreach} + +{literal} + +{/literal} \ No newline at end of file