From 5cd212ea9f77b8fca932e18c70b9e82ee1d023cf Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sat, 3 Oct 2015 13:47:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D1=8F=D0=BC=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/ArticleController.php | 35 --------------- ground/controllers/CommentsController.php | 55 +++++++++++++++++++++++ ground/views/comments/comment.php | 5 ++- ground/views/comments/form.php | 2 +- public/css/comments.css | 1 + 5 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 ground/controllers/CommentsController.php diff --git a/ground/controllers/ArticleController.php b/ground/controllers/ArticleController.php index cfab6ba..dd9789b 100644 --- a/ground/controllers/ArticleController.php +++ b/ground/controllers/ArticleController.php @@ -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']) ){ diff --git a/ground/controllers/CommentsController.php b/ground/controllers/CommentsController.php new file mode 100644 index 0000000..7ee30c6 --- /dev/null +++ b/ground/controllers/CommentsController.php @@ -0,0 +1,55 @@ +'), 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); + } +} diff --git a/ground/views/comments/comment.php b/ground/views/comments/comment.php index 78aa378..b46815f 100644 --- a/ground/views/comments/comment.php +++ b/ground/views/comments/comment.php @@ -2,9 +2,12 @@
- refUser->nick ?>  + refUser->nick ?>  addDate) ?> # + userId == App::$user->id): ?> + +

html, 'html') ?>
diff --git a/ground/views/comments/form.php b/ground/views/comments/form.php index 0222220..ff39d29 100644 --- a/ground/views/comments/form.php +++ b/ground/views/comments/form.php @@ -1,5 +1,5 @@
-
+ diff --git a/public/css/comments.css b/public/css/comments.css index 28b3269..aeba2eb 100644 --- a/public/css/comments.css +++ b/public/css/comments.css @@ -15,6 +15,7 @@ } .singleComment .info .anchor{ + margin-right: 10px; float: right; }