From c7627d699d424ea41e38f79b2929fc8da39d2050 Mon Sep 17 00:00:00 2001 From: Repellent Date: Thu, 1 Jan 2026 14:51:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=81=D0=BC=D0=B5=D0=BD=D1=83=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=90=D0=BD=D0=BE=D0=BD=D0=B8=D0=BC=D0=BE=D0=BC?= =?UTF-8?q?=20-=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=81=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=82=20=D0=B8=D0=BC=D1=8F=20=D0=BF=D0=BE=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B6=D0=B8=D0=B2=D0=B0=20=D0=BA=D1=83=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D0=B8=D1=82=20=D0=BF=D0=BB=D0=B0=D1=88?= =?UTF-8?q?=D0=BA=D1=83=20=D1=81=20=D0=BF=D0=BE=D0=B4=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=BD=D0=BE=D0=B2=D0=BA=D0=BE=D0=B9=20=D0=B2=D1=81=D0=B5?= =?UTF-8?q?=D1=85=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4=D1=83=D1=89=D0=B8?= =?UTF-8?q?=D1=85=20=D0=B8=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/comment.php | 110 +++++++++++++++++++++++++------- js/comment.js | 6 ++ templates/comments_tree.tpl | 35 ++++++---- templates/comments_tree_sub.tpl | 10 +++ 4 files changed, 127 insertions(+), 34 deletions(-) diff --git a/class/comment.php b/class/comment.php index 3c067c5..3f2b001 100644 --- a/class/comment.php +++ b/class/comment.php @@ -138,6 +138,34 @@ function __construct() } } +/** + * Получение всех уникальных имен, использованных анонимом + * * @param string $anon_key уникальный ключ + * @param string $exclude_name исключить это имя из результата (текущее) + * @return array + */ +private function _getAnonNamesHistory($anon_key, $exclude_name = '') +{ + global $AVE_DB; + $names = []; + + $exclude_sql = !empty($exclude_name) ? " AND comment_author_name != '" . addslashes($exclude_name) . "'" : ""; + + $sql = $AVE_DB->Query(" + SELECT DISTINCT comment_author_name + FROM " . PREFIX . "_module_comment_info + WHERE anon_key = '" . addslashes($anon_key) . "' + " . $exclude_sql . " + ORDER BY Id DESC + "); + + while ($row = $sql->FetchAssocArray()) { + $names[] = stripslashes($row['comment_author_name']); + } + return $names; +} + + function _commentSettingsGet($param = '') { global $AVE_DB; @@ -239,6 +267,9 @@ function commentListShow($tpl_dir) $read_groups = explode(',', $settings['comment_user_groups_read']); $assign['no_read_permission'] = 0; + // Чтобы Smarty не ругался, создаем пустую заглушку + $assign['saved_anon'] = ['name' => '', 'email' => '', 'exists' => false]; + if (!in_array($user_group, $read_groups)) { $assign['no_read_permission'] = 1; @@ -323,6 +354,18 @@ if ($settings['comment_use_page_nav'] == 1) while ($row = $sql->FetchAssocArray()) { + + // --- ВОТ ЭТОТ БЛОК --- + if ($assign['saved_anon']['exists'] == false && !empty($row['anon_key']) && $row['anon_key'] == $anon_key) { + $assign['saved_anon'] = [ + 'name' => stripslashes($row['comment_author_name']), + 'email' => stripslashes($row['comment_author_email']), + 'exists' => true + ]; + } + // --- КОНЕЦ БЛОКА --- + + // 1. Получаем аватар через стандартную функцию системы if (isset($row['comment_author_id']) && $row['comment_author_id'] > 0) { @@ -377,6 +420,13 @@ if ($settings['comment_use_page_nav'] == 1) $row['is_my_own'] = $is_author; // ------------------------------------------------------- + // --- НОВОЕ: Получаем историю имен для анонима --- + $row['past_names'] = []; + if (!empty($row['anon_key'])) { + $row['past_names'] = $this->_getAnonNamesHistory($row['anon_key'], $row['comment_author_name']); + } + // --- КОНЕЦ НОВОГО --- + $row['comment_published_raw'] = $row['comment_published']; $row['comment_published'] = ave_date_format($date_time_format, $row['comment_published']); $row['comment_changed'] = ave_date_format($date_time_format, $row['comment_changed']); @@ -410,31 +460,47 @@ if ($settings['comment_use_page_nav'] == 1) * * @param string $tpl_dir - путь к шаблонам модуля */ - function commentPostFormShow($tpl_dir) - { - global $AVE_DB, $AVE_Template; +function commentPostFormShow($tpl_dir) +{ + global $AVE_DB, $AVE_Template; - // Используем оператор объединения с null для PHP 8.4 - $docid = (int)($_REQUEST['docid'] ?? 0); - $user_group = UGROUP ?? 0; - - // Получаем список комментариев на которые запрещены ответы - $geschlossen = $AVE_DB->Query(" - SELECT comments_close - FROM " . PREFIX . "_module_comment_info - WHERE document_id = '" . $docid . "' - LIMIT 1 - ")->GetCell(); + $docid = (int)($_REQUEST['docid'] ?? 0); + $user_group = UGROUP ?? 0; + + // --- НОВОЕ: Автоподстановка для анонима --- + $anon_data = ['name' => '', 'email' => '', 'exists' => false]; + if ($user_group == 2) { // Если гость + $anon_key = $this->_getAnonKey(); + $last_post = $AVE_DB->Query(" + SELECT comment_author_name, comment_author_email + FROM " . PREFIX . "_module_comment_info + WHERE anon_key = '" . $anon_key . "' + ORDER BY Id DESC LIMIT 1 + ")->FetchAssocArray(); + + if ($last_post) { + $anon_data['name'] = stripslashes($last_post['comment_author_name']); + $anon_data['email'] = stripslashes($last_post['comment_author_email']); + $anon_data['exists'] = true; + } + } + $AVE_Template->assign('saved_anon', $anon_data); + // --- КОНЕЦ НОВОГО --- - // Формируем ряд переменных для использования в шаблоне - $AVE_Template->assign('closed', $geschlossen); - $AVE_Template->assign('cancomment', ($this->_commentSettingsGet('comment_active') == 1 && in_array($user_group, explode(',', $this->_commentSettingsGet('comment_user_groups'))))); - $AVE_Template->assign('comment_max_chars', $this->_commentSettingsGet('comment_max_chars')); - $AVE_Template->assign('theme', defined('THEME_FOLDER') ? THEME_FOLDER : DEFAULT_THEME_FOLDER); + $geschlossen = $AVE_DB->Query(" + SELECT comments_close + FROM " . PREFIX . "_module_comment_info + WHERE document_id = '" . $docid . "' + LIMIT 1 + ")->GetCell(); - // Отображаем форму для добавления комментария - $AVE_Template->display($tpl_dir . $this->_comment_form_tpl); - } + $AVE_Template->assign('closed', $geschlossen); + $AVE_Template->assign('cancomment', ($this->_commentSettingsGet('comment_active') == 1 && in_array($user_group, explode(',', $this->_commentSettingsGet('comment_user_groups'))))); + $AVE_Template->assign('comment_max_chars', $this->_commentSettingsGet('comment_max_chars')); + $AVE_Template->assign('theme', defined('THEME_FOLDER') ? THEME_FOLDER : DEFAULT_THEME_FOLDER); + + $AVE_Template->display($tpl_dir . $this->_comment_form_tpl); +} /** * Метод, предназначенный для записи в БД нового комментария. diff --git a/js/comment.js b/js/comment.js index b5362de..3545308 100644 --- a/js/comment.js +++ b/js/comment.js @@ -235,6 +235,12 @@ if (action === 'unlock' || action === 'lock') { $(this).next('.invalid-feedback').fadeOut(200, function() { $(this).remove(); }); }); + // Инициализация тултипов для всех элементов с data-bs-toggle="tooltip" + var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) + var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { + return new bootstrap.Tooltip(tooltipTriggerEl) + }) + // Счетчик: Количество оставшихся символов 1000 для формы создания комментария $('#in_message').limit(1000, '#charsLeft_new'); diff --git a/templates/comments_tree.tpl b/templates/comments_tree.tpl index ccdabb4..8cc256d 100644 --- a/templates/comments_tree.tpl +++ b/templates/comments_tree.tpl @@ -77,18 +77,29 @@ - {else} -
-
- - -
-
- - -
-
- {/if} +{else} + {* Блок для Анонимных пользователей (Гостей) *} +
+
+ + + + {if isset($saved_anon.exists) && $saved_anon.exists} +
Имя зафиксировано по вашему ключу доступа.
+ {/if} +
+
+ + +
+
+{/if}
{if $comment_show_f1 == 1} diff --git a/templates/comments_tree_sub.tpl b/templates/comments_tree_sub.tpl index 6f39495..fc975bb 100644 --- a/templates/comments_tree_sub.tpl +++ b/templates/comments_tree_sub.tpl @@ -29,6 +29,16 @@ {$c.comment_author_name|stripslashes|escape} +{* ПРОВЕРКА ИСТОРИИ ИМЕН АНОНИМА *} +{if !empty($c.past_names)} + + менял имя + +{/if} {$c.comment_published}