3 namespace wcf\system\comment\manager
;
5 use wcf\data\comment\Comment
;
6 use wcf\data\comment\response\CommentResponse
;
7 use wcf\data\
object\type\ObjectTypeCache
;
8 use wcf\data\user\ignore\UserIgnore
;
9 use wcf\data\user\UserProfile
;
10 use wcf\system\cache\runtime\UserProfileRuntimeCache
;
11 use wcf\system\cache\runtime\UserRuntimeCache
;
12 use wcf\system\cache\runtime\ViewableCommentResponseRuntimeCache
;
13 use wcf\system\cache\runtime\ViewableCommentRuntimeCache
;
14 use wcf\system\like\IViewableLikeProvider
;
18 * User profile comment manager implementation.
20 * @author Alexander Ebert
21 * @copyright 2001-2019 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 class UserProfileCommentManager
extends AbstractCommentManager
implements
25 IViewableLikeProvider
,
26 ICommentPermissionManager
31 protected $permissionAdd = 'user.profileComment.canAddComment';
36 protected $permissionAddWithoutModeration = 'user.profileComment.canAddCommentWithoutModeration';
41 protected $permissionCanModerate = 'mod.profileComment.canModerateComment';
46 protected $permissionDelete = 'user.profileComment.canDeleteComment';
51 protected $permissionEdit = 'user.profileComment.canEditComment';
56 protected $permissionModDelete = 'mod.profileComment.canDeleteComment';
61 protected $permissionModEdit = 'mod.profileComment.canEditComment';
66 public function isAccessible($objectID, $validateWritePermission = false)
69 $userProfile = UserProfileRuntimeCache
::getInstance()->getObject($objectID);
70 if ($userProfile === null) {
75 if ($userProfile->isProtected()) {
79 // check target user settings
80 if ($validateWritePermission) {
82 !$userProfile->isAccessible('canWriteProfileComments')
83 && $userProfile->userID
!= WCF
::getUser()->userID
88 if ($userProfile->isIgnoredUser(WCF
::getUser()->userID
, UserIgnore
::TYPE_BLOCK_DIRECT_CONTACT
)) {
97 public function canModerateObject(int $objectTypeID, int $objectID, UserProfile
$user): bool
99 $userProfile = UserProfileRuntimeCache
::getInstance()->getObject($objectID);
100 if ($userProfile === null) {
104 /** @see UserProfile::isProtected() */
107 $user->getPermission('admin.general.canViewPrivateUserOptions')
108 ||
$userProfile->isAccessible('canViewProfile', $user->userID
)
109 ||
$userProfile->userID
=== $user->userID
115 return (bool)$user->getPermission($this->permissionCanModerate
);
121 public function getLink($objectTypeID, $objectID)
123 $user = UserRuntimeCache
::getInstance()->getObject($objectID);
125 return $user->getLink();
134 public function getCommentLink(Comment
$comment)
136 return $this->getLink($comment->objectTypeID
, $comment->objectID
) . '#wall/comment' . $comment->commentID
;
142 public function getResponseLink(CommentResponse
$response)
144 return $this->getLink($response->getComment()->objectTypeID
, $response->getComment()->objectID
)
145 . '#wall/comment' . $response->commentID
. '/response' . $response->responseID
;
151 public function getTitle($objectTypeID, $objectID, $isResponse = false)
154 return WCF
::getLanguage()->get('wcf.user.profile.content.wall.commentResponse');
157 return WCF
::getLanguage()->getDynamicVariable('wcf.user.profile.content.wall.comment');
163 public function updateCounter($objectID, $value)
171 public function canDeleteComment(Comment
$comment)
174 $comment->objectID
== WCF
::getUser()->userID
175 && WCF
::getSession()->getPermission('user.profileComment.canDeleteCommentInOwnProfile')
180 return parent
::canDeleteComment($comment);
186 public function canDeleteResponse(CommentResponse
$response)
189 $response->getComment()->objectID
== WCF
::getUser()->userID
190 && WCF
::getSession()->getPermission('user.profileComment.canDeleteCommentInOwnProfile')
195 return parent
::canDeleteResponse($response);
201 public function prepare(array $likes)
203 if (!WCF
::getSession()->getPermission('user.profile.canViewUserProfile')) {
207 $commentLikeObjectType = ObjectTypeCache
::getInstance()
208 ->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.comment');
210 $commentIDs = $responseIDs = [];
211 foreach ($likes as $like) {
212 if ($like->objectTypeID
== $commentLikeObjectType->objectTypeID
) {
213 $commentIDs[] = $like->objectID
;
215 $responseIDs[] = $like->objectID
;
220 $userIDs = $responses = [];
221 if (!empty($responseIDs)) {
222 $responses = ViewableCommentResponseRuntimeCache
::getInstance()->getObjects($responseIDs);
224 foreach ($responses as $response) {
225 $commentIDs[] = $response->commentID
;
226 if ($response->userID
) {
227 $userIDs[] = $response->userID
;
233 $comments = ViewableCommentRuntimeCache
::getInstance()->getObjects($commentIDs);
237 foreach ($comments as $comment) {
238 $userIDs[] = $comment->objectID
;
239 if ($comment->userID
) {
240 $userIDs[] = $comment->userID
;
243 if (!empty($userIDs)) {
244 $users = UserProfileRuntimeCache
::getInstance()->getObjects(\array_unique
($userIDs));
248 foreach ($likes as $like) {
249 if ($like->objectTypeID
== $commentLikeObjectType->objectTypeID
) {
251 if (isset($comments[$like->objectID
])) {
252 $comment = $comments[$like->objectID
];
254 if (isset($users[$comment->objectID
]) && !$users[$comment->objectID
]->isProtected()) {
255 $like->setIsAccessible();
258 $text = WCF
::getLanguage()->getDynamicVariable(
259 'wcf.like.title.com.woltlab.wcf.user.profileComment',
261 'commentAuthor' => $comment->userID ?
$users[$comment->userID
] : null,
262 'comment' => $comment,
263 'user' => $users[$comment->objectID
],
265 // @deprecated 5.3 Use `$reaction` instead
269 $like->setTitle($text);
272 $like->setDescription($comment->getExcerpt());
277 if (isset($responses[$like->objectID
])) {
278 $response = $responses[$like->objectID
];
279 $comment = $comments[$response->commentID
];
281 if (isset($users[$comment->objectID
]) && !$users[$comment->objectID
]->isProtected()) {
282 $like->setIsAccessible();
285 $text = WCF
::getLanguage()->getDynamicVariable(
286 'wcf.like.title.com.woltlab.wcf.user.profileComment.response',
288 'responseAuthor' => $response->userID ?
$users[$response->userID
] : null,
289 'commentAuthor' => $comment->userID ?
$users[$comment->userID
] : null,
290 'user' => $users[$comment->objectID
],
292 // @deprecated 5.3 Use `$reaction` instead
294 'response' => $response,
297 $like->setTitle($text);
300 $like->setDescription($response->getExcerpt());