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\profile\visitor\UserProfileVisitor
;
7 use wcf\data\user\profile\visitor\UserProfileVisitorEditor
;
8 use wcf\data\user\profile\visitor\UserProfileVisitorList
;
9 use wcf\data\user\UserEditor
;
10 use wcf\data\user\UserProfile
;
11 use wcf\system\breadcrumb\Breadcrumb
;
12 use wcf\system\exception\IllegalLinkException
;
13 use wcf\system\exception\PermissionDeniedException
;
14 use wcf\system\menu\user\profile\UserProfileMenu
;
15 use wcf\system\request\LinkHandler
;
16 use wcf\system\MetaTagHandler
;
20 * Shows the user profile page.
23 * @copyright 2001-2014 WoltLab GmbH
24 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 * @package com.woltlab.wcf
27 * @category Community Framework
29 class UserPage
extends AbstractPage
{
31 * @see \wcf\page\AbstractPage::$activeMenuItem
33 public $activeMenuItem = 'wcf.user.members';
36 * @see \wcf\page\AbstractPage::$enableTracking
38 public $enableTracking = true;
41 * edit profile on page load
44 public $editOnInit = false;
47 * overview editable content object type
48 * @var \wcf\data\object\type\ObjectType
50 public $objectType = null;
53 * profile content for active menu item
56 public $profileContent = '';
66 * @var \wcf\data\user\UserProfile
72 * @var \wcf\data\user\follow\UserFollowerList
74 public $followerList = null;
78 * @var \wcf\data\user\follow\UserFollowingList
80 public $followingList = null;
84 * @var \wcf\data\user\profile\visitor\UserProfileVisitorList
86 public $visitorList = null;
89 * @see \wcf\page\IPage::readParameters()
91 public function readParameters() {
92 parent
::readParameters();
94 if (isset($_REQUEST['id'])) $this->userID
= intval($_REQUEST['id']);
95 $this->user
= UserProfile
::getUserProfile($this->userID
);
96 if ($this->user
=== null) {
97 throw new IllegalLinkException();
100 if ($this->user
->userID
!= WCF
::getUser()->userID
&& !WCF
::getSession()->getPermission('user.profile.canViewUserProfile')) {
101 throw new PermissionDeniedException();
104 // check is Accessible
105 if ($this->user
->isProtected()) {
106 throw new PermissionDeniedException();
109 if (isset($_REQUEST['editOnInit'])) $this->editOnInit
= true;
113 * @see \wcf\page\IPage::readData()
115 public function readData() {
119 if (MODULE_MEMBERS_LIST
) WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.user.members'), LinkHandler
::getInstance()->getLink('MembersList')));
121 // get profile content
122 if ($this->editOnInit
) {
123 // force 'about' tab as primary if editing profile
124 UserProfileMenu
::getInstance()->setActiveMenuItem('about');
127 $activeMenuItem = UserProfileMenu
::getInstance()->getActiveMenuItem();
128 $contentManager = $activeMenuItem->getContentManager();
129 $this->profileContent
= $contentManager->getContent($this->user
->userID
);
130 $this->objectType
= ObjectTypeCache
::getInstance()->getObjectTypeByName('com.woltlab.wcf.user.profileEditableContent', 'com.woltlab.wcf.user.profileAbout');
133 $this->followerList
= new UserFollowerList();
134 $this->followerList
->getConditionBuilder()->add('user_follow.followUserID = ?', array($this->userID
));
135 $this->followerList
->sqlLimit
= 10;
136 $this->followerList
->readObjects();
139 $this->followingList
= new UserFollowingList();
140 $this->followingList
->getConditionBuilder()->add('user_follow.userID = ?', array($this->userID
));
141 $this->followingList
->sqlLimit
= 10;
142 $this->followingList
->readObjects();
145 if (PROFILE_ENABLE_VISITORS
) {
146 $this->visitorList
= new UserProfileVisitorList();
147 $this->visitorList
->getConditionBuilder()->add('user_profile_visitor.ownerID = ?', array($this->userID
));
148 $this->visitorList
->sqlLimit
= 10;
149 $this->visitorList
->readObjects();
152 MetaTagHandler
::getInstance()->addTag('og:url', 'og:url', LinkHandler
::getInstance()->getLink('User', array('object' => $this->user
->getDecoratedObject())), true);
153 MetaTagHandler
::getInstance()->addTag('og:type', 'og:type', 'profile', true);
154 MetaTagHandler
::getInstance()->addTag('og:profile:username', 'og:profile:username', $this->user
->username
, true);
155 MetaTagHandler
::getInstance()->addTag('og:title', 'og:title', WCF
::getLanguage()->getDynamicVariable('wcf.user.profile', array('user' => $this->user
)) . ' - ' . WCF
::getLanguage()->get(PAGE_TITLE
), true);
156 MetaTagHandler
::getInstance()->addTag('og:image', 'og:image', $this->user
->getAvatar()->getURL(), true);
160 * @see \wcf\page\IPage::assignVariables()
162 public function assignVariables() {
163 parent
::assignVariables();
165 WCF
::getTPL()->assign(array(
166 'editOnInit' => $this->editOnInit
,
167 'overviewObjectType' => $this->objectType
,
168 'profileContent' => $this->profileContent
,
169 'userID' => $this->userID
,
170 'user' => $this->user
,
171 'followers' => $this->followerList
->getObjects(),
172 'followerCount' => $this->followerList
->countObjects(),
173 'following' => $this->followingList
->getObjects(),
174 'followingCount' => $this->followingList
->countObjects(),
175 'visitors' => ($this->visitorList
!== null ?
$this->visitorList
->getObjects() : array()),
176 'visitorCount' => ($this->visitorList
!== null ?
$this->visitorList
->countObjects() : 0),
177 'allowSpidersToIndexThisPage' => true
182 * @see \wcf\page\IPage::show()
184 public function show() {
185 // update profile hits
186 if ($this->user
->userID
!= WCF
::getUser()->userID
&& !WCF
::getSession()->spiderID
) {
187 $editor = new UserEditor($this->user
->getDecoratedObject());
188 $editor->updateCounters(array('profileHits' => 1));
191 if (PROFILE_ENABLE_VISITORS
&& WCF
::getUser()->userID
&& !WCF
::getUser()->canViewOnlineStatus
) {
192 if (($visitor = UserProfileVisitor
::getObject($this->user
->userID
, WCF
::getUser()->userID
)) !== null) {
193 $editor = new UserProfileVisitorEditor($visitor);
194 $editor->update(array(
199 UserProfileVisitorEditor
::create(array(
200 'ownerID' => $this->user
->userID
,
201 'userID' => WCF
::getUser()->userID
,
212 * @see \wcf\page\ITrackablePage::getObjectType()
214 public function getObjectType() {
215 return 'com.woltlab.wcf.user';
219 * @see \wcf\page\ITrackablePage::getObjectID()
221 public function getObjectID() {
222 return $this->userID
;