2011-01-24 03:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PhabricatorPeopleProfileController extends PhabricatorPeopleController {
|
|
|
|
|
|
|
|
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-02-20 03:28:41 +01:00
|
|
|
$profile = id(new PhabricatorUserProfile())->loadOneWhere(
|
|
|
|
'userPHID = %s',
|
|
|
|
$user->getPHID());
|
|
|
|
if (!$profile) {
|
|
|
|
$profile = new PhabricatorUserProfile();
|
|
|
|
}
|
|
|
|
|
2011-02-20 02:33:53 +01:00
|
|
|
$links = array();
|
|
|
|
|
|
|
|
if ($user->getPHID() == $viewer->getPHID()) {
|
|
|
|
$links[] = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2011-02-20 03:28:41 +01:00
|
|
|
'href' => '/profile/edit/',
|
2011-02-20 02:33:53 +01:00
|
|
|
),
|
|
|
|
'Edit Profile');
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
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) {
|
|
|
|
$links[] = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $href,
|
|
|
|
),
|
|
|
|
phutil_escape_html($name));
|
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
// TODO: perhaps, if someone wants to add to the profile of the user the
|
|
|
|
// ability to show the task/revisions where he is working/commenting
|
|
|
|
// on, this has to be changed to something like
|
|
|
|
// |$this->page = key($pages)|, since the "page" regexp was added to
|
|
|
|
// the aphrontconfiguration.
|
|
|
|
if (empty($links[$this->page])) {
|
|
|
|
$this->page = 'action';
|
2011-02-20 02:33:53 +01:00
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
switch ($this->page) {
|
|
|
|
default:
|
|
|
|
$content = $this->renderBasicInformation($user, $profile);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-02-20 03:28:41 +01:00
|
|
|
$src_phid = $profile->getProfileImagePHID();
|
|
|
|
if (!$src_phid) {
|
|
|
|
$src_phid = $user->getProfileImagePHID();
|
|
|
|
}
|
2011-06-18 10:13:56 +02:00
|
|
|
$picture = PhabricatorFileURI::getViewURIForPHID($src_phid);
|
|
|
|
$title = nonempty($profile->getTitle(), 'Untitled Document');
|
|
|
|
$realname = '('.$user->getRealName().')';
|
|
|
|
|
|
|
|
$profile = new PhabricatorProfileView();
|
|
|
|
$profile->setProfilePicture($picture);
|
|
|
|
$profile->setProfileNames(
|
|
|
|
$user->getUserName(),
|
|
|
|
$realname,
|
|
|
|
$title);
|
|
|
|
foreach ($links as $page => $name) {
|
|
|
|
if (is_integer($page)) {
|
|
|
|
$profile->addProfileItem(
|
|
|
|
phutil_render_tag(
|
|
|
|
'span',
|
|
|
|
array(),
|
|
|
|
$name));
|
|
|
|
} else {
|
|
|
|
$profile->addProfileItem($page);
|
|
|
|
}
|
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
$profile->appendChild($content);
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$profile,
|
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-02-20 03:28:41 +01:00
|
|
|
$blurb = nonempty(
|
|
|
|
$profile->getBlurb(),
|
|
|
|
'//Nothing is known about this rare specimen.//');
|
|
|
|
|
|
|
|
$factory = new DifferentialMarkupEngineFactory();
|
|
|
|
$engine = $factory->newDifferentialCommentMarkupEngine();
|
|
|
|
$blurb = $engine->markupText($blurb);
|
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>
|
|
|
|
<td>'.phabricator_format_timestamp($user->getDateCreated()).'</td>
|
|
|
|
</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-06-18 10:13:56 +02:00
|
|
|
return $content;
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
}
|