Работа с комментариями перенесена в отдельный контроллер
This commit is contained in:
parent
565fd72f15
commit
5cd212ea9f
|
|
@ -192,41 +192,6 @@ class ArticleController extends Controller
|
|||
App::redirect('/user/');
|
||||
}
|
||||
|
||||
static function actionAddComment()
|
||||
{
|
||||
if (!App::$user ||
|
||||
!isset($_POST['parentType']) ||
|
||||
!isset($_POST['parentId']) ||
|
||||
!isset($_POST['answerTo']) ||
|
||||
!isset($_POST['text']))
|
||||
{
|
||||
App::error404();
|
||||
}
|
||||
|
||||
if (trim($_POST['text']) == '') {
|
||||
App::redirect('/'.$_POST['parentType'].'/'.$_POST['parentId']);
|
||||
}
|
||||
|
||||
$text = str_replace(array('<','>'), array('<','>'), $_POST['text']);
|
||||
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<','>',"'"), array('<','>','′'), $html);
|
||||
$html = Markdown::liteProcessing($html);
|
||||
$html = nl2br($html);
|
||||
|
||||
$comment = new Comment(array(
|
||||
'userId' => App::$user->id,
|
||||
'parentType' => ($_POST['parentType'] == 'article') ? 'article' : 'point',
|
||||
'parentId' => (int)$_POST['parentId'],
|
||||
'answerTo' => (int)$_POST['answerTo'],
|
||||
'addDate' => time(),
|
||||
'text' => $text,
|
||||
'html' => $html,
|
||||
));
|
||||
$comment->save();
|
||||
App::redirect('/'.$_POST['parentType'].'/'.$_POST['parentId'].'#comment'.$comment->id);
|
||||
}
|
||||
|
||||
static function actionMarkdown()
|
||||
{
|
||||
if (isset($_POST['text']) ){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
class CommentsController extends Controller
|
||||
{
|
||||
|
||||
static function actionAdd()
|
||||
{
|
||||
if (!App::$user ||
|
||||
!isset($_POST['parentType']) ||
|
||||
!isset($_POST['parentId']) ||
|
||||
!isset($_POST['answerTo']) ||
|
||||
!isset($_POST['text'])) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
if (trim($_POST['text']) == '') {
|
||||
App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId']);
|
||||
}
|
||||
|
||||
$text = str_replace(array('<', '>'), array('<', '>'), $_POST['text']);
|
||||
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<', '>', "'"), array('<', '>', '′'), $html);
|
||||
$html = Markdown::liteProcessing($html);
|
||||
$html = nl2br($html);
|
||||
|
||||
$comment = new Comment(array(
|
||||
'userId' => App::$user->id,
|
||||
'parentType' => ($_POST['parentType'] == 'article') ? 'article' : 'point',
|
||||
'parentId' => (int) $_POST['parentId'],
|
||||
'answerTo' => (int) $_POST['answerTo'],
|
||||
'addDate' => time(),
|
||||
'text' => $text,
|
||||
'html' => $html,
|
||||
));
|
||||
$comment->save();
|
||||
App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId'] . '#comment' . $comment->id);
|
||||
}
|
||||
|
||||
static function actionDel()
|
||||
{
|
||||
if (!App::$user || !(int)App::getParam('id')) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$id = (int)App::getParam('id');
|
||||
$comment = Comment::model()->getByPK($id);
|
||||
|
||||
if($comment->id && $comment->userId == App::$user->id) {
|
||||
$comment->delete($id);
|
||||
}
|
||||
|
||||
App::redirect('/'.$comment->parentType.'/'.$comment->parentId);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,12 @@
|
|||
<a name="comment<?= $comment->id ?>"></a>
|
||||
<img src="/img/avatars/<?= $comment->refUser->id ?>.jpg" class="avatar"/>
|
||||
<div class="info">
|
||||
<b><?= $comment->refUser->nick ?></b>
|
||||
<a href="/user/<?= $comment->refUser->id ?>"><b><?= $comment->refUser->nick ?></b></a>
|
||||
<?= date('H:i d-m-Y',$comment->addDate) ?>
|
||||
<a href="#comment<?= $comment->id ?>" name="#comment<?= $comment->id ?>" class="anchor">#</a>
|
||||
<?php if (App::$user && $comment->userId == App::$user->id): ?>
|
||||
<a href="/comments/del/id/<?= $comment->id ?>" title="Удалить комментарий" class="anchor"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<br/>
|
||||
<?= Helper::replaceLinks($comment->html, 'html') ?><br/>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="commentForm">
|
||||
<form action="/article/addComment/" method="POST">
|
||||
<form action="/comments/add" method="POST">
|
||||
<input type="hidden" name="answerTo" value="0" />
|
||||
<input type="hidden" name="parentType" value="<?= $parentType ?>" />
|
||||
<input type="hidden" name="parentId" value="<?= $parentId ?>" />
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
}
|
||||
|
||||
.singleComment .info .anchor{
|
||||
margin-right: 10px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue