Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / page / UserPage.class.php
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;
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;
17 use wcf\system\WCF;
18
19 /**
20 * Shows the user profile page.
21 *
22 * @author Marcel Werk
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
26 * @subpackage page
27 * @category Community Framework
28 */
29 class UserPage extends AbstractPage {
30 /**
31 * @see \wcf\page\AbstractPage::$activeMenuItem
32 */
33 public $activeMenuItem = 'wcf.user.members';
34
35 /**
36 * @see \wcf\page\AbstractPage::$enableTracking
37 */
38 public $enableTracking = true;
39
40 /**
41 * edit profile on page load
42 * @var boolean
43 */
44 public $editOnInit = false;
45
46 /**
47 * overview editable content object type
48 * @var \wcf\data\object\type\ObjectType
49 */
50 public $objectType = null;
51
52 /**
53 * profile content for active menu item
54 * @var string
55 */
56 public $profileContent = '';
57
58 /**
59 * user id
60 * @var integer
61 */
62 public $userID = 0;
63
64 /**
65 * user object
66 * @var \wcf\data\user\UserProfile
67 */
68 public $user = null;
69
70 /**
71 * follower list
72 * @var \wcf\data\user\follow\UserFollowerList
73 */
74 public $followerList = null;
75
76 /**
77 * following list
78 * @var \wcf\data\user\follow\UserFollowingList
79 */
80 public $followingList = null;
81
82 /**
83 * visitor list
84 * @var \wcf\data\user\profile\visitor\UserProfileVisitorList
85 */
86 public $visitorList = null;
87
88 /**
89 * @see \wcf\page\IPage::readParameters()
90 */
91 public function readParameters() {
92 parent::readParameters();
93
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();
98 }
99
100 if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
101 throw new PermissionDeniedException();
102 }
103
104 // check is Accessible
105 if ($this->user->isProtected()) {
106 throw new PermissionDeniedException();
107 }
108
109 if (isset($_REQUEST['editOnInit'])) $this->editOnInit = true;
110 }
111
112 /**
113 * @see \wcf\page\IPage::readData()
114 */
115 public function readData() {
116 parent::readData();
117
118 // add breadcrumbs
119 if (MODULE_MEMBERS_LIST) WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.user.members'), LinkHandler::getInstance()->getLink('MembersList')));
120
121 // get profile content
122 if ($this->editOnInit) {
123 // force 'about' tab as primary if editing profile
124 UserProfileMenu::getInstance()->setActiveMenuItem('about');
125 }
126
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');
131
132 // get followers
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();
137
138 // get following
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();
143
144 // get visitors
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();
150 }
151
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);
157 }
158
159 /**
160 * @see \wcf\page\IPage::assignVariables()
161 */
162 public function assignVariables() {
163 parent::assignVariables();
164
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
178 ));
179 }
180
181 /**
182 * @see \wcf\page\IPage::show()
183 */
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));
189
190 // save visitor
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(
195 'time' => TIME_NOW
196 ));
197 }
198 else {
199 UserProfileVisitorEditor::create(array(
200 'ownerID' => $this->user->userID,
201 'userID' => WCF::getUser()->userID,
202 'time' => TIME_NOW
203 ));
204 }
205 }
206 }
207
208 parent::show();
209 }
210
211 /**
212 * @see \wcf\page\ITrackablePage::getObjectType()
213 */
214 public function getObjectType() {
215 return 'com.woltlab.wcf.user';
216 }
217
218 /**
219 * @see \wcf\page\ITrackablePage::getObjectID()
220 */
221 public function getObjectID() {
222 return $this->userID;
223 }
224 }