3 final class PhameBlogProfilePictureController
4 extends PhameBlogController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $blog = id(new PhameBlogQuery())
13 ->needProfileImage(true)
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $blog_uri = '/phame/blog/manage/'.$id;
26 $supported_formats = PhabricatorFile
::getTransformableImageFormats();
30 if ($request->isFormPost()) {
31 $phid = $request->getStr('phid');
33 if ($phid == PhabricatorPHIDConstants
::PHID_VOID
) {
37 $file = id(new PhabricatorFileQuery())
39 ->withPHIDs(array($phid))
42 if ($request->getFileExists('picture')) {
43 $file = PhabricatorFile
::newFromPHPUpload(
46 'authorPHID' => $viewer->getPHID(),
50 $e_file = pht('Required');
52 'You must choose a file when uploading a new blog picture.');
56 if (!$errors && !$is_default) {
57 if (!$file->isTransformableImage()) {
58 $e_file = pht('Not Supported');
60 'This server only supports these image formats: %s.',
61 implode(', ', $supported_formats));
63 $xform = PhabricatorFileTransform
::getTransformByKey(
64 PhabricatorFileThumbnailTransform
::TRANSFORM_PROFILE
);
65 $xformed = $xform->executeTransform($file);
73 $xformed->attachToObject($blog->getPHID());
74 $new_value = $xformed->getPHID();
78 $xactions[] = id(new PhameBlogTransaction())
80 PhameBlogProfileImageTransaction
::TRANSACTIONTYPE
)
81 ->setNewValue($new_value);
83 $editor = id(new PhameBlogEditor())
85 ->setContentSourceFromRequest($request)
86 ->setContinueOnMissingFields(true)
87 ->setContinueOnNoEffect(true);
89 $editor->applyTransactions($blog, $xactions);
91 return id(new AphrontRedirectResponse())->setURI($blog_uri);
95 $title = pht('Edit Blog Picture');
97 $form = id(new PHUIFormLayoutView())
100 $default_image = PhabricatorFile
::loadBuiltin($viewer, 'blog.png');
104 $current = $blog->getProfileImagePHID();
105 $has_current = false;
107 $files = id(new PhabricatorFileQuery())
109 ->withPHIDs(array($current))
112 $file = head($files);
113 if ($file->isTransformableImage()) {
115 $images[$current] = array(
116 'uri' => $file->getBestURI(),
117 'tip' => pht('Current Picture'),
123 $images[PhabricatorPHIDConstants
::PHID_VOID
] = array(
124 'uri' => $default_image->getBestURI(),
125 'tip' => pht('Default Picture'),
128 require_celerity_resource('people-profile-css');
129 Javelin
::initBehavior('phabricator-tooltips', array());
132 foreach ($images as $phid => $spec) {
133 $button = javelin_tag(
136 'class' => 'button-grey profile-image-button',
137 'sigil' => 'has-tooltip',
139 'tip' => $spec['tip'],
148 'src' => $spec['uri'],
162 $button = phabricator_form(
165 'class' => 'profile-image-form',
170 $buttons[] = $button;
175 id(new AphrontFormMarkupControl())
176 ->setLabel(pht('Current Picture'))
177 ->setValue(array_shift($buttons)));
181 id(new AphrontFormMarkupControl())
182 ->setLabel(pht('Use Picture'))
183 ->setValue($buttons));
185 $form_box = id(new PHUIObjectBoxView())
186 ->setHeaderText($title)
187 ->setFormErrors($errors)
188 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
191 $upload_form = id(new AphrontFormView())
193 ->setEncType('multipart/form-data')
195 id(new AphrontFormFileControl())
197 ->setLabel(pht('Upload Picture'))
200 pht('Supported formats: %s', implode(', ', $supported_formats))))
202 id(new AphrontFormSubmitControl())
203 ->addCancelButton($blog_uri)
204 ->setValue(pht('Upload Picture')));
206 $upload_box = id(new PHUIObjectBoxView())
207 ->setHeaderText(pht('Upload New Picture'))
208 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
209 ->setForm($upload_form);
211 $crumbs = $this->buildApplicationCrumbs();
212 $crumbs->addTextCrumb(
214 $this->getApplicationURI('blog/'));
215 $crumbs->addTextCrumb(
217 $this->getApplicationURI('blog/view/'.$id));
218 $crumbs->addTextCrumb(pht('Blog Picture'));
219 $crumbs->setBorder(true);
221 $header = id(new PHUIHeaderView())
222 ->setHeader(pht('Edit Blog Picture'))
223 ->setHeaderIcon('fa-camera');
225 $view = id(new PHUITwoColumnView())
232 return $this->newPage()