diff --git a/ground/classes/Markdown.php b/ground/classes/Markdown.php index 2f5b5cb..16aafb9 100644 --- a/ground/classes/Markdown.php +++ b/ground/classes/Markdown.php @@ -15,6 +15,18 @@ class Markdown return $string; } + static function liteProcessing($string) + { +// $string = self::replaceHeaders($string); + $string = self::replaceBold($string); + $string = self::replaceItalic($string); + $string = self::replaceUnderline($string); + $string = self::replaceChars($string); + $string = self::replaceUrls($string); + + return $string; + } + static private function replaceHeaders($string) { $pr = '(### (.{1,}))'; diff --git a/ground/controllers/ArticleController.php b/ground/controllers/ArticleController.php index 8fde5fe..8ee2c91 100644 --- a/ground/controllers/ArticleController.php +++ b/ground/controllers/ArticleController.php @@ -190,6 +190,37 @@ 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(); + } + + $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/models/Comment.php b/ground/models/Comment.php new file mode 100644 index 0000000..dd6476a --- /dev/null +++ b/ground/models/Comment.php @@ -0,0 +1,18 @@ +_tableName_ = 'comments'; + parent::__construct($fromArray); + $this->setRelation('refUser', 'userId', 'User', 'id', self::TO_ONE); + } + + static function model() + { + return new self(); + } + +} diff --git a/ground/views/article.php b/ground/views/article.php index 7a1d20b..00883da 100644 --- a/ground/views/article.php +++ b/ground/views/article.php @@ -16,6 +16,12 @@