3 use wcf\data\
object\type\ObjectTypeCache
;
4 use wcf\data\user\follow\UserFollowerList
;
5 use wcf\data\user\follow\UserFollowingList
;
6 use wcf\data\user\group\UserGroup
;
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
;
21 * Shows the user profile page.
24 * @copyright 2001-2014 WoltLab GmbH
25 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
26 * @package com.woltlab.wcf
28 * @category Community Framework
30 class UserPage
extends AbstractPage
{
32 * @see \wcf\page\AbstractPage::$activeMenuItem
34 public $activeMenuItem = 'wcf.user.members';
37 * @see \wcf\page\AbstractPage::$enableTracking
39 public $enableTracking = true;
42 * edit profile on page load
45 public $editOnInit = false;
48 * overview editable content object type
49 * @var \wcf\data\object\type\ObjectType
51 public $objectType = null;
54 * profile content for active menu item
57 public $profileContent = '';
67 * @var \wcf\data\user\UserProfile
73 * @var \wcf\data\user\follow\UserFollowerList
75 public $followerList = null;
79 * @var \wcf\data\user\follow\UserFollowingList
81 public $followingList = null;
85 * @var \wcf\data\user\profile\visitor\UserProfileVisitorList
87 public $visitorList = null;
90 * @see \wcf\page\IPage::readParameters()
92 public function readParameters() {
93 parent
::readParameters();
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();
101 if ($this->user
->userID
!= WCF
::getUser()->userID
&& !WCF
::getSession()->getPermission('user.profile.canViewUserProfile')) {
102 throw new PermissionDeniedException();
105 // check is Accessible
106 if ($this->user
->isProtected()) {
107 throw new PermissionDeniedException();
110 if (isset($_REQUEST['editOnInit'])) $this->editOnInit
= true;
114 * @see \wcf\page\IPage::readData()
116 public function readData() {
120 if (MODULE_MEMBERS_LIST
) WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.user.members'), LinkHandler
::getInstance()->getLink('MembersList')));
122 // get profile content
123 if ($this->editOnInit
) {
124 // force 'about' tab as primary if editing profile
125 UserProfileMenu
::getInstance()->setActiveMenuItem('about');
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');
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();
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();
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();
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);
161 * @see \wcf\page\IPage::assignVariables()
163 public function assignVariables() {
164 parent
::assignVariables();
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(),
176 'visitors' => ($this->visitorList
!== null ?
$this->visitorList
->getObjects() : array()),
177 'visitorCount' => ($this->visitorList
!== null ?
$this->visitorList
->countObjects() : 0),
178 'allowSpidersToIndexThisPage' => true,
179 'isAccessible' => UserGroup
::isAccessibleGroup($this->user
->getGroupIDs())
184 * @see \wcf\page\IPage::show()
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));
193 if (PROFILE_ENABLE_VISITORS
&& WCF
::getUser()->userID
&& !WCF
::getUser()->canViewOnlineStatus
) {
194 if (($visitor = UserProfileVisitor
::getObject($this->user
->userID
, WCF
::getUser()->userID
)) !== null) {
195 $editor = new UserProfileVisitorEditor($visitor);
196 $editor->update(array(
201 UserProfileVisitorEditor
::create(array(
202 'ownerID' => $this->user
->userID
,
203 'userID' => WCF
::getUser()->userID
,
214 * @see \wcf\page\ITrackablePage::getObjectType()
216 public function getObjectType() {
217 return 'com.woltlab.wcf.user';
221 * @see \wcf\page\ITrackablePage::getObjectID()
223 public function getObjectID() {
224 return $this->userID
;