From 1fc2b93334a3dd08bc2a8a706c0428138ed93902 Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 13 May 2021 19:42:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=92=8C=E6=8F=90=E9=97=AE=E6=B5=8F=E8=A7=88=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Controllers/ArticleController.php | 4 +--- app/Http/Home/Controllers/QuestionController.php | 4 ++++ app/Services/Logic/Article/ArticleInfo.php | 9 +++++++++ app/Services/Logic/Question/QuestionInfo.php | 9 +++++++++ public/static/home/css/common.css | 4 ---- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Http/Home/Controllers/ArticleController.php b/app/Http/Home/Controllers/ArticleController.php index 87dac7ea..72cf8c46 100644 --- a/app/Http/Home/Controllers/ArticleController.php +++ b/app/Http/Home/Controllers/ArticleController.php @@ -100,9 +100,7 @@ class ArticleController extends Controller $article = $service->handle($id); - $owned = $this->authUser->id == $article['owner']['id']; - - if ($article['private'] == 1 && !$owned) { + if ($article['me']['owned'] == 0) { $this->response->redirect(['for' => 'home.error.403']); } diff --git a/app/Http/Home/Controllers/QuestionController.php b/app/Http/Home/Controllers/QuestionController.php index 78fcbf20..cc616caf 100644 --- a/app/Http/Home/Controllers/QuestionController.php +++ b/app/Http/Home/Controllers/QuestionController.php @@ -99,6 +99,10 @@ class QuestionController extends Controller $question = $service->handle($id); + if ($question['me']['owned'] == 0) { + $this->response->redirect(['for' => 'home.error.403']); + } + $this->seo->prependTitle($question['title']); $this->seo->setDescription($question['summary']); diff --git a/app/Services/Logic/Article/ArticleInfo.php b/app/Services/Logic/Article/ArticleInfo.php index bbe63c0c..201ff557 100644 --- a/app/Services/Logic/Article/ArticleInfo.php +++ b/app/Services/Logic/Article/ArticleInfo.php @@ -70,8 +70,17 @@ class ArticleInfo extends LogicService $me = [ 'liked' => 0, 'favorited' => 0, + 'owned' => 0, ]; + $isOwner = $user->id == $article->owner_id; + + if ($article->published == ArticleModel::PUBLISH_APPROVED) { + $me['owned'] = 1; + } else { + $me['owned'] = $isOwner ? 1 : 0; + } + if ($user->id > 0) { $likeRepo = new ArticleLikeRepo(); diff --git a/app/Services/Logic/Question/QuestionInfo.php b/app/Services/Logic/Question/QuestionInfo.php index 192e19b8..3ec8e782 100644 --- a/app/Services/Logic/Question/QuestionInfo.php +++ b/app/Services/Logic/Question/QuestionInfo.php @@ -91,8 +91,17 @@ class QuestionInfo extends LogicService 'liked' => 0, 'favorited' => 0, 'answered' => 0, + 'owned' => 0, ]; + $isOwner = $user->id == $question->owner_id; + + if ($question->published == QuestionModel::PUBLISH_APPROVED) { + $me['owned'] = 1; + } else { + $me['owned'] = $isOwner ? 1 : 0; + } + if ($user->id > 0) { $likeRepo = new QuestionLikeRepo(); diff --git a/public/static/home/css/common.css b/public/static/home/css/common.css index 609ed47d..727d1878 100644 --- a/public/static/home/css/common.css +++ b/public/static/home/css/common.css @@ -577,10 +577,6 @@ color: #666; } -.article-info .meta a { - color: #666; -} - .article-info .meta .left span { margin-right: 10px; } From aa40087bf1388bbd0b0dce8eb98460f915204333 Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 13 May 2021 20:29:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Views/setting/point.volt | 18 ++++++++++++++++++ .../Home/Controllers/QuestionController.php | 3 +++ app/Http/Home/Views/macros/point.volt | 10 ++++++++++ app/Services/Logic/Article/ArticleCreate.php | 1 + .../Logic/Point/History/AnswerPost.php | 6 ++++++ .../Logic/Point/History/CommentPost.php | 4 +++- app/Services/Logic/Question/QuestionCreate.php | 4 +++- 7 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/Http/Admin/Views/setting/point.volt b/app/Http/Admin/Views/setting/point.volt index 7dafc75f..1d645873 100644 --- a/app/Http/Admin/Views/setting/point.volt +++ b/app/Http/Admin/Views/setting/point.volt @@ -115,6 +115,24 @@ + + 发布问题 + + + + + + + + + 回答问题 + + + + + + +
diff --git a/app/Http/Home/Controllers/QuestionController.php b/app/Http/Home/Controllers/QuestionController.php index cc616caf..0ee20625 100644 --- a/app/Http/Home/Controllers/QuestionController.php +++ b/app/Http/Home/Controllers/QuestionController.php @@ -65,7 +65,10 @@ class QuestionController extends Controller $this->seo->prependTitle('提问题'); + $referer = $this->request->getHTTPReferer(); + $this->view->pick('question/edit'); + $this->view->setVar('referer', $referer); $this->view->setVar('question', $question); $this->view->setVar('xm_tags', $xmTags); } diff --git a/app/Http/Home/Views/macros/point.volt b/app/Http/Home/Views/macros/point.volt index 51918bf5..19ef5d61 100644 --- a/app/Http/Home/Views/macros/point.volt +++ b/app/Http/Home/Views/macros/point.volt @@ -47,6 +47,10 @@ 发布评论 {% elseif value == 10 %} 发布文章 + {% elseif value == 11 %} + 发布问题 + {% elseif value == 12 %} + 发布回答 {% endif %} {%- endmacro %} @@ -78,5 +82,11 @@ {% elseif type == 10 %} {% set article_url = url({'for':'home.article.show','id':info.article.id}) %}

{{ info.article.title }}

+ {% elseif type == 11 %} + {% set question_url = url({'for':'home.question.show','id':info.question.id}) %} +

{{ info.question.title }}

+ {% elseif type == 12 %} + {% set question_url = url({'for':'home.question.show','id':info.question.id}) %} +

{{ info.question.title }}

{% endif %} {%- endmacro %} \ No newline at end of file diff --git a/app/Services/Logic/Article/ArticleCreate.php b/app/Services/Logic/Article/ArticleCreate.php index 616d7857..f382abad 100644 --- a/app/Services/Logic/Article/ArticleCreate.php +++ b/app/Services/Logic/Article/ArticleCreate.php @@ -23,6 +23,7 @@ class ArticleCreate extends LogicService $data = $this->handlePostData($post); $data['published'] = $this->getPublishStatus($user); + $data['owner_id'] = $user->id; $article->create($data); diff --git a/app/Services/Logic/Point/History/AnswerPost.php b/app/Services/Logic/Point/History/AnswerPost.php index 3f4da0e4..6bf957c1 100644 --- a/app/Services/Logic/Point/History/AnswerPost.php +++ b/app/Services/Logic/Point/History/AnswerPost.php @@ -58,10 +58,16 @@ class AnswerPost extends PointHistory $user = $userRepo->findById($answer->owner_id); + $answerSummary = kg_substr($answer->summary, 0, 32); + $eventInfo = [ 'question' => [ 'id' => $question->id, 'title' => $question->title, + ], + 'answer' => [ + 'id' => $answer->id, + 'summary' => $answerSummary, ] ]; diff --git a/app/Services/Logic/Point/History/CommentPost.php b/app/Services/Logic/Point/History/CommentPost.php index a193485b..827db1e1 100644 --- a/app/Services/Logic/Point/History/CommentPost.php +++ b/app/Services/Logic/Point/History/CommentPost.php @@ -53,10 +53,12 @@ class CommentPost extends PointHistory $user = $userRepo->findById($comment->owner_id); + $commentContent = kg_substr($comment->content, 0, 32); + $eventInfo = [ 'comment' => [ 'id' => $comment->id, - 'content' => $comment->content, + 'content' => $commentContent, ] ]; diff --git a/app/Services/Logic/Question/QuestionCreate.php b/app/Services/Logic/Question/QuestionCreate.php index 96cd6b92..f8f2834a 100644 --- a/app/Services/Logic/Question/QuestionCreate.php +++ b/app/Services/Logic/Question/QuestionCreate.php @@ -22,6 +22,8 @@ class QuestionCreate extends LogicService $data = $this->handlePostData($post); + $data['published'] = $this->getPublishStatus($user); + $data['owner_id'] = $user->id; $question->create($data); @@ -39,7 +41,7 @@ class QuestionCreate extends LogicService protected function getPublishStatus(UserModel $user) { - return $user->question_count > 3 ? QuestionModel::PUBLISH_APPROVED : QuestionModel::PUBLISH_PENDING; + return $user->question_count > 100 ? QuestionModel::PUBLISH_APPROVED : QuestionModel::PUBLISH_PENDING; } protected function recountUserQuestions(UserModel $user) From cc19004c12e75d66ee83fbb189b5b3f93f32b5cc Mon Sep 17 00:00:00 2001 From: koogua Date: Sat, 15 May 2021 14:07:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=97=B6=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Services/Tag.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Admin/Services/Tag.php b/app/Http/Admin/Services/Tag.php index 584a8086..f353f444 100644 --- a/app/Http/Admin/Services/Tag.php +++ b/app/Http/Admin/Services/Tag.php @@ -42,7 +42,6 @@ class Tag extends Service $tag = new TagModel(); $tag->name = $validator->checkName($post['name']); - $tag->priority = $validator->checkPriority($post['priority']); $tag->create();