Commit | Line | Data |
---|---|---|
320f4a6d MW |
1 | <?php |
2 | namespace wcf\page; | |
5929567d | 3 | use wcf\data\object\type\ObjectType; |
320f4a6d | 4 | use wcf\data\object\type\ObjectTypeCache; |
b971006b | 5 | use wcf\data\user\cover\photo\UserCoverPhoto; |
320f4a6d MW |
6 | use wcf\data\user\follow\UserFollowerList; |
7 | use wcf\data\user\follow\UserFollowingList; | |
57f097e8 | 8 | use wcf\data\user\group\UserGroup; |
320f4a6d MW |
9 | use wcf\data\user\profile\visitor\UserProfileVisitor; |
10 | use wcf\data\user\profile\visitor\UserProfileVisitorEditor; | |
11 | use wcf\data\user\profile\visitor\UserProfileVisitorList; | |
12 | use wcf\data\user\UserEditor; | |
13 | use wcf\data\user\UserProfile; | |
a8c5936e | 14 | use wcf\system\cache\runtime\UserProfileRuntimeCache; |
320f4a6d MW |
15 | use wcf\system\exception\IllegalLinkException; |
16 | use wcf\system\exception\PermissionDeniedException; | |
17 | use wcf\system\menu\user\profile\UserProfileMenu; | |
ac4ff35d | 18 | use wcf\system\page\PageLocationManager; |
320f4a6d MW |
19 | use wcf\system\request\LinkHandler; |
20 | use wcf\system\MetaTagHandler; | |
21 | use wcf\system\WCF; | |
22 | ||
23 | /** | |
24 | * Shows the user profile page. | |
25 | * | |
26 | * @author Marcel Werk | |
c839bd49 | 27 | * @copyright 2001-2018 WoltLab GmbH |
320f4a6d | 28 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 29 | * @package WoltLabSuite\Core\Page |
320f4a6d MW |
30 | */ |
31 | class UserPage extends AbstractPage { | |
320f4a6d MW |
32 | /** |
33 | * edit profile on page load | |
34 | * @var boolean | |
35 | */ | |
36 | public $editOnInit = false; | |
37 | ||
38 | /** | |
39 | * overview editable content object type | |
5929567d | 40 | * @var ObjectType |
320f4a6d | 41 | */ |
cd358fd9 | 42 | public $objectType; |
320f4a6d MW |
43 | |
44 | /** | |
45 | * profile content for active menu item | |
46 | * @var string | |
47 | */ | |
48 | public $profileContent = ''; | |
49 | ||
50 | /** | |
51 | * user id | |
52 | * @var integer | |
53 | */ | |
54 | public $userID = 0; | |
55 | ||
56 | /** | |
57 | * user object | |
a8c5936e | 58 | * @var UserProfile |
320f4a6d | 59 | */ |
cd358fd9 | 60 | public $user; |
320f4a6d MW |
61 | |
62 | /** | |
63 | * follower list | |
4e25add7 | 64 | * @var UserFollowerList |
320f4a6d | 65 | */ |
cd358fd9 | 66 | public $followerList; |
320f4a6d MW |
67 | |
68 | /** | |
69 | * following list | |
4e25add7 | 70 | * @var UserFollowingList |
320f4a6d | 71 | */ |
cd358fd9 | 72 | public $followingList; |
320f4a6d MW |
73 | |
74 | /** | |
75 | * visitor list | |
4e25add7 | 76 | * @var UserProfileVisitorList |
320f4a6d | 77 | */ |
cd358fd9 | 78 | public $visitorList; |
320f4a6d MW |
79 | |
80 | /** | |
0fcfe5f6 | 81 | * @inheritDoc |
320f4a6d MW |
82 | */ |
83 | public function readParameters() { | |
84 | parent::readParameters(); | |
85 | ||
86 | if (isset($_REQUEST['id'])) $this->userID = intval($_REQUEST['id']); | |
a8c5936e | 87 | $this->user = UserProfileRuntimeCache::getInstance()->getObject($this->userID); |
320f4a6d MW |
88 | if ($this->user === null) { |
89 | throw new IllegalLinkException(); | |
90 | } | |
91 | ||
b3b44b36 MW |
92 | if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->getPermission('user.profile.canViewUserProfile')) { |
93 | throw new PermissionDeniedException(); | |
94 | } | |
95 | ||
320f4a6d | 96 | if (isset($_REQUEST['editOnInit'])) $this->editOnInit = true; |
909b697f | 97 | |
cd358fd9 | 98 | $this->canonicalURL = LinkHandler::getInstance()->getLink('User', ['object' => $this->user]); |
320f4a6d MW |
99 | } |
100 | ||
101 | /** | |
0fcfe5f6 | 102 | * @inheritDoc |
320f4a6d MW |
103 | */ |
104 | public function readData() { | |
105 | parent::readData(); | |
106 | ||
107 | // add breadcrumbs | |
ac4ff35d | 108 | if (MODULE_MEMBERS_LIST) PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.MembersList'); |
320f4a6d MW |
109 | |
110 | // get profile content | |
111 | if ($this->editOnInit) { | |
112 | // force 'about' tab as primary if editing profile | |
113 | UserProfileMenu::getInstance()->setActiveMenuItem('about'); | |
114 | } | |
115 | ||
7ac7dc24 | 116 | $activeMenuItem = UserProfileMenu::getInstance()->getActiveMenuItem($this->user->userID); |
320f4a6d MW |
117 | $contentManager = $activeMenuItem->getContentManager(); |
118 | $this->profileContent = $contentManager->getContent($this->user->userID); | |
119 | $this->objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.user.profileEditableContent', 'com.woltlab.wcf.user.profileAbout'); | |
120 | ||
121 | // get followers | |
122 | $this->followerList = new UserFollowerList(); | |
cd358fd9 AE |
123 | $this->followerList->getConditionBuilder()->add('user_follow.followUserID = ?', [$this->userID]); |
124 | $this->followerList->sqlLimit = 7; | |
320f4a6d MW |
125 | $this->followerList->readObjects(); |
126 | ||
127 | // get following | |
128 | $this->followingList = new UserFollowingList(); | |
cd358fd9 AE |
129 | $this->followingList->getConditionBuilder()->add('user_follow.userID = ?', [$this->userID]); |
130 | $this->followingList->sqlLimit = 7; | |
320f4a6d MW |
131 | $this->followingList->readObjects(); |
132 | ||
133 | // get visitors | |
a1faa664 MW |
134 | if (PROFILE_ENABLE_VISITORS) { |
135 | $this->visitorList = new UserProfileVisitorList(); | |
cd358fd9 AE |
136 | $this->visitorList->getConditionBuilder()->add('user_profile_visitor.ownerID = ?', [$this->userID]); |
137 | $this->visitorList->sqlLimit = 7; | |
a1faa664 MW |
138 | $this->visitorList->readObjects(); |
139 | } | |
320f4a6d | 140 | |
b37952e9 | 141 | MetaTagHandler::getInstance()->addTag('og:url', 'og:url', LinkHandler::getInstance()->getLink('User', ['object' => $this->user->getDecoratedObject()]), true); |
320f4a6d | 142 | MetaTagHandler::getInstance()->addTag('og:type', 'og:type', 'profile', true); |
d9339e08 | 143 | MetaTagHandler::getInstance()->addTag('profile:username', 'profile:username', $this->user->username, true); |
dad79f9a | 144 | MetaTagHandler::getInstance()->addTag('og:title', 'og:title', $this->user->username . ' - ' . WCF::getLanguage()->get('wcf.user.members') . ' - ' . WCF::getLanguage()->get(PAGE_TITLE), true); |
320f4a6d MW |
145 | MetaTagHandler::getInstance()->addTag('og:image', 'og:image', $this->user->getAvatar()->getURL(), true); |
146 | } | |
147 | ||
148 | /** | |
0fcfe5f6 | 149 | * @inheritDoc |
320f4a6d MW |
150 | */ |
151 | public function assignVariables() { | |
152 | parent::assignVariables(); | |
153 | ||
cd358fd9 | 154 | WCF::getTPL()->assign([ |
320f4a6d MW |
155 | 'editOnInit' => $this->editOnInit, |
156 | 'overviewObjectType' => $this->objectType, | |
157 | 'profileContent' => $this->profileContent, | |
158 | 'userID' => $this->userID, | |
159 | 'user' => $this->user, | |
160 | 'followers' => $this->followerList->getObjects(), | |
161 | 'followerCount' => $this->followerList->countObjects(), | |
162 | 'following' => $this->followingList->getObjects(), | |
163 | 'followingCount' => $this->followingList->countObjects(), | |
63b9817b MS |
164 | 'visitors' => $this->visitorList !== null ? $this->visitorList->getObjects() : [], |
165 | 'visitorCount' => $this->visitorList !== null ? $this->visitorList->countObjects() : 0, | |
b971006b AE |
166 | 'isAccessible' => UserGroup::isAccessibleGroup($this->user->getGroupIDs()), |
167 | 'coverPhotoDimensions' => UserCoverPhoto::getCoverPhotoDimensions() | |
cd358fd9 | 168 | ]); |
320f4a6d MW |
169 | } |
170 | ||
171 | /** | |
0fcfe5f6 | 172 | * @inheritDoc |
320f4a6d MW |
173 | */ |
174 | public function show() { | |
175 | // update profile hits | |
93823e40 | 176 | if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->spiderID && !$this->user->isProtected()) { |
320f4a6d | 177 | $editor = new UserEditor($this->user->getDecoratedObject()); |
cd358fd9 | 178 | $editor->updateCounters(['profileHits' => 1]); |
320f4a6d MW |
179 | |
180 | // save visitor | |
3b13d4ea | 181 | /** @noinspection PhpUndefinedFieldInspection */ |
76850764 | 182 | if (PROFILE_ENABLE_VISITORS && WCF::getUser()->userID && !WCF::getUser()->canViewOnlineStatus) { |
320f4a6d MW |
183 | if (($visitor = UserProfileVisitor::getObject($this->user->userID, WCF::getUser()->userID)) !== null) { |
184 | $editor = new UserProfileVisitorEditor($visitor); | |
cd358fd9 | 185 | $editor->update(['time' => TIME_NOW]); |
320f4a6d MW |
186 | } |
187 | else { | |
cd358fd9 | 188 | UserProfileVisitorEditor::create([ |
320f4a6d MW |
189 | 'ownerID' => $this->user->userID, |
190 | 'userID' => WCF::getUser()->userID, | |
191 | 'time' => TIME_NOW | |
cd358fd9 | 192 | ]); |
320f4a6d MW |
193 | } |
194 | } | |
195 | } | |
196 | ||
197 | parent::show(); | |
198 | } | |
320f4a6d | 199 | } |