выбираем в админке либо звезды либо сердечки либо рейтинг отключен

This commit is contained in:
2025-12-20 23:55:02 +05:00
parent f7a4edbac3
commit 9cc11571a0
5 changed files with 86 additions and 29 deletions

View File

@@ -1214,6 +1214,9 @@ function commentPostDelete($comment_id)
// НОВОЕ: Настройка разрешения загрузки файлов
$post_allow_files = $_POST['comment_allow_files'] ?? 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;
@@ -1242,6 +1245,7 @@ function commentPostDelete($comment_id)
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 . "',

View File

@@ -121,8 +121,23 @@
// --- ЛОГИКА ГОЛОСОВАНИЯ (РЕЙТИНГ) ---
$doc.on('mouseenter', '.star-item', function() {
$(this).prevAll().addBack().removeClass('bi-star').addClass('bi-star-fill');
$(this).nextAll().removeClass('bi-star-fill').addClass('bi-star');
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');
}
});
$doc.on('mouseleave', '.star-item', function() {
var $parent = $(this).parent();
if ($parent.hasClass('comment-like')) {
$(this).css('transform', 'scale(1)');
}
});
$doc.on('mouseleave', '.comment-stars', function() {
@@ -135,18 +150,16 @@
var voteValue = $(this).data('value');
$.ajax({
// Используем относительный путь для избежания проблем с протоколом HTTPS/HTTP
url: 'index.php?module=comment&action=vote&ajax=1',
type: 'POST',
data: {
comment_id: commentId,
vote: voteValue,
ajax: 1 // Дублируем для надежности
ajax: 1
},
success: function(response) {
var res = response.toString().trim();
// Проверяем наличие ключевого слова в ответе (защита от варнингов PHP)
if (res.indexOf('success') !== -1) {
$container.html('<span class="text-success small fw-bold">Спасибо!</span>');
setTimeout(function(){ location.reload(); }, 1000);

17
sql.php
View File

@@ -3,7 +3,7 @@
/**
* AVE.cms - Модуль Комментарии
*
* Обновленная структура с поддержкой рейтинга (звезд),
* Обновленная структура с поддержкой выбора типа рейтинга (звезды/лайки),
* идентификации анонимных пользователей, загрузки файлов и защиты по IP.
*/
@@ -36,6 +36,7 @@ $module_sql_install[] = "CREATE TABLE `%%PRFX%%_module_comments` (
`comment_name_f2` varchar(255) NOT NULL default '',
`comment_allow_files` tinyint(1) NOT NULL default '0',
`comment_file_max_size` int(10) NOT NULL default '2048',
`comment_rating_type` tinyint(1) NOT NULL default '0', /* 0 - звезды, 1 - лайки */
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
@@ -48,7 +49,7 @@ $module_sql_install[] = "CREATE TABLE `%%PRFX%%_module_comment_info` (
`comment_author_email` varchar(255) NOT NULL,
`comment_author_city` varchar(255) NOT NULL,
`comment_author_website` varchar(255) NOT NULL,
`comment_author_ip` varchar(45) NOT NULL, /* Увеличено для поддержки IPv6 */
`comment_author_ip` varchar(45) NOT NULL,
`anon_key` varchar(32) DEFAULT NULL,
`comment_published` int(10) unsigned NOT NULL default '0',
`comment_changed` int(10) unsigned NOT NULL default '0',
@@ -66,13 +67,12 @@ $module_sql_install[] = "CREATE TABLE `%%PRFX%%_module_comment_info` (
KEY `anon_key` (`anon_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0;";
// Таблица для хранения истории голосов (Добавлено поле remote_addr для защиты по IP)
$module_sql_install[] = "CREATE TABLE `%%PRFX%%_module_comment_votes` (
`id` int(10) unsigned NOT NULL auto_increment,
`comment_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned DEFAULT '0',
`anon_key` varchar(32) DEFAULT '',
`remote_addr` varchar(45) DEFAULT '', /* Поле для хранения IP проголосовавшего */
`remote_addr` varchar(45) DEFAULT '',
`vote_value` tinyint(1) NOT NULL,
`date_voted` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
@@ -82,7 +82,8 @@ $module_sql_install[] = "CREATE TABLE `%%PRFX%%_module_comment_votes` (
KEY `remote_addr` (`remote_addr`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$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, 2048);";
/* Добавили 0 в конце для comment_rating_type */
$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, 2048, 0);";
// =================================================================================
// 2. ОБНОВЛЕНИЕ МОДУЛЯ (ALTER TABLE)
@@ -98,12 +99,13 @@ $module_sql_update[] = "
LIMIT 1;
";
// Добавляем поля рейтинга в существующую таблицу
/* Добавляем переключатель типа рейтинга, если его нет */
$module_sql_update[] = "ALTER TABLE `%%PRFX%%_module_comments` ADD COLUMN IF NOT EXISTS `comment_rating_type` TINYINT(1) NOT NULL DEFAULT '0';";
$module_sql_update[] = "ALTER TABLE `%%PRFX%%_module_comment_info` ADD `rating_sum` INT(10) NOT NULL DEFAULT '0';";
$module_sql_update[] = "ALTER TABLE `%%PRFX%%_module_comment_info` ADD `rating_count` INT(10) NOT NULL DEFAULT '0';";
$module_sql_update[] = "ALTER TABLE `%%PRFX%%_module_comment_info` MODIFY `comment_author_ip` VARCHAR(45) NOT NULL;";
// Создаем таблицу голосов с полем IP, если её еще нет
$module_sql_update[] = "CREATE TABLE IF NOT EXISTS `%%PRFX%%_module_comment_votes` (
`id` int(10) unsigned NOT NULL auto_increment,
`comment_id` int(10) unsigned NOT NULL,
@@ -119,7 +121,6 @@ $module_sql_update[] = "CREATE TABLE IF NOT EXISTS `%%PRFX%%_module_comment_vote
KEY `remote_addr` (`remote_addr`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
// Если таблица уже была, но поля remote_addr в ней нет — добавляем его
$module_sql_update[] = "ALTER TABLE `%%PRFX%%_module_comment_votes` ADD COLUMN IF NOT EXISTS `remote_addr` VARCHAR(45) DEFAULT '' AFTER `anon_key`;";
?>

View File

@@ -112,6 +112,29 @@
</td>
</tr>
<tr>
<td colspan="4" style="background: #f9f9f9; font-weight: bold; text-align: center;">Система оценки комментариев</td>
</tr>
<tr>
<td>Тип рейтинга:</td>
<td colspan="3">
<div style="display: flex; gap: 20px;">
<span style="display: flex; align-items: center;">
<input type="radio" name="comment_rating_type" id="type_stars" value="0" {if $comment_rating_type == '0'}checked="checked"{/if} style="margin-right: 5px; cursor: pointer;" />
<label for="type_stars" style="cursor: pointer; margin-bottom: 0;">Звезды (1-5)</label>
</span>
<span style="display: flex; align-items: center;">
<input type="radio" name="comment_rating_type" id="type_likes" value="1" {if $comment_rating_type == '1'}checked="checked"{/if} style="margin-right: 5px; cursor: pointer;" />
<label for="type_likes" style="cursor: pointer; margin-bottom: 0;">Лайк (Сердечко)</label>
</span>
<span style="display: flex; align-items: center;">
<input type="radio" name="comment_rating_type" id="type_none" value="2" {if $comment_rating_type == '2'}checked="checked"{/if} style="margin-right: 5px; cursor: pointer;" />
<label for="type_none" style="cursor: pointer; margin-bottom: 0; color: #d9534f;">Выключить рейтинг</label>
</span>
</div>
</td>
</tr>
<tr>
<td colspan="4" style="background: #f9f9f9; font-weight: bold; text-align: center;">Настройки медиафайлов</td>
</tr>

View File

@@ -28,24 +28,40 @@
<span class="me-2"><i class="bi bi-clock me-1"></i> {$c.comment_published}</span>
{* ----- БЛОК РЕЙТИНГА (ЗВЕЗДЫ) ----- *}
<div class="comment-rating-container d-inline-flex align-items-center ms-2 py-1 px-2 bg-light rounded border" data-id="{$c.Id}" style="line-height: 1;">
<div class="comment-stars d-inline-flex" style="cursor: pointer; color: #ffc107; font-size: 0.9rem;">
{assign var="avg_rating" value=0}
{if isset($c.rating_count) && $c.rating_count > 0}
{math equation="round(x / y)" x=$c.rating_sum y=$c.rating_count assign="avg_rating"}
{/if}
{* ----- БЛОК РЕЙТИНГА (ЗВЕЗДЫ ИЛИ ЛАЙКИ) ----- *}
{* Добавлена проверка на полное отключение (значение 2) *}
{if $comment_rating_type != 2}
<div class="comment-rating-container d-inline-flex align-items-center ms-2 py-1 px-2 bg-light rounded border" data-id="{$c.Id}" style="line-height: 1;">
{if $comment_rating_type == 1}
{* РЕЖИМ ЛАЙКОВ (СЕРДЕЧКО) *}
<div class="comment-like d-inline-flex align-items-center" style="cursor: pointer; color: #dc3545; font-size: 0.95rem;">
<i class="star-item bi bi-heart-fill me-1"
data-value="5"
title="Мне нравится"></i>
</div>
{if isset($c.rating_count)}
<span class="ms-1 text-muted fw-bold" style="font-size: 0.8rem;">{$c.rating_count}</span>
{/if}
{else}
{* РЕЖИМ ЗВЕЗД (1-5) - ПО УМОЛЧАНИЮ ПРИ 0 *}
<div class="comment-stars d-inline-flex" style="cursor: pointer; color: #ffc107; font-size: 0.9rem;">
{assign var="avg_rating" value=0}
{if isset($c.rating_count) && $c.rating_count > 0}
{math equation="round(x / y)" x=$c.rating_sum y=$c.rating_count assign="avg_rating"}
{/if}
{section name=star start=1 loop=6}
<i class="star-item bi {if $smarty.section.star.index <= $avg_rating}bi-star-fill{else}bi-star{/if} {if !$smarty.section.star.last}me-1{/if}"
data-value="{$smarty.section.star.index}"
title="Оценить на {$smarty.section.star.index}"></i>
{/section}
{section name=star start=1 loop=6}
<i class="star-item bi {if $smarty.section.star.index <= $avg_rating}bi-star-fill{else}bi-star{/if} {if !$smarty.section.star.last}me-1{/if}"
data-value="{$smarty.section.star.index}"
title="Оценить на {$smarty.section.star.index}"></i>
{/section}
</div>
{if isset($c.rating_count)}
<span class="ms-2 text-muted fw-bold" style="font-size: 0.8rem;">({$c.rating_count})</span>
{/if}
{/if}
</div>
{if isset($c.rating_count)}
<span class="ms-2 text-muted fw-bold" style="font-size: 0.8rem;">({$c.rating_count})</span>
{/if}
</div>
{/if}
{* --------------------------------- *}
{if $comment_show_f1 == 1 && $c.comment_author_website}