diff --git a/class/comment.php b/class/comment.php
index 4b6324f..449bad9 100644
--- a/class/comment.php
+++ b/class/comment.php
@@ -496,6 +496,11 @@ function commentListShow($tpl_dir)
$new_comment['comment_status'] = $comment_status;
$new_comment['comment_file'] = $comment_file_name;
+ // --- ВОТ ЭТИ ТРИ СТРОЧКИ: ПОЛУЧАЕМ РЕЙТИНГ ИЗ ФОРМЫ ---
+ $user_rating = (int)($_POST['comment_user_rating'] ?? 0);
+ if ($user_rating < 0) $user_rating = 0; if ($user_rating > 5) $user_rating = 5;
+ $new_comment['user_rating'] = $user_rating;
+
$comment_text_raw = $_POST['comment_text'] ?? '';
$comment_max_chars = $settings['comment_max_chars'];
$comment_max_chars = (!empty($comment_max_chars) && $comment_max_chars > 10) ? $comment_max_chars : 200;
@@ -648,6 +653,10 @@ function commentPostEdit($comment_id)
$new_file_sql = ", comment_file = ''";
}
+ // --- ВОТ ЭТО ДОБАВИЛ ---
+ $user_rating = isset($_POST['user_rating']) ? (int)$_POST['user_rating'] : (int)$row['user_rating'];
+ // -----------------------
+
// 6. Обновление базы данных
// Если в настройках стоит "нужна премодерация", после правки статус меняется на 0 (если не админ)
$new_status = $is_admin ? (int)$row['comment_status'] : ($row['comment_need_approve'] == '1' ? 0 : 1);
@@ -657,7 +666,8 @@ function commentPostEdit($comment_id)
SET
comment_changed = '" . time() . "',
comment_text = '" . addslashes($comment_text_cut) . "',
- comment_status = '" . $new_status . "'
+ comment_status = '" . $new_status . "',
+ user_rating = '" . $user_rating . "'
$new_file_sql
WHERE
Id = '" . $comment_id . "'
@@ -780,6 +790,7 @@ function commentPostDelete($comment_id)
/**
* Метод для обработки голосования за комментарий
* Защита: ID для залогиненных, Пара (Ключ + IP) для анонимов.
+ * Добавлена проверка глобальной настройки прав для анонимов.
*/
function commentVote()
{
@@ -807,6 +818,18 @@ function commentPostDelete($comment_id)
$user_id = empty($_SESSION['user_id']) ? 0 : (int)$_SESSION['user_id'];
$anon_key = $this->_getAnonKey();
+ // 1.5 ПРОВЕРКА ПРАВ ГОЛОСОВАНИЯ (Новое)
+ // Получаем настройки модуля, чтобы узнать, разрешено ли анонимам голосовать
+ $settings = $this->_commentSettingsGet();
+ if (empty($user_id) && empty($settings['comment_rating_anon_vote'])) {
+ if ($ajax) {
+ if (ob_get_length()) ob_end_clean();
+ echo 'forbidden_anon'; // Специальный статус для JS
+ exit;
+ }
+ return;
+ }
+
// 2. Получаем данные о комментарии, за который голосуют
$comment_row = $AVE_DB->Query("
SELECT comment_author_id, anon_key, comment_author_ip
@@ -1189,82 +1212,92 @@ function commentPostDelete($comment_id)
}
/**
-/**
-/**
- * Метод, предназначенный для управления настройками модуля
- *
- * @param string $tpl_dir - путь к шаблонам модуля
- */
- function commentAdminSettingsEdit($tpl_dir)
- {
- global $AVE_DB, $AVE_Template;
+ * Метод, предназначенный для управления настройками модуля
+ *
+ * @param string $tpl_dir - путь к шаблонам модуля
+ */
+function commentAdminSettingsEdit($tpl_dir)
+{
+ global $AVE_DB, $AVE_Template;
- $request_sub = $_REQUEST['sub'] ?? '';
- $post_max_chars = $_POST['comment_max_chars'] ?? 0;
- $post_user_groups = $_POST['comment_user_groups'] ?? array();
-
- $post_user_groups_read = $_POST['comment_user_groups_read'] ?? array();
-
- $post_need_approve = $_POST['comment_need_approve'] ?? 0;
- $post_active = $_POST['comment_active'] ?? 0;
- $post_use_antispam = $_POST['comment_use_antispam'] ?? 0;
- $post_use_page_nav = $_POST['comment_use_page_nav'] ?? 0;
- $post_page_nav_count = $_POST['comment_page_nav_count'] ?? 0;
+ $request_sub = $_REQUEST['sub'] ?? '';
+ $post_max_chars = $_POST['comment_max_chars'] ?? 0;
+ $post_user_groups = $_POST['comment_user_groups'] ?? array();
+
+ $post_user_groups_read = $_POST['comment_user_groups_read'] ?? array();
+
+ $post_need_approve = $_POST['comment_need_approve'] ?? 0;
+ $post_active = $_POST['comment_active'] ?? 0;
+ $post_use_antispam = $_POST['comment_use_antispam'] ?? 0;
+ $post_use_page_nav = $_POST['comment_use_page_nav'] ?? 0;
+ $post_page_nav_count = $_POST['comment_page_nav_count'] ?? 0;
- // НОВОЕ: Настройка разрешения загрузки файлов
- $post_allow_files = $_POST['comment_allow_files'] ?? 0;
+ // НОВОЕ: Настройка разрешения загрузки файлов
+ $post_allow_files = $_POST['comment_allow_files'] ?? 0;
- // НОВОЕ: Тип рейтинга (0 - звезды, 1 - лайки)
- $post_rating_type = $_POST['comment_rating_type'] ?? 0;
+ // НОВОЕ: Тип рейтинга (0 - звезды, 1 - лайки)
+ $post_rating_type = $_POST['comment_rating_type'] ?? 0;
- // Данные для универсальных полей
- $post_show_f1 = $_POST['comment_show_f1'] ?? 0;
- $post_req_f1 = $_POST['comment_req_f1'] ?? 0;
- $post_name_f1 = $_POST['comment_name_f1'] ?? '';
+ // НОВОЕ: ВКЛ/ВЫКЛ авторских звезд
+ $post_show_user_rating = $_POST['comment_show_user_rating'] ?? 0;
- $post_show_f2 = $_POST['comment_show_f2'] ?? 0;
- $post_req_f2 = $_POST['comment_req_f2'] ?? 0;
- $post_name_f2 = $_POST['comment_name_f2'] ?? '';
+ // НОВОЕ: Разрешение голосования анонимам
+ $post_rating_anon_vote = $_POST['comment_rating_anon_vote'] ?? 0;
- if ($request_sub == 'save')
- {
- $max_chars = (empty($post_max_chars) || $post_max_chars < 50) ? 50 : $post_max_chars;
+ // НОВОЕ: Разрешение анонимам ставить звезды (Авторский рейтинг)
+ $post_rating_anon_set = $_POST['comment_rating_anon_set'] ?? 0;
- $clean_name_f1 = htmlspecialchars(stripslashes($post_name_f1), ENT_QUOTES);
- $clean_name_f2 = htmlspecialchars(stripslashes($post_name_f2), ENT_QUOTES);
+ // Данные для универсальных полей
+ $post_show_f1 = $_POST['comment_show_f1'] ?? 0;
+ $post_req_f1 = $_POST['comment_req_f1'] ?? 0;
+ $post_name_f1 = $_POST['comment_name_f1'] ?? '';
- $AVE_DB->Query("
- UPDATE " . PREFIX . "_module_comments
- SET
- comment_max_chars = '" . (int)$max_chars . "',
- comment_user_groups = '" . implode(',', $post_user_groups) . "',
- comment_user_groups_read = '" . implode(',', $post_user_groups_read) . "',
- comment_need_approve = '" . (int)$post_need_approve . "',
- comment_active = '" . (int)$post_active . "',
- comment_use_antispam = '" . (int)$post_use_antispam . "',
- comment_use_page_nav = '" . (int)$post_use_page_nav . "',
- comment_page_nav_count = '" . (int)$post_page_nav_count . "',
- comment_allow_files = '" . (int)$post_allow_files . "',
- comment_rating_type = '" . (int)$post_rating_type . "',
- comment_show_f1 = '" . (int)$post_show_f1 . "',
- comment_req_f1 = '" . (int)$post_req_f1 . "',
- comment_name_f1 = '" . $clean_name_f1 . "',
- comment_show_f2 = '" . (int)$post_show_f2 . "',
- comment_req_f2 = '" . (int)$post_req_f2 . "',
- comment_name_f2 = '" . $clean_name_f2 . "'
- WHERE
- Id = 1
- ");
- }
+ $post_show_f2 = $_POST['comment_show_f2'] ?? 0;
+ $post_req_f2 = $_POST['comment_req_f2'] ?? 0;
+ $post_name_f2 = $_POST['comment_name_f2'] ?? '';
- $row = $this->_commentSettingsGet();
-
- $row['comment_user_groups'] = explode(',', $row['comment_user_groups']);
- $row['comment_user_groups_read'] = explode(',', $row['comment_user_groups_read']);
+ if ($request_sub == 'save')
+ {
+ $max_chars = (empty($post_max_chars) || $post_max_chars < 50) ? 50 : $post_max_chars;
- $AVE_Template->assign($row);
- $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . $this->_admin_settings_tpl));
- }
+ $clean_name_f1 = htmlspecialchars(stripslashes($post_name_f1), ENT_QUOTES);
+ $clean_name_f2 = htmlspecialchars(stripslashes($post_name_f2), ENT_QUOTES);
+
+ $AVE_DB->Query("
+ UPDATE " . PREFIX . "_module_comments
+ SET
+ comment_max_chars = '" . (int)$max_chars . "',
+ comment_user_groups = '" . implode(',', $post_user_groups) . "',
+ comment_user_groups_read = '" . implode(',', $post_user_groups_read) . "',
+ comment_need_approve = '" . (int)$post_need_approve . "',
+ comment_active = '" . (int)$post_active . "',
+ comment_use_antispam = '" . (int)$post_use_antispam . "',
+ comment_use_page_nav = '" . (int)$post_use_page_nav . "',
+ comment_page_nav_count = '" . (int)$post_page_nav_count . "',
+ comment_allow_files = '" . (int)$post_allow_files . "',
+ comment_rating_type = '" . (int)$post_rating_type . "',
+ comment_show_user_rating = '" . (int)$post_show_user_rating . "',
+ comment_rating_anon_vote = '" . (int)$post_rating_anon_vote . "',
+ comment_rating_anon_set = '" . (int)$post_rating_anon_set . "',
+ comment_show_f1 = '" . (int)$post_show_f1 . "',
+ comment_req_f1 = '" . (int)$post_req_f1 . "',
+ comment_name_f1 = '" . $clean_name_f1 . "',
+ comment_show_f2 = '" . (int)$post_show_f2 . "',
+ comment_req_f2 = '" . (int)$post_req_f2 . "',
+ comment_name_f2 = '" . $clean_name_f2 . "'
+ WHERE
+ Id = 1
+ ");
+ }
+
+ $row = $this->_commentSettingsGet();
+
+ $row['comment_user_groups'] = explode(',', $row['comment_user_groups']);
+ $row['comment_user_groups_read'] = explode(',', $row['comment_user_groups_read']);
+
+ $AVE_Template->assign($row);
+ $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . $this->_admin_settings_tpl));
+}
}
?>
\ No newline at end of file
diff --git a/js/comment.js b/js/comment.js
index 42efdad..302b397 100644
--- a/js/comment.js
+++ b/js/comment.js
@@ -119,14 +119,77 @@
initCommentTimers();
var $doc = $(document);
- // --- ЛОГИКА ГОЛОСОВАНИЯ (РЕЙТИНГ) ---
+ // --- ЛОГИКА ВЫБОРА РЕЙТИНГА В ФОРМЕ (НОВОЕ) ---
+ $doc.on('mouseenter', '.star-choice', function() {
+ var val = $(this).data('value');
+ $(this).parent().find('.star-choice').each(function() {
+ if ($(this).data('value') <= val) {
+ $(this).removeClass('bi-star').addClass('bi-star-fill');
+ } else {
+ $(this).removeClass('bi-star-fill').addClass('bi-star');
+ }
+ });
+ });
+
+ $doc.on('mouseleave', '.rating-edit-block', function() {
+ var cid = $(this).find('input[type="hidden"]').attr('id').replace('rating_input_', '');
+ var currentRating = parseInt($('#rating_input_' + cid).val()) || 0;
+ $(this).find('.star-choice').each(function() {
+ if ($(this).data('value') <= currentRating) {
+ $(this).removeClass('bi-star').addClass('bi-star-fill');
+ } else {
+ $(this).removeClass('bi-star-fill').addClass('bi-star');
+ }
+ });
+ });
+
+ // Универсальный обработчик клика по звездам (и в новой форме, и в ред.)
+ $doc.on('click', '.star-choice', function() {
+ var val = $(this).data('value');
+ var $parent = $(this).parent();
+
+ // 1. Ищем инпут для формы редактирования (он находится внутри .rating-edit-block)
+ var ratingInput = $(this).closest('.rating-edit-block').find('input[type="hidden"]');
+
+ if (ratingInput.length) {
+ ratingInput.val(val);
+ } else {
+ // 2. Ищем инпут для основной формы (по ID)
+ $('#comment_user_rating').val(val);
+ }
+
+ // Визуально фиксируем звезды сразу после клика
+ $(this).prevAll().addBack().removeClass('bi-star').addClass('bi-star-fill');
+ $(this).nextAll().removeClass('bi-star-fill').addClass('bi-star');
+ });
+
+ // Сброс звезд при очистке всей формы (кнопка Reset)
+ $doc.on('click', '#buttonReset', function() {
+ $('#comment_user_rating').val(0);
+ $('#user_rating_stars .star-choice').removeClass('bi-star-fill').addClass('bi-star');
+ });
+
+ // Сброс только звезд по кнопке "Сбросить" в основной форме
+ $doc.on('click', '#reset_stars', function(e) {
+ e.preventDefault();
+ $('#comment_user_rating').val(0);
+ $('#user_rating_stars .star-choice').removeClass('bi-star-fill').addClass('bi-star');
+ });
+
+ // Сброс звезд в форме редактирования
+ $doc.on('click', '.reset-edit-stars', function(e) {
+ e.preventDefault();
+ var cid = $(this).data('id');
+ $('#rating_input_' + cid).val(0);
+ $('#user_rating_stars_' + cid + ' .star-choice').removeClass('bi-star-fill').addClass('bi-star');
+ });
+
+ // --- ЛОГИКА ГОЛОСОВАНИЯ (РЕЙТИНГ УЖЕ ОПУБЛИКОВАННЫХ) ---
$doc.on('mouseenter', '.star-item', function() {
var $parent = $(this).parent();
- // Если это лайки (сердце)
if ($parent.hasClass('comment-like')) {
$(this).css('transform', 'scale(1.2)');
}
- // Если это звезды
else {
$(this).prevAll().addBack().removeClass('bi-star').addClass('bi-star-fill');
$(this).nextAll().removeClass('bi-star-fill').addClass('bi-star');
@@ -140,10 +203,6 @@
}
});
- $doc.on('mouseleave', '.comment-stars', function() {
- // При уходе мыши визуально ничего не меняем до клика или рефреша
- });
-
$doc.on('click', '.star-item', function() {
var $container = $(this).closest('.comment-rating-container');
var commentId = $container.data('id');
@@ -159,7 +218,6 @@
},
success: function(response) {
var res = response.toString().trim();
-
if (res.indexOf('success') !== -1) {
$container.html('Спасибо!');
setTimeout(function(){ location.reload(); }, 1000);
@@ -167,18 +225,20 @@
alert('Вы уже голосовали за этот комментарий.');
} else if (res.indexOf('own_comment') !== -1) {
alert('Нельзя голосовать за свой собственный комментарий.');
- } else {
- console.warn("Server response:", response);
+ }
+ /* НОВОЕ: Обработка запрета голосования для незарегистрированных пользователей */
+ else if (res.indexOf('forbidden_anon') !== -1) {
+ alert('Голосование доступно только зарегистрированным пользователям.');
+ }
+ else {
alert('Ошибка при обработке голоса сервером.');
}
},
error: function(xhr) {
- console.error("XHR Status:", xhr.status);
alert('Ошибка связи с сервером. Статус: ' + xhr.status);
}
});
});
- // ------------------------------------
// Глобальные кнопки управления
$doc.on('click', '#mod_comment_close', function(e) {
@@ -193,13 +253,9 @@
e.preventDefault();
var cid = $(this).data('id');
var $form = $('#mod_comment_new');
-
$form.insertAfter('#comment_' + cid).show();
$('#parent_id').val(cid);
-
- $('html, body').animate({
- scrollTop: $form.offset().top - 150
- }, 500);
+ $('html, body').animate({ scrollTop: $form.offset().top - 150 }, 500);
$('#in_message').focus();
});
@@ -215,7 +271,7 @@
cAction(this, $(this).hasClass('mod_comment_lock') ? 'lock' : 'unlock');
});
- // Редактирование
+ // --- РЕДАКТИРОВАНИЕ (ОБНОВЛЕННОЕ С ПРОВЕРКОЙ is_my_own) ---
$doc.off('click', '.mod_comment_edit').on('click', '.mod_comment_edit', function(e) {
e.preventDefault();
var cid = $(this).data('id');
@@ -224,15 +280,49 @@
if ($wrapper.find('.edit-form-container').length > 0) return;
+ // ПРОВЕРКА АВТОРСТВА: используем флаг is_my_own из атрибута шаблона
+ var isMyOwn = $wrapper.attr('data-is-own') == '1';
+ var currentRating = parseInt($wrapper.attr('data-user-rating')) || 0;
+
$('.edit-form-container').remove();
$('.mod_comment_text').show();
var cleanText = $textBlock.html().replace(/
/mg, "\n").trim();
var currentImg = $wrapper.find('.mod_comment_attached_image img').first().attr('src');
+ // Рисуем звезды ТОЛЬКО если настройка включена И это собственный комментарий (is_my_own)
+ var starsEditBlock = '';
+ if (typeof SHOW_USER_RATING !== 'undefined' && SHOW_USER_RATING == '1' && isMyOwn) {
+
+ // ВНЕДРЕНИЕ: Проверка прав группы (Авторизован или разрешено анонимам)
+ if (typeof UGROUP !== 'undefined' && (UGROUP != '2' || RATING_ANON_SET == '1')) {
+
+ var starsHtml = '';
+ for(var i=1; i<=5; i++) {
+ var starClass = (i <= currentRating) ? 'bi-star-fill' : 'bi-star';
+ starsHtml += ``;
+ }
+
+ starsEditBlock = `
+
{#COMMENT_CHARS_LEFT#} @@ -249,6 +274,10 @@ var DOC_ID = '{$doc_id}'; var MAX_CHARS = '{$comment_max_chars}'; var aveabspath = '{$ABS_PATH}'; + + // Глобальная переменная для JS + var SHOW_USER_RATING = '{$comment_show_user_rating|default:0}'; + var RATING_ANON_SET = '{$comment_rating_anon_set|default:0}';