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