From c4570326457234c2e76ba6d7caf81b6a0cbb1976 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 19 Feb 2011 18:28:41 -0800 Subject: [PATCH] Slightly more sophisticated profiles. Summary: Test Plan: Reviewers: CC: --- src/__celerity_resource_map__.php | 2 +- src/__phutil_library_map__.php | 4 + ...AphrontDefaultApplicationConfiguration.php | 3 + .../PhabricatorPeopleProfileController.php | 27 +++++- .../people/controller/profile/__init__.php | 2 + ...PhabricatorPeopleProfileEditController.php | 97 +++++++++++++++++++ .../controller/profileedit/__init__.php | 20 ++++ .../profile/PhabricatorUserProfile.php | 26 +++++ .../people/storage/profile/__init__.php | 12 +++ 9 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php create mode 100644 src/applications/people/controller/profileedit/__init__.php create mode 100644 src/applications/people/storage/profile/PhabricatorUserProfile.php create mode 100644 src/applications/people/storage/profile/__init__.php diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 45165c3d2c..d8c6cddba3 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -227,7 +227,7 @@ celerity_register_resource_map(array( ), 'phabricator-profile-css' => array( - 'uri' => '/res/c3c5c82e/rsrc/css/application/people/profile.css', + 'uri' => '/res/259ad37f/rsrc/css/application/people/profile.css', 'type' => 'css', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d747c3b38b..81e017f63c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -228,6 +228,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleEditController' => 'applications/people/controller/edit', 'PhabricatorPeopleListController' => 'applications/people/controller/list', 'PhabricatorPeopleProfileController' => 'applications/people/controller/profile', + 'PhabricatorPeopleProfileEditController' => 'applications/people/controller/profileedit', 'PhabricatorRemarkupRuleDifferential' => 'infrastructure/markup/remarkup/markuprule/differential', 'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest', 'PhabricatorRepository' => 'applications/repository/storage/repository', @@ -258,6 +259,7 @@ phutil_register_library_map(array( 'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/base', 'PhabricatorUser' => 'applications/people/storage/user', 'PhabricatorUserDAO' => 'applications/people/storage/base', + 'PhabricatorUserProfile' => 'applications/people/storage/profile', 'PhabricatorUserSettingsController' => 'applications/people/controller/settings', 'PhabricatorXHProfController' => 'applications/xhprof/controller/base', 'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/profile', @@ -457,6 +459,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleEditController' => 'PhabricatorPeopleController', 'PhabricatorPeopleListController' => 'PhabricatorPeopleController', 'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController', + 'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController', 'PhabricatorRemarkupRuleDifferential' => 'PhutilRemarkupRule', 'PhabricatorRemarkupRuleManiphest' => 'PhutilRemarkupRule', 'PhabricatorRepository' => 'PhabricatorRepositoryDAO', @@ -482,6 +485,7 @@ phutil_register_library_map(array( 'PhabricatorTypeaheadDatasourceController' => 'PhabricatorController', 'PhabricatorUser' => 'PhabricatorUserDAO', 'PhabricatorUserDAO' => 'PhabricatorLiskDAO', + 'PhabricatorUserProfile' => 'PhabricatorUserDAO', 'PhabricatorUserSettingsController' => 'PhabricatorPeopleController', 'PhabricatorXHProfController' => 'PhabricatorController', 'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 4664cec0e7..5b78ad3f92 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -64,6 +64,9 @@ class AphrontDefaultApplicationConfiguration 'edit/(?:(?P\w+)/)?$' => 'PhabricatorPeopleEditController', ), '/p/(?P\w+)/$' => 'PhabricatorPeopleProfileController', + '/profile/' => array( + 'edit/$' => 'PhabricatorPeopleProfileEditController', + ), '/conduit/' => array( '$' => 'PhabricatorConduitConsoleController', 'method/(?P[^/]+)$' => 'PhabricatorConduitConsoleController', diff --git a/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php b/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php index a865830539..2f92731e29 100644 --- a/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php @@ -35,13 +35,20 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController { return new Aphront404Response(); } + $profile = id(new PhabricatorUserProfile())->loadOneWhere( + 'userPHID = %s', + $user->getPHID()); + if (!$profile) { + $profile = new PhabricatorUserProfile(); + } + $links = array(); if ($user->getPHID() == $viewer->getPHID()) { $links[] = phutil_render_tag( 'a', array( - 'href' => '/p/'.$user->getUsername().'/edit/', + 'href' => '/profile/edit/', ), 'Edit Profile'); } @@ -64,6 +71,8 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController { implode("\n", $links). ''; + $title = nonempty($profile->getTitle(), 'Untitled Document'); + $username_tag = '

'. phutil_escape_html($user->getUserName()). @@ -74,10 +83,13 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController { '

'; $title_tag = '

'. - 'Cool Title'. + phutil_escape_html($title). '

'; - $src_phid = $user->getProfileImagePHID(); + $src_phid = $profile->getProfileImagePHID(); + if (!$src_phid) { + $src_phid = $user->getProfileImagePHID(); + } $src = PhabricatorFileURI::getViewURIForPHID($src_phid); $picture = phutil_render_tag( @@ -89,7 +101,14 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController { require_celerity_resource('phabricator-profile-css'); - $blurb = 'just build marawdars dood'; + $blurb = nonempty( + $profile->getBlurb(), + '//Nothing is known about this rare specimen.//'); + + $factory = new DifferentialMarkupEngineFactory(); + $engine = $factory->newDifferentialCommentMarkupEngine(); + + $blurb = $engine->markupText($blurb); $content = '
diff --git a/src/applications/people/controller/profile/__init__.php b/src/applications/people/controller/profile/__init__.php index 099425d646..6d2fbb0974 100644 --- a/src/applications/people/controller/profile/__init__.php +++ b/src/applications/people/controller/profile/__init__.php @@ -7,8 +7,10 @@ phutil_require_module('phabricator', 'aphront/response/404'); +phutil_require_module('phabricator', 'applications/differential/parser/markup'); phutil_require_module('phabricator', 'applications/files/uri'); phutil_require_module('phabricator', 'applications/people/controller/base'); +phutil_require_module('phabricator', 'applications/people/storage/profile'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'view/utils'); diff --git a/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php b/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php new file mode 100644 index 0000000000..26ee121d99 --- /dev/null +++ b/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php @@ -0,0 +1,97 @@ +getRequest(); + $user = $request->getUser(); + + $profile = id(new PhabricatorUserProfile())->loadOneWhere( + 'userPHID = %s', + $user->getPHID()); + if (!$profile) { + $profile = new PhabricatorUserProfile(); + $profile->setUserPHID($user->getPHID()); + } + + + if ($request->isFormPost()) { + $profile->setTitle($request->getStr('title')); + $profile->setBlurb($request->getStr('blurb')); + + if (!empty($_FILES['image'])) { + $err = idx($_FILES['image'], 'error'); + if ($err != UPLOAD_ERR_NO_FILE) { + $file = PhabricatorFile::newFromPHPUpload($_FILES['image']); + $profile->setProfileImagePHID($file->getPHID()); + } + } + + $profile->save(); + $response = id(new AphrontRedirectResponse()) + ->setURI('/p/'.$user->getUsername().'/'); + return $response; + } + + $form = new AphrontFormView(); + $form + ->setUser($request->getUser()) + ->setAction('/profile/edit/') + ->setEncType('multipart/form-data') + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Title') + ->setName('title') + ->setValue($profile->getTitle()) + ->setCaption('Serious business title.')) + ->appendChild( + '

Write something about yourself! '. + 'Make sure to include important information like '. + 'your favorite pokemon and which '. + 'Starcraft race you play.

') + ->appendChild( + id(new AphrontFormTextAreaControl()) + ->setLabel('Blurb') + ->setName('blurb') + ->setValue($profile->getBlurb())) + ->appendChild( + id(new AphrontFormFileControl()) + ->setLabel('Change Image') + ->setName('image') + ->setCaption('Upload a 280px-wide image.')) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Save') + ->addCancelButton('/p/'.$user->getUsername().'/')); + + $panel = new AphrontPanelView(); + $panel->setHeader('Edit Profile Details'); + $panel->appendChild($form); + $panel->setWidth(AphrontPanelView::WIDTH_FORM); + + return $this->buildStandardPageResponse( + $panel, + array( + 'title' => 'Edit Profile', + )); + } + +} diff --git a/src/applications/people/controller/profileedit/__init__.php b/src/applications/people/controller/profileedit/__init__.php new file mode 100644 index 0000000000..342b8b2a26 --- /dev/null +++ b/src/applications/people/controller/profileedit/__init__.php @@ -0,0 +1,20 @@ +