fix метода отображения комментариев + обновлен шаблон

This commit is contained in:
2026-04-24 19:25:38 +05:00
parent 455e8c4662
commit 2a93f47848
2 changed files with 114 additions and 112 deletions

View File

@@ -458,38 +458,51 @@ class Poll
* @param string $text
* @param string $title
*/
function pollCommentShow($tpl_dir, $lang_file, $pid, $theme, $errors='', $text='', $title='')
{
global $AVE_DB, $AVE_Template;
function pollCommentShow($tpl_dir, $lang_file, $pid, $theme, $errors='', $text='', $title='')
{
global $AVE_DB, $AVE_Template;
$AVE_Template->config_load($lang_file, 'displayform');
$AVE_Template->config_load($lang_file, 'displayform');
$pid = (int)$pid;
$row = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_poll
WHERE id = '" . $pid . "'
LIMIT 1
")->FetchRow();
$groups = explode(',', $row->poll_groups_id);
$row = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_poll
WHERE id = '" . $pid . "'
LIMIT 1
")->FetchRow();
if ($row->poll_status == 1 && $row->poll_can_comment == 1 && in_array(UGROUP, $groups))
{
$AVE_Template->assign('cancomment', 1);
}
$AVE_Template->assign('max_chars', $this->_commentwords);
if (!$row) {
$row = new stdClass();
$row->poll_groups_id = '';
$row->poll_status = 0;
$row->poll_can_comment = 0;
$row->poll_anti_spam = 0;
if (empty($errors)) $errors = "Опрос с ID {$pid} не найден";
}
if (isset($row->poll_anti_spam) && $row->poll_anti_spam == 1 && function_exists('imagettftext') && function_exists('imagejpeg'))
{
$AVE_Template->assign('anti_spam', 1);
}
$groups = explode(',', $row->poll_groups_id ?? '');
if (!empty($errors)) $AVE_Template->assign('errors', $errors);
if ($row->poll_status == 1 && $row->poll_can_comment == 1 && in_array(UGROUP, $groups))
{
$AVE_Template->assign('cancomment', 1);
}
$AVE_Template->assign('max_chars', $this->_commentwords);
$AVE_Template->assign('theme_folder', $theme);
$AVE_Template->assign('title', $title);
$AVE_Template->assign('text', $text);
$AVE_Template->display($tpl_dir . 'poll_form.tpl');
}
if (isset($row->poll_anti_spam) && $row->poll_anti_spam == 1 && function_exists('imagettftext') && function_exists('imagejpeg'))
{
$AVE_Template->assign('anti_spam', 1);
}
if (!empty($errors)) $AVE_Template->assign('errors', $errors);
$AVE_Template->assign('theme_folder', $theme);
$AVE_Template->assign('title', $title);
$AVE_Template->assign('text', $text);
$AVE_Template->display($tpl_dir . 'poll_form.tpl');
}
/**
* Метод создания нового комментария (UTF-8 Only)

View File

@@ -1,93 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{#POLL_ADD_COMMENT#}</title>
<link href="templates/{$theme_folder}/css/layout.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="templates/{$theme_folder}/js/common.js" type="text/javascript"></script>
</head>
{* Заголовок окна *}
<h5 class="mb-3 text-primary">{#POLL_ADD_COMMENT#}</h5>
<body id="body_popup">
<div id="poll_comment_wrapper">
{if $cancomment != 1}
<div class="alert alert-warning border-0 shadow-sm">
<i class="bi bi-exclamation-triangle me-2"></i>
{#POLL_COMMENT_ERROR#}
</div>
<div class="mt-4">
<button type="button" class="btn btn-secondary w-100" onclick="window.close();">
<i class="bi bi-x-lg me-1"></i> {#POLL_CLOSE_W#}
</button>
</div>
{else}
<form id="poll_form_ajax" method="post" action="index.php?module=poll&action=comment&pid={$smarty.request.pid|escape}">
{if $errors}
<div class="alert alert-danger">
<ul class="mb-0">
{foreach from=$errors item=error}<li>{$error|escape}</li>{/foreach}
</ul>
</div>
{/if}
<script type="text/javascript" language="JavaScript">
var aveabspath = '{$smarty.const.ABS_PATH}';
$(document).ready(function() {ldelim}
$('#comment_text')
.after('{#POLL_CHARSET_LEFT#} - <span class="charsLeft" id="charsLeft_new"></span>')
.limit({$max_chars},'#charsLeft_new');
$('#gpf').submit(function() {ldelim}
if ($('comment_title').val() == '') {ldelim}
alert("{#POLL_ENTER_TITLE#}");
$('comment_title').focus();
return false;
{rdelim}
if ($('comment_text').val() == '') {ldelim}
alert("{#POLL_ENTER_TEXT#}");
$('comment_text').focus();
return false;
{rdelim}
{if $anti_spam == 1}
if ($('#gbf #securecode').val() == '') {ldelim}
alert("{#POLL_ENTER_CODE#}");
$('#gbf #securecode').focus();
return false;
{rdelim}{/if}
{rdelim});
{rdelim});
</script>
<div class="mb-3">
<label for="comment_title" class="form-label fw-bold text-muted small uppercase">{#POLL_COMMENT_T#}</label>
<input name="comment_title" type="text" id="comment_title" class="form-control shadow-sm" value="{$title|escape}" placeholder="Введите заголовок...">
</div>
<h5>{#POLL_ADD_COMMENT#}</h5>
<div class="mb-3">
<label for="comment_text" class="form-label fw-bold text-muted small">{#POLL_COMMENT_M#}</label>
<textarea id="comment_text" name="comment_text" class="form-control shadow-sm" rows="6" maxlength="{$max_chars}">{$text}</textarea>
<div class="form-text text-end small">
{#POLL_CHARSET_LEFT#}: <span id="charsLeft_new" class="fw-bold text-primary">{$max_chars}</span>
</div>
</div>
<div id="module_content">
{if $cancomment != 1}
<p id="module_intro">{#POLL_COMMENT_ERROR#}</p>
<p>&nbsp;</p>
<p><input onclick="window.close();" type="button" class="button" value="{#POLL_CLOSE_W#}" /></p>
{else}
<form id="pf" method="post" action="index.php?module=poll&action=comment&pid={$smarty.request.pid|escape}">
{if $errors}<ul>
{foreach from=$errors item=error}<li>{$error|escape}</li>
{/foreach}
</ul>{/if}
<fieldset>
<legend><label for="l_Titel">{#POLL_COMMENT_T#}</label></legend>
<input name="comment_title" type="text" id="comment_title" style="width:250px" value="{$title|escape}" />
</fieldset><br />
{if $anti_spam == 1}
<div class="card bg-light border-0 mb-3 shadow-sm">
<div class="card-body p-2 text-center">
<label class="form-label d-block small mb-2">{#POLL_SECURE_CODE#}</label>
<img src="{$ABS_PATH}inc/captcha.php" alt="captcha" class="rounded mb-2 border" style="cursor:pointer" onclick="this.src=this.src+'?'+Math.random();">
<input name="securecode" type="text" id="securecode" class="form-control form-control-sm text-center mx-auto" style="max-width: 150px;" placeholder="{#POLL_ENTER_CODE#}">
</div>
</div>
{/if}
<fieldset>
<legend><label for="l_Text">{#POLL_COMMENT_M#}</label></legend>
{* <textarea onkeyup="javascript:textCounter(this.form.comment_text,this.form.charleft,{$max_chars});" onkeydown="javascript:textCounter(this.form.comment_text,this.form.charleft,{$max_chars});" style="width:98%; height:165px" name="comment_text" id="comment_text">{$text}</textarea>
<input type="text" size="6" name="charleft" value="{$max_chars}" /> {#POLL_CHARSET_LEFT#}
*}
<textarea id="comment_text" name="comment_text" cols="80" rows="15" style="width:98%; height:165px">{$text}</textarea>
</fieldset>
{if $anti_spam == 1}
<fieldset>
{*
<legend><label for="l_Text">{#POLL_SECURE_CODE#}</label></legend>
<img src="inc/antispam.php?cp_secureimage={$im}" alt="" width="121" height="41" border="0" /><br />
<br />
<small><span id="S_secure_{$im}"></span></small>
<input name="comment_code" type="text" id="comment_code" style="width:100px" maxlength="7" />
*}
<p>
<label>{#POLL_SECURE_CODE#}</label>
<span id="captcha"><img src="{$ABS_PATH}inc/captcha.php" alt="" width="120" height="60" border="0" /></span><br />
<label>{#POLL_ENTER_CODE#}</label><br />
<input name="securecode" type="text" id="securecode" maxlength="10" /><br />
</p>
</fieldset>
{/if}
<p>
<input type="submit" class="button" value="{#POLL_BUTTON_ADD_C#}" />&nbsp;
<input type="reset" class="button" value="{#POLL_BUTTON_RESET#}" />
</p>
</form>
{/if}
<div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
<button type="reset" class="btn btn-light border">{#POLL_BUTTON_RESET#}</button>
<button type="submit" class="btn btn-primary px-4 shadow">
<i class="bi bi-send-fill me-1"></i> {#POLL_BUTTON_ADD_C#}
</button>
</div>
</form>
{/if}
</div>
</body>
</html>
<script>
$(document).ready(function() {
// Счетчик символов
$('#comment_text').on('input', function() {
var limit = {$max_chars};
var length = $(this).val().length;
$('#charsLeft_new').text(limit - length);
});
// Валидация
$('#poll_form_ajax').on('submit', function() {
if ($('#comment_title').val().trim() == '') {
alert("{#POLL_ENTER_TITLE#}");
$('#comment_title').focus();
return false;
}
if ($('#comment_text').val().trim().length < 10) {
alert("{#POLL_ENTER_TEXT#}");
$('#comment_text').focus();
return false;
}
return true;
});
});
</script>