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>
18 * @package WoltLabSuite\Core\System\Comment\Manager
20 abstract class AbstractCommentManager
extends SingletonFactory
implements ICommentManager
23 * display comments per page
26 public $commentsPerPage = 30;
29 * permission name for comment/response creation
32 protected $permissionAdd = '';
35 * permission name for comment/response creation without approval
38 protected $permissionAddWithoutModeration = '';
41 * permission name for comment/response moderation
44 protected $permissionCanModerate = '';
47 * permission name for deletion of own comments/responses
50 protected $permissionDelete = '';
53 * permission name for editing of own comments/responses
56 protected $permissionEdit = '';
59 * permission name for deletion of comments/responses (moderator)
62 protected $permissionModDelete = '';
65 * permission name for editing of comments/responses (moderator)
68 protected $permissionModEdit = '';
71 * permission name for the list of disallowed bbcodes
74 protected $permissionDisallowedBBCodes = 'user.comment.disallowedBBCodes';
79 public function canAdd($objectID)
81 if (VISITOR_USE_TINY_BUILD
&& !WCF
::getUser()->userID
) {
85 if (!$this->isAccessible($objectID, true)) {
89 return WCF
::getSession()->getPermission($this->permissionAdd
) ?
true : false;
95 public function canAddWithoutApproval($objectID)
97 if (VISITOR_USE_TINY_BUILD
&& !WCF
::getUser()->userID
) {
101 if (empty($this->permissionAddWithoutModeration
)) {
102 if (ENABLE_DEBUG_MODE
) {
103 throw new \
RuntimeException("Missing permission name to create comments without approval.");
106 // backwards-compatibility in production mode
110 return WCF
::getSession()->getPermission($this->permissionAddWithoutModeration
) ?
true : false;
116 public function setDisallowedBBCodes()
118 BBCodeHandler
::getInstance()->setDisallowedBBCodes(\
explode(
120 WCF
::getSession()->getPermission($this->permissionDisallowedBBCodes
)
127 public function canEditComment(Comment
$comment)
129 return $this->canEdit($comment->userID
== WCF
::getUser()->userID
);
135 public function canEditResponse(CommentResponse
$response)
137 return $this->canEdit($response->userID
== WCF
::getUser()->userID
);
143 public function canDeleteComment(Comment
$comment)
145 return $this->canDelete($comment->userID
== WCF
::getUser()->userID
);
151 public function canDeleteResponse(CommentResponse
$response)
153 return $this->canDelete($response->userID
== WCF
::getUser()->userID
);
159 public function canModerate($objectTypeID, $objectID)
161 return WCF
::getSession()->getPermission($this->permissionCanModerate
) ?
true : false;
165 * Returns true if the current user may edit a comment/response.
167 * @param bool $isOwner
170 protected function canEdit($isOwner)
173 if (!WCF
::getUser()->userID
) {
177 // check moderator permission
178 if (WCF
::getSession()->getPermission($this->permissionModEdit
)) {
182 // check user permission and ownership
183 if ($isOwner && WCF
::getSession()->getPermission($this->permissionEdit
)) {
191 * Returns true if the current user may delete a comment/response.
193 * @param bool $isOwner
196 protected function canDelete($isOwner)
199 if (!WCF
::getUser()->userID
) {
203 // check moderator permission
204 if (WCF
::getSession()->getPermission($this->permissionModDelete
)) {
208 // check user permission and ownership
209 if ($isOwner && WCF
::getSession()->getPermission($this->permissionDelete
)) {
219 public function getCommentsPerPage()
221 return $this->commentsPerPage
;
227 public function supportsLike()
235 public function supportsReport()
243 public function getCommentLink(Comment
$comment)
245 return $this->getLink($comment->objectTypeID
, $comment->objectID
) . '#comment' . $comment->commentID
;
251 public function getResponseLink(CommentResponse
$response)
253 return $this->getLink($response->getComment()->objectTypeID
, $response->getComment()->objectID
)
254 . '#comment' . $response->commentID
. '/response' . $response->responseID
;
260 public function isContentAuthor($commentOrResponse)
266 * Returns the object ID for the given Comment or CommentResponse.
270 final protected function getObjectID($commentOrResponse)
273 $commentOrResponse instanceof CommentResponse
275 $commentOrResponse instanceof DatabaseObjectDecorator
276 && $commentOrResponse->getDecoratedObject() instanceof CommentResponse
279 return $commentOrResponse->getComment()->objectID
;
281 return $commentOrResponse->objectID
;