3 namespace wcf\system\comment\manager
;
5 use wcf\data\comment\Comment
;
6 use wcf\data\comment\response\CommentResponse
;
7 use wcf\data\DatabaseObjectDecorator
;
8 use wcf\system\bbcode\BBCodeHandler
;
9 use wcf\system\SingletonFactory
;
13 * Default implementation for comment managers.
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 abstract class AbstractCommentManager
extends SingletonFactory
implements ICommentManager
22 * display comments per page
25 public $commentsPerPage = 30;
28 * permission name for comment/response creation
31 protected $permissionAdd = '';
34 * permission name for comment/response creation without approval
37 protected $permissionAddWithoutModeration = '';
40 * permission name for comment/response moderation
43 protected $permissionCanModerate = '';
46 * permission name for deletion of own comments/responses
49 protected $permissionDelete = '';
52 * permission name for editing of own comments/responses
55 protected $permissionEdit = '';
58 * permission name for deletion of comments/responses (moderator)
61 protected $permissionModDelete = '';
64 * permission name for editing of comments/responses (moderator)
67 protected $permissionModEdit = '';
70 * permission name for the list of disallowed bbcodes
73 protected $permissionDisallowedBBCodes = 'user.comment.disallowedBBCodes';
78 public function canAdd($objectID)
80 if (VISITOR_USE_TINY_BUILD
&& !WCF
::getUser()->userID
) {
84 if (!$this->isAccessible($objectID, true)) {
88 return WCF
::getSession()->getPermission($this->permissionAdd
) ?
true : false;
94 public function canAddWithoutApproval($objectID)
96 if (VISITOR_USE_TINY_BUILD
&& !WCF
::getUser()->userID
) {
100 if (empty($this->permissionAddWithoutModeration
)) {
101 if (ENABLE_DEBUG_MODE
) {
102 throw new \
RuntimeException("Missing permission name to create comments without approval.");
105 // backwards-compatibility in production mode
109 return WCF
::getSession()->getPermission($this->permissionAddWithoutModeration
) ?
true : false;
115 public function setDisallowedBBCodes()
117 BBCodeHandler
::getInstance()->setDisallowedBBCodes(\
explode(
119 WCF
::getSession()->getPermission($this->permissionDisallowedBBCodes
)
126 public function canEditComment(Comment
$comment)
128 return $this->canEdit($comment->userID
== WCF
::getUser()->userID
);
134 public function canEditResponse(CommentResponse
$response)
136 return $this->canEdit($response->userID
== WCF
::getUser()->userID
);
142 public function canDeleteComment(Comment
$comment)
144 return $this->canDelete($comment->userID
== WCF
::getUser()->userID
);
150 public function canDeleteResponse(CommentResponse
$response)
152 return $this->canDelete($response->userID
== WCF
::getUser()->userID
);
158 public function canModerate($objectTypeID, $objectID)
160 return WCF
::getSession()->getPermission($this->permissionCanModerate
) ?
true : false;
164 * Returns true if the current user may edit a comment/response.
166 * @param bool $isOwner
169 protected function canEdit($isOwner)
172 if (!WCF
::getUser()->userID
) {
176 // check moderator permission
177 if (WCF
::getSession()->getPermission($this->permissionModEdit
)) {
181 // check user permission and ownership
182 if ($isOwner && WCF
::getSession()->getPermission($this->permissionEdit
)) {
190 * Returns true if the current user may delete a comment/response.
192 * @param bool $isOwner
195 protected function canDelete($isOwner)
198 if (!WCF
::getUser()->userID
) {
202 // check moderator permission
203 if (WCF
::getSession()->getPermission($this->permissionModDelete
)) {
207 // check user permission and ownership
208 if ($isOwner && WCF
::getSession()->getPermission($this->permissionDelete
)) {
218 public function getCommentsPerPage()
220 return $this->commentsPerPage
;
226 public function supportsLike()
234 public function supportsReport()
242 public function getCommentLink(Comment
$comment)
244 return $this->getLink($comment->objectTypeID
, $comment->objectID
) . '#comment' . $comment->commentID
;
250 public function getResponseLink(CommentResponse
$response)
252 return $this->getLink($response->getComment()->objectTypeID
, $response->getComment()->objectID
)
253 . '#comment' . $response->commentID
. '/response' . $response->responseID
;
259 public function isContentAuthor($commentOrResponse)
265 * Returns the object ID for the given Comment or CommentResponse.
269 final protected function getObjectID($commentOrResponse)
272 $commentOrResponse instanceof CommentResponse
274 $commentOrResponse instanceof DatabaseObjectDecorator
275 && $commentOrResponse->getDecoratedObject() instanceof CommentResponse
278 return $commentOrResponse->getComment()->objectID
;
280 return $commentOrResponse->objectID
;