2011-01-24 03:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-10 23:48:55 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-24 03:09:16 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$nav = new AphrontSideNavFilterView();
|
2012-03-06 22:57:31 +01:00
|
|
|
$nav->setBaseURI(new PhutilURI('/p/'.$username.'/'));
|
2011-12-24 03:17:40 +01:00
|
|
|
$nav->addFilter('feed', 'Feed');
|
|
|
|
$nav->addFilter('about', 'About');
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$nav->addSpacer();
|
|
|
|
$nav->addLabel('Activity');
|
|
|
|
|
|
|
|
$external_arrow = "\xE2\x86\x97";
|
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
|
|
|
"Revisions {$external_arrow}",
|
2012-03-06 22:57:31 +01:00
|
|
|
'/differential/filter/revisions/'.$username.'/');
|
2011-12-24 03:17:40 +01:00
|
|
|
|
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
|
|
|
"Tasks {$external_arrow}",
|
|
|
|
'/maniphest/view/action/?users='.$user->getPHID());
|
|
|
|
|
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
|
|
|
"Commits {$external_arrow}",
|
2012-03-06 22:57:31 +01:00
|
|
|
'/audit/view/author/'.$username.'/');
|
2011-02-20 02:33:53 +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();
|
2011-12-24 03:17:40 +01:00
|
|
|
$added_spacer = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $provider->getProviderName().' Profile';
|
|
|
|
$href = $oauths[$provider_key]->getAccountURI();
|
|
|
|
|
|
|
|
if ($href) {
|
2011-12-24 03:17:40 +01:00
|
|
|
if (!$added_spacer) {
|
|
|
|
$nav->addSpacer();
|
|
|
|
$nav->addLabel('Linked Accounts');
|
|
|
|
$added_spacer = true;
|
|
|
|
}
|
|
|
|
$nav->addFilter(null, $name.' '.$external_arrow, $href);
|
2011-02-22 20:06:37 +01:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
$status = id(new PhabricatorUserStatus())->loadOneWhere(
|
|
|
|
'userPHID = %s AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo',
|
|
|
|
$user->getPHID());
|
|
|
|
if ($status) {
|
|
|
|
$header->setStatus($status->getStatusDescription());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$header->appendChild($nav);
|
|
|
|
$nav->appendChild(
|
|
|
|
'<div style="padding: 1em;">'.$content.'</div>');
|
|
|
|
|
|
|
|
if ($user->getPHID() == $viewer->getPHID()) {
|
|
|
|
$nav->addSpacer();
|
|
|
|
$nav->addFilter(null, 'Edit Profile...', '/settings/page/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->addSpacer();
|
|
|
|
$nav->addFilter(
|
|
|
|
null,
|
|
|
|
'Administrate User...',
|
|
|
|
'/people/edit/'.$user->getID().'/');
|
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
return $this->buildStandardPageResponse(
|
2011-12-24 03:17:40 +01:00
|
|
|
$header,
|
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(),
|
|
|
|
'//Nothing is known about this rare specimen.//');
|
|
|
|
|
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();
|
2011-02-20 03:28:41 +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();
|
|
|
|
|
2011-02-20 02:33:53 +01:00
|
|
|
$content =
|
|
|
|
'<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>
|
|
|
|
<td>'.phutil_escape_html($user->getPHID()).'</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>User Since</th>
|
2011-12-04 01:36:19 +01:00
|
|
|
<td>'.phabricator_datetime($user->getDateCreated(),
|
|
|
|
$viewer).
|
|
|
|
'</td>
|
2011-02-20 02:33:53 +01:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
$content .=
|
|
|
|
'<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>
|
|
|
|
<td>'.$blurb.'</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>';
|
2011-12-24 03:17:40 +01:00
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderUserFeed(PhabricatorUser $user) {
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$user->getPHID(),
|
|
|
|
));
|
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
|
|
|
$builder->setUser($this->getRequest()->getUser());
|
|
|
|
$view = $builder->buildView();
|
|
|
|
|
|
|
|
return
|
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>
|
2011-07-24 02:09:03 +02:00
|
|
|
<div class="phabricator-profile-info-pane">
|
2011-12-24 03:17:40 +01:00
|
|
|
'.$view->render().'
|
2011-07-24 02:09:03 +02:00
|
|
|
</div>
|
|
|
|
</div>';
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
}
|