2011-01-24 03:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorPeopleProfileController
|
|
|
|
extends PhabricatorPeopleController {
|
2011-01-24 03:09:16 +01:00
|
|
|
|
|
|
|
private $username;
|
2011-06-18 10:13:56 +02:00
|
|
|
private $page;
|
2012-08-10 21:11:24 +02:00
|
|
|
private $profileUser;
|
2011-01-24 03:09:16 +01:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-18 10:13:56 +02:00
|
|
|
$this->username = idx($data, 'username');
|
|
|
|
$this->page = idx($data, 'page');
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
|
2012-08-10 21:11:24 +02:00
|
|
|
public function getProfileUser() {
|
|
|
|
return $this->profileUser;
|
|
|
|
}
|
|
|
|
|
2013-02-05 22:46:02 +01:00
|
|
|
private function getMainFilters($username) {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'key' => 'feed',
|
|
|
|
'name' => pht('Feed'),
|
|
|
|
'href' => '/p/'.$username.'/feed/'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'key' => 'about',
|
|
|
|
'name' => pht('About'),
|
|
|
|
'href' => '/p/'.$username.'/about/'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
public function processRequest() {
|
|
|
|
|
2011-02-20 02:33:53 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
$user = id(new PhabricatorUser())->loadOneWhere(
|
|
|
|
'userName = %s',
|
|
|
|
$this->username);
|
|
|
|
if (!$user) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-08-10 21:11:24 +02:00
|
|
|
$this->profileUser = $user;
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
2011-02-20 03:28:41 +01:00
|
|
|
$profile = id(new PhabricatorUserProfile())->loadOneWhere(
|
|
|
|
'userPHID = %s',
|
|
|
|
$user->getPHID());
|
|
|
|
if (!$profile) {
|
|
|
|
$profile = new PhabricatorUserProfile();
|
|
|
|
}
|
2012-03-06 22:57:31 +01:00
|
|
|
$username = phutil_escape_uri($user->getUserName());
|
2011-02-20 03:28:41 +01:00
|
|
|
|
2013-02-05 22:46:02 +01:00
|
|
|
$menu = new PhabricatorMenuView();
|
|
|
|
foreach ($this->getMainFilters($username) as $filter) {
|
|
|
|
$menu->newLink($filter['name'], $filter['href'], $filter['key']);
|
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2013-02-05 22:46:02 +01:00
|
|
|
$menu->newLabel(pht('Activity'), 'activity');
|
|
|
|
// NOTE: applications install the various links through PhabricatorEvent
|
|
|
|
// listeners
|
2012-12-03 23:13:38 +01:00
|
|
|
|
2011-02-22 20:06:37 +01:00
|
|
|
$oauths = id(new PhabricatorUserOAuthInfo())->loadAllWhere(
|
|
|
|
'userID = %d',
|
|
|
|
$user->getID());
|
|
|
|
$oauths = mpull($oauths, null, 'getOAuthProvider');
|
|
|
|
|
|
|
|
$providers = PhabricatorOAuthProvider::getAllProviders();
|
2013-01-13 17:17:12 +01:00
|
|
|
$added_label = false;
|
2011-02-22 20:06:37 +01:00
|
|
|
foreach ($providers as $provider) {
|
|
|
|
if (!$provider->isProviderEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$provider_key = $provider->getProviderKey();
|
|
|
|
|
|
|
|
if (!isset($oauths[$provider_key])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-02-05 22:46:02 +01:00
|
|
|
$name = pht('%s Profile', $provider->getProviderName());
|
2011-02-22 20:06:37 +01:00
|
|
|
$href = $oauths[$provider_key]->getAccountURI();
|
|
|
|
|
|
|
|
if ($href) {
|
2013-01-13 17:17:12 +01:00
|
|
|
if (!$added_label) {
|
2013-02-05 22:46:02 +01:00
|
|
|
$menu->newLabel(pht('Linked Accounts'), 'linked_accounts');
|
2013-01-13 17:17:12 +01:00
|
|
|
$added_label = true;
|
2011-12-24 03:17:40 +01:00
|
|
|
}
|
2013-02-05 22:46:02 +01:00
|
|
|
$menu->addMenuItem(
|
|
|
|
id(new PhabricatorMenuItemView())
|
|
|
|
->setIsExternal(true)
|
|
|
|
->setName($name)
|
|
|
|
->setHref($href)
|
|
|
|
->setType(PhabricatorMenuItemView::TYPE_LINK)
|
|
|
|
);
|
2011-02-22 20:06:37 +01:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
}
|
|
|
|
|
2013-02-05 22:46:02 +01:00
|
|
|
$event = new PhabricatorEvent(
|
|
|
|
PhabricatorEventType::TYPE_PEOPLE_DIDRENDERMENU,
|
|
|
|
array(
|
|
|
|
'menu' => $menu,
|
|
|
|
'person' => $user,
|
|
|
|
));
|
|
|
|
$event->setUser($viewer);
|
|
|
|
PhutilEventEngine::dispatchEvent($event);
|
|
|
|
$nav = AphrontSideNavFilterView::newFromMenu($event->getValue('menu'));
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$this->page = $nav->selectFilter($this->page, 'feed');
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
switch ($this->page) {
|
2011-12-24 03:17:40 +01:00
|
|
|
case 'feed':
|
|
|
|
$content = $this->renderUserFeed($user);
|
|
|
|
break;
|
|
|
|
case 'about':
|
2011-06-18 10:13:56 +02:00
|
|
|
$content = $this->renderBasicInformation($user, $profile);
|
|
|
|
break;
|
2011-12-24 03:17:40 +01:00
|
|
|
default:
|
|
|
|
throw new Exception("Unknown page '{$this->page}'!");
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2012-04-28 02:44:10 +02:00
|
|
|
$picture = $user->loadProfileImageURI();
|
2011-12-24 03:17:40 +01:00
|
|
|
|
|
|
|
$header = new PhabricatorProfileHeaderView();
|
|
|
|
$header
|
|
|
|
->setProfilePicture($picture)
|
|
|
|
->setName($user->getUserName().' ('.$user->getRealName().')')
|
|
|
|
->setDescription($profile->getTitle());
|
|
|
|
|
2012-05-18 00:13:33 +02:00
|
|
|
if ($user->getIsDisabled()) {
|
|
|
|
$header->setStatus('Disabled');
|
|
|
|
} else {
|
2012-05-17 03:42:06 +02:00
|
|
|
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
|
|
|
|
array($user->getPHID()));
|
|
|
|
if ($statuses) {
|
2012-10-24 22:22:24 +02:00
|
|
|
$header->setStatus(reset($statuses)->getTerseSummary($viewer));
|
2012-05-18 00:13:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 22:57:31 +01:00
|
|
|
$nav->appendChild($header);
|
|
|
|
|
2013-02-13 03:46:01 +01:00
|
|
|
$content = hsprintf('<div style="padding: 1em;">%s</div>', $content);
|
2013-01-09 22:57:31 +01:00
|
|
|
$header->appendChild($content);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
|
|
|
if ($user->getPHID() == $viewer->getPHID()) {
|
2013-02-05 22:46:02 +01:00
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
|
|
|
pht('Edit Profile...'),
|
|
|
|
'/settings/panel/profile/'
|
|
|
|
);
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2012-01-17 01:54:05 +01:00
|
|
|
if ($viewer->getIsAdmin()) {
|
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
2013-02-05 22:46:02 +01:00
|
|
|
pht('Administrate User...'),
|
|
|
|
'/people/edit/'.$user->getID().'/'
|
|
|
|
);
|
2012-01-17 01:54:05 +01:00
|
|
|
}
|
|
|
|
|
2012-08-14 00:27:21 +02:00
|
|
|
return $this->buildApplicationPage(
|
2013-01-09 22:57:31 +01:00
|
|
|
$nav,
|
2011-02-20 02:33:53 +01:00
|
|
|
array(
|
2011-06-18 10:13:56 +02:00
|
|
|
'title' => $user->getUsername(),
|
2011-02-20 02:33:53 +01:00
|
|
|
));
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
private function renderBasicInformation($user, $profile) {
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2011-02-20 03:28:41 +01:00
|
|
|
$blurb = nonempty(
|
|
|
|
$profile->getBlurb(),
|
2013-02-12 08:42:37 +01:00
|
|
|
'//'.pht('Nothing is known about this rare specimen.').'//'
|
2013-02-05 22:46:02 +01:00
|
|
|
);
|
2011-02-20 03:28:41 +01:00
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$engine = PhabricatorMarkupEngine::newProfileMarkupEngine();
|
2013-02-12 08:42:37 +01:00
|
|
|
$blurb = $engine->markupText($blurb);
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-12-04 01:36:19 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content = hsprintf(
|
2011-02-20 02:33:53 +01:00
|
|
|
'<div class="phabricator-profile-info-group">
|
|
|
|
<h1 class="phabricator-profile-info-header">Basic Information</h1>
|
|
|
|
<div class="phabricator-profile-info-pane">
|
|
|
|
<table class="phabricator-profile-info-table">
|
|
|
|
<tr>
|
|
|
|
<th>PHID</th>
|
2013-02-08 21:07:44 +01:00
|
|
|
<td>%s</td>
|
2011-02-20 02:33:53 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>User Since</th>
|
2013-02-08 21:07:44 +01:00
|
|
|
<td>%s</td>
|
2011-02-20 02:33:53 +01:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
2013-02-08 21:07:44 +01:00
|
|
|
</div>'.
|
2011-02-20 02:33:53 +01:00
|
|
|
'<div class="phabricator-profile-info-group">
|
|
|
|
<h1 class="phabricator-profile-info-header">Flavor Text</h1>
|
|
|
|
<div class="phabricator-profile-info-pane">
|
|
|
|
<table class="phabricator-profile-info-table">
|
|
|
|
<tr>
|
|
|
|
<th>Blurb</th>
|
2013-02-08 21:07:44 +01:00
|
|
|
<td>%s</td>
|
2011-02-20 02:33:53 +01:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
2013-02-08 21:07:44 +01:00
|
|
|
</div>',
|
|
|
|
$user->getPHID(),
|
|
|
|
phabricator_datetime($user->getDateCreated(), $viewer),
|
|
|
|
$blurb);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderUserFeed(PhabricatorUser $user) {
|
2012-07-03 00:41:19 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$user->getPHID(),
|
|
|
|
));
|
2012-07-03 15:25:03 +02:00
|
|
|
$query->setLimit(100);
|
2012-07-03 00:41:19 +02:00
|
|
|
$query->setViewer($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
2012-07-03 00:41:19 +02:00
|
|
|
$builder->setUser($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2013-02-13 03:46:01 +01:00
|
|
|
return hsprintf(
|
2011-07-24 02:09:03 +02:00
|
|
|
'<div class="phabricator-profile-info-group">
|
2011-12-24 03:17:40 +01:00
|
|
|
<h1 class="phabricator-profile-info-header">Activity Feed</h1>
|
2013-02-13 03:46:01 +01:00
|
|
|
<div class="phabricator-profile-info-pane">%s</div>
|
|
|
|
</div>',
|
|
|
|
$view->render());
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
}
|