['filter' => FILTER_VALIDATE_INT ], 'replyId' => ['filter' => FILTER_VALIDATE_INT ], 'body' => ['filter' => FILTER_CALLBACK, 'options' => [self::class, 'checkTextBlob']] ); protected function generate(): void { if (!$this->assertPOST('commentId', 'replyId', 'body')) { trigger_error('CommentAddreplyResponse - malformed request received', E_USER_ERROR); $this->generate404(User::isInGroup(U_GROUP_STAFF) ? 'request malformed' : ''); } if (!User::canReply()) $this->generate404(Lang::main('cannotComment')); if (!$this->_post['commentId'] || !DB::Aowow()->selectCell('SELECT 1 FROM ?_comments WHERE `id` = ?d', $this->_post['commentId'])) { trigger_error('CommentAddreplyResponse - parent comment #'.$this->_post['commentId'].' does not exist', E_USER_ERROR); $this->generate404(Lang::main('intError')); } if (mb_strlen($this->_post['body']) < CommunityContent::REPLY_LENGTH_MIN || mb_strlen($this->_post['body']) > CommunityContent::REPLY_LENGTH_MAX) $this->generate404(Lang::main('textLength', [mb_strlen($this->_post['body']), CommunityContent::REPLY_LENGTH_MIN, CommunityContent::REPLY_LENGTH_MAX])); if (!DB::Aowow()->query('INSERT INTO ?_comments (`userId`, `roles`, `body`, `date`, `replyTo`) VALUES (?d, ?d, ?, UNIX_TIMESTAMP(), ?d)', User::$id, User::$groups, $this->_post['body'], $this->_post['commentId'])) { trigger_error('CommentAddreplyResponse - write to db failed', E_USER_ERROR); $this->generate404(Lang::main('intError')); } $this->result = Util::toJSON(CommunityContent::getCommentReplies($this->_post['commentId'])); } } ?>