From 3f361569510a96cd93946bd87220b72439935803 Mon Sep 17 00:00:00 2001 From: Repellent Date: Sun, 11 Jan 2026 18:58:53 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/comment.php | 39 +++++++++++++++++++++++++++++++----- lang/ru.txt | 8 +++++--- sql.php | 7 +++---- templates/admin_settings.tpl | 33 ++++++++++++++++++++++-------- 4 files changed, 67 insertions(+), 20 deletions(-) diff --git a/class/comment.php b/class/comment.php index 354d108..c4f6645 100644 --- a/class/comment.php +++ b/class/comment.php @@ -310,28 +310,48 @@ function commentListShow($tpl_dir) $comments = array(); // --- ВЫБОРКА ИЗ БД --- + // Логика формирования SQL-сортировки + $sort_setting = $settings['comment_sort_order'] ?? 'ASC'; + switch ($sort_setting) { + case 'USER_RATING': + // Сначала самые высокие оценки автора (5 звезд), затем дата + $sql_sort = "user_rating DESC, comment_published DESC"; + break; + case 'RATING': + // Сначала самые залайканные пользователями, затем дата + $sql_sort = "rating_sum DESC, comment_published DESC"; + break; + case 'DESC': + $sql_sort = "comment_published DESC"; + break; + case 'ASC': + default: + $sql_sort = "comment_published ASC"; + break; + } + if ($settings['comment_use_page_nav'] == 1) { $limit = (int)$settings['comment_page_nav_count']; if ($limit <= 0) { - $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' " . $where_visibility . " ORDER BY comment_published ASC"); + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' " . $where_visibility . " ORDER BY parent_id ASC, " . $sql_sort); $page_nav = ''; } else { $start = get_current_page() * $limit - $limit; - // 1. Считаем только РОДИТЕЛЕЙ для пагинации (с учетом видимости) + // 1. Считаем только РОДИТЕЛЕЙ для пагинации $num = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' AND parent_id = '0' " . $where_visibility)->GetCell(); - // 2. Основной запрос + // 2. Основной запрос (сортировка применяется к родителям в подзапросе) $sql = $AVE_DB->Query(" SELECT * FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' AND ( - id IN (SELECT id FROM (SELECT id FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' AND parent_id = '0' " . $where_visibility . " ORDER BY comment_published ASC LIMIT " . (int)$start . "," . (int)$limit . ") as tmp) + id IN (SELECT id FROM (SELECT id FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' AND parent_id = '0' " . $where_visibility . " ORDER BY " . $sql_sort . " LIMIT " . (int)$start . "," . (int)$limit . ") as tmp) OR parent_id != '0' ) @@ -358,7 +378,8 @@ function commentListShow($tpl_dir) } else { - $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' " . $where_visibility . " ORDER BY comment_published ASC"); + // Если навигация отключена + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_comment_info WHERE document_id = '" . $document_id . "' " . $where_visibility . " ORDER BY parent_id ASC, " . $sql_sort); $page_nav = ''; } @@ -1479,6 +1500,9 @@ function commentAdminSettingsEdit($tpl_dir) $post_user_groups_read = $_POST['comment_user_groups_read'] ?? array(); $post_allow_self_answer = $_POST['comment_allow_self_answer'] ?? 0; + // НОВАЯ НАСТРОЙКА: Порядок сортировки + $post_sort_order = $_POST['comment_sort_order'] ?? 'ASC'; + $post_need_approve = $_POST['comment_need_approve'] ?? 0; $post_active = $_POST['comment_active'] ?? 0; $post_use_antispam = $_POST['comment_use_antispam'] ?? 0; @@ -1522,6 +1546,10 @@ function commentAdminSettingsEdit($tpl_dir) { $max_chars = (empty($post_max_chars) || $post_max_chars < 50) ? 50 : $post_max_chars; + // Валидация сортировки (ASC, DESC или RATING) + $allowed_sorts = ['ASC', 'DESC', 'RATING', 'USER_RATING']; + $sort_order = in_array(strtoupper($post_sort_order), $allowed_sorts) ? strtoupper($post_sort_order) : 'ASC'; + // Подготовка имен полей и настроек файлов $clean_name_f1 = htmlspecialchars(stripslashes($post_name_f1), ENT_QUOTES); $clean_name_f2 = htmlspecialchars(stripslashes($post_name_f2), ENT_QUOTES); @@ -1542,6 +1570,7 @@ function commentAdminSettingsEdit($tpl_dir) comment_page_nav_count = '" . (int)$post_page_nav_count . "', comment_ajax_replies_limit = '" . (int)$post_ajax_replies_limit . "', comment_allow_self_answer = '" . (int)$post_allow_self_answer . "', + comment_sort_order = '" . $sort_order . "', comment_allow_files = '" . (int)$post_allow_files . "', comment_allow_files_anon = '" . (int)$post_allow_files_anon . "', comment_allowed_extensions = '" . addslashes($clean_extensions) . "', diff --git a/lang/ru.txt b/lang/ru.txt index 732d8ff..d313944 100644 --- a/lang/ru.txt +++ b/lang/ru.txt @@ -122,9 +122,6 @@ COMMENT_JS_ERR_SRV = "Ошибка связи с сервером" COMMENT_WAITING_MODERATION = "Ваш комментарий на проверке и виден пока только вам." - - - [admin] COMMENT_MODULE_NAME = "Комментарии" COMMENT_MODULE_COMENTS = "Список комментариев" @@ -135,6 +132,11 @@ COMMENT_DOC_TITLE = "Документ" COMMENT_DATE_FORMAT = "%d/%m/%Y %H:%M" COMMENT_ENABLE_COMMENT = "Разрешить комментарии?" COMMENT_CHECK_ADMIN = "Опубликовывать только после проверки?" +COMMENT_SORT = "Сортировка:" +COMMENT_SORT_ASC = "Сначала старые (новые внизу)" +COMMENT_SORT_DESC = "Сначала новые (старые внизу)" +COMMENT_SORT_RATING = "По общему рейтингу (лучшие вверху)" +COMMENT_SORT_AUTOR_STARS = "По оценке автора (кол-ву звезд)" COMMENT_FOR_GROUPS = "Группы пользователей, которым разрешено оставлять комментарии:" COMMENT_MAX_CHARS = "Максимальное количество символов:" COMMENT_BUTTON_SAVE = "Сохранить настройки" diff --git a/sql.php b/sql.php index b6480f0..ec2ef92 100644 --- a/sql.php +++ b/sql.php @@ -45,7 +45,8 @@ `comment_edit_time` int(11) NOT NULL DEFAULT '60', `comment_cookie_life` int(11) NOT NULL DEFAULT '30', `comment_ajax_replies_limit` tinyint(3) NOT NULL DEFAULT '5', - `comment_allow_self_answer` tinyint(1) NOT NULL DEFAULT '0', + `comment_allow_self_answer` tinyint(1) NOT NULL DEFAULT '0', + `comment_sort_order` varchar(20) NOT NULL DEFAULT 'ASC', PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=1; "; @@ -96,10 +97,8 @@ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=1; "; - // Начальные настройки (Добавлен 0 в конце для comment_allow_self_answer) - $module_sql_install[] = "INSERT INTO `%%PRFX%%_module_comments` VALUES (1, 1000, '1,3', '1,2,3,4', '0', '1', '1' , '0', '', 1, 0, '', 1, 0, '', 0, 'jpg,jpeg,png,gif,webp', 2048, 5, 0, 1, 0, 0, 0, 0, 60, 30, 5, 0);"; + $module_sql_install[] = "INSERT INTO `%%PRFX%%_module_comments` VALUES (1, 1000, '1,3', '1,2,3,4', '0', '1', '1' , '0', '', 1, 0, '', 1, 0, '', 0, 'jpg,jpeg,png,gif,webp', 2048, 5, 0, 1, 0, 0, 0, 0, 60, 30, 5, 0, 'ASC');"; - // 3. ОБНОВЛЕНИЕ $module_sql_update[] = " UPDATE `%%PRFX%%_module` SET diff --git a/templates/admin_settings.tpl b/templates/admin_settings.tpl index 97cb6f5..334b950 100644 --- a/templates/admin_settings.tpl +++ b/templates/admin_settings.tpl @@ -42,6 +42,25 @@ + + {#COMMENT_USE_ANSWER_ALL#} + +
+ + {#COMMENT_USE_ANSWER_ALL_A#} +
+ + {#COMMENT_SORT#} + + + + + {#COMMENT_USE_PAGE_TITEL#} @@ -49,7 +68,10 @@ {#COMMENT_USE_PAGE_NAV#} {#COMMENT_PAGE_NAV_COUNT#} - {#COMMENT_USE_PAGE_NO_LIMIT#} + + + {#COMMENT_USE_PAGE_NO_LIMIT#} + {#COMMENT_USE_PAGE_ANSWER#} @@ -57,13 +79,8 @@ {#COMMENT_USE_PAGE_NO_LIMIT#} - {#COMMENT_USE_ANSWER_ALL#} - -
- - {#COMMENT_USE_ANSWER_ALL_A#} -
- + +