Добавляем возможность гостевого комментирования топиков
Тестировалось на LS 0.4, но, думаю, пойдет и на более старших версиях.
У вас должен быть в базе пользователь с ником Guest!
Открываем файл /classes/actions/ActionBlog.class.php
Находим функцию SubmitComment()
заменяем в ней:
на:
далее
на:
и вот еще
на
В файле /include/ajax/commentResponse.php меняем:
на:
В файле /templates/skin/<имя скина>/comment_tree.tpl меняем
на
и еще:
на
В /templates/skin/<имя скина>/comment.tpl
на
В /templates/skin/<имя скина>/js/comments.js в функции addComment перед
и в хидер вставляем
п.с. с плагинами не дружу :(
сорри за возможный говнокод
У вас должен быть в базе пользователь с ником Guest!
Открываем файл /classes/actions/ActionBlog.class.php
Находим функцию SubmitComment()
заменяем в ней:
if (!$this->User_IsAuthorization()) {
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
return;
}
на:
if (!$this->User_IsAuthorization() and (getRequest('is_guest') != '1')) {
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
return;
}
$guest = false;
if (getRequest('is_guest') == '1') {
if (!isset($_SESSION['captcha_keystring']) or $_SESSION['captcha_keystring']!=strtolower(getRequest('captcha'))) {
$this->Message_AddError($this->Lang_Get('registration_captcha_error'),$this->Lang_Get('error'));
$bError=true;
return false;
}
unset($_SESSION['captcha_keystring']);
$this->oUserCurrent = $this->User_GetUserByLogin('Guest');
$guest = true;
}
далее
$sText=$this->Text_Parser(getRequest('comment_text'));
на:
if ($guest) {
$sText = nl2br(strip_tags(getRequest('comment_text'))); //ну либо парсер настраивайте на гостя
} else {
$sText=$this->Text_Parser(getRequest('comment_text'));
}
и вот еще
if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'),$this->Lang_Get('error'));
return;
}
на
if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator() and !$guest) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'),$this->Lang_Get('error'));
return;
}
В файле /include/ajax/commentResponse.php меняем:
if ($oEngine->User_IsAuthorization()) {
$oUserCurrent=$oEngine->User_GetUserCurrent();
if ($oTopic=$oEngine->Topic_GetTopicById($idTopic)) {
$aReturn=$oEngine->Comment_GetCommentsNewByTargetId($oTopic->getId(),'topic',$idCommentLast);
$iMaxIdComment=$aReturn['iMaxIdComment'];
$oTopicRead=Engine::GetEntity('Topic_TopicRead');
$oTopicRead->setTopicId($oTopic->getId());
$oTopicRead->setUserId($oUserCurrent->getId());
$oTopicRead->setCommentCountLast($oTopic->getCountComment());
$oTopicRead->setCommentIdLast($iMaxIdComment);
$oTopicRead->setDateRead(date("Y-m-d H:i:s"));
$oEngine->Topic_SetTopicRead($oTopicRead);
$aCmts=$aReturn['comments'];
if ($aCmts and is_array($aCmts)) {
foreach ($aCmts as $aCmt) {
$aComments[]=array(
'html' => $aCmt['html'],
'idParent' => $aCmt['obj']->getPid(),
'id' => $aCmt['obj']->getId(),
);
}
}
$bStateError=false;
} else {
$sMsgTitle=$oEngine->Lang_Get('error');
$sMsg=$oEngine->Lang_Get('system_error');
}
} else {
$sMsgTitle=$oEngine->Lang_Get('error');
$sMsg=$oEngine->Lang_Get('need_authorization');
}
на:
if ($oEngine->User_IsAuthorization()) {
$oUserCurrent=$oEngine->User_GetUserCurrent();
}
if ($oTopic=$oEngine->Topic_GetTopicById($idTopic)) {
$aReturn=$oEngine->Comment_GetCommentsNewByTargetId($oTopic->getId(),'topic',$idCommentLast);
$iMaxIdComment=$aReturn['iMaxIdComment'];
if ($oEngine->User_IsAuthorization()) {
$oTopicRead=Engine::GetEntity('Topic_TopicRead');
$oTopicRead->setTopicId($oTopic->getId());
$oTopicRead->setUserId($oUserCurrent->getId());
$oTopicRead->setCommentCountLast($oTopic->getCountComment());
$oTopicRead->setCommentIdLast($iMaxIdComment);
$oTopicRead->setDateRead(date("Y-m-d H:i:s"));
$oEngine->Topic_SetTopicRead($oTopicRead);
}
$aCmts=$aReturn['comments'];
if ($aCmts and is_array($aCmts)) {
foreach ($aCmts as $aCmt) {
$aComments[]=array(
'html' => $aCmt['html'],
'idParent' => $aCmt['obj']->getPid(),
'id' => $aCmt['obj']->getId(),
);
}
}
$bStateError=false;
} else {
$sMsgTitle=$oEngine->Lang_Get('error');
$sMsg=$oEngine->Lang_Get('system_error');
}
В файле /templates/skin/<имя скина>/comment_tree.tpl меняем
{if $oUserCurrent}
<div class="update" id="update">
<div class="tl"></div>
<div class="wrapper">
<div class="refresh">
<img class="update-comments" id="update-comments" alt="" src="{cfg name='path.static.skin'}/images/update.gif" onclick="lsCmtTree.responseNewComment({$iTargetId},'{$sTargetType}',this); return false;"/>
</div>
<div class="new-comments" id="new-comments" style="display: none;" onclick="lsCmtTree.goNextComment();">
</div>
</div>
<div class="bl"></div>
</div>
{/if}
на
<div class="update" id="update">
<div class="tl"></div>
<div class="wrapper">
<div class="refresh">
<img class="update-comments" id="update-comments" alt="" src="{cfg name='path.static.skin'}/images/update.gif" onclick="lsCmtTree.responseNewComment({$iTargetId},'{$sTargetType}',this); return false;"/>
</div>
<div class="new-comments" id="new-comments" style="display: none;" onclick="lsCmtTree.goNextComment();">
</div>
</div>
<div class="bl"></div>
</div>
и еще:
{if $bAllowNewComment}
{$sNoticeNotAllow}
{else}
{if $oUserCurrent}
<h3 class="reply-title"><a href="javascript:lsCmtTree.toggleCommentForm(0);">{$sNoticeCommentAdd}</a></h3>
<div class="comment"><div class="content"><div class="text" id="comment_preview_0" style="display: none;"></div></div></div>
<div style="display: block;" id="reply_0" class="reply">
{if !$oConfig->GetValue('view.tinymce')}
<div class="panel_form" style="background: #eaecea; margin-top: 2px;">
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','b'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/bold_ru.gif" width="20" height="20" title="{$aLang.panel_b}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','i'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/italic_ru.gif" width="20" height="20" title="{$aLang.panel_i}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','u'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/underline_ru.gif" width="20" height="20" title="{$aLang.panel_u}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','s'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/strikethrough.gif" width="20" height="20" title="{$aLang.panel_s}"></a>
<a href="#" onclick="lsPanel.putTagUrl('form_comment_text','{$aLang.panel_url_promt}'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/link.gif" width="20" height="20" title="{$aLang.panel_url}"></a>
<a href="#" onclick="lsPanel.putQuote('form_comment_text'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/quote.gif" width="20" height="20" title="{$aLang.panel_quote}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','code'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/code.gif" width="30" height="20" title="{$aLang.panel_code}"></a>
</div>
{/if}
<form action="" method="POST" id="form_comment" onsubmit="return false;" enctype="multipart/form-data">
{hook run='form_add_comment_begin'}
<textarea name="comment_text" id="form_comment_text" style="width: 100%; height: 100px;"></textarea>
{hook run='form_add_comment_end'}
<input type="submit" name="submit_preview" value="{$aLang.comment_preview}" onclick="lsCmtTree.preview($('form_comment_reply').getProperty('value')); return false;" />
<input type="submit" name="submit_comment" value="{$aLang.comment_add}" onclick="lsCmtTree.addComment('form_comment',{$iTargetId},'{$sTargetType}'); return false;">
<input type="hidden" name="reply" value="" id="form_comment_reply">
<input type="hidden" name="cmt_target_id" value="{$iTargetId}">
</form>
</div>
{else}
{$aLang.comment_unregistered}
{/if}
{/if}
на
{if $bAllowNewComment}
{$sNoticeNotAllow}
{else}
{if $oUserCurrent}
<h3 class="reply-title"><a href="javascript:lsCmtTree.toggleCommentForm(0);">{$sNoticeCommentAdd}</a></h3>
<div class="comment"><div class="content"><div class="text" id="comment_preview_0" style="display: none;"></div></div></div>
<div style="display: block;" id="reply_0" class="reply">
{if !$oConfig->GetValue('view.tinymce')}
<div class="panel_form" style="background: #eaecea; margin-top: 2px;">
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','b'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/bold_ru.gif" width="20" height="20" title="{$aLang.panel_b}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','i'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/italic_ru.gif" width="20" height="20" title="{$aLang.panel_i}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','u'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/underline_ru.gif" width="20" height="20" title="{$aLang.panel_u}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','s'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/strikethrough.gif" width="20" height="20" title="{$aLang.panel_s}"></a>
<a href="#" onclick="lsPanel.putTagUrl('form_comment_text','{$aLang.panel_url_promt}'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/link.gif" width="20" height="20" title="{$aLang.panel_url}"></a>
<a href="#" onclick="lsPanel.putQuote('form_comment_text'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/quote.gif" width="20" height="20" title="{$aLang.panel_quote}"></a>
<a href="#" onclick="lsPanel.putTagAround('form_comment_text','code'); return false;" class="button"><img src="{cfg name='path.static.skin'}/images/panel/code.gif" width="30" height="20" title="{$aLang.panel_code}"></a>
</div>
{/if}
<form action="" method="POST" id="form_comment" onsubmit="return false;" enctype="multipart/form-data">
{hook run='form_add_comment_begin'}
<textarea name="comment_text" id="form_comment_text" style="width: 100%; height: 100px;"></textarea>
{hook run='form_add_comment_end'}
<input type="submit" name="submit_preview" value="{$aLang.comment_preview}" onclick="lsCmtTree.preview($('form_comment_reply').getProperty('value')); return false;" />
<input type="submit" name="submit_comment" value="{$aLang.comment_add}" onclick="lsCmtTree.addComment('form_comment',{$iTargetId},'{$sTargetType}'); return false;">
<input type="hidden" name="reply" value="" id="form_comment_reply">
<input type="hidden" name="cmt_target_id" value="{$iTargetId}">
</form>
</div>
{else}
<h3 class="reply-title"><a href="javascript:lsCmtTree.toggleCommentForm(0);">{$sNoticeCommentAdd}</a></h3>
<div class="comment"><div class="content"><div class="text" id="comment_preview_0" style="display: none;"></div></div></div>
<div style="display: block;" id="reply_0" class="reply">
<form action="" method="POST" id="form_comment" onsubmit="return false;" enctype="multipart/form-data">
<span class="form_note">Вы — гость, и вам запрещено использовать HTML-теги.</span><br />
<textarea name="comment_text" id="form_comment_text" style="width: 100%; height: 100px;"></textarea>
<img src="{cfg name='path.root.engine_lib'}/external/kcaptcha/index.php?{$_sPhpSessionName}={$_sPhpSessionId}" name="commentCaptcha" onclick="this.src='{cfg name='path.root.engine_lib'}/external/kcaptcha/index.php?{$_sPhpSessionName}={$_sPhpSessionId}&n='+Math.random();"><br />
<span class="form_note">Ты знаешь, что делать →</span> <input type="text" class="input-text" style="width: 80px;" name="captcha" value="" maxlength=3 /><br /> <br />
<input type="hidden" name="is_guest" value="1">
<input type="submit" name="submit_comment" value="{$aLang.comment_add}" onclick="lsCmtTree.addComment('form_comment',{$iTargetId},'{$sTargetType}'); return false;">
<input type="hidden" name="reply" value="" id="form_comment_reply">
<input type="hidden" name="cmt_target_id" value="{$iTargetId}">
</form>
</div>
{/if}
{/if}
В /templates/skin/<имя скина>/comment.tpl
{if $oUserCurrent and !$oComment->getDelete() and !$bAllowNewComment}
<li><a href="javascript:lsCmtTree.toggleCommentForm({$oComment->getId()});" class="reply-link">{$aLang.comment_answer}</a></li>
{/if}
на
{if !$oComment->getDelete() and !$bAllowNewComment}
<li><a href="javascript:lsCmtTree.toggleCommentForm({$oComment->getId()});" class="reply-link">{$aLang.comment_answer}</a></li>
{/if}
В /templates/skin/<имя скина>/js/comments.js в функции addComment перед
thisObj.responseNewComment(targetId,targetType,$('update-comments'),result.sCommentId,true);
вставить
updateCaptcha();
и в хидер вставляем
{literal}
<script language="JavaScript" type="text/javascript">
function updateCaptcha() {
if (document.commentCaptcha) {
{/literal}
document.commentCaptcha.src="{cfg name='path.root.engine_lib'}/external/kcaptcha/index.php?{$_sPhpSessionName}={$_sPhpSessionId}&n='+Math.random();
{literal}
}
}
</script>
{/literal}
п.с. с плагинами не дружу :(
сорри за возможный говнокод
7 комментариев
Разделить пользователей на 2 категории: «Участники» и «Читатели». Первые обладают всеми правами, вторые – не могут ничего писать, не могут комментировать, не могут голосовать. Читательский аккаунт можно зарегистрировать в любой момент даже без пароля и почтового ящика, пользователь вводит свой логин и попадает в Ленту, где может подписываться на блоги и затем получать уведомления на почту. В любой момент он может зайти снова под своим логином, не вводя никаких паролей. Соответственно он может отслеживать таким образом новые статьи и комментарии. Аккаунты читателей не отображаются в списке Участников.
А то все инструкции для прошлых версий, и все плагины для комментариев без регистрации/через соцсети не совместимы.
Все работает (кроме предпросмотра комментария для гостя, но это мелочь).